x264-High quality H.

Source: Internet
Author: User
Tags types of filters

Transferred from: http://www.5i01.cn/topicdetail.php?f=510&t=3735840&r=18&last=48592660

H.264/mpeg-4 AVC is an excellent video encoding format
As far as the mature video encoding format is concerned, the compression ratio is the best.
The compression rate is extremely high and can be used with very low bitrate to provide degraded image quality.

And x264 is the free open source code of the H.264/mpeg-4 AVC encoder,
is currently the most efficient encoding of open source code H.

This article is only a basic knowledge, the description is only a rough.

H.264:wiki
x264: Official website, Wiki


Index:
#1F: Download, basic parameter setting
#2F: GUI-graphical interface Tool interface Introduction
#3F: CLI-command-line interface using teachings
#4F: Cli-ffmpeg with libx264
#5F: Other x264 (CLI)-compiled version
#6F: Compatible encoding parameters for common devices


H. Profiles
Baseline profile (BP)
Primarily for low-cost applications, performance requirements for playback devices are not high, and this profile is common for mobile devices with lower performance (such as Apple ipods). The performance of today's mobile devices is much more powerful than it used to be, and this profile is no longer necessary.

Main profile (MP)
This profile was originally used for SD-resolution digital TV broadcasts, although not implemented, but was used in HD resolution TV broadcasts. This profile is no longer necessary after the 2004 high profile was developed.
Early high-performance action playback devices such as Sony PSP are also used with this profile.

High profile (HiP)
Currently the most widely used profile, it is HD resolution TV applications (such as BLU-RAY/AVCHD CD storage, game consoles and other TV multimedia players, HDTV DVB Broadcasting Service).
Today's mobile playback devices can be smoothly played with this profile SD resolution movie, the middle level can be on the 720p resolution, higher order or even on the FULLHD (soft solution may be a bit difficult, hard solution completely no problem).

High profile (hi10p)
Beyond the current mainstream consumer product capabilities, this profile is based on high profiles, more than the accuracy of support, more accurate color.
In the case of film suppression, the high profile (8 bit) film is re-encoded to the output of H. 8, although the color accuracy does not change, but at least the compression rate is higher than the output of the highest profile (a bit).

High 4:2:2 profile (hi422p)
For professional applications, this profile is built on high-profile, with support for 4:2:2 color sampling and bit depth of up to ten bits.

High 4:4:4 Predictive profile (hi444pp)
This profile is built on top of high 4:2:2 profiles and supports 4:4:4 color sampling, bits depth up to a bit, and supports highly efficient lossless recoding with each screen encoded as three separate color planes.

PS. currently x264 of H. hi444p only supports 8-10 bit

Detailed information (Wiki)


h Frame
The film is made up of many successive Frames, but not all Frames are complete images, and those Frames need to refer to other Frames to decode a complete picture.

There are three kinds of Frame types: I, B and P.

I-frame:
No need to refer to other Frames, is a full picture.

I-frame (IDR):
No need to refer to other Frames, is a full picture.
IDR frame for the true key scribe (keyframes),
P-frame & B-frame will not cross IDR frame to refer to other Frames,
So you can jump to any IDR frame to start playing/decoding without problems.

P-frame:
Only the blocks that are different from the previous Frames are recorded and can refer to the Frames before "16 photos".
When playing/decoding, we need to use some data from the previous Frames to decode the complete picture.
In x264, you can't control the number of p-frame, but you can control the number of frames a p-frame can refer to,
The value of Reference frame (ref).

B-frame:
Only the blocks that differ from the previous Frames are recorded, with a high compression rate (which is a film with low dynamic/low variations),
Play/decode need to use the front and back two pieces of Frames data, to decode the full picture.

(You can view the image after logging in)
From this figure you can see b-frame useful to the previous and the next Frame of the data.

