Exemple #1
0
def get_media_params(file_path):
    m = Metadata()

    try:
        metadata = FFProbe(file_path)

        if metadata.html5SourceType() != "":
            m.add("html5_source_type", metadata.html5SourceType())

        if metadata.bitrate() != 0.0:
            m.add("bit_rate", metadata.bitrate())

        if metadata.durationSeconds() != 0.0:
            m.add("duration", metadata.durationSeconds())

        for stream in metadata.streams:
            if stream.isVideo():
                (width,height) = stream.frameSize()
                if int(width) != 0 and int(height) != 0:
                    m.add("width",width)
                    m.add("height",height)

                if int(stream.frames()) != 0:
                    m.add("frames",stream.frames())
    except Exception as e:
        pass

    """Fallback and calculate bit rate or duration if missing using available data"""
    if m.exists("bit_rate") and m.exists("duration") is False:
        size = os.path.getsize(full_path)
        m.add("duration", (m.get("bit_rate")/8) * size)

    if m.exists("duration") and m.exists("bit_rate") is False:
        size = os.path.getsize(full_path)
        m.add("bit_rate", (size / m.get("duration"))*8)

    if m.exists("frames") and m.exists("duration") and m.exists("frame_rate") is False:
        m.add("frame_rate", int(m.get("frames")/m.get("duration")))

    """If we have some values then return them if not then return False"""
    if m.empty() is False:
        return m

    return False
Exemple #2
0
def get_media_params(file_path):
    m = Metadata()

    try:
        metadata = FFProbe(file_path)

        if metadata.html5SourceType() != "":
            m.add("html5_source_type", metadata.html5SourceType())

        if metadata.bitrate() != 0.0:
            m.add("bit_rate", metadata.bitrate())

        if metadata.durationSeconds() != 0.0:
            m.add("duration", metadata.durationSeconds())

        for stream in metadata.streams:
            if stream.isVideo():
                (width, height) = stream.frameSize()
                if int(width) != 0 and int(height) != 0:
                    m.add("width", width)
                    m.add("height", height)

                if int(stream.frames()) != 0:
                    m.add("frames", stream.frames())
    except Exception as e:
        pass
    """Fallback and calculate bit rate or duration if missing using available data"""
    if m.exists("bit_rate") and m.exists("duration") is False:
        size = os.path.getsize(full_path)
        m.add("duration", (m.get("bit_rate") / 8) * size)

    if m.exists("duration") and m.exists("bit_rate") is False:
        size = os.path.getsize(full_path)
        m.add("bit_rate", (size / m.get("duration")) * 8)

    if m.exists("frames") and m.exists(
            "duration") and m.exists("frame_rate") is False:
        m.add("frame_rate", int(m.get("frames") / m.get("duration")))
    """If we have some values then return them if not then return False"""
    if m.empty() is False:
        return m

    return False
Exemple #3
0
	def test_sample_media(self):
		samples = [ f for f in listdir(self.tmp_dir) if isfile(join(self.tmp_dir,f)) ]
		for sample in samples:
			print "Probing " + sample
			metadata = FFProbe(self.tmp_dir + "/" + sample)
			print "HTML5 Media Source Type: " + metadata.html5SourceType()
			self.assertNotEqual(metadata.durationSeconds(), 0.0)
			self.assertNotEqual(metadata.bitrate(), 0.0)
			for stream in metadata.streams:
				if stream.isAudio() or stream.isVideo():
					self.assertNotEqual(stream.durationSeconds(), 0.0)

				if stream.isVideo():
					self.assertNotEqual(stream.frameSize(), (0,0))
Exemple #4
0
    def test_sample_media(self):
        samples = [
            f for f in listdir(self.tmp_dir) if isfile(join(self.tmp_dir, f))
        ]
        for sample in samples:
            print("Probing " + sample)
            metadata = FFProbe(self.tmp_dir + "/" + sample)
            print("HTML5 Media Source Type: " + metadata.html5SourceType())
            self.assertNotEqual(metadata.durationSeconds(), 0.0)
            self.assertNotEqual(metadata.bitrate(), 0.0)
            for stream in metadata.streams:
                if stream.isAudio() or stream.isVideo():
                    self.assertNotEqual(stream.durationSeconds(), 0.0)

                if stream.isVideo():
                    self.assertNotEqual(stream.frameSize(), (0, 0))