-
Notifications
You must be signed in to change notification settings - Fork 1
/
dvcapture.sh
executable file
·242 lines (213 loc) · 8.03 KB
/
dvcapture.sh
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
#!/bin/bash
#declare the label of the identifier associated with the ingest and resulting package. Other labels are declared directly in the use of the ask and offerChoice functions below.
sourceidlabel="SourceID"
#container format to use (use avi,mkv, or mov)
container="mov"
#declare directory for packages of dv files to be written to during processing
CACHE_DIR=/home/archive-dv/Desktop/dvgrabs
#name of the log for dvgrab process data
DVLOG=dvgrab_capture.log
#name of the log for user process data
#enter technical defaults
CaptureDeviceSoftware="ffmpeg,dv_capture.sh version 0.2"
PlaybackDeviceManufacturer="Sony"
PlaybackDeviceModel="DSR-11"
PlaybackDeviceSerialNo="93313"
Interface="IEEE 1394"
OPLOG=ingest_operator.log
EXPECTED_NUM_ARGS=0
deps(){
DEPENDENCIES="dvgrab dvanalyzer gnuplot ffmpeg md5deep"
deps_ok=YES
for dep in $DEPENDENCIES ; do
if [ ! $(which $dep) ] ; then
echo -e "This script requires $dep to run but it is not installed"
echo -e "If you are running ubuntu or debian you might be able to install $dep with the following command"
echo -e "sudo apt-get install $dep"
deps_ok=NO
fi
done
if [[ "$deps_ok" == "NO" ]]; then
echo -e "Unmet dependencies ^"
echo -e "Aborting!"
exit 1
else
return 0
fi
}
ask(){
# This function requires 3 arguments
# 1) A prompt
# 2) The label for the metadata value
read -p "$1" response
if [ -z "$response" ] ; then
ask "$1" "$2"
else
echo "${2}: ${response}"
fi
}
offerChoice(){
# This function requires 3 arguments
# 1) A prompt
# 2) The label for the metadata value
# 3) A vocabulary list
PS3="$1"
label="$2"
eval set "$3"
select option in "$@"
do
break
done
echo "${label}: ${option}"
}
if [ $# -ne $EXPECTED_NUM_ARGS ] ; then
output_help
exit 0
fi
deps
dvstatus=`dvcont status`
if [ "$?" = "1" ] ; then
echo "The DV deck is not found. Make sure the FireWire is attached correctly and that the deck is on."
exit 1
fi
# setting static process metadata
echo
echo "CaptureDeviceSoftware: $CaptureDeviceSoftware"
echo "PlaybackDeviceManufacturer: $PlaybackDeviceManufacturer"
echo "PlaybackDeviceModel: $PlaybackDeviceModel"
echo "PlaybackDeviceSerialNo: $PlaybackDeviceSerialNo"
echo "Interface: $Interface"
echo
answer=`offerChoice "Do these values match your setup: " "setupcorrect" "'Yes' 'No'"`
if [ "$answer" == "setupcorrect: No" ] ; then
echo "Please edit these values in the header of $0 and rerun."
exit
fi
tmplog=/tmp/dv_capture
touch "$tmplog"
echo "CaptureDeviceSoftware: $CaptureDeviceSoftware" > "$tmplog"
echo "PlaybackDeviceManufacturer: $PlaybackDeviceManufacturer" >> "$tmplog"
echo "PlaybackDeviceModel: $PlaybackDeviceModel" >> "$tmplog"
echo "PlaybackDeviceSerialNo: $PlaybackDeviceSerialNo" >> "$tmplog"
echo "Interface: $Interface" >> "$tmplog"
answer=`ask "Please enter the Operator name: " "Operator"`
echo "$answer" >> "$tmplog"
echo
answer=`ask "Please enter the Source ID: " "$sourceidlabel"`
echo "$answer" >> "$tmplog"
id=`echo "$answer" | cut -d: -f2 | sed 's/ //g'`
answer=`offerChoice "Please enter the tape format: " "SourceFormat" "'DVCam' 'miniDV' 'DVCPRO'"`
echo "$answer" >> "$tmplog"
echo
answer=`offerChoice "Please enter the tape cassette brand: " "CassetteBrand" "'Sony' 'Panasonic' 'JVC' 'Maxell' 'Fujifilm'"`
echo "$answer" >> "$tmplog"
echo
answer=`ask "Please enter the Cassette Product No. (example: DVM60, 124, 126L): " "CassetteProductNo"`
echo "$answer" >> "$tmplog"
echo
answer=`ask "Please enter the tape condition: " "CassetteCondition"`
echo "$answer" >> "$tmplog"
echo
dvstatus=`dvcont status`
while [ "$dvstatus" = "Loading Medium" ] ; do
echo -n "Insert cassette: # ${id}, hit [q] to quit, or any key to continue. "
read insert_response
if [ "$insert_response" = "q" ] ; then
exit 1
else
dvstatus=`dvcont status`
fi
done
answer=`offerChoice "How should the tape be prepared?: " "PrepareMethod" "'Full repack then start' 'Rewind then start' 'Start from current position'"`
echo "$answer" >> "$tmplog"
prepanswer=`echo "$answer" | cut -d: -f2`
if [ "$prepanswer" = "Full repack then start" ] ; then
dvcont stop
echo "Fast Forwarding..."
dvcont ff
(stat=$(dvcont status); while [[ "$stat" != "Winding stopped" ]]; do sleep 2; stat=$(dvcont status); done)
echo "Rewinding..."
dvcont rewind
(stat=$(dvcont status); while [[ "$stat" != "Winding stopped" ]]; do sleep 2; stat=$(dvcont status); done)
elif [ "$prepanswer" = "Rewind then start" ] ; then
dvcont stop
echo "Rewinding..."
dvcont rewind
(stat=$(dvcont status); while [[ "$stat" != "Winding stopped" ]]; do sleep 2; stat=$(dvcont status); done)
fi
packageid=`cat "$tmplog" | grep "$sourceidlabel" | cut -d: -f2 | sed 's/ //g'`
if [ -d "$CACHE_DIR/$packageid" ] ; then
echo "The directory $CACHE_DIR/$packageid already exists. Please delete the directory and try again or do not ingest it again."
exit
fi
startingtime=$(date +"%Y-%m-%dT%T%z")
echo "starting to set up ingest package for $packageid"
echo "If the video on the tape ends AND the timecode stops incrementing below, then please press STOP on the deck to end the capture."
#set up package
mkdir -p "$CACHE_DIR/$packageid" "$CACHE_DIR/$packageid/objects" "$CACHE_DIR/$packageid/logs" "$CACHE_DIR/$packageid/metadata/submissionDocumentation"
#checking dir existence
if [ ! -d "$CACHE_DIR/$packageid" ]; then
echo "ERROR:$CACHE_DIR/$packageid does not exist and could not be corrected."
exit 1
fi
mv "$tmplog" "$CACHE_DIR/$packageid/metadata/submissionDocumentation/$OPLOG"
echo starting capturing tape...
dvgrab -f raw -showstatus -size 0 "$CACHE_DIR/$packageid/objects/${packageid}_.dv" 2>&1 | tee "$CACHE_DIR/$packageid/metadata/submissionDocumentation/${DVLOG}"
#trap '
echo finished capturing tape...
dvcont rewind &
endingtime=$(date +"%Y-%m-%dT%T%z")
echo "startingtime=$startingtime" >> "$CACHE_DIR/$packageid/metadata/submissionDocumentation/$OPLOG"
echo "endingtime=$endingtime" >> "$CACHE_DIR/$packageid/metadata/submissionDocumentation/$OPLOG"
echo done with "$packageid".
scriptdir=`dirname "$0"`
package="$CACHE_DIR/$packageid"
# dvanalyzer analysis
file=`find "$package/objects" -maxdepth 1 -mindepth 1 -type f -name "*v" ! -name ".*"`
filename=`basename "$file"`
if [ -f "$file" ] ; then
outputdir="$package/metadata/submissionDocumentation/${filename%.*}_analysis"
if [ ! -d "$outputdir" ] ; then
mkdir -p "$outputdir"
# plot graph
echo Analyzing DV stream...
dvanalyzer </dev/null --XML "$file" > "$outputdir/${filename%.*}_dvanalyzer.xml"
xsltproc "$scriptdir/dvanalyzer.xsl" "$outputdir/${filename%.*}_dvanalyzer.xml" > "$outputdir/${filename%.*}_dvanalyzer_summary.txt"
echo Plotting results...
echo "set terminal svg size 1920, 1080
set border 0
set datafile separator ','
set output '$outputdir/${filename%.*}${count}_dvanalyzer.svg'
set multiplot layout 4, 1 title 'DV Analyzer Graphs of $filename'
set style fill solid border -1
set xrange [ 0: ]
set yrange [ 0:100 ]
set grid y
unset xtics
set xdata time
set timefmt '%S'
set xtics format '%H:%M:%S'
set xtics nomirror
plot '$outputdir/${filename%.*}_dvanalyzer_summary.txt' u (\$1/29.97):(\$2) title 'Video Error Concealment (percentage)' lt 1 with impulses
plot '' u (\$1/30):(\$3) title 'Channel 1 Audio Error (percentage)' lt 2 with impulses
plot '' u (\$1/30):(\$4) title 'Channel 2 Audio Error (percentage)' lt 3 with impulses
set yrange [ -100:100 ]
plot '' u (\$1/30):(\$5) title 'Audio Error Head Difference' lt 4 with impulses" | gnuplot
echo Done
fi
else
echo "ERROR - $name is not a file"
fi
# rewrap dv file to container
cd "$package/objects/"
for dvfile in *.dv ; do
if [ -f "$dvfile" ] ; then
ffmpeg -i "$dvfile" -map 0 -c copy "${dvfile%.*}.${container}"
if [ "$?" = "0" ] ; then
rm "$dvfile"
fi
fi
done
#md5deep on objects
md5deep -retl "$package/objects/" > "$package/metadata/checksum.txt"
#' 0