简体   繁体   English

FFMPEG,使用“图像选择区域”插件模糊视频区域

[英]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 像这样的东西

在此处输入图片说明

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. 我的意思是使用此插件将提供四个数字,即width, length, top, left ,我需要使用这些数字来模糊视频区域。

I take an screenshot of video. 我为视频截图。 In order to keep the aspect ratio, I will fix the width to 800px and let the height to be scaled up/down. 为了保持宽高比,我将宽度固定为800px并让高度按比例缩放。 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. 很明显的是, width, length, top, left的屏幕截图的选定区域的是一个因素width, length, top, left必须在视频被模糊的区域的。 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. 提前致谢。


Update 更新资料

This is my PHP code that gets the selected area dimensions and offsets 这是我的PHP代码,获取所选区域的尺寸和偏移量

$iLeft = $_POST['left'];
$iTop = $_POST['top'];
$iWidth = $_POST['width'];
$iHeight = $_POST['height'];
exec('ffmpeg -i '.$url.' -filter_complex "[0:v]scale=iw*sar:ih,setsar=1,split[bg][bb];[bb]crop='.$iWidth.'*iw/800:iw*'.$iHeight.'/800:'.$iWidth.'*iw/800:'.$iHeight.'*iw/800,boxblur=10[b0];[bg][b0]overlay='.$iLeft.'*W/800:'.$iTop.'*W/800"" '.$name.' > block.txt 2>&1');

$iLeft, $iTop, $iWidth, $iHeight are the left, top, width and height of the selected area via the image plugin. 通过图像插件$iLeft, $iTop, $iWidth, $iHeight是所选区域的左侧,顶部,宽度和高度。

It blurs many selected areas very well, but areas like this 它很好地模糊了许多选定区域,但是像这样的区域

在此处输入图片说明

The Image Left, Top, Width, Height is 257, 39.26666259765625, 10, 391 图像Left, Top, Width, Height257, 39.26666259765625, 10, 391

don't get blurred. 不要模糊。 Also a video with Dimension 207x207 didn't get blurred as well. 同样,尺寸为207x207的视频也不会模糊。

Running 跑步

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: 将产生如下输出:

1280|720|1:1

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. 第一个条目是视频宽度,然后是高度,最后是像素或采样宽高比,显示为num:den,因此为num / den。 That's your video resolution. 那就是你的视频分辨率。

With that info, the factor is video-width*sar/800 . 有了该信息,因素就是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. 假设您将使用scalesetsar滤镜将所有变形视频缩放到正方形像素,并且800px屏幕截图也未失真。 If you're using FFmpeg to scale screenshot, it's scale=800:ih*800/iw/sar 如果您使用FFmpeg缩放屏幕截图,则scale=800:ih*800/iw/sar

So FFmpeg value for area width is screenshot area width * video-width*sar/800 . 因此,区域宽度的FFmpeg值为screenshot area width * video-width*sar/800

and for FFmpeg Y co-ordinate is screenshot top * video-width*sar/800 , and so on. 对于FFmpeg,Y坐标是screenshot top * video-width*sar/800 ,依此类推。


Assuming the code in the comment is for the screenshot, for the full-sized movie, it would be 假设注释中的代码用于屏幕截图,对于全尺寸电影,则为

"[0:v]scale=iw*sar:ih,setsar=1,split[bg][bb];[bb]crop=50*iw/800:50*iw/800:20*iw/800:10*iw/800,boxblur='min(min(cw/2\,ch/2)\,10)'[b0];
 [bg][b0]overlay=20*W/800:10*W/800"

I've scaled the movie to make sure we're always dealing with a square-pixel video. 我对电影进行了缩放,以确保我们一直在处理正方形像素的视频。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM