Content
Lossless Encoding with x264 and ffmpeg
How Add AUDs (Access Unit Delimiters)
Free H264 High Level Stream Analyzer
Note:
Binaries for all platforms of x264 are located at https://download.videolan.org/x264/binaries/
Lossless Encoding with x264 and ffmpeg
To instruct x264 to make lossless encoding use the following switches: '--qp 0' and '--no-8x8dct'
Example of lossless encoding :
x264 --qp 0 --input-res 352x288 --no-8x8dct --output container_352x288_lossless.h264 container_352x288.yuv
To verify that the output stream is indeed lossless one can apply ffmpeg decoding:
ffmpeg -i container_352x288_lossless.h264 -vcodec rawvideo -pix_fmt yuv420p -y lossless.yuv
It’s worth mentioning that unlike to ffmpeg, JM18 produces near-lossless output of the given stream (container_352x288_lossless.h264). Why?
Another possibility is to use ffmpeg libx264 encoder with ‘-crf 0’ :
ffmpeg -s 1920×1080 -i test.yuv -c:v libx264 -crf 0 -y output.h264
Constant QP Encoding
To generate constant QP stream set the following command line parameters: '--qp <n> --ipratio 1.0 --pbratio 1.0 --qpstep 0'
Example of constant QP encoding (QP=20) :
x264 --qp 20 --ipratio 1.0 --pbratio 1.0 --qpstep 0 --input-res 352x288 --output qp20.h264 container_352x288.yuv
Notice that qp-modulation (aq-mode) is implicitly switched off by x264 in case of constant qp (i.e. if –qp <n> is present).
Constant Quality Mode (CRF)
Visual quality is controlled by ‘-crf’ parameter, lesser crf-value better quality. Reasonable values are in the range 18-28.
Example of encoding in CRF mode:
ffmpeg -s 1920x1080 -i test.yuv -c:v libx264 -crf 25 output.h264
Number Reference Frames
i found that in x264 the option ‘--ref 4’
(four reference frames) option increases significantly encoding time comparing to that with ‘--ref 3’
:
x264 settings:
CRF:
--threads 1 --keyint infinite --no-scenecut --muxer raw --open-gop --qpmax 45 --no-interlaced --bframes 3 --crf 25 --weightb --qcomp 0.6 --no-mixed-refs --ipratio 1.408 --chroma-qp-offset 0 --aq-strength 0.7 --qpstep 4 --qpmin 10 --8x8dct --profile high --input-res 1920x1080 --output test.264 --aud --slices 4 --force-cfr --fps 24000/1001 --sar 1:1 --pic-struct --force-pps-qp 26 --poc-diff 1 --trellis 1 --merange 16 --subme 7 --deadzone-inter 21 --me hex --partitions i4x4,i8x8,p8x8,b8x8 --weightp 1 --direct auto --deadzone-intra 11
VBR:
--threads 1 --keyint infinite --no-scenecut --muxer raw --open-gop --qpmax 45 --no-interlaced --bframes 3 --weightb --qcomp 0.6 --no-mixed-refs --ipratio 1.4 --chroma-qp-offset 0 --qpstep 4 --qpmin 10 --8x8dct --output test.h264 --profile high --input-res 1920x1080 --aud --slices 4 --fps 24000/1001 --sar 1:1 --pic-struct --force-pps-qp 26 --poc-diff 1 --trellis 1 --aq-strength 0.7 --merange 16 --subme 7 --deadzone-inter 21 --me hex --partitions i4x4,i8x8,p8x8,b8x8 --weightp 1 --direct auto --deadzone-intra 11 --rc-lookahead 40 --no-mbtree --b-adapt 0 --b-pyramid normal --sps-id 0 --bitrate 10965
A switch from ‘--ref 3’ to '--ref 4’ i
ncreases significantly encoding times. According to my evaluations the switch from ‘--ref 3’ to '--ref 4’
does not provide a significant gain in coding efficiency.
Note: Perhaps that x264 setting i used is sub-optimal (e.g. ‘umh’ is better than ‘hex’, but ‘umh’ is more time-consuming). i applied same setting with '--ref 3' and '--ref 4'
and obtained negligible gain in coding efficiency and significant penalty in encoding times.
How Add AUDs (Access Unit Delimiters)
AUDs are useful since this NAL unit (the type = 9) delimiters video frames, it’s easy to edit, process and play video streams with AUDs. The AUD NAL unit is too short ( 6 bytes, 00 00 00 01 09 10) to add any significant overhead onto the stream. ffmpeg has an option “-x264opts aud=1” to add AUDs at the start of each frame.
Example:
ffmpeg -y -i .\yuv\battlefield_384x320.y4m -c:v libx264 –x264opts aud=1 -threads 4 -b:v 500K -preset veryslow -g 60 -keyint_min 60 -sc_threshold 0 aud.h264
Encode x264 with ffmpeg
Example: encode 200 first frames, VBR Bitrate 15Mbps, number of slices 15 per frame, no B frame (IPPP stream), GOP size 60 frames, AUD added at the start of each frame:
ffmpeg -y -s 1920×1080 -i test.yuv -c:v libx264 -x264opts aud=1:bframes=0 -threads 4 -b:v 15M -preset veryfast -g 60 -keyint_min 60 -sc_threshold 0 -slices 15 -frames 200 aud.h264
Benchmark option of ffmpeg
the switch ‘-benchmark’ provides the following additional info:
maxrss serves to indicate the maximum RAM used during the ffmpeg execution
rtime the elapsed clock time (or the wall-clock time)
stime – system time taken from rtime
utime the sum of processing time across all threads. In parallel modes, utime exceeds rtime.
Example:
ffmpeg -benchmark -s 640x480 -i fifa_640x480.yuv -y -c:v libx264 -r 60 -g 60 -keyint_min 60 -b:v 4000k -maxrate 5000k -x264-params ref=1:bframes=0 fifa_640x480.h264
....
bench: utime=11.688s stime=0.281s rtime=2.143s
bench: maxrss=158168kB
....
from the results we can deduce that parallelization of x264 increases encoding time by ~5 times, (11.688-0.281)/2.143
Free H264 High Level Stream Analyzer
I compiled the free H264 High Level Stream Analyzer (it’s a headache) of Lei Xiaohua for Windows (Release/Win32). GUI version is located here.
The analyzer parses SPS, PPS and slice headers (therefore i call it “high-level”)
License:
H.264 ·ÖÎöÆ÷
H.264 Analysis
À×Ïöæè Lei Xiaohua
leixiaohua1020@126.com
Öйú´«Ã½´óѧ/Êý×ÖµçÊÓ¼¼Êõ
Communication University of China / Digital TV Technology
http://blog.csdn.net/leixiaohua1020
H.264ÂëÁ÷·ÖÎö¹¤¾ß
H.264 Stream Analysis Tools
23+ years’ programming and theoretical experience in the computer science fields such as video compression, media streaming and artificial intelligence (co-author of several papers and patents).
the author is looking for new job, my resume
magnificent points altogether, you simply gained a new reader. What would you suggest about your post that you made a few days ago? Any positive?
Wow, amazing blog layout! How long have you been blogging for? you make blogging look easy. The overall look of your website is fantastic, let alone the content!
you’re actually a good webmaster. The website loading pace is incredible. It kind of feels that you’re doing any unique trick. Moreover, The contents are masterpiece. you’ve performed a excellent task in this subject!
Simply a smiling visitant here to share the love (:, btw outstanding design.
I will immediately grab your rss feed as I can not find your e-mail subscription hyperlink or e-newsletter service. Do you have any? Kindly allow me recognize in order that I may subscribe. Thanks.
in main page there is “Subscribe”
Hi, Neat post. There is an issue with your web site in web explorer, could check this?K IE nonetheless is the marketplace chief and a large component to other folks will omit your wonderful writing because of this problem.
Some really fantastic information, Sword lily I discovered this. “Life is divided into the horrible and the miserable.” by Woody Allen.
There are certainly a number of particulars like that to take into consideration. That could be a nice point to bring up. I offer the thoughts above as basic inspiration however clearly there are questions like the one you convey up the place a very powerful thing will probably be working in trustworthy good faith. I don?t know if finest practices have emerged round things like that, but I’m positive that your job is clearly identified as a good game. Each boys and girls really feel the affect of only a second’s pleasure, for the remainder of their lives.
I have recently started a site, the information you offer on this website has helped me tremendously. Thanks for all of your time & work.
In this great design of things you receive a B- with regard to hard work. Exactly where you actually misplaced me was first in your facts. As people say, the devil is in the details… And it could not be much more true here. Having said that, let me inform you what did deliver the results. The writing is actually extremely powerful which is most likely the reason why I am taking the effort in order to opine. I do not make it a regular habit of doing that. 2nd, while I can see the jumps in reasoning you come up with, I am not sure of exactly how you seem to unite your points that help to make the actual final result. For the moment I will subscribe to your point however hope in the near future you connect the facts better.
Hey! I just want to give an enormous thumbs up for the great data you may have right here on this post. I can be coming again to your blog for more soon.
I just could not leave your website prior to suggesting that I really enjoyed the usual info a person supply on your visitors? Is gonna be again ceaselessly to inspect new posts
I loved as much as you will receive carried out right here. The sketch is tasteful, your authored material stylish. nonetheless, you command get got an shakiness over that you wish be delivering the following. unwell unquestionably come further formerly again as exactly the same nearly a lot often inside case you shield this hike.
Wonderful website. A lot of helpful info here. I am sending it to a few buddies ans also sharing in delicious. And certainly, thank you on your sweat!
Excellent post. I was checking constantly this weblog and I am inspired! Extremely helpful information specially the remaining phase 🙂 I deal with such information a lot. I used to be seeking this particular info for a long time. Thanks and good luck.
I’m still learning from you, as I’m trying to achieve my goals. I definitely enjoy reading everything that is posted on your site.Keep the tips coming. I liked it!
Thanks for any other informative web site. Where else may just I get that kind of information written in such an ideal approach? I have a undertaking that I’m simply now working on, and I’ve been at the look out for such info.
I’m impressed, I need to say. Really rarely do I encounter a weblog that’s both educative and entertaining, and let me tell you, you will have hit the nail on the head. Your thought is outstanding; the problem is one thing that not sufficient individuals are talking intelligently about. I’m very pleased that I stumbled throughout this in my search for one thing referring to this.
I always was interested in this subject and stock still am, appreciate it for posting.
Hi , I do believe this is an excellent blog. I stumbled upon it on Yahoo , i will come back once again. Money and freedom is the best way to change, may you be rich and help other people.
I’m typically to running a blog and i actually recognize your content. The article has actually peaks my interest. I am going to bookmark your web site and keep checking for new information.