20

va: Implement vah264enc (!1051) · Merge requests · GStreamer / gstreamer · GitLa...

 2 years ago
source link: https://gitlab.freedesktop.org//gstreamer/gstreamer/-/merge_requests/1051
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Created 2 months ago by

va: Implement vah264enc

Members who can merge are allowed to add commits.
Detached merge request pipeline #445160 waiting for manual action for c1dd475a
Approval is optional
Merge blocked: the source branch must be rebased onto the target branch.

Deletes the source branch

  • Resolved by He Junyan 2 months ago

    He Junyan - @He_Junyan wrote here on 07, Sep 2021:

    changed title from WIP: Implement the VA r h264 Encoder. to WIP: Implement the VA h264 Encoder.

Please register or sign in to reply
Resolved by He Junyan 2 months ago

Nicolas Dufresne - @ndufresne wrote here on 07, Sep 2021:

This is just one random comment, didn't took the time to review yet. This bit-writer seems to return a freshly allocated byte buffer, which defeats our attempt to avoid run-time allocation. Can we think of a way to write this into a pre-allocated and pooled block ? Of course that makes the API a tad more complex, in the case the block was too small, but I think it would be a nice feature.

Last reply by He Junyan 2 months ago
Resolved by He Junyan 2 months ago

Víctor Manuel Jáquez Leal - @vjaquez wrote here on 07, Sep 2021:

Perhaps its only me, but I would avoid a base class for now, to avoid premature optimizations. All in a single element, and later decouple as needed.

Please register or sign in to reply
Resolved by He Junyan 2 months ago

He Junyan - @He_Junyan wrote here on 07, Sep 2021:

OK. I just want the base class to handle all misc thing, such as caps setting and multi-threading sync, and let the sub class implement


  gboolean (*reconfigure)    (GstVaBaseEnc * encoder);
  gboolean (*push_frame)     (GstVaBaseEnc * encoder,
                              GstVaEncFrame * frame,
                              gboolean last);
  gboolean (*pop_frame)      (GstVaBaseEnc * encoder,
                              GstVaEncFrame ** out_frame);
  gboolean (*encode_frame)   (GstVaBaseEnc * encoder,
                              GstVaEncFrame * frame);

to handle the real encoding.

It OK to mix them all as one for the first encoder, and split them when we write the second one.

Please register or sign in to reply
Resolved by He Junyan 2 months ago

Nicolas Dufresne - @ndufresne wrote here on 07, Sep 2021:

When I saw "baseclass", I thought of a proper libgstcodecs base class. I would rather consider that stateless encoder will use a base class from libgstcodecs and experiement with that.

Even though simpler, we still need to have something like a DPB, and we might need some tree structure for more advance coding patterns. Bit writers are helper seems fair though, but they could be in the per codec base classes to reduce the boiler plate code.

@sree also would like us to support software bitrate control, even for VA. His lib will likely never provide rate control for anything other then VP9 and AV1 though, so we'd probably also need some in-gstreamer "fallback" implementation, so it minimally works. Of course, most VA driver have their own, as VA API allow that.

Please register or sign in to reply
Resolved by He Junyan 2 months ago

He Junyan - @He_Junyan wrote here on 08, Sep 2021:

I think the problem in current stage is that we do not know what is the common logic for all encoders. Different encoders have different preference and limitation. And I agree with @vjaquez , firstly, write a lean and logic clean encoder, and move the common logic to some base iterative if we find.

About the rate control, I think we can provide a lib to analyse the relationship between the buffer fullness and the incoming frames, decide its init QP and other parameters. We can even write some lookahead element to do the better analysis, and link it before the encoder.

These are big pictures and it needs a lot of effort:). I firstly need to implement a VA encoder in good code logic and with median compression quality(Just depending on HW rate control).

Please register or sign in to reply
Resolved by He Junyan 2 months ago

Nicolas Dufresne - @ndufresne wrote here on 08, Sep 2021:

Well, remember that we found impossible to extract the logic from the VA code in GStreamer VA-API.

Last reply by He Junyan 2 months ago
Resolved by He Junyan 2 months ago

He Junyan - @He_Junyan wrote here on 09, Sep 2021:

added 1 commit

  • 24b59434 - Add the encoder and va base encoder for h264

Compare with previous version

Please register or sign in to reply
Resolved by He Junyan 2 months ago

He Junyan - @He_Junyan wrote here on 14, Sep 2021:

added 30 commits

  • 24b59434...364a2fe0 - 28 commits from branch gstreamer:master
  • 461cfe6c - Add a generic bit code writer for H264.
  • 785b8226 - Add the encoder and va base encoder for h264

Compare with previous version

Please register or sign in to reply
Resolved by He Junyan 2 months ago

