Skip to content

Commit 27cc312

Browse files
OmarabdalgwadlucemiaCopilot
authored
Fixed (#797)
* add README.md * docs: fix demo gif path in README * fix ffmpeg/info.py incompatible in different ffmpeg version #649 * fix ffmpeg/info.py incompatible in different ffmpeg version issue #649 * add tests * add testes * add testes * add * add * add * add * add * FIX UNCOVERED * add * fixed * ADD * fixed * fixed * fixed * fix line endings and formatting * fix line endings and formatting * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix --------- Co-authored-by: David Chen <davidchen@gliacloud.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: lucemia <lucemia@gmail.com>
1 parent 6945245 commit 27cc312

File tree

3 files changed

+102
-30
lines changed

3 files changed

+102
-30
lines changed

src/ffmpeg/info.py

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,16 @@ class CodecFlags(Flag):
2626
output and indicate what features a codec supports.
2727
"""
2828

29-
video = auto() # Codec supports video encoding/decoding
30-
audio = auto() # Codec supports audio encoding/decoding
31-
subtitle = auto() # Codec supports subtitle processing
32-
frame_level_multithreading = auto() # Codec supports frame-level multithreading
33-
slice_level_multithreading = auto() # Codec supports slice-level multithreading
34-
experimental = auto() # Codec is considered experimental
35-
draw_horiz_band = auto() # Codec supports drawing horizontal bands
36-
direct_rendering_method_1 = auto() # Codec supports direct rendering method 1
29+
decoding = auto()
30+
encoding = auto()
31+
video = auto()
32+
audio = auto()
33+
subtitle = auto()
34+
data = auto()
35+
attachment = auto()
36+
intraframe_only = auto()
37+
lossy = auto()
38+
lossless = auto()
3739

3840

3941
@dataclass(frozen=True)
@@ -72,22 +74,26 @@ def parse_codec_flags(flags: str) -> CodecFlags:
7274
7375
"""
7476
flags_enum = CodecFlags(0)
75-
if flags[0] == "V":
77+
if len(flags) > 0 and flags[0] == "D":
78+
flags_enum |= CodecFlags.decoding
79+
if len(flags) > 1 and flags[1] == "E":
80+
flags_enum |= CodecFlags.encoding
81+
if len(flags) > 2 and flags[2] == "V":
7682
flags_enum |= CodecFlags.video
77-
if flags[0] == "A":
83+
if len(flags) > 3 and flags[3] == "A":
7884
flags_enum |= CodecFlags.audio
79-
if flags[0] == "S":
85+
if len(flags) > 4 and flags[4] == "S":
8086
flags_enum |= CodecFlags.subtitle
81-
if flags[1] == "F":
82-
flags_enum |= CodecFlags.frame_level_multithreading
83-
if flags[2] == "S":
84-
flags_enum |= CodecFlags.slice_level_multithreading
85-
if flags[3] == "X":
86-
flags_enum |= CodecFlags.experimental
87-
if flags[4] == "B":
88-
flags_enum |= CodecFlags.draw_horiz_band
89-
if flags[5] == "D":
90-
flags_enum |= CodecFlags.direct_rendering_method_1
87+
if len(flags) > 5 and flags[5] == "D":
88+
flags_enum |= CodecFlags.data
89+
if len(flags) > 6 and flags[6] == "T":
90+
flags_enum |= CodecFlags.attachment
91+
if len(flags) > 7 and flags[7] == "I":
92+
flags_enum |= CodecFlags.intraframe_only
93+
if len(flags) > 8 and flags[8] == "L":
94+
flags_enum |= CodecFlags.lossy
95+
if len(flags) > 9 and flags[9] == "S":
96+
flags_enum |= CodecFlags.lossless
9197
return flags_enum
9298

9399

@@ -167,22 +173,24 @@ def parse_coder_flags(flags: str) -> CoderFlags:
167173
168174
"""
169175
flags_enum = CoderFlags(0)
170-
if flags[0] == "V":
176+
if len(flags) > 0 and flags[0] == "V":
171177
flags_enum |= CoderFlags.video
172-
if flags[0] == "A":
178+
if len(flags) > 1 and flags[1] == "A":
173179
flags_enum |= CoderFlags.audio
174-
if flags[0] == "S":
180+
if len(flags) > 2 and flags[2] == "S":
175181
flags_enum |= CoderFlags.subtitle
176-
if flags[1] == "F":
182+
183+
if len(flags) > 3 and flags[3] == "F":
177184
flags_enum |= CoderFlags.frame_level_multithreading
178-
if flags[2] == "S":
185+
if len(flags) > 4 and flags[4] == "S":
179186
flags_enum |= CoderFlags.slice_level_multithreading
180-
if flags[3] == "X":
187+
if len(flags) > 5 and flags[5] == "X":
181188
flags_enum |= CoderFlags.experimental
182-
if flags[4] == "B":
189+
if len(flags) > 6 and flags[6] == "B":
183190
flags_enum |= CoderFlags.draw_horiz_band
184-
if flags[5] == "D":
191+
if len(flags) > 7 and flags[7] == "D":
185192
flags_enum |= CoderFlags.direct_rendering_method_1
193+
186194
return flags_enum
187195

188196

src/ffmpeg/tests/test_ffmpeg.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,46 @@
22
from syrupy.extensions.json import JSONSnapshotExtension
33

44
import ffmpeg
5+
from ffmpeg.info import CodecFlags, CoderFlags, parse_codec_flags, parse_coder_flags
56

67

78
def test_typed_ffmpeg(snapshot: SnapshotAssertion) -> None:
89
assert dir(ffmpeg) == snapshot(extension_class=JSONSnapshotExtension)
10+
11+
12+
def test_parse_codec_flags() -> None:
13+
flags = "DEVASDTILS"
14+
result = parse_codec_flags(flags)
15+
assert result & CodecFlags.decoding
16+
assert result & CodecFlags.encoding
17+
assert result & CodecFlags.video
18+
assert result & CodecFlags.audio
19+
assert result & CodecFlags.subtitle
20+
assert result & CodecFlags.data
21+
assert result & CodecFlags.attachment
22+
assert result & CodecFlags.intraframe_only
23+
assert result & CodecFlags.lossy
24+
assert result & CodecFlags.lossless
25+
26+
27+
def test_parse_coder_flags() -> None:
28+
flags = "VASFSXBD"
29+
result = parse_coder_flags(flags)
30+
assert result & CoderFlags.video
31+
assert result & CoderFlags.audio
32+
assert result & CoderFlags.subtitle
33+
assert result & CoderFlags.frame_level_multithreading
34+
assert result & CoderFlags.slice_level_multithreading
35+
assert result & CoderFlags.experimental
36+
assert result & CoderFlags.draw_horiz_band
37+
assert result & CoderFlags.direct_rendering_method_1
38+
39+
40+
def test_parse_codec_flags_empty() -> None:
41+
result = parse_codec_flags("")
42+
assert result == CodecFlags(0)
43+
44+
45+
def test_parse_coder_flags_empty() -> None:
46+
result = parse_coder_flags("")
47+
assert result == CoderFlags(0)

uv.lock

Lines changed: 26 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)