Skip to content

Commit 947fac7

Browse files
committed
Split lines better
1 parent 06c55f5 commit 947fac7

File tree

1 file changed

+73
-40
lines changed

1 file changed

+73
-40
lines changed

encoding/codecs/x264.md

Lines changed: 73 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
H.264 has been the de facto standard video format
44
across the internet for the past decade.
55
It is widely supported for playback in all modern browsers
6-
and many hardware devices such as gaming consoles.
6+
and many hardware devices such as gaming consoles and phones.
77
It provides better video quality at smaller file sizes
88
compared to its predecessors.
99

@@ -17,8 +17,8 @@ To get started, you'll need two things:
1717

1818
- A video to encode--for the examples,
1919
we will pipe in a video from VapourSynth,
20-
which you should be able to do if you've been following
21-
the previous sections of this guide
20+
which you should be able to do
21+
if you've been following the previous sections of this guide
2222
- The x264 encoder
2323

2424
Here's how we get a copy of the x264 encoder:
@@ -39,15 +39,19 @@ Here are a few examples:
3939

4040
## Getting Started
4141

42-
x264 is very configurable, and the options may seem overwhelming.
43-
But you can get started encoding by using the presets x264 provides
42+
x264 is very configurable,
43+
and the options may seem overwhelming.
44+
But you can get started encoding
45+
by using the presets x264 provides
4446
and understanding a few basic concepts.
45-
We'll walk through those concepts with the following examples.
47+
We'll walk through those concepts
48+
with the following examples.
4649

4750
## Example 1
4851

4952
Open up a terminal window,
50-
and navigate to the folder where your VapourSynth script lives.
53+
and navigate to the folder
54+
where your VapourSynth script lives.
5155
Let's run the following command:
5256

5357
`vspipe --y4m myvideo.vpy - | x264 --demuxer y4m --preset veryfast --tune animation --crf 24 -o x264output.mkv -`
@@ -56,22 +60,27 @@ Let's run through what each of these options means:
5660

5761
#### `vspipe --y4m myvideo.vpy -`
5862

59-
This portion loads your VapourSynth script and pipes it to stdout,
63+
This portion loads your VapourSynth script
64+
and pipes it to stdout,
6065
adding y4m headers that x264 can decode.
61-
If you use Linux, you're probably familiar with how piping works.
62-
If you're not, it's basically a way of chaining two commands together.
66+
If you use Linux,
67+
you're probably familiar with how piping works.
68+
If you're not,
69+
it's basically a way of chaining two commands together.
6370
In this case, we want to chain `vspipe`,
6471
the program that reads VapourSynth scripts,
6572
with x264, our encoder.
6673

6774
#### `--demuxer y4m`
6875

6976
This tells x264 that we're providing it with a y4m file.
70-
This matches up with the `--y4m` flag that we gave to the `vspipe` command.
77+
This matches up with the `--y4m` flag
78+
that we gave to the `vspipe` command.
7179

7280
#### `--preset veryfast`
7381

74-
x264 has a set of presets to switch between faster encoding, or higher quality.
82+
x264 has a set of presets
83+
to switch between faster encoding, or higher quality.
7584
The full list of presets, from fastest to slowest, is:
7685

7786
- ultrafast
@@ -89,13 +98,17 @@ You will almost never want to use the very extreme settings,
8998
but generally, if you want good quality
9099
and don't care about how long the encode takes,
91100
`slower` or `veryslow` are recommended.
92-
In this example, because we are just demonstrating how x264 works,
101+
In this example,
102+
because we are just demonstrating how x264 works,
93103
we want a fast encode and have chosen `veryfast`.
94104

95-
For the curious, you can see a full list of the settings
96-
enabled by each preset by running `x264 --fullhelp | less`.
105+
For the curious,
106+
you can see a full list of the settings enabled by each preset
107+
by running `x264 --fullhelp | less`.
97108
However, this probably won't mean much at the moment.
98-
Don't worry, this guide will explain later what all of those settings mean.
109+
Don't worry,
110+
this guide will explain later
111+
what all of those settings mean.
99112

100113
#### `--tune animation`
101114

@@ -111,7 +124,8 @@ The following tunings are generally the most useful:
111124
- `grain`: Recommended for particularly grainy films.
112125

113126
You don't need to use a tuning,
114-
but it generally helps to produce a better-looking video.
127+
but it generally helps
128+
to produce a better-looking video.
115129

116130
#### `--crf 24`
117131

@@ -120,25 +134,30 @@ In layman's terms,
120134
this means that we don't need the output to meet a specific filesize,
121135
we just want the output to meet a certain quality level.
122136
CRF ranges from 0 to 51,
123-
with 0 being the best quality and 51 being the smallest filesize,
137+
with 0 being the best quality
138+
and 51 being the smallest filesize,
124139
but there is a certain range of CRF settings
125140
that are generally most useful.
126141
Here are some guidelines:
127142