Víctor Manuel Jáquez Leal - @vjaquez wrote here on 16, Sep 2021:

btw, my original idea is to have low power entrypoint as different elements. So in the end will have vah264enc and vah264lpenc and the different devices, vaD129h264lpenc :smiley:

In that way, iiuc, the logic will be simpler and the user will be in control of what they want.

Still the source will be the same for all of them, just a bool in the class structure.

Last reply by He Junyan 2 months ago
Resolved by He Junyan 2 months ago

Víctor Manuel Jáquez Leal - @vjaquez wrote here on 16, Sep 2021:

If I understand correctly many of these properties are driver-dependent, so they should be autogenerated as GstVaFilter does for vapostproc and vadeinterlace.

Last reply by He Junyan 2 months ago
Resolved by He Junyan 2 months ago

U. Artie Eoff - @ullysses.a.eoff wrote here on 16, Sep 2021:

It would be nice if we could synergize the property names between the various hw plugin elements (e.g. va, vaapi, and msdk plugins).

Currently:

  • b-frames is used here and msdkh264enc but max-bframes is used in vaapih264enc.
  • keyframe-period is used here and vaapih264enc but gop-size is used in msdkh264enc.
  • ref-frames is used here and msdkh264enc but refs is used in vaapih264enc.

... there are other properties that have different names but the same function, too.

If we used the same property names across plugins, then it would make it a whole lot easier for users to remember. And way easier to write boilerplate scripts for testing the various plugins. At minimum, can we synergize property names between va and msdk?

Last reply by He Junyan 2 months ago
Resolved by He Junyan 2 months ago

He Junyan - @He_Junyan wrote here on 18, Sep 2021:

mentioned in merge request !886 (merged)

Please register or sign in to reply
Resolved by He Junyan 2 months ago

He Junyan - @He_Junyan wrote here on 04, Oct 2021:

added 57 commits

  • 785b8226...ca8068c6 - 49 commits from branch gstreamer:master
  • 9144f3f1 - codecparsers: nalutils: Add nal_writer_reset_and_get_data help function.
  • aaaa458c - codecparsers: bitwriter: Add the common bit writer functions for H264.
  • d56a817a - test: Add test cases for the H264 bitwriter.
  • c4f165fa - va: Make the gst_va_create_coded_caps as a common helper function.
  • 2ac07697 - va: encoder: Add a common encoder object.
  • 9e1cbf06 - va: encoder: Import the H264 encoder.
  • 26807ae8 - va: enable the H264 encoder.
  • a0bfff0f - va: Change the H264 profile string order in the profile_map.

Compare with previous version

Please register or sign in to reply
Resolved by He Junyan 2 months ago

He Junyan - @He_Junyan wrote here on 04, Oct 2021:

marked this merge request as ready

Please register or sign in to reply
Resolved by He Junyan 2 months ago

He Junyan - @He_Junyan wrote here on 04, Oct 2021:

@vjaquez I am a little sorry, I make that H264 encoder not so simple and added most of the properties in vaapi. Because I need to measure the performance of it and compare the BD-rate with other encoders:)

Please register or sign in to reply
Resolved by He Junyan 2 months ago

He Junyan - @He_Junyan wrote here on 04, Oct 2021:

I will try to do it, thanks for your notify.

Please register or sign in to reply
Resolved by He Junyan 2 months ago

He Junyan - @He_Junyan wrote here on 04, Oct 2021:

mentioned in merge request !1047 (closed)

Please register or sign in to reply
Resolved by He Junyan 2 months ago
[91/1018] Compiling C object subprojects/gst-plugins-bad/gst-libs/gst/codecparsers/libgstcodecparsers-1.0.so.0.1902.0.p/gsth264bitwriter.c.o                                                                       
../subprojects/gst-plugins-bad/gst-libs/gst/codecparsers/gsth264bitwriter.c:570:3: warning: result of comparison of constant -12 with expression of type 'const guint8' (aka 'const unsigned char') is always false
 [-Wtautological-constant-out-of-range-compare]                                                                                                                                                                    
  WRITE_SE_RANGE (bw, pps->second_chroma_qp_index_offset, -12, 12);                                                                                                                                                
  ^                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  ~~~                                                                                                                                                      
