FFmpeg change output to specific pixel format?
Asked Answered
P

2

8

I am working on an openCV project, I have a stable running variant that is taking input from an HDMI capture card and using FFmpeg to output to a v4L2 loopback device (/dev/video0) my openCV project takes its input from /dev/video0.

The issue comes when I try to use an rtsp feed, the following command works to send the feed to my loopback device:

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

And I am able to view that feed with VLC (on /dev/video0) no problem, however when I feed it to my openCV app, I get the following error:

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

When I run v4l2-ctl -d /dev/video0 --all on both working and non working variants this is what I get:

Working output

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             : 

Nonfunctional output

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             : 

So I am concluding that the pixel format 'YU12' is not compatible with openCV while format 'UYVY' is. If it's possible, how do I set the output of FFmpeg to be in pixel format UYVY when the input is YU12?

Pond answered 16/12, 2018 at 5:18 Comment(0)
S
26

Use the format filter or the -pix_fmt option. For example we'll use yuv420p pixel format!

# 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

[Bonus] there are plenty of pixel formats available to get a list of them run ffmpeg -pix_fmts.

Schizoid answered 15/1, 2019 at 10:5 Comment(1)
You can see a list of pixel formats with ffmpeg -pix_fmts.Galileo
B
3

ffmpeg -pix_fmts will see a list of available pixel formats

Use

-pix_fmt rgb24

for example and you wont see that deprecated warning anymore

Below answered 16/2, 2021 at 12:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.