media | video edit

Make webm

convert video to webm for html5. here crf is quality (qmin < crf < qmax).

ffmpeg -y -i input.avi -c:v libvpx -qmin 20 -qmax 40 -crf 26 -b:v 1M -c:a libvorbis -qscale:a 7 output.webm

convert video to webm for html5 without sound.

ffmpeg -y -i input.avi -c:v libvpx -qmin 22 -qmax 50 -crf 26 -b:v 1M -an output.webm

convert video to vp9 webm

ffmpeg -i input.mp4 -c:v libvpx-vp9 -crf 30 -b:v 900K -c:a libvorbis -b:a 128k -threads 8 -speed 1 output.webm

remove audio from a video:

ffmpeg -i input.webm -c copy -an output.webm

Cut video

cut video without encoding from 15s to 20s.

ffmpeg -i input.webm -c copy -ss 00:00:15 -to 00:00:20 out.webm

cut video and encode from 15s to 20s. (with sound)

ffmpeg -y -i input.avi -c:v libvpx -qmin 20 -qmax 40 -crf 26 -b:v 1M -ss 00:00:15 -to 00:00:20 -c:a libvorbis -qscale:a 7 output.webm

cut video and encode from 15s to 20s. (without sound)

ffmpeg -y -i in.avi -c:v libvpx -qmin 22 -qmax 50 -crf 26 -b:v 1M -ss 00:00:15 -to 00:00:20 -an out.webm

clip starting at 15s for duration 20 seconds. (with sound)

ffmpeg -y -i input.avi -c:v libvpx -qmin 20 -qmax 40 -crf 26 -b:v 1M -ss 00:00:15 -t 00:00:20 -c:a libvorbis -qscale:a 7 output.webm

clip starting at 15s for duration 20 seconds. (without sound)

ffmpeg -y -i in.avi -c:v libvpx -qmin 22 -qmax 50 -crf 26 -b:v 1M -ss 00:00:15 -t 00:00:20 -an out.webm

flag to implement milliseconds:

-ss 00:00:15.aaa -t 00:00:20.bbb

Crop video

crop video:

ffmpeg -i in.mp4 -filter:v "crop=640:480:20:30" out.mp4

test before cropping:

ffplay -i input.avi -vf "crop=640:480:20:30"

Change fps

ffmpeg flag to inccrease fps:

-filter:v "setpts=0.5*PTS"

ffmpeg flag to decrease fps:

-filter:v "setpts=2.0*PTS"

Scale video

ffmpeg flag to resize video:

-vf scale=1024:768

ffmpeg flag to scale video keeping the aspect ratio:

-vf scale=1024:-1

Concatenate Videos

Concat ts files in a folder and output to mp4:

ffmpeg -i "concat:$(ls -1 *.ts* | perl -0pe 's/\n/|/g;s/\|$//g')" -c copy -bsf:a aac_adtstoasc outputfile.mp4

Join Videos Side by Side

Join 4 mp4 files (10px border between left & right, 3px border between top & bottom):

ffmpeg -i top_l.mp4 -i bottom_l.mp4 -i top_r.mp4 -i bottom_r.mp4 -filter_complex "[0:v]pad=iw:ih+3[tl]; [tl][1:v]vstack,pad=iw+10:ih[l]; [2:v]pad=iw:ih+3[tr]; [tr][3:v]vstack[r]; [l][r]hstack" output.mp4

ffmpeg flag to add to terminate video when the shortest input terminates:

*stack=shortest=1

Reference

stackoverflow

askubuntu