I want to use latest ffmpeg to encode set of JPG frames to 1920×1080 60fps h.264 movie.
I'm looking for set of parameters that will allow smooth playback of encoded video on fairly strong PC machines like I5-3570@3.4GHZ+Intel HD Graphics.
I tried various profiles (main, high) and levels (2.1, 3.1, 4) and bitrates (6mbps, 8mbps, 10mbps) for example:
ffmpeg -framerate 60 -start_number 1 -i frame-%05d.jpg -vcodec libx264 -preset slow -b:v 8M -profile:v high -level:v 3.1 -y output.mp4
But when I play output.mp4 in latest VLC or WMP I got framedrops (not many, but noticeable).
I played random youtube 60fps/1080 material on the same machine and the playback was smooth, so I assume that the machine is capable of smooth playback but the video has to be encoded with appropriate parameters.
What parameters could be used to make the decoding less processing power demanding?
I would like to maintain full hd quality and 60fps, but the file size is not relevant.
Output of ffmpeg command:
ffmpeg -framerate 60 -start_numb
er 1 -i d:\tmp\demo-60\test-%05d.jpg -vcodec libx264 -preset slow -b:v 8M -profi
le:v high -level:v 3.1 -y d:\tmp\insys-demo-60-noaudio.mp4
ffmpeg version N-67742-g3f07dd6 Copyright (c) 2000-2014 the FFmpeg developers
built on Nov 16 2014 22:10:05 with gcc 4.9.2 (GCC)
configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-av
isynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enab
le-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --
enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-lib
modplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrw
b --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinge
r --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --en
able-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis
--enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-
libx265 --enable-libxavs --enable-libxvid --enable-zlib
libavutil 54. 13.100 / 54. 13.100
libavcodec 56. 12.101 / 56. 12.101
libavformat 56. 13.100 / 56. 13.100
libavdevice 56. 3.100 / 56. 3.100
libavfilter 5. 2.103 / 5. 2.103
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 1.100 / 1. 1.100
libpostproc 53. 3.100 / 53. 3.100
Input #0, image2, from 'd:\tmp\demo-60\test-%05d.jpg':
Duration: 00:07:01.67, start: 0.000000, bitrate: N/A
Stream #0:0: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 1920x1080
[SAR 96:96 DAR 16:9], 60 fps, 60 tbr, 60 tbn, 60 tbc
No pixel format specified, yuvj420p for H.264 encoding chosen.
Use -pix_fmt yuv420p for compatibility with outdated media players.
[libx264 @ 0000000002c47d60] using SAR=1/1
[libx264 @ 0000000002c47d60] frame MB size (120x68) > level limit (3600)
[libx264 @ 0000000002c47d60] DPB size (4 frames, 32640 mbs) > level limit (2 fra
mes, 18000 mbs)
[libx264 @ 0000000002c47d60] MB rate (489600) > level limit (108000)
[libx264 @ 0000000002c47d60] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2
AVX
[libx264 @ 0000000002c47d60] profile High, level 3.1
[libx264 @ 0000000002c47d60] 264 - core 142 r2479 dd79a61 - H.264/MPEG-4 AVC cod
ec - Copyleft 2003-2014 - http://www.videolan.org/x264.html - options: cabac=1 r
ef=2 deblock=1:0:0 analyse=0x3:0x113 me=umh subme=8 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_pski
p=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 deci
mate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_
adapt=2 b_bias=0 direct=3 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=2
5 scenecut=40 intra_refresh=0 rc_lookahead=50 rc=abr mbtree=1 bitrate=8000 ratet
ol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'd:\tmp\insys-demo-60-noaudio.mp4':
Metadata:
encoder : Lavf56.13.100
Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuvj420p(pc), 1
920x1080 [SAR 96:96 DAR 16:9], q=-1--1, 8000 kb/s, 60 fps, 15360 tbn, 60 tbc
Metadata:
encoder : Lavc56.12.101 libx264
Stream mapping:
Stream #0:0 -> #0:0 (mjpeg (native) -> h264 (libx264))
Press [q] to stop, [?] for help
frame= 68 fps= 31 q=33.0 size= 252kB time=00:00:00.10 bitrate=20638.7kbits
frame= 87 fps= 32 q=27.0 size= 273kB time=00:00:00.41 bitrate=5358.4kbits/
frame= 102 fps= 31 q=24.0 size= 422kB time=00:00:00.66 bitrate=5191.4kbits/
frame= 119 fps= 31 q=22.0 size= 601kB time=00:00:00.95 bitrate=5183.7kbits/
frame= 136 fps= 31 q=21.0 size= 814kB time=00:00:01.23 bitrate=5409.1kbits/
frame= 150 fps= 31 q=21.0 size= 1047kB time=00:00:01.46 bitrate=5846.0kbits/
frame= 163 fps= 30 q=22.0 size= 1375kB time=00:00:01.68 bitrate=6690.5kbits/
frame= 177 fps= 30 q=22.0 size= 1598kB time=00:00:01.91 bitrate=6829.8kbits/
frame= 178 fps= 27 q=21.0 size= 1618kB time=00:00:01.93 bitrate=6854.9kbits/
frame= 193 fps= 27 q=21.0 size= 1810kB time=00:00:02.18 bitrate=6789.8kbits/
frame= 206 fps= 27 q=21.0 size= 2070kB time=00:00:02.40 bitrate=7065.7kbits/
frame= 220 fps= 27 q=22.0 size= 2313kB time=00:00:02.63 bitrate=7196.7kbits/
frame= 234 fps= 27 q=22.0 size= 2615kB time=00:00:02.86 bitrate=7474.0kbits/
frame= 247 fps= 27 q=22.0 size= 2793kB time=00:00:03.08 bitrate=7420.5kbits/
frame= 263 fps= 27 q=21.0 size= 2947kB time=00:00:03.35 bitrate=7205.6kbits/
frame= 279 fps= 28 q=21.0 size= 3119kB time=00:00:03.61 bitrate=7064.4kbits/
frame= 297 fps= 28 q=20.0 size= 3257kB time=00:00:03.91 bitrate=6811.5kbits/
frame= 312 fps= 28 q=20.0 size= 4109kB time=00:00:04.16 bitrate=8078.8kbits/
frame= 328 fps= 28 q=22.0 size= 4272kB time=00:00:04.43 bitrate=7893.5kbits/
frame= 345 fps= 28 q=21.0 size= 4391kB time=00:00:04.71 bitrate=7626.7kbits/
frame= 361 fps= 28 q=21.0 size= 4650kB time=00:00:04.98 bitrate=7644.7kbits/
...
At the end of processing ffmpeg prints:
frame=25193 fps= 17 q=33.0 size= 395561kB time=00:06:58.85 bitrate=7736.5kbits/
frame=25211 fps= 17 q=33.0 size= 395617kB time=00:06:59.15 bitrate=7732.1kbits/
frame=25232 fps= 17 q=32.0 size= 395672kB time=00:06:59.50 bitrate=7726.7kbits/
frame=25250 fps= 17 q=32.0 size= 395735kB time=00:06:59.80 bitrate=7722.4kbits/
frame=25267 fps= 17 q=32.0 size= 395776kB time=00:07:00.08 bitrate=7718.0kbits/
frame=25285 fps= 17 q=32.0 size= 395811kB time=00:07:00.38 bitrate=7713.2kbits/
frame=25300 fps= 17 q=-1.0 Lsize= 396340kB time=00:07:01.63 bitrate=7700.6kbits
/s
video:396048kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxin
g overhead: 0.073937%
[libx264 @ 00000000003675c0] frame I:104 Avg QP:26.69 size:182027
[libx264 @ 00000000003675c0] frame P:8999 Avg QP:31.82 size: 28039
[libx264 @ 00000000003675c0] frame B:16197 Avg QP:36.70 size: 8291
[libx264 @ 00000000003675c0] consecutive B-frames: 8.4% 12.1% 19.4% 60.0%
[libx264 @ 00000000003675c0] mb I I16..4: 17.2% 51.0% 31.8%
[libx264 @ 00000000003675c0] mb P I16..4: 2.2% 4.8% 1.5% P16..4: 17.9% 9.6
% 5.9% 0.0% 0.0% skip:58.0%
[libx264 @ 00000000003675c0] mb B I16..4: 0.3% 0.5% 0.1% B16..8: 22.8% 4.8
% 1.4% direct: 0.9% skip:69.2% L0:43.6% L1:50.3% BI: 6.0%
[libx264 @ 00000000003675c0] final ratefactor: 27.73
[libx264 @ 00000000003675c0] 8x8 transform intra:55.0% inter:51.7%
[libx264 @ 00000000003675c0] direct mvs spatial:97.7% temporal:2.3%
[libx264 @ 00000000003675c0] coded y,uvDC,uvAC intra: 27.2% 19.8% 10.7% inter: 5
.8% 3.5% 1.3%
[libx264 @ 00000000003675c0] i16 v,h,dc,p: 44% 45% 5% 6%
[libx264 @ 00000000003675c0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 23% 10% 45% 3% 4%
4% 4% 3% 4%
[libx264 @ 00000000003675c0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 20% 17% 18% 6% 8%
7% 8% 6% 10%
[libx264 @ 00000000003675c0] i8c dc,h,v,p: 72% 16% 11% 2%
[libx264 @ 00000000003675c0] Weighted P-Frames: Y:2.0% UV:1.5%
[libx264 @ 00000000003675c0] ref P L0: 71.7% 14.6% 13.6% 0.1%
[libx264 @ 00000000003675c0] ref B L0: 87.9% 12.1%
[libx264 @ 00000000003675c0] ref B L1: 94.2% 5.8%
[libx264 @ 00000000003675c0] kb/s:7694.27
VLC Player preferences:
Update
After testing various options of GOP (-g), reference frames (-refs), buffer sizes (-bufsize), bframes (-bf), disabling cabac (-coder 0), profiles (main, high, high10, high422, high444), levels (3.0 – 5.0) and testing various players enabling/disabling hardware acceleration I come to conclusion that it is probably not possible to encode sharp H.264 1920×1080@60fps with game-like dynamics so it would be playable on typical PC flawlesly. I tested various machines including Mac Book Pro. The only machine that was able to play the material smoothly was the latest Samsung TV model (UHD series).
Best Answer