Title: i.MX8MP V4L2 H.264 Encoder Fails on Dynamic Runtime Update (Bitrate Mode / Resolution) — poll

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Title: i.MX8MP V4L2 H.264 Encoder Fails on Dynamic Runtime Update (Bitrate Mode / Resolution) — poll

631 Views
VishnuSidda
Contributor III

IMX8MPLUS 

Platform Details:

  • SoC: i.MX8MP

  • BSP: (Linux imx8mpevk 6.12.20-lts-next-gdfaf2136deb2)

  • GStreamer: 1.26.0 (NXP plugins)

  • Encoder: v4l2h264enc

  • Source: v4l2src (camera)

  • OS: Linux (Yocto-based)


Use Case:
We are building a dynamic multi-stream video pipeline using GStreamer with the following architecture:

v4l2src → capsfilter → imxvideoconvert_g2d → tee
                                         ├── RTSP branch (v4l2h264enc)

We dynamically create/remove encoder branches from a tee (using request pads) and support runtime configuration updates via API.


Problem Description:

We are attempting to dynamically update encoder parameters at runtime (pipeline in PLAYING state), specifically:

  • Bitrate mode (CBR / VBR)

  • Bitrate

  • Resolution (caps change)

This is done using:

  • g_object_set() on encoder (extra-controls)

  • Updating caps on downstream capsfilter

  • Updating videorate (max-rate)


Relevant Code (Simplified):

enc_el.set_property("extra-controls", Gst.Structure.new_from_string(
    "controls,video_bitrate_mode=1,video_gop_size=25"))

rate_el.set_property("max-rate", fps)

res_el.set_property("caps", Gst.Caps.from_string(
    f"video/x-raw,width={w},height={h},format=BGRx"))

Observed Behavior:

Immediately after applying dynamic update (especially bitrate mode change), pipeline fails with:

gstvideoencoder.c:2506:
Can't copy metadata because input frame disappeared

v4l2object.c:6524: gst_v4l2_object_poll:
poll error 1: Invalid argument (22)

GST_ERROR:
Could not read from resource.

gstbasesrc.c:3187:
Internal data stream error.
streaming stopped, reason error (-5)

This results in:

  • Encoder failure (v4l2h264enc)

  • Queue failure

  • Source (v4l2src) stopping

  • Entire pipeline going to error state


Full Error Logs (Excerpt):

gst_v4l2_object_poll:<v4l2h264enc> error: poll error 1: Invalid argument (22)
gst_element_message_full_with_details: Could not read from resource
gst_base_src_loop:<v4l2src> error: Internal data stream error
streaming stopped, reason error (-5)

Key Observations:

  1. Issue is reproducible when changing:

    • video_bitrate_mode (CBR ↔ VBR)

    • bitrate

  2. Sometimes encoder accepts property but:

    • no visible effect OR

    • fails shortly after

  3. FPS changes using videorate work fine

  4. Resolution changes sometimes work but are unstable


Questions:

  1. Is runtime update of v4l2h264enc controls supported?

    • Specifically:

      • video_bitrate_mode

      • video_bitrate

      • video_gop_size

  2. Are these controls required to be set only in:

    • NULL / READY state?

  3. Does the i.MX8MP VPU driver support:

    • dynamic bitrate adjustment in PLAYING state?

  4. For resolution change:

    • Is dynamic caps renegotiation supported with imxvideoconvert_g2d + encoder?

    • Or is pipeline restart required?

  5. What is the recommended approach for:

    • changing bitrate mode (CBR/VBR)

    • changing resolution

    • in a live streaming pipeline?


Additional Context:
In commercial IP cameras, bitrate appears to change dynamically without stream interruption.
We would like to understand whether:

  • This is supported at driver level, or

  • Requires encoder restart / pipeline rebuild.


Expected Guidance:

  • Official recommendation from NXP for runtime encoder reconfiguration

  • Supported vs unsupported controls in PLAYING state

  • Best practice for dynamic streaming pipelines


Summary:
Dynamic updates to v4l2h264enc (especially bitrate mode) result in:

  • V4L2 poll errors (EINVAL)

  • Encoder failure

  • Pipeline crash

We want to confirm whether this is expected behavior and how to correctly implement dynamic reconfiguration.


Thank you.

0 Kudos
Reply
1 Reply

595 Views
joanxie
NXP TechSupport
NXP TechSupport

I've already mailed to you for enabling VBR, then you can control it dynamically, pls check my mail

0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-2333932%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ETitle%3A%20i.MX8MP%20V4L2%20H.264%20Encoder%20Fails%20on%20Dynamic%20Runtime%20Update%20(Bitrate%20Mode%20%2F%20Resolution)%20%E2%80%94%20poll%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2333932%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fc-pwmxy87654%2FIMX8MPLUS%2Fpd-p%2FIMX8MPLUS%22%20class%3D%22lia-product-mention%22%20data-product%3D%2221-1%22%20target%3D%22_blank%22%3EIMX8MPLUS%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3EPlatform%20Details%3A%3C%2FSTRONG%3E%3C%2FP%3E%3CUL%3E%3CLI%3E%3CP%3ESoC%3A%20i.MX8MP%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3EBSP%3A%20(Linux%20imx8mpevk%206.12.20-lts-next-gdfaf2136deb2)%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3EGStreamer%3A%201.26.0%20(NXP%20plugins)%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3EEncoder%3A%20v4l2h264enc%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3ESource%3A%20v4l2src%20(camera)%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3EOS%3A%20Linux%20(Yocto-based)%3C%2FP%3E%3C%2FLI%3E%3C%2FUL%3E%3CHR%20%2F%3E%3CP%3E%3CSTRONG%3EUse%20Case%3A%3C%2FSTRONG%3E%3CBR%20%2F%3EWe%20are%20building%20a%20%3CSTRONG%3Edynamic%20multi-stream%20video%20pipeline%3C%2FSTRONG%3E%20using%20GStreamer%20with%20the%20following%20architecture%3A%3C%2FP%3E%3CPRE%3Ev4l2src%20%E2%86%92%20capsfilter%20%E2%86%92%20imxvideoconvert_g2d%20%E2%86%92%20tee%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%E2%94%9C%E2%94%80%E2%94%80%20RTSP%20branch%20(v4l2h264enc)%0A%0A%3C%2FPRE%3E%3CP%3EWe%20dynamically%20create%2Fremove%20encoder%20branches%20from%20a%20tee%20(using%20request%20pads)%20and%20support%20runtime%20configuration%20updates%20via%20API.%3C%2FP%3E%3CHR%20%2F%3E%3CP%3E%3CSTRONG%3EProblem%20Description%3A%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3EWe%20are%20attempting%20to%20%3CSTRONG%3Edynamically%20update%20encoder%20parameters%20at%20runtime%3C%2FSTRONG%3E%20(pipeline%20in%20PLAYING%20state)%2C%20specifically%3A%3C%2FP%3E%3CUL%3E%3CLI%3E%3CP%3EBitrate%20mode%20(CBR%20%2F%20VBR)%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3EBitrate%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3EResolution%20(caps%20change)%3C%2FP%3E%3C%2FLI%3E%3C%2FUL%3E%3CP%3EThis%20is%20done%20using%3A%3C%2FP%3E%3CUL%3E%3CLI%3E%3CP%3Eg_object_set()%20on%20encoder%20(extra-controls)%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3EUpdating%20caps%20on%20downstream%20capsfilter%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3EUpdating%20videorate%20(max-rate)%3C%2FP%3E%3C%2FLI%3E%3C%2FUL%3E%3CHR%20%2F%3E%3CP%3E%3CSTRONG%3ERelevant%20Code%20(Simplified)%3A%3C%2FSTRONG%3E%3C%2FP%3E%3CPRE%3Eenc_el.set_property(%22extra-controls%22%2C%20Gst.Structure.new_from_string(%0A%20%20%20%20%22controls%2Cvideo_bitrate_mode%3D1%2Cvideo_gop_size%3D25%22))%0A%0Arate_el.set_property(%22max-rate%22%2C%20fps)%0A%0Ares_el.set_property(%22caps%22%2C%20Gst.Caps.from_string(%0A%20%20%20%20f%22video%2Fx-raw%2Cwidth%3D%7Bw%7D%2Cheight%3D%7Bh%7D%2Cformat%3DBGRx%22))%3C%2FPRE%3E%3CHR%20%2F%3E%3CP%3E%3CSTRONG%3EObserved%20Behavior%3A%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3EImmediately%20after%20applying%20dynamic%20update%20(especially%20bitrate%20mode%20change)%2C%20pipeline%20fails%20with%3A%3C%2FP%3E%3CPRE%3Egstvideoencoder.c%3A2506%3A%0ACan't%20copy%20metadata%20because%20input%20frame%20disappeared%0A%0Av4l2object.c%3A6524%3A%20gst_v4l2_object_poll%3A%0Apoll%20error%201%3A%20Invalid%20argument%20(22)%0A%0AGST_ERROR%3A%0ACould%20not%20read%20from%20resource.%0A%0Agstbasesrc.c%3A3187%3A%0AInternal%20data%20stream%20error.%0Astreaming%20stopped%2C%20reason%20error%20(-5)%3C%2FPRE%3E%3CP%3EThis%20results%20in%3A%3C%2FP%3E%3CUL%3E%3CLI%3E%3CP%3EEncoder%20failure%20(v4l2h264enc)%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3EQueue%20failure%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3ESource%20(v4l2src)%20stopping%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3EEntire%20pipeline%20going%20to%20error%20state%3C%2FP%3E%3C%2FLI%3E%3C%2FUL%3E%3CHR%20%2F%3E%3CP%3E%3CSTRONG%3EFull%20Error%20Logs%20(Excerpt)%3A%3C%2FSTRONG%3E%3C%2FP%3E%3CPRE%3Egst_v4l2_object_poll%3A%3CV4L2H264ENC%3E%20error%3A%20poll%20error%201%3A%20Invalid%20argument%20(22)%0Agst_element_message_full_with_details%3A%20Could%20not%20read%20from%20resource%0Agst_base_src_loop%3A%3CV4L2SRC%3E%20error%3A%20Internal%20data%20stream%20error%0Astreaming%20stopped%2C%20reason%20error%20(-5)%3C%2FV4L2SRC%3E%3C%2FV4L2H264ENC%3E%3C%2FPRE%3E%3CHR%20%2F%3E%3CP%3E%3CSTRONG%3EKey%20Observations%3A%3C%2FSTRONG%3E%3C%2FP%3E%3COL%3E%3CLI%3E%3CP%3EIssue%20is%20reproducible%20when%20changing%3A%3C%2FP%3E%3CUL%3E%3CLI%3E%3CP%3Evideo_bitrate_mode%20(CBR%20%E2%86%94%20VBR)%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3Ebitrate%3C%2FP%3E%3C%2FLI%3E%3C%2FUL%3E%3C%2FLI%3E%3CLI%3E%3CP%3ESometimes%20encoder%20accepts%20property%20but%3A%3C%2FP%3E%3CUL%3E%3CLI%3E%3CP%3Eno%20visible%20effect%20OR%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3Efails%20shortly%20after%3C%2FP%3E%3C%2FLI%3E%3C%2FUL%3E%3C%2FLI%3E%3CLI%3E%3CP%3EFPS%20changes%20using%20videorate%20work%20fine%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3EResolution%20changes%20sometimes%20work%20but%20are%20unstable%3C%2FP%3E%3C%2FLI%3E%3C%2FOL%3E%3CHR%20%2F%3E%3CP%3E%3CSTRONG%3EQuestions%3A%3C%2FSTRONG%3E%3C%2FP%3E%3COL%3E%3CLI%3E%3CP%3E%3CSTRONG%3EIs%20runtime%20update%20of%20v4l2h264enc%20controls%20supported%3F%3C%2FSTRONG%3E%3C%2FP%3E%3CUL%3E%3CLI%3E%3CP%3ESpecifically%3A%3C%2FP%3E%3CUL%3E%3CLI%3E%3CP%3Evideo_bitrate_mode%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3Evideo_bitrate%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3Evideo_gop_size%3C%2FP%3E%3C%2FLI%3E%3C%2FUL%3E%3C%2FLI%3E%3C%2FUL%3E%3C%2FLI%3E%3CLI%3E%3CP%3EAre%20these%20controls%20required%20to%20be%20set%20only%20in%3A%3C%2FP%3E%3CUL%3E%3CLI%3E%3CP%3ENULL%20%2F%20READY%20state%3F%3C%2FP%3E%3C%2FLI%3E%3C%2FUL%3E%3C%2FLI%3E%3CLI%3E%3CP%3EDoes%20the%20i.MX8MP%20VPU%20driver%20support%3A%3C%2FP%3E%3CUL%3E%3CLI%3E%3CP%3Edynamic%20bitrate%20adjustment%20in%20PLAYING%20state%3F%3C%2FP%3E%3C%2FLI%3E%3C%2FUL%3E%3C%2FLI%3E%3CLI%3E%3CP%3EFor%20resolution%20change%3A%3C%2FP%3E%3CUL%3E%3CLI%3E%3CP%3EIs%20dynamic%20caps%20renegotiation%20supported%20with%20imxvideoconvert_g2d%20%2B%20encoder%3F%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3EOr%20is%20pipeline%20restart%20required%3F%3C%2FP%3E%3C%2FLI%3E%3C%2FUL%3E%3C%2FLI%3E%3CLI%3E%3CP%3EWhat%20is%20the%20%3CSTRONG%3Erecommended%20approach%3C%2FSTRONG%3E%20for%3A%3C%2FP%3E%3CUL%3E%3CLI%3E%3CP%3Echanging%20bitrate%20mode%20(CBR%2FVBR)%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3Echanging%20resolution%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3Ein%20a%20live%20streaming%20pipeline%3F%3C%2FP%3E%3C%2FLI%3E%3C%2FUL%3E%3C%2FLI%3E%3C%2FOL%3E%3CHR%20%2F%3E%3CP%3E%3CSTRONG%3EAdditional%20Context%3A%3C%2FSTRONG%3E%3CBR%20%2F%3EIn%20commercial%20IP%20cameras%2C%20bitrate%20appears%20to%20change%20dynamically%20without%20stream%20interruption.%3CBR%20%2F%3EWe%20would%20like%20to%20understand%20whether%3A%3C%2FP%3E%3CUL%3E%3CLI%3E%3CP%3EThis%20is%20supported%20at%20driver%20level%2C%20or%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3ERequires%20encoder%20restart%20%2F%20pipeline%20rebuild.%3C%2FP%3E%3C%2FLI%3E%3C%2FUL%3E%3CHR%20%2F%3E%3CP%3E%3CSTRONG%3EExpected%20Guidance%3A%3C%2FSTRONG%3E%3C%2FP%3E%3CUL%3E%3CLI%3E%3CP%3EOfficial%20recommendation%20from%20NXP%20for%20runtime%20encoder%20reconfiguration%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3ESupported%20vs%20unsupported%20controls%20in%20PLAYING%20state%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3EBest%20practice%20for%20dynamic%20streaming%20pipelines%3C%2FP%3E%3C%2FLI%3E%3C%2FUL%3E%3CHR%20%2F%3E%3CP%3E%3CSTRONG%3ESummary%3A%3C%2FSTRONG%3E%3CBR%20%2F%3EDynamic%20updates%20to%20v4l2h264enc%20(especially%20bitrate%20mode)%20result%20in%3A%3C%2FP%3E%3CUL%3E%3CLI%3E%3CP%3EV4L2%20poll%20errors%20(EINVAL)%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3EEncoder%20failure%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3EPipeline%20crash%3C%2FP%3E%3C%2FLI%3E%3C%2FUL%3E%3CP%3EWe%20want%20to%20confirm%20whether%20this%20is%20expected%20behavior%20and%20how%20to%20correctly%20implement%20dynamic%20reconfiguration.%3C%2FP%3E%3CHR%20%2F%3E%3CP%3EThank%20you.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2333932%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CLINGO-LABEL%3Ei.MX%208%20Family%20%7C%20i.MX%208QuadMax%20(8QM)%20%7C%208QuadPlus%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Ei.MX%208M%20%7C%20i.MX%208M%20Mini%20%7C%20i.MX%208M%20Nano%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2334434%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20Title%3A%20i.MX8MP%20V4L2%20H.264%20Encoder%20Fails%20on%20Dynamic%20Runtime%20Update%20(Bitrate%20Mode%20%2F%20Resolution)%20%E2%80%94%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2334434%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EI've%20already%20mailed%20to%20you%20for%20enabling%20VBR%2C%20then%20you%20can%20control%20it%20dynamically%2C%20pls%20check%20my%20mail%3C%2FP%3E%3C%2FLINGO-BODY%3E