[英]Decoding to specific pixel format in ffmpeg with C++
I need to decode video but my video player only supports RGB8 pixel format. 我需要解码视频,但是我的视频播放器仅支持RGB8像素格式。 So I'm looking into how to do pixel format conversion in the GPU, preferably in the decoding process, but if not possible, after it.
因此,我正在研究如何在GPU中进行像素格式转换,最好是在解码过程中,但如果可能的话,在此之后。
I've found How to set decode pixel format in libavcodec? 我发现如何在libavcodec中设置解码像素格式? which explains how to decode video on ffmpeg to an specific pixel format, as long as it's suported by the codec.
解释了如何将ffmpeg上的视频解码为特定的像素格式,只要它受编解码器支持即可。
Basically, get_format()
is a function which chooses, from a list of supported pixel formats from the codec, a pixel format for the decoded video. 基本上,
get_format()
是从编解码器支持的像素格式列表中选择解码视频的像素格式的函数。 My questions are: 我的问题是:
sws_scale()
function converts in the GPU or CPU? sws_scale()
函数在GPU或CPU中转换吗? av_hwframe_transfer_data
like in the example. av_hwframe_transfer_data
从GPU下载解码帧。 From this point on it doesn't make much of a difference if you used hardware or software decoding. sws_scale
isn't using hardware acceleration. sws_scale
没有使用硬件加速。 Since it's not accepting "hwframes". GPUMat
there then upload your frame, call cvtColor
and download it again. GPUMat
一下OpenCV,您可以在那里使用GPUMat
,然后上传您的框架,调用cvtColor
并再次下载。 Some general remarks: 一些一般性的评论:
Almost any image operation scaling etc. is faster on your GPU, but uploading and downloading the data can take ages. 在您的GPU上,几乎任何图像操作缩放等操作都更快,但是上载和下载数据可能会花费一些时间。 For single operations, it's often not worth using your GPU.
对于单个操作,通常不值得使用GPU。
In your case, I would try to work with CPU decoding and CPU color conversion first. 在您的情况下,我将尝试首先使用CPU解码和CPU颜色转换。 Just make sure to use well threaded and vectorized algorithms like OpenCV or Intel IPP.
只需确保使用良好的线程化和矢量化算法,例如OpenCV或Intel IPP。 If you still lack performance then you can think about Hardware Acceleration.
如果仍然缺乏性能,则可以考虑硬件加速。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.