video_transcoding 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4eabf1da30ec818a49f5532ab48e63ce0fb18b31
4
+ data.tar.gz: 433ade20465ac801eef9366780b6789bedc99542
5
+ SHA512:
6
+ metadata.gz: cd3bc7d50ae781b6d44e8cd7b91e6448340e035d51c5986e47932bbffc1d453e644982032a464599e284ca9ff567503d2113992c1413091cf1dc19f0dfe07f60
7
+ data.tar.gz: 632dc6ad766a9443d638c8d1d9de00af815fcaa934e86e68aff7dee5e5468668cc46ab94bd2bc4a5ca3eeb8021040d5f0b925bfc216e75bef7713a6083a184cf
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2013-2015 Don Melton
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,573 @@
1
+ # Video Transcoding
2
+
3
+ Tools to transcode, inspect and convert videos.
4
+
5
+ ## About
6
+
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
+
9
+ What makes these tools unique is the special rate control system which achieves those goals.
10
+
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
+
13
+ Most of the tools in this package are essentially intelligent wrappers around Open Source software like [HandBrake](https://handbrake.fr/), [MKVToolNix](https://www.bunkus.org/videotools/mkvtoolnix/), [MPlayer](http://mplayerhq.hu/), [FFmpeg](http://ffmpeg.org/), and [MP4v2](https://code.google.com/p/mp4v2/). And they're all designed to be executed from the command line shell:
14
+
15
+ * [`transcode-video`](#whytranscode-video)
16
+ Transcode video file or disc image directory into format and size similar to popular online downloads.
17
+
18
+ * [`detect-crop`](#whydetect-crop)
19
+ Detect optimal crop values for video file or disc image directory.
20
+
21
+ * [`convert-video`](#whyconvert-video)
22
+ Convert video file from Matroska to MP4 format or from MP4 to Matroksa format without transcoding video.
23
+
24
+ * [`query-handbrake-log`](#whyquery-handbrake-log)
25
+ Report information from HandBrake-generated `.log` files.
26
+
27
+ Even if you don't try any of my tools, you may find this "README" document helpful:
28
+
29
+ * [About](#about)
30
+ * [Installation](#installation)
31
+ * [Rationale](#rationale)
32
+ * [Usage](#usage)
33
+ * [Guide](#guide)
34
+ * [Feedback](#feedback)
35
+ * [Acknowledgements](#acknowledgements)
36
+ * [License](#license)
37
+
38
+ ## Installation
39
+
40
+ My Video Transcoding tools are designed to work on OS X, Linux and Windows. They're packaged as a Gem and require Ruby version 2.0 or later. See "[Installing Ruby](https://www.ruby-lang.org/en/documentation/installation/)" if don't have the proper version on your platform.
41
+
42
+ Use this command to install the package:
43
+
44
+ gem install video_transcoding
45
+
46
+ You may need to prefix that command with `sudo` in some environments:
47
+
48
+ sudo gem install video_transcoding
49
+
50
+ ### Requirements
51
+
52
+ Most of the tools in this package require other software to function properly, specifically these command line programs:
53
+
54
+ * `HandBrakeCLI`
55
+ * `ffmpeg`
56
+ * `mkvmerge`
57
+ * `mkvpropedit`
58
+ * `mp4track`
59
+ * `mplayer`
60
+
61
+ You can download the command line version of HandBrake, called `HandBrakeCLI`, here:
62
+
63
+ <https://handbrake.fr/downloads2.php>
64
+
65
+ On OS X, the other dependencies can be easily installed via [Homebrew](http://brew.sh/), an add-on package manager:
66
+
67
+ brew install ffmpeg
68
+ brew install mkvtoolnix
69
+ brew install mp4v2
70
+ brew install mplayer
71
+
72
+ `HandBrakeCLI` is also available via [Homebrew Cask](http://caskroom.io/), an extension to Homebrew:
73
+
74
+ brew install caskroom/cask/brew-cask
75
+ brew cask install handbrakecli
76
+
77
+ On Linux, package management systems vary so it's best consult the indexes for those systems.
78
+
79
+ On Windows, it's best to search the Web for the appropriate binary or add-on package manager. The [VideoHelp](http://www.videohelp.com) and [Cygwin](https://cygwin.com/) sites are a good place to start.
80
+
81
+ When installing `HandBrakeCLI` or other downloaded programs, make sure the executable binary is in a directory listed in your `PATH` environment variable. On Unix-style systems like OS X and Linux, that directory might be `/usr/local/bin`.
82
+
83
+ ## Rationale
84
+
85
+ ### Why `transcode-video`?
86
+
87
+ Videos from the [iTunes Store](https://en.wikipedia.org/wiki/ITunes_Store) are my template for a portable format while remaining high enough quality to be mistaken for the originals. Their files are very good quality, only about 20% the size of the same video on a Blu-ray Disc, and play on a wide variety of devices.
88
+
89
+ HandBrake is a powerful video transcoding tool but it's complicated to configure. It has several presets but they aren't smart enough to automatically change bitrate targets and other encoding options based on different inputs. More importantly, HandBrake's default presets don't produce a predictable output size with sufficient quality.
90
+
91
+ HandBrake's "AppleTV 3" preset is closest to what I want but transcoding "[Planet Terror (2007)](http://www.blu-ray.com/movies/Planet-Terror-Blu-ray/1248/)" with it results in a huge video bitrate of 19.9 Mbps, very near the original of 22.9 Mbps. And transcoding "[The Girl with the Dragon Tattoo (2011)](http://www.blu-ray.com/movies/The-Girl-with-the-Dragon-Tattoo-Blu-ray/35744/)," while much smaller in output size, lacks detail compared to the original.
92
+
93
+ So, to follow the iTunes Store template, the `transcode-video` tool configures the [x264 video encoder](http://www.videolan.org/developers/x264.html) within HandBrake to use a [constrained variable bitrate (CVBR)](https://en.wikipedia.org/wiki/Variable_bitrate) mode, and to automatically target bitrates appropriate for different input resolutions.
94
+
95
+ Input resolution | Target video bitrate
96
+ --- | ---
97
+ 1080p or Blu-ray video | 5 Mbps
98
+ 720p | 4 Mbps
99
+ 480i, 576p or DVD video | 2 Mbps
100
+
101
+ When audio transcoding is required, it's done in [AAC format](https://en.wikipedia.org/wiki/Advanced_Audio_Coding) and, if the original is [multi-channel surround sound](https://en.wikipedia.org/wiki/Surround_sound), in [Dolby Digital AC-3 format](https://en.wikipedia.org/wiki/Dolby_Digital). Meaning the output can contain two tracks from the same source in different formats. And mono, stereo and surround inputs are all handled differently.
102
+
103
+ Input channels | Pass through | AAC track | AC-3 track
104
+ --- | --- | --- | ---
105
+ Mono | AAC only | 80 Kbps | none
106
+ Stereo | AAC only | 160 Kbps | none
107
+ Surround | AC-3 only, up to 448 Kbps | 160 Kbps | 384 Kbps with 5.1 channels
108
+
109
+ Which makes the output of `transcode-video` very near the same size, quality and configuration as videos from the iTunes Store, including their audio tracks.
110
+
111
+ But if the iTunes-style configuration is not suitable, most of these default settings and automatic behaviors can be easily overridden or augmented with additional command line options.
112
+
113
+ ### Why `detect-crop`?
114
+
115
+ Removing the black, non-content borders of a video during transcoding is not about making the edges of the output look pretty. Those edges are usually not visible anyway when viewed full screen.
116
+
117
+ Cropping is about faster transcoding and higher quality. Fewer pixels to read and write almost always leads to a speed improvement. Fewer pixels also means the x264 encoder within HandBrake doesn't waste bitrate on non-content.
118
+
119
+ HandBrake applies automatic crop detection by default. While it's usually correct, it does guess wrong often enough not to be trusted without review. For example, HandBrake's default behavior removes the top and bottom 140 pixels from "[The Dark Knight (2008)](http://www.blu-ray.com/movies/The-Dark-Knight-Blu-ray/743/)" and "[The Hunger Games: Catching Fire (2013)](http://www.blu-ray.com/movies/The-Hunger-Games-Catching-Fire-Blu-ray/67923/)," losing significant portions of their full-frame content.
120
+
121
+ And sometimes HandBrake only crops a few pixels from one or more edges, which is too small of a difference in size to improve performance or quality.
122
+
123
+ This is why `transcode-video` doesn't allow HandBrake to apply cropping by default.
124
+
125
+ Instead, the `detect-crop` tool leverages both HandBrake and MPlayer, with additional measurements and constraints, to find the optimal video cropping bounds. It then indicates whether those two programs agree. To aid in review, this tool prints commands to the terminal console allowing the recommended (or disputed) crop to be displayed, as well as a sample command line for `transcode-video` itself.
126
+
127
+ ### Why `convert-video`?
128
+
129
+ All videos from the iTunes Store are in [MP4 format](https://en.wikipedia.org/wiki/MPEG-4_Part_14) format. However, the `transcode-video` tool generates output in the more flexible [Matroska format](https://en.wikipedia.org/wiki/Matroska) by default.
130
+
131
+ While you can easily change the behavior of `transcode-video` to generate MP4 format with a command line option, it's sometimes handy to convert between formats quickly without re-transcoding. The `convert-video` tool is designed for exactly that convenience.
132
+
133
+ ### Why `query-handbrake-log`?
134
+
135
+ The `transcode-video` tool creates both video files and `.log` files. While not nearly as entertaining, the cryptic `.log` file still contains useful information. And the `query-handbrake-log` can extract performance metrics, video bitrate and relative quality from those `.log` files into easily readable reports.
136
+
137
+ ## Usage
138
+
139
+ Each of my Video Transcoding tools has several command line options. The `transcode-video` tool is the most complex with over 40 of its own. Not all of those options are detailed here. Use `--help` to list the full set of options available for a specific tool, along with brief instructions on their usage:
140
+
141
+ transcode-video --help
142
+
143
+ This built-in help works even if a tool's software dependencies are not yet installed.
144
+
145
+ All of the tools can accept multiple inputs, but batch processing for `transcode-video` is still best handled by a separate script.
146
+
147
+ The `transcode-video` and `detect-crop` tools work best with video files:
148
+
149
+ transcode-video "/path/to/Movie.mkv"
150
+
151
+ However, both tools also accept disc image directories as input:
152
+
153
+ transcode-video "/path/to/Movie disc image directory/"
154
+
155
+ Disc image directories contain unencrypted backups of Blu-ray Discs or DVDs. Typically these formats include more than one video title. These additional titles can be bonus features, alternate versions of a movie, multiple TV show episodes, etc.
156
+
157
+ By default, `transcode-video` and `detect-crop` will automatically select the main feature in a disc image directory. Or they will select the first title, if the main feature can't be determined.
158
+
159
+ Both tools allow you to scan disc image directories, listing titles and tracks:
160
+
161
+ transcode-video --scan "/path/to/Movie disc image directory/"
162
+
163
+ So you can then select a specific title by number:
164
+
165
+ transcode-video --title 5 "/path/to/Movie disc image directory/"
166
+
167
+ ### Using `transcode-video`
168
+
169
+ The `transcode-video` tool automatically determines target video bitrate, number of audio tracks, etc. without any command line options, so using it can be as simple as:
170
+
171
+ transcode-video "/path/to/Movie.mkv"
172
+
173
+ That command creates, after a reasonable amount of time, two files in the current working directory:
174
+
175
+ Movie.mkv
176
+ Movie.mkv.log
177
+
178
+ The `.log` file can be used as input to the `query-handbrake-log` tool.
179
+
180
+ #### Changing output format
181
+
182
+ By default, the `transcode-video` tool generates output in Matroska format. To generate output in MP4 format, use the `--mp4` option:
183
+
184
+ transcode-video --mp4 "/path/to/Movie.mkv"
185
+
186
+ Which will instead create:
187
+
188
+ Movie.mp4
189
+ Movie.mp4.log
190
+
191
+ To create MP4 output with the `.m4v` file extension instead of `.mp4`, use the `--m4v` option:
192
+
193
+ transcode-video --m4v "/path/to/Movie.mkv"
194
+
195
+ The `.m4v` file extension is more "iTunes-friendly," but the file content itself is exactly the same as a file with the `.mp4` extension.
196
+
197
+ #### Improving quality
198
+
199
+ If quality is more important to you than output size, use the `--big` option:
200
+
201
+ transcode-video --big "/path/to/Movie.mkv"
202
+
203
+ Video bitrate targets are raised 50-60% depending upon the video resolution of your input.
204
+
205
+ Input resolution | Target video bitrate with `--big`
206
+ --- | ---
207
+ 1080p or Blu-ray video | 8 Mbps
208
+ 720p | 6 Mbps
209
+ 480i, 576p or DVD video | 3 Mbps
210
+
211
+ Dolby Digital AC-3 audio bitrate limits are raised 66% to their maximum allowed value. However, there's no impact on the bitrate of mono and stereo AAC audio tracks.
212
+
213
+ Input channels | Pass through<br />with `--big` | AAC track<br />with `--big` | AC-3 track<br />with `--big`
214
+ --- | --- | --- | ---
215
+ Mono | AAC only | 80 Kbps | none
216
+ Stereo | AAC only | 160 Kbps | none
217
+ Surround | AC-3 only, up to 640 Kbps | 160 Kbps | 640 Kbps with 5.1 channels
218
+
219
+ With `--big`, noisy video and complex surround audio have the most potential for perceptible quality improvements.
220
+
221
+ Be aware that performance degrades 6-10% using the `--big` option due to more calculations being made and more bits being written to disk.
222
+
223
+ #### Improving performance
224
+
225
+ If you're willing to trade some precision for a 45-50% increase in video encoding speed, use the `--quick` option:
226
+
227
+ transcode-video --quick "/path/to/Movie.mkv"
228
+
229
+ The precision loss is minor and, when combined with the `--big` option, may not even be perceptible:
230
+
231
+ transcode-video --big --quick "/path/to/Movie.mkv"
232
+
233
+ The `--quick` option is also more than 15% speedier than the x264 video encoder's "fast" preset and it avoids the occasional quality loss problems of the "faster" and "veryfast" presets.
234
+
235
+ Be aware that output files are slightly larger when using the `--quick` option since the loss of precision is also a loss of efficiency.
236
+
237
+ #### Cropping
238
+
239
+ No cropping is applied by default. Use the `--crop TOP:BOTTOM:LEFT:RIGHT` option and arguments to indicate the amount of black, non-content border to remove from the edges of your video.
240
+
241
+ This command removes the top and bottom 144 pixels, typical of a 2.40:1 widescreen movie embedded within 16:9 Blu-ray Disc video:
242
+
243
+ transcode-video --crop 144:144:0:0 "/path/to/Movie.mkv"
244
+
245
+ This command removes the left and right 240 pixels, typical of a 4:3 classic TV show embedded within 16:9 Blu-ray Disc video:
246
+
247
+ transcode-video --crop 0:0:240:240 "/path/to/Movie.mkv"
248
+
249
+ Use the `detect-crop` tool to determine the optimal cropping bounds.
250
+
251
+ You can also call the `detect-crop` logic from `transcode-video` with the single `detect` argument:
252
+
253
+ transcode-video --crop detect "/path/to/Movie.mkv"
254
+
255
+ However, be aware that `detect` can fail if HandBrake and MPlayer disagree about the cropping values.
256
+
257
+ #### Understanding audio
258
+
259
+ By default, the `transcode-video` tool selects the first audio track in the input as the main audio track. This is the first track in the output and the default track for playback.
260
+
261
+ But you can select any audio track as the main track. In this case, track number 3:
262
+
263
+ transcode-video --main-audio 3 "/path/to/Movie.mkv"
264
+
265
+ You can also give the main audio track a custom name:
266
+
267
+ transcode-video --main-audio 3="Original Stereo" "/path/to/Movie.mkv"
268
+
269
+ By default, only one audio track is selected. But you can add additional tracks, also with custom names:
270
+
271
+ transcode-video --add-audio 4 --add-audio 5="Director Commentary" "/path/to/Movie.mkv"
272
+
273
+ Or you can add all audio tracks with a single option and argument:
274
+
275
+ transcode-video --add-audio all "/path/to/Movie.mkv"
276
+
277
+ You can even add audio tracks selected by their three-letter language code. This command adds all French and Spanish language tracks:
278
+
279
+ transcode-video --add-audio language=fre,spa "/path/to/Movie.mkv"
280
+
281
+ If no main audio track has been selected before adding tracks by language code, the first track added becomes the main audio track.
282
+
283
+ By default, the main audio track is transcoded in AAC format and, if the original is multi-channel surround sound, in Dolby Digital AC-3 format. Meaning the output can contain two tracks from the same source in different formats. So, main audio output is "wide" enough for "double" tracks.
284
+
285
+ Also by default, any added audio tracks are only transcoded in AAC format. Meaning the output only contains a single track in one format. So, additional audio output is only "wide" enough for "stereo" tracks.
286
+
287
+ However, you can change the "width" of main audio or additional audio output using the `--audio-width` option. There are three possible widths: `double`, `surround` and `stereo`.
288
+
289
+ Use this command to treat any additional audio tracks just like the main audio track:
290
+
291
+ transcode-video --audio-width all=double "/path/to/Movie.mkv"
292
+
293
+ Or use this command to make main audio output as a single track but still allow it in surround format:
294
+
295
+ transcode-video --audio-width 1=surround "/path/to/Movie.mkv"
296
+
297
+ If possible, audio is first passed through in its original format, providing that format is either AC-3 or AAC. This hardly ever works for Blu-ray Discs but it often will for DVDs and other random videos.
298
+
299
+ However, you can copy the original audio track, provided HandBrake and your selected file format support it:
300
+
301
+ transcode-video --copy-audio 1 "/path/to/Movie.mkv"
302
+
303
+ Be aware that copying audio tracks in their original format will likely defeat two very important goals of transcoding: portability and compression.
304
+
305
+ #### Understanding subtitles
306
+
307
+ By default, the `transcode-video` tool automatically burns any forced subtitle track it detects into the output video track. "Burning" means that the subtitle becomes part of the video itself and isn't retained as a separate track. A "forced" subtitle track is detected by a special flag on that track in the input.
308
+
309
+ But you can select any subtitle track for burning. In this case, track number 3:
310
+
311
+ transcode-video --burn-subtitle 3 "/path/to/Movie.mkv"
312
+
313
+ You can also use a special "scan" mode of HandBrake to find any embedded forced subtitle track that's in the same language as the main audio track:
314
+
315
+ transcode-video --burn-subtitle scan "/path/to/Movie.mkv"
316
+
317
+ Be aware that using this special "scan" mode does not always work. Sometimes it won't find any track or, worse, it will find the wrong track. And you won't know whether it worked until the transcoding is complete.
318
+
319
+ Burning subtitles into the output video works best for "forced" rather than optional subtitles. But it's still a much better idea than adding subtitle tracks in their original format to the output file.
320
+
321
+ Blu-ray Disc and DVD subtitles are bitmap formats. They're not text. They're large, unwieldy and may not appear correctly if you crop your video. Blu-ray Disc-format subtitles aren't even allowed in MP4 output. And DVD-format subtitles, while allowed, often won't display at all in many MP4 players.
322
+
323
+ However, you can leverage programs like [SUBtools](http://www.emmgunn.com/subtools/subtoolshome.html) or [Subtitle Edit](http://www.nikse.dk/SubtitleEdit/) to extract Blu-ray Disc and DVD subtitles and convert them into text format. Be aware that while both of these programs can perform automatic character recognition of the subtitle bitmaps, you'll still need to edit the output text by hand. Even the best automatic character recognition is still wrong far too often.
324
+
325
+ You can also find text-based subtitles for your movies and TV shows at sites like [OpenSubtitles](http://www.opensubtitles.org/), where someone else has already done the tedious work of conversion and editing.
326
+
327
+ If and when you do have a subtitle in text format, specifically [SubRip](https://en.wikipedia.org/wiki/SubRip) `.srt` format, you can easily add it to your output video from an external file:
328
+
329
+ transcode-video --add-srt "/path/to/Subtitle.srt" "/path/to/Movie.mkv"
330
+
331
+ ### Using `detect-crop`
332
+
333
+ The command to find the optimal video cropping bounds is as simple as:
334
+
335
+ detect-crop "/path/to/Movie.mkv"
336
+
337
+ Which prints out something like this:
338
+
339
+ mplayer -really-quiet -nosound -vf rectangle=1920:816:0:132 '/path/to/Movie.mkv'
340
+ mplayer -really-quiet -nosound -vf crop=1920:816:0:132 '/path/to/Movie.mkv'
341
+
342
+ transcode-video --crop 132:132:0:0 '/path/to/Movie.mkv'
343
+
344
+ Just copy and paste the sample commands to preview or transcode.
345
+
346
+ When input is a disc image directory instead of a single file, the `detect-crop` tool doesn't use MPlayer, nor does it print out commands to preview the crop.
347
+
348
+ Be aware that the algorithm to determine optimal shape always crops from the top and bottom or from the left and right, never from both axes.
349
+
350
+ ### Using `convert-video`
351
+
352
+ The `convert-video` tool repackages video files, converting them from Matroska to MP4 format or from MP4 to Matroksa format without transcoding the video. It's as simple as:
353
+
354
+ convert-video "Movie.mkv"
355
+
356
+ Which creates this MP4 file in the current working directory:
357
+
358
+ Movie.mp4
359
+
360
+ Or...
361
+
362
+ convert-video "Movie.mp4"
363
+
364
+ Which creates this Matroska file in the current working directory:
365
+
366
+ Movie.mkv
367
+
368
+ If necessary, the `convert-video` tool may transcode audio tracks to AAC or Dolby Digital AC-3 format when converting to MP4 format.
369
+
370
+ Chapter markers and metadata such as track titles are preserved. However, be aware that subtitle tracks are not converted.
371
+
372
+ ### Using `query-handbrake-log`
373
+
374
+ The `query-handbrake-log` tool reports information from HandBrake-generated `.log` files. While it can certainly work with a single `.log` file, it really shines with multiple files.
375
+
376
+ There are four types of information that `query-handbrake-log` can report on:
377
+
378
+ * `time`
379
+ The time spent during transcoding, sorted from short to long. This even works for two-pass transcodings.
380
+
381
+ * `speed`
382
+ The speed of transcoding in frames per second, sorted from fast to slow. Since most video is `23.976` FPS, you can easily see trends when you're faster or slower than real time.
383
+
384
+ * `bitrate`
385
+ The final video bitrate of the transcoded output, sorted from low to high. Very useful since most media query tools only provide approximate bitrates for Matroska files, if at all.
386
+
387
+ * `ratefactor`
388
+ Technically this is the average P-frame quantizer for transcoding, sorted from low to high. But you should consider it a relative quality assessment by the x264 video encoder.
389
+
390
+ One of these information types is required as an argument:
391
+
392
+ query-handbrake-log time "/path/to/Logs directory/"
393
+
394
+ Which prints out something like this, time spent transcoding followed by video file name:
395
+
396
+ 01:20:25 Movie.mkv
397
+ 01:45:10 Another Movie.mkv
398
+ 02:15:35 Yet Another Movie.mkv
399
+
400
+ ## Guide
401
+
402
+ ### Preparing your media for transcoding
403
+
404
+ I have four rules when preparing my own media for transcoding:
405
+
406
+ 1. Use [MakeMKV](http://www.makemkv.com/) to rip Blu-ray Discs and DVDs.
407
+ 2. Rip each selected video as a single Matroska format `.mkv` file.
408
+ 3. Look for forced subtitles and isolate them in their own track.
409
+ 4. Convert lossless audio tracks to [FLAC format](https://en.wikipedia.org/wiki/FLAC).
410
+
411
+ #### Why MakeMKV?
412
+
413
+ * It runs on most desktop computer platforms like OS X, Windows and Linux. There's even a free version available to try before you buy.
414
+
415
+ * It was designed to decrypt and extract a video track, usually the main feature of a disc and convert it into a single Matroska format `.mkv` file. And it does this really, really well.
416
+
417
+ * It can also make an unencrypted backup of your entire Blu-ray or DVD to a disc image directory.
418
+
419
+ * It's not pretty and it's not particularly easy use. But once you figure out how it works, you can rip your video exactly the way you want.
420
+
421
+ #### Why a single `.mkv` file?
422
+
423
+ * Many automatic behaviors and other features in both `transcode-video` and `detect-crop` are not available when input is a disc image directory. This is because that format limits the ability of `HandBrakeCLI` and `mplayer` to detect or manipulate certain information about the video.
424
+
425
+ * Both forced subtitle extraction and lossless audio conversion, detailed below, are not possible when input is a disc image directory.
426
+
427
+ #### Why bother with forced subtitles?
428
+
429
+ * Remember "[The Hunt for Red October (1990)](http://www.blu-ray.com/movies/The-Hunt-For-Red-October-Blu-ray/920/)" when Sean Connery and Sam Neill are speaking actual Russian at the beginning of the movie instead of just using cheesy accents like they did the rest of the time? The Blu-ray Disc version provides English subtitles just for those few scenes. They're "forced" on screen for you. Which is actually very convenient.
430
+
431
+ * Forced subtitles are often embedded within a full subtitle track. And a special flag is set on the portion of that track which is supposed to be forced. MakeMKV can recognize that flag when it converts the video into a single `.mkv` file. It can even extract just the forced portion of that subtitle into a another separate subtitle track. And it can set a different "forced" flag in the output `.mkv` file on that separate track so other software can tell what it's for.
432
+
433
+ * Not all discs with forced subtitles have those subtitles embedded within other tracks. Sometimes they really are separate. But enough discs are designed with the embedded technique that you should avoid using a disc image directory as input for transcoding.
434
+
435
+ #### Why convert lossless audio?
436
+
437
+ * [DTS-HD Master Audio](https://en.wikipedia.org/wiki/DTS-HD_Master_Audio) is the most popular high definition, lossless audio format. It's used on more than 80% of all Blu-ray Discs.
438
+
439
+ * HandBrake, FFmpeg, MPlayer and other Open Source software can't decode the lossless portion of a DTS-HD audio track. They're only able to extract the non-HD, lossy core which is in [DTS format](https://en.wikipedia.org/wiki/DTS_(sound_system)).
440
+
441
+ * But MakeMKV can [decode DTS-HD with some help from additional software](http://www.makemkv.com/dtshd/) and convert it into FLAC format which can then be decoded by HandBrake and most other software. Once again, MakeMKV can only do this when it converts the video into a single `.mkv` file.
442
+
443
+ ### Understanding the x264 preset system
444
+
445
+ The `--preset` option in `transcode-video` controls the x264 video encoder, not the other preset system built into HandBrake. It takes a preset name as its single argument:
446
+
447
+ transcode-video --preset fast "/path/to/Movie.mkv"
448
+
449
+ The x264 presets are supposed to trade encoding speed for compression efficiency, and their names attempt to reflect this. However, that's not quite how they always work.
450
+
451
+ Preset name | Note
452
+ --- | --- | ---
453
+ `ultrafast` | not recommended
454
+ `superfast` | not recommended
455
+ `veryfast` | use with caution
456
+ `faster` | use with caution
457
+ `fast` | good but you might want to use `--quick` instead
458
+ `medium` | default
459
+ `slow` | use with caution
460
+ `slower` | use with caution
461
+ `veryslow` | use with caution
462
+ `placebo` | not recommended
463
+
464
+ Presets faster than `medium` trade precision for more speed. That tradeoff is acceptable for the `fast` preset. But you may notice occasional quality loss problems when using the `faster` or `veryfast` presets.
465
+
466
+ Presets slower than `medium` trade encoding speed for more compression efficiency. Any quality improvement using these presets may not be perceptible for most input. And on rare occasions, these presets lower quality noticeably.
467
+
468
+ ### Recommended `transcode-video` usage
469
+
470
+ Use the default settings whenever possible.
471
+
472
+ Use the `--mp4` or `--m4v` options if your target player can't handle Matroska format.
473
+
474
+ Use the `--big` option if you can't retain your original source rip or you just have plenty of storage space.
475
+
476
+ Use the `--quick` option if you're in a hurry or you have a huge number of files to transcode.
477
+
478
+ Apply unambiguous crop values from `detect-crop` after review.
479
+
480
+ Don't add audio tracks in their original format that aren't AAC or Dolby Digital AC-3.
481
+
482
+ Don't add subtitles in their original Blu-ray Disc or DVD format.
483
+
484
+ Save your `.log` files so you can mine the data later.
485
+
486
+ ### Batch control for `transcode-video`
487
+
488
+ Although the `transcode-video` tool can accept multiple inputs, batch processing is still best handled by a separate script because options can be changed for each input.
489
+
490
+ A `batch.sh` script can simply be a list of commands:
491
+
492
+ #!/usr/bin/env bash
493
+
494
+ transcode-video --crop 132:132:0:0 "/path/to/Movie.mkv"
495
+ transcode-video "/path/to/Another Movie.mkv"
496
+ transcode-video --crop 0:0:240:240 "/path/to/Yet Another Movie.mkv"
497
+
498
+ But a better solution is to write the script once and supply the list of movies and their crop values separately:
499
+
500
+ #!/usr/bin/env bash
501
+
502
+ readonly work="$(cd "$(dirname "$0")" && pwd)"
503
+ readonly queue="$work/queue.txt"
504
+ readonly crops="$work/Crops"
505
+
506
+ input="$(sed -n 1p "$queue")"
507
+
508
+ while [ "$input" ]; do
509
+ title_name="$(basename "$input" | sed 's/\.[^.]*$//')"
510
+ crop_file="$crops/${title_name}.txt"
511
+
512
+ if [ -f "$crop_file" ]; then
513
+ crop_option="--crop $(cat "$crop_file")"
514
+ else
515
+ crop_option=''
516
+ fi
517
+
518
+ sed -i '' 1d "$queue" || exit 1
519
+
520
+ transcode-video $crop_option "$input"
521
+
522
+ input="$(sed -n 1p "$queue")"
523
+ done
524
+
525
+ This requires a `work` directory on disk with three items, one of which is a directory itself:
526
+
527
+ batch.sh
528
+ Crops/
529
+ Movie.txt
530
+ Yet Another Movie.txt
531
+ queue.txt
532
+
533
+ The contents of `Crops/Movie.txt` is simply the crop value for `/path/to/Movie.mkv`:
534
+
535
+ 132:132:0:0
536
+
537
+ And the contents of `queue.txt` is just the list of movies, full paths without quotes, delimited by carriage returns:
538
+
539
+ /path/to/Movie.mkv
540
+ /path/to/Another Movie.mkv
541
+ /path/to/Yet Another Movie.mkv
542
+
543
+ Notice that there's no crop file for `/path/to/Another Movie.mkv`. This is because it doesn't require cropping.
544
+
545
+ For other options that won't change from input to input, e.g. `--mp4`, simply augment the line in the script calling `transcode-video`:
546
+
547
+ transcode-video --mp4 $crop_option "$input"
548
+
549
+ The transcoding process is started by executing the script:
550
+
551
+ ./batch.sh
552
+
553
+ The path is first deleted from the `queue.txt` file and then passed as an argument to the `transcode-video.` tool. To pause after `transcode-video` returns, simply insert a blank line at the top of the `queue.txt` file.
554
+
555
+ These examples are written in Bash and only supply crop values. But almost any scripting language can be used and any option can be changed on a per input basis.
556
+
557
+ ## Feedback
558
+
559
+ The best way to send feedback is mentioning me, [@donmelton](https://twitter.com/donmelton), on Twitter. You can also file bugs or ask questions in a longer form by [creating a new issue](https://github.com/donmelton/video_transcoding/issues) on GitHub. I always try to respond quickly but sometimes it may take as long as 24 hours.
560
+
561
+ ## Acknowledgements
562
+
563
+ A big "thank you" to the developers of HandBrake and the other tools used by this package. So much wow.
564
+
565
+ Thanks to [Rene Ritchie](https://twitter.com/reneritchie) for letting me continue to babble on about transcoding in his podcasts.
566
+
567
+ Thanks to [Joyce Melton](https://twitter.com/erinhalfelven), my sister, for help editing this "README" document.
568
+
569
+ Many thanks to [Jordan Breeding](https://twitter.com/jorbsd) and numerous others online for their positive feedback, bug reports and useful suggestions.
570
+
571
+ ## License
572
+
573
+ Video Transcoding is copyright [Don Melton](http://donmelton.com/) and available under a [MIT license](https://github.com/donmelton/video_transcoding/blob/master/LICENSE).