add another example

Moritz Bunkus 2019-01-24 21:33:38 +01:00
parent 7dde146877
commit 40157295c4
No known key found for this signature in database
GPG Key ID: 74AF00ADF2E32C85

@ -162,4 +162,36 @@ for FILE in *.mkv *.webm ; do
done
```
## Example 4: combine MP4 files with similarly named subtitle files
Often you might have a lot of MP4 files lying around with subtitle files that are similarly named: only the extension differs
(e.g. `Wonderful Movie.mp4` and `Wonderful Movie.srt`). The following example iterates over all MP4 files in the current directory. It looks
for SRT and VobSub subtitle files in the same directory that have the same base name (both are used if both are found). Then it multiplexes
all of them together into a Matroska file.
This example is written in shell (`bash` or `zsh`) and doesn't have any other requirements.
```sh
# an array for the arguments
declare -a args
# loop over all MP4 files
for mp4 in *.mp4 ; do
base="${mp4%mp4}"
args=(-o "output/${base}mkv" "${mp4}")
# look for subtitles with the same base name
if [[ -f "${base}srt" ]]; then
args=("${args[@]}" "${base}srt")
fi
if [[ -f "${base}idx" ]]; then
args=("${args[@]}" "${base}idx")
fi
# create output file
mkvmerge "${args[@]}"
done
```
Categories: [merging](FAQ#category-merging), [misc](FAQ#category-misc)