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.

Revisions

  1. andrewhodel revised this gist May 21, 2023. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions ffmpeg_audio_video_files_sync.sh
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,7 @@ ffmpeg -i one.mp4 -i electricity-zap.mp3 -map 0:v -map 1:a -c:v copy test.mp4
    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=3[a]" -map 0:v -map "[a]" -preset ultrafast video_with_audio.mp4
    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=3[a]" -map 0:v -map "[a]" -preset ultrafast video_with_audio.mp4
    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
  2. andrewhodel revised this gist May 21, 2023. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions ffmpeg_audio_video_files_sync.sh
    Original file line number Diff line number Diff line change
    @@ -17,6 +17,4 @@ ffmpeg -stream_loop 500 -i test.mp4 -c copy 500_loops.mp4
    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=3[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=3[a]" -map 0:v -map "[a]" -preset ultrafast video_with_audio.mp4

    # if you add more than 10 using either of the previous two commands, use multiple ffmpeg commands and 10 per or it will create a file with no sound
    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=3[a]" -map 0:v -map "[a]" -preset ultrafast video_with_audio.mp4
  3. andrewhodel revised this gist May 21, 2023. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion ffmpeg_audio_video_files_sync.sh
    Original file line number Diff line number Diff line change
    @@ -17,4 +17,6 @@ ffmpeg -stream_loop 500 -i test.mp4 -c copy 500_loops.mp4
    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=3[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=3[a]" -map 0:v -map "[a]" -preset ultrafast video_with_audio.mp4
    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=3[a]" -map 0:v -map "[a]" -preset ultrafast video_with_audio.mp4

    # if you add more than 10 using either of the previous two commands, use multiple ffmpeg commands and 10 per or it will create a file with no sound
  4. andrewhodel revised this gist May 21, 2023. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion ffmpeg_audio_video_files_sync.sh
    Original file line number Diff line number Diff line change
    @@ -14,4 +14,7 @@ ffmpeg -i one.mp4 -i electricity-zap.mp3 -map 0:v -map 1:a -c:v copy test.mp4
    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=3[a]" -map 0:v -map "[a]" -preset ultrafast video_with_audio.mp4
    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=3[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=3[a]" -map 0:v -map "[a]" -preset ultrafast video_with_audio.mp4
  5. andrewhodel revised this gist May 21, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ffmpeg_audio_video_files_sync.sh
    Original file line number Diff line number Diff line change
    @@ -14,4 +14,4 @@ ffmpeg -i one.mp4 -i electricity-zap.mp3 -map 0:v -map 1:a -c:v copy test.mp4
    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[s1];[2]adelay=2500[s2];[3]adelay=4000[s3];[s1][s2][s3]amix=3[a]" -map 0:v -map "[a]" -preset ultrafast video_with_audio.mp4
    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=3[a]" -map 0:v -map "[a]" -preset ultrafast video_with_audio.mp4
  6. andrewhodel revised this gist May 21, 2023. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion ffmpeg_audio_video_files_sync.sh
    Original file line number Diff line number Diff line change
    @@ -11,4 +11,7 @@ ffmpeg -i one.mp4 -i electricity-zap.mp3 -filter_complex "[1:0]apad" -shortest t
    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
    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[s1];[2]adelay=2500[s2];[3]adelay=4000[s3];[s1][s2][s3]amix=3[a]" -map 0:v -map "[a]" -preset ultrafast video_with_audio.mp4
  7. andrewhodel revised this gist May 20, 2023. 1 changed file with 1 addition and 4 deletions.
    5 changes: 1 addition & 4 deletions ffmpeg_audio_video_files_sync.sh
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,4 @@ ffmpeg -i one.mp4 -i electricity-zap.mp3 -filter_complex "[1:0]apad" -shortest t
    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
    ffmpeg -stream_loop 500 -i test.mp4 -c copy 500_loops.mp4
  8. andrewhodel revised this gist May 20, 2023. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions ffmpeg_audio_video_files_sync.sh
    Original file line number Diff line number Diff line change
    @@ -8,10 +8,10 @@ ffmpeg -i one.mp4 -f null /dev/null
    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 one_with_audio.mp4
    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 one_with_audio.mp4 -c copy 500_loops.mp4
    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
  9. andrewhodel revised this gist May 20, 2023. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion ffmpeg_audio_video_files_sync.sh
    Original file line number Diff line number Diff line change
    @@ -11,4 +11,7 @@ ffmpeg -i one.mp4 -i electricity-zap.mp3 -filter_complex "[1:0]apad" -shortest t
    ffmpeg -i one.mp4 -i electricity-zap.mp3 -map 0:v -map 1:a -c:v copy one_with_audio.mp4

    # loop a file a number of times into one long file
    ffmpeg -stream_loop 500 -i one_with_audio.mp4 -c copy 500_loops.mp4
    ffmpeg -stream_loop 500 -i one_with_audio.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
  10. andrewhodel created this gist May 20, 2023.
    14 changes: 14 additions & 0 deletions ffmpeg_audio_video_files_sync.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    # 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 one_with_audio.mp4

    # loop a file a number of times into one long file
    ffmpeg -stream_loop 500 -i one_with_audio.mp4 -c copy 500_loops.mp4