如何使用ffmpeg overlay_cuda过滤器制作SBS视频? [英] How to use the ffmpeg overlay_cuda filter to make a SBS video?

查看:111
本文介绍了如何使用ffmpeg overlay_cuda过滤器制作SBS视频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

FFMPEG几个月前推出了带有新过滤器"overlay_cuda"的FFMPEG新版本,该过滤器与"overlay"过滤器的功能相同.但要使用Nvidia卡进行应用.

我在FFMPEG网站上找到了该过滤器的说明,但没有使用它的示例.我发现的唯一示例来自开发人员提交,但是将视频或照片放在另一个视频上.

在使用普通的重叠式滤镜之前,我使用宽度为两倍的nullsrc图像进行此操作,但现在我不知道如何使用该滤镜.

提交说明: https://patchwork.ffmpeg.org/project/ffmpeg/patch/20200318071955.2329-1-yyyaroslav @ gmail.com/ffmpeg文档网页: https://ffmpeg.org/ffmpeg-filters.html#overlay_005fcuda-1

希望你能帮助我.

更新:

我下达了这个FFmpeg命令:

  1. 输入每个视频.
  2. 第一个视频在右侧创建填充,然后上传到卡的内存中.
  3. 使用叠加的Cuda,其他视频放在原始视频的右侧.

  ffmpeg -y -loglevel信息\-i $ video_1 \-hwaccel cuda -hwaccel_output_format cuda -i $ video_2 \-filter_complex \"\[0:v] pad = w = 2 * iw:h = ih:x = 0:y = 0,hwupload_cuda [base];[base] [1:v] overlay_cuda = x = 800:y = 0"\-an -c:v h264_nvenc overlay_test.mp4 

但是我收到此错误消息:

  [overlay_cuda @ 0x55fdec4b2ec0]无法在yuv420p上覆盖nv12[Parsed_overlay_cuda_2 @ 0x55fdec4b2d80]无法在Parsed_overlay_cuda_2上配置输出键盘重新初始化过滤器时出错!无法将帧注入到过滤器网络中:无效的参数处理流#1:0的解码数据时出错 

像素格式有问题,希望您能对我有所帮助.

更新2:

我终于解决了像素格式问题,现在用填充物进行覆盖(在覆盖视频中增加了空间)

这是成功的命令:

  ffmpeg -y -loglevel信息\-i $ video_1 \-hwaccel cuda -hwaccel_output_format cuda -i $ video_2 \-filter_complex \"\[0:v] pad = w = 2 * iw:h = ih:x = 0:y = 0,hwupload_cuda,scale_npp = format = nv12 [base];[base] [1:v] overlay_cuda = x = 800:y = 0"\-an -c:v h264_nvenc overlay_test.mp4 

现在,我想将 x = 800 更改为类似 x = iw + 1 的变量,但似乎此过滤器不支持该功能.有没有办法设置全局变量?

解决方案

我明白了!再次阅读使用Cuda滤镜的功能后,我发现 scale_npp 不仅可以调整视频的大小,还可以更改像素格式.

因此,经过一些测试,我找到了一个非常好的解决方案:

  ffmpeg -y -loglevel信息\-hwaccel cuda -hwaccel_output_format cuda -i $ video_1 \-hwaccel cuda -hwaccel_output_format cuda -i $ video_2 \-filter_complex \"\[0:v] scale_npp = 640:-2:format = yuv420p,hwdownload,pad = w = 2 * iw:h = ih:x = 0:y = 0,hwupload_cuda,scale_npp = format = nv12 [base];[1:v] scale_npp = 640:-2:format = nv12 [overlay_video];[base] [overlay_video] overlay_cuda = x = 640:y = 0"\-an -c:v h264_nvenc overlay_test.mp4 

此FFMPEG命令的产生原因:

  1. 输入两个具有Cuda解码的视频.
  2. 第一个视频 [0:v] :
    • 扩展至640像素宽度,使宽高比收音机保持YUV420P像素格式
    • 从GPU内存下载到系统内存
    • 应用填充滤镜以在视频右侧添加640像素的宽度
    • 再次上传到GPU内存
    • 将像素格式更改为nv12
    • 标签为 [base]
  3. 第二个视频 [1:v]
    • 扩展至640像素宽度,使宽高比收音机保持NV12像素格式
    • 标记为 [overlay_video]
  4. 应用 overlay_cuda 过滤器
    • [base] 视频作为背景视频
    • [overlay_video] 视频作为前景视频
    • 在右侧插入 [overlay_video] 640像素作为 [base] 视频
  5. 完成编码
    • -an 作为音频null(可以删除,在实际使用中,您需要混合音频信号或从两个视频中选择一个,甚至添加外部音频源.)
    • -c:v h264_nvenc 使用带有h264编解码器的GPU对视频进行编码(可在此处更改您的需求).

