-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbarsandtoner
executable file
·71 lines (60 loc) · 2.61 KB
/
barsandtoner
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
#!/bin/bash
get_width(){
width=$(ffprobe "$1" -show_streams -select_streams v:0 2> /dev/null | grep "^width=" | cut -d = -f 2)
}
get_height(){
height=$(ffprobe "$1" -show_streams -select_streams v:0 2> /dev/null | grep "^height=" | cut -d = -f 2)
}
get_framerate(){
framerate=$(ffprobe "$1" -show_streams -select_streams v:0 2> /dev/null | grep "^r_frame_rate=" | cut -d = -f 2)
}
get_channels(){
channels=$(ffprobe "$1" -show_streams -select_streams a:0 2> /dev/null | grep "^channels=" | cut -d = -f 2)
}
get_sar(){
sar=$(ffprobe "$1" -show_streams -select_streams v:0 2> /dev/null | grep "^sample_aspect_ratio=" | cut -d = -f 2 | sed 's|:|/|g')
if [ "$sar" = "0/1" ] ; then
sar="1/1"
fi
}
if [ "$#" = 0 ] ; then
echo "This script accepts input videos and generates outputs that include bars and tone at the head, plus a timecode track."
echo "Usage: $(basename ${0}) [ -o output_directory ] fileorpackage1 [ fileorpackage2 ... ]"
exit
fi
# command-line options to set mediaid and original variables
OPTIND=1
while getopts ":o:x:" opt ; do
case "${opt}" in
o) output_dir="$OPTARG" ;;
x) audio_offset="$OPTARG" ;;
*) echo "bad option -$OPTARG" ; usage ;;
:) echo "Option -$OPTARG requires an argument" ; exit 1 ;;
esac
done
shift $(( ${OPTIND} - 1 ))
input_movie="$1"
name=`basename "$input_movie"`
if [ ! -s "$input_movie" ] ; then
echo Hey "$input_movie" does not look like a real file.
exit
fi
if [ ! -d "$output_dir" ] ; then
output_dir=`dirname "$input_movie"`
fi
if [ ! "$audio_offset" ] ; then
audio_offset="0"
fi
get_width "${input_movie}"
get_height "${input_movie}"
get_framerate "${input_movie}"
get_channels "${input_movie}"
get_sar "${input_movie}"
ffmpeg -f lavfi -i "smptebars=s=${width}x${height}:r=${framerate}:sar=${sar}:d=40.033" \
-f lavfi -i "aevalsrc=0.141253*sin(1000*2*PI*t):d=40.033:s=48000:c=${channels}" \
-f lavfi -i "color=black:s=${width}x${height}:r=${framerate}:sar=${sar}:d=5" \
-f lavfi -i "aevalsrc=0:d=5:s=48000:c=${channels}" -i "${input_movie}" \
-filter_complex "[0:v:0][1:a:0][2:v:0][3:a:0][4:v:0][4:a:0]concat=n=3:v=1:a=1[v][a];\
[v]drawtext=fontsize=40:fontfile=/Library/Fonts/Courier New Bold.ttf:fontcolor=white:enable=gte(t\,30)*lt(t\,40):x=(w-text_w)/2:y=(h-text_h-line_h)/2:box=1:[email protected]:text=${name%.*}[v1];\
[a]asetpts=PTS+${audio_offset}/TB[a1]" \
-map '[v1]' -map '[a1]' -shortest -c:v v210 -r 30000/1001 -metadata:s:v:0 timecode="00:59:15;00" -metadata:s:v:0 encoder="Uncompressed 10-bit 4:2:2" -c:a pcm_s24le -ac 2 -ar 48000 -y "$output_dir/${name%.*}_ohyay3.mov"