Skip to content

Instantly share code, notes, and snippets.

@andrewhodel
Last active May 23, 2023 15:31
Show Gist options
  • Select an option

  • Save andrewhodel/a2854df02a5ab06967b5223f5b0a44b6 to your computer and use it in GitHub Desktop.

Select an option

Save andrewhodel/a2854df02a5ab06967b5223f5b0a44b6 to your computer and use it in GitHub Desktop.
ffmpeg synchonize audio and video
# 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
# loop a file a number of times into one long file and keep valid frame rate, -c copy set the frame rate at 58.1264 fps
ffmpeg -stream_loop 500 -i test.mp4 -filter:v fps=60 500_loops.mp4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment