Skip to content

Instantly share code, notes, and snippets.

@masonwan
Last active February 12, 2024 06:41
Show Gist options
  • Save masonwan/281f7fd5a17c00a4ffe81afc44d9cfee to your computer and use it in GitHub Desktop.
Save masonwan/281f7fd5a17c00a4ffe81afc44d9cfee to your computer and use it in GitHub Desktop.

FFmpeg

A list of useful ffmpeg commands

See the video meta data

ffprobe video.mp4

Covert to High Efficiency Video Coding (HEVC) format

ffmpeg -c:v libx265 -c:a copy -i input.mp4 out.mp4

IMO, HEVC is so far (2020-04-15) the best codec for video. Very good compression rate and encoding performance.

WebM has a lot of limitations. I have not find a performant way to encode to WebM with FFmpeg.

Resize (scale) the video to 720p

ffmpeg -vf scale=-1:720 -c:a copy -i input.mp4 out.mp4

-1 means it will automatically calculate the output width with the source ratio.

Skip to certain time

ffmpeg -ss 00:00:15 -i input.mp4 -codec copy out.mp4

The order of -ss actually matters (surprise!). It seems one uses the closest frame before the encoding, another uses the frame after the encoding.

Specify duration

ffmpeg -i input.mp4 -codec copy -t 15 out.mp4

Audio parameters

  • -c:a copy: copy the audio stream
  • -an: ignore the audio stream

Script to concat GoPro video files

function concat-gopro-video -d 'Concat all GoPro video files in the folder'
  set files (ls GX*.MP4)
  rm files.txt
  for file in $files
    echo "file '$file'" >> files.txt
  end
  cat files.txt
  sleep 1
  ffmpeg -f concat -safe 0 -i files.txt -c copy $argv[1]
  log info "Complete concat video '$argv[1]'"
end

Example of the text file for merging video

file 'video1.mp4'
file 'video2.mp4'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment