# ffmpeg.configure.args
#
# This file has TWO consumers with opposite encoding requirements: bash
# (scripts/build-ffmpeg.sh, via grep '^#') and PowerShell
# (scripts/verify-binary.ps1, via Get-Content). Keep it pure ASCII with NO
# byte-order mark: a BOM here breaks bash's '^#' comment-stripping match on
# line 1 (the BOM bytes land before the '#', so grep's anchor misses it and
# a garbage line leaks into the actual ./configure arguments) -- this is the
# opposite of every .ps1/.psm1 file in this project, which DOES need a BOM.
# Pure ASCII content is safe for PowerShell's Get-Content either way, so
# there is no BOM that satisfies both consumers -- just stay ASCII-only.
#
# FFmpeg 8.1.2 configure argument list for the NextNote compatibility build.
# One flag per line; blank lines and lines starting with # are stripped by
# scripts/build-ffmpeg.sh before the arguments are passed to ./configure, IN
# THE ORDER THEY APPEAR HERE. Order matters:
#   - --disable-everything must be the FIRST component-related flag: it
#     unsets the underlying *_LIST enumeration variables that individual
#     --enable-decoder=X / --enable-muxer=X / etc rely on, so any such flag
#     placed before it would be discarded.
#   - --disable-programs must precede --enable-ffmpeg for the same reason
#     (disable-programs disables the whole PROGRAM_LIST; enable-ffmpeg then
#     re-enables just the one program).
#   - --disable-autodetect is order-independent with respect to the mandatory
#     hardware-encoder flags below: FFmpeg's configure applies autodetect's
#     weak-disable pass once, after all command-line arguments are parsed,
#     and set_weak() only touches variables that are still unset -- so an
#     explicit --enable-amf/--enable-nvenc/--enable-ffnvcodec/--enable-libvpl
#     anywhere else on this list survives it. Verified against the FFmpeg
#     8.1.2 configure source, not assumed (2026-07-22).
#
# Every --enable-decoder / --enable-encoder / --enable-muxer / --enable-demuxer
# / --enable-parser / --enable-bsf / --enable-protocol / --enable-filter /
# --enable-indev value below is the exact symbol FFmpeg's configure derives
# from libavcodec/libavformat/libavfilter/libavdevice source (verified via
# find_things_extern / find_filters_extern against the actual 8.1.2 source,
# per config/required-capabilities.json). This is the FULL COMPATIBILITY
# BUILD surface (PROJECT_PLAN.md two-stage strategy, stage 1) -- minimisation
# happens in Milestone 4 after the full test matrix passes here.

# --- Determinism / meta ---
--disable-everything
--disable-autodetect
--disable-network
--disable-doc

# --- Programs: ship ffmpeg.exe only, never ffprobe/ffplay ---
--disable-programs
--enable-ffmpeg

# --- Licensing ---
# Keep the standalone FFmpeg executable under FFmpeg's default
# LGPL-2.1-or-later terms. Do not enable GPL or non-free components.

# --- Single static executable ---
--enable-static
--disable-shared
# Use pkg-config's "Libs.private" line (transitive static deps) rather than
# just "Libs" -- required so ffnvcodec/vpl's own static link
# requirements are pulled into the ffmpeg.exe link line.
--pkg-config-flags=--static
# --enable-static/--disable-shared only control FFmpeg's OWN libav* build
# type; by default MinGW still dynamically links the GCC/C++/pthread
# *runtime* (libgcc_s_seh, libstdc++, libwinpthread) as DLLs. libvpl's C++
# dispatcher pulls in libstdc++, and the resulting ffmpeg.exe crashed on a
# clean invocation with exit code -1073741515 (0xC0000135
# STATUS_DLL_NOT_FOUND) -- confirmed during Milestone 2 authoring: the first
# fully-built binary would not even run outside the MSYS2 shell that built
# it, which is exactly the "runs on a clean Windows install without MSYS2"
# exit criterion this build must meet. -static forces the linker to prefer
# the static (.a) variants of the runtime that mingw-w64-ucrt-x86_64-gcc
# ships, eliminating every non-system DLL dependency.
--extra-ldflags=-static
# --- Milestone 4 minimisation: link-time dead-code elimination ---
# --disable-everything already means there is essentially nothing left to
# remove from the *enabled component* list itself (every enabled encoder/
# decoder/muxer/demuxer/parser/bsf/protocol/filter traces directly to a
# NextNote invocation or a documented transitive dependency in
# required-capabilities.json -- audited 2026-07-22, nothing found to cut).
# The remaining lever is link-time: -ffunction-sections/-fdata-sections
# (applied to FFmpeg's own compile here, and to libvpl's compile in
# build-dependencies.sh) puts each function/data object in its own linker
# section; -Wl,--gc-sections then lets the linker discard any that ended up
# unreferenced -- most relevant for the statically-linked libvpl
# archives, which are pulled in whole otherwise even though only specific
# entry points are used. --extra-cflags/--extra-ldflags both ACCUMULATE
# across repeated occurrences in FFmpeg's configure (add_cflags/add_ldflags
# both use append(), confirmed against source, not assumed) -- safe to add
# here independently of build-ffmpeg.sh's own --extra-cflags=-I<amf-headers>.
--extra-cflags=-ffunction-sections -fdata-sections
--extra-ldflags=-Wl,--gc-sections

