Skip to content

Instantly share code, notes, and snippets.

@vdakalov
Last active February 1, 2023 16:45
Show Gist options
  • Select an option

  • Save vdakalov/3e5975fd0fe3019fa465760c8734b91d to your computer and use it in GitHub Desktop.

Select an option

Save vdakalov/3e5975fd0fe3019fa465760c8734b91d to your computer and use it in GitHub Desktop.
Find all video of the series, trim splash screen for each of them, keep and reorder two audio streams and make first by default
#!/usr/bin/env bash
source="/home/user/source"
target="/home/user/target"
find "$source" -type f -name "*.mkv" -print0 | while read -d $'\0' f; do
name=$(basename "$f" .mkv)
echo "$name"
ss=$(ffprobe -i "$f" 2>&1 | grep "Chapter #0:1" | grep -Eo "[0-9.]+" | head -3 | tail +3)
ss=$(echo $ss + 7 | bc)
ffmpeg \
-v error \
-nostdin \
-y \
-i "$f" \
-ss "$ss" \
-map 0:v -c:v copy \
-map 0:a:1 -c:a:0 copy \
-map 0:a:0 -c:a:1 copy \
-disposition:a:0 default \
-async 1 \
"$target/$name.mkv"
done
@vdakalov
Copy link
Author

vdakalov commented Feb 1, 2023

If the stream disposition doesn't apply and first stream is remains default prepend this option with -disposition:s:0 0 that remove default disposition of the first stream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment