Skip to content

Commit

Permalink
Handle brackets and language in FFMPEG output (Zulko#1837)
Browse files Browse the repository at this point in the history
* Improve regex to handle brackets and language

* Update CHANGELOG.md

* Simplify `if`
  • Loading branch information
LoipesMas authored Oct 7, 2022
1 parent 46dca4a commit 1393889
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed scroll FX not being scrolling [\#1591](https://github.com/Zulko/moviepy/pull/1591)
- Fixed parsing FFMPEG streams with square brackets [\#1781](https://github.com/Zulko/moviepy/pull/1781)
- Fixed audio processing for streams with missing `audio_bitrate` [\#1783](https://github.com/Zulko/moviepy/pull/1783)
- Fixed parsing language from stream output with square brackets [\#1837](https://github.com/Zulko/moviepy/pull/1837)


## [v2.0.0.dev2](https://github.com/zulko/moviepy/tree/v2.0.0.dev2) (2020-10-05)
Expand Down
8 changes: 4 additions & 4 deletions moviepy/video/io/ffmpeg_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,8 @@ def parse(self):

# get input number, stream number, language and type
main_info_match = re.search(
r"^Stream\s#(\d+):(\d+)[\[(]?(\w+)?[\])]?:\s(\w+):", line.lstrip()
r"^Stream\s#(\d+):(\d+)(?:\[\w+\])?\(?(\w+)?\)?:\s(\w+):",
line.lstrip(),
)
(
input_number,
Expand All @@ -434,9 +435,8 @@ def parse(self):
stream_number = int(stream_number)
stream_type_lower = stream_type.lower()

if language is not None:
if language == "und" or language.startswith("0x"):
language = None
if language == "und":
language = None

# start builiding the current stream
self._current_stream = {
Expand Down
16 changes: 16 additions & 0 deletions tests/test_ffmpeg_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,22 @@ def test_stream_square_brackets():
assert d["inputs"][0]["streams"][1]["language"] is None


def test_stream_square_brackets_and_language():
infos = """
Input #0, mpeg, from 'clip.mp4':
Duration: 00:02:15.00, start: 52874.498178, bitrate: 266 kb/s
Stream #0:0[0x1e0](eng): Video: ..., 25 tbr, 90k tbn, 50 tbc
Stream #0:1[0x1c0](und): Audio: mp2, 0 channels, s16p
At least one output file must be specified"""

d = FFmpegInfosParser(infos, "clip.mp4").parse()

assert d
assert len(d["inputs"][0]["streams"]) == 2
assert d["inputs"][0]["streams"][0]["language"] == "eng"
assert d["inputs"][0]["streams"][1]["language"] is None


def test_stream_missing_audio_bitrate():
infos = """
Input #0, mpeg, from 'clip.mp4':
Expand Down

0 comments on commit 1393889

Please sign in to comment.