Difference between revisions of "Mainline Hardware Encoding"

From PINE64
Jump to navigation Jump to search
m (→‎SoC Support: getting fancy with tables)
(Update, add notes)
 
(11 intermediate revisions by 2 users not shown)
Line 1: Line 1:
'''Mainline Hardware Encoding''' of video can be achieved through the V4L2 user-space API, for which currently only GStreamer implements the required code.
'''Mainline Hardware Encoding''' of video can be achieved through the V4L2 user-space API, for which currently only GStreamer implements the required code.


= SoC Support =
== SoC Support ==


The following table shows the current supported codecs for encoding for each SoC. Support for decoding is separate.
The following table shows the current supported codecs for encoding for each SoC. Support for decoding is separate.
Line 7: Line 7:
{| class="wikitable plainrowheaders" border="1"
{| class="wikitable plainrowheaders" border="1"
! scope="col" {{Diagonal split header|Codec|SoC}}
! scope="col" {{Diagonal split header|Codec|SoC}}
! scope="col" | RK3328
! scope="col" | RK3399
! scope="col" | RK3399
! scope="col" | RK3566
! scope="col" | RK3566
Line 12: Line 13:
|-
|-
! scope="row" | JPEG
! scope="row" | JPEG
| style="text-align:center;"| N/A
| style="background:PaleGreen; text-align:center;"| Yes
| style="background:PaleGreen; text-align:center;"| Yes
| style="background:LightYellow; text-align:center;"| In review
| style="background:PaleGreen; text-align:center;"| Yes
| style="background:#F99; text-align:center;"| No
|-
! scope="row" | VP8
| style="text-align:center;"| N/A
| style="background:LightYellow; text-align:center;"| RFC<sup>[https://lore.kernel.org/linux-rockchip/20230309125651.23911-1-andrzej.p@collabora.com/T/]</sup><sup style="font-style:italic;color:green">a</sup>
| style="background:LightYellow; text-align:center;"| RFC<sup>[https://lore.kernel.org/linux-rockchip/20230309125651.23911-1-andrzej.p@collabora.com/T/]</sup><sup style="font-style:italic;color:green">a</sup>
| style="background:#F99; text-align:center;"| No
| style="background:#F99; text-align:center;"| No
|-
|-
Line 19: Line 27:
| style="background:#F99; text-align:center;"| No
| style="background:#F99; text-align:center;"| No
| style="background:#F99; text-align:center;"| No
| style="background:#F99; text-align:center;"| No
| style="background:#F99; text-align:center;"| No<sup style="font-style:italic;color:green">a</sup>
| style="background:#F99; text-align:center;"| No
| style="background:#F99; text-align:center;"| No
|-
|-
! scope="row" | H.265/HEVC
! scope="row" | H.265/HEVC
| style="background:#F99; text-align:center;"| No
| style="background:#F99; text-align:center;"| No
| style="text-align:center;"| N/A
| style="background:#F99; text-align:center;"| No
| style="background:#F99; text-align:center;"| No
| style="background:#F99; text-align:center;"| No
| style="background:#F99; text-align:center;"| No
|}
|}


= Encoding With GStreamer =
=== Notes ===
<ol style="list-style-type:lower-alpha">
<li>Userspace API [https://lore.kernel.org/linux-media/ZK2NiQd1KnraAr20@aptenodytes/ under discussion] as part of the V4L2 stateless encoder uAPI development, with experimental implementations being worked on.</li>
</ol>
 
== Encoding With GStreamer ==


With GStreamer, in general, any V4L2 control can be set using the <code>extra-controls=foo,name=value</code> syntax after the encode pipeline stage identifier, where <code>foo</code> is any name you wish which GStreamer will promptly ignore, <code>name</code> is the name of the V4L2 control as shown by <code>v4l2-ctl --list-ctrls</code> (make sure to pick the right device with <code>-d</code>), and <code>value</code> is whatever value you want to set it to.
With GStreamer, in general, any V4L2 control can be set using the <code>extra-controls=foo,name=value</code> syntax after the encode pipeline stage identifier, where <code>foo</code> is any name you wish which GStreamer will promptly ignore, <code>name</code> is the name of the V4L2 control as shown by <code>v4l2-ctl --list-ctrls</code> (make sure to pick the right device with <code>-d</code>), and <code>value</code> is whatever value you want to set it to.


== JPEG Encoding ==
=== JPEG Encoding ===


This example converts an input MP4 file to an output MJPEG-inside-MKV file at JPEG quality 95, without any audio.
This example converts an input MP4 file to an output MJPEG-inside-MKV file at JPEG quality 95, without any audio.


    gst-launch-1.0 filesrc location=input.mp4 ! qtdemux name=demux demux.video_0 ! decodebin ! videoconvert ! v4l2jpegenc extra-controls=s,compression_quality=95 ! matroskamux ! filesink location=output.mkv
gst-launch-1.0 filesrc location=input.mp4 ! qtdemux name=demux demux.video_0 ! decodebin ! videoconvert ! v4l2jpegenc extra-controls=s,compression_quality=95 ! matroskamux ! filesink location=output.mkv
 
=== VP8 Encoding ===
 
{{hint|'''Note:''' This requires a draft [https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3736 GStreamer merge request] and the RFC kernel patchset applied.}}
{{note|'''Note:''' Patchset no longer applies cleanly, as AV1 decode controls were introduced and conflict.}}
 
This example converts an input MP4 file to an output VP8-inside-MKV file with a quantiser between 12 and 28, without any audio. The quantiser value goes from 0 (best quality, biggest filesize) to 63 (worst quality, smallest filesize).
 
gst-launch-1.0 filesrc location=input.mp4 ! qtdemux name=demux demux.video_0 ! decodebin ! videoconvert ! v4l2slvp8enc min-quality=12 max-quality=28 ! queue ! matroskamux ! filesink location=output.mkv
 
Alternatively, you can encode in variable bitrate mode with a target bitrate given in bits per second. Do note that Hantro doesn't seem to do target bitrates below 2 mbit/s. In this example, the file is transcoded at a target bitrate of 3 megabits per second.
 
gst-launch-1.0 filesrc location=input.mp4 ! qtdemux name=demux demux.video_0 ! decodebin ! videoconvert ! v4l2slvp8enc bitrate=3000000 ! queue ! matroskamux ! filesink location=output.mkv
 
== See Also ==
 
* [[Mainline Hardware Decoding]]
 


[[Category:Quartz64]] [[Category:ROCKPro64]] [[Category:Rockchip RK3566]] [[Category:Rockchip RK3399]] [[Category:PineBook Pro]] [[Category:PinePhone Pro]] [[Category:PineNote]] [[Category:Rockchip RK3588]]
[[Category:Quartz64]] [[Category:ROCKPro64]] [[Category:Rockchip RK3566]] [[Category:Rockchip RK3399]] [[Category:Pinebook Pro]] [[Category:PinePhone Pro]] [[Category:PineNote]] [[Category:Rockchip RK3588]] [[Category:Rockchip RK3328]] [[Category:ROCK64]]

Latest revision as of 04:01, 5 September 2023

Mainline Hardware Encoding of video can be achieved through the V4L2 user-space API, for which currently only GStreamer implements the required code.

SoC Support

The following table shows the current supported codecs for encoding for each SoC. Support for decoding is separate.

SoC
Codec
RK3328 RK3399 RK3566 RK3588
JPEG N/A Yes Yes No
VP8 N/A RFC[1]a RFC[2]a No
H.264/AVC No No Noa No
H.265/HEVC No N/A No No

Notes

  1. Userspace API under discussion as part of the V4L2 stateless encoder uAPI development, with experimental implementations being worked on.

Encoding With GStreamer

With GStreamer, in general, any V4L2 control can be set using the extra-controls=foo,name=value syntax after the encode pipeline stage identifier, where foo is any name you wish which GStreamer will promptly ignore, name is the name of the V4L2 control as shown by v4l2-ctl --list-ctrls (make sure to pick the right device with -d), and value is whatever value you want to set it to.

JPEG Encoding

This example converts an input MP4 file to an output MJPEG-inside-MKV file at JPEG quality 95, without any audio.

gst-launch-1.0 filesrc location=input.mp4 ! qtdemux name=demux demux.video_0 ! decodebin ! videoconvert ! v4l2jpegenc extra-controls=s,compression_quality=95 ! matroskamux ! filesink location=output.mkv

VP8 Encoding

Note: This requires a draft GStreamer merge request and the RFC kernel patchset applied.
Note: Patchset no longer applies cleanly, as AV1 decode controls were introduced and conflict.

This example converts an input MP4 file to an output VP8-inside-MKV file with a quantiser between 12 and 28, without any audio. The quantiser value goes from 0 (best quality, biggest filesize) to 63 (worst quality, smallest filesize).

gst-launch-1.0 filesrc location=input.mp4 ! qtdemux name=demux demux.video_0 ! decodebin ! videoconvert ! v4l2slvp8enc min-quality=12 max-quality=28 ! queue ! matroskamux ! filesink location=output.mkv

Alternatively, you can encode in variable bitrate mode with a target bitrate given in bits per second. Do note that Hantro doesn't seem to do target bitrates below 2 mbit/s. In this example, the file is transcoded at a target bitrate of 3 megabits per second.

gst-launch-1.0 filesrc location=input.mp4 ! qtdemux name=demux demux.video_0 ! decodebin ! videoconvert ! v4l2slvp8enc bitrate=3000000 ! queue ! matroskamux ! filesink location=output.mkv

See Also