FFmpeg将输出更改为特定的像素格式?

时间:2018-12-16 05:18:46

标签: opencv ffmpeg v4l2 v4l2loopback

我正在处理一个openCV项目,我有一个稳定运行的变体,它从HDMI捕获卡获取输入,并使用FFmpeg输出到v4L2回送设备(/ dev / video0),我的openCV项目从/获取它的输入dev / video0。

当我尝试使用rtsp提要时,问题就来了,以下命令可以将提要发送到我的回送设备:

ffmpeg -rtsp_transport tcp -i rtsp://@192.168.1.27:552//stream1 -acodec rawvideo -vcodec rawvideo -f v4l2 /dev/video0

我可以使用VLC(在/ dev / video0上)查看该供稿,但是没有问题,但是当我将其供入openCV应用程序时,出现以下错误:

VIDEOIO ERROR: V4L2: Pixel format of incoming image is unsupported by OpenCV

当我在有效版本和无效版本上运行v4l2-ctl -d /dev/video0 --all时,我得到的是:

工作输出

Format Video Output:
Width/Height      : 1920/1080
Pixel Format      : 'UYVY'
Field             : None
Bytes per Line    : 3840
Size Image        : 4147200
Colorspace        : sRGB
Transfer Function : Default
YCbCr Encoding    : Default
Quantization      : Default
Flags             : 

非正常输出

Format Video Output:
Width/Height      : 1280/720
Pixel Format      : 'YU12'
Field             : None
Bytes per Line    : 1280
Size Image        : 1382400
Colorspace        : sRGB
Transfer Function : Default
YCbCr Encoding    : Default
Quantization      : Default
Flags             : 

所以我得出结论,像素格式“ YU12”与openCV不兼容,而格式“ UYVY”却与OpenCV不兼容。如果有可能,当输入为YU12时,如何将FFmpeg的输出设置为像素格式UYVY?

2 个答案:

答案 0 :(得分:1)

使用format过滤器或-pix_fmt选项。例如,我们将使用yuv420p像素格式!

# Using the format filter (yuv420p)
ffmpeg -i in_file -filter:v "format=yuv420p" out_file

# Using the 'pix_fmt' option
ffmpeg -i in_file -pix_fmt yuv420p out_file
  

[奖金] ,有很多可用的像素格式来获取运行ffmpeg -pix_fmts的像素格式。

答案 1 :(得分:0)

ffmpeg -pix_fmts 将看到可用像素格式的列表

使用

-pix_fmt rgb24

例如,您将不会再看到已弃用的警告

相关问题