-
Notifications
You must be signed in to change notification settings - Fork 16
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
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
typed-ffmpeg➜ typed-ffmpeg git:(fix-615-parse-ffmpeg-h-full) ✗ cat ffmpeg-h-full.txt| grep ptions: | wc -l (a)movie AVOptions: -> movie and amovie |
xcbgrab indev AVOptions: |
imagepipe demuxer AVOptions: |
PulseAudio outdev AVOptions: |
(stream) hash muxer AVOptions: |
av1_cuvid AVOptions: |
V210 Decoder AVOptions: |
libxvid AVOptions: |
There was a problem hiding this 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. |
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>.*)?" |
There was a problem hiding this comment.
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.
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(" "): |
There was a problem hiding this comment.
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.
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:
all_options
command was added tosrc/scripts/parse_help/cli.py
, which parses and prints all FFmpeg options from the help output using theextract_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:
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 asextract_options_help_text
andparse_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:
FFMpegAVOption
andFFMpegOptionChoice
were added insrc/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:
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)
)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:
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)
)