[FFmpeg-user] Sync troubles with input pipes from raw -> AAC/Scaling/H.264 -> live RTMP

Heinrich Fink heinrich.fink at hfink.eu
Wed Apr 3 15:53:08 CEST 2013


Hi, 

thanks for taking time to comment on this.

Carl Eugen Hoyos <cehoyos at ag.or.at> wrote:

> Heinrich Fink <heinrich.fink <at> hfink.eu> writes:
> 
>> I have troubles with A/V sync for a live RTMP output stream 
>> generated by ffmpeg.
> 
> Is your problem only reproducible with rtmp output or also if 
> you output to a (flv) file?

It is also reproducible with other output types / output format types (see below).

> 
>> However, unfortunately A/V seems to drift after running 
>> for a couple of hours.
> 
> (I wrote the above before reading this sentence.)
> Could this be a problem with the framerate?
> Ie, are you missing a “000/1001" somewhere?

My test case uses 25p only, so this shouldn’t be an issue.

> 
>> Here’s the full command:
> 
> It is unfortunately missing the complete, uncut console 
> output that is always needed if you want support on this 
> mailing list.

sorry for that, my new test case (using flv1 as you suggested) includes now both the command the console output.

> Generally, if your problem is reproducible without external 
> libraries (libx264), you should not use them as not using 
> them often makes reproducing the problem easier.
> (Is it reproducible with -vcodec flv1 ?)

yes, it is. I ran a test for about 3 hours, recording into a flv file, and I was able to observe a A/V shift of 4 frames.

Here is the command: 

./ffmpeg \
   -nostdin \
   -vsync cfr \
   -c:v rawvideo\
   -top:v 1 \
   -video_size 1920x1080 \
   -pixel_format yuv420p \
   -f rawvideo \
   -fflags nobuffer \
   -i /tmp/pipevideo \
   -c:a pcm_s16le \
   -ac 2 \
   -ar 48000 \
   -f s16le \
   -fflags nobuffer \
   -analyzeduration 0 \
   -i /tmp/pipeaudio \
   -c:v flv1 \
   -map 0:0,1:0 \
   -map 1:0 \
   -loglevel debug \
   -vf "yadif=0:-1:0, scale=640:360" \
   -af "aresample=async=1" \
   -strict -2 \
   -acodec aac \
   -ab 192000 \
   -ac 2 \
   -ar 48000 \
   -r 25 \
   -fflags nobuffer \
   -y \
   -f flv capture.flv

and here is the uncut console output of the full test session:

## CONSOLE OUTPUT BEGIN ##

