Beispiel #1
0
 def __init__(self, f):
     FLV.__init__(self, f)
     self.metadata = None
     self.keyframes = FLVObject()
     self.keyframes.filepositions = []
     self.keyframes.times = []
     self.no_video = True
     self.audio_tag_number = 0
     self.first_media_tag_offset = None
Beispiel #2
0
 def __init__(self, f):
     FLV.__init__(self, f)
     self.metadata = None
     self.keyframes = FLVObject()
     self.keyframes.filepositions = []
     self.keyframes.times = []
     self.no_video = True
     self.audio_tag_number = 0
     self.first_media_tag_offset = None
Beispiel #3
0
	def __init__(self, f):
		FLV.__init__(self, f)
		
		try:
			st_size = os.stat(self.f.name)[6]
		except:
			print '[-] Could not stat() original file'
			return
		
		self.buffer = self.f.read(st_size)
		self.f.seek(0L)
Beispiel #4
0
    def __init__(self, f):
        FLV.__init__(self, f)

        try:
            st_size = os.stat(self.f.name)[6]
        except:
            print '[-] Could not stat() original file'
            return

        self.buffer = self.f.read(st_size)
        self.f.seek(0L)
Beispiel #5
0
class FLVPlayer(Player):
    """ Reads a FLV stream and emulates playout by advancing the stream as time passes """
    FILE_HEADER_SIZE = 9
    TAG_HEADER_SIZE = 15

    def __init__(self):
        Player.__init__(self)
        self._lastAudioTS = 0
        self._lastVideoTS = 0
        self.flv = FLV(self)

    def feed(self, data):
        """ input downloaded media data here piece by piece """
        self.put(data)

        # nothing parsed yet
        if self.tell() == 0:
            self.changeState(PlayerState.BUFFERING)
            if self.availBytes() >= self.FILE_HEADER_SIZE:
                self.flv.parse_header()
        else:
            tag = 0
            while tag != None:
                avail = self.availBytes()
                tag = None
                if avail >= self.TAG_HEADER_SIZE:
                    # peek for tag size
                    tag_type = get_ui8(self)
                    tag_size = get_ui24(self)
                    # log.debug("peek: %02X %u, available: %u" % (tag_type,tag_size,avail))
                    self.seek(-4, os.SEEK_CUR)
                    # size + next header size
                    if avail >= tag_size + self.TAG_HEADER_SIZE:
                        tag = self.flv.get_next_tag()
                        if type(tag) == VideoTag:
                            self._lastVideoTS = tag.timestamp
                            # log.debug("lastVideo: %u", self._lastVideoTS)
                        elif type(tag) == AudioTag:
                            self._lastAudioTS = tag.timestamp
                            # log.debug("lastAudio: %u", self._lastAudioTS)
            super(FLVPlayer, self).feed(data)

    def getLastMediaTimeStamp(self):
        """ get the presentation TS of the last complete frame """
        raise NotImplementedException()
        return min(self._lastVideoTS, self._lastAudioTS) / 1000.0

    def getBufferedSeconds(self, offset = 0):
        """ until when the buffer contains media """ 
        return  (min(self._lastVideoTS, self._lastAudioTS) / 1000.0) - offset
        
    def __str__(self):
        return ' FLVPlayer(unparsed bytes: %d, last A/V TS: %u/%u)' % \
            (self.availBytes(), self._lastAudioTS, self._lastVideoTS)
def retimestamp_tags_inplace(f, fu):
    flv = FLV(f)
    offset = None

    for tag in flv.iter_tags():
        if offset is None and is_nonheader_media(tag):
            offset = tag.timestamp
            log.debug("Determined the offset to be %d", offset)

        # optimise for offset == 0, which in case of inplace updating is a noop
        if offset is not None and offset != 0:
            fu.seek(tag.offset + 4, os.SEEK_SET)
            fu.write(make_si32_extended(tag.timestamp - offset))
Beispiel #7
0
def retimestamp_tags_inplace(f, fu):
    flv = FLV(f)
    offset = None

    for tag in flv.iter_tags():
        if offset is None and is_nonheader_media(tag):
            offset = tag.timestamp
            log.debug("Determined the offset to be %d", offset)

        # optimise for offset == 0, which in case of inplace updating is a noop
        if offset is not None and offset != 0:
            fu.seek(tag.offset + 4, os.SEEK_SET)
            fu.write(make_si32_extended(tag.timestamp - offset))
    def __init__(self, f):
        FLV.__init__(self, f)
        self.metadata = None
        self.keyframes = FLVObject()
        self.keyframes.filepositions = []
        self.keyframes.times = []
        self.no_video = True

        # If the FLV file has no video, there are no keyframes. We want to put
        # some info in the metadata anyway -- Flash players use keyframe
        # information as a seek table. In audio-only FLV files you can usually
        # seek to the beginning of any tag (this is not entirely true for AAC).
        # Most players still work if you just provide "keyframe" info that's
        # really a table of every Nth audio tag, even with AAC.
        # Because of that, until we see a video tag we make every Nth
        # IndexingAudioTag store its offset and timestamp.
        self.audio_tag_number = 0
        self.audio_seekpoints = FLVObject()
        self.audio_seekpoints.filepositions = []
        self.audio_seekpoints.times = []

        self.metadata_tag_start = None
        self.metadata_tag_end = None
        self.first_media_tag_offset = None
Beispiel #9
0
    def __init__(self, f):
        FLV.__init__(self, f)
        self.metadata = None
        self.keyframes = FLVObject()
        self.keyframes.filepositions = []
        self.keyframes.times = []
        self.no_video = True

        # If the FLV file has no video, there are no keyframes. We want to put
        # some info in the metadata anyway -- Flash players use keyframe
        # information as a seek table. In audio-only FLV files you can usually
        # seek to the beginning of any tag (this is not entirely true for AAC).
        # Most players still work if you just provide "keyframe" info that's
        # really a table of every Nth audio tag, even with AAC.
        # Because of that, until we see a video tag we make every Nth
        # IndexingAudioTag store its offset and timestamp.
        self.audio_tag_number = 0
        self.audio_seekpoints = FLVObject()
        self.audio_seekpoints.filepositions = []
        self.audio_seekpoints.times = []

        self.metadata_tag_start = None
        self.metadata_tag_end = None
        self.first_media_tag_offset = None
Beispiel #10
0
 def __init__(self):
     Player.__init__(self)
     self._lastAudioTS = 0
     self._lastVideoTS = 0
     self.flv = FLV(self)