ykla
Posts: 8
Joined: Tue Oct 29, 2019 9:18 am

How to enable H264/H265/MPG2 or others decoders in RPI4B?

Tue Jan 21, 2020 9:28 am

Gentoo Linux aarch64 with raspberry pi4B.
----------------------------------------------------------------------------------------

Code: Select all

ykla ~ # vcgencmd codec_enabled MPG2
MPG2=disabled
ykla ~ # vcgencmd codec_enabled H264
H264=disabled
ykla ~ # vcgencmd codec_enabled H265
H265=disabled
ykla ~ # 
-------------------------------------------------------------------------------------

Code: Select all

ykla ~ # cat /boot/config.txt 
# have a properly sized image
disable_overscan=1
# for sound over HDMI
hdmi_drive=2
# Enable audio (loads snd_bcm2835)
dtparam=audio=on
# set 64 bit mode
arm_64bit=1

enable_gic=1
armstub=armstub8-gic.bin
# lets have the VC4 hardware accelerated video
dtoverlay=vc4-fkms-v3d
gpu_mem=16
force_turbo=0
arm_freq=2000
over_voltage=10
enable_uart=1
ykla ~ # 
---------------------------------------------------------------------------
So how to enable them in raspberry pi 4B?
Different languages different worldviews.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 26349
Joined: Sat Jul 30, 2011 7:41 pm

Re: How to enable H264/H265/MPG2 or others decoders in RPI4B?

Tue Jan 21, 2020 10:49 am

Those should all be enabled by default in the firmware. It's possible that on Gentoo 64bit (not supported by us and still very much beta software I suspect) that vcgencmd is reporting incorrectly.

Have you tried to see if they actually work?
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed.
I've been saying "Mucho" to my Spanish friend a lot more lately. It means a lot to him.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 8659
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: How to enable H264/H265/MPG2 or others decoders in RPI4B?

Tue Jan 21, 2020 12:05 pm

(Sorry, James is partly talking rubbish)

On a Pi4 the only decode supported by the GPU firmware (which is what vcgencmd reports) is H264, and that should be reported as enabled.
H263, MPEG4, MPG2, and VC-1 hardware decode are not available on the Pi4, so will report disabled.

H265 hardware acceleration is implemented via ARM side drivers, hence the GPU won't report it.

On 64bit systems the only supported hardware decode API is V4L2 M2M devices. /dev/video10 should exist for video decode (video11 is encode, and 12 for resize and format conversion). If you use "v4l2-ctl -d 10 --list-formats-out" it should list the formats that the GPU has reported as supported.

Code: Select all

pi@raspberrypi:~ $ v4l2-ctl -d 10 --list-formats-out
ioctl: VIDIOC_ENUM_FMT
	Type: Video Output Multiplanar

	[0]: 'H264' (H.264, compressed)
	[1]: 'MJPG' (Motion-JPEG, compressed)
	[2]: 'VP80' (VP8, compressed)
(VP8 is done in software on the GPU, but can be accessed via the same API).
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 8659
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: How to enable H264/H265/MPG2 or others decoders in RPI4B?

Tue Jan 21, 2020 12:12 pm

Hang on

Code: Select all

gpu_mem=16
Will switch to the cut-down firmware which has all the codecs etc stripped out. Yes, all codecs will be disabled.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

User avatar
sakaki
Posts: 542
Joined: Sun Jul 16, 2017 1:11 pm

Re: How to enable H264/H265/MPG2 or others decoders in RPI4B?

Tue Jan 21, 2020 1:00 pm

I can confirm on the v1.5.3 gentoo-on-rpi-64bit image, on an RPi4B with the GPU memory set at e.g. 128MiB (the shipped default), then H264 shows as enabled:

Code: Select all

demouser@pi64 ~ $ vcgencmd codec_enabled H264
H264=enabled
Also, if you run Applications -> Settings -> RPi Config Tool, and hover over the GPU memory dropdown menu, the tooltip help will tell you that you need at least 96MiB allocated for the codecs to run correctly.

