Skip to content

Enable AMF Decoder, HWContext AMF, vpp_amf filter - #7698

Closed
Hotactioncop wants to merge 2 commits into
HandBrake:masterfrom
Hotactioncop:Enable_HWContext
Closed

Hotactioncop wants to merge 2 commits into
HandBrake:masterfrom
Hotactioncop:Enable_HWContext

Conversation

@Hotactioncop

Copy link
Copy Markdown
Contributor

This PR supersedes #6475.

It continues AMF decode integration, adds support for the vpp_amf filter, and implements full HW pipeline behavior with explicit SW fallback for unsupported filters.

Benefits:

  • Optimizations for direct video memory access from CPU
  • Significant performance boost in full AMF pipelines with filters
  • Integration of GPU filters like VPP, Super Resolution, and
    Compression Artefact Removal(in future plans)
  • VCN power management control for decoders.
  • Ability to specify which VCN instance to use for decoding
    (like for encoder)

Tested on:

  • Windows 10+ (via MinGW)
  • Ubuntu Linux

Build / Run

Build with AMF decode support:

  • ./configure --enable-vce --enable-amfdec ...
  • make -j$(nproc)

Run with AMF decode enabled:

  • HandBrakeCLI --enable-hw-decoding amfdec ...

Notes

  • Full HW path is used when only HW-capable filters are present (e.g. vpp_amf crop/scale/format) or when no frame-data SW filters are required.
  • If SW-only filters are present (e.g. rotate/deblock), frames are transferred to system memory for filtering, then encoded with VCE.

@Hotactioncop
Hotactioncop marked this pull request as draft March 11, 2026 10:59
@Hotactioncop
Hotactioncop marked this pull request as ready for review March 11, 2026 11:00
@galad87

galad87 commented Mar 18, 2026

Copy link
Copy Markdown
Contributor

There is a lot of code duplication and unrelated changes that honestly I don't like. The goal should be to avoid as many HB_PROJECT_FEATURE_VCE as possible, not to add yet another custom path that is probably not needed.

If an additional feature is needed, it should be added in a general way, and not by making yet another custom gadget that will complicate the already complicated decavcodec.c.

It would be better to move the UI changes to a different commit, and the translation changes are unnecessary (they are imported from transifex.com, and adding them here won't sync to transifex).

I don't have any AMD hardware around to test it, but I'll add some comments.

Comment thread libhb/handbrake/common.h Resolved
Comment thread libhb/decavcodec.c Resolved
Comment thread libhb/decavcodec.c Resolved
Comment thread libhb/decavcodec.c Resolved
Comment thread libhb/decavcodec.c Resolved
Comment thread libhb/hbavfilter.c Resolved
Comment thread libhb/hbavfilter.c Resolved
Comment thread libhb/hwaccel.c Resolved
Comment thread libhb/work.c Resolved
Comment thread libhb/work.c Resolved
@Hotactioncop
Hotactioncop marked this pull request as draft April 9, 2026 12:50
@Hotactioncop
Hotactioncop force-pushed the Enable_HWContext branch 4 times, most recently from 07151bf to b9a49aa Compare May 5, 2026 09:58
@Hotactioncop
Hotactioncop marked this pull request as ready for review May 5, 2026 11:06
@Hotactioncop
Hotactioncop requested a review from galad87 May 5, 2026 11:07

@galad87 galad87 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The UI changes should be moved to a separate commit, and all the localizations changes should be removed because they handled on transifex.

Comment thread libhb/decavcodec.c Resolved
Comment thread libhb/hb_json.c Resolved
Comment thread libhb/hbavfilter.c Resolved
@Hotactioncop
Hotactioncop marked this pull request as draft May 13, 2026 16:17
@Hotactioncop
Hotactioncop force-pushed the Enable_HWContext branch 2 times, most recently from aaa582e to 1d0e8df Compare May 13, 2026 17:18
@Hotactioncop

Copy link
Copy Markdown
Contributor Author

The UI changes should be moved to a separate commit, and all the localizations changes should be removed because they handled on transifex.

Thanks for the review.
I split the changes into two commits and remove localization fixes.

@Hotactioncop
Hotactioncop marked this pull request as ready for review May 13, 2026 17:21

@galad87 galad87 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The full hw path needs to be tested with:

Comment thread libhb/decavcodec.c Resolved
Comment thread libhb/decavcodec.c Resolved
Comment thread libhb/decavcodec.c Resolved
Comment thread libhb/decavcodec.c Resolved
Comment thread libhb/vce_common.c Resolved
Comment thread libhb/vce_common.c Resolved
Comment thread libhb/work.c Resolved
@Hotactioncop
Hotactioncop marked this pull request as draft May 16, 2026 00:41
@Hotactioncop

Copy link
Copy Markdown
Contributor Author

The full hw path needs to be tested with:

I ran the requested tests for the AMF decoder / full HW pipeline patch.

For the BBB sunflower sample:

Tested with Align A/V Start enabled and disabled, with and without scale filter.
AMF decoder behavior matched the software decoder path.
With Align A/V enabled, the expected initial black frames were inserted for timestamp alignment.
With Align A/V disabled, the original stream timing was preserved.
Full HW pipeline worked correctly when only supported filters were present:
AMF decode -> AMF scale (by vpp_amf filter) -> AMD VCE encode.

For the multiple resolution changes sample:

Tested both at source resolution and with scale enabled.
Tested with both AMF and software decode paths.
Output video characteristics matched between AMF and software decode:
resolution changes, frame counts, sync behavior, and output geometry were identical.
No crashes, corrupted frames, or dropped frames observed.

When unsupported filters are present (for example Decomb or rotate), the pipeline correctly falls back to system memory:
AMF decode -> SW filters -> AMD VCE encode.

In the Decomb + Scale test, both filters were processed in software because vpp_amf does not appear to support Decomb.

Logs from all test runs were saved.

Comment thread libhb/scan.c
// decoder, keep it marked as supported for the encode job.
if (hwaccel != NULL && hw_device_ctx != NULL)
{
vid_info.video_decode_support |= hwaccel->id;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is already set in decavcodec.c:2449, or somewhere around.

Comment thread libhb/decavcodec.c Outdated
#include "handbrake/qsv_common.h"
#endif
#if HB_PROJECT_FEATURE_VCE
#include "handbrake/vce_common.h"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this still needed?

Comment thread libhb/hb_json.c Outdated
json_t *video = json_object_get(dict, "Video");
if (video != NULL)
{
json_t *hardware_decode = json_object_get(video, "HardwareDecode");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There is already "HWDecode" decode key, what's the use of this one?

Comment thread libhb/hbavfilter.c Outdated
#include "handbrake/hbavfilter.h"
#include "handbrake/avfilter_priv.h"
#include "handbrake/hwaccel.h"
#include "handbrake/vce_common.h"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this needed?

Comment thread libhb/decavcodec.c Outdated

do
{
if(send_packet)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please add a whitespace after the if, in all the other places too.

Comment thread libhb/work.c Outdated
#endif

#if HB_PROJECT_FEATURE_VCE
#include "handbrake/vce_common.h"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I guess this can be removed too now.

@Hotactioncop
Hotactioncop requested a review from galad87 June 3, 2026 16:16
@galad87

galad87 commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Urgh, let's do this: I'll commit the good libhb and cli parts first, and then we try to get it working in the cli. Then we'll try to WinGui changes, then maybe the LinGui because there is no maintainer at the moment.

@galad87

galad87 commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

I commited the libhb and cli parts that seemed OK to me in 99aeb91
I don't know if it actually works in the cli or not.

@Hotactioncop

Copy link
Copy Markdown
Contributor Author

Thanks @galad87.

I've tested it with HandBrakeCLI first, and then verified in the GUI on both Windows and Linux. It works as expected.

@galad87

galad87 commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Now that the basic parts are in, it would be better to open a new PR for the WinGui changes first, and another for the LinGui after.

@Hotactioncop

Copy link
Copy Markdown
Contributor Author

@galad87

Thanks,
The GUI changes have been split into separate pull requests:

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

Development

Successfully merging this pull request may close these issues.

3 participants