Drupalist Drupalist - 1 year ago 133
Javascript Question

FFMPEG, Blur an area of a video using Image Select Areas Plugin

I am building an online video editor. I need to allow the users to blur an area of movies. This must be done graphically, I mean user should be able to select an area of a video, using an screenshot, then the selected area must be blurred. Some thing like this

enter image description here

Is there anyway to map this selected area dimension and its distance from borders to the real values that must be applied to the video?

I mean four numbers,

width, length, top, left
will be provided using this plug in and I need to use these numbers to blur an area of videos.

I take an screenshot of video. In order to keep the aspect ratio, I will fix the width to
and let the height to be scaled up/down. It is clear that the
width, length, top, left
of the selected area of the screenshot is a factor of the
width, length, top, left
of the area that must be blurred in video. but I don't know how to get this factor. Besides that I don't know how to get the video resolution.

Thanks in advance.

Answer Source


ffprobe in.mp4 -loglevel quiet -select_streams v -show_entries stream=width,height,sample_aspect_ratio -of compact=p=0:nk=1

will produce an output that looks like this:


The first entry is the video width, then the height, and finally the pixel or sample aspect ratio, shown as num:den so it's num/den. That's your video resolution.

With that info, the factor is video-width*sar/800. This assumes that you'll be scaling all anamorphic videos to square pixels using the scale and setsar filters, and that the 800px screenshot is undistorted as well. If you're using FFmpeg to scale screenshot, it's scale=800:ih*800/iw/sar

So FFmpeg value for area width is screenshot area width * video-width*sar/800.

and for FFmpeg Y co-ordinate is screenshot top * video-width*sar/800, and so on.

Assuming the code in the comment is for the screenshot, for the full-sized movie, it would be


I've scaled the movie to make sure we're always dealing with a square-pixel video.