Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ffmpeg: update v4l2-request patch #8356

Merged
merged 2 commits into from
Dec 5, 2023

Conversation

Kwiboo
Copy link
Member

@Kwiboo Kwiboo commented Nov 22, 2023

This PR updates the ffmpeg v4l2-request patch with following changes and fixes:

  • Fix an issue with h264 long term buf idx for frame based h264 decoding of field encoded videos
    • fixes fluster test vector MR6_BT_B and MR8_BT_B from test suite JVT-AVC_V1
  • Stop passing AVCodecContext as the opaque in buffer pool functions
    • removes the need for reverting two upstream commits
  • Change to use driver preferred format instead of current try_format loop
  • Rework v4l2_request_capture_pixelformats array to include more details like sw_format
    • adopt and include a Allwinner specific patch
  • Drop defines of drm and v4l2 pixel formats
    • libdrm 2.4.118 now include missing NV15/NV20 drm fourcc and kernel patches already add the missing v4l2 formats
  • Add rawvideo, image2 and md5 muxers to ffmpeg when building with FFMPEG_TESTING
    • this help to run fluster tests on devel builds

This has only been runtime tested with hantro and rkvdec driver and needs to be runtime tested with cedrus driver

Based on ffmpeg branch https://github.com/Kwiboo/FFmpeg/commits/v4l2-request-n6.0.1/

Patch created using revisions c41ff72..34c3a37
from branch v4l2-request-n6.0.1 of https://github.com/Kwiboo/FFmpeg
This make it easier to run fluster tests
@jernejsk
Copy link
Member

Looks good in principle. I'll merge once I'll test it.

@jernejsk jernejsk merged commit db968f9 into LibreELEC:master Dec 5, 2023
Kwiboo added a commit to Kwiboo/FFmpeg that referenced this pull request Aug 6, 2024
This is a follow up to a very old series from April 2019 [1] and
December 2020 [2], adding V4L2 Request API hwaccels for stateless
decoding of MPEG2, H.264 and HEVC.

These hwaccels has in one form or another been used in LibreELEC
community, nightly and release images since Dec 20th 2018.

HISTORY

The initial v4l2-request hwaccel code was mainly created as a proof of
concept at the end of 2018 by me and Jernej Skrabec. Back when Bootlin's
crowdfunding campaign for upstream Linux kernel driver for Allwinner VPU
had started to bear fruit.

At the time we had very little knowledge on how to properly interact
with any of the V4L2 APIs, and the existing V4L2 M2M code in FFmpeg
seemed very complex to start working with, so we started from scratch.

(That is the main reason why these hwaccels still does not use any of
the existing V4L2 M2M code in FFmpeg.)

The hwaccels had one major limitation, it waited on the kernel to
complete decoding before continuing with next request. Due to hwaccels
still was able to decode up to 4k 50-60fps on Allwinner and Rockchip
boards, time was never spent trying to improve this limitation.

The initial version of these hwaccels was merged as patches into
LibreELEC in April 2019 [3], with my FFmpeg tree as main source for any
update of FFmpeg v4l2-request patches included in LibreELEC.

A RFC was sent in April 2019 [1], with very little feedback and the
required kernel headers not being merged until a year later there was
never any new RFC revision submitted.

After the release of the Raspberry Pi 4 in June 2019 there was hope that
RPi folks would rework and/or improve our proof-of-concept to something
better that could be upstreamed, as history has show this did not happen.
And instead we have just ended up with a second FFmpeg v4l2-request
implementation that has only really been used for HEVC decoding on RPi.

Due to personal reasons I took a long break from doing open-source
contributions during ~2020-2023. During this time Jernej's FFmpeg tree
became the main source for FFmpeg v4l2-request patches in LibreELEC [4].

In December 2020 a v1 of this series was sent [2], at that time kernel
headers for H.264 had been merged into Linux kernel, and I cannot
remember why it never went any further.

Last update to the v4l2-request patches in LibreELEC was done by me in
November 2023 [5].

Along the way there has been noteworthy contributions including from
Boris Brezillon, Ezequiel Garcia, Alex Bee and Benjamin Gaignard.

PRESENT DAY

The version submitted in this series have seen major refactoring to the
common code, to make it more ready for upstreaming and also a rework of
how buffers and requests are handled.

The limitation of waiting for decoding to complete has been removed and
now multiple pending requests can be in-flight at the same time. This
was a requirement to better support HEVC decoding on RPi.

The older versions also incorrectly required use of a DRM hwdevice,
however V4L2 decoding has nothing to do with the DRM subsystem in Linux.

Instead in this version a new V4L2 Request API hwdevice has been added.
Thanks to this it is now possible to specify what media device to use
for decoding, in case multiple decoders exists on a system. E.g. using a
-init_hw_device v4l2request:/dev/media1 parameter.

This version only add support for MPEG2, H264 and HEVC. Support for VP8,
VP9 and AV1 is planned and be added in next revision or in a follow up
series.

HOW TO USE

To use the V4L2 Request API hwaccels you must build FFmpeg on a system
with recent Linux kernel headers, v6.0+. It also requires libdrm and
libudev to successfully build.

This can then be runtime tested on multiple Allwinner and Rockchip
devices. To runtime test this on a RPi 4 or 5 you should use latest
rpi-6.6.y kernel.

  ffmpeg -hwaccel v4l2request -hwaccel_output_format drm_prime \
         -i <input-path> -map 0:v -f null -

This series has been tested with cedrus driver on Allwinner H6, hantro
and rkvdec driver on Rockchip RK3399, and rpivid driver on RPi 4/5.

PRs have also been opened for Kodi and mpv to assist with the transition
from DRM to a new V4L2REQUEST hwdevice type.

- Kodi: xbmc/xbmc#25467
- mpv: mpv-player/mpv#14511

With those PRs applied it should be possible to playback video using
kodi-gbm or mpv, see the PRs above for more details.

It should also be possible to run fluster test suites with following PR:

- fluster: fluendo/fluster#179

I am expecting that there will be a new revision adding VP8, VP9 and AV1
support in a week or two.

Please get back with any type of feedback!

A copy of this series can also be found at [6].

[1] https://lists.ffmpeg.org/pipermail/ffmpeg-devel/2019-April/242316.html
[2] https://lists.ffmpeg.org/pipermail/ffmpeg-devel/2020-December/273579.html
[3] LibreELEC/LibreELEC.tv#3405
[4] https://github.com/LibreELEC/LibreELEC.tv/commits/master/packages/multimedia/ffmpeg/patches/v4l2-request
[5] LibreELEC/LibreELEC.tv#8356
[6] https://github.com/Kwiboo/FFmpeg/commits/v4l2request-2024-v2/

Signed-off-by: Jonas Karlman <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants