Search code examples
ffmpegtileandroid-ffmpeg

FFmpeg tile cropping


This image is splitted to 12 equal pieces. Is there any way to do such a work with ffmpeg?

this images was uploaded on Instagram


Solution

  • Use

    ffmpeg -loop 1 -i image.png -vf "crop=iw/3:ih/4:mod(n,3)*iw/3:trunc(n/3)*ih/4" -vframes 12 out%d.png
    

    For full coverage of image, the image width has to be divisible by 3, and height by 4.


    For square output, set crop height to crop width. The vertical crop leaves some space at top and bottom.

    ffmpeg -loop 1 -i image.png -vf "crop=iw/3:iw/3:mod(n,3)*iw/3:trunc(n/3)*iw/3+(ih-iw)/2" -vframes 12 out%d.png
    

    (This method requires that ih/4 > iw/3 for desired output)