From d7c082249f239824ed4ee6f48514840ff3ddf6bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Sat, 8 Oct 2022 16:24:22 +0200 Subject: [PATCH] strip_track_except: use complete TMPFILE name, exit when ffmpeg errors out --- strip_track_except.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/strip_track_except.sh b/strip_track_except.sh index 353c654..db184e1 100755 --- a/strip_track_except.sh +++ b/strip_track_except.sh @@ -21,8 +21,8 @@ UNDESIRED_TRACK_COUNT=$(echo "$JSON_OUTPUT" | jq "[.[] | select(.properties.lang [[ $UNDESIRED_TRACK_COUNT -eq 0 ]] && echo -e "\tFile has only '$LANGUAGE_TO_KEEP' tracks, skipping." && exit 1 FILENAME_EXT=${FILENAME##*.} echo -e "\tRemoving all audio tracks except '$LANGUAGE_TO_KEEP' tracks..." -TMPFILE=$(mktemp) -echo -e "\tOutputting to temporary file ${TMPFILE}.${FILENAME_EXT}..." -pv "$FILENAME" | ffmpeg -i pipe:0 -map 0:v -map 0:a:m:language:${LANGUAGE_TO_KEEP} -map 0:s -c copy -v error "${TMPFILE}.${FILENAME_EXT}" +TMPFILE=$(mktemp --dry-run --suffix=.${FILENAME_EXT}) +echo -e "\tOutputting to temporary file ${TMPFILE}..." +! pv "$FILENAME" | ffmpeg -i pipe:0 -map 0:v -map 0:a:m:language:${LANGUAGE_TO_KEEP} -map 0:s -c copy -v error "${TMPFILE}" && echo "Something went wrong, aborting." && exit echo -e "\tReplacing ${FILENAME} with ${TMPFILE}..." -mv "${TMPFILE}.${FILENAME_EXT}" "$FILENAME" +mv "${TMPFILE}" "$FILENAME"