Last active
March 6, 2024 18:44
-
-
Save NISH1001/8167d6270168b0b9ef1559db61c502d8 to your computer and use it in GitHub Desktop.
merge audio with a looped GIF 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 | |
echo "i am paradox" | |
#ffmpeg -i audio.mp3 -ignore_loop 0 -i test.gif -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" -shortest -strict -2 -c:v libx264 -threads 5 -c:a aac -b:a 192k -pix_fmt yuv420p -shortest final.mp4 | |
# ffmpeg -i audio.mp3 -ignore_loop 0 -i test.gif -shortest -strict -2 -c:v libx264 -threads 5 -c:a aac -b:a 192k -pix_fmt yuv420p -shortest final.mp4 | |
# ffmpeg -i audio.mp3 -ignore_loop 0 -i test.gif -vf "scale=trunc(iw/2)*1:trunc(ih/2)*2" -shortest -strict -2 -c:v libx264 -threads 5 -c:a aac -b:a 192k -pix_fmt yuv420p -shortest final.mp4 | |
# ffmpeg -i audio.mp3 -ignore_loop 0 -i test.gif -vf "scale=640:-1" -shortest -strict -2 -c:v libx264 -threads 5 -c:a aac -b:a 192k -pix_fmt yuv420p -shortest final.mp4 | |
FRAME_RATE=24 | |
WIDTH=640 | |
HEIGHT=-1 | |
AUDIO="audio.mp3" | |
VIDEO="video.mp4" | |
GIF="test.gif" | |
OUTPUT="merged.mp4" | |
# convert video to gif | |
ffmpeg -i $VIDEO $GIF -hide_banner | |
# if you have a list of pictures to create GIF | |
# convert -delay 20 -loop 0 *.jpg output.gif | |
# merge gif and audio | |
ffmpeg -i $AUDIO -ignore_loop 0 -i $GIF -r $FRAME_RATE -vf scale=$WIDTH:$HEIGHT,pad=640:480:0:60:black -shortest -strict -2 -c:v libx264 -threads 8 -c:a aac -b:a 192k -pix_fmt yuv420p -shortest $OUTPUT | |
# if top and bottom cropping to be done | |
# reference: https://video.stackexchange.com/questions/4563/how-can-i-crop-a-video-with-ffmpeg | |
# Crop 20 pixels from the top, and 20 from the bottom: | |
ffmpeg -i $AUDIO -ignore_loop 0 -i $GIF -r $FRAME_RATE -vf scale=$WIDTH:$HEIGHT,pad=$WIDTH:0:0:60:black -filter:v "crop=in_w:in_h-40" -shortest -strict -2 -c:v libx264 -threads 8 -c:a aac -b:a 192k -pix_fmt yuv420p -shortest $OUTPUT | |
# change volume | |
ffmpeg -i input.mp4 -vol <volume_value> -vcodec copy out.mp4 -y | |
# download mp3 from youtube playlist | |
youtube-dl --extract-audio --audio-format mp3 -o "%(title)s.%(ext)s" <url to playlist> | |
ffmpeg -ss 01:32:30.0 -i video.mp4 -c copy -t 00:00:15.0 output.mp4 -y |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nem todo herói usa capa... obrigado!