0

I used this command to burn inside my video the timecode.

While everything looked fine, when I open my video inside Premiere it seems that my timecode doesn't match.

Timecode doesn't match!

My fear is that the timecode processed by ffmpeg was the original of the input file but when recompressed via h264 the number of frames changed giving precedence to the h264 compression algorythms.

How can I fix it? Or better how I can have an output video that match exactly the duration and the frames of the original input file?

Sadly my input file was already an h264 mp4 stream.

The command I used is the following:

ffmpeg -i "file.mp4" -c:v libx264 -x264-params "crf=17" -preset fast -c:a copy -c:s copy -copyinkf -filter_complex "drawtext=fontfile=font.otf: timecode='00\:00\:00\:00':rate=24: text='': fontsize=56: fontcolor=white@0.9: borderw=3: bordercolor=black: x=50-text_w/2:y=50" "file2.mp4"

The full console output is the following:

ffmpeg version N-82500-g52da3f6 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 4.9.3 (GCC)
  configuration: --arch=x86_64 --target-os=mingw32 --cross-prefix=/root/opt/ffmpeg-cross-compile/sandbox/cross_compilers/mingw-w64-x86_64/bin/x86_64-w64-mingw32- --pkg-config=pkg-config --disable-w32t
hreads --enable-libsoxr --enable-fontconfig --enable-libass --enable-libbluray --enable-iconv --enable-libtwolame --extra-cflags=-DLIBTWOLAME_STATIC --enable-libzvbi --enable-libcaca --enable-libmodpl
ug --extra-libs=-lstdc++ --extra-libs=-lpng --enable-decklink --extra-libs=-loleaut32 --enable-libmp3lame --enable-version3 --enable-zlib --enable-librtmp --enable-libvorbis --enable-libtheora --enabl
e-libspeex --enable-libopenjpeg --enable-gnutls --enable-libgsm --enable-libfreetype --enable-libopus --enable-bzlib --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --ena
ble-libschroedinger --enable-libvpx --enable-libilbc --enable-libwavpack --enable-libwebp --enable-libgme --enable-dxva2 --enable-avisynth --enable-gray --enable-libopenh264 --enable-netcdf --enable-l
ibflite --enable-lzma --enable-libsnappy --enable-libzimg --enable-gpl --enable-libx264 --enable-libx265 --enable-frei0r --enable-filter=frei0r --enable-librubberband --enable-libvidstab --enable-libx
avs --enable-libxvid --enable-libmfx --extra-libs=-lpsapi --extra-libs=-lspeexdsp --extra-cflags='-mtune=core2' --extra-cflags=-O3 --enable-static --disable-shared --prefix=/root/opt/ffmpeg-cross-comp
ile/sandbox/cross_compilers/mingw-w64-x86_64/x86_64-w64-mingw32 --enable-nonfree --enable-libfdk-aac --enable-runtime-cpudetect
  libavutil      55. 40.100 / 55. 40.100
  libavcodec     57. 66.103 / 57. 66.103
  libavformat    57. 57.100 / 57. 57.100
  libavdevice    57.  2.100 / 57.  2.100
  libavfilter     6. 67.100 /  6. 67.100
  libswscale      4.  3.101 /  4.  3.101
  libswresample   2.  4.100 /  2.  4.100
  libpostproc    54.  2.100 / 54.  2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'file.mp4':
  Metadata:
    major_brand     : iso5
    minor_version   : 512
    compatible_brands: iso6mp41
  Duration: 00:51:27.38, start: 0.000000, bitrate: 3246 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080 [SAR 1:1 DAR 16:9], 2988 kb/s, 24 fps, 24 tbr, 12288 tbn, 48 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 256 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
[libx264 @ 0000000003746020] using SAR=1/1
[libx264 @ 0000000003746020] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 0000000003746020] profile High, level 4.0
[libx264 @ 0000000003746020] 264 - core 148 r2708 86b7198 - H.264/MPEG-4 AVC codec - Copyleft 2003-2016 - http://www.videolan.org/x264.html - options: cabac=1 ref=2 deblock=1:0:0 analyse=0x3:0x113 me=
hex subme=6 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 dec
imate=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=1 keyint=250 keyint_min=24 scenecut=40 intra_refresh=0 rc_lookah
ead=30 rc=crf mbtree=1 crf=17.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'file2.mp4':
  Metadata:
    major_brand     : iso5
    minor_version   : 512
    compatible_brands: iso6mp41
    encoder         : Lavf57.57.100
    Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=-1--1, 24 fps, 12288 tbn, 24 tbc (default)
    Metadata:
      encoder         : Lavc57.66.103 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
    Stream #0:1(und): Audio: aac (LC) ([64][0][0][0] / 0x0040), 48000 Hz, stereo, fltp, 256 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Stream mapping:
  Stream #0:0 (h264) -> drawtext
  drawtext -> Stream #0:0 (libx264)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame= 2105 fps= 36 q=-1.0 Lsize=   41555kB time=00:01:27.58 bitrate=3886.8kbits/s dup=2 drop=0 speed=1.49x
video:38775kB audio:2719kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.145290%
[libx264 @ 0000000003746020] frame I:11    Avg QP: 7.99  size: 70608
[libx264 @ 0000000003746020] frame P:761   Avg QP:13.37  size: 28331
[libx264 @ 0000000003746020] frame B:1333  Avg QP:14.85  size: 13030
[libx264 @ 0000000003746020] consecutive B-frames:  2.0% 40.1%  1.9% 56.1%
[libx264 @ 0000000003746020] mb I  I16..4: 49.6% 36.9% 13.5%
[libx264 @ 0000000003746020] mb P  I16..4:  9.6% 15.5%  2.1%  P16..4: 20.5%  7.4%  3.1%  0.0%  0.0%    skip:41.8%
[libx264 @ 0000000003746020] mb B  I16..4:  2.5%  3.7%  0.4%  B16..8: 17.6%  7.0%  0.8%  direct: 7.7%  skip:60.4%  L0:50.5% L1:44.4% BI: 5.1%
[libx264 @ 0000000003746020] 8x8 transform intra:56.0% inter:56.8%
[libx264 @ 0000000003746020] coded y,uvDC,uvAC intra: 37.2% 61.9% 19.6% inter: 6.6% 19.9% 0.8%
[libx264 @ 0000000003746020] i16 v,h,dc,p: 51% 24% 14% 10%
[libx264 @ 0000000003746020] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 36% 18% 29%  3%  3%  3%  2%  3%  3%
[libx264 @ 0000000003746020] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 39% 23% 15%  4%  4%  4%  3%  4%  3%
[libx264 @ 0000000003746020] i8c dc,h,v,p: 45% 18% 29%  7%
[libx264 @ 0000000003746020] Weighted P-Frames: Y:5.8% UV:3.0%
[libx264 @ 0000000003746020] ref P L0: 77.3% 22.7%
[libx264 @ 0000000003746020] ref B L0: 87.0% 13.0%
[libx264 @ 0000000003746020] ref B L1: 97.2%  2.8%
[libx264 @ 0000000003746020] kb/s:3621.54

I re runned it to obtain the output and closed it after some seconds with [q] option ;)

EDIT: runned again keeping the video only!

ffmpeg version N-82500-g52da3f6 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 4.9.3 (GCC)
  configuration: --arch=x86_64 --target-os=mingw32 --cross-prefix=/root/opt/ffmpeg-cross-compile/sandbox/cross_compilers/mingw-w64-x86_64/bin/x86_64-w64-mingw32- --pkg-config=pkg-config --disable-w32t
