[FFmpeg-user] How to change audio stream offset
Francois Visagie
francois.visagie at gmail.com
Fri Sep 6 14:57:23 CEST 2013
> -----Original Message-----
> From: ffmpeg-user-bounces at ffmpeg.org [mailto:ffmpeg-user-
> bounces at ffmpeg.org] On Behalf Of Carl Eugen Hoyos
> Sent: 06 September 2013 13:07
> To: ffmpeg-user at ffmpeg.org
> Subject: Re: [FFmpeg-user] How to change audio stream offset
>
> Francois Visagie <francois.visagie <at> gmail.com> writes:
>
> > I'm getting a few cases where only ffmpeg correctly understand the AV
> > sync in its mp4 output, in the sense that other applications play
> > audio too early wrt. video.
>
> Which applications?
MPC-HC 1.6.3.5818 and Windows Media Player 12.0.7601.17514 are the ones I've
tested so far along with ffplay. Both the former play the encode with the
same AV desync while ffplay plays with no desync. Remuxing with '-itsoffset'
does not seem to fix the offset problem.
This only happens with certain inputs. Most encodes are correctly understood
by all these players.
Here's a problem input sample (82 MB):
http://www.mediafire.com/download/0l70888haao0ir0/VTS_01_1.001.VOB
(Here's another problem input sample with which ffmpeg shows the same
behaviour (67 MB):
http://www.mediafire.com/download/p5ywp0aqwuuw6na/VTS_01_1.cut.VOB)
Here are the command lines and console output:
C:\Users\fvisagie\Videos\My DVDs\MainMovie\Neil Diamond Live at the
Greek\VIDEO_TS\SPLITS>ffmpeg -i VTS_01_1.001.VOB -filter:a
aformat=channel_layouts=stereo -p
reset ultrafast bbb.mp4
ffmpeg version N-55159-gf118b41 Copyright (c) 2000-2013 the FFmpeg
developers
built on Aug 1 2013 18:01:57 with gcc 4.7.3 (GCC)
configuration: --enable-gpl --enable-version3 --disable-w32threads
--enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r
--enable-gnutls --enab
le-iconv --enable-libass --enable-libbluray --enable-libcaca
--enable-libfreetype --enable-libgsm --enable-libilbc --enable-libmodplug
--enable-libmp3lame --ena
ble-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg
--enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr
--enable-libsp
eex --enable-libtheora --enable-libtwolame --enable-libvo-aacenc
--enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264
--enable-libxavs --
enable-libxvid --enable-zlib
libavutil 52. 40.100 / 52. 40.100
libavcodec 55. 19.100 / 55. 19.100
libavformat 55. 12.102 / 55. 12.102
libavdevice 55. 3.100 / 55. 3.100
libavfilter 3. 82.100 / 3. 82.100
libswscale 2. 4.100 / 2. 4.100
libswresample 0. 17.103 / 0. 17.103
libpostproc 52. 3.100 / 52. 3.100
Input #0, mpeg, from 'VTS_01_1.001.VOB':
Duration: 00:01:17.49, start: 0.060000, bitrate: 8867 kb/s
Stream #0:0[0x1bf]: Data: dvd_nav_packet
Stream #0:1[0x1e0]: Video: mpeg2video (Main), yuv420p, 720x480 [SAR 8:9
DAR 4:3], max. 7000 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc
Stream #0:2[0x8a]: Audio: dts (DTS), 48000 Hz, 5.1(side), fltp, 1536
kb/s
Stream #0:3[0x80]: Audio: ac3, 48000 Hz, stereo, fltp, 192 kb/s
[libx264 @ 03def400] using SAR=8/9
[libx264 @ 03def400] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 03def400] profile Constrained Baseline, level 3.0
[libx264 @ 03def400] 264 - core 135 r2345 f0c1c53 - H.264/MPEG-4 AVC codec -
Copyleft 2003-2013 - http://www.videolan.org/x264.html - options: cabac=0
ref=1 deb
lock=0:0:0 analyse=0:0 me=dia subme=0 psy=1 psy_rd=1.00:0.00 mixed_ref=0
me_range=16 chroma_me=1 trellis=0 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1
chroma_qp_
offset=0 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1
interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0
keyint=250 keyint_m
in=25 scenecut=0 intra_refresh=0 rc=crf mbtree=0 crf=23.0 qcomp=0.60 qpmin=0
qpmax=69 qpstep=4 ip_ratio=1.40 aq=0
Output #0, mp4, to 'bbb.mp4':
Metadata:
encoder : Lavf55.12.102
Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p,
720x480 [SAR 8:9 DAR 4:3], q=-1--1, 30k tbn, 29.97 tbc
Stream #0:1: Audio: aac (libvo_aacenc) ([64][0][0][0] / 0x0040), 48000
Hz, stereo, s16, 128 kb/s
Stream mapping:
Stream #0:1 -> #0:0 (mpeg2video -> libx264)
Stream #0:2 -> #0:1 (dca -> libvo_aacenc)
Press [q] to stop, [?] for help
[mpeg2video @ 023df600] warning: first frame is no keyframe
Last message repeated 1 times
[mpeg2video @ 023df600] ac-tex damaged at 2 20e=00:00:24.99
bitrate=4581.0kbits/s dup=8 drop=0
[mpeg2video @ 023df600] Warning MVs not available
[mpeg2video @ 023df600] concealing 45 DC, 45 AC, 45 MV errors in B frame
[dca @ 03deec40] ERROR: block code look-up failed0:00:31.39
bitrate=4007.6kbits/s dup=8 drop=0
[dca @ 03deec40] error decoding block
Error while decoding stream #0:2: Invalid data found when processing input
[mpeg2video @ 023df600] ac-tex damaged at 30 19=00:01:15.26
bitrate=2790.2kbits/s dup=8 drop=0
[mpeg2video @ 023df600] Warning MVs not available
[mpeg2video @ 023df600] concealing 495 DC, 495 AC, 495 MV errors in B frame
[dca @ 03deec40] Didn't get subframe DSYNC
[dca @ 03deec40] error decoding block
Error while decoding stream #0:2: Invalid data found when processing input
frame= 2344 fps=376 q=-1.0 Lsize= 26393kB time=00:01:18.21
bitrate=2764.5kbits/s dup=8 drop=0
video:25115kB audio:1212kB subtitle:0 global headers:0kB muxing overhead
0.252889%
[libx264 @ 03def400] frame I:10 Avg QP:20.90 size: 33999
[libx264 @ 03def400] frame P:2334 Avg QP:24.21 size: 10873
[libx264 @ 03def400] mb I I16..4: 100.0% 0.0% 0.0%
[libx264 @ 03def400] mb P I16..4: 8.2% 0.0% 0.0% P16..4: 52.0% 0.0%
0.0% 0.0% 0.0% skip:39.8%
[libx264 @ 03def400] coded y,uvDC,uvAC intra: 25.2% 47.1% 13.4% inter: 31.9%
26.4% 2.8%
[libx264 @ 03def400] i16 v,h,dc,p: 33% 35% 20% 12%
[libx264 @ 03def400] i8c dc,h,v,p: 39% 32% 20% 9%
[libx264 @ 03def400] kb/s:2630.53
(At this point ffplay plays bbb.mp4 in sync while both MPC-HC and Windows
Media Player play audio 650ms too early (from about 1m10s there's good
footage with which to match audio).)
C:\Users\fvisagie\Videos\My DVDs\MainMovie\Neil Diamond Live at the
Greek\VIDEO_TS\SPLITS>ffmpeg -i bbb.mp4 -itsoffset 0.650 -i bbb.mp4 -map 0:0
-map 1:1 -acode
c copy -vcodec copy ccc.mp4
ffmpeg version N-55159-gf118b41 Copyright (c) 2000-2013 the FFmpeg
developers
built on Aug 1 2013 18:01:57 with gcc 4.7.3 (GCC)
configuration: --enable-gpl --enable-version3 --disable-w32threads
--enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r
--enable-gnutls --enab
le-iconv --enable-libass --enable-libbluray --enable-libcaca
--enable-libfreetype --enable-libgsm --enable-libilbc --enable-libmodplug
--enable-libmp3lame --ena
ble-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg
--enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr
--enable-libsp
eex --enable-libtheora --enable-libtwolame --enable-libvo-aacenc
--enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264
--enable-libxavs --
enable-libxvid --enable-zlib
libavutil 52. 40.100 / 52. 40.100
libavcodec 55. 19.100 / 55. 19.100
libavformat 55. 12.102 / 55. 12.102
libavdevice 55. 3.100 / 55. 3.100
libavfilter 3. 82.100 / 3. 82.100
libswscale 2. 4.100 / 2. 4.100
libswresample 0. 17.103 / 0. 17.103
libpostproc 52. 3.100 / 52. 3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'bbb.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf55.12.102
Duration: 00:01:18.21, start: 0.000000, bitrate: 2764 kb/s
Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 /
0x31637661), yuv420p, 720x480 [SAR 8:9 DAR 4:3], 2630 kb/s, SAR 32:27 DAR
16:9, 29.97 fps, 29.9
7 tbr, 30k tbn, 59.94 tbc
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo,
fltp, 128 kb/s
Metadata:
handler_name : SoundHandler
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'bbb.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf55.12.102
Duration: 00:01:18.21, start: 0.000000, bitrate: 2764 kb/s
Stream #1:0(und): Video: h264 (Constrained Baseline) (avc1 /
0x31637661), yuv420p, 720x480 [SAR 8:9 DAR 4:3], 2630 kb/s, SAR 32:27 DAR
16:9, 29.97 fps, 29.9
7 tbr, 30k tbn, 59.94 tbc
Metadata:
handler_name : VideoHandler
Stream #1:1(und): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo,
fltp, 128 kb/s
Metadata:
handler_name : SoundHandler
Output #0, mp4, to 'ccc.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf55.12.102
Stream #0:0(und): Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 720x480
[SAR 32:27 DAR 16:9], q=2-31, 2630 kb/s, 29.97 fps, 30k tbn, 30k tbc
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac ([64][0][0][0] / 0x0040), 48000 Hz, stereo,
128 kb/s
Metadata:
handler_name : SoundHandler
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #1:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame= 2344 fps=0.0 q=-1.0 Lsize= 26393kB time=00:01:18.77
bitrate=2744.7kbits/s
video:25115kB audio:1212kB subtitle:0 global headers:0kB muxing overhead
0.251847%
Playback of ccc.mp4 is the same as that of bbb.mp4.
Adding '-async 1' to the original batch encode command line prevents this
behaviour. However, it also makes some encodes ~10% longer than their input
and normal encode lengths which causes subtitle desync in such cases.
Therefore at this point I'd rather continue without '-async 1' and manually
correct the occasional AV shift after the encode, but '-itsoffet' doesn't
work.
Any more suggestions for (relatively) quickly fixing an MP4 desync after the
encode?
More information about the ffmpeg-user
mailing list