├── LICENSE.txt ├── README.md └── aniconvert.py /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Andrew Sun (@crossbowffs) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AniConvert 2 | 3 | Yet another batch file converter for [HandBrake](https://handbrake.fr/) 4 | 5 | ## Features 6 | 7 | - Convert an entire folder of videos with just one command 8 | - Recursive video searching: perfect for TV shows with multiple seasons 9 | - Automatically choose an audio and subtitle track based on your language preferences 10 | - Smart "destination file already exists" handling - no more accidental overwriting 11 | - No annoying dependencies, everything is in one portable script 12 | - Works on Windows, Mac OS X, and Linux 13 | 14 | ## Requirements 15 | 16 | - [HandBrake (command-line version)](https://handbrake.fr/downloads2.php) 17 | - [Python](https://www.python.org/downloads/) 2.7 or above (Python 3 is supported) 18 | - A folder full of videos to convert! 19 | 20 | ## Usage notes 21 | 22 | If HandBrakeCLI is not in your PATH, you may place it in the same directory as 23 | the script, or specify the path manually. 24 | 25 | ## Example usage 26 | 27 | - Convert a folder of videos using default settings: `aniconvert.py path/to/folder` 28 | - Also look in subdirectories: `aniconvert.py -r ...` 29 | - Automatically select Japanese audio and English subtitles: `aniconvert.py -a jpn -s eng ...` 30 | - Skip files that have already been converted: `aniconvert.py -w skip ...` 31 | - Any combination of the above, and more! See the source code for full documentation. 32 | 33 | ## License 34 | 35 | Distributed under the [MIT License](http://opensource.org/licenses/MIT). 36 | 37 | ## FAQ 38 | 39 | ### How do I pronounce the name? 40 | 41 | "AnyConvert". The "Ani" is also short for "anime", which is what this script 42 | was designed for. Of course, it also works great with just about any show 43 | series, from Game of Thrones to My Little Pony. 44 | 45 | ### How does it work? Is FFmpeg/Libav required? 46 | 47 | All of this script's information comes from parsing the output that 48 | HandBrake produces. If HandBrake works, this script will too. No external 49 | libraries are used by the script itself, but may be required by HandBrake. 50 | 51 | ### Why would I need this? 52 | 53 | If you are watching your videos on a powerful computer, you probably don't. 54 | However, if you are using an older device, or want to save some disk space, 55 | then converting your videos using HandBrake is a good idea. Your videos will 56 | be smaller (200-300MB for a typical episode of anime at 720p), and you will 57 | be able to utilize H.264 hardware acceleration on devices that support it. 58 | 59 | ### How is this better than the official HandBrake GUI? 60 | 61 | The official HandBrake app requires that you apply your audio and subtitle 62 | preferences to each video file individually, which is annoying if you have 63 | a folder of videos that you know are in the same format. This script aims to 64 | solve that problem, while also providing extra automation such as language 65 | priority for your audio and subtitle tracks. 66 | 67 | ### Why are my subtitles burned into the video? 68 | 69 | Again, this script was written with anime in mind, where subtitles tend to 70 | be highly stylized. HandBrake does not handle these subtitles well, and the 71 | only way to maintain their styling is to burn them into the video. Read 72 | [the HandBrake wiki](https://trac.handbrake.fr/wiki/Subtitles#wikipage) 73 | for more details. 74 | 75 | ### Why do I get the error `AssertionError: Track count mismatch`? 76 | 77 | This commonly occurs if your copy of HandBrakeCLI is linked against FFmpeg 78 | instead of Libav, and your video contains ASS format subtitles. If possible, 79 | use a pre-built copy of HandBrakeCLI downloaded from the 80 | [official site](https://handbrake.fr/downloads2.php). For other operating 81 | systems, you will have to compile HandBrakeCLI yourself. 82 | 83 | For a more in-depth explanation, FFmpeg uses distinct constants to represent 84 | SSA (`AV_CODEC_ID_SSA`) and ASS (`AV_CODEC_ID_ASS`), while Libav only uses 85 | one constant for both, `AV_CODEC_ID_SSA`. HandBrake in turn only checks for 86 | `AV_CODEC_ID_SSA`. Thus, if your file contains ASS format subtitles, FFmpeg 87 | will return `AV_CODEC_ID_ASS`, which HandBrake will ignore, causing this error. 88 | -------------------------------------------------------------------------------- /aniconvert.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | ############################################################### 3 | # AniConvert: Batch convert directories of videos using 4 | # HandBrake. Intended to be used on anime and TV series, 5 | # where files downloaded as a batch tend to have the same 6 | # track layout. Can also automatically select a single audio 7 | # and subtitle track based on language preference. 8 | # 9 | # Copyright (c) 2015 Andrew Sun (@crossbowffs) 10 | # Distributed under the MIT license 11 | ############################################################### 12 | 13 | from __future__ import print_function 14 | import argparse 15 | import collections 16 | import errno 17 | import logging 18 | import os 19 | import re 20 | import subprocess 21 | import sys 22 | 23 | ############################################################### 24 | # Configuration values, no corresponding command-line args 25 | ############################################################### 26 | 27 | # Name of the HandBrake CLI binary. Set this to the full path 28 | # of the binary if the script cannot find it automatically. 29 | HANDBRAKE_EXE = "HandBrakeCLI" 30 | 31 | # The format string for logging messages 32 | LOGGING_FORMAT = "[%(levelname)s] %(message)s" 33 | 34 | # If no output directory is explicitly specified, the output 35 | # files will be placed in a directory with this value appended 36 | # to the name of the input directory. 37 | DEFAULT_OUTPUT_SUFFIX = "-converted" 38 | 39 | # Define the arguments to pass to HandBrake. 40 | # Do not define any of the following: 41 | # -i 42 | # -o 43 | # -a