# --- Core libraries: avutil/avcodec/avformat/avfilter/avdevice/swscale stay
#     enabled (FFmpeg's default); swresample (audio resampling) is unused --
#     every NextNote encode uses -an, and there is no audio decode path.
--disable-swresample

# --- Threading: match the currently-shipping Gyan 8.1 build's proven choice
#     (its own -buildconf shows --disable-w32threads), which forces the
#     pthreads detection path. MSYS2's UCRT64 GCC provides a full winpthreads
#     implementation, so pthreads works natively on Windows through it.
--disable-w32threads

# --- Hardware H.264 encoders ---
# LiveView requires a supported NVIDIA, AMD, or Intel hardware encoder.
# There is deliberately no GPL software encoder fallback.
--enable-amf
--enable-nvenc
--enable-ffnvcodec
--enable-libvpl

# --- Windows hardware H.264 decode ---
# D3D11VA is the vendor-neutral Windows decode path. It can use Intel, NVIDIA,
# or AMD hardware through the installed display driver, so the Display does
# not need vendor-specific QSV/NVDEC/AMF decoder selection. Both H.264 bridge
# implementations are explicit because --disable-everything clears the whole
# HWACCEL_LIST before individual components are re-enabled.
--enable-d3d11va
--enable-hwaccel=h264_d3d11va
--enable-hwaccel=h264_d3d11va2

# --- Input devices ---
--enable-indev=gdigrab
--enable-indev=lavfi

# --- Demuxers / muxers ---
--enable-demuxer=h264
--enable-muxer=h264
--enable-muxer=rawvideo
--enable-muxer=null

# --- Decoders ---
# bmp and wrapped_avframe are auto-selected by gdigrab/lavfi respectively
# (configure: gdigrab_indev_select="bmp_decoder"; lavfi wraps frames as
# wrapped_avframe packets) but are listed explicitly per the plan's
# "explicitly enable what's required" policy -- do not rely on auto-select.
--enable-decoder=h264
--enable-decoder=bmp
--enable-decoder=wrapped_avframe

# --- Encoders ---
--enable-encoder=h264_amf
--enable-encoder=h264_nvenc
--enable-encoder=h264_qsv
# rawvideo is a distinct encoder (ff_rawvideo_encoder) from the rawvideo
# MUXER already enabled above -- Display's decode command writes -f rawvideo
# -pix_fmt bgra pipe:1, and that output still goes through avcodec's encode
# API via this passthrough codec even though there is no real encoding
# happening. Without it: "Error selecting an encoder ... Encoder not found."
# Found via the decode smoke test during Milestone 2 authoring (2026-07-22).
--enable-encoder=rawvideo

# --- Parser ---
--enable-parser=h264

# --- Bitstream filters ---
# Configure's component name (derived from the C symbol) differs from the
# runtime -bsf:v name for dump_extra -- see config/required-capabilities.json
# "configureNameMapping". Symbol ff_dump_extradata_bsf -> configure name
# "dump_extradata"; the filter's own .p.name (the string NextNote's -bsf:v
# argument uses) is "dump_extra".
--enable-bsf=dump_extradata
--enable-bsf=filter_units
# h264_metadata is never invoked by NextNote and adds no runtime capability
# on its own -- it exists here purely to compile in cbs_h264 (FFmpeg's
# H.264 Coded Bitstream unit), which filter_units's .p.codec_ids
# (ff_cbs_all_codec_ids) needs to recognise "h264" at all. Without it,
# filter_units fails at runtime with "Codec 'h264' (27) is not supported by
# the bitstream filter 'filter_units'" even though filter_units itself is
# enabled. cbs_h264 is FFmpeg's own CONFIG_EXTRA ("options emitted with
# CONFIG_ prefix but not available on the command line" per configure's own
# comment) -- it cannot be enabled directly and must be pulled in
# transitively; h264_metadata_bsf_select="cbs_h264" is the option with the
# smallest footprint among the handful that select it (the others are
# VAAPI/Vulkan/D3D12 hwaccel encoders NextNote does not use). Verified
# directly against FFmpeg 8.1.2 configure/filter_units.c source and this
# build's own failure during Milestone 2 authoring (2026-07-22).
--enable-bsf=h264_metadata

# --- Protocols ---
--enable-protocol=pipe
--enable-protocol=file

# --- Filters ---
# buffer/buffersink are NOT optional: fftools/ffmpeg_filter.c calls
# avfilter_get_by_name("buffer") and avfilter_get_by_name("buffersink")
# unconditionally to build the CLI's own filtergraph plumbing -- the ffmpeg
# binary cannot process any video without them, verified against 8.1.2
# fftools source (2026-07-22). This corrects an M0 assumption that a "null"
# filter was auto-inserted into every filtergraph; no such call exists in
# fftools, and NextNote never issues -vf null, so it has been removed.
--enable-filter=buffer
--enable-filter=buffersink
--enable-filter=color
--enable-filter=drawbox
--enable-filter=format
--enable-filter=scale
