Created
April 12, 2020 11:01
-
-
Save konrad/c43572f53b23e4d00e23202abe11a8e5 to your computer and use it in GitHub Desktop.
Small shell script to combine some photos and a mp3 file into a video file using ffmpeg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Small script to combine some photos, cut a mp3 file into two pieces, | |
# fade in and out and merge everything. Rather specific so needs to be | |
# adapted. ;) | |
# CC0 - Konrad Förstner | |
main(){ | |
TMP_FOLDER=/tmp/tmp_images | |
image_folder_to_video "input/photo_set_2/" output/Der_mutige_Hase.mp4 | |
add_audio | |
} | |
image_folder_to_video(){ | |
image_folder=$1 | |
output_video_path=$2 | |
mkdir -p ${TMP_FOLDER} | |
mkdir -p output | |
counter=1 | |
for image_file_path in ${image_folder}/* | |
do | |
tmp_image_file_path=${TMP_FOLDER}/$(printf "pic_%04d.jpg" "$counter") | |
echo "$image_file_path" to "$tmp_image_file_path" | |
cp "$image_file_path" "$tmp_image_file_path" | |
let counter=counter+1 | |
done | |
ffmpeg \ | |
-framerate 5 \ | |
-i ${TMP_FOLDER}/pic_%04d.jpg \ | |
-vcodec libx264 \ | |
-pix_fmt yuv420p \ | |
-y \ | |
${output_video_path} | |
} | |
add_audio(){ | |
# Cut part 1 | |
ffmpeg \ | |
-i input/Mission_Impossible_2_Theme_Instrumental.mp3 \ | |
-ss 00:01:17.0 \ | |
-to 00:01:34.0 \ | |
-y \ | |
-codec copy \ | |
tmp_1.mp3 | |
# fade in part 1 | |
ffmpeg -y -i tmp_1.mp3 -af afade=t=in:d=4 tmp_2.mp3 | |
# fade out part 1 | |
ffmpeg -y -i tmp_2.mp3 -af afade=t=out:st=16:d=1 tmp_3.mp3 | |
# Cut part 2 | |
ffmpeg \ | |
-i input/Mission_Impossible_2_Theme_Instrumental.mp3 \ | |
-ss 00:00:29.0 \ | |
-to 00:00:42.0 \ | |
-y \ | |
-codec copy \ | |
tmp_4.mp3 | |
# fade in part 2 | |
ffmpeg -y -i tmp_4.mp3 -af afade=t=in:d=4 tmp_5.mp3 | |
# fade out part 2 | |
ffmpeg -y -i tmp_5.mp3 -af afade=t=out:st=5:d=3 tmp_6.mp3 | |
printf "file tmp_3.mp3\nfile tmp_6.mp3\n" > tmp.txt | |
# Concat audio files | |
ffmpeg \ | |
-f concat \ | |
-safe 0 \ | |
-i tmp.txt \ | |
-c copy \ | |
-y \ | |
tmp_concated.mp3 | |
# Merge audio audio and Video | |
ffmpeg \ | |
-i output/Der_mutige_Hase.mp4 \ | |
-i tmp_concated.mp3 \ | |
-codec copy \ | |
-shortest \ | |
-y \ | |
output/Der_mutige_Hase_mit_Audio.mp4 | |
rm -f tmp* | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment