Skip to content

Video editing with Python

Fix libavformat compatiblity break (#1768)

Bartłomiej Kurzeja5853ff83bd78
diff --git a/moviepy/video/io/ffmpeg_reader.py b/moviepy/video/io/ffmpeg_reader.py
index 3e245573..e9610171 100644
--- a/moviepy/video/io/ffmpeg_reader.py
+++ b/moviepy/video/io/ffmpeg_reader.py
@@ -415,14 +415,14 @@ class FFmpegInfosParser:
else:
self._last_metadata_field_added = field
self.result["metadata"][field] = value
- elif line.startswith(" Stream "):
+ elif line.lstrip().startswith("Stream "):
# exit stream " Metadata:"
if self._current_stream:
self._current_input_file["streams"].append(self._current_stream)
# get input number, stream number, language and type
main_info_match = re.search(
- r"^\s{4}Stream\s#(\d+):(\d+)\(?(\w+)?\)?:\s(\w+):", line
+ r"^Stream\s#(\d+):(\d+)\(?(\w+)?\)?:\s(\w+):", line.lstrip()
)
(
input_number,
diff --git a/tests/test_ffmpeg_reader.py b/tests/test_ffmpeg_reader.py
index da40ef51..a1a5cce6 100644
--- a/tests/test_ffmpeg_reader.py
+++ b/tests/test_ffmpeg_reader.py
@@ -487,6 +487,30 @@ def test_not_default_audio_stream_audio_bitrate():
assert d["audio_bitrate"] == 139
+def test_stream_deidentation_not_raises_error():
+ """Test libavformat reduced streams identation to 2 spaces.
+
+ See https://github.com/FFmpeg/FFmpeg/commit/b7251aed
+ """
+ infos = """Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'clip.mp4':
+ Metadata:
+ major_brand : isom
+ minor_version : 512
+ compatible_brands: isomiso2avc1mp41
+ encoder : Lavf58.12.100
+ Duration: 01:00:00.00, start: 0.000000, bitrate: 1222 kb/s
+ Stream #0:0(und): Video: ..., 30 tbr, 60 tbc
+ Metadata:
+ handler_name : VideoHandler
+ vendor_id : [0][0][0][0]
+At least one output file must be specified"""
+
+ d = FFmpegInfosParser(infos, "clip.mp4").parse()
+
+ assert d
+ assert len(d["inputs"][0]["streams"]) == 1
+
+
def test_sequential_frame_pos():
"""test_video.mp4 contains 5 frames at 1 fps.
Each frame is 1x1 pixels and the sequence is Red, Green, Blue, Black, White.