Skip to content
Permalink
Browse files

Report MP4 codec

  • Loading branch information
sampsyo committed Nov 10, 2014
1 parent 124faf7 commit b2f22b81c77ce80601f4509ff76d3e9fc12f76a7
Showing with 14 additions and 1 deletion.
  1. +8 −1 mutagen/mp4.py
  2. +6 −0 tests/test_mp4.py
@@ -981,6 +981,7 @@ class AudioSampleEntry(object):
sample_size (int): sample size in bits
sample_rate (int): sample rate in Hz
bitrate (int): bits per second (0 means unknown)
codec (string): audio codec, either 'mp4a' or 'alac'
Can raise ValueError.
"""
@@ -989,9 +990,12 @@ class AudioSampleEntry(object):
sample_size = 0
sample_rate = 0
bitrate = 0
kind = None

def __init__(self, atom, fileobj):
if atom.name not in (b"mp4a", b"alac"):
if atom.name in (b"mp4a", b"alac"):
self.kind = atom.name.decode()
else:
raise ValueError("Unsupported coding name %s" % atom.name)

ok, data = atom.read(fileobj)
@@ -1107,12 +1111,14 @@ class MP4Info(StreamInfo):
* channels -- number of audio channels
* sample_rate -- audio sampling rate in Hz
* bits_per_sample -- bits per sample
* codec -- either 'mp4a' or 'alac'
"""

bitrate = 0
channels = 0
sample_rate = 0
bits_per_sample = 0
kind = None

def __init__(self, atoms, fileobj):
for trak in list(atoms[b"moov"].findall(b"trak")):
@@ -1195,6 +1201,7 @@ def _parse_stsd(self, atom, fileobj):
self.bits_per_sample = entry.sample_size
self.sample_rate = entry.sample_rate
self.bitrate = entry.bitrate
self.kind = entry.kind

def pprint(self):
return "MPEG-4 audio, %.2f seconds, %d bps" % (
@@ -461,6 +461,9 @@ def test_bitrate(self):
def test_length(self):
self.failUnlessAlmostEqual(3.7, self.audio.info.length, 1)

def test_kind(self):
self.assertEqual(self.audio.info.kind, u'mp4a')

def test_padding(self):
self.audio["\xa9nam"] = u"wheeee" * 10
self.audio.save()
@@ -890,6 +893,9 @@ def test_length(self):
def test_bitrate(self):
self.assertEqual(self.audio.info.bitrate, 2764)

def test_kind(self):
self.assertEqual(self.audio.info.kind, u'alac')

add(TMP4ALAC)


0 comments on commit b2f22b8

Please sign in to comment.
You can’t perform that action at this time.