Last edited 7 months ago

How to encode a video stream with the hardware video encoder

Applicable for STM32MP25x lines


When using complex GStreamer bins such as encodebin or encodebin2, hardware acceleration is abstracted to user and automatically selected to achieve the best level of performances.

Here is an example with a local encoding of a 10s video test pattern in VP8:

 gst-launch-1.0 videotestsrc num-buffers=300 ! video/x-raw, width=640, height=480, framerate=30/1 ! encodebin profile="video/x-vp8" ! matroskamux ! filesink location=v_vp8_640x480_30fps.webm
[...]
Got EOS from element "pipeline0".
Execution ended after 0:00:01.229040368
[...]

Play back the file to check encoded content:

 gst-play-1.0 v_vp8_640x480_30fps.webm
[...]
0:00:10.0 / 0:00:10.0     
Reached end of play list.

Here is another example with a local encoding of a 10s video test pattern in H264:

 gst-launch-1.0 videotestsrc num-buffers=300 ! video/x-raw, width=640, height=480, framerate=30/1 ! encodebin profile="video/x-h264" ! qtmux ! filesink location=v_h264_640x480_30fps.mp4
[...]
Got EOS from element "pipeline0".
Execution ended after 0:00:01.125719575
[...]

Play back the file to check encoded content:

 gst-play-1.0 v_h264_640x480_30fps.mp4
[...]
0:00:10.0 / 0:00:10.0     
Reached end of play list.


Info white.png Information
Note that encoding is done as fast as possible, about 1.2s here but play back of encoded content well shows 10s of videos played meaning that the framerate information is well taken into account while encoding.


Info white.png Information
More information related to video encoding can be found in the article V4L2 video codec overview.