Skip to content

Instantly share code, notes, and snippets.

@aleskiontherun
Last active September 5, 2016 04:56
Show Gist options
  • Save aleskiontherun/ed98e16307afba59aae1 to your computer and use it in GitHub Desktop.
Save aleskiontherun/ed98e16307afba59aae1 to your computer and use it in GitHub Desktop.
Creating HTML5 video files with ffmpeg
# Based on https://blog.mediacru.sh/2013/12/23/The-right-way-to-encode-HTML5-video.html
# ogv
ffmpeg -i input.mp4 -q 5 -pix_fmt yuv420p -vcodec libtheora -vf "crop=1200:680:360:200" -an output.ogv
# Cropped WebM without audio
ffmpeg -i input.mp4 -c:v libvpx -pix_fmt yuv420p -quality good -b:v 2M -crf 5 -vf "crop=1200:680:360:200,scale=trunc(in_w/2)*2:trunc(in_h/2)*2" -an -f webm output.webm
# Same mp4
ffmpeg -i input.mp4 -vcodec libx264 -pix_fmt yuv420p -profile:v baseline -preset slower -b:v 2M -crf 18 -maxrate 4000k -bufsize 1835k -vf "crop=1200:680:360:200,scale=trunc(in_w/2)*2:trunc(in_h/2)*2" -an -movflags faststart -f mp4 output.mp4
# Cut video
ffmpeg -i input.mov -c copy -t 5 output.mov
# Check mp4 for streaming
# avprobe moov atom first right after the ftyp
sudo apt-get install libav-tools
sudo apt-get install atomicparsley
AtomicParsley input.mp4 -T | less
# fix
ffmpeg -i input.mp4 -movflags faststart -vcodec copy -acodec copy output.mp4
# first frame
ffmpeg -i input.mp4 -vf "crop=1200:680:360:200" -vframes 1 -f image2 output.jpg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment