other_video_transcoding 0.4.0 → 0.9.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: fa5db474ee387172ee779cd57befc925892dde23348ed6376cd35c416662576f
4
- data.tar.gz: bd15276c43996afe54cf1bd7ad0f52eb55e5f5a6c1d90ebd36721d206eb17205
3
+ metadata.gz: 88e79f218a2cdbb3a930db25fd5d5b94e6294fec90f451bb979457c68ae13a82
4
+ data.tar.gz: cc6b33de67d3da5fb80d59634181ccdd89aa539cb4d35b5d5729bd3b4ee5dae0
5
5
  SHA512:
6
- metadata.gz: 577dcc59ee2b7b2304ad59243abd5999851ed5a0407934eccfd25e59d320145428b40a86eb3f6938b30e6c45d2343cc20aa2b62f474e7b4d0c1dd9a99d8dc43e
7
- data.tar.gz: 053d07452a33c7d04239e8dee324ec954e08682607871cf8c79e2cdbf0cb6bbca0dff202e8464e2fe49f80c6e7a4adb50c3a9f815636e0fe786e7ac86829ddd6
6
+ metadata.gz: 638f9905c7df90b4c7921ae6a1d4b54e93f264c119a2599356ce911132b9688eba83edfe5ab2a0d6037326ce0c62c7aa4813792da45e15840f06d38bff1f999c
7
+ data.tar.gz: e213384ceb4e30a711e0a161ec371e72cb53b0d8d562ee7dc73dd8aade72dca2df1e8855800643dc36afe4cfa4356ae55a40fd80b2de503944261e7042388f73
data/CHANGELOG.md CHANGED
@@ -2,6 +2,106 @@
2
2
 
3
3
  This single document contains all of the notes created for each [release](https://github.com/donmelton/other_video_transcoding/releases).
4
4
 
5
+ ## [0.9.0](https://github.com/donmelton/other_video_transcoding/releases/tag/0.9.0)
6
+
7
+ Saturday, June 5, 2021
8
+
9
+ Nvidia encoders:
10
+
11
+ * Add a `--nvenc-recommended` option to `other-transcode` which easily and optimally configures the Nvidia H.264 and HEVC video encoders, equivalent to using:
12
+ * `--nvenc-spatial-aq --nvenc-lookahead 32 --nvenc-bframe-refs middle`
13
+ * The `--nvenc-bframe-refs` option is also new and using `middle` as its argument increases compression efficiency. However, it's not supported on all Nvidia hardware. Which means, neither is the `--nvenc-recommended` option.
14
+ * So, using `--nvenc-recommended` for H.264 encoding requires at minimum a fourth generation Pascal-based GPU like the GTX 1080. And using it for HEVC encoding requires at minimum a more recent sixth generation Turing-based model like the GTX 1660 or RTX 2070.
15
+ * Add a `--nvenc-cq` option to `other-transcode` to allow constant quality (CQ) ratecontrol. This option ignores the target video bitrate and takes a single numerical argument between `1` and `51` with lower values indicating higher quality. However, only values between `25` and `30` are really practical for 1080p content. It's recommended to start with `--nvenc-cq 28` and adjust as needed. Fractional values are also supported.
16
+ * While CQ ratecontrol can adapt better to extremely dynamic content compared to the default average bitrate (ABR) ratecontrol system, the output bitrates produced by CQ can vary significantly and it can be slightly more prone to color banding with the H.264 encoder. So, for now, consider the `--nvenc-cq` option an experimental feature.
17
+ * Deprecate the `--nvenc-rc-mode` option in `other-transcode` because maximum rate and buffer size values are already specified so an explicit ratecontrol mode is not required.
18
+
19
+ Audio:
20
+
21
+ * Modify `other-transcode` to no longer explicitly set audio bitrates and instead rely on the defaults from the audio encoders included with `ffmpeg`. This is being done to both simplify the code in `other-transcode` and to leverage the judgement of the audio encoder developers, which means:
22
+ * AC-3 surround audio is lowered from 640 Kbps to 448 Kbps.
23
+ * Dolby Digital Plus (Enhanced AC-3) surround audio is raised from 384 Kbps to 448 Kbps.
24
+ * AAC stereo audio is lowered from 256 Kbps to 128 Kbps when using the native `ffmpeg` or Apple AudioToolbox encoders.
25
+ * If desired, use the `--surround-bitrate` and `--stereo-bitrate` options to restore the previous default audio bitrates.
26
+ * Add a `--aac-only` option to `other-transcode` to force transcoding of all audio into AAC format, copying only tracks which are already in that format. Surround tracks are converted to a 5.1-channel AAC format at 341 Kbps when using the native `ffmpeg` encoder. This channel layout is compatible with most playback devices. Allowing more than 5.1 channels would significantly reduce playback compatibility.
27
+ * Deprecate the `--aac-stereo` option in `other-transcode` and replace with a new `--eac3-aac` option, which uses Dolby Digital Plus format only for surround audio with AAC format for stereo audio. Since the `--aac-stereo` option only made sense when used in combination with the `--eac3` option, this makes `--eac3-aac` more convenient.
28
+
29
+ Other changes:
30
+
31
+ * Change the default ratecontrol maximum rate and buffer size values in `other-transcode`, as well as how those values increased when the target video bitrate is increased. The default values now also differ depending on whether the output video is in H.264 or HEVC format.
32
+ * Modify the `--rc-maxrate` and `--rc-bufsize` options in `other-transcode` to allow specific bitrates as arguments and not just multiples of the video bitrate target. These options are most useful for lowering maximum rate and buffer size values. To raise those values, increase the target video bitrate instead.
33
+ * Change the pixel format and force a Main 10 video profile in `other-transcode` when using the Apple VideoToolbox encoder to create output with a 10-bit color depth. Correct generation of 10-bit output requires macOS Big Sur or later.
34
+ * Modify `other-transcode` to copy the three basic color properties (primaries, transer and space) from the input to the output when those properties are availabe. Otherwise use some sensible defaults.
35
+ * Modify `other-transcode` to force a H.264 level when using `--x264` with slower presets. This ensures that the `x264` encoder continues to generate a video stream compatible with most playback devices when those presets are used.
36
+ * Modify `other-transcode` to remove the hack which avoids using the Matroksa muxer `-disposition` option in old versions of `ffmpeg`. This means version 4.3 or later of `ffmpeg` is now required to run `other-transcode`.
37
+
38
+ ## [0.8.0](https://github.com/donmelton/other_video_transcoding/releases/tag/0.8.0)
39
+
40
+ Saturday, February 13, 2021
41
+
42
+ * Modify `other-transcode` to:
43
+ * No longer automatically deinterlace video with a frame rate of 29.97 FPS.
44
+ * No longer change the frame rate of any video in MPEG-2 format which was automatically deinterlaced.
45
+ * Only automatically deinterlace non-progressive video.
46
+ * Apply any automatic or explicit deinterlacing to all frames of the video, not just the interlaced frames.
47
+ * Force a constant frame rate for any video in MPEG-2 format at 29.97 FPS.
48
+ * Add a `--yadif-params` option to `other-transcode` to allow customization of the `yadif` filter used for deinterlacing.
49
+ * Remove the deprecated `--all-eac3` option of `other-transcode`.
50
+
51
+ ## [0.7.0](https://github.com/donmelton/other_video_transcoding/releases/tag/0.7.0)
52
+
53
+ Monday, January 4, 2021
54
+
55
+ * Modify `other-transcode` to lower default target bitrates in order to significantly reduce the size of transcoded output at the risk of a slight reduction in perceived quality. Via [ #89](https://github.com/donmelton/other_video_transcoding/issues/89).
56
+
57
+ H.264 video:
58
+
59
+ Resolution | old | new
60
+ --- | --- | ---
61
+ 1080p (Blu-ray video) | 8000 Kbps | 6000 Kbps
62
+ 720p | 4000 Kbps | 3000 Kbps
63
+ 480p (DVD video) | 2000 Kbps | 1500 Kbps
64
+
65
+ HEVC video:
66
+
67
+ Resolution | old | new
68
+ --- | --- | ---
69
+ 1080p (Blu-ray video) | 6000 Kbps | 4000 Kbps
70
+ 720p | 3000 Kbps | 2000 Kbps
71
+ 480p (DVD video) | 1500 Kbps | 1000 Kbps
72
+
73
+ Dolby Digital Plus (Enhanced AC-3) audio:
74
+
75
+ Channels | old | new
76
+ --- | --- | ---
77
+ Surround | 640 Kbps | 384 Kbps
78
+ Stereo | 256 Kbps | 192 Kbps
79
+ Mono | 128 Kbps | 96 Kbps
80
+
81
+ Note: There are no changes to default target bitrates for Dolby Digital (AC-3) and AAC audio formats.
82
+
83
+ * Change the `--eac3` option in `other-transcode` to use Dolby Digital Plus format for _all_ transcoded audio instead of just surround output.
84
+ * Deprecate the `--all-eac3` option in `other-transcode` since the `--eac3` option now has the same behavior.
85
+ * Add a `--aac-stereo` option to `other-transcode`. This uses AAC format for transcoded stereo audio output so it can be paired with `--eac3` to get that option's old behavior.
86
+ * Add a `--8-bit-vc1` option. When the color depth is currently 10-bit, this option uses an 8-bit color depth _for video inputs in VC-1 format only_.
87
+
88
+ ## [0.6.0](https://github.com/donmelton/other_video_transcoding/releases/tag/0.6.0)
89
+
90
+ Tuesday, December 22, 2020
91
+
92
+ * Lower the default target bitrates for 8-bit HEVC video in `other-transcode` to match the defaults for 10-bit HEVC video. This means, for example, the default target for HEVC at a 1080p resolution will be 6000 Kbps no matter the output bit depth.
93
+ * Modify `other-transcode` to set the video buffer size equal to the maximum video bitrate when using an Nvidia encoder, essentially adding `--rc-bufsize 3` to the command line. Previously the buffer size was never explicitly set so `ffmpeg` would use a default value of twice the target bitrate. Since the maximum bitrate is normally three times the target bitrate this meant the buffer size was actually smaller than the maximum. While this didn't cause any known problems, Nvidia recommends a larger buffer size to improve quality. However, using `--rc-bufsize 0` will restore the old behavior and the default value from `ffmpeg`.
94
+ * Ignore the `--nvenc-lookahead` option in `other-transcode` when the argument is `0` since such a value won't change the behavior of an Nvidia encoder anyway.
95
+ * Add a `--limit-ac3-surround` option to `other-transcode` which prevents surround audio in AC-3 or Dolby Digital Plus (Enhanced AC-3) format from being copied instead of transcoded when the orginal bitrate is above the transcoding bitrate. This allows setting a lower target with the `--surround-bitrate` option in order to force higher-bitrate tracks to be transcoded instead of copied.
96
+ * Reduce the minimum bitrates for Dolby Digital Plus audio in `other-transcode` from 256, 128 and 64 Kbps for surround, stereo and mono layouts to 192, 96 and 48 Kbps. The default bitrates for Dolby Digital Plus audio remain the same and this change does not affect audio output in AC-3 or AAC formats.
97
+
98
+ ## [0.5.0](https://github.com/donmelton/other_video_transcoding/releases/tag/0.5.0)
99
+
100
+ Tuesday, November 24, 2020
101
+
102
+ * Add `--qsv-decoder` and `--qsv-device` options to `other-transcode`, both of which enable the scoped use of the Intel Quick Sync Video (QSV) decoder instead of the generic hardware decoder. These options can significantly speed operation of the QSV encoder, invoked via `--qsv`. It's recommended that `--decode all` be included when using these options to decode all video input formats. The `--qsv-device` option allows selection of specific hardware by number or path depending on platform. Please note that deinterlacing, cropping, scaling or using other filters will disable QSV's format-specific decoders.
103
+ * Remove all deprecated options and arguments from `other-transcode`.
104
+
5
105
  ## [0.4.0](https://github.com/donmelton/other_video_transcoding/releases/tag/0.4.0)
6
106
 
7
107
  Sunday, November 1, 2020
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2019-2020 Don Melton
1
+ Copyright (c) 2019-2021 Don Melton
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to deal
data/bin/ask-ffmpeg-log CHANGED
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # ask-ffmpeg-log
4
4
  #
5
- # Copyright (c) 2019-2020 Don Melton
5
+ # Copyright (c) 2019-2021 Don Melton
6
6
  #
7
7
 
8
8
  require 'abbrev'
@@ -16,8 +16,8 @@ module Transcoding
16
16
  class Command
17
17
  def about
18
18
  <<-HERE
19
- ask-ffmpeg-log 0.4.0
20
- Copyright (c) 2019-2020 Don Melton
19
+ ask-ffmpeg-log 0.9.0
20
+ Copyright (c) 2019-2021 Don Melton
21
21
  HERE
22
22
  end
23
23
 
data/bin/other-transcode CHANGED
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # other-transcode
4
4
  #
5
- # Copyright (c) 2019-2020 Don Melton
5
+ # Copyright (c) 2019-2021 Don Melton
6
6
  #
7
7
 
8
8
  require 'English'
@@ -18,8 +18,8 @@ module Transcoding
18
18
  class Command
19
19
  def about
20
20
  <<-HERE
21
- other-transcode 0.4.0
22
- Copyright (c) 2019-2020 Don Melton
21
+ other-transcode 0.9.0
22
+ Copyright (c) 2019-2021 Don Melton
23
23
  HERE
24
24
  end
25
25
 
@@ -91,8 +91,9 @@ Video options:
91
91
  --x264 use x264 software video encoder
92
92
  --x265 use x265 " " "
93
93
  --10-bit, --no-10-bit
94
- use 10-bit pixel format (default: not used for H.264,
94
+ use 10-bit color depth (default: not used for H.264,
95
95
  used for HEVC with Nvidia, Intel and x265 encoders)
96
+ --8-bit-vc1 use 8-bit color depth for VC-1 format only
96
97
  --preset NAME apply video encoder preset
97
98
  --decode vc1|all|none
98
99
  set scope of automatic hardware decoder acceleration
@@ -102,6 +103,10 @@ Video options:
102
103
  instead of generic hardware decoder
103
104
  (default: enabled when using Nvidia video encoder,
104
105
  disabled when using other encoders)
106
+ --qsv-decoder enable scoped use of Intel Quick Sync video decoder
107
+ instead of generic hardware decoder
108
+ --qsv-device DEVICE
109
+ enable scoped use of QSV decoder for specific device
105
110
  HERE
106
111
  end
107
112
 
@@ -123,7 +128,7 @@ Video options:
123
128
  --deinterlace reduce interlace artifacts without changing frame rate
124
129
  (applied automatically for some inputs)
125
130
  --rate FPS force constant video frame rate
126
- (`24000/1001` applied automatically for some inputs)
131
+ (disables automatic deinterlacing)
127
132
  --detelecine drop duplicate frames to restore original frame rate
128
133
  (disables any deinterlacing and forced frame rate)
129
134
  --no-filters disable any automatic adjustments via filters
@@ -132,15 +137,23 @@ Video options:
132
137
 
133
138
  def usage10
134
139
  <<-HERE
135
- --rc-maxrate FACTOR, --rc-bufsize FACTOR
140
+ --yadif-params KEY=VALUE[:KEY=VALUE]...
141
+ override yadif deinterlace filter configuration
142
+ --rc-maxrate FACTOR, --rc-bufsize FACTOR|BITRATE
136
143
  set ratecontrol maximum rate and/or buffer size
137
- as multiple of video bitrate target
144
+ as multiple of video bitrate target or specific bitrate
138
145
  --copy-video disable transcoding and copy original video track
139
146
 
140
147
  Apple Video Toolbox encoder options:
141
148
  --vt-allow-sw allow software encoding
142
149
 
143
150
  Nvidia video encoder options:
151
+ --nvenc-recommended
152
+ apply optimal quality settings, equivalent to using:
153
+ `--nvenc-spatial-aq`
154
+ `--nvenc-lookahead 32`
155
+ `--nvenc-bframe-refs middle`
156
+ (not supported on all Nvidia hardware)
144
157
  --nvenc-spatial-aq
145
158
  enable spatial adaptive quantization (AQ)
146
159
  --nvenc-temporal-aq
@@ -153,8 +166,10 @@ Nvidia video encoder options:
153
166
  set number of reference frames
154
167
  --nvenc-bframes FRAMES
155
168
  set maximum number of B-frames
156
- --nvenc-rc-mode vbr|vbr_hq
157
- set ratecontrol mode (default: vbr)
169
+ --nvenc-bframe-refs each|middle
170
+ set mode for using B-frames as reference frames
171
+ --nvenc-cq QUALITY
172
+ use constant quality (CQ) ratecontrol at target quality
158
173
 
159
174
  Intel Quick Sync video encoder options:
160
175
  --qsv-refs FRAMES
@@ -234,31 +249,39 @@ Audio options:
234
249
  def usage15
235
250
  <<-HERE
236
251
  --surround-bitrate BITRATE
237
- set surround audio bitrate (default: 640)
252
+ set surround audio bitrate (default: 448)
238
253
  --stereo-bitrate BITRATE
239
- set stereo audio bitrate (default: 256)
254
+ set stereo audio bitrate (default: 128)
240
255
  HERE
241
256
  end
242
257
 
243
258
  def usage16
244
259
  <<-HERE
245
260
  --mono-bitrate BITRATE
246
- set mono audio bitrate (default: 50% of stereo bitrate)
261
+ set mono audio bitrate (default: ~50% of stereo bitrate)
247
262
  HERE
248
263
  end
249
264
 
250
265
  def usage17
251
266
  <<-HERE
252
- --eac3 use Enhanced AC-3 format for surround audio
267
+ --eac3 use Dolby Digital Plus (E-AC-3) format for all audio
268
+ (default bitrates: 448 for surround, 192 for stereo)
253
269
  HERE
254
270
  end
255
271
 
256
272
  def usage18
257
273
  <<-HERE
258
- --all-eac3 " " " " " all audio
274
+ --eac3-aac use Dolby Digital Plus format only for surround audio
275
+ with AAC format for stereo audio
276
+ --aac-only use AAC format for all audio,
277
+ disabling passthrough of audio in other formats
278
+ (default bitrates: 341 for surround, 128 for stereo)
279
+ --limit-ac3-surround
280
+ don't copy surround audio in AC-3 format
281
+ when orginal bitrate is above passthrough bitrate
259
282
  --keep-ac3-stereo
260
283
  copy stereo and mono audio in AC-3 format
261
- even when orginal bitrate is above transcoding bitrate
284
+ even when orginal bitrate is above passthrough bitrate
262
285
  --pass-dts enable passthrough of audio in DTS and DTS-ES formats
263
286
  HERE
264
287
  end
@@ -300,17 +323,17 @@ Requires `ffprobe`, `ffmpeg` and `mkvpropedit`.
300
323
  @detect = false
301
324
  @preview = false
302
325
  @format = :mkv
303
- @mkv_options = []
304
326
  @copy_track_names = false
305
327
  @max_muxing_queue_size = nil
306
328
  @dry_run = false
307
329
  @hevc = false
308
330
  @encoder = nil
309
331
  @ten_bit = nil
332
+ @eight_bit_vc1 = false
310
333
  @preset = nil
311
334
  @decode_scope = :vc1
312
335
  @decode_method = nil
313
- @decoder_type = nil
336
+ @qsv_device = nil
314
337
  @target_2160p = nil
315
338
  @target_1080p = nil
316
339
  @target_720p = nil
@@ -323,6 +346,7 @@ Requires `ffprobe`, `ffmpeg` and `mkvpropedit`.
323
346
  @rate = nil
324
347
  @detelecine = false
325
348
  @enable_filters = true
349
+ @yadif_params = nil
326
350
  @maxrate = nil
327
351
  @bufsize = nil
328
352
  @vt_allow_sw = false
@@ -332,7 +356,8 @@ Requires `ffprobe`, `ffmpeg` and `mkvpropedit`.
332
356
  @nvenc_multipass = nil
333
357
  @nvenc_refs = nil
334
358
  @nvenc_bframes = nil
335
- @nvenc_rc_mode = 'vbr'
359
+ @nvenc_bframe_refs = nil
360
+ @nvenc_cq = nil
336
361
  @qsv_refs = nil
337
362
  @qsv_bframes = nil
338
363
  @amf_quality = nil
@@ -352,11 +377,13 @@ Requires `ffprobe`, `ffmpeg` and `mkvpropedit`.
352
377
  :title => nil,
353
378
  :width => :surround
354
379
  }]
355
- @surround_bitrate = 640
356
- @stereo_bitrate = 256
380
+ @surround_bitrate = nil
381
+ @stereo_bitrate = nil
357
382
  @mono_bitrate = nil
358
383
  @surround_encoder = 'ac3'
359
384
  @stereo_encoder = nil
385
+ @aac_fallback_encoder = 'aac'
386
+ @keep_ac3_surround = true
360
387
  @keep_ac3_stereo = false
361
388
  @pass_dts = false
362
389
  @subtitle_selections = []
@@ -494,19 +521,17 @@ Requires `ffprobe`, `ffmpeg` and `mkvpropedit`.
494
521
 
495
522
  opts.on '--[no-]10-bit' do |arg|
496
523
  @ten_bit = arg
524
+ @eight_bit_vc1 = false
497
525
  @encoder = nil if @encoder == 'copy'
498
526
  end
499
527
 
500
- opts.on '--preset ARG' do |arg|
501
- if arg == 'none'
502
- Kernel.warn '**********'
503
- Kernel.warn 'Using deprecated `--preset` argument: none'
504
- Kernel.warn '**********'
505
- @preset = nil
506
- else
507
- @preset = arg
508
- end
528
+ opts.on '--8-bit-vc1' do
529
+ @eight_bit_vc1 = true
530
+ @encoder = nil if @encoder == 'copy'
531
+ end
509
532
 
533
+ opts.on '--preset ARG' do |arg|
534
+ @preset = arg
510
535
  @encoder = nil if @encoder == 'copy'
511
536
  end
512
537
 
@@ -523,11 +548,13 @@ Requires `ffprobe`, `ffmpeg` and `mkvpropedit`.
523
548
  @decode_method = arg ? 'cuda' : 'auto'
524
549
  end
525
550
 
526
- opts.on '--cuvid' do
527
- Kernel.warn '**********'
528
- Kernel.warn 'Using deprecated option: --cuvid'
529
- Kernel.warn '**********'
530
- @decoder_type = :cuvid
551
+ opts.on '--qsv-decoder' do
552
+ @decode_method = 'qsv'
553
+ end
554
+
555
+ opts.on '--qsv-device ARG' do |arg|
556
+ @qsv_device = arg
557
+ @decode_method = 'qsv'
531
558
  end
532
559
 
533
560
  opts.on '--target ARG' do |arg|
@@ -552,6 +579,7 @@ Requires `ffprobe`, `ffmpeg` and `mkvpropedit`.
552
579
  @target = [arg.to_i, 1].max
553
580
  end
554
581
 
582
+ @nvenc_cq = nil
555
583
  @encoder = nil if @encoder == 'copy'
556
584
  end
557
585
 
@@ -584,7 +612,7 @@ Requires `ffprobe`, `ffmpeg` and `mkvpropedit`.
584
612
  @deinterlace = true
585
613
  @detelecine = false
586
614
  @enable_filters = false
587
- @encoder = nil if @encoder == 'copy' and @decoder_type != :cuvid
615
+ @encoder = nil if @encoder == 'copy'
588
616
  end
589
617
 
590
618
  opts.on '--rate ARG' do |arg|
@@ -622,6 +650,14 @@ Requires `ffprobe`, `ffmpeg` and `mkvpropedit`.
622
650
  @enable_filters = false
623
651
  end
624
652
 
653
+ opts.on '--yadif-params ARG' do |arg|
654
+ arg.split ':' do |param|
655
+ fail UsageError, "invalid argument: #{arg}" unless param =~ /^[\w\-]+=[\w\-\.,]+$/
656
+ end
657
+
658
+ @yadif_params = arg
659
+ end
660
+
625
661
  opts.on '--rc-maxrate ARG', Float do |arg|
626
662
  @maxrate = arg
627
663
  @encoder = nil if @encoder == 'copy'
@@ -650,31 +686,31 @@ Requires `ffprobe`, `ffmpeg` and `mkvpropedit`.
650
686
  @vt_allow_sw = true
651
687
  end
652
688
 
653
- opts.on '--[no-]nvenc-spatial-aq' do |arg|
654
- unless arg
655
- Kernel.warn '**********'
656
- Kernel.warn 'Using deprecated option: --no-nvenc-spatial-aq'
657
- Kernel.warn '**********'
658
- end
659
-
689
+ opts.on '--nvenc-recommended' do
660
690
  @encoder = @hevc ? 'hevc_nvenc' : 'h264_nvenc'
661
- @nvenc_spatial_aq = arg
691
+ @nvenc_spatial_aq = true
692
+ @nvenc_lookahead = 32
693
+ @nvenc_bframe_refs = 'middle'
662
694
  end
663
695
 
664
- opts.on '--[no-]nvenc-temporal-aq' do |arg|
665
- unless arg
666
- Kernel.warn '**********'
667
- Kernel.warn 'Using deprecated option: --no-nvenc-temporal-aq'
668
- Kernel.warn '**********'
669
- end
696
+ opts.on '--nvenc-spatial-aq' do
697
+ @encoder = @hevc ? 'hevc_nvenc' : 'h264_nvenc'
698
+ @nvenc_spatial_aq = true
699
+ end
670
700
 
701
+ opts.on '--nvenc-temporal-aq' do
671
702
  @encoder = @hevc ? 'hevc_nvenc' : 'h264_nvenc'
672
- @nvenc_temporal_aq = arg
703
+ @nvenc_temporal_aq = true
673
704
  end
674
705
 
675
706
  opts.on '--nvenc-lookahead ARG', Integer do |arg|
676
707
  @encoder = @hevc ? 'hevc_nvenc' : 'h264_nvenc'
677
- @nvenc_lookahead = [[arg, 0].max, 32].min
708
+
709
+ if arg > 0
710
+ @nvenc_lookahead = [arg, 32].min
711
+ else
712
+ @nvenc_lookahead = nil
713
+ end
678
714
  end
679
715
 
680
716
  opts.on '--nvenc-multipass ARG' do |arg|
@@ -698,17 +734,30 @@ Requires `ffprobe`, `ffmpeg` and `mkvpropedit`.
698
734
  @nvenc_bframes = [[arg, 0].max, 4].min
699
735
  end
700
736
 
701
- opts.on '--nvenc-rc-mode ARG' do |arg|
737
+ opts.on '--nvenc-bframe-refs ARG' do |arg|
702
738
  @encoder = @hevc ? 'hevc_nvenc' : 'h264_nvenc'
703
739
 
704
- @nvenc_rc_mode = case arg
705
- when 'vbr', 'vbr_hq'
740
+ @nvenc_bframe_refs = case arg
741
+ when 'each', 'middle'
706
742
  arg
707
743
  else
708
- fail UsageError, "invalid rate control argument: #{arg}"
744
+ fail UsageError, "invalid B-frames as references argument: #{arg}"
709
745
  end
710
746
  end
711
747
 
748
+ opts.on '--nvenc-cq ARG', Float do |arg|
749
+ @encoder = @hevc ? 'hevc_nvenc' : 'h264_nvenc'
750
+ @nvenc_cq = [[arg, 1].max, 51].min.to_s.sub(/\.0$/, '')
751
+ end
752
+
753
+ opts.on '--nvenc-rc-mode ARG' do |arg|
754
+ Kernel.warn '**********'
755
+ Kernel.warn 'Using deprecated option: --nvenc-rc-mode'
756
+ Kernel.warn '**********'
757
+ @encoder = @hevc ? 'hevc_nvenc' : 'h264_nvenc'
758
+ fail UsageError, "invalid rate control argument: #{arg}" unless arg =~ /^vbr(_hq)?$/
759
+ end
760
+
712
761
  opts.on '--qsv-refs ARG', Integer do |arg|
713
762
  @encoder = @hevc ? 'hevc_qsv' : 'h264_qsv'
714
763
  @qsv_refs = [arg, 0].max
@@ -845,6 +894,7 @@ Requires `ffprobe`, `ffmpeg` and `mkvpropedit`.
845
894
 
846
895
  opts.on '--stereo-bitrate ARG', Integer do |arg|
847
896
  @stereo_bitrate = arg
897
+ @mono_bitrate ||= @stereo_bitrate / 2
848
898
  end
849
899
 
850
900
  opts.on '--mono-bitrate ARG', Integer do |arg|
@@ -853,19 +903,38 @@ Requires `ffprobe`, `ffmpeg` and `mkvpropedit`.
853
903
 
854
904
  opts.on '--eac3' do
855
905
  @surround_encoder = 'eac3'
906
+ @stereo_encoder = 'eac3'
856
907
  end
857
908
 
858
- opts.on '--all-eac3' do
909
+ opts.on '--eac3-aac' do
859
910
  @surround_encoder = 'eac3'
860
- @stereo_encoder = 'eac3'
911
+ @stereo_encoder = nil
912
+ end
913
+
914
+ opts.on '--aac-stereo' do
915
+ Kernel.warn '**********'
916
+ Kernel.warn 'Using deprecated option: --aac-stereo'
917
+ Kernel.warn '**********'
918
+ @stereo_encoder = nil
919
+ end
920
+
921
+ opts.on '--aac-only' do
922
+ @surround_encoder = nil
923
+ @stereo_encoder = nil
924
+ end
925
+
926
+ opts.on '--limit-ac3-surround' do
927
+ @keep_ac3_surround = false
861
928
  end
862
929
 
863
930
  opts.on '--keep-ac3-stereo' do
864
931
  @keep_ac3_stereo = true
932
+ @surround_encoder ||= 'ac3'
865
933
  end
866
934
 
867
935
  opts.on '--pass-dts' do
868
936
  @pass_dts = true
937
+ @surround_encoder ||= 'ac3'
869
938
  end
870
939
 
871
940
  opts.on '--add-subtitle ARG' do |arg|
@@ -918,14 +987,6 @@ Requires `ffprobe`, `ffmpeg` and `mkvpropedit`.
918
987
  def configure(path)
919
988
  @audio_selections.uniq!
920
989
  @subtitle_selections.uniq!
921
- @surround_bitrate = [[@surround_bitrate, 256].max, (@surround_encoder == 'ac3' ? 640 : 768)].min
922
- @stereo_bitrate = [[@stereo_bitrate, 128].max, (@stereo_encoder == 'eac3' ? 768 : 320)].min
923
-
924
- if @mono_bitrate.nil?
925
- @mono_bitrate = @stereo_bitrate / 2
926
- else
927
- @mono_bitrate = [[@mono_bitrate, 64].max, (@stereo_encoder == 'eac3' ? 768 : 256)].min
928
- end
929
990
 
930
991
  [
931
992
  ['ffprobe', '-loglevel', 'quiet', '-version'],
@@ -965,24 +1026,23 @@ Requires `ffprobe`, `ffmpeg` and `mkvpropedit`.
965
1026
  end
966
1027
  end
967
1028
 
1029
+ @nvenc_cq = nil unless @encoder =~ /nvenc$/
968
1030
  @ten_bit = (@hevc and @encoder =~ /(nvenc|qsv|x265)$/ ? true : false) if @ten_bit.nil?
969
- @target_2160p ||= (@hevc and @ten_bit) ? 12000 : 16000
970
- @target_1080p ||= (@hevc and @ten_bit) ? 6000 : 8000
971
- @target_720p ||= (@hevc and @ten_bit) ? 3000 : 4000
972
- @target_480p ||= (@hevc and @ten_bit) ? 1500 : 2000
1031
+ @target_2160p ||= @hevc ? 8000 : 12000
1032
+ @target_1080p ||= @hevc ? 4000 : 6000
1033
+ @target_720p ||= @hevc ? 2000 : 3000
1034
+ @target_480p ||= @hevc ? 1000 : 1500
973
1035
  @decode_method ||= @encoder =~ /nvenc$/ ? 'cuda' : 'auto'
974
1036
 
975
1037
  if @stereo_encoder.nil?
976
1038
  if encoders =~ /aac_at/ or encoders =~ /libfdk_aac/
977
1039
  @stereo_encoder = $MATCH
1040
+ @aac_fallback_encoder = 'libfdk_aac' if encoders =~ /libfdk_aac/
978
1041
  else
979
1042
  @stereo_encoder = 'aac'
980
1043
  end
981
- end
982
1044
 
983
- if @format == :mkv
984
- capabilities = get_muxer_capabilities
985
- @mkv_options = ['-default_mode', 'passthrough'] if capabilities =~ /passthrough/
1045
+ @surround_encoder ||= @stereo_encoder
986
1046
  end
987
1047
  end
988
1048
 
@@ -1032,17 +1092,17 @@ Requires `ffprobe`, `ffmpeg` and `mkvpropedit`.
1032
1092
  IO.popen([
1033
1093
  'ffmpeg',
1034
1094
  '-loglevel', 'quiet',
1035
- '-nostdin'
1036
- ] + (encoder =~ /vaapi$/ ? ['-vaapi_device', '/dev/dri/renderD128'] : []) + [
1095
+ '-nostdin',
1096
+ *(encoder =~ /vaapi$/ ? ['-vaapi_device', '/dev/dri/renderD128'] : []),
1037
1097
  '-i', path,
1038
- '-frames:v', '1'
1039
- ] + (encoder =~ /vaapi$/ ? ['-filter:v', 'format=nv12,hwupload'] : []) + [
1098
+ '-frames:v', '1',
1099
+ *(encoder =~ /vaapi$/ ? ['-filter:v', 'format=nv12,hwupload'] : []),
1040
1100
  '-c:v', encoder,
1041
- '-b:v', '1000k'
1042
- ] + (encoder =~ /nvenc$/ ? ['-rc:v', @nvenc_rc_mode] : []) +
1043
- (encoder == 'h264_qsv' ? ['-look_ahead:v', '1'] : []) +
1044
- (encoder == 'hevc_qsv' ? ['-load_plugin:v', 'hevc_hw'] : []) +
1045
- (encoder =~ /amf$/ ? ['-rc:v', 'vbr_latency'] : []) + [
1101
+ '-b:v', '1000k',
1102
+ *(encoder =~ /nvenc$/ ? ['-rc:v', 'vbr'] : []),
1103
+ *(encoder == 'h264_qsv' ? ['-look_ahead:v', '1'] : []),
1104
+ *(encoder == 'hevc_qsv' ? ['-load_plugin:v', 'hevc_hw'] : []),
1105
+ *(encoder =~ /amf$/ ? ['-rc:v', 'vbr_latency'] : []),
1046
1106
  '-an',
1047
1107
  '-sn',
1048
1108
  '-ignore_unknown',
@@ -1060,30 +1120,6 @@ Requires `ffprobe`, `ffmpeg` and `mkvpropedit`.
1060
1120
  $CHILD_STATUS.exitstatus == 0
1061
1121
  end
1062
1122
 
1063
- def get_muxer_capabilities
1064
- Kernel.warn 'Getting muxer capabilities...'
1065
- output = ''
1066
-
1067
- begin
1068
- IO.popen([
1069
- 'ffmpeg',
1070
- '-loglevel', 'quiet',
1071
- '-h', 'muxer=matroska'
1072
- ], :err=>[:child, :out]) do |io|
1073
- io.each do |line|
1074
- Kernel.warn line if @debug
1075
- output += line
1076
- end
1077
- end
1078
- rescue SystemCallError => e
1079
- raise "getting muxer capabilities failed: #{e}"
1080
- end
1081
-
1082
- fail 'getting muxer capabilities failed' unless $CHILD_STATUS.exitstatus == 0
1083
-
1084
- output
1085
- end
1086
-
1087
1123
  def process_input(path)
1088
1124
  seconds = Time.now.tv_sec
1089
1125
 
@@ -1145,16 +1181,16 @@ Requires `ffprobe`, `ffmpeg` and `mkvpropedit`.
1145
1181
  ffmpeg_command = [
1146
1182
  'ffmpeg',
1147
1183
  '-loglevel', (@debug ? 'verbose' : 'error'),
1148
- '-stats'
1149
- ] + time_options +
1150
- decode_options + [
1151
- '-i', path
1152
- ] + (@max_muxing_queue_size.nil? ? [] : ['-max_muxing_queue_size', @max_muxing_queue_size.to_s]) +
1153
- encode_options +
1154
- get_audio_options(media_info) +
1155
- get_subtitle_options(media_info, burn_subtitle) + [
1156
- '-metadata:g', 'title='
1157
- ] + (@format == :mkv ? @mkv_options : ['-movflags', 'disable_chpl']) + [
1184
+ '-stats',
1185
+ *time_options,
1186
+ *decode_options,
1187
+ '-i', path,
1188
+ *(@max_muxing_queue_size.nil? ? [] : ['-max_muxing_queue_size', @max_muxing_queue_size.to_s]),
1189
+ *encode_options,
1190
+ *get_audio_options(media_info),
1191
+ *get_subtitle_options(media_info, burn_subtitle),
1192
+ '-metadata:g', 'title=',
1193
+ *(@format == :mkv ? ['-default_mode', 'passthrough'] : ['-movflags', 'disable_chpl']),
1158
1194
  output_path
1159
1195
  ]
1160
1196
 
@@ -1314,10 +1350,11 @@ Requires `ffprobe`, `ffmpeg` and `mkvpropedit`.
1314
1350
  index += 1
1315
1351
  puts "\##{index} subtitle:"
1316
1352
  print " format = #{stream['codec_name']}"
1317
- frames = stream.fetch('tags', {}).fetch('NUMBER_OF_FRAMES-eng', '')
1353
+ tags = stream.fetch('tags', {})
1354
+ frames = tags.fetch('NUMBER_OF_FRAMES', tags.fetch('NUMBER_OF_FRAMES-eng', ''))
1318
1355
  puts frames.empty? ? '' : " / #{frames} " + (frames == 1 ? 'frame' : 'frames')
1319
- puts " language = #{stream.fetch('tags', {}).fetch('language', '')}"
1320
- title = stream.fetch('tags', {}).fetch('title', '')
1356
+ puts " language = #{tags.fetch('language', '')}"
1357
+ title = tags.fetch('title', '')
1321
1358
  puts " title = #{title}" unless title.empty?
1322
1359
  default = (stream['disposition']['default'] == 1)
1323
1360
  forced = (stream['disposition']['forced'] == 1)
@@ -1332,8 +1369,8 @@ Requires `ffprobe`, `ffmpeg` and `mkvpropedit`.
1332
1369
  end
1333
1370
 
1334
1371
  def get_bitrate(stream)
1335
- bitrate = stream.fetch('bit_rate', '')
1336
- bitrate = stream.fetch('tags', {}).fetch('BPS-eng', '') if bitrate.empty?
1372
+ tags = stream.fetch('tags', {})
1373
+ bitrate = stream.fetch('bit_rate', tags.fetch('BPS', tags.fetch('BPS-eng', '')))
1337
1374
  return nil if bitrate.empty?
1338
1375
 
1339
1376
  bitrate.to_i / 1000
@@ -1563,101 +1600,44 @@ Requires `ffprobe`, `ffmpeg` and `mkvpropedit`.
1563
1600
  end
1564
1601
 
1565
1602
  def get_video_options(media_info, video, burn_subtitle, crop)
1566
- if @decoder_type == :cuvid
1567
- cuvid_decoder = case video['codec_name']
1568
- when 'mpeg1video'
1569
- 'mpeg1_cuvid'
1570
- when 'mpeg2video'
1571
- 'mpeg2_cuvid'
1572
- when 'mjpeg'
1573
- 'mjpeg_cuvid'
1574
- when 'mpeg4'
1575
- 'mpeg4_cuvid'
1576
- when 'h264'
1577
- 'h264_cuvid'
1578
- when 'vc1'
1579
- 'vc1_cuvid'
1580
- when 'vp8'
1581
- 'vp8_cuvid'
1582
- when 'vp9'
1583
- 'vp9_cuvid'
1584
- when 'hevc'
1585
- 'hevc_cuvid'
1586
- end
1587
- else
1588
- cuvid_decoder = nil
1589
- end
1590
-
1591
- cuvid_options = []
1592
-
1593
1603
  if burn_subtitle.nil?
1594
1604
  overlay_filter = nil
1595
1605
  else
1596
1606
  overlay_filter = "[0:#{burn_subtitle['index']}]overlay"
1597
- cuvid_decoder = nil
1598
1607
  end
1599
1608
 
1600
1609
  deinterlace = @deinterlace
1601
- rate = @rate
1602
1610
 
1603
- if @enable_filters
1604
- if video['avg_frame_rate'] == '30000/1001' or video.fetch('field_order', 'progressive') != 'progressive'
1605
- deinterlace = true
1606
-
1607
- if video['codec_name'] == 'mpeg2video' and video['avg_frame_rate'] != '25/1'
1608
- rate = '24000/1001'
1609
- end
1610
- end
1611
+ if @enable_filters and video.fetch('field_order', 'progressive') != 'progressive'
1612
+ deinterlace = true
1611
1613
  end
1612
1614
 
1613
1615
  frame_rate_filter = nil
1614
1616
 
1615
- if deinterlace
1616
- if cuvid_decoder.nil?
1617
- frame_rate_filter = 'yadif=deint=interlaced' unless @encoder == 'copy'
1618
- else
1619
- cuvid_options += ['-deint:v', 'adaptive']
1620
- end
1617
+ if deinterlace and @encoder != 'copy'
1618
+ frame_rate_filter = 'yadif'
1619
+ frame_rate_filter += "=#{@yadif_params}" unless @yadif_params.nil?
1621
1620
  end
1622
1621
 
1623
- unless rate.nil?
1622
+ unless @rate.nil?
1624
1623
  frame_rate_filter = '' if frame_rate_filter.nil?
1625
1624
  frame_rate_filter += ',' unless frame_rate_filter.empty?
1626
- frame_rate_filter += "fps=#{rate}"
1625
+ frame_rate_filter += "fps=#{@rate}"
1627
1626
  end
1628
1627
 
1629
1628
  if @detelecine
1630
1629
  frame_rate_filter = 'fieldmatch=order=tff:combmatch=none,decimate'
1631
- cuvid_decoder = nil
1632
1630
  end
1633
1631
 
1634
1632
  width = video['width'].to_i
1635
1633
  height = video['height'].to_i
1636
1634
 
1637
- if width == 720 and height == 576 and video['codec_name'] == 'mpeg2video'
1638
- pal = true
1639
- else
1640
- pal = false
1641
- end
1642
-
1643
1635
  if crop.nil? or (crop == {:width => width, :height => height, :x => 0, :y => 0})
1644
1636
  crop_filter = nil
1645
1637
  else
1646
- media_width = width
1647
- media_height = height
1648
- width = crop[:width]
1649
- height = crop[:height]
1650
-
1651
- if cuvid_decoder.nil?
1652
- crop_filter = "crop=#{width}:#{height}:#{crop[:x]}:#{crop[:y]}"
1653
- else
1654
- crop_filter = nil
1655
- top = crop[:y]
1656
- bottom = media_height - (top + height)
1657
- left = crop[:x]
1658
- right = media_width - (left + width)
1659
- cuvid_options += ['-crop:v', "#{top}x#{bottom}x#{left}x#{right}"]
1660
- end
1638
+ width = crop[:width]
1639
+ height = crop[:height]
1640
+ crop_filter = "crop=#{width}:#{height}:#{crop[:x]}:#{crop[:y]}"
1661
1641
  end
1662
1642
 
1663
1643
  if @hevc
@@ -1672,14 +1652,8 @@ Requires `ffprobe`, `ffmpeg` and `mkvpropedit`.
1672
1652
  scale = [(max_width.to_f / width), (max_height.to_f / height)].min
1673
1653
  width = ((width * scale).ceil / 2) * 2
1674
1654
  height = ((height * scale).ceil / 2) * 2
1675
-
1676
- if cuvid_decoder.nil?
1677
- scale_filter = "scale=#{width}:#{height}"
1678
- scale_filter += ':flags=bicubic' unless overlay_filter.nil?
1679
- else
1680
- scale_filter = nil
1681
- cuvid_options += ['-resize:v', "#{width}x#{height}"]
1682
- end
1655
+ scale_filter = "scale=#{width}:#{height}"
1656
+ scale_filter += ':flags=bicubic' unless overlay_filter.nil?
1683
1657
  else
1684
1658
  scale_filter = nil
1685
1659
  end
@@ -1690,24 +1664,52 @@ Requires `ffprobe`, `ffmpeg` and `mkvpropedit`.
1690
1664
  decode_options = []
1691
1665
  end
1692
1666
 
1693
- if cuvid_decoder.nil?
1694
- if (@decode_scope == :vc1 and video['codec_name'] == 'vc1') or @decode_scope == :all
1695
- if @encoder =~ /vaapi$/
1696
- decode_options = [
1697
- '-hwaccel', 'vaapi',
1698
- '-hwaccel_device', '/dev/dri/renderD128',
1699
- '-hwaccel_output_format', 'vaapi'
1700
- ]
1667
+ if (@decode_scope == :vc1 and video['codec_name'] == 'vc1') or @decode_scope == :all
1668
+ if @encoder =~ /vaapi$/
1669
+ decode_options = [
1670
+ '-hwaccel', 'vaapi',
1671
+ '-hwaccel_device', '/dev/dri/renderD128',
1672
+ '-hwaccel_output_format', 'vaapi'
1673
+ ]
1674
+ else
1675
+ if @decode_method == 'qsv' and @encoder != 'h264_qsv'
1676
+ decode_method = 'auto'
1701
1677
  else
1702
- decode_options += ['-hwaccel', @decode_method]
1678
+ decode_method = @decode_method
1703
1679
  end
1704
- end
1705
- else
1706
- Kernel.warn "video decoder = #{cuvid_decoder}"
1707
1680
 
1708
- decode_options += [
1709
- '-c:v', cuvid_decoder
1710
- ] + cuvid_options
1681
+ decode_options += ['-hwaccel', decode_method]
1682
+
1683
+ if decode_method == 'qsv' and
1684
+ overlay_filter.nil? and
1685
+ frame_rate_filter.nil? and
1686
+ crop_filter.nil? and
1687
+ scale_filter.nil?
1688
+ qsv_decoder = case video['codec_name']
1689
+ when 'av1'
1690
+ 'av1_qsv'
1691
+ when 'h264'
1692
+ 'h264_qsv'
1693
+ when 'hevc'
1694
+ 'hevc_qsv'
1695
+ when 'mjpeg'
1696
+ 'mjpeg_qsv'
1697
+ when 'mpeg2video'
1698
+ 'mpeg2_qsv'
1699
+ when 'vc1'
1700
+ 'vc1_qsv'
1701
+ when 'vp8'
1702
+ 'vp8_qsv'
1703
+ when 'vp9'
1704
+ 'vp9_qsv'
1705
+ else
1706
+ nil
1707
+ end
1708
+
1709
+ decode_options += ['-qsv_device', @qsv_device] unless @qsv_device.nil?
1710
+ decode_options += ['-c:v', qsv_decoder] unless qsv_decoder.nil?
1711
+ end
1712
+ end
1711
1713
  end
1712
1714
 
1713
1715
  if @encoder =~ /vaapi$/ and not decode_options.include?('-hwaccel')
@@ -1716,9 +1718,15 @@ Requires `ffprobe`, `ffmpeg` and `mkvpropedit`.
1716
1718
  conversion_filter = nil
1717
1719
  end
1718
1720
 
1721
+ encode_options = []
1722
+
1719
1723
  if @encoder == 'copy'
1720
1724
  filter = ''
1721
1725
  else
1726
+ if video['codec_name'] == 'mpeg2video' and video['avg_frame_rate'] == '30000/1001'
1727
+ encode_options += ['-vsync', 'cfr']
1728
+ end
1729
+
1722
1730
  filter = overlay_filter.nil? ? '' : overlay_filter
1723
1731
  filter += frame_rate_filter.nil? ? '' : ",#{frame_rate_filter}"
1724
1732
  filter += crop_filter.nil? ? '' : ",#{crop_filter}"
@@ -1728,7 +1736,7 @@ Requires `ffprobe`, `ffmpeg` and `mkvpropedit`.
1728
1736
  end
1729
1737
 
1730
1738
  if overlay_filter.nil?
1731
- encode_options = [
1739
+ encode_options += [
1732
1740
  '-map', "0:#{video['index']}"
1733
1741
  ]
1734
1742
 
@@ -1738,64 +1746,64 @@ Requires `ffprobe`, `ffmpeg` and `mkvpropedit`.
1738
1746
  ]
1739
1747
  end
1740
1748
  else
1741
- encode_options = [
1749
+ encode_options += [
1742
1750
  '-filter_complex', "[0:#{video['index']}]#{filter}[v]",
1743
1751
  '-map', '[v]'
1744
1752
  ]
1745
1753
  end
1746
1754
 
1747
- hdr = ((video.fetch('pix_fmt', 'yuv420p') == 'yuv420p10le') and @ten_bit)
1755
+ color_primaries = video['color_primaries']
1756
+ color_trc = video['color_transfer']
1757
+ colorspace = video['color_space']
1758
+ ten_bit = (@ten_bit ? (@eight_bit_vc1 ? (video['codec_name'] != 'vc1') : true) : false)
1748
1759
 
1749
- if hdr
1750
- color_primaries = 'bt2020'
1751
- color_trc = 'smpte2084'
1752
- colorspace = 'bt2020nc'
1753
- else
1754
- color_primaries = 'bt709'
1755
- color_trc = 'bt709'
1756
- colorspace = 'bt709'
1760
+ if (video.fetch('pix_fmt', 'yuv420p') == 'yuv420p10le') and ten_bit
1761
+ color_primaries ||= 'bt2020'
1762
+ color_trc ||= 'smpte2084'
1763
+ colorspace ||= 'bt2020nc'
1757
1764
  end
1758
1765
 
1759
1766
  if width > 1920 or height > 1080
1767
+ level = '5.1'
1760
1768
  bitrate = @target_2160p
1761
- max_bitrate = 40000
1762
- max_dpb_mbs = 184320
1769
+ max_bitrate = @hevc ? 25000 : 135000 # Level 5 HEVC Main 10 or H.264 Main
1763
1770
  elsif width > 1280 or height > 720
1771
+ level = '4'
1764
1772
  bitrate = @target_1080p
1765
- max_bitrate = 20000
1766
- max_dpb_mbs = 32768
1773
+ max_bitrate = @hevc ? 12000 : 20000 # Level 4
1767
1774
  elsif width > 720 or height > 576
1775
+ level = '3.1'
1768
1776
  bitrate = @target_720p
1769
- max_bitrate = 10000
1770
- max_dpb_mbs = 18000
1777
+ max_bitrate = @hevc ? 10000 : 14000 # Level 3.1
1771
1778
  else
1779
+ color_primaries ||= (width == 720 and height == 576 and video['codec_name'] == 'mpeg2video') ? 'bt470bg' : 'smpte170m'
1780
+ colorspace ||= 'smpte170m'
1781
+ level = '3'
1772
1782
  bitrate = @target_480p
1773
- max_bitrate = 5000
1774
- max_dpb_mbs = 8100
1775
-
1776
- unless hdr
1777
- color_primaries = pal ? 'bt470bg' : 'smpte170m'
1778
- colorspace = 'smpte170m'
1779
- end
1783
+ max_bitrate = @hevc ? 6000 : 10000 # Level 3
1780
1784
  end
1781
1785
 
1786
+ color_primaries ||= 'bt709'
1787
+ color_trc ||= 'bt709'
1788
+ colorspace ||= 'bt709'
1782
1789
  bitrate = @target unless @target.nil?
1783
1790
  bitrate = [bitrate, max_bitrate].min
1784
- maxrate = 0
1785
- bufsize = 0
1786
1791
 
1787
1792
  if @encoder =~ /(nvenc|hevc_qsv|libx26[45])$/
1788
- if @maxrate.nil?
1789
- maxrate = bitrate * 3
1790
- else
1791
- maxrate = [[(bitrate * @maxrate).to_i, (bitrate * 1.5).to_i].max, bitrate * 3].min
1793
+ maxrate = [max_bitrate, bitrate * 2].max
1794
+
1795
+ unless @maxrate.nil?
1796
+ maxrate = [[(@maxrate < bitrate ? bitrate * @maxrate : @maxrate).to_i, bitrate].max, maxrate].min
1792
1797
  end
1793
1798
 
1794
- if @bufsize.nil?
1795
- bufsize = maxrate if @encoder =~ /^libx26[45]$/
1796
- else
1797
- bufsize = [[(bitrate * @bufsize).to_i, bitrate].max, bitrate * 4].min
1799
+ bufsize = @encoder == 'hevc_qsv' ? 0 : maxrate
1800
+
1801
+ unless @bufsize.nil?
1802
+ bufsize = [[(@bufsize < bitrate ? bitrate * @bufsize : @bufsize).to_i, bitrate].max, maxrate].min
1798
1803
  end
1804
+ else
1805
+ maxrate = 0
1806
+ bufsize = 0
1799
1807
  end
1800
1808
 
1801
1809
  unless @preset.nil?
@@ -1827,7 +1835,7 @@ Requires `ffprobe`, `ffmpeg` and `mkvpropedit`.
1827
1835
  text = "#{sprintf("%2d", video['index'])} = #{@encoder}"
1828
1836
 
1829
1837
  unless @encoder == 'copy'
1830
- text += " / #{bitrate} Kbps"
1838
+ text += @nvenc_cq.nil? ? " / #{bitrate} Kbps" : " / #{@nvenc_cq} CQ"
1831
1839
  text += " / #{@preset}" unless @preset.nil?
1832
1840
  end
1833
1841
 
@@ -1837,21 +1845,25 @@ Requires `ffprobe`, `ffmpeg` and `mkvpropedit`.
1837
1845
 
1838
1846
  Kernel.warn text
1839
1847
  encode_options += ['-c:v', @encoder]
1840
- encode_options += ['-pix_fmt:v', (@encoder =~ /(nvenc|qsv)$/ ? 'p010le' : 'yuv420p10le')] if @ten_bit
1841
- encode_options += ['-b:v', "#{bitrate}k"] unless @encoder == 'copy'
1848
+ encode_options += ['-pix_fmt:v', (@encoder =~ /(videotoolbox|nvenc|qsv)$/ ? 'p010le' : 'yuv420p10le')] if ten_bit
1849
+ encode_options += (@nvenc_cq.nil? ? ['-b:v', "#{bitrate}k"] : ['-cq:v', @nvenc_cq]) unless @encoder == 'copy'
1842
1850
  encode_options += ['-maxrate:v', "#{maxrate}k"] if maxrate > 0
1843
1851
  encode_options += ['-bufsize:v', "#{bufsize}k"] if bufsize > 0
1844
1852
  encode_options += ['-preset:v', @preset] unless @preset.nil?
1845
- encode_options += ['-allow_sw:v', '1'] if @encoder =~ /videotoolbox$/ and @vt_allow_sw
1853
+
1854
+ if @encoder =~ /videotoolbox$/
1855
+ encode_options += ['-allow_sw:v', '1'] if @vt_allow_sw
1856
+ encode_options += ['-profile:v', 'main10'] if ten_bit
1857
+ end
1846
1858
 
1847
1859
  if @encoder =~ /nvenc$/
1848
- encode_options += ['-rc:v', @nvenc_rc_mode]
1849
1860
  encode_options += ['-spatial-aq:v', '1'] if @nvenc_spatial_aq
1850
1861
  encode_options += ['-temporal-aq:v', '1'] if @nvenc_temporal_aq
1851
1862
  encode_options += ['-rc-lookahead:v', @nvenc_lookahead.to_s] unless @nvenc_lookahead.nil?
1852
1863
  encode_options += ['-multipass:v', @nvenc_multipass] unless @nvenc_multipass.nil?
1853
1864
  encode_options += ['-refs:v', @nvenc_refs.to_s] unless @nvenc_refs.nil?
1854
1865
  encode_options += ['-bf:v', @nvenc_bframes.to_s] unless @nvenc_bframes.nil?
1866
+ encode_options += ['-b_ref_mode:v', @nvenc_bframe_refs] unless @nvenc_bframe_refs.nil?
1855
1867
  end
1856
1868
 
1857
1869
  if @encoder =~ /qsv$/
@@ -1887,20 +1899,10 @@ Requires `ffprobe`, `ffmpeg` and `mkvpropedit`.
1887
1899
  ]
1888
1900
  end
1889
1901
  else
1890
- max_refs = [(max_dpb_mbs / (((width + 15) / 16) * ((height + 15) / 16))), 16].min
1891
-
1892
1902
  case @preset
1893
- when 'slow'
1894
- refs = 5
1895
- when 'slower'
1896
- refs = 8
1897
- when 'veryslow', 'placebo'
1898
- refs = 16
1899
- else
1900
- refs = 0
1903
+ when 'slow', 'slower', 'veryslow', 'placebo'
1904
+ encode_options += ['-level:v', level]
1901
1905
  end
1902
-
1903
- encode_options += ['-refs:v', max_refs.to_s] if refs > max_refs
1904
1906
  end
1905
1907
 
1906
1908
  encode_options += ['-x264-params:v', @x264_params] unless @x264_params.nil?
@@ -1910,7 +1912,7 @@ Requires `ffprobe`, `ffmpeg` and `mkvpropedit`.
1910
1912
  encode_options += ['-x265-params:v', @x265_params] unless @x265_params.nil?
1911
1913
  end
1912
1914
 
1913
- unless @ten_bit
1915
+ unless ten_bit
1914
1916
  encode_options += ['-profile:v', 'high'] if @encoder =~ /^(h264_nvenc|h264_amf|libx264)$/
1915
1917
  end
1916
1918
 
@@ -1953,15 +1955,7 @@ Requires `ffprobe`, `ffmpeg` and `mkvpropedit`.
1953
1955
 
1954
1956
  audio_tracks = [{
1955
1957
  :stream => main_audio,
1956
- :width => width,
1957
- :bitrate => case width
1958
- when :stereo
1959
- @stereo_bitrate
1960
- when :surround
1961
- @surround_bitrate
1962
- when :original
1963
- nil
1964
- end
1958
+ :width => width
1965
1959
  }]
1966
1960
 
1967
1961
  titles = {}
@@ -1975,15 +1969,6 @@ Requires `ffprobe`, `ffmpeg` and `mkvpropedit`.
1975
1969
 
1976
1970
  width = selection[:width]
1977
1971
 
1978
- bitrate = case width
1979
- when :stereo
1980
- @stereo_bitrate
1981
- when :surround
1982
- @surround_bitrate
1983
- when :original
1984
- nil
1985
- end
1986
-
1987
1972
  unless selection[:track].nil?
1988
1973
  audio_track = 0
1989
1974
 
@@ -1995,8 +1980,7 @@ Requires `ffprobe`, `ffmpeg` and `mkvpropedit`.
1995
1980
  if audio_track == selection[:track]
1996
1981
  audio_tracks += [{
1997
1982
  :stream => stream,
1998
- :width => width,
1999
- :bitrate => bitrate
1983
+ :width => width
2000
1984
  }]
2001
1985
 
2002
1986
  break
@@ -2013,8 +1997,7 @@ Requires `ffprobe`, `ffmpeg` and `mkvpropedit`.
2013
1997
  stream['index'] != main_audio['index']
2014
1998
  audio_tracks += [{
2015
1999
  :stream => stream,
2016
- :width => width,
2017
- :bitrate => bitrate
2000
+ :width => width
2018
2001
  }]
2019
2002
  end
2020
2003
  end
@@ -2029,8 +2012,7 @@ Requires `ffprobe`, `ffmpeg` and `mkvpropedit`.
2029
2012
  if title =~ /#{selection[:title]}/i and stream['index'] != main_audio['index']
2030
2013
  audio_tracks += [{
2031
2014
  :stream => stream,
2032
- :width => width,
2033
- :bitrate => bitrate
2015
+ :width => width
2034
2016
  }]
2035
2017
 
2036
2018
  titles[stream['index']] = title
@@ -2056,23 +2038,32 @@ Requires `ffprobe`, `ffmpeg` and `mkvpropedit`.
2056
2038
  if track[:width] == :original
2057
2039
  encoder = 'copy'
2058
2040
  else
2041
+ input_bitrate = track[:stream].fetch('bit_rate', '256').to_i / 1000
2059
2042
  dts = (codec_name == 'dts' and track[:stream].fetch('profile', 'DTS') =~ /^DTS(?:-ES)?$/)
2060
2043
 
2061
2044
  if track[:width] == :surround
2062
- if codec_name == @surround_encoder or
2063
- codec_name == 'ac3' or
2045
+ if (@surround_encoder =~ /aac/ and codec_name == 'aac') or
2046
+ (@surround_encoder =~ /ac3$/ and
2047
+ (codec_name == @surround_encoder or codec_name == 'ac3') and
2048
+ (@keep_ac3_surround or input_bitrate <= (@surround_bitrate.nil? ? 640 : @surround_bitrate))) or
2064
2049
  (@pass_dts and dts)
2065
2050
  encoder = 'copy'
2066
2051
  elsif input_channels > 2
2067
2052
  encoder = @surround_encoder
2068
2053
  bitrate = @surround_bitrate
2054
+
2055
+ if encoder =~ /aac/
2056
+ encoder = @aac_fallback_encoder if encoder == 'aac_at'
2057
+ channels = 6
2058
+ end
2069
2059
  end
2070
2060
  end
2071
2061
 
2072
2062
  if encoder.nil?
2073
2063
  if input_channels <= 2 and (codec_name == 'aac' or
2074
- ((codec_name == @surround_encoder or codec_name == 'ac3') and
2075
- (@keep_ac3_stereo or (track[:stream]['bit_rate'].to_i / 1000) <= @stereo_bitrate)) or
2064
+ (@surround_encoder =~ /ac3$/ and
2065
+ (codec_name == @surround_encoder or codec_name == 'ac3') and
2066
+ (@keep_ac3_stereo or input_bitrate <= (@stereo_bitrate.nil? ? 256 : @stereo_bitrate))) or
2076
2067
  (@pass_dts and dts))
2077
2068
  encoder = 'copy'
2078
2069
  else
@@ -2101,19 +2092,19 @@ Requires `ffprobe`, `ffmpeg` and `mkvpropedit`.
2101
2092
  configurations[input_index] = configuration
2102
2093
  text = "#{sprintf("%2d", input_index)} = #{encoder}"
2103
2094
  text += " / #{bitrate} Kbps" unless bitrate.nil?
2104
- text += ' / stereo' unless channels.nil?
2095
+ text += ' / stereo' unless channels.nil? or channels > 2
2105
2096
  text += " / #{titles[input_index]}" if titles.has_key?(input_index)
2106
2097
  Kernel.warn text
2107
2098
  copy_track_name = (@copy_track_names or titles.has_key?(input_index))
2108
2099
 
2109
2100
  options += [
2110
2101
  '-map', "0:#{input_index}",
2111
- "-c:a:#{index}", encoder
2112
- ] + (encoder == 'aac_at' ? ["-aac_at_mode:a:#{index}", 'cvbr'] : []) +
2113
- (bitrate.nil? ? [] : ["-b:a:#{index}", "#{bitrate}k"]) +
2114
- (channels.nil? ? [] : ["-ac:a:#{index}", "#{channels}"]) +
2115
- (track[:stream]['sample_rate'] != '48000' ? ["-ar:a:#{index}", '48000'] : []) +
2116
- (copy_track_name ? [] : ["-metadata:s:a:#{index}", 'title=']) + [
2102
+ "-c:a:#{index}", encoder,
2103
+ *(encoder == 'aac_at' ? ["-aac_at_mode:a:#{index}", 'cvbr'] : []),
2104
+ *(bitrate.nil? ? [] : ["-b:a:#{index}", "#{bitrate}k"]),
2105
+ *(channels.nil? ? [] : ["-ac:a:#{index}", "#{channels}"]),
2106
+ *((encoder != 'copy' and track[:stream]['sample_rate'] != '48000') ? ["-ar:a:#{index}", '48000'] : []),
2107
+ *(copy_track_name ? [] : ["-metadata:s:a:#{index}", 'title=']),
2117
2108
  "-disposition:a:#{index}", (index == 0 ? 'default' : '0')
2118
2109
  ]
2119
2110
 
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'other_video_transcoding'
3
- s.version = '0.4.0'
3
+ s.version = '0.9.0'
4
4
  s.required_ruby_version = '>= 2.0'
5
5
  s.summary = 'Other tools to transcode videos.'
6
6
  s.description = <<-HERE
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: other_video_transcoding
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.9.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: 2020-11-02 00:00:00.000000000 Z
11
+ date: 2021-06-05 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: " Other Video Transcoding is a package of tools to transcode videos.\n"
14
14
  email: don@blivet.com
@@ -31,6 +31,11 @@ files:
31
31
  - other_video_transcoding-0.3.0.gem
32
32
  - other_video_transcoding-0.3.1.gem
33
33
  - other_video_transcoding-0.3.2.gem
34
+ - other_video_transcoding-0.4.0.gem
35
+ - other_video_transcoding-0.5.0.gem
36
+ - other_video_transcoding-0.6.0.gem
37
+ - other_video_transcoding-0.7.0.gem
38
+ - other_video_transcoding-0.8.0.gem
34
39
  - other_video_transcoding.gemspec
35
40
  homepage: https://github.com/donmelton/other_video_transcoding
36
41
  licenses:
@@ -51,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
51
56
  - !ruby/object:Gem::Version
52
57
  version: '0'
53
58
  requirements: []
54
- rubygems_version: 3.1.2
59
+ rubygems_version: 3.1.4
55
60
  signing_key:
56
61
  specification_version: 4
57
62
  summary: Other tools to transcode videos.