1

I'm looking for a way, with FFmpeg, to crop an image removing all white pixels; something like the Photoshop's "crop white spaces".

I tried looking around but I didn't find a solution, here is an example of what I'm looking for:

Given this: Input

I would be able to obtain this: Output

How should I get this edit?

llogan
  • 121,796
  • 28
  • 232
  • 243
Pier Giorgio Misley
  • 5,305
  • 4
  • 27
  • 66

1 Answers1

5
  1. Use negate to invert the image colors and cropdetect to find crop parameters:

    ffmpeg -loop 1 -i input.png -frames:v 3 -vf "negate,cropdetect=limit=0:round=0" -f null -
    ...
    [Parsed_cropdetect_1 @ 0x5581f7287580] x1:198 x2:1255 y1:472 y2:968 w:1058 h:496 x:198 y:472 pts:3 t:0.120000 crop=1056:496:200:472
    
  2. Test with ffplay if desired:

    ffplay -vf crop=1056:496:200:472 input.png
    
  3. Then use crop:

    ffmpeg -i input.png -vf crop=1056:496:200:472 output.png
    

See ffmpeg get value from cropdetect for a Bash shell example to extract the cropdetect value for scripted usage.

llogan
  • 121,796
  • 28
  • 232
  • 243