Last active
May 23, 2023 15:31
-
-
Save andrewhodel/a2854df02a5ab06967b5223f5b0a44b6 to your computer and use it in GitHub Desktop.
ffmpeg synchonize audio and video
This file contains 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
# trim video file to a certain range of frames | |
ffmpeg -i render0000-28914.mp4 -vf select="between(n\,0\,61),setpts=PTS-STARTPTS" one.mp4 | |
# display number of frames in a video file | |
ffmpeg -i one.mp4 -f null /dev/null | |
# add audio to video file at the start and extend the audio to the end of the video with silence | |
ffmpeg -i one.mp4 -i electricity-zap.mp3 -filter_complex "[1:0]apad" -shortest test.mp4 | |
# add audio to video file and leave audio length as is, -stream_loop will loop the audio faster than the video with this file | |
ffmpeg -i one.mp4 -i electricity-zap.mp3 -map 0:v -map 1:a -c:v copy test.mp4 | |
# loop a file a number of times into one long file | |
ffmpeg -stream_loop 500 -i test.mp4 -c copy 500_loops.mp4 | |
# add multiple audio files to video at defined millisecond times of the video file | |
ffmpeg -y -i video.mp4 -i 002.ogg.mp3 -i 003.ogg.mp3 -i 004.ogg.mp3 -filter_complex "[1]adelay=1000:all=1[s1];[2]adelay=2500:all=1[s2];[3]adelay=4000:all=1[s3];[s1][s2][s3]amix=inputs=3:normalize=false[a]" -map 0:v -map "[a]" -preset ultrafast video_with_audio.mp4 | |
# add one audio file multiple times to video at defined millisecond times of the video file | |
ffmpeg -y -i video.mp4 -i 002.ogg.mp3 -filter_complex "[1]adelay=1000:all=1[s1];[1]adelay=2500:all=1[s2];[1]adelay=4000:all=1[s3];[s1][s2][s3]amix=inputs=3:normalize=false[a]" -map 0:v -map "[a]" -preset ultrafast video_with_audio.mp4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment