This repository has been archived by the owner on Jul 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.sh
67 lines (55 loc) · 1.86 KB
/
script.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
#!/bin/sh
# retrieve all mp4 media files inside assets/timeline folder and generate multiple video resolutions for those videos using its metadata.
ASSETS_FOLDER=assets/timeline
for MEDIA_FILE in `ls $ASSETS_FOLDER | grep .mp4`; do
# 1. retrieve filename
FILE_NAME=$(echo $MEDIA_FILE | sed -n 's/.mp4//p' | sed -n 's/-1920x1080//p')
# 2. split files into isolated folders and create different files for each video resolution
FILE_PATH=$ASSETS_FOLDER/$MEDIA_FILE
FOLDER_TARGET=$ASSETS_FOLDER/$FILE_NAME
mkdir -p $FOLDER_TARGET
OUTPUT=$ASSETS_FOLDER/$FILE_NAME/$FILE_NAME
DURATION=$(ffprobe -i $FILE_PATH -show_format -v quiet | sed -n 's/duration=//p')
OUTPUT144=$OUTPUT-$DURATION-144
OUTPUT360=$OUTPUT-$DURATION-360
OUTPUT720=$OUTPUT-$DURATION-720
echo 'rendering in 720p'
ffmpeg -y -i $FILE_PATH \
-c:a aac -ac 2 \
-vcodec h264 -acodec aac \
-ab 128k \
-movflags frag_keyframe+empty_moov+default_base_moof \
-b:v 1500k \
-maxrate 1500k \
-bufsize 1000k \
-vf "scale=-1:720" \
-v quiet \
$OUTPUT720.mp4
echo 'rendering in 360p'
ffmpeg -y -i $FILE_PATH \
-c:a aac -ac 2 \
-vcodec h264 -acodec aac \
-ab 128k \
-movflags frag_keyframe+empty_moov+default_base_moof \
-b:v 400k \
-maxrate 400k \
-bufsize 400k \
-vf "scale=-1:360" \
-v quiet \
$OUTPUT360.mp4
echo 'rendering in 144'
ffmpeg -y -i $FILE_PATH \
-c:a aac -ac 2 \
-vcodec h264 -acodec aac \
-ab 128k \
-movflags frag_keyframe+empty_moov+default_base_moof \
-b:v 300k \
-maxrate 300k \
-bufsize 300k \
-vf "scale=256:144" \
-v quiet \
$OUTPUT144.mp4
echo $OUTPUT144.mp4
echo $OUTPUT360.mp4
echo $OUTPUT720.mp4
done