The order in which the Farme is played is in accordance with the frame's point in time, but the decoding order is not necessarily
When B-frame is useful to the latter frame's data, it must be pre-decoded to a frame.
Consider an example
decoding (processing) Order: 1-2-4-3
Display (play) Order: 1-2-3-4

Since P-/b-frame is not a complete picture, the decoding must refer to other Frames,
So you can't jump to play/decode on P-/b-frame.
That is, if you play the MPEG video format, when you jump to play the point of time,
Normally, it does not jump to the point of time you choose, but rather the most recent idr/i-frame.


In terms of compression ratio ...
Since P-/b-frame is not a complete picture, it takes up less data,
Increasing this type of Frame usage can increase the compression rate, but the image quality will hardly decrease,
This means that a few bitrate (bit rate) can be used to maintain a certain picture quality.

It is learned from the above that, in the case of sufficient bitrate, there is no need to use more b-frame, Reference frame (ref),
How many bitrate for sufficient depending on the content of the film, high-dynamic film needs more bitrate, low-moving is less.

As for the time of use ...
Increasing b-frame/ref usage can reduce bitrate demand and achieve target quality with less bitrate.
Low dynamic film can use more b-frame, high dynamic or pure static is p-frame effect is better.

For compatibility and hardware burden ...
The side effects of increasing b-frame/ref usage are reduced compatibility and increased hardware burden, please ensure compatibility before the pursuit of compression ratio.
And the side effect of ref is stronger than b-frame, for example ref=16 this means decoding a p-frame must even jump back to 1~16 before the Frames access data.


x264 parameter Setting

Maximun b-frame:
When the B-frame is set, the number of repetitions/changes less Frames will be encoded as B-frame
This value limits the maximum number of consecutive b-frame.

Reference frame (ref):
Sets the number of Frames that a p-frame can refer to.
Ref affects playback compatibility, please refer to section H.

Recommended settings
? Reference frame (ref): 3-5
? Maximun B-frame:3-6

GOP Length:
A keyframe (IDR frame) to the next Keyframe range.
So the GOP is set to infinity although it can greatly increase the compression rate, but it is not free to jump to other time-point play/decode.
It is recommended that you maintain the default.


H. A (x264)
The higher the profile, the higher the compression rate, but the higher the coding complexity, the higher the performance requirements for the playback hardware.

The x264 supports the output of H:
Baseline, Main, high, High10, high422, high444

There is no special need to use high profile.

If the output profile cannot be specified directly, the parameter values can be set manually.

Parameters of H.

ps. empty field represents unlimited
Full form (Wiki, drop down to Profiles bottom)


Parameter description:

Bframes (number of B-frames):
Sets the maximum number of consecutive b-frames between I-frame P-frame.

CQM (custom quantization matrices):
Set all custom quantization matrices (named quantization matrices) as one of the built-in defaults. The built-in defaults are flat and JVT.

WEIGHTP (Explicit weighted prediction):
Enables x264 to use explicit weighted forecasts (explicit weighted prediction) to improve the compression rate of p-frame. It also improves the quality of fade in/fade out. The higher the pattern, the slower it becomes.

8X8DCT (Adaptive 8x8 DCT):
The elastic 8x8 discrete cosine transform (DCT) enables the x264 to use I-frame's 8x8 conversion flexibly.

Cabac (cabac:context Adaptive Binary arithmetic coder):
Elastic content binary arithmetic encodes data stream compression, disabling CABAC switches back to less efficient elastic content with variable length encoding (cavlc:context Adaptive Variable length coder) system. Significantly reduces compression efficiency (typically 10~20%) and decoding hardware requirements.

Interlaced:
Support for encoded output interlaced video.


x264 Preset
Preset is a collection of options, which sets the encoding speed to determine the compression ratio. The slower the speed, the better the compression coding efficiency (image quality-bit rate ratio or image quality-file size ratio). In other words, if you set a target bit rate or file size, the slower the Preset will get better output quality. For setting a constant quality (CRF) or constant quantization value (QP), you can simply save bit rate (i.e. get smaller file size) by choosing a slower Preset.

Generally, use the slowest Preset you can endure. The current presets by speed descending order is: ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow, placebo. The default Preset is medium. Ignore placebo because it wastes more time than veryslow and the effects are too small.

The slower the Preset, the higher the Reference frame (ref) value, for example, the ref of Veryslow Preset is 16. Since this is usually not required, you can limit ref by specifying a level, or manually specify a reasonable ref value (1 ~ 6).


x264 Tune
Fine-tune the parameter settings for a specific type of movie to get better quality or compression rates.

Film (film): Film film.
Animation (animation): such as cartoon/Japanese animation.
Grain (film Pellet): A film with a very grainy feel.
Still image (still image): A movie such as a slide effect.
PSNR: Optimizes the PSNR value. Wiki
Ssim: Optimizes the Ssim value. Wiki
Fast Decode (Quick decode): For low performance playback devices. (※ compression rate is very low)
Zero Latency (0 delay): Low latency at the time of the place. Mainly used for live broadcast and so on. (※ compression rate is very low)


h .
Level, Maxdpbmbs directly indicates the decoding performance requirements of the playback device.
The higher the value, the higher the decoding performance requirement for the playback device, and the higher the compression rate of the relative output movie

Maxdpbmbs the corresponding level


To illustrate:
Level 3.2:maxdpbmbs 20480 or less
Level 4.1:maxdpbmbs 32768 or less


Relationship equation:

Force specify level (limit maxdpbmbs), the
ref = Min (Floor (maxdpbmbs/(Picwidthinmbs * frameheightinmbs)), 16)

PS. 1. Floor (x): Take integers, small digital directly out. Ex. Floor (1.9) = 1
PS. 2. Min (x, y): Take a relatively small number. Ex. Min (2, 5) = 2

Force to specify ref, the
Maxdpbmbs = picwidthinmbs * Frameheightinmbs * ref

Picwidthinmbs = WIDTH/16
Frameheightinmbs = HEIGHT/16
(Fractional direct binary)

Example 1:
When I set the output to
? resolution:1280x1720
? Level: Not Specified (automatic)
? Reference frame (ref): 4

Then Maxdpbmbs = 80 * 45 * 4 = 14400
Level = 3.1 Compared to the table above

Example 2:
When the output is set to
? resolution:1280x1720
? level:3.1
? Reference frame (ref): Not Specified (automatic)

