Skip to content

Commit

Permalink
split out for_duration as for_stream(s) and for_format
Browse files Browse the repository at this point in the history
  • Loading branch information
aisch committed Dec 23, 2015
1 parent c3c04e1 commit dae8d8f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
16 changes: 15 additions & 1 deletion marm/ffmpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,25 @@ def for_first_frame(cls, *args, **kwargs):
return n

@classmethod
def for_duration(cls, *args, **kwargs):
def for_format_duration(cls, *args, **kwargs):
probe = cls(['-show_format'] + list(args), **kwargs)
probe()
return timedelta(seconds=probe.result['format']['duration'])

@classmethod
def for_stream_durations(cls, *args, **kwargs):
probe = cls(['-show_streams'] + list(args), **kwargs)
probe()
return [
timedelta(seconds=s['duration']) for s in probe.result['streams']
]

@classmethod
def for_stream_duration(cls, *args, **kwargs):
probe = cls(['-show_streams'] + list(args), **kwargs)
probe()
return max(cls.for_stream_durations(*args, **kwargs) + [timedelta()])

@classmethod
def for_streams(cls, *args, **kwargs):
probe = cls(['-show_streams'] + list(args), **kwargs)
Expand Down
19 changes: 19 additions & 0 deletions test/test_ff_wrapper.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from datetime import timedelta

import pytest

import marm
Expand Down Expand Up @@ -41,3 +43,20 @@ def test_ffprobe_last_packet(fixtures, file_name, args, as_fo, expected):
else:
r = marm.FFProbe.for_last_packet(*(args + [p.strpath]))
assert r == expected


@pytest.mark.parametrize(
'file_name,expected_stream,expected_format', [
('sonic.ts',
timedelta(seconds=120.033333),
timedelta(seconds=120.054667)),
]
)
def test_ffprobe_duration(
fixtures,
file_name,
expected_stream,
expected_format):
p = fixtures.join(file_name)
assert marm.FFProbe.for_stream_duration(p.strpath) == expected_stream
assert marm.FFProbe.for_format_duration(p.strpath) == expected_format

0 comments on commit dae8d8f

Please sign in to comment.