Useful FFmpeg Commands for Working with Audio and Video Files

  1. Cut video file into a smaller clip
    ffmpeg -i input.mp4 -ss 00:00:50.0 -codec copy -t 20 output.mp4
  2. Split a video into multiple parts
    ffmpeg -i video.mp4 -t 00:00:50 -c copy small-1.mp4 -ss 00:00:50 -codec copy small-2.mp4
  3. Mute a video
    ffmpeg -i video.mp4 -an mute-video.mp4
  4. Extract the audio from video
    ffmpeg -i video.mp4 -vn -ab 256 audio.mp3
  5. Convert a video into an animated GIF
    ffmpeg -i video.mp4 -vf scale=500:-1 -t 10 -r 10 image.gif
  6. Extract image frames from a video
    ffmpeg -ss 00:00:15 -i video.mp4 -vf scale=800:-1 -vframes 1 image.jpg
  7. Convert Video into Images
    ffmpeg -i movie.mp4 -r 0.25 frames_%04d.png
  8. Merge an audio and video file
    ffmpeg -i video.mp4 -i audio.mp3 -c:v copy -c:a aac -strict experimental output.mp4
  9. Resize a video
    ffmpeg -i input.mp4 -s 480x320 -c:a copy output.mp4
  10. Create video slideshow from images (5 seconds duration for each frame)
    ffmpeg -r 1/5 -i img%03d.png -c:v libx264 -r 30 -pix_fmt yuv420p slideshow.mp4
  11. Add a poster image to audio
    ffmpeg -loop 1 -i image.jpg -i audio.mp3 -c:v libx264 -c:a aac -strict experimental -b:a 192k -shortest output.mp4
  12. Convert a single image into a video (the -t parameter is the video duration)
    ffmpeg -loop 1 -i image.png -c:v libx264 -t 30 -pix_fmt yuv420p video.mp4
  13. Add subtitles to a movie
    ffmpeg -i movie.mp4 -i subtitles.srt -map 0 -map 1 -c copy -c:v libx264 -crf 23 -preset veryfast output.mkv
  14. Crop an audio file
    ffmpeg -ss 00:01:30 -t 30 -acodec copy -i inputfile.mp3 outputfile.mp3
  15. Change the audio volume
    ffmpeg -i input.wav -af 'volume=0.5' output.wav
  16. Rotate a video 90° clockwise
    ffmpeg -i input.mp4 -filter:v 'transpose=1' rotated-video.mp4
    ffmpeg -i input.mp4 -filter:v 'transpose=2,transpose=2' rotated-video.mp4 # 180° counter-clockwise
  17. Speed up or Slow down the video
    ffmpeg -i input.mp4 -filter:v "setpts=0.125*PTS" output.mp4
  18. Speed up or Slow down the audio
    ffmpeg -i input.mkv -filter:a "atempo=2.0" -vn output.mkv