Back in 2012, I was wondering if I could play a video using MPlayer, and cropping into a certain area — note that I wasn’t looking for a way to crop an area of a video as in re-encoding, but a playback method:
• crop playback using mplayer - 2012-08-08T04:56:38Z
For example, a frame from this video as shown below, you can see the most of the video is a terminal window with the calculator on top of it:
The focal point is that calculator, there might be a way to zoom in perfectly, but it took me two years and four months to finally get to find the solution.
Since I use MPlayer to play videos most of time, the answer lies in the filters -vf (formerly -vop), the crop filter is the one would do the trick:
- Crops the given part of the image and discards the rest. Useful to remove black bands from widescreen movies.
In this case, the command would be — you can also use with -ss to skip to the main part, cropping and skipping might come together — like the following, nicely crop out the area of the calculator as you can see on the right:
% mplayer -vf crop=199:299:686:226 <video file>
It might be tricky when you are trying to find the correct size and position to crop out the area you want, that’s where the rectangle filter comes in to help out:
- Draws a rectangle of the requested width and height at the specified coordinates over the image and prints current rectangle parameters to the console. This can be used to find optimal cropping parameters. If you bind the input.conf directive ‘change_rectangle‘ to keystrokes, you can move and resize the rectangle on the fly.
Note the last part about change_rectangle keybinding, though I haven’t yet to try it, it seems that would be even easier to help to define the area.
Using the command as follows, it draws a rectangular box to indicate the area, so one can slowly adjust until satisfied:
% mplayer -vf rectangle=100:200:700:200 <video file>
Beside these two, there is also a cropdetect to help determine the area:
- Calculates necessary cropping parameters and prints the recommended parameters to stdout.
You will get messages like, using default values:
[CROP] Crop area: X: 0..1279 Y: 0..719 (-vf crop=1280:720:0:0). A: 23.0 V: 22.8 A-V: 0.190 ct: 0.786 0/ 0 2% 0% 0.2% 5 0 [CROP] Crop area: X: 0..1279 Y: 0..719 (-vf crop=1280:720:0:0). A: 23.1 V: 23.0 A-V: 0.126 ct: 0.786 0/ 0 2% 0% 0.2% 5 0
The suggested -vf doesn’t help for this video, it gives you a parameter virtually crop the entire video out, but that’s understandable, you probably need to be a human to decide properly what you want.
After all this time, I couldn’t even recall what the video triggered me having this thought. Anyway, now I know how to do it next time I need it.