ffmpeg.md 2.1 KB

Playing with ffmpeg

...to extrac, manipulate and reassmbly frames

Frames extraction

In running the command take note about original video fps

ffmpeg -i video.mp4 %05d.png

Video creation from frames

In running the command take note about original video fps

ffmpeg -framerate 30 -pattern_type glob -i '*.png' -c:v libx264 -pix_fmt yuv420p paint.mp4

Video warping from images

Using CUDA:

ffmpeg -y -fflags +genpts -r 30 -hwaccel cuda -hwaccel_output_format cuda -pattern_type glob -i '*.png' -vf "setpts=100*PTS,minterpolate=fps=24:scd=none" -pix_fmt yuv420p  -c:v h264_nvenc "test01.mp4"

Add silent audio track to a video (with no audio tack)

ffmpeg -i "test.mp4" -f lavfi -i anullsrc=cl=stereo:r=48000 -shortest -y "test_silent.mp4"

Useful if you want to merge more than one *.mp4 video and some of these ave no audio track Make sure that audio rate for the silent track matches the one of file(s) you are going to merge with it

Crop a video to a well defined size

ffmpeg -i test_silent.mp4 -filter:v "crop=512:512:1200:200" -c:a copy te.mp4

Crop to size 512x512 starting from 1200,200 where 0,0 is the top left corner

Concatenation of two videos

Once you've performed tthe two steps above (same size and a silent audio if needed):

ffmpeg -i te.mp4 -i 20231104021840.mp4 -filter_complex "[0:v][0:a][1:v][1:a]concat=n=2:v=1:a=1" -vsync vfr output.mp4

Create a slideshow (video) from images with different timings

ffmpeg -f concat -i input.txt -pix_fmt yuv420p -movflags +faststart intro.mp4

in which input.txt looks like:

file '00.png'
duration 2
file '01.png'
duration 14 
file '02.png'
duration 2
file '03.png'
duration 6 
file '04.png'
duration 2 
file '05.png'
duration 10
file '06.png'
duration 1 

Cut a video in an interval

ffmpeg -ss 00:09:41 -i .\xynthesi_no_titoli.mp4 -t 50 -map 0 -c copy clip02.mp4

t option is in seconds from the ss start timestamp in HH:MM:SS

ffmpeg -copyts -ss [start] -i in.mp4 -to [end] -map 0 -c copy out.mp4

In this second command we're specifying start and end with a full timestamp in format HH:MM:SS