filterffmpegtile

ffmpeg using an expression for tile filter


Is there any way to supply the 'tile' filter of ffmpeg with an expression? I've tried about every combination I can think of using different escape characters and quotes, but it won't accept anything other than an explicit string like '10x10'. See the example below that works:

ffmpeg -i "big_buck_bunny.mp4" -vf "tile=10x10" grid_%d.jpg

I'd like to be able to do something like:

ffmpeg -i "big_buck_bunny.mp4" -vf "tile=expr(n*2)x10" grid_%d.jpg

Where 'n' is the current frame number. This isn't the exact expression I'm looking to use, but wanted to start with a simple example that I can then adapt to a more complex expression. Everything I've tried gives me an error like the following:

[tile @ 0x7facc1d000c0] Unable to parse option value "expr(n*2)x10" as image size

Can tile simply not accept an expression? Or is there some sort of concatenate function that I should be trying?


Solution

  • I'm not completely answering your question, but this might be of help finding it.

    If you want to do calculations based on the amount of frames, you will probably have to extract the nb_frames attribute from the output of ffprobe -show_streams -i "big_buck_bunny.mp4" first. Then you can perform the calculation and insert the result into your command with the correct tile filter.

    If you're looking for a way to extract only a certain number of frames from the video and merge them into one file, I would recommend the tutorial on this website: https://www.binpress.com/generate-video-previews-ffmpeg/

    Generating a preview is just another one-liner where ffmpeg captures images and joins them into a single long film strip.

    ffmpeg -loglevel panic -y -i "video.mp4" -frames 1 -q:v 1 -vf "select=not(mod(n\,40)),scale=-1:120,tile=100x1" video_preview.jpg

    • -loglevel panic We don’t want to see any output. You can remove this option if you’re having any problems seeing what went wrong.
    • -i "$MOVIE" The input file.
    • -y Override any existing output file.
    • -frames 1 Tell ffmpeg that output from this command is just a single image (one frame).
    • -q:v 1 Output quality, 0 is the best.
    • -vf select= That's where all the magic happens. This is the selector function for video filter.
    • not(mod(n,40)) Select one frame every 40 frames see the documentation.
    • scale=-1:120 Resize frames to fit 120px height, and the width is adjusted automatically to keep the correct aspect ratio.
    • tile=100x1 Layout captured frames into this grid.