Since this release has 6by9's 64-bit MMAL pointer-wrangling PR#586 included, you should be able to use both V4L2 M2M and MMAL routes to access the H264 codec (aiui; the v1.5.3 release contains a patched ffmpeg with MMAL and V4L2 M2M support).

See for example my notes here.

Also, although the Gentoo image does not support use of the h/w video codecs in Firefox or Chromium yet (should be possible in the latter, but requires use of their "ozone" abstraction layer, and I haven't got round to unpicking that...), it is possible via e.g. Applications -> Multimedia -> SMPlayer, as this does have the necessary acceleration enabled. In this app, you can specify the default quality you want via Options -> Preferences, Network (left tab), and open streams via Open -> URL... (just paste in the youtube URL you want to watch).

On my RPi4B (4GB), with a fast IP connection, this plays back 1080p videos smoothly; for instance:

Image

Please see my post here for further details.

hth, sakaki
Last edited by sakaki on Tue Jan 21, 2020 1:27 pm, edited 5 times in total.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 26349
Joined: Sat Jul 30, 2011 7:41 pm

Re: How to enable H264/H265/MPG2 or others decoders in RPI4B?

Tue Jan 21, 2020 1:08 pm

6by9 wrote:
Tue Jan 21, 2020 12:05 pm
(Sorry, James is partly talking rubbish)

On a Pi4 the only decode supported by the GPU firmware (which is what vcgencmd reports) is H264, and that should be reported as enabled.
H263, MPEG4, MPG2, and VC-1 hardware decode are not available on the Pi4, so will report disabled.

H265 hardware acceleration is implemented via ARM side drivers, hence the GPU won't report it.

On 64bit systems the only supported hardware decode API is V4L2 M2M devices. /dev/video10 should exist for video decode (video11 is encode, and 12 for resize and format conversion). If you use "v4l2-ctl -d 10 --list-formats-out" it should list the formats that the GPU has reported as supported.

Code: Select all

pi@raspberrypi:~ $ v4l2-ctl -d 10 --list-formats-out
ioctl: VIDIOC_ENUM_FMT
	Type: Video Output Multiplanar

	[0]: 'H264' (H.264, compressed)
	[1]: 'MJPG' (Motion-JPEG, compressed)
	[2]: 'VP80' (VP8, compressed)
(VP8 is done in software on the GPU, but can be accessed via the same API).
Partly?
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed.
I've been saying "Mucho" to my Spanish friend a lot more lately. It means a lot to him.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 8659
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: How to enable H264/H265/MPG2 or others decoders in RPI4B?

Tue Jan 21, 2020 1:19 pm

sakaki wrote:
Tue Jan 21, 2020 1:00 pm
Since this release has 6by9's 64-bit MMAL pointer-wrangling PR#586 included, you should be able to use both V4L2 M2M and MMAL routes to access the H264 codec (aiui; the v1.5.3 release contains a patched ffmpeg with MMAL and V4L2 M2M support).
Please be aware that we have reverted that change for the time being (although it looks like Dom has only done it for releases and not in userland). Kodi was showing up some weird issues on 32bit systems where the same client context was being returned twice which shouldn't happen. As we free the client context lookup after the first one had been returned, we end up with a NULL pointer deref and seg fault :-( I haven't had time to investigate why the same context is being returned yet.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

User avatar
sakaki
Posts: 542
Joined: Sun Jul 16, 2017 1:11 pm

Re: How to enable H264/H265/MPG2 or others decoders in RPI4B?

Tue Jan 21, 2020 1:22 pm

Ack. Is that only a 32-bit userland thing? Seems quite well behaved from 64-bit contexts so far.

Best, sakaki

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 8659
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: How to enable H264/H265/MPG2 or others decoders in RPI4B?

Tue Jan 21, 2020 2:20 pm

sakaki wrote:
Tue Jan 21, 2020 1:22 pm
Ack. Is that only a 32-bit userland thing? Seems quite well behaved from 64-bit contexts so far.
It's common code for 32 and 64 bit deliberately so it got exercised by more people to show up any odd bugs.

Kodi generally runs fine, but will sometimes throw a seg fault in the middle of playing a file. Generally 45mins-3 hours in, so it's not an obvious path.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Return to “General discussion”