Skip to content

Instantly share code, notes, and snippets.

@herdianf
Created June 6, 2023 06:23
Show Gist options
  • Save herdianf/fa85931e1ff11a317fefa78889587bd8 to your computer and use it in GitHub Desktop.
Save herdianf/fa85931e1ff11a317fefa78889587bd8 to your computer and use it in GitHub Desktop.
ffmpeg scripts
# cut video in middle
# In order to keep <start-15s> and <45s-end>, you need to
# keep all the frames which are "not between 15s and 45s":
ffmpeg -i input.mp4 \
-vf "select='not(between(t,15,45))', setpts=N/FRAME_RATE/TB" \
-af "aselect='not(between(t,15,45))', asetpts=N/SR/TB" \
output.mp4
#source https://stackoverflow.com/questions/64866231/remove-a-section-from-the-middle-of-a-video-without-concat
# concat multiple video with different orientation
ffmpeg -i 480.mp4 -i 640.mp4 -filter_complex \
"[0:v]scale=640:480:force_original_aspect_ratio=decrease,pad=640:480:(ow-iw)/2:(oh-ih)/2[v0]; \
[v0][0:a][1:v][1:a]concat=n=2:v=1:a=1[v][a]" \
-map "[v]" -map "[a]" -c:v libx264 -c:a aac output.mp4
ffmpeg -i input1.mp4 -i input2.webm -i input3.mov \
-filter_complex "[0:v:0][0:a:0][1:v:0][1:a:0][2:v:0][2:a:0]concat=n=3:v=1:a=1[outv][outa]" \
-map "[outv]" -map "[outa]" output.mkv
#source https://trac.ffmpeg.org/wiki/Concatenate
# cut video by time
ffmpeg -ss 00:01:00 -to 00:02:00 -i input.mp4 -c copy output.mp4
#source https://stackoverflow.com/questions/18444194/cutting-the-videos-based-on-start-and-end-time-using-ffmpeg
# change video ratio
ffmpeg -i input -vf "scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:-1:-1:color=black" output
# without upscaling
ffmpeg -i input -vf "scale='min(1280,iw)':min'(720,ih)':force_original_aspect_ratio=decrease,pad=1280:720:-1:-1:color=black" output
# crop to fit
ffmpeg -i input -vf "scale=1280:720:force_original_aspect_ratio=increase,crop=1280:720" output
# Using input images that each vary in size
ffmpeg -i input -vf "scale=1280:720:force_original_aspect_ratio=decrease:eval=frame,pad=1280:720:-1:-1:color=black" output
#src https://superuser.com/questions/547296/resizing-videos-with-ffmpeg-avconv-to-fit-into-static-sized-player
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment