FFmpeg is the assembler of audio and video.
As a result, Ciro Santilli who likes "lower level stuff", has had many many hours if image manipulation fun with this software, see e.g.:
- the "Media" section of the best articles by Ciro Santillis.
- Figure "Ciro knows how to convert videos to GIFs"
As older Ciro grows, the more he notices that FFmpeg can do basically any lower level audio video task. It is just an amazing piece of software, the immediate go-to for any low level operation.
FFmpeg was created by Fabrice Bellard, which Ciro deeply respects.
Resize a video: superuser.com/questions/624563/how-to-resize-a-video-to-make-it-smaller-with-ffmpeg:
Unlike every other convention under the sun, the height in
ffmpeg -i input.avi -filter:v scale=720:-1 -c:a copy output.mkv
scale
is the first number.Filter graphs are a thing of great beauty. What an amazingly obscure domain-specific language, but which can produce striking results with very little!!!
A quick example from stackoverflow.com/questions/59551013/how-to-generate-stereo-sine-wave-using-ffmpeg-with-different-frequencies-for-eac/77730492#77730492 illustrates some of the fundamentals:
ffplay -autoexit -nodisp -f lavfi -i '
sine=frequency=500[a];
sine=frequency=1000[b];
[a][b]amerge, atrim=end=2
'
+--------+
[sine=frequency=500]--->[a]-->| |
| amerge |-->[atrim]-->[output]
[sine=frequency=1000]-->[b]-->| |
+--------+
So we see the following syntax patterns:
sine
,amerge
andatrim
are filterssine=frequency=500
: the first=
says "araguments follow"frequency=500
sets thefrequency
argument of thesine
filter- for multiple arguments the syntax is to separate arguments with colons e.g.
sine=frequency=500:duration=2
;
: separates statements[a]
,[b]
: sets the name of an edge,
: creates unnamed edge between filters that have one input and one output
A list of all filters can be obtained ith:
and parameters for a single filter can be obtained with:
Related question: stackoverflow.com/questions/69251087/in-ffmpeg-command-line-how-to-show-all-filter-settings-and-their-parameters-bef
ffmpeg -filters
ffmpeg --help filter=sine
TODO dump graph to ASCII art? trac.ffmpeg.org/wiki/FilteringGuide#Visualizingfilters mentions a
-dumpgraph
option, but haven't managed to use it yet.Bibliography:
- ffmpeg.org/ffmpeg-filters.html official documentation
- trac.ffmpeg.org/wiki/FilteringGuide some handy tips from the FFMpeg Wiki
Awesome tool to view quick stuff quickly without generating files. Unfortunately it doesn't support all options that the ffmpeg CLI supports, e.g. ffplay multiple input files. One day, one day.
TODO possible? superuser.com/questions/559768/ffplay-how-to-play-together-separate-video-and-audio-files
For synthesized streams like
but it does not seem to accept multiple
fails with:
sine
we can do it e.g.
ffplay -autoexit -nodisp -f lavfi -i '
sine=frequency=500[a];
sine=frequency=1000[b];
[a][b]amerge, atrim=end=2
'
-i
for some reason. So is there a way to open a file from some filter? E.g.:
ffplay -i tmp.wav -i tmp.mkv -filter_complex "[0:a]atrim=end=2[a];[1:v]trim=end=2[v]" -map '[a]' -map '[v]'
Argument 'tmp.mkv' provided as input filename, but 'tmp.wav' was already specified.
Simple sines and variants:
- unix.stackexchange.com/questions/82112/stereo-tone-generator-for-linux/536860#536860
- stackoverflow.com/questions/5109038/linux-sine-wave-audio-generator/57610684#57610684
- superuser.com/questions/724391/how-to-generate-a-sine-wave-with-ffmpeg
- stackoverflow.com/questions/59551013/how-to-generate-stereo-sine-wave-using-ffmpeg-with-different-frequencies-for-eac/77730492#77730492
2 second 1000 Hz:
ffmpeg -f lavfi -i "sine=f=1000:d=2" out.wav
Video with a solid color:
- 2 second white video:
Also add some audio:
ffplay -autoexit -f lavfi -i 'color=white:640x480:d=3,format=rgb24,trim=end=2'
TODO how to ffplay the video + audio directly?ffmpeg -lavfi "color=white:640x480:d=3,format=rgb24,trim=end=2[v];sine=f=1000:d=2[a]" -map '[a]' -map '[v]' out.mkv
-map
does not seem to work unfortunately. - 2 second white followed by 2 second black video:
ffplay -autoexit -f lavfi -i 'color=white:640x480:d=3,format=rgb24,trim=end=2[a];color=black:640x480:d=3,format=rgb24,trim=end=2[b];[a][b]concat=n=2:v=1:a=0'
- bibliography:
Display count in seconds on the video:
- black text on white background. Start from 0 and count up to 2:
ffplay -autoexit -f lavfi -i " color=white:480x480:d=3, format=rgb24, drawtext= fontcolor=black: fontsize=600: text='%{eif\:t\:d}': x=(w-text_w)/2: y=(h-text_h)/2 "
- bibliography:
FFmpeg is likely the backend of YouTube through reverse engineering: streaminglearningcenter.com/blogs/youtube-uses-ffmpeg-for-encoding.html (archive)
Crop
20
pixels from the bottom of the image:
convert image.png -gravity East -chop 20x0 result.png
convert -size 512x512 xc:blue blue.png
convert -size 256x256 gradient: out.png
convert -size 256x256 gradient:white-black out.png
convert -size 256x256 gradient:red-blue out.png
convert -size 256x256 radial-gradient: out.png
convert -size 256x256 radial-gradient:white-black out.png
Digits 0 to 9, white on black background:
for i in `seq 0 9`; do convert -size 512x512 xc:black -pointsize 500 -gravity center -fill white -draw "text 0,0 \"$i\"" $i.png; done
Articles by others on the same topic
There are currently no matching articles.