唯一的缺点是您需要预先设置分辨率,无法设置输入分辨率(就像普通的叠加滤镜一样).幸运的是,您可以将其设置为脚本变量,然后使用 ffprobe 来获取此变量.

FFMPEG a few months ago launched the new version of FFMPEG with the new filter "overlay_cuda", this filter makes the same as the "overlay" but using an Nvidia card for applying it.

I found on the FFMPEG website description of the filter, but no examples of how to use it. The only examples I found are from the developer commits but are to put a video or a photo over another video.

I before the normal overlay filter to do this using a nullsrc image with the twice of width but now I don't know how to with this filter.

Commit description: https://patchwork.ffmpeg.org/project/ffmpeg/patch/20200318071955.2329-1-yyyaroslav@gmail.com/ ffmpeg documentation webpage: https://ffmpeg.org/ffmpeg-filters.html#overlay_005fcuda-1

I hope you can help me.

Update:

I made this FFmpeg order that:

  1. Input each video.
  2. The first video creates padding to the right and then is uploaded to the card's memory.
  3. With overlay Cuda, the other video puts on the right of the original video.

ffmpeg -y -loglevel info \
-i $video_1  \
-hwaccel cuda -hwaccel_output_format cuda -i $video_2 \
-filter_complex \
" \
[0:v]pad=w=2*iw:h=ih:x=0:y=0,hwupload_cuda[base];
[base][1:v]overlay_cuda=x=800:y=0" \
-an -c:v h264_nvenc overlay_test.mp4

But I get this error message:

[overlay_cuda @ 0x55fdec4b2ec0] Can't overlay nv12 on yuv420p 
[Parsed_overlay_cuda_2 @ 0x55fdec4b2d80] Failed to configure output pad on Parsed_overlay_cuda_2
Error reinitializing filters!
Failed to inject frame into filter network: Invalid argument
Error while processing the decoded data for stream #1:0

I have issues with the pixel formats, I hope you can help me.

Update 2:

I finally solved the pixel format issue and now makes the overlay with the padding (adds space to the overlay video)

This is the command that succeeds:

ffmpeg -y -loglevel info \
-i $video_1  \
-hwaccel cuda -hwaccel_output_format cuda -i $video_2 \
-filter_complex \
" \
[0:v]pad=w=2*iw:h=ih:x=0:y=0,hwupload_cuda,scale_npp=format=nv12[base];
[base][1:v]overlay_cuda=x=800:y=0" \
-an -c:v h264_nvenc overlay_test.mp4

Now I want to change x=800 to a variable like x=iw+1 but it seems this filter doesn't support that. Is there a way to set a global variable?

解决方案

I got it! After reading again what I can do with the Cuda filters, I found that the scale_npp not only resizes the videos, but also you can change the pixel format.

So after a few test I found a very nice solution:

ffmpeg -y -loglevel info \
-hwaccel cuda -hwaccel_output_format cuda -i $video_1  \
-hwaccel cuda -hwaccel_output_format cuda -i $video_2 \
-filter_complex \
" \
[0:v]scale_npp=640:-2:format=yuv420p,hwdownload,pad=w=2*iw:h=ih:x=0:y=0,hwupload_cuda,scale_npp=format=nv12[base];
[1:v]scale_npp=640:-2:format=nv12[overlay_video];
[base][overlay_video]overlay_cuda=x=640:y=0" \
-an -c:v h264_nvenc overlay_test.mp4

What makes this FFMPEG command:

  1. Input two videos with Cuda decoding.
  2. The first video [0:v]:
    • Escale to 640 pixels width keeping the aspect radio with a YUV420P pixel format
    • Download from the GPU memory to the system memory
    • Apply a Padding filter to add 640 pixels width to the right of the video
    • Upload again to the GPU memory
    • Change the pixel format to nv12
    • Label as [base]
  3. The second video [1:v]
    • Escale to 640 pixels width keeping the aspect radio with a NV12 pixel format
    • Label as [overlay_video]
  4. Apply overlay_cuda filter
    • [base] video as the background video
    • [overlay_video] video as the foreground video
    • Insert [overlay_video] 640 pixels to the right as the [base] video
  5. Finish the encoding
    • -an as Audio null (This can be deleted, in the real usage you need to mix the audio signals or choose one from the two videos, or even add an external audio source.)
    • -c:v h264_nvenc Encode the video using the GPU with the h264 codec (Here you can change to your needs).

The only drawback is that you need to set a resolution from beforehand, there is no way to set the input resolution (Like in the normal overlay filter). Fortunately, you can make this like a variable for a script and use ffprobe to get this variable before.

这篇关于如何使用ffmpeg overlay_cuda过滤器制作SBS视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