Skip to content

Instantly share code, notes, and snippets.

@Pmmlabs
Last active April 7, 2019 11:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pmmlabs/20d697297ee70320da7c0ba1aca6812c to your computer and use it in GitHub Desktop.
Save Pmmlabs/20d697297ee70320da7c0ba1aca6812c to your computer and use it in GitHub Desktop.
preset="-c:v h264 -crf 18 -preset veryslow"
width=640
height=1136
audiorate=44100
output="output.ts"
rm -rf processed $output
mkdir processed
pad_vertical() {
for i in `ls *.mp4`
do
out=$(ffmpeg -i $i -c copy -map 0:a /dev/null 2>&1)
if [[ $out = *"no streams"* ]]; then
ffmpeg -i $i -y -f lavfi -t 999 -i anullsrc=channel_layout=mono:sample_rate=44100 -shortest -c:v copy -c:a aac -map 0:v -map 1:a processed/$i.ts
else
ffmpeg -i $i -y -c copy processed/$i.ts
fi
done
}
pad_images() {
time=3
for i in `ls *.jpg`
do
ffmpeg \
-loop 1 -framerate 30 -t $time -i $i \
-f lavfi -t $time -i anullsrc=channel_layout=mono:sample_rate=$audiorate -c:a aac \
-vf scale=-2:$height,setsar=1:1 \
$preset -pix_fmt yuv420p -profile:v main \
-n processed/$i.ts
done;
}
pad_vertical
pad_images
cat processed/*.ts > $output
ls=`ls -l`
count=`echo "$ls" | wc -l`
for i in `seq 1 $count`
do
first=`echo "$ls" | head -n $i | tail -1 | awk '{print $9}'`
second=`echo "$ls" | head -n $((i+1)) | tail -1 | awk '{print $9}'`
first_t=`echo "$ls" | head -n $i | tail -1 | awk '{print $8}'`
second_t=`echo "$ls" | head -n $((i+1)) | tail -1 | awk '{print $8}'`
first_size=`echo "$ls" | head -n $i | tail -1 | awk '{print $5}'`
second_size=`echo "$ls" | head -n $((i+1)) | tail -1 | awk '{print $5}'`
if [[ "$first_t" == "$second_t" && "`echo $first | egrep -o '\.\w{3}'`" == ".mp4" && "`echo $second | egrep -o '\.\w{3}'`" == ".jpg" ]]
then
rm $second
fi
if [[ "$first_size" == "$second_size" ]]
then
rm $second
fi
done
preset="-crf 18 -preset veryslow"
width=1514
height=852
pad=517 #$[($width−480)/2]
audiorate=48000
output="output.mp4"
rm -rf processed $output
mkdir processed
pad_horizontal() {
for i in `ls *.hmp4`
do
ffmpeg \
-f mp4 \
-i $i \
-vf transpose=2,scale=$width:$height,setsar=1:1 \
$preset \
-ar $audiorate \
-y processed/$i.mp4
done;
}
pad_vertical() {
for i in `ls *.mp4`
do
ffmpeg \
-i $i \
-vf scale=-2:$height,pad=$width:$height:$pad:0,setsar=1:1 \
$preset \
-ar $audiorate \
-y processed/$i
done;
}
pad_images() {
time=4
for i in `ls *.jpg`
do
ffmpeg \
-loop 1 -framerate 30 -t $time -i $i \
-f lavfi -t $time -i anullsrc=channel_layout=mono:sample_rate=$audiorate \
-vf scale=-2:$height,pad=$width:$height:$pad:0,setsar=1:1 \
$preset \
-y processed/$i.mp4
done;
}
pad_horizontal
pad_vertical
pad_images
printf "file '%s'\n" processed/*.mp4 > mylist.txt
ffmpeg -f concat -safe 0 -i mylist.txt -fflags +genpts -c copy -y $output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment