forked from mediamicroservices/mm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakelossless
executable file
·81 lines (72 loc) · 4.25 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
77
78
79
80
81
#!/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
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"
sourcefilename=$(basename "$sourcefile")
log -b
get_codectagstring "$sourcefile"
if [ "$codec_tag_string" == "2vuy" ] ; then
report -dt "$sourcefilename is 2vuy, starting encode"
mkdir -p "$outputdir" "$logdir"
export FFREPORT="file=${logdir}/%p_%t_convert-to-ffv1.log"
ffmpeg -v warning -stats -vsync 0 -i "$sourcefile" -map 0:v -map 0:a -c:v ffv1 -g 1 -c:a copy "$outputdir/${sourcefilename%.*}_ffv1.mov" -f framemd5 -an "$logdir/${sourcefilename%.*}.framemd5"
ffmpeg_ffv1_err="$?"
[ "$ffmpeg_ffv1_err" -gt 0 ] && { echo ffmpeg ended with error ; exit 1 ;};
ffmpeg -i "$outputdir/${sourcefilename%.*}_ffv1.mov" -f framemd5 -pix_fmt uyvy422 -an "$logdir/${sourcefilename%.*}_ffv1.framemd5"
ffmpeg_md5_err="$?"
[ "$ffmpeg_md5_err" -gt 0 ] && { echo ffmpeg md5 ended with error ; exit 1 ;};
mkdir "$outputdir/trimmed_materials"
muxmovie "$sourcefile" -track "Timecode Track" -track "Closed Caption Track" -self-contained -o "$outputdir/trimmed_materials/${sourcefilename%.*}_tc_e608.mov"
muxmovie_err="$?"
[ "$muxmovie_err" -gt 0 ] && { echo muxmovie ended with error ; exit 1 ;};
if [ $(md5 -q "$logdir/${sourcefilename%.*}.framemd5") = $(md5 -q "$logdir/${sourcefilename%.*}_ffv1.framemd5") ] ; then
report -dt "Everything looks safe. Going to delete the original."
mediainfo -f --language=raw --output=XML "$sourcefile" > "$logdir/${sourcefilename%.*}_mediainfo.xml"
rm -f -v "$sourcefile"
else
report -wt "Not looking safe. Going to keep the original."
fi
elif [ "$codec_tag_string" == "v210" ] ; then
report -dt "$sourcefilename is v210, starting encode"
mkdir -p "$outputdir" "$logdir"
export FFREPORT="file=${logdir}/%p_%t_convert-to-ffv1.log"
ffmpeg -v warning -stats -vsync 0 -i "$sourcefile" -map 0:v -map 0:a -c:v ffv1 -g 1 -c:a copy "$outputdir/${sourcefilename%.*}_ffv1.mov" -f framemd5 -an "$logdir/${sourcefilename%.*}.framemd5"
ffmpeg_ffv1_err="$?"
[ "$ffmpeg_ffv1_err" -gt 0 ] && { echo ffmpeg ended with error ; exit 1 ;};
ffmpeg -i "$outputdir/${sourcefilename%.*}_ffv1.mov" -f framemd5 -an "$logdir/${sourcefilename%.*}_ffv1.framemd5"
ffmpeg_md5_err="$?"
[ "$ffmpeg_md5_err" -gt 0 ] && { echo ffmpeg md5 ended with error ; exit 1 ;};
mkdir "$outputdir/trimmed_materials"
muxmovie "$sourcefile" -track "Timecode Track" -track "Closed Caption Track" -self-contained -o "$outputdir/trimmed_materials/${sourcefilename%.*}_tc_e608.mov"
muxmovie_err="$?"
[ "$muxmovie_err" -gt 0 ] && { echo muxmovie ended with error ; exit 1 ;};
if [ $(md5 -q "$logdir/${sourcefilename%.*}.framemd5") = $(md5 -q "$logdir/${sourcefilename%.*}_ffv1.framemd5") ] ; then
report -dt "Everything looks safe. Going to delete the original."
mediainfo -f --language=raw --output=XML "$sourcefile" > "$logdir/${sourcefilename%.*}_mediainfo.xml"
rm -f -v "$sourcefile"
else
report -wt "Not looking safe. Going to keep the original."
fi
else
report -wt "$sourcefilename is not 2vuy or v210, quitting"
exit 1
fi
report -dt echo done with "$sourcefile"
shift
done
log -e