howto:merge-video
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| howto:merge-video [2024/02/27 03:32] – Wuff | howto:merge-video [2025/12/07 03:54] (current) – Wuff | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Merge/ | ====== Merge/ | ||
| + | |||
| + | GUI tool for mkv files. Older version is in default debian/ | ||
| + | < | ||
| + | sudo wget -O / | ||
| + | |||
| + | cat <<EOF | sudo tee / | ||
| + | deb [arch=amd64 signed-by=/ | ||
| + | deb-src [arch=amd64 signed-by=/ | ||
| + | EOF | ||
| + | sudo apt update | ||
| + | sudo apt install mkvtoolnix mkvtoolnix-gui | ||
| + | </ | ||
| + | |||
| + | {{.: | ||
| MPG/MPEG files: | MPG/MPEG files: | ||
| Line 80: | Line 94: | ||
| output=" | output=" | ||
| - | sort -n -o $TMPFILE" | + | sort -V -o $TMPFILE" |
| echo "The following files will be merged in this order:" | echo "The following files will be merged in this order:" | ||
| Line 92: | Line 106: | ||
| actualheight=$(ffprobe -v error -select_streams v -show_entries stream=height -of csv=p=0:s=x " | actualheight=$(ffprobe -v error -select_streams v -show_entries stream=height -of csv=p=0:s=x " | ||
| # | # | ||
| - | output2=" | + | output2=" |
| mv " | mv " | ||
| echo " | echo " | ||
| Line 119: | Line 133: | ||
| Terminal=true | Terminal=true | ||
| </ | </ | ||
| + | |||
| + | alternative merge script with chapters, inspired by https:// | ||
| + | <code bash video_mergechapters.sh> | ||
| + | #!/bin/bash | ||
| + | # | ||
| + | set -euo pipefail | ||
| + | IFS=$' | ||
| + | |||
| + | cd " | ||
| + | echo " | ||
| + | ## Script to merge all mp4 videos in current directory (recursively 2 levels) | ||
| + | ## And update chapter marks to retain the folder/ | ||
| + | |||
| + | ## Script for merging videos | ||
| + | |||
| + | temp_dir=$(mktemp -d) | ||
| + | function finish { | ||
| + | rc=$? | ||
| + | if [[ $rc != 0 ]]; then | ||
| + | echo | ||
| + | echo " | ||
| + | fi | ||
| + | echo -n " | ||
| + | rm -rf " | ||
| + | echo " | ||
| + | exit $rc | ||
| + | } | ||
| + | trap finish SIGHUP EXIT | ||
| + | |||
| + | current_dir=$(pwd) | ||
| + | bname=$(basename ${current_dir}) | ||
| + | final_mp4=${bname}.mp4 | ||
| + | input_list=${temp_dir}/ | ||
| + | file_list=${temp_dir}/ | ||
| + | meta_file=${temp_dir}/ | ||
| + | |||
| + | #Hopefully this will work for either BSD or GNU sed | ||
| + | extended_match=" | ||
| + | echo "" | ||
| + | |||
| + | if [ -e " | ||
| + | echo " | ||
| + | echo;read -rsn1 -p "Press any key to continue . . ."; | ||
| + | exit 1 | ||
| + | fi | ||
| + | |||
| + | echo -n " | ||
| + | find . -maxdepth 2 -type f -iname ' | ||
| + | sed -e ' | ||
| + | tee " | ||
| + | awk " | ||
| + | echo " | ||
| + | |||
| + | cat " | ||
| + | echo;read -rsn1 -p "Press any key to continue . . ."; | ||
| + | |||
| + | ## chapter marks | ||
| + | #Do this first so we fail early | ||
| + | #TODO: Test (‘=’, ‘;’, ‘#’, ‘\’) are escaped | ||
| + | ts=0 | ||
| + | echo -n " | ||
| + | ffmpeg -i " | ||
| + | |||
| + | cat " | ||
| + | do | ||
| + | ds=$(ffprobe -v quiet -of csv=p=0 -show_entries format=duration " | ||
| + | # echo " | ||
| + | escaped_title=$(echo ${file} | sed ${extended_match} -e ' | ||
| + | echo " | ||
| + | echo " | ||
| + | echo " | ||
| + | ts=$(awk "BEGIN {print ${ts}+${ds}; | ||
| + | echo " | ||
| + | echo " | ||
| + | done | ||
| + | echo " | ||
| + | |||
| + | echo -n " | ||
| + | ffmpeg -f concat -safe 0 -i " | ||
| + | echo " | ||
| + | |||
| + | echo "Job Completed." | ||
| + | |||
| + | echo;read -rsn1 -p "Press any key to continue . . ."; | ||
| + | </ | ||
| + | |||
| + | Notes re subtitles: | ||
| + | note: mp4 format does not support ass or srt subtitles, but mov_text subtitles. ffmpeg can convert them. formatting from ass subtitles will be lost. | ||
| + | |||
| + | Embed srt subtitle file into mp4 as additional user-controllable track: | ||
| + | < | ||
| + | |||
| + | set metadata of first subtitle stream to english: | ||
| + | < | ||
| + | ffmpeg -i infile.mp4 -i infile.ass -c copy -c:s mov_text -metadata: | ||
| + | </ | ||
| + | |||
| + | extract subtitle from video: | ||
| + | < | ||
| + | |||
| + | Multiple subs require mapping, otherwise first sub will be overwritten | ||
| + | First add another input: -i input2.srt. Second, map that as 2nd stream: -map 2:0. Finally, select encoder for 2nd subtitle stream (the same as the first one): -c:s srt. The complete example\ < | ||
| + | |||
| + | convert srt to ass or ass to srt: | ||
| + | < | ||
| + | ffmpeg -i input.ass input.srt | ||
| + | </ | ||
| + | |||
| + | Remove audio from a video file: | ||
| + | < | ||
| + | ffmpeg -i input_file -c copy -an output_file | ||
| + | |||
| + | # remove all but a specific language audio streams | ||
| + | ffmpeg -i input_file -map 0 -map -0:a -map 0: | ||
| + | # loop to remove all but turkish audio streams: | ||
| + | for f in *.mkv; do ffmpeg -hide_banner -i " | ||
| + | |||
| + | |||
| + | </ | ||
| + | |||
| + | |||
howto/merge-video.1709004723.txt.gz · Last modified: by Wuff