[FFmpeg-user] confusion with "-vsync 1" / "-vsync cfr" and "-map" (to sync audio to video)
tracey jaquith
tracey at archive.org
Sun Jan 13 21:55:32 CET 2013
So I am coming to the conclusion that either:
(a) there is no way in fact to choose "sync video to audio, dupe/drop video as needed" vs "sync audio to video, dupe/drop audio as needed", with "-vsync 1" and "-map" options
(b) I am doing it wrong (the clueless phone is ringing and it's for me 8-)
I have an even shorter test case, both invocations here output an identical output file (full output below).
(i.e.: diff 0.ts 1.ts shows identical)
I wrote up a simple php cmd-line basic packets analysis bash function (using ffprobe) to show a bit of the A/V skew (in pts), #packets, in this source, etc.
function packets_stats ()
{
vid=${1:?"Usage: vi <video>"};
ffprobe -print_format compact -show_packets $vid 2> /dev/null | php -B '$stats=array("packetsA"=>0,"packetsV"=>0);' -R '
$pts=-666;
if (preg_match("/pts_time=([\d\.]+)/",$argn,$mat)){
$pts=$mat[1];
}
if (strpos($argn,"codec_type=v")){
$stats["packetsV"]++;
if ($pts!=-666) $stats["vpts"][]=$pts;
}
if (strpos($argn,"codec_type=a")){
$stats["packetsA"]++;
if ($pts!=-666) $stats["apts"][]=$pts;
}' -E '
$stats["ptsMinA"]=min($stats["apts"]);
$stats["ptsMaxA"]=max($stats["apts"]);
$stats["ptsMinV"]=min($stats["vpts"]);
$stats["ptsMaxV"]=max($stats["vpts"]);
$stats["vpts"]=join(", ",$stats["vpts"]);
$stats["apts"]=join(", ",$stats["apts"]);
print_r($stats);'
}
packets_stats tv.ts
Array
(
[packetsA] => 48
[packetsV] => 47
[vpts] => 92.602111, 92.635478, 92.735578, 92.702211, 92.835678, 92.768944, 92.802311, 92.935778, 92.869044, 92.902411, 93.002511, 92.969144, 93.035878, 93.135978, 93.069244, 93.102611, 93.236078, 93.169344, 93.202711, 93.336178, 93.269444, 93.302811, 93.436278, 93.369544, 93.402911, 93.503011, 93.469644, 93.603111, 93.536378, 93.569744, 93.703211, 93.636478, 93.669844, 93.803311, 93.736578, 93.769944, 93.903411, 93.836678, 93.870044, 94.003511, 93.936778, 93.970144, 94.103611, 94.036878, 94.070244, 94.203711
[apts] => 92.072000, 92.104000, 92.136000, 92.168000, 92.200000, 92.232000, 92.264000, 92.296000, 92.328000, 92.360000, 92.392000, 92.424000, 92.456000, 92.488000, 92.520000, 92.552000, 92.584000, 92.616000, 92.648000, 92.680000, 92.712000, 92.744000, 92.776000, 92.808000, 92.840000, 92.872000, 92.904000, 92.936000, 92.968000, 93.000000, 93.032000, 93.064000, 93.096000, 93.128000, 93.160000, 93.192000, 93.224000, 93.256000, 93.288000, 93.320000, 93.352000, 93.384000, 93.416000, 93.448000, 93.480000, 93.512000, 93.544000, 92.072000
[ptsMinA] => 92.072000
[ptsMaxA] => 93.544000
[ptsMinV] => 92.602111
[ptsMaxV] => 94.203711
)
audio and video streams are "off" by about .6 seconds (minA, minV) in source
packets_stats 0.ts
Array
(
[packetsA] => 63
[packetsV] => 65
[vpts] => 1.400000, 1.433367, 1.466733, 1.500100, 1.533467, 1.566833, 1.600200, 1.633567, 1.666933, 1.700300, 1.733667, 1.767033, 1.800400, 1.833767, 1.867133, 1.900500, 1.933867, 1.967233, 2.000600, 2.033967, 2.067333, 2.100700, 2.134067, 2.167433, 2.200800, 2.234167, 2.267533, 2.300900, 2.334267, 2.367633, 2.401000, 2.434367, 2.467733, 2.501100, 2.534467, 2.567833, 2.601200, 2.634567, 2.667933, 2.701300, 2.734667, 2.768033, 2.801400, 2.834767, 2.868133, 2.901500, 2.934867, 2.968233, 3.001600, 3.034967, 3.068333, 3.101700, 3.135067, 3.168433, 3.201800, 3.235167, 3.268533, 3.301900, 3.335267, 3.368633, 3.402000, 3.435367, 3.468733, 3.502100, 3.535467
[apts] => 1.421978, 1.445978, 1.469978, 1.493978, 1.517978, 1.541978, 1.565978, 1.557978, 1.581978, 1.605978, 1.629978, 1.653978, 1.677978, 1.701978, 1.725978, 1.749978, 1.773978, 1.797978, 1.821978, 1.845978, 1.869978, 1.893978, 1.917978, 1.941978, 1.965978, 1.989978, 2.013978, 2.037978, 2.061978, 2.085978, 2.109978, 2.133978, 2.157978, 2.181978, 2.205978, 2.229978, 2.253978, 2.277978, 2.301978, 2.325978, 2.349978, 2.373978, 2.397978, 2.421978, 2.445978, 2.469978, 2.493978, 2.517978, 2.541978, 2.565978, 2.589978, 2.613978, 2.637978, 2.661978, 2.685978, 2.709978, 2.733978, 2.757978, 2.781978, 2.805978, 2.829978, 2.853978, 2.877978
[ptsMinA] => 1.421978
[ptsMaxA] => 2.877978
[ptsMinV] => 1.400000
[ptsMaxV] => 3.535467
)
audio and video streams are nearly aligned (dupes 25 video frames/packets below, as I understand it)
I would have assumed if it were possible(/I did it properly) to use "-vsync 1" with a "sync_file_id:stream_specifier"
in the "-map" option, and was able to say sync audio to video, that it would instead
drop some number of audio packets, instead of duping video packets, etc.
thanks again for any tips, advice, shoes sailing overhead, etc.!
ffmpeg -y -i http://archive.org/~tracey/_/tv-a-change/tv.ts -vsync 1 -map 0:0,0:1 -map 0:1,0:1 1.ts;
ffmpeg version N-47856-g51fcf27 Copyright (c) 2000-2012 the FFmpeg developers
built on Dec 15 2012 07:01:55 with gcc 4.7 (Ubuntu/Linaro 4.7.2-2ubuntu1)
configuration: --disable-shared --disable-ffserver --disable-vdpau --enable-avfilter --enable-gpl --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libtheora --enable-libvorbis --enable-libxvid --enable-nonfree --enable-postproc --enable-pthreads --enable-static --enable-ffplay --enable-libvpx --enable-libx264 --enable-version3 --extra-cflags=-I/tmp/f/usr/local/include --extra-ldflags=-L/tmp/f/usr/local/lib --extra-cflags=-static --prefix=/usr --enable-libfreetype --enable-libgsm --enable-libspeex --extra-ldflags=-static
libavutil 52. 12.100 / 52. 12.100
libavcodec 54. 79.102 / 54. 79.102
libavformat 54. 49.102 / 54. 49.102
libavdevice 54. 3.102 / 54. 3.102
libavfilter 3. 27.101 / 3. 27.101
libswscale 2. 1.103 / 2. 1.103
libswresample 0. 17.102 / 0. 17.102
libpostproc 52. 2.100 / 52. 2.100
[mpeg2video @ 0x39d0d80] mpeg_decode_postinit() failure
Last message repeated 3 times
Truncating packet of size 2041 to 1178
Last message repeated 1 times
Input #0, mpeg, from 'http://archive.org/~tracey/_/tv/tv.ts':
Duration: 00:00:02.13, start: 92.072000, bitrate: 7505 kb/s
Stream #0:0[0x1e0]: Video: mpeg2video (Main), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc
Stream #0:1[0x80]: Audio: ac3, 48000 Hz, stereo, fltp, 192 kb/s
Output #0, mpegts, to '1.ts':
Metadata:
encoder : Lavf54.49.102
Stream #0:0: Video: mpeg2video, yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 90k tbn, 29.97 tbc
Stream #0:1: Audio: mp2, 48000 Hz, stereo, s16, 128 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (mpeg2video -> mpeg2video)
Stream #0:1 -> #0:1 (ac3 -> mp2)
Press [q] to stop, [?] for help
[ac3 @ 0x39d1ac0] frame sync error
Error while decoding stream #0:1: Operation not permitted
[mpegts @ 0x39d1f40] st:0 PTS: 7738 DTS: 7738 < 8459 invalid, clipping
Truncating packet of size 2041 to 117851kB time=00:00:01.50 bitrate=1916.2kbits/s dup=23 drop=0
[mpeg2video @ 0x39d0d80] ac-tex damaged at 32 39
[mpeg2video @ 0x39d0d80] Warning MVs not available
[mpeg2video @ 0x39d0d80] concealing 3480 DC, 3480 AC, 3480 MV errors in P frame
[ac3 @ 0x39d1ac0] incomplete frame
frame= 65 fps=0.0 q=31.0 Lsize= 780kB time=00:00:02.13 bitrate=2992.6kbits/s dup=25 drop=0
video:692kB audio:24kB subtitle:0 global headers:0kB muxing overhead 9.072786%
ffmpeg -y -i http://archive.org/~tracey/_/tv-a-change/tv.ts -vsync 1 -map 0:0,0:0 -map 0:1,0:0 0.ts;
ffmpeg version N-47856-g51fcf27 Copyright (c) 2000-2012 the FFmpeg developers
built on Dec 15 2012 07:01:55 with gcc 4.7 (Ubuntu/Linaro 4.7.2-2ubuntu1)
configuration: --disable-shared --disable-ffserver --disable-vdpau --enable-avfilter --enable-gpl --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libtheora --enable-libvorbis --enable-libxvid --enable-nonfree --enable-postproc --enable-pthreads --enable-static --enable-ffplay --enable-libvpx --enable-libx264 --enable-version3 --extra-cflags=-I/tmp/f/usr/local/include --extra-ldflags=-L/tmp/f/usr/local/lib --extra-cflags=-static --prefix=/usr --enable-libfreetype --enable-libgsm --enable-libspeex --extra-ldflags=-static
libavutil 52. 12.100 / 52. 12.100
libavcodec 54. 79.102 / 54. 79.102
libavformat 54. 49.102 / 54. 49.102
libavdevice 54. 3.102 / 54. 3.102
libavfilter 3. 27.101 / 3. 27.101
libswscale 2. 1.103 / 2. 1.103
libswresample 0. 17.102 / 0. 17.102
libpostproc 52. 2.100 / 52. 2.100
[mpeg2video @ 0x28efd80] mpeg_decode_postinit() failure
Last message repeated 3 times
Truncating packet of size 2041 to 1178
Last message repeated 1 times
Input #0, mpeg, from 'http://archive.org/~tracey/_/tv/tv.ts':
Duration: 00:00:02.13, start: 92.072000, bitrate: 7505 kb/s
Stream #0:0[0x1e0]: Video: mpeg2video (Main), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc
Stream #0:1[0x80]: Audio: ac3, 48000 Hz, stereo, fltp, 192 kb/s
Output #0, mpegts, to '0.ts':
Metadata:
encoder : Lavf54.49.102
Stream #0:0: Video: mpeg2video, yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 90k tbn, 29.97 tbc
Stream #0:1: Audio: mp2, 48000 Hz, stereo, s16, 128 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (mpeg2video -> mpeg2video)
Stream #0:1 -> #0:1 (ac3 -> mp2)
Press [q] to stop, [?] for help
[ac3 @ 0x28f0ac0] frame sync error
Error while decoding stream #0:1: Operation not permitted
[mpegts @ 0x28f0f40] st:0 PTS: 7738 DTS: 7738 < 8459 invalid, clipping
Truncating packet of size 2041 to 117858kB time=00:00:01.56 bitrate=1868.2kbits/s dup=23 drop=0
[mpeg2video @ 0x28efd80] ac-tex damaged at 32 39
[mpeg2video @ 0x28efd80] Warning MVs not available
[mpeg2video @ 0x28efd80] concealing 3480 DC, 3480 AC, 3480 MV errors in P frame
[ac3 @ 0x28f0ac0] incomplete frame
frame= 65 fps=0.0 q=31.0 Lsize= 780kB time=00:00:02.13 bitrate=2992.6kbits/s dup=25 drop=0
video:692kB audio:24kB subtitle:0 global headers:0kB muxing overhead 9.072786%
On Jan 11, 2013, at 5:22 PM, Carl Eugen Hoyos <cehoyos at ag.or.at> wrote:
> Tracey Jaquith <tracey <at> archive.org> writes:
>
>> Did "-vsync" in my command line make a difference?
>> Absolutely!
>
> Yes, I thought -vsync is an input option, but as you
> showed, it is not.
>
> Carl Eugen
>
> _______________________________________________
> ffmpeg-user mailing list
> ffmpeg-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
More information about the ffmpeg-user
mailing list