User Tools

Site Tools


Sidebar



ffmpeg

FFMPEG

quality

-q:v 0 is highest quality
-q:v 31 is lowest quality

get / calculate number of frames

ffmpeg -i FILENAME -f null /dev/null

or add this to ~/.bash_profile

_fps() {
    ffmpeg -i "$1" -f null /dev/null
}
alias fps=_fps

set volume of audio

ffmpeg -i input.wav -af "volume=0.5" output.wav

gifenc (with speed)

palette="/tmp/palette.png"
speed=5

filters="fps=15,scale=800:-1:flags=lanczos,setpts=(1/$speed)*PTS"

ffmpeg -v warning -i $1 -vf "$filters,palettegen" -y $palette
ffmpeg -v warning -i $1 -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse" -y $2

calculate framerate to get a desired number of frames

say you have 2500 frames. You want to get 300 frames. 2500/300=8.3. Use 8.3 as input framerate and use 1 as output framerate. (or 83 as input framerate and 10 as output framerate)

ffmpeg -r 8.3 -i input.mp4 -vcodec mpeg4 -q:v 0 -r 1 output.mp4 

or

ffmpeg -r 83 -i input.mp4 -vcodec mpeg4 -q:v 0 -r 10 output.mp4 

etc

ffmpeg -r 7.5 -f concat -i list.txt -vcodec mpeg4 -g 1 -q:v 0 -s 2048x1024 -r 1 -y output2.mov

HQ animated gifs with custom palette

concat

list.txt:

file 'a-ceno.mov'
file 'b-cret.mov'
file 'c-jurtrias.mov'
file 'd-ltpaleo.mov'

commmand:

ffmpeg -f concat -i list.txt -c copy output.mov

change speed

ffmpeg -i input.mp4 -vf "setpts=(1/<speed>)*PTS" output.mp4

resize video to 480p or 720p

ffmpeg -i INPUT.MOV -s hd480 OUTPUT.MOV

create animated GIF from sequence and specify framerate

convert image sequence to movie

ffmpeg -i output/frame%d.jpg -g 1 -y -q:v 0 -r 10  output.mp4

lossless skip first x seconds of mp3

ffmpeg -ss 54 -i input.mp3 -acodec copy -y output.mp3

limit total number of frames (not changing framerate)

ffmpeg -i input.mp4 -vcodec mpeg4 -vframes 500 -q:v 0 output.mp4

cut / split video

ffmpeg -ss 00:01:22 -i Doodle3D.m4v -q 0 -vcodec copy -acodec copy -y tmp.mov
ffmpeg -ss 00:01:14 -t 00:00:31 -i Doodle3D-kickstarter-movie.mp4 -q 0 -vcodec copy -acodec copy -y tmp2.mp4

offset & seek

offset video (0.5 sec) & seek/skip to position in audio (0.3 sec):

ffmpeg -itsoffset 0.3 -i video-input.mp4 -ss 0.5 -i audio-input.mp3 -vcodec copy -acodec copy -y output.mov

fix aspect ratio

..... -s 900x720 -aspect 16:9 

-sameq vs -qscale

  • for video
-q:v 0
  • for audio
-q:a 0

add audio / soundtrack to movie

ffmpeg -i IMG_7966.MOV -i sound.mp3 -vcodec copy -acodec copy output.mov 

wellicht interessant

rawvideo / uncompressed avi

ffmpeg -i air_traffic_2048.mp4 -sameq -r 15 -vcodec rawvideo -y new.avi

more uncompressed info

ffmpeg -i one-hand-with-sleeve.mpg -sameq -g 1 -f mov -vcodec qtrle -pix_fmt rgb24 output.mov
ffmpeg -i input.mov -vcodec rawvideo -pix_fmt uyvy422 -vtag 2vuy  uncompressed.mov 

combine jpg's with existing mjpeg movie (on Windows)

@echo off
cd /d %0\..
 
