使用GStreamer结合NVDEC提取视频帧失败的解决咨询
使用GStreamer NVDEC解码时无法链接videoscale与jpegenc的解决方法
问题重现
CPU解码管道可正常运行:
gst-launch-1.0 filesrc location=video.mkv ! matroskademux ! h264parse ! avdec_h264 ! videoconvert ! videoscale ! video/x-raw,width=2560,height=1920 ! jpegenc ! multifilesink index=0 location=%d.jpg
切换到NVDEC硬件解码时出现报错:
gst-launch-1.0 filesrc location=video.mkv ! matroskademux ! h264parse ! nvdec ! videoconvert ! videoscale ! video/x-raw,width=2560,height=1920 ! jpegenc ! multifilesink index=0 location=%d.jpg
WARNING: erroneous pipeline: could not link videoscale0 to jpegenc0, videoscale0 can't handle caps video/x-raw, width=(int)2560, height=(int)1920
问题原因
NVDEC解码器输出的是GPU内存中的视频格式(video/x-raw(memory:NVMM)),而标准的videoscale插件仅支持处理CPU内存中的video/x-raw格式,两者的缓冲区类型不兼容,导致caps协商失败。
解决方案
方案1:使用NVIDIA硬件转换插件nvvidconv(推荐)
nvvidconv是NVIDIA官方提供的GStreamer插件,可直接在GPU内存中完成格式转换和缩放操作,无需将帧拷贝到CPU,性能更优,同时能输出CPU兼容的格式:
gst-launch-1.0 filesrc location=video.mkv ! matroskademux ! h264parse ! nvdec ! nvvidconv ! video/x-raw,width=2560,height=1920 ! jpegenc ! multifilesink index=0 location=%d.jpg
方案2:先将GPU帧导出到CPU内存
如果必须使用标准的videoscale,需要先通过nvvidconv把GPU内存的帧转换为CPU内存的video/x-raw格式,再进行后续处理:
gst-launch-1.0 filesrc location=video.mkv ! matroskademux ! h264parse ! nvdec ! nvvidconv ! video/x-raw ! videoconvert ! videoscale ! video/x-raw,width=2560,height=1920 ! jpegenc ! multifilesink index=0 location=%d.jpg
验证插件可用性
执行以下命令确认nvvidconv插件已正确安装:
gst-inspect-1.0 nvvidconv
如果输出插件信息则说明安装正常,否则需要检查NVIDIA GStreamer插件的编译和安装路径是否正确。
内容的提问来源于stack exchange,提问作者Dávid Molnár
相关产品推荐
相关产品推荐

