Skip to content

Commit

Permalink
only print length warning for non-EBU type normalization
Browse files Browse the repository at this point in the history
  • Loading branch information
slhck committed Mar 14, 2020
1 parent 9efdce2 commit 69ac934
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
6 changes: 3 additions & 3 deletions ffmpeg_normalize/_media_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ def parse_streams(self):
sample_rate = int(sample_rate_match.group(1)) if sample_rate_match else None
bit_depth_match = re.search(r's(\d+)p?,', line)
bit_depth = int(bit_depth_match.group(1)) if bit_depth_match else None
self.streams['audio'][stream_id] = AudioStream(self, stream_id, sample_rate, bit_depth, duration)
self.streams['audio'][stream_id] = AudioStream(self, self.ffmpeg_normalize, stream_id, sample_rate, bit_depth, duration)

elif 'Video' in line:
logger.debug("Found video stream at index {}".format(stream_id))
self.streams['video'][stream_id] = VideoStream(self, stream_id)
self.streams['video'][stream_id] = VideoStream(self, self.ffmpeg_normalize, stream_id)

elif 'Subtitle' in line:
logger.debug("Found subtitle stream at index {}".format(stream_id))
self.streams['subtitle'][stream_id] = SubtitleStream(self, stream_id)
self.streams['subtitle'][stream_id] = SubtitleStream(self, self.ffmpeg_normalize, stream_id)

if not self.streams['audio']:
raise FFmpegNormalizeError(
Expand Down
21 changes: 13 additions & 8 deletions ffmpeg_normalize/_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
logger = setup_custom_logger('ffmpeg_normalize')

class MediaStream(object):
def __init__(self, media_file, stream_type, stream_id):
def __init__(self, ffmpeg_normalize, media_file, stream_type, stream_id):
"""
Arguments:
media_file {MediaFile} -- parent media file
stream_type {str} -- stream type
stream_id {int} -- Audio stream id
"""
self.ffmpeg_normalize = ffmpeg_normalize
self.media_file = media_file
self.stream_type = stream_type
self.stream_id = stream_id
Expand All @@ -25,22 +26,22 @@ def __repr__(self):
)

class VideoStream(MediaStream):
def __init__(self, media_file, stream_id):
super(VideoStream, self).__init__(media_file, 'video', stream_id)
def __init__(self, ffmpeg_normalize, media_file, stream_id):
super(VideoStream, self).__init__(media_file, ffmpeg_normalize, 'video', stream_id)

class SubtitleStream(MediaStream):
def __init__(self, media_file, stream_id):
super(SubtitleStream, self).__init__(media_file, 'subtitle', stream_id)
def __init__(self, ffmpeg_normalize, media_file, stream_id):
super(SubtitleStream, self).__init__(media_file, ffmpeg_normalize, 'subtitle', stream_id)

class AudioStream(MediaStream):
def __init__(self, media_file, stream_id, sample_rate=None, bit_depth=None, duration=None):
def __init__(self, ffmpeg_normalize, media_file, stream_id, sample_rate=None, bit_depth=None, duration=None):
"""
Arguments:
sample_rate {int} -- in Hz
bit_depth {int}
duration {int} -- duration in seconds
"""
super(AudioStream, self).__init__(media_file, 'audio', stream_id)
super(AudioStream, self).__init__(media_file, ffmpeg_normalize, 'audio', stream_id)

self.loudness_statistics = {
'ebu': None,
Expand All @@ -52,7 +53,11 @@ def __init__(self, media_file, stream_id, sample_rate=None, bit_depth=None, dura
self.bit_depth = bit_depth
self.duration = duration

if self.duration and self.duration <= 3:
if (
self.ffmpeg_normalize.normalization_type == "ebu" and
self.duration and
self.duration <= 3
):
logger.warn(
"Audio stream has a duration of less than 3 seconds. "
"Normalization may not work. "
Expand Down

0 comments on commit 69ac934

Please sign in to comment.