if exist clouds-queue\*.jpg (
  cat clouds-queue/*.jpg | ffmpeg -f image2pipe -vcodec mjpeg -i - -sameq -s 2048x1024 -f mjpeg -vcodec mjpeg -y new-clouds.mov
  ffmpeg -f mjpeg -i concat:"clouds2048.mov|new-clouds.mov" -c copy -y combined.mov
)
 
if exist combined.mov (
  del clouds2048.mov
  del new-clouds.mov
  move combined.mov clouds2048.mov
  move clouds-queue\*.jpg clouds-done\
)

in case of segmentation faults you might need to add -vcoded

ffmpeg -i Globe4D-energy-related-content.mov -sameq -s 512x256 -vcodec mpeg4 Globe4D-energy-related-content-512.mov

combine multiple movies with ffmpeg

#!/bin/bash
ffmpeg -f mjpeg -i <\
(  ffmpeg -v 0 -i 07h.mov -f image2pipe -vcodec copy -y /dev/stdout;
  ffmpeg -v 0 -i 08h.mov -f image2pipe -vcodec copy -y /dev/stdout;
  ffmpeg -v 0 -i 09h.mov -f image2pipe -vcodec copy -y /dev/stdout;
  ...
) -vcodec copy -an -y total.mov
stty echo

add non-sequence images to movie with cat and ffmpeg

cat 2012050412*.jpg | ffmpeg -v 0 -f image2pipe -vcodec mjpeg -i  - -sameq -vcodec mjpeg -y 12h.mov

add new frames / image files to an existing mjpeg movie with ffmpeg

#!/bin/bash
ffmpeg -f mjpeg -i <\
(  ffmpeg -v 0 -i clouds.mov -f image2pipe -vcodec copy -y /dev/stdout;
  cat clouds-queue/*.jpg | ffmpeg -v 0 -f image2pipe -vcodec mjpeg -i  - -sameq -vcodec mjpeg -f mjpeg -y -s 1024x512 /dev/stdout;
) -vcodec copy -an -y tmp.mov
 
rm clouds.mov
mv tmp.mov clouds.mov
mv clouds-queue/*.jpg clouds-done/

losse plaatjes omzetten naar filmpje met framerate en veel keyframes

ffmpeg -f image2 -r 1 -i frame-%04d.png -r 5 -g 1 -y -sameq -s 1024x512 output.mov

output framerate 10, keyframe on everyframe

ffmpeg -i ring.mov -r 10 -g 1 -sameq -y ring-10.mov

-r 1 sets input framerate to 1

ffmpeg -r 1 -i image-%d.PNG -sameq -g 1 -y  A2-vegetation.mov

convert movie to iPad

ffmpeg -i input.mov -acodec libfaac -ac 2 -ab 160k -s 1024x768 -vcodec libx264 -vpre slow -vpre ipod640 -b 1200k -f mp4 -threads 10 output.mp4

convert image sequence to movie

ffmpeg -f image2 -i frame%03d.png -s 1024x512 output.mov

convert movie from canon ixus to mpeg

ffmpeg -i MVI_0131.AVI -r 25 -sameq output.mov

rotate movie (with memcoder)

mencoder -vf rotate=1 -o OUTPUT.AVI -oac copy -ovc lavc MVI_7590.AVI 

Remove audio from a movie

ffmpeg -i input.mov -an output.mov

Combine jpg and mp3 audio to mpg

(in this case portrait). Be sure to use RGB jpg's instead of CMYK.

ffmpeg -y -i vogels.jpg -loop_input -i vogels.mp3 -s 320x480 vogels320x480.mpg
or:
ffmpeg -y -b 2500k -r 30 -i yellow-brick-road.jpg -i brand-new-day.mp3 -map 0:0 -map 1:0 -vsync 1 -sameq  -vcodec mpeg4 -s 320x480 result2.mp4

crop away black side bars

ffmpeg -i in.mov -sameq -cropleft 104 -cropright 104 hands.mov

set start / offset time of input movie

-itsoffset needs to go before -i filename

ffmpeg -itsoffset 10 -i IMG_4699.MOV -s 640x360 -an -sameq hebbenEnHouden.mov

timelapse with ffmpeg / gstreamer

ffmpeg.txt · Last modified: 2017/02/28 10:24 by rick