[FFmpeg-user] Transcoding mpeg2video in mpegts to h264 in mpegts has fast playback

Pat Double pat at patdouble.com
Fri Sep 18 19:51:59 EEST 2020


I’m transcoding a file recorded from an OTA tuner using Plex DVR to h264 to
reduce the size. Due to how Plex DVR tracks existing episodes I want to
shrink the file size using h264 without changing the filename. The
transcoded mpegts file plays faster than the original, appears to be about
2x faster. I can issue the same commands (except for how subtitles are
handled) except using the mkv container and playback is at the expected
speed. I’ve tried various combinations of the fps filter, the -r switch,
thinking it’s the frame rate. I also tried values for the setpts filter and
whatever I tried it made the playback faster (setpts=0.5*PTS,
setpts=2.0*PTS). I have turned on Plex DVR’s support for transcoding to
h264 in a mpegts container and playback is fine. I’ve based my ffmpeg
arguments on that transcoding feature. (I can’t use this feature because my
computer doesn’t have enough compute power.)

I’m using “MPlayer OS X Extended” to play.

Here is my sample:

https://www.dropbox.com/s/7s7itvj1uy2nov7/RobotMaker-short.ts?dl=0

$ ffmpeg -i .\~RobotMaker-short.ts
ffmpeg version 4.3.1 Copyright (c) 2000-2020 the FFmpeg developers
  built with Apple clang version 11.0.3 (clang-1103.0.32.62)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/4.3.1 --enable-shared
--enable-pthreads --enable-version3 --enable-avresample --cc=clang
--host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl
--enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame
--enable-libopus --enable-librav1e --enable-librubberband
--enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora
--enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp
--enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid
--enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r
--enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb
--enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-libsoxr
--enable-videotoolbox --disable-libjack --disable-indev=jack
  libavutil      56. 51.100 / 56. 51.100
  libavcodec     58. 91.100 / 58. 91.100
  libavformat    58. 45.100 / 58. 45.100
  libavdevice    58. 10.100 / 58. 10.100
  libavfilter     7. 85.100 /  7. 85.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  7.100 /  5.  7.100
  libswresample   3.  7.100 /  3.  7.100
  libpostproc    55.  7.100 / 55.  7.100
Input #0, mpegts, from '.~RobotMaker-short.ts':
  Duration: 00:02:00.08, start: 1.400000, bitrate: 2343 kb/s
  Program 1
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #0:0[0x100]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002),
yuv420p(tv, top first), 704x480 [SAR 40:33 DAR 16:9], Closed Captions,
29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc
    Side data:
      cpb: bitrate max/min/avg: 2917200/0/0 buffer size: 1835008 vbv_delay:
N/A
    Stream #0:1[0x101](eng): Audio: ac3 ([129][0][0][0] / 0x0081), 48000
Hz, stereo, fltp, 192 kb/s



The mpegts transcode:

$ /usr/local/bin/ffmpeg -hide_banner -benchmark -f lavfi -i
'movie=/Users/double/Movies/.~tmpXXXXXXX.lnk[out+subcc]' -i
/Users/double/Movies/RobotMaker-short.ts -map 1:a -map_chapters 1
-map_metadata 1 -aspect 16:9 -filter_complex
'[1:v]fps=fps=29.969999999999999[0];[0]yadif[1];[1]format=pix_fmts=yuv420p|nv12[2]'
-map '[2]' -crf:v 16 -c:v libx264 -c:a copy -preset fast -t 2:00
/Users/double/Movies/.~RobotMaker-short.transcoded.ts
Input #0, lavfi, from
'movie=/Users/double/Movies/.~tmpXXXXXXX.lnk[out+subcc]':
  Duration: N/A, start: 1.558733, bitrate: N/A
    Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 704x480 [SAR
1:1 DAR 22:15], 29.97 fps, 29.97 tbr, 90k tbn, 90k tbc
    Stream #0:1: Subtitle: eia_608
Input #1, mpegts, from '/Users/double/Movies/RobotMaker-short.ts':
  Duration: 00:02:00.08, start: 1.400000, bitrate: 2343 kb/s
  Program 1
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #1:0[0x100]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002),
yuv420p(tv, top first), 704x480 [SAR 40:33 DAR 16:9], Closed Captions,
29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc
    Side data:
      cpb: bitrate max/min/avg: 2917200/0/0 buffer size: 1835008 vbv_delay:
N/A
    Stream #1:1[0x101](eng): Audio: ac3 ([129][0][0][0] / 0x0081), 48000
Hz, stereo, fltp, 192 kb/s
Stream mapping:
  Stream #1:0 (mpeg2video) -> fps
  Stream #1:1 -> #0:0 (copy)
  format -> Stream #0:1 (libx264)
Press [q] to stop, [?] for help
[libx264 @ 0x7fa3a8095e00] using SAR=40/33
[libx264 @ 0x7fa3a8095e00] using cpu capabilities: MMX2 SSE2Fast SSSE3
SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x7fa3a8095e00] profile High, level 3.0, 4:2:0, 8-bit
Output #0, mpegts, to
'/Users/double/Movies/.~RobotMaker-short.transcoded.ts':
  Metadata:
    encoder         : Lavf58.45.100
    Stream #0:0(eng): Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz,
stereo, fltp, 192 kb/s
    Stream #0:1: Video: h264 (libx264), yuv420p, 704x480 [SAR 40:33 DAR
16:9], q=-1--1, 29.97 fps, 90k tbn, 29.97 tbc
    Metadata:
      encoder         : Lavc58.91.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
frame= 3592 fps=290 q=-1.0 Lsize=   30112kB time=00:01:59.96
bitrate=2056.2kbits/s speed= 9.7x
video:25655kB audio:2812kB subtitle:0kB other streams:0kB global
headers:0kB muxing overhead: 5.777693%
bench: utime=106.170s stime=3.512s rtime=12.367s
bench: maxrss=159133696kB
[libx264 @ 0x7fa3a8095e00] frame I:50    Avg QP:11.49  size: 30274
[libx264 @ 0x7fa3a8095e00] frame P:997   Avg QP:16.07  size: 13303
[libx264 @ 0x7fa3a8095e00] frame B:2545  Avg QP:18.89  size:  4516
[libx264 @ 0x7fa3a8095e00] consecutive B-frames:  3.2%  4.8%  6.7% 85.3%
[libx264 @ 0x7fa3a8095e00] mb I  I16..4: 25.0% 63.4% 11.7%
[libx264 @ 0x7fa3a8095e00] mb P  I16..4:  4.4% 19.8%  2.0%  P16..4: 24.8%
14.8%  7.0%  0.0%  0.0%    skip:27.2%
[libx264 @ 0x7fa3a8095e00] mb B  I16..4:  1.3%  4.8%  1.4%  B16..8: 24.3%
10.0%  1.2%  direct:11.5%  skip:45.4%  L0:43.1% L1:41.7% BI:15.2%
[libx264 @ 0x7fa3a8095e00] 8x8 transform intra:70.0% inter:60.2%
[libx264 @ 0x7fa3a8095e00] coded y,uvDC,uvAC intra: 67.0% 76.6% 43.3%
inter: 19.6% 27.9% 3.5%
[libx264 @ 0x7fa3a8095e00] i16 v,h,dc,p: 57% 18% 12% 13%
[libx264 @ 0x7fa3a8095e00] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 30% 20% 28%  3%
 3%  4%  3%  4%  4%
[libx264 @ 0x7fa3a8095e00] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 35% 19% 11%  4%
 6%  7%  6%  6%  5%
[libx264 @ 0x7fa3a8095e00] i8c dc,h,v,p: 43% 21% 29%  7%
[libx264 @ 0x7fa3a8095e00] Weighted P-Frames: Y:10.7% UV:6.3%
[libx264 @ 0x7fa3a8095e00] ref P L0: 67.4% 32.6%
[libx264 @ 0x7fa3a8095e00] ref B L0: 84.8% 15.2%
[libx264 @ 0x7fa3a8095e00] ref B L1: 96.1%  3.9%
[libx264 @ 0x7fa3a8095e00] kb/s:1753.49



The mkv transcode:

$ /usr/local/bin/ffmpeg -hide_banner -benchmark -f lavfi -i
'movie=/Users/double/Movies/.~tmpXXXXXXX.lnk[out+subcc]' -i
/Users/double/Movies/RobotMaker-short.ts -map 0:s -map 1:a -map_chapters 1
-map_metadata 1 -aspect 16:9 -filter_complex
'[1:v]fps=fps=29.969999999999999[0];[0]yadif[1];[1]format=pix_fmts=yuv420p|nv12[2]'
-map '[2]' -crf:v 16 -c:v libx264 -c:a copy -c:s ass -metadata:s:s:0
language=eng -preset fast -t 2:00
/Users/double/Movies/.~RobotMaker-short.transcoded.mkv
Input #0, lavfi, from
'movie=/Users/double/Movies/.~tmpXXXXXXX.lnk[out+subcc]':
  Duration: N/A, start: 1.558733, bitrate: N/A
    Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 704x480 [SAR
1:1 DAR 22:15], 29.97 fps, 29.97 tbr, 90k tbn, 90k tbc
    Stream #0:1: Subtitle: eia_608
Input #1, mpegts, from '/Users/double/Movies/RobotMaker-short.ts':
  Duration: 00:02:00.08, start: 1.400000, bitrate: 2343 kb/s
  Program 1
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #1:0[0x100]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002),
yuv420p(tv, top first), 704x480 [SAR 40:33 DAR 16:9], Closed Captions,
29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc
    Side data:
      cpb: bitrate max/min/avg: 2917200/0/0 buffer size: 1835008 vbv_delay:
N/A
    Stream #1:1[0x101](eng): Audio: ac3 ([129][0][0][0] / 0x0081), 48000
Hz, stereo, fltp, 192 kb/s
Stream mapping:
  Stream #1:0 (mpeg2video) -> fps
  Stream #0:1 -> #0:0 (eia_608 (cc_dec) -> ass (native))
  Stream #1:1 -> #0:1 (copy)
  format -> Stream #0:2 (libx264)
Press [q] to stop, [?] for help
[libx264 @ 0x7fc76b81f600] using SAR=40/33
[libx264 @ 0x7fc76b81f600] using cpu capabilities: MMX2 SSE2Fast SSSE3
SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x7fc76b81f600] profile High, level 3.0, 4:2:0, 8-bit
[libx264 @ 0x7fc76b81f600] 264 - core 160 r3011 cde9a93 - H.264/MPEG-4 AVC
codec - Copyleft 2003-2020 - 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=15
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=1 keyint=250 keyint_min=25
scenecut=40 intra_refresh=0 rc_lookahead=30 rc=crf mbtree=1 crf=16.0
qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, matroska, to
'/Users/double/Movies/.~RobotMaker-short.transcoded.mkv':
  Metadata:
    encoder         : Lavf58.45.100
    Stream #0:0(eng): Subtitle: ass
    Metadata:
      encoder         : Lavc58.91.100 ass
    Stream #0:1(eng): Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, stereo,
fltp, 192 kb/s
    Stream #0:2: Video: h264 (libx264) (H264 / 0x34363248), yuv420p,
704x480 [SAR 40:33 DAR 16:9], q=-1--1, 29.97 fps, 1k tbn, 29.97 tbc
    Metadata:
      encoder         : Lavc58.91.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
[Parsed_movie_0 @ 0x7fc76ae04800] EOF timestamp not
reliablebitrate=1897.7kbits/s speed=9.83x
frame= 3592 fps=292 q=-1.0 Lsize=   28526kB time=00:01:59.96
bitrate=1947.9kbits/s speed=9.76x
video:25653kB audio:2812kB subtitle:3kB other streams:0kB global
headers:1kB muxing overhead: 0.204090%
bench: utime=103.705s stime=3.778s rtime=12.288s
bench: maxrss=167841792kB
[libx264 @ 0x7fc76b81f600] frame I:50    Avg QP:11.49  size: 30230
[libx264 @ 0x7fc76b81f600] frame P:997   Avg QP:16.07  size: 13303
[libx264 @ 0x7fc76b81f600] frame B:2545  Avg QP:18.89  size:  4516
[libx264 @ 0x7fc76b81f600] consecutive B-frames:  3.2%  4.8%  6.7% 85.3%
[libx264 @ 0x7fc76b81f600] mb I  I16..4: 25.0% 63.4% 11.7%
[libx264 @ 0x7fc76b81f600] mb P  I16..4:  4.4% 19.8%  2.0%  P16..4: 24.8%
14.8%  7.0%  0.0%  0.0%    skip:27.2%
[libx264 @ 0x7fc76b81f600] mb B  I16..4:  1.3%  4.8%  1.4%  B16..8: 24.3%
10.0%  1.2%  direct:11.5%  skip:45.4%  L0:43.1% L1:41.7% BI:15.2%
[libx264 @ 0x7fc76b81f600] 8x8 transform intra:70.0% inter:60.2%
[libx264 @ 0x7fc76b81f600] coded y,uvDC,uvAC intra: 67.0% 76.6% 43.3%
inter: 19.6% 27.9% 3.5%
[libx264 @ 0x7fc76b81f600] i16 v,h,dc,p: 57% 18% 12% 13%
[libx264 @ 0x7fc76b81f600] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 30% 20% 28%  3%
 3%  4%  3%  4%  4%
[libx264 @ 0x7fc76b81f600] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 35% 19% 11%  4%
 6%  7%  6%  6%  5%
[libx264 @ 0x7fc76b81f600] i8c dc,h,v,p: 43% 21% 29%  7%
[libx264 @ 0x7fc76b81f600] Weighted P-Frames: Y:10.7% UV:6.3%
[libx264 @ 0x7fc76b81f600] ref P L0: 67.4% 32.6%
[libx264 @ 0x7fc76b81f600] ref B L0: 84.8% 15.2%
[libx264 @ 0x7fc76b81f600] ref B L1: 96.1%  3.9%
[libx264 @ 0x7fc76b81f600] kb/s:1753.35


-- 
Patrick Double
"Ye must be born again." - John 3:7


More information about the ffmpeg-user mailing list