[theora] example_encoder.c patch to read successfully from FIFOs
Mike Baynton
mike at mbaynton.com
Sat Oct 5 18:41:49 PDT 2013
Hello,
Some years back I tried to use example_encoder.c with mkfifo FIFO
buffers to encode content as it was being decoded by mplayer. This
deadlocks, because to do this you need two FIFOs (one for decompressed
audio and one for video) that mplayer alternates writing output to, and
that encoder_example similarly alternates reading chunks of audio and
video input from. The trouble is, mplayer will fill one of the two
buffers (say the video FIFO) and still have more to write to that buffer
before alternating back to the other one (audio), but encoder_example
will remain in the "reading from the audio input" part of its code,
blocking on a read from the empty audio buffer, and so will not empty
any data from the full video buffer until it receives a bit more audio
input.
This seems like a useful thing to support, as the alternative of first
dumping complete raw a/v to files on disk and then consuming them with
encoder_example requires massive disk i/o and space, and does not allow
decode and encode to run in parallel. Looks like other people have tried
it in the distant past as well:
- http://lists.xiph.org/pipermail/theora/2003-February/000335.html
- http://lists.xiph.org/pipermail/theora-dev/2002-September/001308.html
At the time, I patched encoder_example to basically replace all freads
to instead read from dynamically allocated internal memory buffers,
which in turn read from fread, but would automatically cut over to and
buffer data some data from the other stream when one stream became
empty. I was then able to encode on-the-fly with encoder_example
successfully. This was in 2006; I just looked and there have been
substantial changes to encoder_example.c since then, but none that fix
this issue. So, I am writing to the mailing list to see if there would
be interest in incorporating an updated patch if I were to take the time
to sync and test it with the current code. I'm not sure if this would be
seen as beyond the scope of an example encoder...but I personally think
it'd be quite useful.
Thanks!
Mike Baynton
More information about the theora
mailing list