So I have a handful of old mpeg2 (.mpg
) files with the following profiles as provided by ffmpeg (the timecodes on each are different):
Stream #0:0(eng): Video: mpeg4 (Advanced Simple Profile) (mp4v / 0x7634706D), yuv420p, 640x480 [SAR 1:1 DAR 4:3], 1385 kb/s, 29.88 fps, 29.97 tbr, 2997 tbn, 1k tbc (default)
Metadata:
creation_time : 2006-XX-XX XX:XX:XX
handler_name : Apple Alias Data Handler
encoder : MPEG-4 Video
timecode : 00:00:08;07
Stream #0:1(eng): Data: none (tmcd / 0x64636D74)
Metadata:
creation_time : 2006-XX-XX XX:XX:XX
handler_name : Apple Alias Data Handler
timecode : 00:00:08;07
Stream #0:2(eng): Audio: pcm_s16be (twos / 0x736F7774), 48000 Hz, 2 channels, s16, 1536 kb/s (default)
Metadata:
creation_time : 2006-XX-XX XX:XX:XX
handler_name : Apple Alias Data Handler
it appears that for each of them in playback (using mplayer and vlc) the first frame will be frozen for about 8 seconds while the audio starts from 00:00:00. So the audio remains about 8 seconds ahead of the video stream throughout.
When I try to convert them with FFmpeg, copying the video and audio codecs, I get a ton of "buffer underflow" and "packet too large" errors (which probably has to do with the codec etc. as per: https://superuser.com/questions/835871/how-to-make-an-mpeg2-video-file-with-the-highest-quality-possible-using-ffmpeg). If I convert it to another video and audio codec, it's fine - no buffer underflow/packet too large errors. But the audio remains out of sync with the video.
I have also tried passing the ffmpeg conversion -itsoffset -8.0
to the input file and the audio is still out of sync, even though the video then does appear to advance from 00:00:00 in playback for the converted file.
Not sure if there is anything else I can do about this but I am wondering if it's possible to get this audio and video synced. I have also tried mencoder with -mc 0
, -noskip
and -vf harddup
options and that actually syncs the video for the first portion, but then the audio and video fall out of sync after about 30 minutes or so in.
Update - some input and output details:
ffmpeg -threads 1 -itsoffset -8.0 -i in.mpg -f mp4 -g 60 -c:v libx264 -pix_fmt yuvj420p -c:a libfdk_aac -y out.mp4
ffmpeg version 2.7.2 Copyright (c) 2000-2015 the FFmpeg developers
built with gcc 4.8.5 (Gentoo 4.8.5 p1.3, pie-0.6.2)
configuration: --prefix=/usr --libdir=/usr/lib64 --shlibdir=/usr/lib64 --mandir=/usr/share/man --enable-shared -- cc=x86_64-pc-linux-gnu-gcc --cxx=x86_64-pc-linux-gnu-g++ --ar=x86_64-pc-linux-gnu-ar --optflags=' ' --disable- static --enable-avfilter --enable-avresample --disable-stripping --enable-version3 --disable-indev=v4l2 --disable -outdev=v4l2 --disable-indev=oss --disable-indev=jack --disable-outdev=oss --disable-outdev=sdl --enable-nonfree --enable-bzlib --disable-runtime-cpudetect --disable-debug --disable-doc --disable-gnutls --enable-gpl --enable- hardcoded-tables --enable-iconv --disable-lzma --enable-network --disable-openssl --enable-postproc --disable- libsmbclient --disable-ffplay --disable-vaapi --disable-vdpau --enable-xlib --disable-libxcb --disable-libxcb- shm --disable-libxcb-xfixes --enable-zlib --disable-libcdio --disable-libiec61883 --disable-libdc1394 --disable- libcaca --disable-openal --disable-opengl --disable-libv4l2 --disable-libpulse --disable-libopencore-amrwb -- disable-libopencore-amrnb --enable-libfdk-aac --disable-libopenjpeg --disable-libbluray --disable-libcelt -- disable-libgme --disable-libgsm --disable-libmodplug --disable-libopus --disable-libquvi --disable-librtmp -- disable-libssh --disable-libschroedinger --disable-libspeex --disable-libvorbis --enable-libvpx --disable- libzvbi --disable-libbs2b --disable-libflite --disable-frei0r --disable-libfribidi --disable-fontconfig --disable -ladspa --disable-libass --disable-libfreetype --disable-libsoxr --enable-pthreads --enable-libvo-aacenc -- disable-libvo-amrwbenc --enable-libmp3lame --disable-libaacplus --disable-libfaac --disable-libtheora --disable- libtwolame --disable-libwavpack --disable-libwebp --enable-libx264 --disable-libx265 --disable-libxvid --enable- x11grab --disable-amd3dnow --disable-amd3dnowext --disable-fma4 --disable-xop --cpu=core-avx-i
libavutil 54. 27.100 / 54. 27.100
libavcodec 56. 41.100 / 56. 41.100
libavformat 56. 36.100 / 56. 36.100
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 16.101 / 5. 16.101
libavresample 2. 1. 0 / 2. 1. 0
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 2.100 / 1. 2.100
libpostproc 53. 3.100 / 53. 3.100
Guessed Channel Layout for Input Stream #0.2 : stereo
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'in.mpg':
Metadata:
major_brand : qt
minor_version : 537199360
compatible_brands: qt
creation_time : 2006-XX-XX XX:XX:XX
Duration: 01:00:19.88, start: 0.000000, bitrate: 2940 kb/s
Stream #0:0(eng): Video: mpeg4 (Advanced Simple Profile) (mp4v / 0x7634706D), yuv420p, 640x480 [SAR 1:1 DAR 4:3], 1385 kb/s, 29.88 fps, 29.97 tbr, 2997 tbn, 1k tbc (default)
Metadata:
creation_time : 2006-XX-XX XX:XX:XX
handler_name : Apple Alias Data Handler
encoder : MPEG-4 Video
timecode : 00:00:08;07
Stream #0:1(eng): Data: none (tmcd / 0x64636D74)
Metadata:
creation_time : 2006-XX-XX XX:XX:XX
handler_name : Apple Alias Data Handler
timecode : 00:00:08;07
Stream #0:2(eng): Audio: pcm_s16be (twos / 0x736F7774), 48000 Hz, 2 channels, s16, 1536 kb/s (default)
Metadata:
creation_time : 2006-XX-XX XX:XX:XX
handler_name : Apple Alias Data Handler
[swscaler @ 0x1297040] deprecated pixel format used, make sure you did set range correctly
[libx264 @ 0x12c7be0] using SAR=1/1
[libx264 @ 0x12c7be0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
[libx264 @ 0x12c7be0] profile High, level 3.0
[libx264 @ 0x12c7be0] 264 - core 148 - H.264/MPEG-4 AVC codec - Copyleft 2003-2015 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_ bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=60 keyint_min=6 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'out.mp4':
Metadata:
major_brand : qt
minor_version : 537199360
compatible_brands: qt
encoder : Lavf56.36.100
Stream #0:0(eng): Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuvj420p(pc), 640x480 [SAR 1:1 DAR 4:3], q=-1--1, 29.97 fps, 11988 tbn, 29.97 tbc (default)
Metadata:
creation_time : 2006-XX-XX XX:XX:XX
handler_name : Apple Alias Data Handler
timecode : 00:00:08;07
encoder : Lavc56.41.100 libx264
Stream #0:1(eng): Audio: aac (libfdk_aac) ([64][0][0][0] / 0x0040), 48000 Hz, stereo, s16, 139 kb/s (default)
Metadata:
creation_time : 2006-XX-XX XX:XX:XX
handler_name : Apple Alias Data Handler
encoder : Lavc56.41.100 libfdk_aac
Stream mapping:
Stream #0:0 -> #0:0 (mpeg4 (native) -> h264 (libx264))
Stream #0:2 -> #0:1 (pcm_s16be (native) -> aac (libfdk_aac))
Press [q] to stop, [?] for help
Past duration 239.760002 too large
frame= 98 fps=0.0 q=26.0 size= 345kB time=00:00:02.26 bitrate=1250.8kbits/
frame= 186 fps=185 q=29.0 size= 933kB time=00:00:05.18 bitrate=1474.3kbits/
...
frame=108248 fps=218 q=-1.0 Lsize= 708299kB time=01:00:11.81 bitrate=1606.5kbits/s dup=78 drop=0
video:643485kB audio:61559kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.461699%
[libx264 @ 0x12c7be0] frame I:1846 Avg QP:19.79 size: 25621
[libx264 @ 0x12c7be0] frame P:93233 Avg QP:24.01 size: 6332
[libx264 @ 0x12c7be0] frame B:13169 Avg QP:25.95 size: 1618
[libx264 @ 0x12c7be0] consecutive B-frames: 80.5% 8.5% 3.6% 7.3%
[libx264 @ 0x12c7be0] mb I I16..4: 17.5% 76.4% 6.1%
[libx264 @ 0x12c7be0] mb P I16..4: 1.9% 9.2% 0.4% P16..4: 35.5% 9.0% 6.3% 0.0% 0.0% skip:37.6%
[libx264 @ 0x12c7be0] mb B I16..4: 0.4% 1.7% 0.0% B16..8: 28.2% 3.0% 0.7% direct: 4.2% skip:61.8% L0:59.1% L1:33.8% BI: 7.1%
[libx264 @ 0x12c7be0] 8x8 transform intra:79.2% inter:86.3%
[libx264 @ 0x12c7be0] coded y,uvDC,uvAC intra: 65.8% 77.0% 11.3% inter: 24.3% 16.3% 1.4%
[libx264 @ 0x12c7be0] i16 v,h,dc,p: 42% 32% 24% 3%
[libx264 @ 0x12c7be0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 22% 24% 40% 3% 2% 2% 2% 2% 4%
[libx264 @ 0x12c7be0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 33% 27% 12% 3% 5% 5% 5% 4% 5%
[libx264 @ 0x12c7be0] i8c dc,h,v,p: 40% 28% 29% 3%
[libx264 @ 0x12c7be0] Weighted P-Frames: Y:0.6% UV:0.2%
[libx264 @ 0x12c7be0] ref P L0: 73.9% 12.5% 9.0% 4.5% 0.0%
[libx264 @ 0x12c7be0] ref B L0: 82.4% 16.2% 1.4%
[libx264 @ 0x12c7be0] ref B L1: 91.0% 9.0%
[libx264 @ 0x12c7be0] kb/s:1459.47
ffprobe out.mp4
[mov,mp4,m4a,3gp,3g2,mj2 @ 0xaf7c40] Could not find codec parameters for stream 0 (Video: h264 (avc1 / 0x31637661), none, 640x480, 1459 kb/s): unspecified pixel format
Consider increasing the value for the 'analyzeduration' and 'probesize' options
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'out.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf56.36.100
Duration: 01:00:11.88, start: -8.042667, bitrate: 1606 kb/s
Stream #0:0(eng): Video: h264 (avc1 / 0x31637661), none, 640x480, 1459 kb/s, 29.97 fps, 29.97 tbr, 11988 tbn, 23976 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 139 kb/s (default)
Metadata:
handler_name : SoundHandler
mencoder in.mpg -oac pcm -ovc raw -o out2.avi
tons of 1 duplicate frame(s)! warnings. video not synced
mencoder in.mpg -ovc copy -mc 0 -noskip -vf harddup -oac pcm -o out2.mpg
works partially, seems to be the closest fix, no warnings in the output, but loses sync (in this example) at 00:28:48, where the video stream seems to jump some frames at that time
ffmpeg
? An example command and the complete console output would be informative (you can trim lines that repeat over-and-over).ffmpeg version 2.7.2
andMEncoder SVN-r37440
. Not sure how helpful it will be, but I've put some example commands and output in an update above.