How do I crop out Region of Interest (ROI) from .mp4 video using FFMPEG? I would like to crop out ROI from specific .mp4 file. User needs to define the ROI by specifying X,Y,Width and Height in percentage between 0 and 10000. 

For example, if someone specifies X=4000, and Y=3000 that would mean that top left corner (starting point of the crop) is located 40% to the right from bottom left corner of the video, and 30% down from top left corner of the video. Width and Height should determine bottom right and top left corners.

I am currently doing some tests on this image:



I expected following command to crop out 50% of the width and 50% of the height of the image, starting from top left corner:

ffmpeg -i test.png -filter:v "crop=in_w*(5000/10000):in_h*(5000/10000):in_w:in_h" -c:a copy roi.png


For some reason I get bottom right quarter instead of top left quarter of the image. What am I doing wrong?



EDIT

Once I change command to:

 ffmpeg -i test.png -filter:v "crop=in_w*(5000/10000):in_h*(5000/10000):0:in_h" -c:a copy roi.png


I get top right quarter of the image:



Since I specified X=in_w, and Y=0, this means that (X,Y) is top-right corner of the image. If that is true, and W is 50% of in_w, while H is also 50% of in_h, and I specified (X,Y) to be at top right corner, how did FFMPEG decide that it needs to go to the LEFT of the (X,Y) coordinate and not to the RIGHT in order to make the crop?

Because if it went to the right like it normally does, it would go out of range I guess. How is this logic implemented? I would like to know so I know how to program edge cases for it.
The crop filter arguments specify a crop window of the given width and height whose top-left corner is at co-ordinates (x, y) measured from top-left corner of the input frame. The entire crop window must be contained within the frame. So, to start with, w &lt;= iw &amp;&amp; h &lt;= ih. 

Then, x+w &lt;= iw &amp;&amp; x &gt;= 0 and y+h &lt;= ih &amp;&amp; y &gt;= 0. If this condition isn't meant, x or y will be adjusted to auto-center the crop window along that axis, e.g. for a 100x100 input, if w = 50 and x = 60, then x is adjusted to (100-50)/2 = 25.