0

Im currently working on a school project which require me to handle mpeg-2 files. Currently, i am using mutagen to extract the metadata for my mpeg file. However when i try to get the metadata of title, artist, album, etc. It show me with a following error. [Python Code Appreciated]

Below if my output :

mutagen.id3.ID3NoHeaderError: 'media/test.mpeg' doesn't start with ID3 Tag

It shows that there was no container so called to hold the ID3 Tag, do anyone care to explain me why it is so?

It works out perfectly when i am working with mp3 file but not with mpeg.

Below is a portion of my code (hardcode):

from mutagen.id3 import ID3

file = "media/test.mpeg"
audio = ID3(file)

print "Artist: %s" % audio['TPE1'].text[0]
print "Track: %s" % audio["TIT2"].text[0]
print "Release Year: %s" % audio["TDRC"].text[0]

The second problem is that when i try to get the duration of the mpeg file, it return me with a wrong duration.

File duration = 21 second

when i run my code it show a duration of : 1124.5705721 second

Below is a portion of my code (hardcode):

import mutagen

from mutagen.mp3 import MP3
from mutagen.mp3 import MPEGInfo

file = "media/test.mpeg"
audio = MP3(file)

print audio.info.length
Winson
  • 35
  • 2
  • 11
  • Isn't .mpeg video files, I doubt they put id3 tags on video files. – Musa Jul 19 '12 at 06:50
  • oh, so in a sense mpeg-2 format does not have metadata for title, album, artist, etc. Sorry i have just ventured out into the region of audio. I have 0 prior knowledge about how they are actually formatted and such. Thanks for clearing my misunderstanding, i really apperciate it @Musa – Winson Jul 19 '12 at 06:54

1 Answers1

1

Mutagen uses the .mpeg suffix as one way of identifying that an input file is MP3 audio. See class MP3(ID3FileType) near the end of http://code.google.com/p/mutagen/source/browse/mutagen/mp3.py

Mutagen could be extended to detect video file types and read metadata from them (see for example http://code.google.com/p/mutagen/issues/attachmentText?id=90&aid=900002000&name=itunes-video.patch) but it is not explicitly designed for that purpose.

dhj
  • 11
  • 3