changed order of operations for moving files to be safer overall
This commit is contained in:
parent
e995a59662
commit
dd8b68d722
30
reencode.sh
30
reencode.sh
@ -72,29 +72,37 @@ encodeFile() {
|
|||||||
|
|
||||||
tmpfile="$infile.bak"
|
tmpfile="$infile.bak"
|
||||||
|
|
||||||
|
ffmpeg -nostdin -hide_banner -i "$infile" -c:v hevc_nvenc -c:a copy -c:s copy -map 0 -vtag hvc1 output.mkv
|
||||||
|
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "FFMPEG re-encode failed: $infile"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
mv "$infile" "$tmpfile"
|
mv "$infile" "$tmpfile"
|
||||||
|
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "Failed to make backup file: $infile"
|
echo "Failed to make backup file: $infile"
|
||||||
|
rm output.mkv
|
||||||
return 2
|
return 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ffmpeg -nostdin -hide_banner -i "$tmpfile" -c:v hevc_nvenc -c:a copy -c:s copy -map 0 -vtag hvc1 "$outfile"
|
mv output.mkv "$outfile"
|
||||||
|
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "FFMPEG re-encode failed: $infile"
|
echo "Failed final move to: $outfile"
|
||||||
echo "Restoring from backup"
|
|
||||||
mv -f "$tmpfile" "$infile"
|
mv -f "$tmpfile" "$infile"
|
||||||
return 1
|
rm output.mkv
|
||||||
fi
|
return 2
|
||||||
|
fi
|
||||||
|
|
||||||
echo "Output file: $outfile"
|
echo "Output file: $outfile"
|
||||||
|
|
||||||
rm -f "$tmpfile"
|
rm "$tmpfile"
|
||||||
oldsize=$( echo "$filesize" | formatSize )
|
oldsize=$( formatSize $filesize )
|
||||||
oldbitr=$( echo "$bitrate" | formatRate )
|
oldbitr=$( formatRate $bitrate )
|
||||||
newsize=$( fileSize "$outfile" | formatSize )
|
newsize=$( formatSize $( fileSize "$outfile" ) )
|
||||||
newbitr=$( getBitrate "$outfile" | formatRate )
|
newbitr=$( formatRate $( getBitrate "$outfile" ) )
|
||||||
echo "Converted $infile:" >> summary.txt
|
echo "Converted $infile:" >> summary.txt
|
||||||
echo "\t$oldsize ($oldbitr) => $newsize ($newbitr)\n" >> summary.txt
|
echo "\t$oldsize ($oldbitr) => $newsize ($newbitr)\n" >> summary.txt
|
||||||
return 0
|
return 0
|
||||||
@ -183,7 +191,7 @@ if [ "$mode" != "sim" ]; then
|
|||||||
|
|
||||||
cat simulation.txt | while read line; do
|
cat simulation.txt | while read line; do
|
||||||
encodeFile "$line"
|
encodeFile "$line"
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -eq 2 ]; then
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user