Hardware h264 video encoding in linux

Hello All,

I tried the above gst commands but with no luck, pipeline errors, please can anyone give me a gstreamer/ffmpeg command, which allows me to stream from /dev/video0 with hardware encoding enabled. I was able to do SW ffmpeg and the speed I get is 4fps which is bad, I need to do HW encoding can anyone help me

Thanks
ram

Hi all,

Please anyone inform which gstreamer-plugin i will use dragon 410c for android.

manju

The following commands for me :
Videotestsrc:
gst-launch-1.0 videotestsrc ! v4l2enc ! filesink location=raw_dual.mkv

gst-launch-1.0 -vvv videotestsrc ! video/x-raw,width=320,height=240,framerate=30/1,format=NV12 ! v4l2enc ! filesink location=raw_dual.mkv

Webcam:
gst-launch-1.0 -vvv v4l2src device=/dev/video0 ! videoconvert ! video/x-raw,width=320,height=240,framerate=30/1,format=NV12 ! v4l2enc ! filesink location=temp.mkv

Note the conversion to explicit NV12. It is very important as @svarbanov pointed out.

The following command works for streaming over UDP -
gst-launch-1.0 -vvv v4l2src device=/dev/video0 ! videoconvert ! video/x-raw,width=320,height=240,framerate=30/1,format=NV12 ! v4l2enc ! h264parse ! rtph264pay ! udpsink host=192.168.0.13 port=5000

Note the presence of h264parse. v4l2enc gives out byte-stream with aligment = au. rtph264pay does not seem to like that. h264parse converts to avc with alignment = au

Hi, does anyone know if the hardware is capable of encoding multiple streams simultaneously? Has anyone tried it? Specifically, I am interested in recording / encoding from two cameras at once.

I’m considering the 410 for a new design, but I can’t seem to find much detailed information on this part of the SoC. Thanks in advance.

matt

Hi, Matt. You should open two instances of the video encoder driver then you will encode camera streams simultaneously. Of course you should take into account the camera resolutions, I think 2x720p is supported from the hardware without overloading (overheating).

Stan

Thanks Stan, 2x720p would certainly meet our requirements. Unfortunately I do not have a board to test this with. If there’s no documentation that can verify the specs, I guess I’ll have to get the Dragonboard to try.

Has anyone seen a block diagram of this part of the SoC? I wonder if the video must be written to memory first, then consumed by the encoder, or if there is a direct path from the CSI’s to the video codec.

When using the below commands everything works perfectly.

sudo apt-get install gstreamer1.0-plugins-v4l2

gst-launch-1.0 -v -e --gst-debug=v4l2enc:0 videotestsrc ! video/x-raw,format=NV12,width=1280,height=720,framerate=30/1,profile=high,level\=\(string\)"5" ! v4l2enc ! queue ! filesink location=/home/linaro/enc.h264

gst-launch-1.0 -v -e --gst-debug=v4l2enc:0 videotestsrc ! video/x-raw,format=NV12,width=1280,height=720,framerate=30/1,profile=high,level\=\(string\)"5" ! v4l2enc ! h264parse ! mp4mux ! queue ! filesink location=/home/linaro/enc.mp4

I am getting an encoded video file which is playable.

But before doing the above steps I tried to compile the v4l2plugins from the source as below on the DB410C board itself.

mkdir transcoder

git clone https://git.linaro.org/landing-teams/working/qualcomm/pkg/gst-plugins-v4l2.git trasncoder/

cd transcoder

./autogen.sh

make

make install

sudo chown linaro:linaro -R /usr/local/lib/gstreamer-1.0

sudo chmod 777 -R /usr/local/lib/gstreamer-1.0

ls -l /usr/local/lib/gstreamer-1.0
-rwxrwxrwx 1 linaro linaro   1066 Feb 21 07:25 libgstv4l2dec.la
-rwxrwxrwx 1 linaro linaro 169520 Feb 21 07:25 libgstv4l2dec.so
-rwxrwxrwx 1 linaro linaro   1066 Feb 21 07:25 libgstv4l2enc.la
-rwxrwxrwx 1 linaro linaro 176792 Feb 21 07:25 libgstv4l2enc.so
-rwxrwxrwx 1 linaro linaro   1078 Feb 21 07:25 libgstv4l2trans.la
-rwxrwxrwx 1 linaro linaro 220192 Feb 21 07:25 libgstv4l2trans.so

export GST_PLUGIN_PATH=/usr/local/lib/gstreamer-1.0

gst-inspect-1.0 | grep "v4l2"
v4l2dec:  v4l2dec: V4L2 decoder
v4l2enc:  v4l2enc: V4L2 encoder
v4l2trans:  v4l2trans: V4L2 transform
video4linux2:  v4l2src: Video (video4linux2) Source
video4linux2:  v4l2sink: Video (video4linux2) Sink
video4linux2:  v4l2radio: Radio (video4linux2) Tuner
video4linux2:  v4l2deviceprovider (GstDeviceProviderFactory)
video4linux2:  v4l2video32dec: V4L2 Video Decoder

Now when I use the compiled v4l2enc plugin It was giving me the following error. Please help me to identify what went wrong with my compilation.

$ gst-launch-1.0 -v -e --gst-debug=v4l2enc:0 videotestsrc ! video/x-raw,format=NV12,width=1280,height=720,framerate=30/1,profile=high,level\=\(string\)"5" ! v4l2enc ! queue ! filesink location=/home/linaro/enc.h264
Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
/GstPipeline:pipeline0/GstVideoTestSrc:videotestsrc0.GstPad:src: caps = "video/x-raw\,\ format\=\(string\)NV12\,\ width\=\(int\)1280\,\ height\=\(int\)720\,\ framerate\=\(fraction\)30/1\,\ profile\=\(string\)high\,\ level\=\(string\)5\,\ pixel-aspect-ratio\=\(fraction\)1/1\,\ interlace-mode\=\(string\)progressive"
/GstPipeline:pipeline0/GstCapsFilter:capsfilter0.GstPad:src: caps = "video/x-raw\,\ format\=\(string\)NV12\,\ width\=\(int\)1280\,\ height\=\(int\)720\,\ framerate\=\(fraction\)30/1\,\ profile\=\(string\)high\,\ level\=\(string\)5\,\ pixel-aspect-ratio\=\(fraction\)1/1\,\ interlace-mode\=\(string\)progressive"
/GstPipeline:pipeline0/GstV4L2Enc:v4l2enc0.GstPad:sink: caps = "video/x-raw\,\ format\=\(string\)NV12\,\ width\=\(int\)1280\,\ height\=\(int\)720\,\ framerate\=\(fraction\)30/1\,\ profile\=\(string\)high\,\ level\=\(string\)5\,\ pixel-aspect-ratio\=\(fraction\)1/1\,\ interlace-mode\=\(string\)progressive"
/GstPipeline:pipeline0/GstCapsFilter:capsfilter0.GstPad:sink: caps = "video/x-raw\,\ format\=\(string\)NV12\,\ width\=\(int\)1280\,\ height\=\(int\)720\,\ framerate\=\(fraction\)30/1\,\ profile\=\(string\)high\,\ level\=\(string\)5\,\ pixel-aspect-ratio\=\(fraction\)1/1\,\ interlace-mode\=\(string\)progressive"
/GstPipeline:pipeline0/GstV4L2Enc:v4l2enc0.GstPad:src: caps = "video/x-h264\,\ width\=\(int\)1280\,\ height\=\(int\)720\,\ pixel-aspect-ratio\=\(fraction\)1/1\,\ framerate\=\(fraction\)30/1"
/GstPipeline:pipeline0/GstQueue:queue0.GstPad:sink: caps = "video/x-h264\,\ width\=\(int\)1280\,\ height\=\(int\)720\,\ pixel-aspect-ratio\=\(fraction\)1/1\,\ framerate\=\(fraction\)30/1"
/GstPipeline:pipeline0/GstQueue:queue0.GstPad:sink: caps = "video/x-h264\,\ width\=\(int\)1280\,\ height\=\(int\)720\,\ pixel-aspect-ratio\=\(fraction\)1/1\,\ framerate\=\(fraction\)30/1"
ERROR: from element /GstPipeline:pipeline0/GstV4L2Enc:v4l2enc0: GStreamer error: negotiation problem.
Additional debug info:
gstvideoencoder.c(1463): gst_video_encoder_chain (): /GstPipeline:pipeline0/GstV4L2Enc:v4l2enc0:
encoder not initialized
ERROR: pipeline doesn't want to preroll.
Setting pipeline to NULL ...
/GstPipeline:pipeline0/GstFileSink:filesink0.GstPad:sink: caps = "NULL"
/GstPipeline:pipeline0/GstQueue:queue0.GstPad:src: caps = "NULL"
/GstPipeline:pipeline0/GstQueue:queue0.GstPad:sink: caps = "NULL"
/GstPipeline:pipeline0/GstV4L2Enc:v4l2enc0.GstPad:src: caps = "NULL"
/GstPipeline:pipeline0/GstV4L2Enc:v4l2enc0.GstPad:sink: caps = "NULL"
/GstPipeline:pipeline0/GstCapsFilter:capsfilter0.GstPad:src: caps = "NULL"
/GstPipeline:pipeline0/GstCapsFilter:capsfilter0.GstPad:sink: caps = "NULL"
/GstPipeline:pipeline0/GstVideoTestSrc:videotestsrc0.GstPad:src: caps = "NULL"
Freeing pipeline ...

Regards,
Sunny.

hi,

sorry, i might have missed this message …

First of all, you are using a very old thing here… so it took me some time to remember… From your log you are using the ‘master’ branch from the gst plugin git tree, and you should be using the “debian” branch instead. From what I remember it was the debian branch which was pushed into our release (in Debian/Jessie).

Note that moving forward we are no longer supporting this external Gstreamer plugin for v4l2. Instead we are using the v4l2 plugins from Gstreamer Core (e.g. gst-plugins-good). The v4l2dec is already merged in Gst core, and the v4l2enc is being developed these days. The out of tree gst plugins we used in the past won’t work with any kernel more recent than what we had in the 16.09 release (or we would need to update the plugins accordingly).

Thanks for the info. :slight_smile:

I am not able to find v4l2dec plugin on gstreamer documentation. Can you please provide a link for v4l2dec plugin ?

I can’t find it in the doc neither… so it must be missing… here is a link to the plugin source code:

https://cgit.freedesktop.org/gstreamer/gst-plugins-good/tree/sys/v4l2/gstv4l2videodec.c

Unfortunately dynamic instantiated plugins don’t show up in the documentation. Though, gst-inspect-1.0 v4l2videoNdec should give you all the details you need. This should eventually be addressed by:

Bug 742918 – v4l2: Add decoder and converter element with RW device property

I don’t get it, but below is what I see under my PC. Can you please confirm in which gstreamer release the v4l2videodec plugin is included ?

user@linuxpc:~$ gst-inspect-1.0 --version
gst-inspect-1.0 version 1.8.2
GStreamer 1.8.2
https://launchpad.net/distros/ubuntu/+source/gstreamer1.0

user@linuxpc:~$ gst-inspect-1.0 | grep “v4l2”
video4linux2: v4l2src: Video (video4linux2) Source
video4linux2: v4l2sink: Video (video4linux2) Sink
video4linux2: v4l2radio: Radio (video4linux2) Tuner
video4linux2: v4l2deviceprovider (GstDeviceProviderFactory)

user@linuxpc:~$ gst-inspect-1.0 v4l2videoNdec
No such element or plugin ‘v4l2videoNdec’

user@linuxpc:~$ gst-inspect-1.0 v4l2videodec
No such element or plugin ‘v4l2videodec’

it is normal. on your PC there is no v4l2 decoder driver, so there won’t be any instance of the Gst v4l2videoNdec plugin. if you run the same command on your DB410c , then you should see one instance of the plugin.

Oh sorry my bad, I got confused between DB410 and DB820. This post is related to DB410 and not DB820, I am looking for v4l2 decoder and encoder plugins on DB820. Yes ndec am able to see both v4l2videodec and v4l2videoenc on DB410, I have already tested both the plugins on DB410. Thanks.

Hi @anon91830841,

I am also facing the same thing as described here,
in the output of gst-inspect-1.0 |grep v4l2 command,
I don’t see the v4l2enc.

can you suggest me any way to use the hardware encoder provided in my DB410c board.
I am using the latest linaro build, and i did update and upgrade after fresh installation.

Could you help me out here.

Thanks,
Hinesh

sorry, i missed this message earlier.

don’t you see something like that:

root@dragonboard-410c:~# gst-inspect-1.0 | grep v4l2
video4linux2:  v4l2src: Video (video4linux2) Source
video4linux2:  v4l2sink: Video (video4linux2) Sink
video4linux2:  v4l2radio: Radio (video4linux2) Tuner
video4linux2:  v4l2deviceprovider (GstDeviceProviderFactory)
video4linux2:  v4l2mpeg4dec: V4L2 MPEG4 Decoder
video4linux2:  v4l2mpeg2dec: V4L2 MPEG2 Decoder
video4linux2:  v4l2h263dec: V4L2 H263 Decoder
video4linux2:  v4l2h264dec: V4L2 H264 Decoder
video4linux2:  v4l2vp8dec: V4L2 VP8 Decoder
video4linux2:  v4l2vc1dec: V4L2 VC1 Decoder
video4linux2:  v4l2h264enc: V4L2 H.264 Encoder
video4linux2:  v4l2mpeg4enc: V4L2 MPEG4 Encoder
video4linux2:  v4l2h263enc: V4L2 H.263 Encoder
video4linux2:  v4l2vp8enc: V4L2 VP8 Encoder

There are a couple of video encoder here.

It is with Gst 1.14.2

If you don’t see that, please share more info about your build, gst version, …

Hi @anon91830841

When I ran above mentioned command, I was getting only below outputs.

video4linux2: v4l2src: Video (video4linux2) Source
video4linux2: v4l2sink: Video (video4linux2) Sink
video4linux2: v4l2radio: Radio (video4linux2) Tuner

I am not able to find v4l2enc ( which i am looking for),
I am using the latest gst version provided in linaro latest build.( also performed update and upgrade).
Do I require to install some more set of gst plugins???

Kindly provide your suggestions.

Thanks,
Hinesh

Just in case, could you check with ‘lsmod’ you have modules loaded, including venus_dec/venus_enc.
There is a known issue with last build and upgrading: After sudo apt upgrade - the wifi device is gone

Hi @Loic,
I have checked with lsmod, And I Don’t find the encoder in them as well.

Thanks,