video_transcoding 0.21.2 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +45 -65
- data/bin/transcode-video +26 -6
- data/lib/video_transcoding/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ec7d9f2674f60b914a959df7c76debc47249ae57b925606b1d2ca86937a6f35
|
4
|
+
data.tar.gz: 5db202054bf388c995005cd9752ae6203551e2aec5680acbdb3a887b5d1d38ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27dc2c42fee463759a08d50bafe115d43b42a904cb89ff9e9cd0fe59bb8be14f98bbd3f6cd23a08b7b40952191ee5c1f6f5d47c539f9fd178f929203a76b35c6
|
7
|
+
data.tar.gz: 548d0b737f9d976daf3a5e4f710837b0c2a807cead897b0d2c7ee7eed2509fdd1ca0044595c1b41fa29d90ecfaaf2f43d71503ae541f6b7df2074169eca62ca9
|
data/README.md
CHANGED
@@ -6,7 +6,7 @@ Tools to transcode, inspect and convert videos.
|
|
6
6
|
|
7
7
|
Hi, I'm [Don Melton](http://donmelton.com/). I created these tools to transcode my collection of Blu-ray Discs and DVDs into a smaller, more portable format while remaining high enough quality to be mistaken for the originals.
|
8
8
|
|
9
|
-
What makes these tools unique are the [
|
9
|
+
What makes these tools unique are the [ratecontrol systems](#explanation) which achieve those goals.
|
10
10
|
|
11
11
|
This package is based on my original collection of [Video Transcoding Scripts](https://github.com/donmelton/video-transcoding-scripts) written in Bash. While still available online, those scripts are no longer in active development. Users are encouraged to install this Ruby Gem instead.
|
12
12
|
|
@@ -559,83 +559,49 @@ These examples are written in Bash and only supply crop values. But almost any s
|
|
559
559
|
|
560
560
|
## Explanation
|
561
561
|
|
562
|
-
###
|
562
|
+
### Ratecontrol systems
|
563
563
|
|
564
|
-
What is a ratecontrol
|
564
|
+
What is a ratecontrol system? It's how a video encoder decides on the amount of bits to allocate for a specific frame.
|
565
565
|
|
566
|
-
My `transcode-video` tool has
|
566
|
+
My `transcode-video` tool has three different ratecontrol systems which manipulate the x264 and x265 software-based video encoders built into `HandBrakeCLI`.
|
567
567
|
|
568
|
-
|
568
|
+
Additionally, `transcode-video` allows access to hardware-based video encoders which have their own ratecontrol systems.
|
569
569
|
|
570
|
-
|
570
|
+
All of these ratecontrol systems, mine and those built into hardware, target a specific video bitrate.
|
571
571
|
|
572
|
-
|
572
|
+
The target video bitrate for all of these systems is automatically determined by `transcode-video` using the resolution of the input. For example, the default target for 1080p output is `6000` Kbps, which is about one-fifth the video bitrate found on a typical Blu-ray Disc.
|
573
573
|
|
574
|
-
|
574
|
+
### How my simple and special ratecontrol systems work
|
575
575
|
|
576
|
-
|
576
|
+
My simple and special ratecontrol systems attempt to produce the highest possible video quality near a target bitrate using a constant ratefactor (CRF) to specify quality. A CRF is represented by a number from `0` to `51` with lower values indicating higher quality. The special value of `0` is for lossless output.
|
577
577
|
|
578
|
-
|
579
|
-
|
580
|
-
When using `transcode-video`, you might notice two lines in the console output containing something like this:
|
581
|
-
|
582
|
-
```
|
583
|
-
options: vbv-maxrate=6000:vbv-bufsize=12000:crf-max=25:qpmax=34
|
584
|
-
|
585
|
-
quality: 1.00 (RF)
|
586
|
-
```
|
587
|
-
|
588
|
-
These are actually the settings used by my special ratecontrol system to configure the x264 video encoder within HandBrake.
|
589
|
-
|
590
|
-
This system attempts to produce the highest possible video quality near a target bitrate using a constant ratefactor (CRF) to specify quality. A CRF is represented by a number from `0` to `51` with lower values indicating higher quality. The special value of `0` is for lossless output.
|
591
|
-
|
592
|
-
Unfortunately, the output bitrate is extremely unpredictable when using the x264's default CRF-based system. Typically, people pick a middle-level CRF value as their quality target and just hope for the best. This is what most of the presets built into HandBrake do, choosing a CRF of `20` or `22`.
|
578
|
+
Unfortunately, the output bitrate is extremely unpredictable when using the default CRF-based system in x264 or x265. Typically, people pick a middle-level CRF value as their quality target and just hope for the best. This is what most of the presets built into HandBrake do, choosing a CRF of `20` or `22`.
|
593
579
|
|
594
580
|
But such a strategy can result in output larger than its input or, worse, output too low in quality to be mistaken for that input.
|
595
581
|
|
596
|
-
So I set the target CRF value to `1`, the best possible "lossy" quality. Normally this would produce a huge output bitrate but I also
|
582
|
+
So I set the target CRF value to `1`, the best possible "lossy" quality. Normally this would produce a huge output bitrate but I also reduce the encoder's maximum bitrate to my target, e.g. `6000` Kbps for 1080p output, by manipulating an option called `vbv-maxrate`.
|
597
583
|
|
598
|
-
|
584
|
+
With this approach, the encoder chooses the lowest CRF value, and therefore the highest quality, which fits below that maximum bitrate ceiling, even if that's usually not a a CRF value of `1`.
|
599
585
|
|
600
|
-
|
586
|
+
And this fully describes the behavior of `transcode-video` when using the `--simple` option.
|
601
587
|
|
602
|
-
|
588
|
+
However, my special, or default, ratecontrol system also sets a maximum CRF (`crf-max`) value of `25`, raising the minimum quality. This allows `vbv-maxrate` to become a "soft" ceiling so that the output bitrate can exceed the target when necessary to maintain that quality.
|
603
589
|
|
604
|
-
|
590
|
+
Unfortunately, this internal tug of war can cause the encoder to sometimes generate a few very low quality frames.
|
605
591
|
|
606
|
-
|
607
|
-
|
608
|
-
As part of the encoding process, x264 calculates a quantizer value (QP) for each macroblock within a frame of video. A QP is represented by a number from `0` to `69` with lower values indicating higher quality.
|
592
|
+
As part of the encoding process, a quantizer value (QP) is calculated for each macroblock within a frame of video. A QP is represented by a number from `0` to `69` with lower values indicating higher quality.
|
609
593
|
|
610
594
|
So I set a maximum quantizer (`qpmax`) value of `34`, again raising the minimum quality. The occasional bad frame is still there, but it's no longer noticeable because it's now of sufficient quality to blend in with the others.
|
611
595
|
|
612
|
-
There's a final change required for the VBV model. I need to set the VBV buffer size (`vbv-bufsize`) so that my previous adjustment of `vbv-maxrate` is honored by x264. Otherwise the encoder will just ignore the VBV.
|
613
|
-
|
614
|
-
It's safe to set `vbv-bufsize` anywhere in the range from one half to twice that of `vbv-maxrate`. However, that larger `vbv-bufsize` value produces an output bitrate closest to, on average, that of the target. So, if `vbv-maxrate` is `6000` Kbps, then I set `vbv-bufsize` to `12000` Kbps.
|
615
|
-
|
616
596
|
### How my average bitrate (ABR) ratecontrol system works
|
617
597
|
|
618
|
-
|
619
|
-
|
620
|
-
```
|
621
|
-
options: vbv-maxrate=9000:vbv-bufsize=12000:nal-hrd=vbr
|
622
|
-
|
623
|
-
bitrate: 6000 kbps, pass: 0
|
624
|
-
```
|
598
|
+
My average bitrate (ABR) ratecontrol system, selected via the `--abr` option, is based on the ABR algorithm already within x264 and x265 which targets a specific bitrate.
|
625
599
|
|
626
|
-
|
627
|
-
|
628
|
-
As mentioned before, the VBV model typically allows bitrates to peak as high as `25000` Kbps during playback on most devices. But I constrain the VBV maximum bitrate (`vbv-maxrate`) to only 1.5 times that of the target, i.e. to just `9000` Kbps when the target bitrate is `6000` Kbps for 1080p output.
|
600
|
+
But I constrain the maximum bitrate (`vbv-maxrate`) to only 1.5 times that of the target, i.e. to just `9000` Kbps when the target bitrate is `6000` Kbps for 1080p output.
|
629
601
|
|
630
602
|
It seems counterintuitive, but constraining the maximum bitrate prevents too much bitrate being wasted on complex or difficult to encode passages at the expense of quality elsewhere. This is because with an average bitrate algorithm, when the peaks get too high then the valleys get too low.
|
631
603
|
|
632
|
-
|
633
|
-
|
634
|
-
This VBV model manipulation is exactly the same strategy used by streaming services such as Netflix.
|
635
|
-
|
636
|
-
The final setting, `nal-hrd=vbr`, doesn't actually affect ratecontrol. This is a x264 option signaling Hypothetical Reference Decoder (HRD) information, meaning that it adds the VBV maximum bitrate value as metadata to the output video. Which is useful for certain streaming environments and media tools.
|
637
|
-
|
638
|
-
And this information is safe to include since my ABR ratecontrol implementation will, by design, never exceed the maximum bitrate. Which is something the default ratecontrol system cannot promise.
|
604
|
+
And this manipulation is exactly the same strategy used by streaming services such as Netflix.
|
639
605
|
|
640
606
|
## FAQ
|
641
607
|
|
@@ -651,23 +617,25 @@ Plus, I wouldn't use a GUI for these tasks. And it's a bad idea to develop softw
|
|
651
617
|
|
652
618
|
### When will you add support for H.265 video?
|
653
619
|
|
654
|
-
[High Efficiency Video Coding](https://en.wikipedia.org/wiki/High_Efficiency_Video_Coding) or H.265
|
620
|
+
HandBrake has supported [High Efficiency Video Coding](https://en.wikipedia.org/wiki/High_Efficiency_Video_Coding) or H.265 ever since it included the [x265 video encoder](http://x265.org/).
|
621
|
+
|
622
|
+
You can try HEVC transcoding now using the `--encoder` option:
|
655
623
|
|
656
|
-
|
624
|
+
transcode-video --encoder x265 "/path/to/Movie.mkv"
|
657
625
|
|
658
|
-
|
626
|
+
While speed continues to improve, x265 is still considerably slower than the default x264 encoder.
|
659
627
|
|
660
|
-
|
628
|
+
### What about hardware-based video transcoding?
|
661
629
|
|
662
|
-
|
630
|
+
Hardware-based encoders, like those in [Intel Quick Sync Video](https://en.wikipedia.org/wiki/Intel_Quick_Sync_Video), are often considerably faster than x264 or x265. Some are available in recent versions of HandBrake.
|
663
631
|
|
664
|
-
|
632
|
+
Check the output of `HandBrakeCLI --help` to find out if your platform has any of these video encoders available. The names of these encoders all end with "`_h264`" (for H.264) or "`_h265`" (for HEVC).
|
665
633
|
|
666
|
-
|
634
|
+
You can try hardware-based transcoding now using the `--encoder` option. On macOS, select the H.264 encoder this way:
|
667
635
|
|
668
|
-
|
636
|
+
transcode-video --encoder vt_h264 "/path/to/Movie.mkv"
|
669
637
|
|
670
|
-
|
638
|
+
You can also use the `--target` option with these encoders.
|
671
639
|
|
672
640
|
### How do you assess video transcoding quality?
|
673
641
|
|
@@ -689,17 +657,29 @@ For a few problematic videos, I have to apply options like `--force-rate 23.976
|
|
689
657
|
|
690
658
|
## History
|
691
659
|
|
660
|
+
### [0.22.0](https://github.com/donmelton/video_transcoding/releases/tag/0.22.0)
|
661
|
+
|
662
|
+
Saturday, December 15, 2018
|
663
|
+
|
664
|
+
* Add an `--encoder` option to `transcode-video` so `--encoder x265` will work the same as the much longer and harder to type `--handbrake-option encoder=x265`.
|
665
|
+
* Add a `--simple` ratecontrol option to `transcode-video` (via [ #211](https://github.com/donmelton/video_transcoding/issues/211)) which:
|
666
|
+
* Works like my special, or default, ratecontrol system but won't emit those annoying `VBV underflow` warnings because it's only constrained by the target bitrate and not also a minimum quality.
|
667
|
+
* Signals Hypothetical Reference Decoder (HRD) information in metadata like my average bitrate (ABR) ratecontrol system.
|
668
|
+
* Produces output similar in appearance to that from hardware-based encoders but is less prone to color banding.
|
669
|
+
* Modify `transcode-video` to not pass the target video bitrate to hardware-based encoders when a CRF value is also specified, e.g. via something like `--handbrake-option quality=20`. Currently, this is only applicable to encoders such as `nvenc_h264`, `nvenc_h265`, `vce_h264` and `vce_h265`.
|
670
|
+
* Revise both the H.265 video and hardware-based video transcoding answers in the "FAQ" section of the "README" document.
|
671
|
+
* Update and simplify the "Explanation" section of the "README" document.
|
672
|
+
|
692
673
|
### [0.21.2](https://github.com/donmelton/video_transcoding/releases/tag/0.21.2)
|
693
674
|
|
694
|
-
|
675
|
+
Tuesday, December 4, 2018
|
695
676
|
|
696
677
|
* Modify `transcode-video` to pass the target video bitrate to hardware-based encoders available in HandBrake for Windows and Linux as well as HandBrake nightly builds for macOS:
|
697
678
|
* Check the output of `HandBrakeCLI --help` from one of those builds to find out if your platform has any of these video encoders available.
|
698
679
|
* The names of these encoders all end with "`_h264`" (for H.264) or "`_h265`" (for HEVC).
|
699
|
-
* On macOS, adding `--handbrake-option encoder=vt_h264` is all that's needed to enable hardware-based H.264 transcoding. Use `
|
680
|
+
* On macOS, adding `--handbrake-option encoder=vt_h264` is all that's needed to enable hardware-based H.264 transcoding. Use `vt_h265` for HEVC.
|
700
681
|
* On Windows and Linux, use `qsv_h264` or `qsv_h265`. Other encoders might be available as well in nightly builds.
|
701
682
|
* WARNING: If you request an encoder that is _not_ available, `HandBrakeCLI` may fail or it may just fallback to a software-based encoder. Check your console output while transcoding to be certain.
|
702
|
-
* With the encoders I've tested so far, `--preset` and `--encoder-option` have no effect no matter what you pass.
|
703
683
|
* These hardware-based encoders are far faster than the software-based `x264` and `x265` encoders while still delivering _reasonable_ quality. Of course, your mileage (and perception) may vary.
|
704
684
|
|
705
685
|
### [0.21.1](https://github.com/donmelton/video_transcoding/releases/tag/0.21.1)
|
data/bin/transcode-video
CHANGED
@@ -56,8 +56,12 @@ Output options:
|
|
56
56
|
-n, --dry-run don't transcode, just show `HandBrakeCLI` command and exit
|
57
57
|
|
58
58
|
Quality options:
|
59
|
+
--encoder NAME use named video encoder (default: x264)
|
60
|
+
(refer to `HandBrakeCLI --help` for available encoders)
|
59
61
|
--abr use constrained average bitrate (ABR) ratecontrol
|
60
62
|
(predictable size with different quality than default)
|
63
|
+
--simple use simple constrained ratecontrol
|
64
|
+
(limited size with different quality than default)
|
61
65
|
--target big|small
|
62
66
|
apply video bitrate target macro for all input resolutions
|
63
67
|
(`big` trades some size for increased quality)
|
@@ -69,12 +73,12 @@ Quality options:
|
|
69
73
|
(can be used multiple times)
|
70
74
|
--quick increase encoding speed by 70-80%
|
71
75
|
with no easily perceptible loss in video quality
|
72
|
-
(avoids quality problems
|
76
|
+
(avoids quality problems with some encoder presets)
|
73
77
|
--veryquick increase encoding speed by 90-125%
|
74
78
|
with little easily perceptible loss in video quality
|
75
79
|
(unlike `--quick`, output size is larger than default)
|
76
80
|
--preset veryfast|faster|fast|slow|slower|veryslow
|
77
|
-
apply
|
81
|
+
apply video encoder preset
|
78
82
|
|
79
83
|
Video options:
|
80
84
|
--crop T:B:L:R set video crop values (default: 0:0:0:0)
|
@@ -192,11 +196,10 @@ External subtitle options:
|
|
192
196
|
|
193
197
|
Advanced options:
|
194
198
|
-E, --encoder-option NAME=VALUE|_NAME
|
195
|
-
pass
|
199
|
+
pass video encoder option by name with value
|
196
200
|
or disable use of option by prefixing name with "_"
|
197
201
|
(e.g.: `-E vbv-bufsize=8000`)
|
198
202
|
(e.g.: `-E _crf-max`)
|
199
|
-
(refer to `x264 --fullhelp` for more information)
|
200
203
|
(can be used multiple times)
|
201
204
|
-H, --handbrake-option NAME[=VALUE]|_NAME
|
202
205
|
pass `HandBrakeCLI` option by name or by name with value
|
@@ -228,6 +231,7 @@ HERE
|
|
228
231
|
@log = true
|
229
232
|
@dry_run = false
|
230
233
|
@use_abr = false
|
234
|
+
@use_simple = false
|
231
235
|
@target_bitrate_2160p = 12000
|
232
236
|
@target_bitrate_1080p = 6000
|
233
237
|
@target_bitrate_720p = 3000
|
@@ -317,8 +321,18 @@ HERE
|
|
317
321
|
opts.on('--no-log') { @log = false }
|
318
322
|
opts.on('-n', '--dry-run') { @dry_run = true }
|
319
323
|
|
324
|
+
opts.on '--encoder ARG' do |arg|
|
325
|
+
force_handbrake_option 'encoder', arg
|
326
|
+
end
|
327
|
+
|
320
328
|
opts.on '--abr' do
|
321
|
-
@use_abr
|
329
|
+
@use_abr = true
|
330
|
+
@use_simple = false
|
331
|
+
end
|
332
|
+
|
333
|
+
opts.on '--simple' do
|
334
|
+
@use_simple = true
|
335
|
+
@use_abr = false
|
322
336
|
end
|
323
337
|
|
324
338
|
opts.on '--target ARG' do |arg|
|
@@ -933,7 +947,7 @@ HERE
|
|
933
947
|
|
934
948
|
encoder = @handbrake_options.fetch('encoder', 'x264')
|
935
949
|
|
936
|
-
if encoder =~ /_h26[45]$/
|
950
|
+
if encoder =~ /_h26[45]$/ and not @handbrake_options.has_key? 'quality'
|
937
951
|
handbrake_options['vb'] = bitrate.to_s
|
938
952
|
end
|
939
953
|
|
@@ -960,6 +974,12 @@ HERE
|
|
960
974
|
encoder_options['vbv-bufsize'] = ((bitrate * 2).to_i).to_s
|
961
975
|
encoder_options['nal-hrd'] = 'vbr' if encoder =~ /^x264(?:_10bit)?$/
|
962
976
|
encoder_options['hrd'] = '1' if encoder =~ /^x265(?:_1[02]bit)?$/
|
977
|
+
elsif @use_simple
|
978
|
+
handbrake_options['quality'] = '1'
|
979
|
+
encoder_options['vbv-maxrate'] = bitrate.to_s
|
980
|
+
encoder_options['vbv-bufsize'] = bitrate.to_s
|
981
|
+
encoder_options['nal-hrd'] = 'vbr' if encoder =~ /^x264(?:_10bit)?$/
|
982
|
+
encoder_options['hrd'] = '1' if encoder =~ /^x265(?:_1[02]bit)?$/
|
963
983
|
else
|
964
984
|
handbrake_options['quality'] = '1'
|
965
985
|
encoder_options['vbv-maxrate'] = bitrate.to_s
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: video_transcoding
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.22.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Don Melton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-12-
|
11
|
+
date: 2018-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |2
|
14
14
|
Video Transcoding is a package of tools to transcode, inspect
|