Skip to content

v4l2 MMAL_PARAMETER_VIDEO_ENCODE_INLINE_HEADER param not working #2780

Closed

Description

@zoff99

MMAL_PARAMETER_VIDEO_ENCODE_INLINE_HEADER,
&ctrl_set_video_encode_param_output,
true /* Errors ignored as requires latest firmware to work */

Activity

  1. zoff99 commented on Dec 9, 2018

    @zoff99
    Author

    i am using the latest firmware (as of now 9.Dec.2018)
    i have done all 3 just now:

    apt-get update
    apt-get dist-upgrade
    rpi-update
    

    using a RPI 3B+ hardware with a picam module v2.1

    SPS/PPS are only generated at the first buffer and never again

  2. 6by9 commented on Dec 10, 2018

    @6by9
    Contributor

    More detail required as to what you've been done.

    sudo modprobe bcm2835-v4l2 debug=5
    v4l2-ctl -v width=640,height=480,pixelformat=H264
    v4l2-ctl --set-ctrl repeat_sequence_header=1
    v4l2-ctl --set-ctrl h264_i_frame_period=10
    v4l2-ctl --stream-mmap=3 --stream-count=100 --stream-to=/dev/null
    dmesg | grep length
    

    The resulting log shows

    [  726.127944] bcm2835-v4l2: buffer_cb: status:0, buf:b99ed600, length:26, flags 4132, pts 0
    [  726.145360] bcm2835-v4l2: buffer_cb: status:0, buf:b99eda00, length:7980, flags 4108, pts 730117492
    [  726.176399] bcm2835-v4l2: buffer_cb: status:0, buf:b99ec800, length:1524, flags 4100, pts 730150820
    [  726.209839] bcm2835-v4l2: buffer_cb: status:0, buf:b99ed600, length:1833, flags 4100, pts 730184147
    [  726.243890] bcm2835-v4l2: buffer_cb: status:0, buf:b99eda00, length:2580, flags 4100, pts 730217475
    [  726.276646] bcm2835-v4l2: buffer_cb: status:0, buf:b99ec800, length:4147, flags 4100, pts 730250804
    [  726.311738] bcm2835-v4l2: buffer_cb: status:0, buf:b99ed600, length:3122, flags 4100, pts 730284130
    [  726.343162] bcm2835-v4l2: buffer_cb: status:0, buf:b99eda00, length:2542, flags 4100, pts 730317458
    [  726.376453] bcm2835-v4l2: buffer_cb: status:0, buf:b99ec800, length:2274, flags 4100, pts 730350786
    [  726.409863] bcm2835-v4l2: buffer_cb: status:0, buf:b99ed600, length:2299, flags 4100, pts 730384113
    [  726.443831] bcm2835-v4l2: buffer_cb: status:0, buf:b99eda00, length:2279, flags 4100, pts 730417443
    [  726.477779] bcm2835-v4l2: buffer_cb: status:0, buf:b99ec800, length:26, flags 4132, pts 0
    [  726.478791] bcm2835-v4l2: buffer_cb: status:0, buf:b99ed600, length:11699, flags 4108, pts 730450769
    [  726.509815] bcm2835-v4l2: buffer_cb: status:0, buf:b99eda00, length:1951, flags 4100, pts 730484096
    [  726.542939] bcm2835-v4l2: buffer_cb: status:0, buf:b99ec800, length:1296, flags 4100, pts 730517424
    [  726.576216] bcm2835-v4l2: buffer_cb: status:0, buf:b99ed600, length:1083, flags 4100, pts 730550751
    [  726.609831] bcm2835-v4l2: buffer_cb: status:0, buf:b99eda00, length:2448, flags 4100, pts 730584080
    [  726.645597] bcm2835-v4l2: buffer_cb: status:0, buf:b99ec800, length:2078, flags 4100, pts 730617406
    [  726.676305] bcm2835-v4l2: buffer_cb: status:0, buf:b99ed600, length:1556, flags 4100, pts 730650735
    [  726.709637] bcm2835-v4l2: buffer_cb: status:0, buf:b99eda00, length:1218, flags 4100, pts 730684062
    [  726.742868] bcm2835-v4l2: buffer_cb: status:0, buf:b99ec800, length:1119, flags 4100, pts 730717389
    [  726.776160] bcm2835-v4l2: buffer_cb: status:0, buf:b99ed600, length:955, flags 4100, pts 730750718
    [  726.811120] bcm2835-v4l2: buffer_cb: status:0, buf:b99eda00, length:26, flags 4132, pts 0
    [  726.812158] bcm2835-v4l2: buffer_cb: status:0, buf:b99ec800, length:11538, flags 4108, pts 730784044
    [  726.843622] bcm2835-v4l2: buffer_cb: status:0, buf:b99ed600, length:1444, flags 4100, pts 730817372
    [  726.876186] bcm2835-v4l2: buffer_cb: status:0, buf:b99eda00, length:1178, flags 4100, pts 730850700
    [  726.909710] bcm2835-v4l2: buffer_cb: status:0, buf:b99ec800, length:1570, flags 4100, pts 730884027
    [  726.942941] bcm2835-v4l2: buffer_cb: status:0, buf:b99ed600, length:1514, flags 4100, pts 730917356
    [  726.977979] bcm2835-v4l2: buffer_cb: status:0, buf:b99eda00, length:1505, flags 4100, pts 730950683
    [  727.009661] bcm2835-v4l2: buffer_cb: status:0, buf:b99ec800, length:1479, flags 4100, pts 730984010
    [  727.043537] bcm2835-v4l2: buffer_cb: status:0, buf:b99ed600, length:1170, flags 4100, pts 731017340
    [  727.076150] bcm2835-v4l2: buffer_cb: status:0, buf:b99eda00, length:1163, flags 4100, pts 731050666
    [  727.109548] bcm2835-v4l2: buffer_cb: status:0, buf:b99ec800, length:1155, flags 4100, pts 731083993
    [  727.144335] bcm2835-v4l2: buffer_cb: status:0, buf:b99ed600, length:26, flags 4132, pts 0
    [  727.145322] bcm2835-v4l2: buffer_cb: status:0, buf:b99eda00, length:11443, flags 4108, pts 731117321
    [  727.176179] bcm2835-v4l2: buffer_cb: status:0, buf:b99ec800, length:1379, flags 4100, pts 731150649
    [  727.209662] bcm2835-v4l2: buffer_cb: status:0, buf:b99ed600, length:1103, flags 4100, pts 731183978
    [  727.243514] bcm2835-v4l2: buffer_cb: status:0, buf:b99eda00, length:981, flags 4100, pts 731217304
    [  727.276099] bcm2835-v4l2: buffer_cb: status:0, buf:b99ec800, length:962, flags 4100, pts 731250632
    [  727.311232] bcm2835-v4l2: buffer_cb: status:0, buf:b99ed600, length:913, flags 4100, pts 731283959
    [  727.342868] bcm2835-v4l2: buffer_cb: status:0, buf:b99eda00, length:1483, flags 4100, pts 731317287
    [  727.376205] bcm2835-v4l2: buffer_cb: status:0, buf:b99ec800, length:1556, flags 4100, pts 731350616
    [  727.409609] bcm2835-v4l2: buffer_cb: status:0, buf:b99ed600, length:1623, flags 4100, pts 731383942
    [  727.443535] bcm2835-v4l2: buffer_cb: status:0, buf:b99eda00, length:1415, flags 4100, pts 731417269
    

    flags 4132 (hex 0x1024) is MMAL_BUFFER_HEADER_FLAG_NAL_END | MMAL_BUFFER_HEADER_FLAG_CONFIG | MMAL_BUFFER_HEADER_FLAG_FRAME_END - MMAL_BUFFER_HEADER_FLAG_CONFIG denoting that it is the header bytes.
    26 bytes is the expected length for the SPS/PPS headers on H264, and the driver works around the fact that the firmware always gives it a pts of 0 and gives it a sensible timestamp.

    As root echo 0xFFFF > /sys/class/video4linux/video0/dev_debug and capture again, then dmesg | grep bytesused shows the same callbacks being made.

    Set h264_i_frame_period to 2, and modify v4l2-ctl to log the length and first few bytes of each packet and I get

    pi@raspberrypi:~/v4l-utils/utils/v4l2-ctl $ ./v4l2-ctl --stream-mmap=3 --stream-count=20 --stream-to=foo.h264
    
    Start of packet len 26 00 00 00 01 27 64
    <
    Start of packet len 7958 00 00 00 01 25 88
    K
    Start of packet len 880 00 00 00 01 21 9A
    <
    Start of packet len 26 00 00 00 01 27 64
    <
    Start of packet len 7987 00 00 00 01 25 88
    K
    Start of packet len 3480 00 00 00 01 21 9A
    <
    Start of packet len 26 00 00 00 01 27 64
    <
    Start of packet len 11034 00 00 00 01 25 88
    K
    Start of packet len 1708 00 00 00 01 21 9A
    <
    Start of packet len 26 00 00 00 01 27 64
    <
    Start of packet len 12071 00 00 00 01 25 88
    K
    Start of packet len 1325 00 00 00 01 21 9A
    <
    Start of packet len 26 00 00 00 01 27 64
    <
    Start of packet len 12006 00 00 00 01 25 88
    K
    Start of packet len 1345 00 00 00 01 21 9A
    <
    Start of packet len 26 00 00 00 01 27 64
    <
    Start of packet len 12046 00 00 00 01 25 88
    K
    Start of packet len 1421 00 00 00 01 21 9A
    <
    Start of packet len 26 00 00 00 01 27 64
    <
    Start of packet len 12085 00 00 00 01 25 88
    K
    

    Stream to a file and use ```xxd`` (or similar hex editor) to look at the bitstream and I see the same as the above.

    So from all that I'm farily happy that is working as expected. I'm running 4.14.86, but have also checked with 4.19.6. None of this has changed on 4.14 in a good few months anyway.

  3. 6by9 commented on Dec 10, 2018

    @6by9
    Contributor

    And it's absolutely nothing to do with #849. That appears to be a GStreamer bug in that particular version.

  4. zoff99 commented on Dec 10, 2018

    @zoff99
    Author

    the issue seems that i am using v4l2 syscalls in a C program and no matter what i set V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER to, the output remains the same.
    but raspivid seems to be able to do generate a correct output stream.

    we think that the option is not correctly passed down to the firmware when setting via v4l2

    v4l2-ctl shoed the parameter set correctly.

  5. zoff99 commented on Dec 10, 2018

    @zoff99
    Author

    i will give more debug info when i am near the RPI3B+ again

  6. 6by9 commented on Dec 10, 2018

    @6by9
    Contributor

    All the above debug was done with v4l2-ctl which is itself a C program using the V4L2 API. The source is at https://git.linuxtv.org/v4l-utils.git/tree/utils/v4l2-ctl

    If you are trying to enable V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER from your app, check the value afterwards using v4l2-ctl --list-ctrls. For V4L2 capture devices the settings persist after stopping streaming.

    One thought - you need to set V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER before calling STREAMON. (Looking at the code implementing this I'm not sure why that limitation is being enforced, but it's not something I really fancy fiddling with)

  7. zoff99 commented on Dec 10, 2018

    @zoff99
    Author

    i checked the value afterwards with v4l2-ctl and it was set to "1" and i also tried with "0". did not make any change.

    but let me test all the above on the PI so that i can give more info

  8. zoff99 commented on Dec 10, 2018

    @zoff99
    Author

    ohhh i set it after STREAMON. ok so will try that. thanks for the info.

  9. 6by9 commented on Dec 10, 2018

    @6by9
    Contributor

    Setting it after STREAMON should mean it applies for the next run, but not the current run.

  10. zoff99 commented on Dec 10, 2018

    @zoff99
    Author

    what does this mean in the source:

    true	/* Errors ignored as requires latest firmware to work */ 
    
  11. 6by9 commented on Dec 10, 2018

    @6by9
    Contributor

    Tracking it back, the commit text was

    Add support for V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER
    to control H264 inline headers.
    Requires firmware fix to work correctly, otherwise format
    has to be set to H264 before this parameter is set.
    

    56ffb0f - a Linux 3.12 branch change in Dec 2013!
    A lot of water has passed under the bridge so it would be reasonable to drop that requirement now, and the firmware will be returning an error should you change that setting whilst streaming.
    TBH It would make more sense for me to investigate whether we can change inline headers mode whilst streaming.

  12. zoff99 commented on Dec 10, 2018

    @zoff99
    Author

    that would help, since we did not get an error we didnt realize it

  13. zoff99 commented on Dec 10, 2018

    @zoff99
    Author

    we made a quick test now with a remote Pi3 and it seems to solve our issue.
    i will confirm later tonight to make sure.

    thanks for you help!

  14. zoff99 commented on Dec 10, 2018

    @zoff99
    Author

    ok i can confirm when setting it before STREAMON it works.
    thanks for all the tips to get debug info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions