From 3f6daaf851c9a2a994c0f0d3d37fe9d3f1114e07 Mon Sep 17 00:00:00 2001 From: Peter Date: Tue, 27 Apr 2021 19:13:38 +0100 Subject: Subtitle extractor script --- .local/bin/subextract | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .local/bin/subextract diff --git a/.local/bin/subextract b/.local/bin/subextract new file mode 100644 index 0000000..1b7018d --- /dev/null +++ b/.local/bin/subextract @@ -0,0 +1,14 @@ +#!/bin/sh + +# assign variables +filename=${1%%.*} +if [ -z "$2" ]; then language=nob; else language=$2; fi +if [ -z "$3" ]; then destination=.; else destination=$3; fi +stream=$(ffmpeg -i "$1" 2>&1 | awk -v lang="$language" -F"[#(]" '$0~lang {print $2}') +output_filename=$(printf %s/%s_%s.srt "$destination" "$filename" "$language") + +# dump subtitle +ffmpeg -i "$1" -c copy -map "$stream" "$output_filename" + +# remove empty file +if [ ! -s "$output_filename" ]; then rm "$output_filename" ; fi -- cgit v1.2.3