mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2026-11-06 21:37:26 +00:00
sr1-1 and point need a packed RGB surface. Software input was handled by restricting the negotiated formats so libavfilter inserts a converter, but a hardware surface backed by NV12 or P010 could only be rejected, which made both algorithms unusable with any AMF or D3D11VA producer upstream - including every player that hands libavfilter its decoder frames. Chain an AMFVideoConverter ahead of the scaler in that case instead. The conversion stays on the GPU, so no download is introduced, and the component is driven from the shared filter_frame path through a new pre_converter field. The HQ scaler has no output format property and emits the format it was initialised with, so one packed RGB target drives the converter output format, AMFHQScaler::Init() and the output frames context alike. P010 converts to X2BGR10 and NV12 to RGBA by default; an explicit format= is kept when it names a packed RGB format and rejected otherwise. Where no conversion is needed the scaler cannot change the format at all, so an explicit format= differing from the input is rejected and the target is pinned to the input format, rather than letting the output link negotiate a frames context that disagrees with the surface the scaler produces. AMD's Video Converter programming guide has the caller poll for output and stop submitting while the component reports AMF_INPUT_FULL, so both calls are retried instead of turning a valid asynchronous state into a dropped frame or an error. The component runs synchronously on the tested device and the retry never triggers there. The converter is asked for full range output, and the converted frame is tagged AVCOL_SPC_RGB with AVCOL_RANGE_JPEG rather than inheriting the input's YUV matrix. The output frames context follows the converted format, so the filter emits packed RGB where it previously emitted NV12; with format=same this is only reachable for the two algorithms that cannot produce YUV anyway. Tested on Windows 11, RX 9070 XT, driver 32.0.31041.1004, with -hwaccel amf -hwaccel_output_format amf: point and sr1-1 measure YMIN=YAVG=YMAX=0 before this change and match the plain decode to within 0.6/255 after, while bilinear, bicubic and sr1-0 keep their NV12 output. point at 2x scores 36.5 dB PSNR against a software neighbour reference, the converted frame is tagged pc/gbr, P010 reaches X2BGR10, the accepted and rejected format= values behave as described, and 300 frames run through the converter for both algorithms. Assisted-by: Claude Opus 5 Signed-off-by: Julius Bairaktaris <julius@bairaktaris.de>