globiboulga666
Posts: 40
Joined: Sun Jun 17, 2018 6:38 pm

[SOLVED] Using FFMPEG codec "h264_omx" hardware encoder for VLC streaming

Mon Nov 11, 2019 5:39 pm

Hi,

What I would like to do is in the title :
I successfully found the way to encode live camera stream using h264_omx using nearly no CPU at all (awesome).

Code: Select all

ffmpeg -f v4l2 -video_size 1280x800 -i /dev/video0 -codec:v h264_omx -b:v 2048k webcam.mkv
Even for video conversion, this is millions times faster than using -codec:v libx264 or -codec:v libx265.

Whithout h264_omx, the only codec that is able to run almost fine on a Pi4 is "-codec:v mpeg4" (but is still uses lot of CPU compared with h264_omx).


Struggling some hours with VLC, I successfully found a way to tell VLC to stream using ffmpeg and mpeg4 codec.

Code: Select all

cvlc v4l2:///dev/video0:width=1280:height=800 --sout '#transcode{vcodec=mp4v,scale=Auto,acodec=none,scodec=none}:http{mux=ffmpeg{mux=avi},dst=:8080/}' -vvv
It uses ffmpeg and because of "vcodec=mp4v" it seems to use the equivalent of "-codec:v mpeg4" into ffmpeg.

But that's not satisfying at all : this is quite low quality and this is not using the h264_omx functionality of ffmpeg. On Pi3B+ this is too slow and pictures are in increasing late with some "delay reset" at fixed intervals (catastrophic).

As VLC "vcodec=xxxx" parameter only keep the 4 first characters, and the list of recognized commands is here https://wiki.videolan.org/Codec/ it seems that I need to write the command differently. But I have no idea how to do so.

If someone is able to tell me how to acheive this very last step, thank you in advance !
Last edited by globiboulga666 on Mon Nov 11, 2019 7:55 pm, edited 2 times in total.

globiboulga666
Posts: 40
Joined: Sun Jun 17, 2018 6:38 pm

Re: Using FFMPEG codec "h264_omx" encoder for VLC streaming

Mon Nov 11, 2019 7:04 pm

Oh, I think I have an Idea

What about piping the ffmpeg h264-omx encoded data stream to VLC so that it is made available untouched on http ?

This command doesn't work :

Code: Select all

ffmpeg -f v4l2 -video_size 1280x800 -i /dev/video0 -codec:v h264_omx -b:v 2048k | cvlc stream:///dev/stdin --sout '#http{mux=ffmpeg{mux=avi},dst=:8080/}' -vvv
It says

Code: Select all

VLC is unable to open the MRL 'stream:///dev/stdin'. Check the log for details
A new problem... Each step forward is like discovering another hidden door to the hell.

--------------------------------------------

EDIT : seems like 'stream:///dev/stdin' should be replaced by '-'. When using cat file.avi | vlc - -vvv it works fine but not when using ffmpeg output. Also, ffmpeg output seems to care about the file extension we are using (selecting mux) so I'll take a look at it
--------------------------------------------

EDIT2 : ffmpeg wants the dash '-' as output file, and the mux type :

Code: Select all

ffmpeg -f v4l2 -video_size 1280x800 -i /dev/video0 -codec:v h264_omx -b:v 2048k -f matroska - | vlc - -vvv

globiboulga666
Posts: 40
Joined: Sun Jun 17, 2018 6:38 pm

Re: Using FFMPEG codec "h264_omx" encoder for VLC streaming

Mon Nov 11, 2019 7:54 pm

SOLVED !! :D

USB Camera HTTP video streaming server using h264 and Raspberry Pi hardware encoding : 3% CPU usage (while viewing the stream from another computer on the network) : this is satisfying.

Here is the command I used : it uses ffmpeg ability to hardware encode the live input, then giving it to VLC which make it available from network with a working format (flv works for h264).

Code: Select all