ffmpeg version 1.2 Copyright (c) 2000-2013 the FFmpeg developers
  built on Mar 15 2013 18:24:17 with llvm-gcc 4.2.1 (LLVM build 2336.11.00)
  configuration: --prefix=/Volumes/Ramdisk/sw --enable-gpl --enable-pthreads --enable-version3 --enable-libspeex --enable-libvpx --disable-decoder=libvpx --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libx264 --enable-avfilter --enable-libopencore_amrwb --enable-libopencore_amrnb --enable-filters --enable-libgsm --arch=x86_64 --enable-runtime-cpudetect
  libavutil      52. 18.100 / 52. 18.100
  libavcodec     54. 92.100 / 54. 92.100
  libavformat    54. 63.104 / 54. 63.104
  libavdevice    54.  3.103 / 54.  3.103
  libavfilter     3. 42.103 /  3. 42.103
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
Splitting the commandline.
Reading option '-nostdin' ... matched as option 'stdin' (enable or disable interaction on standard input) with argument 0.
Reading option '-vsync' ... matched as option 'vsync' (video sync method) with argument 'cfr'.
Reading option '-c:v' ... matched as option 'c' (codec name) with argument 'rawvideo'.
Reading option '-top:v' ... matched as option 'top' (top=1/bottom=0/auto=-1 field first) with argument '1'.
Reading option '-video_size' ... matched as AVOption 'video_size' with argument '1920x1080'.
Reading option '-pixel_format' ... matched as AVOption 'pixel_format' with argument 'yuv420p'.
Reading option '-f' ... matched as option 'f' (force format) with argument 'rawvideo'.
Reading option '-fflags' ... matched as AVOption 'fflags' with argument 'nobuffer'.
Reading option '-i' ... matched as input file with argument '/tmp/pipevideo'.
Reading option '-c:a' ... matched as option 'c' (codec name) with argument 'pcm_s16le'.
Reading option '-ac' ... matched as option 'ac' (set number of audio channels) with argument '2'.
Reading option '-ar' ... matched as option 'ar' (set audio sampling rate (in Hz)) with argument '48000'.
Reading option '-f' ... matched as option 'f' (force format) with argument 's16le'.
Reading option '-fflags' ... matched as AVOption 'fflags' with argument 'nobuffer'.
Reading option '-analyzeduration' ... matched as AVOption 'analyzeduration' with argument '0'.
Reading option '-i' ... matched as input file with argument '/tmp/pipeaudio'.
Reading option '-c:v' ... matched as option 'c' (codec name) with argument 'flv1'.
Reading option '-map' ... matched as option 'map' (set input stream mapping) with argument '0:0,1:0'.
Reading option '-map' ... matched as option 'map' (set input stream mapping) with argument '1:0'.
Reading option '-loglevel' ... matched as option 'loglevel' (set libav* logging level) with argument 'debug'.
Reading option '-vf' ... matched as option 'vf' (set video filters) with argument 'yadif=0:-1:0, scale=640:360'.
Reading option '-af' ... matched as option 'af' (set audio filters) with argument 'aresample=async=1'.
Reading option '-strict' ... matched as AVOption 'strict' with argument '-2'.
Reading option '-acodec' ... matched as option 'acodec' (force audio codec ('copy' to copy stream)) with argument 'aac'.
Reading option '-ab' ... matched as AVOption 'ab' with argument '192000'.
Reading option '-ac' ... matched as option 'ac' (set number of audio channels) with argument '2'.
Reading option '-ar' ... matched as option 'ar' (set audio sampling rate (in Hz)) with argument '48000'.
Reading option '-r' ... matched as option 'r' (set frame rate (Hz value, fraction or abbreviation)) with argument '25'.
Reading option '-fflags' ... matched as AVOption 'fflags' with argument 'nobuffer'.
Reading option '-y' ... matched as option 'y' (overwrite output files) with argument '1'.
Reading option '-f' ... matched as option 'f' (force format) with argument 'flv'.
Reading option 'capture.flv' ... matched as output file.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option nostdin (enable or disable interaction on standard input) with argument 0.
Applying option vsync (video sync method) with argument cfr.
Applying option loglevel (set libav* logging level) with argument debug.
Applying option y (overwrite output files) with argument 1.
Successfully parsed a group of options.
Parsing a group of options: input file /tmp/pipevideo.
Applying option c:v (codec name) with argument rawvideo.
Applying option top:v (top=1/bottom=0/auto=-1 field first) with argument 1.
Applying option f (force format) with argument rawvideo.
Successfully parsed a group of options.
Opening an input file: /tmp/pipevideo.
[rawvideo @ 0x7f9fea020200] File position before avformat_find_stream_info() is 0
[rawvideo @ 0x7f9fea020200] All info found
[rawvideo @ 0x7f9fea020200] Estimating duration from bitrate, this may be inaccurate
[rawvideo @ 0x7f9fea020200] File position after avformat_find_stream_info() is 3110400
Input #0, rawvideo, from '/tmp/pipevideo':
  Duration: N/A, start: 0.000000, bitrate: 622080 kb/s
    Stream #0:0, 1, 1/25: Video: rawvideo (I420 / 0x30323449), yuv420p, 1920x1080, 1/25, 622080 kb/s, 25 tbr, 25 tbn, 25 tbc
Successfully opened the file.
Parsing a group of options: input file /tmp/pipeaudio.
Applying option c:a (codec name) with argument pcm_s16le.
Applying option ac (set number of audio channels) with argument 2.
Applying option ar (set audio sampling rate (in Hz)) with argument 48000.
Applying option f (force format) with argument s16le.
Successfully parsed a group of options.
Opening an input file: /tmp/pipeaudio.
[s16le @ 0x7f9fea029600] File position before avformat_find_stream_info() is 0
[s16le @ 0x7f9fea029600] max_analyze_duration 0 reached at 0 microseconds
[s16le @ 0x7f9fea029600] Estimating duration from bitrate, this may be inaccurate
[s16le @ 0x7f9fea029600] File position after avformat_find_stream_info() is 12288
Guessed Channel Layout for  Input Stream #1.0 : stereo
Input #1, s16le, from '/tmp/pipeaudio':
  Duration: N/A, bitrate: 1536 kb/s
    Stream #1:0, 2, 1/48000: Audio: pcm_s16le, 48000 Hz, stereo, s16, 1536 kb/s
