-
Notifications
You must be signed in to change notification settings - Fork 1
/
vid2x264
executable file
·59 lines (45 loc) · 1.15 KB
/
vid2x264
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
#!/bin/bash
# Convert a video stream into high quality x264; by default 720p, CRF 20,
# preset: slow.
IFN=""
OFN=""
PROFILE="720high"
ENCSETTINGS_HIGH="-preset slow -crf 20"
ENCSETTINGS_MED="-preset slow -crf 23"
usage() {
echo "Convert a video stream into x264, copying audio."
echo -e "\nUsage: $0 -i input_file [-p profile] [-d] output_file"
exit 1
}
# Parse arguments
while getopts "i:p:d" OPT; do
case $OPT in
i ) IFN=$OPTARG ;;
p ) PROFILE=$OPTARG ;;
d ) DRYRUN=1 ;;
esac
done
shift $((OPTIND-1))
OFN="$1"; shift
[[ -z "$IFN" ]] && usage
[[ -z "$OFN" ]] && usage
# Profile definitions
if [[ $PROFILE == "high" ]]; then
ENCSETTINGS="$ENCSETTINGS_HIGH"
elif [[ $PROFILE == "med" ]]; then
ENCSETTINGS="$ENCSETTINGS_MED"
elif [[ $PROFILE == "720high" ]]; then
HEIGHT="720"
ENCSETTINGS="$ENCSETTINGS_HIGH"
elif [[ $PROFILE == "480med" ]]; then
HEIGHT="480"
ENCSETTINGS="$ENCSETTINGS_MED"
else
echo "No valid profile specified!"
exit
fi
# Compile command line and run ffmpeg
[[ -n $HEIGHT ]] && VF="-vf scale=-2:$HEIGHT"
CMD="ffmpeg -y -i '$IFN' $VF -c:v libx264 $ENCSETTINGS -c:a copy $@ '$OFN'"
echo "$CMD"
[[ -z $DRYRUN ]] && eval $CMD