ffmpeg -f v4l2 -video_size 1280x800 -i /dev/video0 -codec:v h264_omx -b:v 2048k -f matroska - | cvlc - --sout '#http{mux=ffmpeg{mux=flv},dst=:8080/}' -vvv
By the way, here is my entire memo, too (i'll keep it safe into my linux/things recipes) :

Code: Select all

#Listing available ffmpeg codecs (encoding and decoding)
ffmpeg -decoders | grep mmal
ffmpeg -encoders | grep omx

#Listing available formats and resolutions for the capture input :
ffmpeg -f v4l2 -list_formats all -i /dev/video0

#Doing a raw "capture and place to file" with input resolution specified (still using mux depending on file extension)
ffmpeg -f v4l2 -video_size 1280x800 -i /dev/video0 -codec copy output.avi

#Standards encoders (not for Raspberry Pi unless you are not hurry)
ffmpeg -f v4l2 -video_size 1280x800 -i /dev/video0 -codec:v libx264 output-x264.mkv
ffmpeg -f v4l2 -video_size 1280x800 -i /dev/video0 -codec:v libx265 output-x265.mkv

#Same with raspberry Pi special encoder (omx - which seems not to be only about Raspberry Pi), without and with target bitrate specification.
ffmpeg -f v4l2 -video_size 1280x800 -i /dev/video0 -codec:v h264_omx output-1280x800-h264.mkv
ffmpeg -f v4l2 -video_size 1280x800 -i /dev/video0 -codec:v h264_omx -b:v 2048k output-1280x800-h264-bitrate2048k.mkv

#Can be used to convert some file, too
ffmpeg -i inputFile.avi -codec:v h264_omx outputFile-1280x800-h264.mkv
ffmpeg -i inputFile.avi -codec:v h264_omx -b:v 2048k outputFile-1280x800-h264-bitrate2048k.mkv

#Displaying the output into VLC instead of recording it to a file :
ffmpeg -f v4l2 -video_size 1280x800 -i /dev/video0 -codec:v h264_omx -b:v 2048k -f matroska - | cvlc - -vvv

#Streaming it :
ffmpeg -f v4l2 -video_size 1280x800 -i /dev/video0 -codec:v h264_omx -b:v 2048k -f matroska - | cvlc - --sout '#http{mux=ffmpeg{mux=flv},dst=:8080/}' -vvv
VLC Only stuff

Code: Select all

#Raw capture :
cvlc v4l2:///dev/video0:width=1280:height=800 --sout '#file{dst=capture.avi}' -vvv

#Streaming with differnt encoding (not hardware, unfortunately) :
cvlc v4l2:///dev/video0:width=1280:height=800 --sout '#transcode{vcodec=h264,scale=Auto,acodec=none,scodec=none}:http{mux=ffmpeg{mux=flv},dst=:8080/}' -vvv
cvlc v4l2:///dev/video0:width=1280:height=800 --sout '#transcode{vcodec=mp2v,scale=Auto,acodec=none,scodec=none}:http{mux=ffmpeg{mux=avi},dst=:8080/}' -vvv
cvlc v4l2:///dev/video0:width=1280:height=800 --sout '#transcode{vcodec=mp4v,scale=Auto,acodec=none,scodec=none}:http{mux=ffmpeg{mux=avi},dst=:8080/}' -vvv

#With some parameters about videobitrate (vb 800 means 800k) and framerate (5 fps)
cvlc v4l2:///dev/video0:width=1280:height=800 --sout '#transcode{vcodec=mp4v,vb=512,scale=Auto,acodec=none,scodec=none,fps=5}:http{mux=ffmpeg{mux=avi},dst=:8080/}' -vvv

#Streaming desktop, need vlc-plugin-access-extra installed for opening screen://
cvlc screen:// :screen-fps=10 --sout '#transcode{vcodec=mp4v,scale=Auto,acodec=none,scodec=none}:http{mux=ffmpeg{mux=avi},dst=:8080/}' -vvv


Mycelium
Posts: 4
Joined: Tue Dec 22, 2020 10:07 pm

Re: [SOLVED] Using FFMPEG codec "h264_omx" hardware encoder for VLC streaming

Sun Dec 27, 2020 3:05 pm

Hey thanks for sharing.
Last edited by Mycelium on Sat Feb 06, 2021 12:37 am, edited 1 time in total.

winnywho
Posts: 1
Joined: Mon Jan 18, 2021 1:22 pm

Re: [SOLVED] Using FFMPEG codec "h264_omx" hardware encoder for VLC streaming

Mon Jan 18, 2021 1:26 pm

Hi,
Frankly speaking thank you for sharing your work and tests :)

Return to “Camera board”