Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Convert videos to proper formats for HTML5 video on Linux shell using ffmpeg. Will probably convert this to a bash script later, but for the time being, here's some examples. Not sure there have actually sensible dimensions and bitrates for web video.
# webm
ffmpeg -i IN -f webm -vcodec libvpx -acodec libvorbis -ab 128000 -crf 22 -s 640x360 OUT.webm
# mp4
ffmpeg -i IN -acodec aac -strict experimental -ac 2 -ab 128k -vcodec libx264 -vpre slow -f mp4 -crf 22 -s 640x360 OUT.mp4
# ogg (if you want to support older Firefox)
ffmpeg2theora IN -o OUT.ogv -x 640 -y 360 --videoquality 5 --audioquality 0 --frontend
@joker234
Copy link

joker234 commented May 11, 2014

Maybe someone is interested in my stuff ;)

#!/usr/bin/zsh
# based on https://gist.github.com/yellowled/1439610
IN=$1
OUT=$(echo $1 | sed 's/^\(.*\)\.[a-zA-Z0-9]*$/\1/')
# webm
ffmpeg -i $IN -f webm -vcodec libvpx -acodec libvorbis -ab 128000 -crf 22 -s 640x360 $OUT.webm

# mp4
ffmpeg -i $IN -acodec aac -strict experimental -ac 2 -ab 128k -vcodec libx264 -vpre slow -f mp4 -crf 22 -s 640x360 $OUT.mp4

# ogg (if you want to support older Firefox)
ffmpeg2theora $IN -o $OUT.ogv -x 640 -y 360 --videoquality 5 --audioquality 0  --frontend

@MrOrz
Copy link

MrOrz commented Jun 4, 2014

Thanks for sharing this script. Extremely useful!

BTW I found that while single-pass webm video looks bad compared to h264 videos with the same size, its performance is pretty satisfactory when using 2-pass encoding workflow.

ffmpeg -i $(IN) -c:v libvpx -pass 1 -an -f rawvideo -y /dev/null  # Generates ffmpeg2pass-0.log
ffmpeg -i $(IN) -c:v libvpx -pass 2 -f webm -b:v 400K -crf 10 -an -y $(OUT).webm

@crivotz
Copy link

crivotz commented Aug 7, 2015

Thanks very useful ;)

@joaofnr
Copy link

joaofnr commented Sep 14, 2015

Just what I needed! Convertion to webm succesful, but to mp4 i received the error message: "File for preset 'slow' not found"

Looking around, i found out that now the preset option must be declared using -preset instead of -vpre - thanks to Stack Overflow: http://stackoverflow.com/questions/11929109/i-only-have-two-presets-for-ffmpeg-x264-in-ubuntu-11-04

That helped a lot! Thanks for sharing ;)

@chuyskywalker
Copy link

chuyskywalker commented Dec 21, 2015

This was a good starting point. I went further and am to do all the encoding without having to directly install FFmpeg! https://github.com/chuyskywalker/easy-web-video-encode

@jsiebach
Copy link

jsiebach commented Feb 20, 2017

THANK YOU!

As @joaofnr said, -vpre does need to be changed to -preset in the mp4 line

@rpsu
Copy link

rpsu commented Jul 16, 2017

Will probably convert this to a bash script later, but for the time being, here's some examples.

Well, I did it now. https://github.com/rpsu/dvd_converter/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment