-
Notifications
You must be signed in to change notification settings - Fork 1
/
capture-vhs
executable file
·112 lines (98 loc) · 3.31 KB
/
capture-vhs
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
#!/bin/bash
#
# Copyright 2015 by Chris Osborn <[email protected]>
#
# This file is part of viddin.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License at <http://www.gnu.org/licenses/> for
# more details.
INPUT=2
WIDTH=640
HEIGHT=480
FPS=29.97
while [ $# -gt 0 -a `expr substr "${1:-empty}" 1 2` = "--" ] ; do
case "$1" in
--width)
WIDTH=$2
shift 2
;;
--height)
HEIGHT=$2
shift 2
;;
--input)
INPUT=$2
shift 2
;;
--fps)
FPS=$2
shift 2
;;
*)
echo unknown flag "$1"
exit 1
;;
esac
done
DEST=$1
DURATION=$2
if [ -z "${DEST}" ] ; then
echo Need a filename
exit 1
fi
if [ -z "${DURATION}" ] ; then
echo How long to record for
exit 1
fi
# Accept duration as seconds, mm:ss, or h:mm:ss
MINSEC=${DURATION}
DURSECONDS=0
while expr match ${MINSEC} '[0-9][0-9]*:[0-9][0-9]' > /dev/null ; do
minutes=`echo ${MINSEC} | sed -e 's/:.*//'`
MINSEC=`echo ${MINSEC} | sed -e 's/[^:]*://'`
DURSECONDS=`expr ${DURSECONDS} \* 60 + ${minutes}`
done
DURSECONDS=`expr ${DURSECONDS} \* 60 + ${MINSEC}`
HOURS=`expr ${DURSECONDS} / 3600`
MINUTES=`expr ${DURSECONDS} % 3600 / 60`
SECONDS=`expr ${DURSECONDS} % 3600 % 60`
DURHMS=`echo ${HOURS} ${MINUTES} ${SECONDS} | awk '{printf "%i:%02i:%02i\n", $1, $2, $3}'`
# FIXME - look at extension and allow mpeg2 or mp4
BASE="${DEST%.*}"
# Start the VCR
linqir Mitsubishi/0xea20
mkdir ${BASE}
cd ${BASE}
dvgrab -d ${DURHMS}
# mpeg2
#DEST="${BASE}.mpg"
#vlc v4l2:// :v4l2-dev=/dev/video0 :v4l2-width=${WIDTH} :v4l2-height=${HEIGHT} :v4l2-input=${INPUT} :standard=0 :input-slave=alsa://hw:0,0 --sout="#duplicate{dst=display,dst={transcode{vcodec=mp2v,vb=4096,acodec=mpga,ab=192}:std{access=file,mux=ps,dst='${DEST}'}}}" --run-time=${DURSECONDS} vlc://quit
# mp4
#DEST="${BASE}.mp4"
#vlc v4l2:// :v4l2-dev=/dev/video0 :v4l2-width=${WIDTH} :v4l2-height=${HEIGHT} :v4l2-input=${INPUT} :standard=0 :input-slave=alsa://hw:0,0 --sout="#duplicate{dst=display,dst={transcode{venc=x264{profile=baseline},vcodec=h264,vb=2000,fps='${FPS}',vfilter=canvas{width='${WIDTH}',height='${HEIGHT}',aspect=4:3},acodec=mpga,ab=128}:std{access=file,mux=mp4,dst='${DEST}'}}}" --run-time=${DURSECONDS} vlc://quit
# This will dump exact copy of stream from card. 60-70 gigs per hour!
#DEST="${BASE}.avi"
#vlc v4l2:// :v4l2-dev=/dev/video0 :v4l2-width=${WIDTH} :v4l2-height=${HEIGHT} :v4l2-input=${INPUT} :standard=0 :input-slave=alsa://hw:0,0 --sout="#duplicate{dst=std{access=file,dst='${DEST}'}, dst=display}" --run-time=${DURSECONDS} vlc://quit
#v4lctl setinput ${INPUT}
#ffmpeg -f alsa -ac 2 -i hw:0,0 -f video4linux2 -i /dev/video0 -s 720x480 -aspect 4:3 -vcodec libx264 -preset ultrafast -acodec libfaac -t ${DURSECONDS} ${DEST}
# Stop the VCR
linqir Mitsubishi/0xea28
# Merge all the split dv files
pv dv* > ${BASE}.dv
STATUS=$?
if [ $STATUS = 0 ] ; then
rm dv*
mv ${BASE}.dv ..
cd ..
rmdir ${BASE}
else
rm ${BASE}.dv
fi