i readed this guide of h264
https://trac.ffmpeg.org/wiki/Encode/H.264
but there is only crf and two pass examples
how can i do average bitrate encoding where we specify bitrate not crf with only one line of code
need one example code
+ Reply to Thread
Results 1 to 30 of 39
-
Anonymous543Guest
-
define average bitrate... normally you can control bit rate by specyfying (vbv) buffer size, minimum bitrate and maximum bitrate - usually buffer size is specified to match destination medium characteristic.
In case of libx264 there is 'vbv_maxrate=' and 'vbv_bufsize=' - if your buffer will be to low then quality will be poor, if too high then you may gain nothing in exchange...
To control fine encoding aspects on libx264 i use 'x264opts=' structure and this may look in ffmpeg script as:
Code:@setlocal @SET x264opts="crf=20:level=4.0:qpmin=16:vbv_maxrate=9984:vbv_bufsize=9984:cabac=1:interlaced=0:no_psnr=1:no_ssim=1:bluray_compat=1:open-gop=0:pic_struct=1:aud=1:nal_hrd=vbr:force_cfr=1:fullrange=off:overscan=show:colorprim=bt709:transfer=bt709:colormatrix=bt709:stitchable=1" @ffmpeg.exe -hide_banner -v quiet -stats -y -i %name% -sn -dn -c:v libx264 -preset faster -tune film -profile:v high -level:v 4.0 -x264opts %x264opts% -x264-params %x264opts% -flags:a +qscale -c:a libmp3lame -q:a 4 -f matroska "%~n1_.mkv" @endlocal @pause
-
Why don't you use MeGUI? You will see 2 pass-average bitrate option in H264 profiles. And you won't have to deal with command lines.
Using ffmpeg won't you give any extra quality. I've done encodings with MeGUI, Handbrake, AVIDemux, VirtualDub, ffmpeg, each gave the same video quality - unless you use some special Avisynth scripts. -
Anonymous543Guest
If i make some change to crf example which is
Code:ffmpeg -i input -c:v libx264 -preset slow -crf 22 -c:a copy output.mkv
Instead of specifying crf if i specify -b:v like this
Code:ffmpeg -i input -c:v libx264 -preset slow -b:v 1000k -c:a copy output.mkv
-
Yes, but crf focus on quality where bitrate will focus on bitrate not on quality - you may use crf and bitrate control trying to keep as much possible from crf.
If your goal is o match file size for example use DVD disc as much as possible then you can follow this https://forum.videohelp.com/threads/380289-encode-with-X264-target-size
But there is no warranty of course so you must be prepared to allocate some spare headroom. -
Anonymous543Guest
-
Anonymous543Guest
because ffmpeg can do many options which gui encoders does not includes....like editing meta data ,adding subtitles , adding extra tracks etc
so for encoding i prefer ffmpeg
and for lossless cutting video clips, croping videos ,adding some filters for that kind of oprations i use gui softwares like avidemux -
It define your target bitrate but key to overall bitrate is bitrate control - constant bitrate is extreme case for variable (average) bitrate where bitrate control is very tight and strict so bitrate variability is minimized but still there is no such thing like constant bitrate - from practical perspective it is variable bitrate with very low bitrate variability. You can to constant bitrate for dynamic data compression - sometimes to get very strict constant bitrate, special data are added on top - those data are used to fill gaps and are called usually stuffing - this is common practice in broadcast industry for example for static multiplexing (popular in past but nowadays used only in very simplistic setups)
-
Anonymous543Guest
-
In my personal opinion not - lib.x264 is rather difficult to be configured to produce more or less CBR video - it can be done with some limited success but this particular encoder was never designed to be able do CBR video. Using your examples it is rather closer to concept of the ABR than to the CBR.
(btw ABR concept was introduced if i recall correctly by lame for MP3 encoding). -
Anonymous543Guest
I don't want cbr i just want my video bitrate goes high at complex sections and low during non complex sections
how can I get that? -
Last edited by davexnet; 6th Feb 2022 at 02:09.
-
Anonymous543Guest
-
ABR is a poor choice and is not advised.
https://slhck.info/video/2017/03/01/rate-control.html -
MeGUI also does them. First, you can extract subtitle and audio tracks from original file (via "HD Streams Extractor", which is actually an inside-GUI to command-line tools like "eac3to"), and later add them to the encoded file while muxing.
Remember that MeGUI is a package with all-needed encoding tools like dgindex, eac3to, ffmpeg, lsmash, tsmuxer, x264 and x265 encoders, etc... Most of them are command-line tools, but MeGUI offers you a graphical user interface, so you don't need to write or memorise any command lines. There are also many options for H264 in MeGUI.
For "lossless cutting video clips", I guess you mean "cutting without re-encoding", the best to use is MKVToolnix, or VirtualDubMod (which is very old but still useful).
Cropping is not recommended. You should leave them as original. Even you cut "black bars" on the top and bottom, you will see them again on your TV.
Croppings also make "a small zoom" on the video, that zooming reduces the quality. -
No it is not necessary, you specifying those additional parameters to better control your encoding so you can be closer to final expectations but even guide you provided recommend to avoid ABR (from my perspective this is not ABR but just bitrate) mode - you control encoder by specifying what is your goal.
For this and in many earlier threads you started it is not entirely clear what is your goal.
If you trying to get some knowledge then do experiments - you not pay for anything except electricity... -
Anonymous543Guest
after reading this
https://slhck.info/video/2017/03/01/rate-control.html
my input has only video stream
firstly i tried Average Bitrate (ABR, also “target bitrate”) method with this code
Code:ffmpeg -i input.mp4 -vf scale=426:240 -c:v libx264 -preset ultrafast -b:v 260k output260k.mp4
[Attachment 63215 - Click to enlarge]
after that i tried Constrained Encoding (VBV) method with this code
Code:ffmpeg -i input.mp4 -vf scale=426:240 -c:v libx264 -preset ultrafast -b:v 260k -maxrate 260k -bufsize 520k output.mp4
during encoding its bitrate never goes higher then 260k
what is the major advantage and disadvantages of Average Bitrate (ABR, also “target bitrate”) method and Constrained Encoding (VBV) method
trough experiment i know that in constrained encoding bitrate doesnot goes higher then maxrate but dont know what is the role of bufsize??
when to use Average Bitrate (ABR, also “target bitrate”) method?? and also
when to use Constrained Encoding (VBV) method??
currently i have very low specification computer thats why i used ultrafast preset with higher bitrate you can check my pc specifications in my profile..Last edited by Anonymous543; 7th Feb 2022 at 01:49.
-
I saw that you use a gui to crop. You can crop with ffmpeg by first using -vf cropdetect til you get useful values and then run again with -vf crop.
For one-pass average bitrate, your best bet is what you were using -b:v
As mentioned above MeGUI is quite good for your purposes, Handbrake is fine but has to be tweaked from it's preset values, Staxrip does a really good job at a GUI, Hybrid does everything but has a learning curve, RipBot is great as well, but I've found it to be unstable sometimes.Last edited by blud7; 7th Feb 2022 at 10:10.
-
Go for baseline not high profile if your computer is slow or you can turn off CABAC in high profile... i would personally use preset 'faster' - this is more or less inline with some reports for example https://unrealaussies.com/tech/x264-presets-and-settings-quality-analysis-of-720p60-apex-legends/ - turning off CABAC you will loose few % but playout should be improved, you may try to turn off some other features - beware that provided link refer to computer graphics - this may be not entirely inline with regular movies.
try this one - 426 is not dividable by 16 - allow encoder to breathe... sometimes scenes need more bits - see no audio settings
Code:ffmpeg -i input.mp4 -vf scale=432:-2 -c:v libx264 -preset ultrafast -b:v 260k -maxrate 390k -bufsize 390k output.mp4
Last edited by pandy; 7th Feb 2022 at 14:32.
-
Anonymous543Guest
playback on my pc isnt problem..my computer can play videos smothly which is encoded at high profiles
but it should be in under 720p resolution...
main problem is encoding speed is too loww..and thats why i use ultrafast preset with libx264 codec which actually automaticaly selects constrained baseline video profile...thats why output video only contains I and P frames (no Bframes because constrained baseline profile doesnot supports Bframes i guess)
i can go for higher bitrates to preserve quality of video and encoding speeds in constrained baseline profile
but the question is which method shall i use for speedy encodes
Average Bitrate (ABR, also “target bitrate”) method with only specifying -b:v
or
Constrained Encoding (VBV) method which requires additional settings whihch is -b:v -minrate -maxrate -bufsize etc
and also i dont know properly how this -minrate -maxrate -bufsize affects the video quality
Theoretically if i encode a video with both methods at same bitrate and same settings then which one will give better visaul quality??
Practically it's too difficult (impossible)to know which one is giving better qualityLast edited by Anonymous543; 8th Feb 2022 at 02:11.
-
Best quality results are with CRF, you can add maxbitrate and buffer size to cap (limit) variability of bitrate.
Buffer size IMHO should be around 1 second for max bitrate (but some people may disagree with this) i.e. maxbitrate = buffsize - alternatively you may try to use GOP length (or rather GOP/fps) to shape buffer size but then i would avoid anything higher than 5 seconds (once again other may disagree).
IMHO most important baseline limitation beside to B frames is lack of CABAC - if your playout is OK then i would use B frames and CABAC - both are substantial features and quality benefits are obvious (both saving bitrate).
It is unavoidable - video compression is computationally intensive task - if your GPU support HW video compression (IMHO best video compression in HW is offered by NVidia) then you can use dedicated HW for much faster compression (albeit reduced quality and/or increased bitrate).
All above is purely my opinion and it doesn't try to address your playout environment (such as screen type and size, content etc).Last edited by pandy; 10th Feb 2022 at 12:24.
-
Anonymous543Guestbut the question is which method shall i use for speedy encodes
Average Bitrate (ABR, also “target bitrate”) method with only specifying -b:v
or
Constrained Encoding (VBV) method which requires additional settings whihch is -b:v -minrate -maxrate -bufsize etc
and also i dont know properly how this -minrate -maxrate -bufsize affects the video quality
Theoretically if i encode a video with both methods at same bitrate and same settings then which one will give better visaul quality??
Practically it's too difficult (impossible)to know which one is giving better quality
still this question is unanswered ,may be only the developers of x264 can know who will perform well ABR or constrained(VBV)
where file quality is detemined by bitrate(filesize) not with CRF. -
Abr delivers the worst quality. Use 2-pass vbr or crf.
There's no reason to constrain bitrate unless you have hardware limitations (for example, Blu-ray) or streaming limitations (where you may want to limit peaks and buffer size).
Presets ultrafast and superfast typically require ~2x more bitrate than veryfast or above. Avoid using them unless you can afford the extra bitrate or are constrained by realtime encoding. -
Anonymous543Guest
So..for offline usage ABR is used and for streaming purposes constrained bitrate used??
-
ABR with constraints is used for live broadcast/streaming -- it's live so you can't do two passes and you usually have bitrate constraints. Use CRF or 2-pass with everything else.
With ABR the encoder doesn't know what's coming in the future (aside from the small lookahead buffer) and doesn't have a memory of what happened in the past. So it can't allocate bits optimally over an entire video. It just uses some conservative settings to keep the bitrate in the right ballpark for the small piece of video it's currently working on. Easily compressed portions of the video will end up with more bitrate than they need. Hard to compress sections will end up with less than they need.
CRF encoding just compresses each frame with the quality you specify. It doesn't care about bitrate.
2-pass encoding examines every frame during the first pass, determining how much bitrate each needs (it uses a CRF encoding for this). Then during the second pass it allocates bits to each frame based on that need and the overall average bitrate you specified.
Use ABR encoding for live encoding. Use CRF encoding when you want a specific quality but don't care about the exact file size. Use 2-pass encoding when you need a specific file size but don't care about quality. -
-
It's both an encoding and decoding issue. The only time you care about the buffer size is when you must conform to some playback limitations. For example, Blu-ray players have a limited amount of memory so you need to limit the buffer size while encoding -- so as not to overflow that memory while decoding.
Last edited by jagabo; 11th Feb 2022 at 20:54.
-
Anonymous543Guest
As if i only specify -b:v without specifying -bufsize then will any default bufsize will be used??
Similar Threads
-
ffmpeg h264 guide related
By Anonymous543 in forum Newbie / General discussionsReplies: 10Last Post: 16th Dec 2021, 07:24 -
HEVC and H264 bitrate/quality equivalency
By philvideofilm in forum Video ConversionReplies: 15Last Post: 29th Sep 2017, 18:41 -
Giving a video file a higher average bitrate than it actually is?
By Chibi in forum EditingReplies: 4Last Post: 5th Sep 2017, 22:51 -
Can we decode H264 in ffmpeg?
By nothingnew in forum Newbie / General discussionsReplies: 22Last Post: 18th Aug 2017, 03:47 -
ffmpeg hardware encoding H264
By marcorocchini in forum Newbie / General discussionsReplies: 53Last Post: 21st Jul 2017, 12:54