Skip to content
This repository has been archived by the owner on Sep 27, 2018. It is now read-only.

Commit

Permalink
metadata: add sample_rate and channel_layout to audio streams
Browse files Browse the repository at this point in the history
  • Loading branch information
zmwangx committed Oct 22, 2017
1 parent 0a97bc0 commit 0ce1ee7
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/storyboard/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,15 @@ class Stream(object):
Display aspect ratio as a human readable string, e.g.,
``'16:9'``.
sample_rate : float
Sample rate of audio stream, in Hz.
sample_rate_text : str
Sample rate as a human readable string, e.g., ``'44100 Hz'``.
channel_layout : str
Channel layout of audio stream, e.g. ``'stereo'``.
info_string : str
Assembled string of stream metadata, intended for printing.
Expand All @@ -172,6 +181,10 @@ def __init__(self):
self.frame_rate_text = None
self.dar = None # display aspect ratio
self.dar_text = None
# audio stream specific attributes
self.sample_rate = None
self.sample_rate_text = None
self.channel_layout = None
# assembled
self.info_string = None

Expand Down Expand Up @@ -1124,6 +1137,24 @@ def _process_audio_stream(self, stream_dict):
else:
s.codec = sdict['codec_long_name']

# sample rate
if 'sample_rate' in sdict:
s.sample_rate = float(sdict['sample_rate'])
s.sample_rate_text = '%d Hz' % int(s.sample_rate)
else:
s.sample_rate = None
s.sample_rate_text = None

# channel layout
if 'channel_layout' in sdict:
s.channel_layout = sdict['channel_layout']
elif 'channels' in sdict:
channels = sdict['channels']
s.channel_layout = ('mono' if channels == 1 else
('%d channels' % channels))
else:
s.channel_layout = None

# bit rate
if 'bit_rate' in sdict:
s.bit_rate = float(sdict['bit_rate'])
Expand All @@ -1144,6 +1175,10 @@ def _process_audio_stream(self, stream_dict):
s.info_string = "Audio (%s), %s" % (s.language_code, s.codec)
else:
s.info_string = "Audio, %s" % s.codec
if s.sample_rate_text:
s.info_string += ", " + s.sample_rate_text
if s.channel_layout:
s.info_string += ", " + s.channel_layout
if s.bit_rate_text:
s.info_string += ", " + s.bit_rate_text

Expand Down

0 comments on commit 0ce1ee7

Please sign in to comment.