-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmerge_mp4.sh
executable file
·64 lines (52 loc) · 1.11 KB
/
merge_mp4.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
#!/bin/bash
# Merge mp4 files using ffmpeg
# See also https://trac.ffmpeg.org/wiki/Concatenate
set -e
USAGE="usage: `basename $0` [-o|--output <filename>] <input file(s)>"
INPUT=()
# Default output name
OUTPUT="output.mp4"
# Exit if no input files
if [ -z "$1" ]; then
echo $USAGE
exit 1
fi
if [ "$1" == "--help" ] || [ "$1" == "-h" ]; then
echo $USAGE
exit 1
fi
TEMP=`getopt -o o: --long output: -n 'merge_mp4.sh' -- "$@"`
eval set -- "$TEMP"
while true; do
case "$1" in
-o|--output)
case "$2" in
"")
shift 2
;;
*)
OUTPUT="$2"
shift 2
;;
esac
;;
--) shift; break ;;
esac
done
# Deal with spaces in filenames
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
# Add input files
while [ -n "$1" ]; do
INPUT+=($1)
shift;
done
PARTS=$(mktemp merge_mp4.XXXXXXXXXX)
for ITEM in ${INPUT[*]}
do
echo "file '$ITEM'" >> $PARTS
done
ffmpeg -f concat -safe 0 -i "$PARTS" -c copy $OUTPUT
rm -f "$PARTS"
# Restore IFS
IFS=$SAVEIFS