From a24b575929b0ccdb706093802f4245eb7659dc16 Mon Sep 17 00:00:00 2001 From: Medinar Date: Sun, 19 Jan 2020 22:36:36 +0100 Subject: [PATCH 1/2] The SIDE_DATA section inside a stream section are ignored --- ffprobe/ffprobe.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ffprobe/ffprobe.py b/ffprobe/ffprobe.py index abc4ad9..04f84e7 100644 --- a/ffprobe/ffprobe.py +++ b/ffprobe/ffprobe.py @@ -36,6 +36,7 @@ def __init__(self, path_to_video): p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) stream = False + ignoreLine = False self.streams = [] self.video = [] self.audio = [] @@ -47,13 +48,20 @@ def __init__(self, path_to_video): if '[STREAM]' in line: stream = True + ignoreLine = False data_lines = [] elif '[/STREAM]' in line and stream: stream = False + ignoreLine = False # noinspection PyUnboundLocalVariable self.streams.append(FFStream(data_lines)) elif stream: - data_lines.append(line) + if '[SIDE_DATA]' in line: + ignoreLine = True + elif '[/SIDE_DATA]' in line: + ignoreLine = False + elif ignoreLine == False: + data_lines.append(line) self.metadata = {} is_metadata = False From 646ca3e8a289da93396202f4333b750cbf64b0b3 Mon Sep 17 00:00:00 2001 From: Medinar Date: Sun, 19 Jan 2020 22:58:17 +0100 Subject: [PATCH 2/2] Fix test file to run with pytest -Filename changed to be detected by pytest -Function added to be detected as a test by pytest -Remove link to removed data (50mb) --- tests/ffprobe-test.py | 33 --------------------------------- tests/ffprobe_test.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 33 deletions(-) delete mode 100644 tests/ffprobe-test.py create mode 100644 tests/ffprobe_test.py diff --git a/tests/ffprobe-test.py b/tests/ffprobe-test.py deleted file mode 100644 index 4e20ef9..0000000 --- a/tests/ffprobe-test.py +++ /dev/null @@ -1,33 +0,0 @@ -from __future__ import print_function - -import os -from ffprobe3 import FFProbe -from ffprobe3.exceptions import FFProbeError - -test_dir = os.path.dirname(os.path.abspath(__file__)) - -test_videos = [ - os.path.join(test_dir, './data/SampleVideo_720x480_5mb.mp4'), - os.path.join(test_dir, './data/SampleVideo_1280x720_1mb.mp4'), - os.path.join(test_dir, './data/SampleVideo_360x240_50mb.mp4'), - os.path.join(test_dir, './data/SampleVideo_1280x720_50mb.mp4'), -] - -for test_video in test_videos: - media = FFProbe(test_video) - print('File:', test_video) - print('\tStreams:', len(media.streams)) - for index, stream in enumerate(media.streams, 1): - print('\tStream: ', index) - try: - if stream.is_video(): - frame_rate = stream.frames() / stream.duration_seconds() - print('\t\tFrame Rate:', frame_rate) - print('\t\tFrame Size:', stream.frame_size()) - print('\t\tDuration:', stream.duration_seconds()) - print('\t\tFrames:', stream.frames()) - print('\t\tIs video:', stream.is_video()) - except FFProbeError as e: - print(e) - except Exception as e: - print(e) diff --git a/tests/ffprobe_test.py b/tests/ffprobe_test.py new file mode 100644 index 0000000..2d09444 --- /dev/null +++ b/tests/ffprobe_test.py @@ -0,0 +1,32 @@ +from __future__ import print_function + +import os +from ffprobe import FFProbe +from ffprobe.exceptions import FFProbeError + +test_dir = os.path.dirname(os.path.abspath(__file__)) + +test_videos = [ + os.path.join(test_dir, './data/SampleVideo_720x480_5mb.mp4'), + os.path.join(test_dir, './data/SampleVideo_1280x720_1mb.mp4'), +] + +def test_video (): + for test_video in test_videos: + media = FFProbe(test_video) + print('File:', test_video) + print('\tStreams:', len(media.streams)) + for index, stream in enumerate(media.streams, 1): + print('\tStream: ', index) + try: + if stream.is_video(): + frame_rate = stream.frames() / stream.duration_seconds() + print('\t\tFrame Rate:', frame_rate) + print('\t\tFrame Size:', stream.frame_size()) + print('\t\tDuration:', stream.duration_seconds()) + print('\t\tFrames:', stream.frames()) + print('\t\tIs video:', stream.is_video()) + except FFProbeError as e: + print(e) + except Exception as e: + print(e)