6

I have built a segmenter that takes as input a h264 / AAC video and segments according to the HLS specification. The source code for it can be seen here: https://gist.github.com/cpnielsen/f36729c371aac0fe535d

It is implemented as a python extension, but the interesting parts are in the process_video() function. It makes use of the libav library (alternatively ffmpeg) to do the heavy lifting.

It works 95% of the time, but we have come upon some videos where it produces segments with audio out of sync. If I was using the command-line tool, I could simply add -async 1 to fix it, but how do I implement the same functionality in my C code?

I found a snippet of code in avconv_filter.c (for libav, not sure what the ffmpeg equivalent is) where they initiate the filter, but without any documentation it is hard to figure out how to do this outside the whole modular setup.

I just need to:

  1. Initiate the correct filter
  2. Apply it to the input (or output? not sure)
  3. Know of any pitfalls when using the filter.

Any help is welcome; sample code, explanation of the filter, etc.

Christian P.
  • 4,784
  • 7
  • 53
  • 70
  • Do you mean `asynchts` in the `libav` command line tool `avconv`? – Gene Sep 28 '13 at 21:43
  • Did you take a look into `ffmpeg.c` searching for the flag `audio_sync_method`? – alk Sep 29 '13 at 11:16
  • Gene: Yes, that would be the name. alk: I haven't yet, but reading through some of the samples in ffmpeg it's not (to me) super obvious how to apply these filters in my code (see file) – Christian P. Sep 30 '13 at 08:00
  • It's less then 40 lines of relevant code (in `ffmpeg.c`) which is involved if `ffmpeg` is called with the option `-async 1`. It is not "*super obvious*" to me either, but this might due to haven't hacked around in FFmpeg's sourcess for over 4 years now. But as you seem to be just at it, I'm sure you'll make it!-) However is does not look like `-async 1` does apply a seperate filter. – alk Sep 30 '13 at 09:44
  • The issue is, that to understand the bits and pieces of the input filters you have to understand most of the flow. The functions are defined in one place, the commandline parameters defined in another and the actual application of filters done in a third place. That's why I am looking for someone who can explain it without the entanglement of the ffmpeg.c command-line program code. – Christian P. Sep 30 '13 at 11:37
  • FFmpeg already has [HLS](http://ffmpeg.org/ffmpeg-formats.html#hls) and [segment](http://ffmpeg.org/ffmpeg-formats.html#segment) muxers. Why write your own? – llogan Mar 25 '14 at 17:50
  • @LordNeckbeard: They only offer an all-or-nothing approach, we wish to be able to do "give me segment 3-5 and 9-15" on-the-fly without having all the segments made in advance (to save disk space primarily). – Christian P. Mar 26 '14 at 12:06

0 Answers0