-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathmakelossless
executable file
·76 lines (69 loc) · 3.52 KB
/
makelossless
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
scriptdir=`dirname "$0"`
. "$scriptdir/mmfunctions" || { echo "Missing '$scriptdir/mmfunctions'. Exiting." ; exit 1 ;};
check_dependencies ffmpeg muxmovie mediainfo
cleanup(){
log -a "Process aborted"
exit 1
}
trap cleanup SIGHUP SIGINT SIGTERM
log -b
while [ "$*" != "" ] ; do
file="$1"
filename=`basename "$file"`
dirname=`dirname "$file"`
[ "$#" != 0 ] && input="$1"
[ -d "$input" ] && { outputdir="$input/objects" && logdir="$input/metadata/submissionDocumentation/logs" ;};
[ -f "$input" ] && { outputdir=`dirname "$input"`"/lossless" && logdir="`dirname "$input"`/lossless/logs" ;};
[ ! "$outputdir" ] && { outputdir="$input/objects" && logdir="$input/metadata/submissionDocumentation/logs" ;};
[ -d "$input" ] && sourcefile=`find "$1/objects" -maxdepth 1 -mindepth 1 -type f \( -name "*.mov" -o -name "*.mxf" -o -name "*.mp4" -o -name "*.dv" \) ! -name ".*"`
[ -f "$input" ] && sourcefile="$input"
get_codectagstring "$sourcefile"
if [ "$codec_tag_string" == "2vuy" ] ; then
echo "$filename is 2vuy, starting encode"
mkdir -p "$outputdir" "$logdir"
export FFREPORT="file=${logdir}/%p_%t_convert-to-ffv1.log"
ffmpeg -report -vsync 0 -i "$sourcefile" -map 0:v -map 0:a -c:v ffv1 -g 1 -c:a copy "$outputdir/${filename%.*}_ffv1.mov" -f framemd5 -an "$logdir/${filename%.*}.framemd5"
ffmpeg_ffv1_err="$?"
[ "$ffmpeg_ffv1_err" -gt 0 ] && echo ffmpeg ended with error && exit 1
ffmpeg -i "$outputdir/${filename%.*}_ffv1.mov" -f framemd5 -pix_fmt uyvy422 -an "$logdir/${filename%.*}_ffv1.framemd5"
ffmpeg_md5_err="$?"
[ "$ffmpeg_md5_err" -gt 0 ] && echo ffmpeg md5 ended with error && exit 1
muxmovie "$sourcefile" -track "Timecode Track" -track "Closed Caption Track" -self-contained -o "$outputdir/${filename%.*}_tc_e608.mov"
muxmovie_err="$?"
[ "$muxmovie_err" -gt 0 ] && echo muxmovie ended with error && exit 1
if [ `md5 -q "$logdir/${filename%.*}.framemd5"` = `md5 -q "$logdir/${filename%.*}_ffv1.framemd5"` ] ; then
echo Everything looks safe. Going to delete the original.
mediainfo -f --language=raw --output=XML "$sourcefile" > "$logdir/${filename%.*}_mediainfo.xml"
#rm -f -v "$sourcefile"
else
echo Not looking safe. Going to keep the original.
fi
elif [ "$codec_tag_string" == "v210" ] ; then
echo "$filename is v210, starting encode"
mkdir -p "$outputdir" "$logdir"
export FFREPORT="file=${logdir}/%p_%t_convert-to-ffv1.log"
ffmpeg -report -vsync 0 -i "$sourcefile" -map 0:v -map 0:a -c:v ffv1 -g 1 -c:a copy "$outputdir/${filename%.*}_ffv1.mov" -f framemd5 -an "$logdir/${filename%.*}.framemd5"
ffmpeg_ffv1_err="$?"
[ "$ffmpeg_ffv1_err" -gt 0 ] && echo ffmpeg ended with error && exit 1
ffmpeg -i "$outputdir/${filename%.*}_ffv1.mov" -f framemd5 -an "$logdir/${filename%.*}_ffv1.framemd5"
ffmpeg_md5_err="$?"
[ "$ffmpeg_md5_err" -gt 0 ] && echo ffmpeg md5 ended with error && exit 1
muxmovie "$sourcefile" -track "Timecode Track" -track "Closed Caption Track" -self-contained -o "$outputdir/${filename%.*}_tc_e608.mov"
muxmovie_err="$?"
[ "$muxmovie_err" -gt 0 ] && echo muxmovie ended with error && exit 1
if [ `md5 -q "$logdir/${filename%.*}.framemd5"` = `md5 -q "$logdir/${filename%.*}_ffv1.framemd5"` ] ; then
echo Everything looks safe. Going to delete the original.
mediainfo -f --language=raw --output=XML "$sourcefile" > "$logdir/${filename%.*}_mediainfo.xml"
#rm -f -v "$sourcefile"
else
echo Not looking safe. Going to keep the original.
fi
else
echo "$filename is not 2vuy or v210, quitting"
exit 1
fi
echo done with "$sourcefile"
shift
done
log -e