ffmpeg_vpp_amf_d3d11_ext

Extended vpp_amf filter with D3D11-based deinterlace and crop for ffmpeg
(github pages)

1. Overview of This Extension


2. Basic Command Examples

2-1. When the AMF decoder (-hwaccel amf) supports the codec

ffmpeg -hwaccel amf -i "input.m2ts" \
  -c:v hevc_amf \
  -vf "vpp_amf=w=1920:h=720:deint=fast:deint_frame_format=tff:format=nv12:cx=0:cy=139:cw=1920:ch=802" \
  -c:a copy -f mp4 "output.mp4"

2-2. When the AMF decoder does NOT support the codec

ffmpeg -i "input.m2ts" \
  -c:v hevc_amf \
  -vf "format=nv12, vpp_amf=w=1920:h=720:deint=fast:deint_frame_format=tff:format=nv12:cx=0:cy=139:cw=1920:ch=802" \
  -c:a copy -f mp4 "output.mp4"

3. Notes on Options (Based on AMD Radeon RX 7600 Behavior)

3-1. Hardware decoding with AMF may cause playback stutter


3-2. deint=adaptive may produce jagged frames


3-3. When AMF does not support the codec

AMF decoder support as of 2026.1:

DEFINE_AMF_DECODER(h264, H264, ...)
DEFINE_AMF_DECODER(hevc, HEVC, ...)
DEFINE_AMF_DECODER(vp9,  VP9,  ...)
DEFINE_AMF_DECODER(av1,  AV1,  ...)

3-4. Automatic per-frame detection of tff/bff/progressive


3-5. Some videos are detected as tff/bff by ffprobe but are actually progressive


4. Useful Commands for Inspecting Source Videos

4-1. Progressive / Interlaced detection

ffmpeg -i test.vob -filter:v idet -frames:v 300 -an -f null -

4-2. Check codec

ffprobe -select_streams v:0 -show_entries stream=codec_name test.vob

4-3. Crop size detection

ffmpeg -i "test.mp4" -vf cropdetect -f null -

5. Project Structure

ffmpeg_vpp_amf_d3d11_ext
+- patches
|  +- original
|  |  +- vf_amf_common.c
|  |  +- vf_amf_common.h
|  |  +- vf_vpp_amf.c
|  +- patched
|  |  +- vf_amf_common.c
|  |  +- vf_amf_common.h
|  |  +- vf_vpp_amf.c
|  +- vf_amf_common_c.patch
|  +- vf_amf_common_h.patch
|  +- vf_vpp_amf_c.patch
+- Makefile

6. Makefile Overview

6-1. Preparation

Edit the following line:

ROOT := /d/Data/ffmpeg_vpp_amf_d3d11_ext
INSTALL_TO := /d/utils/ffmpeg-self

6-2. Build

cd ffmpeg_vpp_amf_d3d11_ext
make

6-3. What the Makefile does


7. Tips

7-1. Behavior of the reset_sar option

The following code inside amf_init_filter_config() does not appear to behave as originally intended:

if (ctx->reset_sar && inlink->sample_aspect_ratio.num)
    w_adj = (double) inlink->sample_aspect_ratio.num / inlink->sample_aspect_ratio.den;

ff_scale_adjust_dimensions(inlink, &ctx->width, &ctx->height,
                           ctx->force_original_aspect_ratio, ctx->force_divisible_by, w_adj);

Regarding inlink->sample_aspect_ratio.num:

As a result, ff_scale_adjust_dimensions() is executed with w_adj left at 1.0.

This behavior appears to be unintended and is problematic for my extension. Since inlink->sample_aspect_ratio.num is rarely zero in actual frames passed to the filter, this may be due to a change in FFmpeg’s filter framework or a bug in the current version.

If this is indeed a bug, it may be fixed in a future stable release. For now, I will work around it by selecting command‑line parameters according to the specific objective.

7-2. Relationship between FFmpeg command-line parameters and the reset_sar option

Workaround notes for observed FFmpeg expression‑evaluation behavior (as of 2026‑04‑15):

The following patterns have been confirmed regarding w (width) and reset_sar. Command‑line parameters should be chosen according to these rules:

  1. w unspecified & reset_sar=false
    w is evaluated as iw; output SAR matches input SAR.

  2. w unspecified & reset_sar=true
    w is evaluated as iw; output SAR is forced to 1.
    Note: This causes distortion if the input SAR is not 1:1.

  3. w=-2 & reset_sar=false
    w is evaluated as h * dar / sar; output SAR matches input SAR.

  4. w=-2 & reset_sar=true
    w is evaluated as h * dar / sar, then scaled again by w * sar inside vpp_amf; output SAR is forced to 1.

  5. w=value/expr & reset_sar=false
    Output SAR matches input SAR. The input value should represent Display Width / SAR.

  6. w=value/expr & reset_sar=true
    Output SAR is forced to 1. The input value should be the actual Display Width.


8. Disclaimer / Support Policy


9. License

This patch follows the ffmpeg project’s license (GPL/LGPL).
Refer to the ffmpeg source tree for full license details.