Skip to content

Commit

Permalink
Fix ffmpeg demuxing when some of the streams are marked forced
Browse files Browse the repository at this point in the history
Close #18
  • Loading branch information
tp7 committed Apr 4, 2015
1 parent 0268b48 commit 8442970
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
19 changes: 12 additions & 7 deletions demux.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,18 @@ def demux_file(input_path, **kwargs):

@staticmethod
def _get_audio_streams(info):
streams = re.findall(r'Stream #0:(\d+).*?Audio:\s*(.*?(?:\((default)\))?)\r?\n(?:\s*Metadata:\s*\r?\n\s*title\s*:\s*(.*?)\r?\n)?',
info)
streams = re.findall(r'Stream\s\#0:(\d+).*?Audio:\s*(.*?(?:\((default)\))?)\s*?(?:\(forced\))?\r?\n'
r'(?:\s*Metadata:\s*\r?\n'
r'\s*title\s*:\s*(.*?)\r?\n)?',
info, flags=re.VERBOSE)
return [MediaStreamInfo(int(x[0]), x[1], x[2] != '', x[3]) for x in streams]

@staticmethod
def _get_video_streams(info):
streams = re.findall(r'Stream #0:(\d+).*?Video:\s*(.*?(?:\((default)\))?)\r?\n(?:\s*Metadata:\s*\r?\n\s*title\s*:\s*(.*?)\r?\n)?',
info)
streams = re.findall(r'Stream\s\#0:(\d+).*?Video:\s*(.*?(?:\((default)\))?)\s*?(?:\(forced\))?\r?\n'
r'(?:\s*Metadata:\s*\r?\n'
r'\s*title\s*:\s*(.*?)\r?\n)?',
info, flags=re.VERBOSE)
return [MediaStreamInfo(int(x[0]), x[1], x[2] != '', x[3]) for x in streams]

@staticmethod
Expand All @@ -79,9 +83,10 @@ def _get_subtitles_streams(info):
'subrip': '.srt'
}

streams = re.findall(
r'Stream\s#0:(\d+).*?Subtitle:\s*((\w*)\s*?(?:\((default)\))?)\r?\n(?:\s*Metadata:\s*\r?\n\s*title\s*:\s*(.*?)\r?\n)?',
info)
streams = re.findall(r'Stream\s\#0:(\d+).*?Subtitle:\s*((\w*)\s*?(?:\((default)\))?\s*?(?:\(forced\))?)\r?\n'
r'(?:\s*Metadata:\s*\r?\n'
r'\s*title\s*:\s*(.*?)\r?\n)?',
info, flags=re.VERBOSE)
return [SubtitlesStreamInfo(int(x[0]), x[1], maps.get(x[2], x[2]), x[3] != '', x[4].strip()) for x in streams]

@classmethod
Expand Down
4 changes: 2 additions & 2 deletions tests/demuxing.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ class FFmpegTestCase(unittest.TestCase):
Stream #0:0(jpn): Video: h264 (High 10), yuv420p10le, 1280x720 [SAR 1:1 DAR 16:9], 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
Metadata:
title : Video 10bit
Stream #0:1(jpn): Audio: aac, 48000 Hz, stereo, fltp (default)
Stream #0:1(jpn): Audio: aac, 48000 Hz, stereo, fltp (default) (forced)
Metadata:
title : Audio AAC 2.0
Stream #0:2(eng): Audio: aac, 48000 Hz, stereo, fltp
Metadata:
title : English Audio AAC 2.0
Stream #0:3(eng): Subtitle: ssa (default)
Stream #0:3(eng): Subtitle: ssa (default) (forced)
Metadata:
title : English Subtitles
Stream #0:4(enm): Subtitle: ass
Expand Down

0 comments on commit 8442970

Please sign in to comment.