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

Fix h264_v4l2m2m acceleration in Raspberry Pi 4 #7227

Closed
wants to merge 2 commits into from

Conversation

MELSunny
Copy link

Changes

Fixed by replacing pixel format from NV21 to yuv420p.

Issues

Error when enabling v4l acceleration in Raspberry Pi 4
Logs:
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'file:/srv/dev-disk-by-uuid-17558f66-a74f-4416-b283-4c70bb44b6f8/MediaLibrary/Movie/test.mp4':
Metadata:
major_brand : isom
minor_version : 1
compatible_brands: isomavc1
creation_time : 2015-04-23T22:01:41.000000Z
Duration: 02:08:29.76, start: 0.000000, bitrate: 2173 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709/bt709/unknown), 1920x800 [SAR 1:1 DAR 12:5], 2075 kb/s, 23.98 fps, 23.98 tbr, 24k tbn, 47.95 tbc (default)
Metadata:
creation_time : 2015-04-23T22:01:41.000000Z
handler_name : video.264#trackID=1:fps=23.976 - Imported with GPAC 0.5.0-rev
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 93 kb/s (default)
Metadata:
creation_time : 2015-04-23T22:01:53.000000Z
handler_name : GPAC ISO Audio Handler
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> h264 (h264_v4l2m2m))
Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
[h264_v4l2m2m @ 0x559ce26380] Using device /dev/video11
[h264_v4l2m2m @ 0x559ce26380] driver 'bcm2835-codec' on card 'bcm2835-codec-encode' in mplane mode
[h264_v4l2m2m @ 0x559ce26380] requesting formats: output=YU12 capture=H264
[h264_v4l2m2m @ 0x559ce26380] Encoder requires yuv420p pixel format.
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
Conversion failed!

Error when enabling v4l acceleration in Raspberry Pi 4
Logs:
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'file:/srv/dev-disk-by-uuid-17558f66-a74f-4416-b283-4c70bb44b6f8/MediaLibrary/Movie/test.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 1
    compatible_brands: isomavc1
    creation_time   : 2015-04-23T22:01:41.000000Z
  Duration: 02:08:29.76, start: 0.000000, bitrate: 2173 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709/bt709/unknown), 1920x800 [SAR 1:1 DAR 12:5], 2075 kb/s, 23.98 fps, 23.98 tbr, 24k tbn, 47.95 tbc (default)
    Metadata:
      creation_time   : 2015-04-23T22:01:41.000000Z
      handler_name    : video.264#trackID=1:fps=23.976 - Imported with GPAC 0.5.0-rev
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 93 kb/s (default)
    Metadata:
      creation_time   : 2015-04-23T22:01:53.000000Z
      handler_name    : GPAC ISO Audio Handler
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (h264_v4l2m2m))
  Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
[h264_v4l2m2m @ 0x559ce26380] Using device /dev/video11
[h264_v4l2m2m @ 0x559ce26380] driver 'bcm2835-codec' on card 'bcm2835-codec-encode' in mplane mode
[h264_v4l2m2m @ 0x559ce26380] requesting formats: output=YU12 capture=H264
[h264_v4l2m2m @ 0x559ce26380] Encoder requires yuv420p pixel format.
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
Conversion failed!

Fixed by replacing pixel format to yuv420p.
@MELSunny
Copy link
Author

Related discussing jellyfin/jellyfin-ffmpeg#310

@@ -1283,7 +1283,7 @@ public string GetVideoQualityParam(EncodingJobInfo state, string videoEncoder, E

if (string.Equals(videoEncoder, "h264_v4l2m2m", StringComparison.OrdinalIgnoreCase))
{
param += " -pix_fmt nv21";
param += " -pix_fmt yuv420p";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove this field and add a new case for V4L2 encoder after these lines?

if (isVaapiEncoder)
{
outFormat = "nv12";
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo? nv12 / nv21

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nyanmisaka I submitted a new PR (#7291) that moves this change down to that location, however I did not fix the potential issue that @Maxplosion pointed out? All credit to @MELSunny as this is more or less just an update on his PR

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for your PR @aolszowka.
nv12 is tested to work on raspberry pi 4 as well.
@Maxplosion nv21 is not a typo, it exists in pixel format in FFmpeg. But nv21 is not supported by raspberry pi encoder h264_v4l2m2m.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove this field and add a new case for V4L2 encoder after these lines?

if (isVaapiEncoder)
{
outFormat = "nv12";
}

Many thanks for the contribution by @aolszowka,
I have updated the code according to @nyanmisaka advice

deae9bb

@emgre
Copy link

emgre commented Feb 17, 2022

Does someone know why this particular pixel format was explicitly specified for h264_v4l2m2m? Was it because of a particular hardware? My guess would be that it's related to some Android device. What if we let ffmpeg choose the pixel format?

@aolszowka
Copy link
Contributor

@emgre As per the PR the hardware being targeted here is a Raspberry Pi 4 (https://www.raspberrypi.com/products/raspberry-pi-4-model-b/specifications/ a Broadcom BCM2711 SOC). I suspect that that pixel format is being specifically targeted due to ffmpeg stating the following (from the log above):

[h264_v4l2m2m @ 0x559ce26380] Encoder requires yuv420p pixel format.

@emgre
Copy link

emgre commented Feb 18, 2022

@aolszowka I understand the current change, my question was why nv21 was explicitely set originally?

@aolszowka
Copy link
Contributor

@emgre Ah that is a different question, I suspect as you do that this was for support for an Android Device, as the original drop down for this used to read Exynos V4L2M2. The Exynos is a SoC similar to the Broadcom on the Pi, but on different boards, most likely a ODROID of some type. A search of the previous issues shows at least one user reporting an issue with it.

At some point this text was modified to no loner reference this specific SoC (I am unable to find the PR/Commit this was done on) the original changes look to be done on #1369?

Many thanks for the contribution by @aolszowka, jellyfin#7291
I have updated the code according to @nyanmisaka advice jellyfin#7227 (comment)
@nyanmisaka
Copy link
Member

Closed in #7291

@nyanmisaka nyanmisaka closed this Mar 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants