Skip to content

fix #615 parse ffmpeg -h full #628

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 10, 2025
Merged

fix #615 parse ffmpeg -h full #628

merged 5 commits into from
Jun 10, 2025

Conversation

lucemia
Copy link
Contributor

@lucemia lucemia commented Jun 4, 2025

This pull request introduces enhancements to the FFmpeg CLI parsing capabilities, including the addition of a new command for extracting AVOptions, a parser for processing FFmpeg help output, and corresponding tests and schemas. The changes focus on improving the functionality for handling complex FFmpeg commands and parsing detailed option metadata.

Enhancements to FFmpeg CLI Parsing:

  • Addition of a new command to extract AVOptions:

    • A new all_options command was added to src/scripts/parse_help/cli.py, which parses and prints all FFmpeg options from the help output using the extract_avoption_info_from_help function. ([src/scripts/parse_help/cli.pyR15-R31](https://github.com/livingbio/typed-ffmpeg/pull/628/files#diff-17454f51769de1d8033951bd57d78e54b213c1cf78eeb21eed0797a35c3234acR15-R31))
  • Implementation of an AVOption parser:

    • A new module src/scripts/parse_help/parse_all_options.py was introduced to parse FFmpeg help text, extract AVOptions, and handle option metadata like types, flags, and choices. It includes functions such as extract_options_help_text and parse_all_options. ([src/scripts/parse_help/parse_all_options.pyR1-R139](https://github.com/livingbio/typed-ffmpeg/pull/628/files#diff-11331cb0b1d091faae786120577f1e0ae611563506f335478059f4d4be9e3f07R1-R139))
  • Schema for AVOptions and option choices:

    • New data classes FFMpegAVOption and FFMpegOptionChoice were added in src/scripts/parse_help/schema.py to define the structure for parsed options and their choices. ([src/scripts/parse_help/schema.pyR1-R22](https://github.com/livingbio/typed-ffmpeg/pull/628/files#diff-f79f5493fe7f5aa3189e95a5d72766877d16f452d1404a121b4d9d53ad743e69R1-R22))

Testing and Validation:

  • Snapshot-based tests for FFmpeg option parsing:
    • Added tests in src/scripts/parse_help/tests/test_ffmpeg_option_parser.py to validate the parsing of various FFmpeg options, including global options, options with default values, and options with descriptions. These tests utilize the Syrupy snapshot assertion library. ([src/scripts/parse_help/tests/test_ffmpeg_option_parser.pyR1-R72](https://github.com/livingbio/typed-ffmpeg/pull/628/files#diff-9d2dcae4d60f8d8dfb5aa7985f7b1b777e1c990629fc0202c312eb4d0dc127a6R1-R72))
    • Snapshots for test cases were added in src/scripts/parse_help/tests/__snapshots__/test_ffmpeg_option_parser.ambr to ensure consistent parsing results. ([src/scripts/parse_help/tests/__snapshots__/test_ffmpeg_option_parser.ambrR1-R40](https://github.com/livingbio/typed-ffmpeg/pull/628/files#diff-ad9ce33fb23ee581e8b93893c9fd5efbd6fdb32cfaae821a61665ea4b712497dR1-R40))

Additional Improvements:

  • Support for complex FFmpeg commands in tests:
    • A new test case was added in src/ffmpeg/compile/tests/test_compile_cli.py to handle a complex FFmpeg command with multiple options and filters, enhancing the robustness of the parsing logic. ([src/ffmpeg/compile/tests/test_compile_cli.pyR47-R50](https://github.com/livingbio/typed-ffmpeg/pull/628/files#diff-f41044319fa755947196da1a92e14e54936c96872f1a682cc14dfeac80c8b807R47-R50))

@lucemia lucemia changed the title fix #615 wip fix #615 parse ffmpeg -h full Jun 4, 2025
Copy link

codecov bot commented Jun 4, 2025

Codecov Report

Attention: Patch coverage is 79.74684% with 16 lines in your changes missing coverage. Please review.

Project coverage is 91.83%. Comparing base (ea7006a) to head (3b8a04b).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/scripts/parse_help/parse_all_options.py 76.36% 13 Missing ⚠️
src/scripts/parse_help/cli.py 57.14% 3 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #628      +/-   ##
==========================================
- Coverage   92.12%   91.83%   -0.30%     
==========================================
  Files          55       57       +2     
  Lines        2920     2999      +79     
==========================================
+ Hits         2690     2754      +64     
- Misses        230      245      +15     
Flag Coverage Δ
3.10 92.41% <ø> (+0.04%) ⬆️
3.11 92.37% <ø> (+0.04%) ⬆️
3.12 92.37% <ø> (+0.04%) ⬆️
backend 92.41% <ø> (+0.04%) ⬆️
python 92.41% <ø> (+0.04%) ⬆️
python-3.10 90.31% <79.74%> (-1.11%) ⬇️
scripts 90.31% <79.74%> (-1.11%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/scripts/parse_help/schema.py 100.00% <100.00%> (ø)
src/scripts/parse_help/cli.py 85.00% <57.14%> (-15.00%) ⬇️
src/scripts/parse_help/parse_all_options.py 76.36% <76.36%> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@lucemia
Copy link
Contributor Author

lucemia commented Jun 4, 2025

typed-ffmpeg➜ typed-ffmpeg git:(fix-615-parse-ffmpeg-h-full) ✗ cat ffmpeg-h-full.txt| grep ptions: | wc -l
1035

(a)movie AVOptions: -> movie and amovie
smpte(hd)bars AVOptions: -> smptebars and smptehdbars

@lucemia
Copy link
Contributor Author

lucemia commented Jun 4, 2025

xcbgrab indev AVOptions:
libcdio indev AVOptions:
libdc1394 indev AVOptions:
SWScaler AVOptions:
SWResampler AVOptions:
AVFilter AVOptions:

@lucemia
Copy link
Contributor Author

lucemia commented Jun 4, 2025

imagepipe demuxer AVOptions:
imagepipe demuxer AVOptions:
imagepipe demuxer AVOptions:
imagepipe demuxer AVOptions:

@lucemia
Copy link
Contributor Author

lucemia commented Jun 4, 2025

PulseAudio outdev AVOptions:
sdl2 outdev AVOptions:
xvideo outdev AVOptions:

@lucemia
Copy link
Contributor Author

lucemia commented Jun 4, 2025

(stream) hash muxer AVOptions:
Tee muxer AVOptions:

@lucemia
Copy link
Contributor Author

lucemia commented Jun 4, 2025

av1_cuvid AVOptions:
h264_cuvid AVOptions:
hevc_cuvid AVOptions:
mjpeg_cuvid AVOptions:
mpeg1_cuvid AVOptions:
mpeg2_cuvid AVOptions:

@lucemia
Copy link
Contributor Author

lucemia commented Jun 4, 2025

V210 Decoder AVOptions:
vc1_v4l2m2m_decoder AVOptions:
vp8_v4l2m2m_decoder AVOptions:

@lucemia
Copy link
Contributor Author

lucemia commented Jun 4, 2025

libxvid AVOptions:
h263_v4l2m2m_encoder AVOptions:
av1_nvenc AVOptions:
av1_vaapi AVOptions:

@lucemia lucemia requested a review from Copilot June 10, 2025 06:39
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes issue #615 by enhancing the FFmpeg help parser to correctly interpret full help output and adds tests and a CLI command for options parsing.

  • Added comprehensive tests for various FFmpeg option output formats.
  • Updated and integrated a new CLI command to extract AV options.
  • Extended the parsing schema and refined regex patterns in the parser.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/scripts/parse_help/tests/test_ffmpeg_option_parser.py Added new tests covering different option layouts.
src/scripts/parse_help/tests/snapshots/test_ffmpeg_option_parser.ambr Created/upadated snapshots for the new option parsing tests.
src/scripts/parse_help/schema.py Introduced data classes for option and choice representations.
src/scripts/parse_help/parse_all_options.py Updated the core parser to support full FFmpeg help output.
src/scripts/parse_help/cli.py Added an "all_options" CLI command to expose options parsing.
src/ffmpeg/compile/tests/test_compile_cli.py Extended CLI tests for complex FFmpeg command scenarios.

Comment on lines +14 to +20
r"(?P<short_name>[\w\-]+)\s+\<(?P<type>[\w]+)\>\s+(?P<flags>[\w\.]{11})\s*(?P<help>.*)?"
)
re_choice_pattern = re.compile(
r"(?P<short_name>[\w\-\s]+)\s+(?P<flags>[\w\.]{11})\s*(?P<help>.*)?"
)
re_value_pattern = re.compile(
r"(?P<short_name>[\w\-\s]+)\s+(?P<value>[\w\-]+)\s+(?P<flags>[\w\.]{11})\s*(?P<help>.*)?"
Copy link
Preview

Copilot AI Jun 10, 2025

Choose a reason for hiding this comment

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

The regex pattern for flags enforces exactly 11 characters, which may be brittle if the FFmpeg help output format changes. Consider using a more flexible approach that adapts to variable flag field lengths.

Suggested change
r"(?P<short_name>[\w\-]+)\s+\<(?P<type>[\w]+)\>\s+(?P<flags>[\w\.]{11})\s*(?P<help>.*)?"
)
re_choice_pattern = re.compile(
r"(?P<short_name>[\w\-\s]+)\s+(?P<flags>[\w\.]{11})\s*(?P<help>.*)?"
)
re_value_pattern = re.compile(
r"(?P<short_name>[\w\-\s]+)\s+(?P<value>[\w\-]+)\s+(?P<flags>[\w\.]{11})\s*(?P<help>.*)?"
r"(?P<short_name>[\w\-]+)\s+\<(?P<type>[\w]+)\>\s+(?P<flags>[\w\.]+)\s*(?P<help>.*)?"
)
re_choice_pattern = re.compile(
r"(?P<short_name>[\w\-\s]+)\s+(?P<flags>[\w\.]+)\s*(?P<help>.*)?"
)
re_value_pattern = re.compile(
r"(?P<short_name>[\w\-\s]+)\s+(?P<value>[\w\-]+)\s+(?P<flags>[\w\.]+)\s*(?P<help>.*)?"

Copilot uses AI. Check for mistakes.

continue

# Choice line
if line.startswith(" "):
Copy link
Preview

Copilot AI Jun 10, 2025

Choose a reason for hiding this comment

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

The parser relies on fixed whitespace prefixes to differentiate choice lines from option lines. Consider using a regex-based approach to identify these lines to enhance robustness against formatting changes.

Copilot uses AI. Check for mistakes.

@lucemia lucemia marked this pull request as ready for review June 10, 2025 07:08
@lucemia lucemia merged commit 770ee7d into main Jun 10, 2025
11 checks passed
@lucemia lucemia deleted the fix-615-parse-ffmpeg-h-full branch June 10, 2025 07:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Get a complete options list from ffmpeg -h full
1 participant