hreads --enable-libsoxr --enable-fontconfig --enable-libass --enable-libbluray --enable-iconv --enable-libtwolame --extra-cflags=-DLIBTWOLAME_STATIC --enable-libzvbi --enable-libcaca --enable-libmodpl
ug --extra-libs=-lstdc++ --extra-libs=-lpng --enable-decklink --extra-libs=-loleaut32 --enable-libmp3lame --enable-version3 --enable-zlib --enable-librtmp --enable-libvorbis --enable-libtheora --enabl
e-libspeex --enable-libopenjpeg --enable-gnutls --enable-libgsm --enable-libfreetype --enable-libopus --enable-bzlib --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --ena
ble-libschroedinger --enable-libvpx --enable-libilbc --enable-libwavpack --enable-libwebp --enable-libgme --enable-dxva2 --enable-avisynth --enable-gray --enable-libopenh264 --enable-netcdf --enable-l
ibflite --enable-lzma --enable-libsnappy --enable-libzimg --enable-gpl --enable-libx264 --enable-libx265 --enable-frei0r --enable-filter=frei0r --enable-librubberband --enable-libvidstab --enable-libx
avs --enable-libxvid --enable-libmfx --extra-libs=-lpsapi --extra-libs=-lspeexdsp --extra-cflags='-mtune=core2' --extra-cflags=-O3 --enable-static --disable-shared --prefix=/root/opt/ffmpeg-cross-comp
ile/sandbox/cross_compilers/mingw-w64-x86_64/x86_64-w64-mingw32 --enable-nonfree --enable-libfdk-aac --enable-runtime-cpudetect
  libavutil      55. 40.100 / 55. 40.100
  libavcodec     57. 66.103 / 57. 66.103
  libavformat    57. 57.100 / 57. 57.100
  libavdevice    57.  2.100 / 57.  2.100
  libavfilter     6. 67.100 /  6. 67.100
  libswscale      4.  3.101 /  4.  3.101
  libswresample   2.  4.100 /  2.  4.100
  libpostproc    54.  2.100 / 54.  2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'file.mp4':
  Metadata:
    major_brand     : iso5
    minor_version   : 512
    compatible_brands: iso6mp41
  Duration: 00:51:27.38, start: 0.000000, bitrate: 3246 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080 [SAR 1:1 DAR 16:9], 2988 kb/s, 24 fps, 24 tbr, 12288 tbn, 48 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 256 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
[libx264 @ 000000000315f7c0] using SAR=1/1
[libx264 @ 000000000315f7c0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 000000000315f7c0] profile High, level 4.0
[libx264 @ 000000000315f7c0] 264 - core 148 r2708 86b7198 - H.264/MPEG-4 AVC codec - Copyleft 2003-2016 - http://www.videolan.org/x264.html - options: cabac=1 ref=2 deblock=1:0:0 analyse=0x3:0x113 me=
hex subme=6 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 dec
imate=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=1 keyint=250 keyint_min=24 scenecut=40 intra_refresh=0 rc_lookah
ead=30 rc=crf mbtree=1 crf=17.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'file2.mp4':
  Metadata:
    major_brand     : iso5
    minor_version   : 512
    compatible_brands: iso6mp41
    encoder         : Lavf57.57.100
    Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=-1--1, 24 fps, 12288 tbn, 24 tbc (default)
    Metadata:
      encoder         : Lavc57.66.103 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
Stream mapping:
  Stream #0:0 (h264) -> drawtext
  drawtext -> Stream #0:0 (libx264)
Press [q] to stop, [?] for help
frame=  843 fps= 36 q=-1.0 Lsize=   10386kB time=00:00:35.00 bitrate=2430.9kbits/s dup=2 drop=0 speed= 1.5x
video:10375kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.103293%
[libx264 @ 000000000315f7c0] frame I:4     Avg QP: 5.49  size: 41664
[libx264 @ 000000000315f7c0] frame P:285   Avg QP:12.19  size: 19489
[libx264 @ 000000000315f7c0] frame B:554   Avg QP:13.02  size:  8849
[libx264 @ 000000000315f7c0] consecutive B-frames:  2.6% 28.7%  1.8% 66.9%
[libx264 @ 000000000315f7c0] mb I  I16..4: 65.5% 27.6%  6.9%
[libx264 @ 000000000315f7c0] mb P  I16..4:  9.0% 11.3%  1.3%  P16..4: 15.5%  5.1%  2.2%  0.0%  0.0%    skip:55.6%
[libx264 @ 000000000315f7c0] mb B  I16..4:  2.4%  2.2%  0.1%  B16..8: 11.6%  4.9%  0.6%  direct: 7.1%  skip:71.0%  L0:50.3% L1:45.1% BI: 4.6%
[libx264 @ 000000000315f7c0] 8x8 transform intra:49.4% inter:53.5%
[libx264 @ 000000000315f7c0] coded y,uvDC,uvAC intra: 26.0% 54.6% 16.0% inter: 4.1% 16.1% 0.6%
[libx264 @ 000000000315f7c0] i16 v,h,dc,p: 52% 26% 14%  8%
[libx264 @ 000000000315f7c0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 31% 22% 38%  1%  1%  1%  2%  1%  2%
[libx264 @ 000000000315f7c0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 38% 28% 20%  2%  3%  3%  3%  2%  2%
[libx264 @ 000000000315f7c0] i8c dc,h,v,p: 49% 19% 26%  7%
[libx264 @ 000000000315f7c0] Weighted P-Frames: Y:15.4% UV:8.1%
[libx264 @ 000000000315f7c0] ref P L0: 71.5% 28.5%
[libx264 @ 000000000315f7c0] ref B L0: 84.7% 15.3%
[libx264 @ 000000000315f7c0] ref B L1: 96.2%  3.8%
[libx264 @ 000000000315f7c0] kb/s:2419.57

This is the media info I obtained:

Video
ID : 1
Format : AVC
Format/Info : Advanced Video Codec
Format profile : High@L4
Format settings, CABAC : Yes
Format settings, ReFrames : 2 frames
Codec ID : avc1
Codec ID/Info : Advanced Video Coding
Duration : 50s 0ms
Bit rate : 2 991 Kbps
Width : 1 920 pixels
Height : 1 080 pixels
Display aspect ratio : 16:9
Frame rate mode : Variable
Frame rate : 23.976 (23976/1000) fps
Minimum frame rate : 12.000 fps
Maximum frame rate : 24.000 fps
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressive
Bits/(Pixel*Frame) : 0.060
Stream size : 17.8 MiB (100%)
Writing library : x264 core 148 r2708 86b7198
Encoding settings : cabac=1 / ref=2 / deblock=1:0:0 / analyse=0x3:0x113 / me=hex / subme=6 / 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=0 / b_adapt=1 / b_bias=0 / direct=1 / weightb=1 / open_gop=0 / weightp=1 / keyint=250 / keyint_min=24 / scenecut=40 / intra_refresh=0 / rc_lookahead=30 / rc=crf / mbtree=1 / crf=17.0 / qcomp=0.60 / qpmin=0 / qpmax=69 / qpstep=4 / ip_ratio=1.40 / aq=1:1.00

  • Show the full console output. – Gyan Mar 30 '17 at 9:58
  • @Mulvya done :) – user3450548 Mar 30 '17 at 16:39
  • The console output shows only two duplicated frames. But the output is only 1m27s whereas the source is 51m. So, if there are dropped frames further, this console output won't reveal that. Does Premiere at the 1m27s mark show a 2 frame difference? – Gyan Mar 30 '17 at 19:05
  • 1
    Use -vsync 0. – Gyan Apr 1 '17 at 11:11
  • 1
    None of the options I suggested there disable P-frames. And B-frames aren't disabled, just limited. Or you could just live with the missing 2 frames :) – Gyan Apr 2 '17 at 6:29
2

You might have variable frame rate media. The time base looks pretty crazy for standard 24p media. I might hit it with MediaInfo (note the Windows GUI includes adware, but the CLI version does not) and post the output from that.

  • Yes.. it seems so, I tried many transcodings and always it seems change th fps on the fly. How can I obtain a constant output ? – user3450548 Apr 1 '17 at 19:34
  • That time base is the standard that ffmpeg produces i.e .framerate x 512. – Gyan Apr 1 '17 at 19:55
  • @Mulvya let me post the info for the last encoded file... – user3450548 Apr 1 '17 at 22:17
  • @Mulvya let me reply here so both of you can read, I did many other tests, I also tried to encode only the video in .mov with a proress codec instead of h264.. ffmpeg doesn't show duplicated frames however at the very beginning of the movie there's the black background with white text for the initial credits.. and in this part 00:00:00:03 and 00:00:00:04 are repeated 2 times in premiere leaving Premiere being always +2 frames over the total until the end :( I don't understand why, can it be something bugged about particular scenes like white text on black background? – user3450548 Apr 2 '17 at 9:11
  • @user3450548 What you would need to do is manually specify the output frame rate in your encoding tool. So for ffmpeg you would use -r 24000/1001 for 23.976, and for Handbrake there's a dropdown and you would select Constant Frame Rate. – ivkowalenko Apr 24 '17 at 18:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.