Successfully opened the file.
Parsing a group of options: output file capture.flv.
Applying option c:v (codec name) with argument flv1.
Applying option map (set input stream mapping) with argument 0:0,1:0.
Applying option map (set input stream mapping) with argument 1:0.
Applying option vf (set video filters) with argument yadif=0:-1:0, scale=640:360.
Applying option af (set audio filters) with argument aresample=async=1.
Applying option acodec (force audio codec ('copy' to copy stream)) with argument aac.
Applying option ac (set number of audio channels) with argument 2.
Applying option ar (set audio sampling rate (in Hz)) with argument 48000.
Applying option r (set frame rate (Hz value, fraction or abbreviation)) with argument 25.
Applying option f (force format) with argument flv.
Successfully parsed a group of options.
Opening an output file: capture.flv.
Matched encoder 'flv' for codec 'flv1'.
Successfully opened the file.
[yadif @ 0x7f9fe9c03880] Setting 'mode' to value '0'
[yadif @ 0x7f9fe9c03880] Setting 'parity' to value '-1'
[yadif @ 0x7f9fe9c03880] Setting 'deint' to value '0'
[Parsed_yadif_0 @ 0x7f9fe9c04240] mode:0 parity:-1 deint:0
[scale @ 0x7f9fe9c03c40] Setting 'w' to value '640'
[scale @ 0x7f9fe9c03c40] Setting 'h' to value '360'
[scale @ 0x7f9fe9c03c40] Setting 'flags' to value '0x4'
[Parsed_scale_1 @ 0x7f9fe9c03be0] w:640 h:360 flags:'0x4' interl:0
[buffer @ 0x7f9fe9c03f80] Setting entry with key 'video_size' to value '1920x1080'
[buffer @ 0x7f9fe9c03f80] Setting entry with key 'pix_fmt' to value '0'
[buffer @ 0x7f9fe9c03f80] Setting entry with key 'time_base' to value '1/25'
[buffer @ 0x7f9fe9c03f80] Setting entry with key 'pixel_aspect' to value '0/1'
[buffer @ 0x7f9fe9c03f80] Setting entry with key 'sws_param' to value 'flags=2'
[buffer @ 0x7f9fe9c03f80] Setting entry with key 'frame_rate' to value '25/1'
[graph 0 input from stream 0:0 @ 0x7f9fe9c04060] w:1920 h:1080 pixfmt:yuv420p tb:1/25 fr:25/1 sar:0/1 sws_param:flags=2
[Parsed_scale_1 @ 0x7f9fe9c03be0] w:1920 h:1080 fmt:yuv420p sar:0/1 -> w:640 h:360 fmt:yuv420p sar:0/1 flags:0x4
[abuffer @ 0x7f9fe9c08220] Setting entry with key 'time_base' to value '1/48000'
[abuffer @ 0x7f9fe9c08220] Setting entry with key 'sample_rate' to value '48000'
[abuffer @ 0x7f9fe9c08220] Setting entry with key 'sample_fmt' to value 's16'
[abuffer @ 0x7f9fe9c08220] Setting entry with key 'channel_layout' to value '0x3'
[graph 1 input from stream 1:0 @ 0x7f9fe9c08160] tb:1/48000 samplefmt:s16 samplerate:48000 chlayout:0x3
[aformat @ 0x7f9fe9c087a0] Setting entry with key 'sample_fmts' to value 'fltp'
[aformat @ 0x7f9fe9c087a0] Setting entry with key 'sample_rates' to value '48000'
[aformat @ 0x7f9fe9c087a0] Setting entry with key 'channel_layouts' to value '0x3'
[Parsed_aresample_0 @ 0x7f9fe9c06f20] ch:2 chl:stereo fmt:s16 r:48000Hz -> ch:2 chl:stereo fmt:fltp r:48000Hz
[flv @ 0x7f9fea03b400] intra_quant_bias = 0 inter_quant_bias = -64
Output #0, flv, to 'capture.flv':
  Metadata:
    encoder         : Lavf54.63.104
    Stream #0:0, 0, 1/1000: Video: flv1 ([2][0][0][0] / 0x0002), yuv420p, 640x360, 1/25, q=2-31, 200 kb/s, 1k tbn, 25 tbc
    Stream #0:1, 0, 1/1000: Audio: aac ([10][0][0][0] / 0x000A), 48000 Hz, stereo, fltp, 192 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo -> flv)
  Stream #1:0 -> #0:1 (pcm_s16le -> aac)
*** 1 dup!
EOF on sink link output stream 0:0:default. time=03:09:12.68 bitrate= 559.1kbits/s dup=1 drop=0    
[output stream 0:1 @ 0x7f9fe9c084e0] EOF on sink link output stream 0:1:default.
No more output streams to write to, finishing.
[aac @ 0x7f9fea03ee00] Trying to remove 768 more samples than there are in the queue
frame=283826 fps= 25 q=31.0 Lsize=  774856kB time=03:09:13.04 bitrate= 559.1kbits/s dup=1 drop=0    
video:540535kB audio:221051kB subtitle:0 global headers:0kB muxing overhead 1.742400%
Statistics: 882812390400 bytes read, 0 seeks
[AVIOContext @ 0x7f9fe9c04c20] Statistics: 2179752960 bytes read, 0 seeks

## CONSOLE OUTPUT END ##

I would appreciate any comments on this.

many thanks, 

Heinrich



More information about the ffmpeg-user mailing list