ref = MIN (Floor (18000/(+)) = min (Floor (5.0), h) = min (5, 16) = 5

Then the output of the ref can be 4 or 5.

If you want to force the designation of ref and level at the same time
The ref setting value cannot be greater than 5
(Force a restriction that specifies that ref cannot be greater than level)

Detailed description (Wiki)


x264 bitrate Control
Specify output quality: QP (VBR), CRF (VBR)
Specify output bitrate/File size: Single pass (ABR), 2-pass (VBR)

Typically, only two rate controls are used: Constant rates Factor (CRF) or 2-pass bitrate. Rate control refers to the method that determines how many bits will be used for each scribe. This determines the file size and how the quality is distributed. The distribution of the bit rate of CRF is the best, if there is no control output size need to use CRF can.

Constant Quantizer (QP)

Set the x264 to encode the video in a constant quantization value (Constant quantizer) mode. This method allows each scribe to have the same quality (set value).
The set value range is 0–69,0 and the default value is 23. Lower values will be higher quality, a reasonable range of 21-28.

Constant ratefactor (CRF)

This method allows the encoder to automatically allocate the bit rate to try to achieve a certain output quality. Let each scribe get the number of bits it needs to maintain the desired quality level. The CRF will get the best bit-rate allocation results, with the disadvantage that you cannot directly specify a target bit rate or file size.
The set value range is 0–51.0,0 to the highest quality, and the default value is 23. Lower values will be higher quality, a reasonable range of 18-28. Consider 18 as visually lossless (or near), so it should look the same as the input (or close) but it is technically not lossless.

bitrate

Custom bitrate control output Size, direct encoding output video. Without first scanning, x264 was unable to know the complexity of the film's time points. So x264 can only be in the coding of the complexity of the subsequent guessing, this will not be accurate according to the complexity of the time points and other proportional allocation of bit rate, because if the previous allocation of excessive traffic, then the traffic must be revised to make the output bit rate average equal to the user set value.

bitrate, 2-pass

This square Law encoder 1st-pass will be aware of the complexity of the film's various grids, 2nd-pass, according to the input video, the complexity of each scribe and other proportional allocation of bits output, and the final average bit rate will be equal to the set value. The 2-pass bit rate allocation results are close to the CRF, and the disadvantage is that it takes a lot of time.

1st-pass CRF + 2-pass bitrate

This square law encoder will know the number of bits required for each scribe in the 1st-pass, and the total average value of the final bit rate will be equal to the set value when the 2nd-pass is proportional to the number of bits required by each of the panes. The 2-pass bit rate allocation results are close to the CRF, and the disadvantage is that it takes a lot of time.


x264 Setting the priority level
Preset---Tune-user settings, fast first pass, profile, level

When a parameter conflicts, the latter will replace the former or affect the former

The parameters of the preset slower are:
--B-ADAPT 2--direct Auto--me UMH
--partitions All--rc-lookahead 60
--ref 8--SUBME 9--trellis 2

When I set:
? x264 Preset:slower
? Reference frame (ref): 4

Equivalent to:
--B-ADAPT 2--direct Auto--me UMH
--partitions All--rc-lookahead 60
--ref 4--SUBME 9--trellis 2

Output of H. Reference Frame (ref) is 4

When I set
? x264 Preset:slower
? level:3.2

Output of H. Reference Frame (ref) is 5
(Please refer to the "H. Level" section above)


References
Wiki/h.264/mpeg-4_avc
nmm-x264 settings
http://www.cnblogs.com/zyl910/archive/2011/12/04/x264_presets.html no graphic kingdragon2014-02-05 13:07 #2
    • Private message
    • Link
GUI (graphical Interface) tool interface Introduction

The following are ranked by recommended level (the more front the more recommended)

1. Vidcoder
Link: homepage/downloads

(You can view the image after logging in)

2. Handbrake
Link: homepage/downloads

(You can view the image after logging in)

3. MeGUI
Link: homepage/downloads

(You can view the image after logging in)



No graphic kingdragon2014-02-05 13:07 #3
    • Private message
    • Link
CLI (Command-line interface) using teachings

The CLI interface must be used with basic CMD

CLI Usage Notes: here
CMD Introductory Tutorial: here

----------------------------------------------------------------

Basic Usage

Basic syntax:
x264 [Setting options]-o < output > < input >


You can use raw input,
or Yuv4mpeg (*.y4m)
or AviSynth (*.avs, requires a supported version of the code)
or LAVF/FFMS supported input format

Select the output file format according to the specified file name:
. ByteStream Raw
. mkv-Matroska
. flv, Flash Video
. MP4-MP4 (requires a compiled version of GPAC)

Ex. 1.
x264--CRF 20-o output.mkv input.m2ts

Ex. 2.
x264--profile High--preset veryslow--CRF--ref 4--bframes 5-o output.mp4 input.m2ts


----------------------------------------------------------------

bitrate Control

Specify bitrate:--bitrate,-B
Specify quality (CRF):--CRF
Specify Quality (QP):--QP

Custom bitrate (ABR):
x264 [SET options]-B 1000-o < output > < input >

Custom bitrate, 2-pass (VBR):
x264 [SET options]-p 1-b 1000-o < output > < input >
x264 [SET options]-p 2-b 1000-o < output > < input >

Constant Quantizer (QP):
x264 [Setting options]--QP 20-o < output > < input >

Constant Ratefactor (CRF):
x264 [Setting options]--CRF 20-o < output > < input >

1st pass CRF + 2nd pass bitrate:
X264-P1--stat "Xxx.stat"--CRF--slow-firstpass [setting options]-o < output > < input >
X264-P2--stat "Xxx.stat"-B 1000 [setting options]-o < output > < input >


If you are not satisfied with the output file size, then use 2-pass bitrate correction
If the file size meets the requirement, no 2-pass is required bitrate

※1-pass must be used--slow-firstpass

----------------------------------------------------------------

Filtering

--VF,--video-filter <filter0>/<filter1>/...

Filter options specified in <filter>:<option>=<value> format.

There are currently only three types of filters in the official edition
crop:left,top,right,bottomresize:[width,height][,sar][,fittobox][,csp][,method]select_every:step,offset1[,...]

Other compiled version common filters
Hqdn3d:ls,cs,lt,ctpad:[left][,top][,right][,bottom][,width][,height][,red][,green][,blue]yadif:[mode][,order]


For details, please refer to
x264--Fullhelp


Syntax 1:
--VF Crop:0,140,0,140/resize:width=1280,fittobox=width,method=lanczos

Syntax 2:
--VF crop:0,140,0,140/resize:1280,,, Width,,lanczos



Resize Example:

Ex. 1280x720 (PAR 1:1, DAR 16:9)
--VF resize:width=720,height=480,sar=1:1

Ex. 1280xH (mod 2)
--VF Resize:width=720,fittobox=width

Ex. Letterbox, 720x480, PAR 40:33
--VF resize:width=720,height=480,sar=40:33,fittobox=both/pad:width=720,height=480


---------------------------------------------------------------

Frame Rate

x264 change FPS does not discard or fill Frames length of time and video sync
If you need this feature, you can use AviSynth to enter or FFmpeg

Example:

If you determine that the input is CFR, force the output CFR
x264 [Setting options]--force-cfr-o < output > < input >

Force specified fps (cfr:23.976 fps)
x264 [Setting options]--fps 23.976-o < output > < input >

Force specified fps (cfr:24000/1001 fps)
x264 [Setting options]--fps 24000/1001-o < output > < input >

Mandatory designation of Timebase
x264 [Setting options]--timebase 1001/24000-o < output > < input >

Using timecode to control output fps
x264 [Setting options]--tcfile-in Timecode.txt-o < output > < input >

To designate the timebase of timecode.
x264 [Setting options]--timebase 1001--tcfile-in timecode.txt-o < output > < input >


If the input is VFR, the output video is Raw ByteStream
You can export the timecode of the input movie to muxer/remuxer for use

Output timecode
x264 [Setting options]--tcfile-out Timecode.txt-o < output > < input >


---------------------------------------------------------------

Piping

Pipe A to B
A program [parameters] | b program [parameters]

The output parameter of a is written with the "value" of the input parameter of B "-"
※ Note that the Edge decoding tool supports piping

If you need to use FFmpeg's decoder/filters

Pipe FFmpeg to x264
Ffmpeg-i input.mkv [Setting options]-F yuv4mpegpipe-| x264 [Setting options]--demuxer Y4m-o < output >-


FFmpeg has a compiled version containing x264, Rui no special needs directly using a single FFmpeg can

x264 version 64bit cannot be used AviSynth (32bit)
Use AviSynth 64bit or try the following methods

Pipe FFmpeg (32bit) to x264
Ffmpeg-i < input AVS file >-F yuv4mpegpipe-| x264 [Setting options]--demuxer Y4m-o < output >-

Pipe AVS2YUV to x264
AVS2YUV < input AVS File >-| x264 [Setting options]--demuxer Y4m-o < output >-


---------------------------------------------------------------

RELATED LINKS

FFmpeg reference
Avs2yuv
Avs4x264mod no graphic kingdragon2014-02-05 13:07 #4
    • Private message
    • Link
Cli-ffmpeg with libx264

Basically, the FFmpeg built-in x264 is the same as the name of the X264.exe same parameter
Just a slight difference in the wording/rules

libx264 Options

----------------------------------------------------------------

Fan code example

x264 Sample Parameters: Profile High, preset veryslow, CRF, ref 4, Bframes 5

Ex1. Built-in x264 encoding
Ffmpeg-i input.mkv-an-c:v libx264-profile:v high-preset:v veryslow-crf 18-x264opts ref=4:bframes=5 output.mp4

Ex2. Built-in x264 code + copy Audio
Ffmpeg-i input.mkv-c:v libx264-profile:v high-preset:v veryslow-crf 18-x264opts ref=4:bframes=5-c:a copy Output.mp4

Ex3. Pipe FFmpeg to x264 (used when x264_10bit is required, otherwise superfluous)
Ffmpeg-i input.mkv-f Yuv4mpegpipe-| x264--profile:v High--preset:v veryslow--CRF--ref 4--bframes 5--demuxer y4m--O Output.mp4

x264 lossless Compression

Ex4. Built-in x264 lossless compression RGB24
FFmpeg-I  rgb24.mkv-pix_fmt bgr24-c:v libx264rgb-qp 0 output.mp4


----------------------------------------------------------------

Libx264 bit Rate control

Recommended CRF, if you need to control the output size, use 1-pass CRF + 2-pass bitrate

1. Constant ratefactor (CRF):
Ffmpeg-i blu_ray.m2ts-c:v libx264-crf 20-c:a copy output.mkv

Key parameters:-c:v LIBX264-CRF xx


2. Custom bitrate (ABR):
Ffmpeg-i blu_ray.m2ts-c:v libx264-b:v 1000k-c:a copy output.mkv

Key parameters:-c:v libx264-b:v xxxk


3. Custom bitrate, 2-pass (VBR):
: 1st-passffmpeg-i blu_ray.m2ts-an-pass 1-passlogfile text.log-fastfirstpass 0-c:v libx264-b:v 1000k-f null-:2rd-p Assffmpeg-i blu_ray.m2ts-pass 2-passlogfile text.log-c:v libx264-b:v 1000k-c:a copy output.mkv

Key parameters:-pass n-passlogfile xxx.log-c:v libx264-b:v xxxk


4.1st Pass CRF + 2nd pass bitrate:

Because the bitrate distribution method of CRF is the best
In order for 2-pass to refer to the bitrate allocation method of the CRF
The same effect as the CRF, more 2-pass can be corrected output size

Step 1:1-pass CRF
Ffmpeg-i blu_ray.m2ts-an-pass 1-passlogfile text.log-fastfirstpass 0-c:v libx264-crf 20-f null-

Step 2:2-pass Bitrate
Ffmpeg-i blu_ray.m2ts-pass 2-passlogfile text.log-c:v libx264-b:v 1000k-c:a copy output.mkv

Key parameters (1):-pass 1-passlogfile xxx.log-c:v LIBX264-CRF xx
Key parameters (2):-pass 2-passlogfile xxx.log-c:v libx264-b:v xxxk

In "Step 1:1-pass CRF" You can set the output file
If you are not satisfied with the output file size, then use 2-pass bitrate correction
If the file size meets the requirement, no 2-pass bitrate is required kingdragon2014-02-09 13:08 #5
    • Private message
    • Link
other x264 compiled version

For details, please download and use x264--fullhelp

1. x264.nl
http://mirror01.x264.nl/

2. X264kmod
http://komisar.gin.by/

3. [Email protected]
http://pop.4-bit.jp/
http://pop.4-bit.jp/bin/x264/
To block Japan's foreign IPs, you need to use a proxy server

4. X264tmod
http://www.nmm-hd.org/newbbs/viewtopic.php?f=8&t=219
This compiled version is more Vsfilter

x264-High quality H.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.