../subprojects/gst-plugins-bad/gst-libs/gst/codecparsers/gsth264bitwriter.c:84:24: note: expanded from macro 'WRITE_SE_RANGE'                                                                                      
  if (val > max || val < min ||                                               \                                                                                                                                    
                   ~~~ ^ ~~~                                                                                                                                                                                       
1 warning generated.                  
Last reply by He Junyan 2 months ago
Resolved by He Junyan 2 months ago
../subprojects/gst-plugins-bad/sys/va/gstvah264enc.c:1557:30: warning: field 'type' with variable sized type 'VAEncMiscParameterBuffer' (aka 'struct _VAEncMiscParameterBuffer') not at the end of a struct or class is a GNU extension [-Wgnu-variable-sized-type-not-at-end]
    VAEncMiscParameterBuffer type;
                             ^
../subprojects/gst-plugins-bad/sys/va/gstvah264enc.c:1595:30: warning: field 'type' with variable sized type 'VAEncMiscParameterBuffer' (aka 'struct _VAEncMiscParameterBuffer') not at the end of a struct or class is a GNU extension [-Wgnu-variable-sized-type-not-at-end]
    VAEncMiscParameterBuffer type;
                             ^
../subprojects/gst-plugins-bad/sys/va/gstvah264enc.c:1627:30: warning: field 'type' with variable sized type 'VAEncMiscParameterBuffer' (aka 'struct _VAEncMiscParameterBuffer') not at the end of a struct or class is a GNU extension [-Wgnu-variable-sized-type-not-at-end]
    VAEncMiscParameterBuffer type;
                             ^
../subprojects/gst-plugins-bad/sys/va/gstvah264enc.c:1653:30: warning: field 'type' with variable sized type 'VAEncMiscParameterBuffer' (aka 'struct _VAEncMiscParameterBuffer') not at the end of a struct or class is a GNU extension [-Wgnu-variable-sized-type-not-at-end]
    VAEncMiscParameterBuffer type;
                             ^
../subprojects/gst-plugins-bad/sys/va/gstvah264enc.c:1683:30: warning: field 'type' with variable sized type 'VAEncMiscParameterBuffer' (aka 'struct _VAEncMiscParameterBuffer') not at the end of a struct or class is a GNU extension [-Wgnu-variable-sized-type-not-at-end]
    VAEncMiscParameterBuffer type;
  • 163e1ed9...d189b0d0 - 31 commits from branch gstreamer:main
  • d91f8336 - codecparsers: nalutils: Add nal_writer_reset_and_get_data help function.
  • b20626c1 - codecparsers: bitwriter: Add the common bit writer functions for H264.
  • f9d839fd - test: Add test cases for the H264 bitwriter.
  • e33589ab - va: Make the gst_va_create_coded_caps as a common helper function.
  • b25ef5b9 - va: encoder: Add a common encoder object.
  • a22b1d1e - va: encoder: Import the H264 encoder.
  • dcfc2df0 - va: enable the H264 encoder.
  • 64f10722 - va: Change the H264 profile string order in the profile_map.

Compare with previous version

Toggle commit list

Great job @He_Junyan !

I just pushed a branch in my repo with a couple style change proposals: https://gitlab.freedesktop.org/vjaquez/gstreamer/-/commits/mr-1051

The missing bit I see is downstream negotiation.

Resolved by Seungha Yang 1 month ago

fwiw, I just started reading Direct3D12 video encoding APIs (part of Windows 11 SDK) and got an impression that overall flow is very similar to that of VA encoding

Last reply by Seungha Yang 1 month ago
Víctor Manuel Jáquez Leal @vjaquez changed title from gst-plugins-bad: Implement the VA h264 Encoder. to va: Implement vah264enc 1 month ago

I would like to merge this in the next development cycle (for 1.21)

  • 64f10722...7cb2dff8 - 210 commits from branch gstreamer:main
  • 790af46d - codecparsers: nalutils: Add nal_writer_reset_and_get_data help function.
  • 63cbb27e - codecparsers: bitwriter: Add the common bit writer functions for H264.
  • 84717a01 - test: Add test cases for the H264 bitwriter.
  • e92a509b - va: Make the gst_va_create_coded_caps as a common helper function.
  • 59790cd4 - va: encoder: Add a common encoder object.
  • b095e895 - va: encoder: Import the H264 encoder.
  • 17cd1c22 - va: enable the H264 encoder.
  • d8170586 - va: Change the H264 profile string order in the profile_map.

Compare with previous version

Toggle commit list
  • d8170586...8c35850f - 35 commits from branch gstreamer:main
  • 92300a3e - codecparsers: nalutils: Add nal_writer_reset_and_get_data help function.
  • c9227f89 - codecparsers: bitwriter: Add the common bit writer functions for H264.
  • 3719487a - test: Add test cases for the H264 bitwriter.
  • 426e9443 - va: Make the gst_va_create_coded_caps as a common helper function.
  • 558d313e - va: Change the H264 profile string order in the profile_map.
  • a8894ad9 - va: Add the profile string name into the profile_map.
  • 5c7117da - va: encoder: Add a common encoder object.
  • b696eb2c - va: encoder: Import the H264 encoder.
  • b2903780 - va: enable the H264 encoder.

Compare with previous version

Toggle commit list
  • 2bd7aea7 - vah264enc: Style changes proposal
  • 61ce0e44 - va: encoder: Specify the buffer type in signatures.

Compare with previous version

  • 9b27e3ba - vah264enc: Style changes proposal
  • 2ff6a3ca - va: encoder: Specify the buffer type in signatures.
  • d270d983 - va: caps: Conform with gst-indent.

Compare with previous version

  • cc97041b...cfbd8201 - 12 commits from branch gstreamer:main
  • 37ed170e - codecparsers: nalutils: Add nal_writer_reset_and_get_data help function.
  • 9246b54e - codecparsers: bitwriter: Add the common bit writer functions for H264.
  • afa45042 - test: Add test cases for the H264 bitwriter.
  • 23898e8b - va: caps: Make the gst_va_create_coded_caps as a common helper function.
  • 22ebb097 - va: Change the H264 profile string order in the profile_map.
  • 12c97b79 - va: Add the profile string name into the profile_map.
  • f0c3940b - va: encoder: Add a common encoder object.
  • 9f79a49b - va: encoder: Import the H264 encoder.
  • 67e85251 - va: enable the H264 encoder.

Compare with previous version

Toggle commit list
  • 67e85251...1e6d26ac - 27 commits from branch gstreamer:main
  • a19339e5 - codecparsers: nalutils: Add nal_writer_reset_and_get_data help function.
  • 1bedc18d - codecparsers: bitwriter: Add the common bit writer functions for H264.
  • b97f6e10 - test: Add test cases for the H264 bitwriter.
  • 2c6a3269 - va: caps: Make the gst_va_create_coded_caps as a common helper function.
  • 50099714 - va: Change the H264 profile string order in the profile_map.
  • ee73a780 - va: Add the profile string name into the profile_map.
  • a989101a - va: encoder: Add a common encoder object.
  • 7104a257 - va: encoder: Import the H264 encoder.
  • 94c2869e - va: enable the H264 encoder.

Compare with previous version

Toggle commit list
  • 94c2869e...d6923936 - 52 commits from branch gstreamer:main
  • 72b2d7e9 - codecparsers: nalutils: Add nal_writer_reset_and_get_data help function.
  • a01a6e07 - codecparsers: bitwriter: Add the common bit writer functions for H264.
  • 2a22e6ba - test: Add test cases for the H264 bitwriter.
  • b094285d - va: caps: Make the gst_va_create_coded_caps as a common helper function.
  • f41302a1 - va: Change the H264 profile string order in the profile_map.
  • 9a4911ac - va: Add the profile string name into the profile_map.
  • 9b6a1f24 - va: encoder: Add a common encoder object.
  • 73f0cc67 - va: encoder: Import the H264 encoder.
  • 30e51bd3 - va: enable the H264 encoder.

Compare with previous version

Toggle commit list
  • 30e51bd3...214691b9 - 30 commits from branch gstreamer:main
  • e496df70 - codecparsers: nalutils: Add nal_writer_reset_and_get_data help function.
  • 3d3b36a2 - codecparsers: bitwriter: Add the common bit writer functions for H264.
  • 2511da02 - test: Add test cases for the H264 bitwriter.
  • 78e7db90 - va: caps: Make the gst_va_create_coded_caps as a common helper function.
  • 06e4f468 - va: Change the H264 profile string order in the profile_map.
  • ec262eab - va: Add the profile string name into the profile_map.
  • 6585b38c - va: encoder: Add a common encoder object.
  • 4b35f7fa - va: encoder: Import the H264 encoder.
  • a406910f - va: enable the H264 encoder.

Compare with previous version

Toggle commit list
  • a406910f...972615cf - 28 commits from branch gstreamer:main
  • 735c0d25 - codecparsers: nalutils: Add nal_writer_reset_and_get_data help function.
  • 15d01dc1 - codecparsers: bitwriter: Add the common bit writer functions for H264.
  • 7446cc23 - test: Add test cases for the H264 bitwriter.
  • fc1f6b0e - va: caps: Make the gst_va_create_coded_caps as a common helper function.
  • 5d3fe98f - va: Change the H264 profile string order in the profile_map.
  • e0ff8268 - va: Add the profile string name into the profile_map.
  • 65d9c6b9 - va: encoder: Add a common encoder object.
  • 1b730b32 - va: encoder: Import the H264 encoder.
  • c1dd475a - va: enable the H264 encoder.

Compare with previous version

Toggle commit list
Please register or sign in to reply
0 Assignees
0 Reviewers
Milestone
Time tracking
Lock merge request
Unlocked
participants
Reference:

Source branch: gst-plugins-bad-encoder_h264


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK