I'm working on a project that will treat the images coming from a camera in YUV420 format connected by ethernet.
During the development, we can't have constant access to the camera so I wanted to emulate the behaviour.
My idea is to take video, convert it from mp4
to yuv
using ffmpeg
:
ffmpeg -i input.mp4 -pix_fmt yuv420p output.yuv
Then, stream the video in an infinite loop. This works:
ffmpeg -stream_loop -1 -f rawvideo -s 960x540 -r 30 -pix_fmt yuv420p -i output.yuv -f mpegts udp://127.0.0.1:23000
I managed to read (and show) the images with:
#In python
import cv2
cap = cv2.VideoCapture('udp://127.0.0.1:23000', cv2.CAP_FFMPEG)
...
However, the shape of the images I get is (540, 960, 3)
, but I expected YUV420 format, I wanted (540*3/2, 960)
or 3 channel 540x960, 540/2x960/2, 540/2x960/2.
How can I get the "raw" format?, I'm not sure if it is ffmpeg
or opencv
adding treatment to the stream.