Files
facefusion/tests/test_ffmpeg_builder.py
T
b60ea40d26 3.8.0 (#1212)
* mark as next

* unify the dependency checks in pre_check and add ffprobe (#1181)

* drop keep_temp and the common options component (#1180)

Claude-Session: https://claude.ai/code/session_01Tbcd6VWCiU4BQP1gywPr2a

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>

* introduce ffprobe and ffprobe_builder (#1182)

* introduce ffprobe and ffprobe_builder

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tbcd6VWCiU4BQP1gywPr2a

* introduce ffprobe and ffprobe_builder

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tbcd6VWCiU4BQP1gywPr2a

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>

* probe video metadata via ffprobe in vision (#1184)

* probe video metadata via ffprobe in vision

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tbcd6VWCiU4BQP1gywPr2a

* probe video metadata via ffprobe in vision

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tbcd6VWCiU4BQP1gywPr2a

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>

* adopt the workflow task vocabulary from next major (#1185)

Claude-Session: https://claude.ai/code/session_01Tbcd6VWCiU4BQP1gywPr2a

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>

* introduce workflow-mode and workflow-strategy like next major (#1187)

Claude-Session: https://claude.ai/code/session_01Tbcd6VWCiU4BQP1gywPr2a

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>

* restrict hdr color transfer and tag the merge output as bt709 (#1188)

* restrict hdr color transfer and tag the merge output as bt709

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tbcd6VWCiU4BQP1gywPr2a

* restrict hdr color transfer and tag the merge output as bt709

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tbcd6VWCiU4BQP1gywPr2a

* full video migration

* compose the hdr fixture via the builder chain

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tbcd6VWCiU4BQP1gywPr2a

* compose the test fixtures via the builder and run_ffmpeg

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tbcd6VWCiU4BQP1gywPr2a

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>

* compose every test fixture via the builder and run_ffmpeg (#1189)

* compose every test fixture via the builder and run_ffmpeg

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tbcd6VWCiU4BQP1gywPr2a

* use loops in tests for ffmpeg stuff

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>

* New Video Manager (#1191)

* tiny adjustment for tests

* address the review on the video manager

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tbcd6VWCiU4BQP1gywPr2a

* introduce the stream strategy for the video workflow (#1192)

* introduce the stream strategy for the video workflow

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tbcd6VWCiU4BQP1gywPr2a

* address the review on the stream strategy

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tbcd6VWCiU4BQP1gywPr2a

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>

* annotate the changes for review

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tbcd6VWCiU4BQP1gywPr2a

* annotate the new tests for review

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tbcd6VWCiU4BQP1gywPr2a

* match the temp pixel format help to the locale style

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tbcd6VWCiU4BQP1gywPr2a

* question the set_input_seek naming

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tbcd6VWCiU4BQP1gywPr2a

* question the reader and writer keys

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tbcd6VWCiU4BQP1gywPr2a

* drop the review annotations from the encoder mapping tests

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tbcd6VWCiU4BQP1gywPr2a

* drop the review annotations from the thread count tests

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tbcd6VWCiU4BQP1gywPr2a

* drop the review annotations from the ui files

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tbcd6VWCiU4BQP1gywPr2a

* capture the open review questions as annotations

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tbcd6VWCiU4BQP1gywPr2a

* drop the settled annotations from the types

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tbcd6VWCiU4BQP1gywPr2a

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>

* switch to ffmpeg.style for audio.py

* remove todos that were never needed

* fix for ffmpeg7

* Add frame_store module (#1194)

* add frame_store module

* rename and change tests

* rename and update tests

* route window read through frame_store (#1196)

* route window read through frame_store

* update proper id

* restore todos

* restore todos

* go v4 style for workflow (#1197)

* go v4 style for workflow

* remove some todos

* route chunk read through frame_store (#1198)

* vision integration

* Deleted read_video_chunk + read_static_video_chunk

* margin decouple (#1199)

* fix windows CI fail (#1200)

* Cleanup Part1 (#1201)

* remove some todos, improve video manager, simplify ffmpeg commands and more

* do more

* remove thread count for filters

* Cleanup Part 2 (#1202)

* tons of renaming

* tons of renaming

* multi reader approach

* bring tests to an okay-ish state

* bring drain back

* improve read_video_frame speed

* rename method

* move variables

* seek video reader only when trim frame start is larger 0

* make stream the default

* Cleanup/part 3 (#1203)

* remove todo

* sort out workflow, to match upcoming v4

* remove look ahead

* remove core namespace again

* Revamp execution provider overrides/adjustments (#1206)

* Split provider hooks into override/adjust with cached CoreML base

Replace the single resolve_inference_providers processor hook with two:
override_inference_providers (full replacement) and adjust_inference_providers
(merge options onto the base providers built by create_inference_providers).
This lets CoreML processors inherit ModelCacheDirectory + SpecializationStrategy
from the base while layering ModelFormat/MLComputeUnits on top.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HTQCZiYjJyUX11bDpbRSiB

* fix caching for execution provider by having override and adjust ways

* fix caching for execution provider by having override and adjust ways

* fix lint

* use proper pytest fixtures

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix update preview bug (#1205)

* fix update preview bug

* fix update preview bug

* remove guard

* add is_vision_frame

* Restrict the preview frame slider and the reader seek to the last frame index (#1207)

* fix index bug

* fix rounding bug

* avoid tobytes copy (#1208)

* beautify tests

* hide ffmpeg warnings

* simplify process_stream_frame

* Use is vision frame everywhere (#1210)

* use is_vision_frame everywhere

* fix hash

* fix lint

* fix hash creation in face store

* that model does not exist

* update workflow ffmpeg

* guard workflow (#1211)

* bump version and dependencies

* Update preview

* switch workflow strategy to disk|memory

* update preview

* update preview

* fix wording

* last minute change workflow position

* adjust wording

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: Harisreedhar <46858047+harisreedhar@users.noreply.github.com>
Co-authored-by: harisreedhar <h4harisreedhar.s.s@gmail.com>
2026-07-30 22:25:09 +02:00

155 lines
7.2 KiB
Python

from shutil import which
from facefusion import ffmpeg_builder
from facefusion.ffmpeg_builder import chain, concat, convert_color_space, keep_video_alpha, restrict_color_transfer, run, seek_to, select_frame_range, set_audio_quality, set_audio_sample_size, set_faststart, set_output_format, set_stream_mode, set_thread_count, set_video_encoder, set_video_fps, set_video_quality, set_video_tag
def test_run() -> None:
assert run([]) == [ which('ffmpeg'), '-loglevel', 'error' ]
def test_chain() -> None:
assert chain(
ffmpeg_builder.set_input('input.mp4'),
ffmpeg_builder.set_output('output.mp4')
) == [ '-i', 'input.mp4', 'output.mp4' ]
assert chain(
ffmpeg_builder.set_video_encoder('libx264'),
ffmpeg_builder.set_video_fps(30),
ffmpeg_builder.set_audio_encoder('aac')
) == [ '-c:v', 'libx264', '-vf', 'fps=30', '-c:a', 'aac' ]
def test_concat() -> None:
assert concat(
set_video_encoder('libvpx-vp9'),
set_video_fps(30)
) == [ '-c:v', 'libvpx-vp9', '-vf', 'fps=30' ]
assert concat(
set_video_encoder('libvpx-vp9'),
set_video_fps(30),
keep_video_alpha('libvpx-vp9')
) == [ '-c:v', 'libvpx-vp9', '-vf', 'fps=30,format=yuva420p' ]
assert concat(
select_frame_range(0, 100, 30),
keep_video_alpha('libvpx-vp9')
) == [ '-vf', 'trim=start_frame=0:end_frame=100,fps=30,format=yuva420p' ]
def test_set_stream_mode() -> None:
assert set_stream_mode('udp') == [ '-f', 'mpegts' ]
assert set_stream_mode('v4l2') == [ '-f', 'v4l2' ]
def test_seek_to() -> None:
assert seek_to(0.0) == [ '-ss', '0.0' ]
assert seek_to(1.5) == [ '-ss', '1.5' ]
def test_set_output_format() -> None:
assert set_output_format('rawvideo') == [ '-f', 'rawvideo' ]
def test_select_frame_range() -> None:
assert select_frame_range(0, None, 30) == [ '-vf', 'trim=start_frame=0,fps=30' ]
assert select_frame_range(None, 100, 30) == [ '-vf', 'trim=end_frame=100,fps=30' ]
assert select_frame_range(0, 100, 30) == [ '-vf', 'trim=start_frame=0:end_frame=100,fps=30' ]
assert select_frame_range(None, None, 30) == [ '-vf', 'fps=30' ]
def test_restrict_color_transfer() -> None:
assert restrict_color_transfer('smpte2084') == [ '-vf', 'scale=out_primaries=bt709:out_transfer=bt709:intent=perceptual' ]
assert restrict_color_transfer('arib-std-b67') == [ '-vf', 'scale=out_primaries=bt709:out_transfer=bt709:intent=perceptual' ]
assert restrict_color_transfer('invalid') == []
def test_convert_color_space() -> None:
assert convert_color_space('bt601') == [ '-vf', 'scale=out_color_matrix=bt601:out_range=tv,setparams=colorspace=bt601:color_primaries=bt601:color_trc=bt601' ]
assert convert_color_space('bt709') == [ '-vf', 'scale=out_color_matrix=bt709:out_range=tv,setparams=colorspace=bt709:color_primaries=bt709:color_trc=bt709' ]
assert convert_color_space('bt2020') == [ '-vf', 'scale=out_color_matrix=bt2020:out_range=tv,setparams=colorspace=bt2020:color_primaries=bt2020:color_trc=bt2020' ]
def test_set_audio_sample_size() -> None:
assert set_audio_sample_size(16) == [ '-f', 's16le' ]
assert set_audio_sample_size(32) == [ '-f', 's32le' ]
def test_set_audio_quality() -> None:
assert set_audio_quality('aac', 0) == [ '-q:a', '0.1' ]
assert set_audio_quality('aac', 50) == [ '-q:a', '1.0' ]
assert set_audio_quality('aac', 100) == [ '-q:a', '2.0' ]
assert set_audio_quality('libmp3lame', 0) == [ '-q:a', '9' ]
assert set_audio_quality('libmp3lame', 50) == [ '-q:a', '4' ]
assert set_audio_quality('libmp3lame', 100) == [ '-q:a', '0' ]
assert set_audio_quality('libopus', 0) == [ '-b:a', '64k' ]
assert set_audio_quality('libopus', 50) == [ '-b:a', '160k' ]
assert set_audio_quality('libopus', 100) == [ '-b:a', '256k' ]
assert set_audio_quality('libvorbis', 0) == [ '-q:a', '-1.0' ]
assert set_audio_quality('libvorbis', 50) == [ '-q:a', '4.5' ]
assert set_audio_quality('libvorbis', 100) == [ '-q:a', '10.0' ]
assert set_audio_quality('flac', 0) == []
assert set_audio_quality('flac', 50) == []
assert set_audio_quality('flac', 100) == []
def test_set_thread_count() -> None:
assert set_thread_count(8) == [ '-threads', '8' ]
assert set_thread_count(16) == [ '-threads', '16' ]
def test_set_faststart() -> None:
assert set_faststart('m4v') == [ '-movflags', '+faststart' ]
assert set_faststart('mov') == [ '-movflags', '+faststart' ]
assert set_faststart('mp4') == [ '-movflags', '+faststart' ]
assert set_faststart('mkv') == []
assert set_faststart('webm') == []
def test_set_video_tag() -> None:
assert set_video_tag('libx265', 'm4v') == [ '-tag:v', 'hvc1' ]
assert set_video_tag('hevc_nvenc', 'mov') == [ '-tag:v', 'hvc1' ]
assert set_video_tag('hevc_videotoolbox', 'mp4') == [ '-tag:v', 'hvc1' ]
assert set_video_tag('libx265', 'mkv') == []
assert set_video_tag('libx265', 'webm') == []
assert set_video_tag('libx264', 'mp4') == []
assert set_video_tag('h264_nvenc', 'mp4') == []
def test_set_video_quality() -> None:
assert set_video_quality('libx264', 0) == [ '-crf', '51' ]
assert set_video_quality('libx264', 50) == [ '-crf', '26' ]
assert set_video_quality('libx264', 100) == [ '-crf', '0' ]
assert set_video_quality('libx264rgb', 0) == [ '-crf', '51' ]
assert set_video_quality('libx264rgb', 50) == [ '-crf', '26' ]
assert set_video_quality('libx264rgb', 100) == [ '-crf', '0' ]
assert set_video_quality('libx265', 0) == [ '-crf', '51' ]
assert set_video_quality('libx265', 50) == [ '-crf', '26' ]
assert set_video_quality('libx265', 100) == [ '-crf', '0' ]
assert set_video_quality('libvpx-vp9', 0) == [ '-crf', '63' ]
assert set_video_quality('libvpx-vp9', 50) == [ '-crf', '32' ]
assert set_video_quality('libvpx-vp9', 100) == [ '-crf', '0' ]
assert set_video_quality('h264_nvenc', 0) == [ '-cq' , '51' ]
assert set_video_quality('h264_nvenc', 50) == [ '-cq' , '26' ]
assert set_video_quality('h264_nvenc', 100) == [ '-cq' , '0' ]
assert set_video_quality('hevc_nvenc', 0) == [ '-cq' , '51' ]
assert set_video_quality('hevc_nvenc', 50) == [ '-cq' , '26' ]
assert set_video_quality('hevc_nvenc', 100) == [ '-cq' , '0' ]
assert set_video_quality('h264_amf', 0) == [ '-qp_i', '51', '-qp_p', '51', '-qp_b', '51' ]
assert set_video_quality('h264_amf', 50) == [ '-qp_i', '26', '-qp_p', '26', '-qp_b', '26' ]
assert set_video_quality('h264_amf', 100) == [ '-qp_i', '0', '-qp_p', '0', '-qp_b', '0' ]
assert set_video_quality('hevc_amf', 0) == [ '-qp_i', '51', '-qp_p', '51', '-qp_b', '51' ]
assert set_video_quality('hevc_amf', 50) == [ '-qp_i', '26', '-qp_p', '26', '-qp_b', '26' ]
assert set_video_quality('hevc_amf', 100) == [ '-qp_i', '0', '-qp_p', '0', '-qp_b', '0' ]
assert set_video_quality('h264_qsv', 0) == [ '-qp', '51' ]
assert set_video_quality('h264_qsv', 50) == [ '-qp', '26' ]
assert set_video_quality('h264_qsv', 100) == [ '-qp', '0' ]
assert set_video_quality('hevc_qsv', 0) == [ '-qp', '51' ]
assert set_video_quality('hevc_qsv', 50) == [ '-qp', '26' ]
assert set_video_quality('hevc_qsv', 100) == [ '-qp', '0' ]
assert set_video_quality('h264_videotoolbox', 0) == [ '-b:v', '1024k' ]
assert set_video_quality('h264_videotoolbox', 50) == [ '-b:v', '25768k' ]
assert set_video_quality('h264_videotoolbox', 100) == [ '-b:v', '50512k' ]
assert set_video_quality('hevc_videotoolbox', 0) == [ '-b:v', '1024k' ]
assert set_video_quality('hevc_videotoolbox', 50) == [ '-b:v', '25768k' ]
assert set_video_quality('hevc_videotoolbox', 100) == [ '-b:v', '50512k' ]