p2p
Posts: 7
Joined: Thu Mar 25, 2021 5:26 pm

Problem of Hardware Accelerated mjpeg to h264

Mon Jun 21, 2021 8:27 am

I have a usb2.0 uvc capture card can output 1080p 30fps mjpeg
I can use

Code: Select all

ffmpeg -f v4l2 -input_format mjpeg -s 1920x1080 -r 30 -i /dev/video0 -c:v copy test.mkv
to record raw mjpeg video file without any frame drop.

But if I want to record h264 mp4 file using

Code: Select all

ffmpeg -f v4l2 -input_format mjpeg -framerate 30 -video_size 1920x1080 -i /dev/video0 -b:v 10M -c:v h264_omx test.mp4
I only get 10-12fps and high cpu usage, I think pi is using cpu encode? But I use h264_omx

if I change the encoder to h264_v4l2m2m, I can get full 1080p 30fps mp4 video without any fram drop

Code: Select all

ffmpeg -f v4l2 -input_format mjpeg -framerate 30 -video_size 1920x1080 -i /dev/video0 -b:v 10M -c:v h264_v4l2m2m test.mp4
but before ffmpeg 4.3, video from h264_v4l2m2m only have green color.

So I compile new version of ffmpeg for my pi and run the same command, and error popout

Code: Select all

File 'test.mp4' already exists. Overwrite? [y/N] y
Stream mapping:
  Stream #0:0 -> #0:0 (mjpeg (native) -> h264 (h264_v4l2m2m))
Press [q] to stop, [?] for help
[h264_v4l2m2m @ 0x224b520] Using device /dev/video11
[h264_v4l2m2m @ 0x224b520] driver 'bcm2835-codec' on card 'bcm2835-codec-encode' in mplane mode
[h264_v4l2m2m @ 0x224b520] requesting formats: output=YU12 capture=H264
[h264_v4l2m2m @ 0x224b520] Encoder requires yuv420p pixel format.
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
Conversion failed!
I'm stuck here now, what should I do?Thank you in advance for your suggestions and help!

User avatar
topguy
Posts: 7189
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Problem of Hardware Accelerat mjpeg to h264

Mon Jun 21, 2021 9:43 am

Which Pi model do you have ?

p2p
Posts: 7
Joined: Thu Mar 25, 2021 5:26 pm

Re: Problem of Hardware Accelerat mjpeg to h264

Mon Jun 21, 2021 3:24 pm

topguy wrote:
Mon Jun 21, 2021 9:43 am
Which Pi model do you have ?
I tried on pi 3b and cm4

WilliansBR
Posts: 2
Joined: Wed Jun 23, 2021 5:11 am

Re: Problem of Hardware Accelerat mjpeg to h264

Wed Jun 23, 2021 5:24 am

Hi. Same problem here.
I want stream to youtube an input HDMI to USB on /dev/video0 of Raspberry 3B+

With h264_v4l2m2m the stream its 30FPS at 1280x720 but presence of green screen.

With libx264 the color its OK and down to only 17fps.

I change many -pix_fmt and -colorspace bt709, bt602, bt470, bt470bg...... no sucess

Comand line:
ffmpeg -re -input_format mjpeg -video_size 1280x720 -framerate 30 -thread_queue_size 15000 -i /dev/video0 -f alsa -ac 2 -thread_queue_size 540000 -i hw:2 -vcodec h264_v4l2m2m -vpre baseline -vpre my_ffpreset -preset medium -r 30 -g 60 -b:v 2M -maxrate 1M -bufsize 2M -c:a aac -b:a 64k -ar 44100 -s 1280x720 -f flv rtmp://a.rtmp.youtube.com/live2/****key****


If anyone can help i apreciate .

p2p
Posts: 7
Joined: Thu Mar 25, 2021 5:26 pm

Re: Problem of Hardware Accelerat mjpeg to h264

Thu Jun 24, 2021 9:22 am

WilliansBR wrote:
Wed Jun 23, 2021 5:24 am
Hi. Same problem here.
I want stream to youtube an input HDMI to USB on /dev/video0 of Raspberry 3B+

With h264_v4l2m2m the stream its 30FPS at 1280x720 but presence of green screen.

With libx264 the color its OK and down to only 17fps.

I change many -pix_fmt and -colorspace bt709, bt602, bt470, bt470bg...... no sucess

Comand line:
ffmpeg -re -input_format mjpeg -video_size 1280x720 -framerate 30 -thread_queue_size 15000 -i /dev/video0 -f alsa -ac 2 -thread_queue_size 540000 -i hw:2 -vcodec h264_v4l2m2m -vpre baseline -vpre my_ffpreset -preset medium -r 30 -g 60 -b:v 2M -maxrate 1M -bufsize 2M -c:a aac -b:a 64k -ar 44100 -s 1280x720 -f flv rtmp://a.rtmp.youtube.com/live2/****key****


If anyone can help i apreciate .
green screen is fixed after ffmpeg 4.3. I found this article but after I compile the new version of ffmpeg, h264_v4l2m2m can't decode mjpeg and show error as I mentioned before. You can try this.
https://www.willusher.io/general/2020/1 ... oding-rpi4

WilliansBR
Posts: 2
Joined: Wed Jun 23, 2021 5:11 am

Re: Problem of Hardware Accelerat mjpeg to h264

Thu Jun 24, 2021 3:47 pm

p2p wrote:
Thu Jun 24, 2021 9:22 am
green screen is fixed after ffmpeg 4.3. I found this article but after I compile the new version of ffmpeg, h264_v4l2m2m can't decode mjpeg and show error as I mentioned before. You can try this.
https://www.willusher.io/general/2020/1 ... oding-rpi4
I will compile the FFMPEG 4.3 too and try some settings with h264_v4l2m2m and libx264.
Tks.

Return to “Graphics, sound and multimedia”