128143
- CRF 13: This is considered visually lossless to videophiles.
129144
This can produce rather large files,
130145
but is a good choice if you want high quality videos.
131-
Fansubbing groups often use this for Blu-ray encodes.
146+
Some fansubbing groups use this for Blu-ray encodes.
132147
- CRF 16-18: This is considered visually lossless to most viewers,
133-
and leans toward high quality while still providing a reasonable filesize.
148+
and leans toward high quality
149+
while still providing a reasonable filesize.
134150
This is a typical range for fansub encodes.
135151
- CRF 21-24: This provides a good balance between quality and filesize.
136-
Some quality loss becomes visible, but this is generally a good choice
137-
where filesize becomes a concern, such as for videos viewed over the internet.
138-
- CRF 26-30: This prioritizes filesize, and quality loss becomes more obvious.
139-
It is generally not recommended to go higher than CRF 30 in any real-world
140-
encoding scenario, unless you want your videos to look like they were made
141-
for dial-up.
152+
Some quality loss becomes visible,
153+
but this is generally a good choice
154+
where filesize becomes a concern,
155+
such as for videos viewed over the internet.
156+
- CRF 26-30: This prioritizes filesize,
157+
and quality loss becomes more obvious.
158+
It is generally not recommended to go higher than CRF 30
159+
in any real-world encoding scenario,
160+
unless you want your videos to look like they were made for dial-up.
142161

143162
#### `-o x264output.mkv -`
144163

@@ -153,15 +172,21 @@ which tells x264 to use the piped output from vspipe.
153172

154173
## Example 2
155174

156-
For the next example, let's say we want to make sure our encode
157-
fits onto a single 4.7GB DVD. How would we do that in x264?
175+
For the next example,
176+
let's say we want to make sure our encode
177+
fits onto a single 4.7GB DVD.
178+
How would we do that in x264?
158179

159-
First, we'll need to figure out what bitrate our encode should be,
160-
in **kilobits per second**. This means we'll need to know a couple of things:
180+
First, we'll need to figure out
181+
what bitrate our encode should be,
182+
in **kilobits per second**.
183+
This means we'll need to know a couple of things:
161184

162185
- The length of our video, in seconds.
163-
For this example, let's say our movie is 2 hours (120 minutes) long.
164-
We'll convert that to seconds: 120 \* 60 = **7200 seconds**.
186+
For this example,
187+
let's say our movie is 2 hours (120 minutes) long.
188+
We'll convert that to seconds:
189+
120 \* 60 = **7200 seconds**.
165190
- Our target filesize.
166191
We know that this is 4.7GB,
167192
but we need to convert it to kilobits.
@@ -183,24 +208,30 @@ The `--bitrate` option, by itself,
183208
says that we want to do a 1-pass, average-bitrate encode.
184209
In other words, the encoder will still give more bits
185210
to sections of the video that have more detail or motion,
186-
but the average bitrate of the video will be close to what we requested.
211+
but the average bitrate of the video
212+
will be close to what we requested.
187213

188214
## Example 3
189215

190216
So far, we've only done 1-pass encodes.
191-
While using CRF 1-pass is great when you don't have a target bitrate,
192-
it's recommended not to use 1-pass for targeted-bitrate encodes,
217+
While using CRF 1-pass is great
218+
when you don't have a target bitrate,
219+
it's recommended not to use 1-pass
220+
for targeted-bitrate encodes,
193221
because the encoder can't know
194222
what's coming ahead of the current section of video.
195223
This means it can't make good decisions
196224
about what parts of the video need the most bitrate.
197225

198-
How do we fix this? x264 supports what is known as 2-pass encoding.
226+
How do we fix this?
227+
x264 supports what is known as 2-pass encoding.
199228
In 2-pass mode, x264 runs through the video twice,
200-
the first time analyzing it to determine where to place keyframes
229+
the first time analyzing it
230+
to determine where to place keyframes
201231
and which sections of video need the most bitrate,
202232
and the second time performing the actual encode.
203-
2-pass mode is highly recommended if you need to target a certain bitrate.
233+
2-pass mode is highly recommended
234+
if you need to target a certain bitrate.
204235

205236
Here's how we would run our first pass:
206237

@@ -214,8 +245,10 @@ which x264 will use in the second pass:
214245
You'll notice all we had to change was `--pass 1` to `--pass 2`. Simple!
215246

216247
Although x264 will automatically use faster settings for the first pass,
217-
it should be no surprise that 2-pass encoding is slower than 1-pass encoding.
218-
Therefore, there are still certain use cases where 1-pass, bitrate-targeted video
248+
it should be no surprise
249+
that 2-pass encoding is slower than 1-pass encoding.
250+
Therefore, there are still certain use cases
251+
where 1-pass, bitrate-targeted video
219252
is a good fit, such as streaming.
220253

221254
## Recap

0 commit comments

Comments
 (0)