video_transcoding 0.21.2 → 0.22.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 89811ccde1116e1e2eb8005841225587b2e9ce21dd2407d8164b081ed4da7694
4
- data.tar.gz: 652fde3679a6176b5cb587c76a44a095bda1721de984d5f1adaff9f5f6c5685f
3
+ metadata.gz: 2ec7d9f2674f60b914a959df7c76debc47249ae57b925606b1d2ca86937a6f35
4
+ data.tar.gz: 5db202054bf388c995005cd9752ae6203551e2aec5680acbdb3a887b5d1d38ed
5
5
  SHA512:
6
- metadata.gz: 33621c9e885597c9dd0dcfe6662e17fd6e5700a3c5069c3700e4a67b5f473a0d76fec00308fe30790126e5789c98796d8b213174d6ea2af63a3a1be163c0197d
7
- data.tar.gz: 2033fb19aeaf1f169dbd841f4a80497b23bdaaac751d8e54b75fdb2082ad87e3d7b4112ab66ce3e2ebc7a8368b4e2abdd77e4c1b0b6483d9e4a060983b338bbc
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 [two ratecontrol systems](#explanation) which achieve those goals.
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
- ### A tale of two ratecontrol systems
562
+ ### Ratecontrol systems
563
563
 
564
- What is a ratecontrol sytem? It's how a video encoder decides on the amount of bits to allocate for a specific frame.
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 two different ratecontrol systems available to control the size and quality of output video. The special, or default, ratecontrol system is designed to deliver consistent quality, while the average bitrate (ABR) ratecontrol system, enabled via the `--abr` option, is designed to produce a predictable output size.
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
- Both ratecontrol systems are modified versions of what is commonly called a constrained variable bitrate (CVBR) mode. Which means they both allow bitrate to vary per frame but still constrain that bitrate.
568
+ Additionally, `transcode-video` allows access to hardware-based video encoders which have their own ratecontrol systems.
569
569
 
570
- My special ratecontrol system leverages the constant quality ratecontrol system already within the x264 video encoder, an algorithm which uses a constant ratefactor (CRF) to target a specific quality instead of a bitrate.
570
+ All of these ratecontrol systems, mine and those built into hardware, target a specific video bitrate.
571
571
 
572
- My average bitrate (ABR) ratecontrol system modifies the ABR algorithm already within x264 which targets a specific bitrate, constraining it to produce better overall quality.
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
- The target video bitrate for both 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.
574
+ ### How my simple and special ratecontrol systems work
575
575
 
576
- While both systems deliver high quality, they sometimes have different visual characteristics.
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
- ### How my special ratecontrol system works
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 manipulate the video buffering verifier (VBV) model within x264 to constrain that bitrate.
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
- Typically, the VBV model limits the output bitrate to a generous `25000` Kbps for video playback on devices like the Apple TV or Roku. But I reduce the VBV maximum bitrate (`vbv-maxrate`) to my target, e.g. `6000` Kbps for 1080p output.
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
- With this approach, x264 chooses the lowest CRF value, and therefore the highest quality, which fits below that ceiling, even if that's usually not a a CRF value of `1`.
586
+ And this fully describes the behavior of `transcode-video` when using the `--simple` option.
601
587
 
602
- But manipulating only CRF and `vbv-maxrate` will not produce high enough quality output in some cases. Why? Sometimes you need a much higher bitrate for complex or difficult to encode passages than what is allowed by `vbv-maxrate`.
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
- Along with the target CRF value of `1`, I set 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.
590
+ Unfortunately, this internal tug of war can cause the encoder to sometimes generate a few very low quality frames.
605
591
 
606
- But just adding a maximum CRF value is not enough. When under pressure to fit within all these constraints, x264 will sometimes generate a single, but still noticeable, very low quality frame. Why? Even though `crf-max` is set to `25`, individual frames can still use a higher quantizer value (QP) of much less quality.
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
- When using `transcode-video` with the `--abr` option, you might notice two lines in the console output containing something like this:
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
- This ABR ratecontrol system attempts to produce a predictable output size while still maintaining high quality by manipulating the video buffering verifier (VBV) model within the x264 video encoder.
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
- As with the default ratecontrol system, I need to set the VBV buffer size (`vbv-bufsize`) so that my previous adjustment of `vbv-maxrate` won't be ignored by x264. So, if `vbv-maxrate` is `9000` Kbps, then I set `vbv-bufsize` to `12000` Kbps.
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 is the likely successor to [H.264](https://en.wikipedia.org/wiki/H.264/MPEG-4_AVC), which is the format currently output by `transcode-video`. HandBrake has supported H.265 ever since it included the [x265 video encoder](http://x265.org/).
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
- My ratecontrol system couldn't be applied with the x265 encoder in older versions of HandBrake because it didn't allow access to `qpmax`, critical for maintaining quality in certain situations. The latest version of HandBrake includes a new encoder which fixes that.
624
+ transcode-video --encoder x265 "/path/to/Movie.mkv"
657
625
 
658
- But support also requires equivalent quality at a smaller size when using my rate control system. And performance is an issue. While speed continues to improve, the x265 encoder is still considerably slower than the current H.264 system.
626
+ While speed continues to improve, x265 is still considerably slower than the default x264 encoder.
659
627
 
660
- You can try _experimental_ HEVC transcoding now with an advanced option:
628
+ ### What about hardware-based video transcoding?
661
629
 
662
- transcode-video --handbrake-option encoder=x265 "/path/to/Movie.mkv"
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
- But use this _only_ with `HandBrakeCLI` version 1.0.0 or later.
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
- ### What about hardware-based video transcoding?
634
+ You can try hardware-based transcoding now using the `--encoder` option. On macOS, select the H.264 encoder this way:
667
635
 
668
- Using hardware with [Intel Quick Sync Video](https://en.wikipedia.org/wiki/Intel_Quick_Sync_Video) instead of software like x264 is certainly faster. HandBrake even supports that hardware on some platforms. However, my default ratecontrol system can't be applied to existing hardware encoders because they lack API to change the necessary settings.
636
+ transcode-video --encoder vt_h264 "/path/to/Movie.mkv"
669
637
 
670
- Also, keep in mind that hardware encoders are typically designed for realtime video chat or other similar duties. To maintain that performance, they often take shortcuts with video quality like reducing reference frames, lowering subpixel motion estimation, etc. Such an approach is the equivalent of using the `veryfast` preset with a software encoder. That's fine for video chat but I wouldn't recommend it for transcoding your disc collection.
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
- Sunday, December 4, 2018
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 `vt_h264` for HEVC.
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 associated with x264 presets)
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 x264 encoder preset
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 x264 video encoder option by name with value
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 = true
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
@@ -5,5 +5,5 @@
5
5
  #
6
6
 
7
7
  module VideoTranscoding
8
- VERSION = '0.21.2'
8
+ VERSION = '0.22.0'
9
9
  end
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.21.2
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-04 00:00:00.000000000 Z
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