<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    hi guys!<br>
    I'm writing an audio encoder, and I'm having trouble.<br>
    When I encode an audio segment to flac, the encoder generates
    invalid file.<br>
    <br>
    $./encoder.py<br>
    &nbsp;&nbsp; (encoder.py:10109): GStreamer-CRITICAL **:
    _gst_util_uint64_scale: assertion `denom != 0' failed<br>
    &nbsp;&nbsp; True<br>
    &nbsp;&nbsp; eos<br>
    <br>
    $ file dest.flac<br>
    &nbsp;&nbsp; file dest.flac: MPEG ADTS, AAC, v2 LC, 24 kHz, stereo+center+LFE<br>
    <br>
    Thanks<br>
    &nbsp;&nbsp; Platon<br>
    <br>
    <span class="Apple-style-span" style="border-collapse: separate;
      color: rgb(0, 0, 0); font-family: Arial; font-style: normal;
      font-variant: normal; font-weight: normal; letter-spacing: normal;
      line-height: normal; orphans: 2; text-align: auto; text-indent:
      0px; text-transform: none; white-space: normal; widows: 2;
      word-spacing: 0px; -webkit-border-horizontal-spacing: 0px;
      -webkit-border-vertical-spacing: 0px;
      -webkit-text-decorations-in-effect: none;
      -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;
      font-size: medium; "><span class="Apple-style-span"
        style="font-family: serif; font-size: 15px; line-height: 20px;
        white-space: pre-wrap; ">#!/usr/bin/python<br>
        <br>
        import pygst<br>
        pygst.require("0.10")<br>
        import gst<br>
        import gobject<br>
        import sys<br>
        from urllib import quote<br>
        from threading import Semaphore, Thread<br>
        FILE="/media/love/lossless/The Lovin' Spoonful/The Very Best
        Of/The Lovin' Spoonful - The Very Best Of.ape"<br>
        <br>
        sem = Semaphore(0)<br>
        eos = Semaphore(0)<br>
        state = None<br>
        def on_message(bus, message):<br>
        t = message.type<br>
        src = message.src.get_name()<br>
        global sem,eos, state<br>
        if src == 'pipeline' and t == gst.MESSAGE_STATE_CHANGED:<br>
        os,ns,pn = message.parse_state_changed()<br>
        if ns == state:<br>
        state = None<br>
        sem.release()<br>
        elif t == gst.MESSAGE_EOS:<br>
        print "eos"<br>
        eos.release()<br>
        elif t == gst.MESSAGE_ERROR:<br>
        print "Error"<br>
        eos.release()<br>
        sem.release()<br>
        sys.exit(1)<br>
        <br>
        def encode():<br>
        start = 3673626666666L<br>
        stop = 3785800000000L<br>
        pipeline = gst.element_factory_make("playbin", "pipeline")<br>
        pipeline.set_property("uri", '<a class="moz-txt-link-freetext" href="file://">file://</a>' + quote(FILE) )<br>
        fakesink = gst.element_factory_make("fakesink", "fakesink")<br>
        abin = gst.Bin()<br>
        <br>
        enc = gst.element_factory_make("flacenc", "encoder")<br>
        sink = gst.element_factory_make("filesink", "sink")<br>
        sink.set_property("location", "dest.flac")<br>
        <br>
        abin.add(enc, sink)<br>
        gst.element_link_many(enc, sink)<br>
        sinkpad = enc.get_static_pad("sink")<br>
        abin.add_pad(gst.GhostPad('sink', sinkpad))<br>
        <br>
        pipeline.set_property("audio-sink", abin)<br>
        pipeline.set_property("video-sink", fakesink)<br>
        <br>
        bus = pipeline.get_bus()<br>
        bus.add_signal_watch()<br>
        bus.connect("message", on_message)<br>
        <br>
        <br>
        global state, sem<br>
        state = gst.STATE_PAUSED<br>
        <br>
        pipeline.set_state(gst.STATE_NULL)<br>
        pipeline.set_state(gst.STATE_PAUSED)<br>
        sem.acquire()<br>
        print pipeline.seek(1.0, gst.Format(gst.FORMAT_TIME),
        gst.SEEK_FLAG_FLUSH, gst.SEEK_TYPE_SET, start,
        gst.SEEK_TYPE_SET, stop)<br>
        <br>
        pipeline.set_state(gst.STATE_PLAYING)<br>
        eos.acquire()<br>
        pipeline.set_state(gst.STATE_NULL)<br>
        loop.quit()<br>
        <br>
        gobject.threads_init()<br>
        loop = gobject.MainLoop()<br>
        Thread(target=encode).start()<br>
        loop.run()<br>
        <br>
      </span></span>
  </body>
</html>