diff --git a/removeads.py b/removeads.py index 28c0260..d1cd0e6 100755 --- a/removeads.py +++ b/removeads.py @@ -250,6 +250,18 @@ def getTSFrame(frame): ts = timedelta(seconds=pts_time) return ts +def getPacketDuration(packet): + if 'duration' in packet: + duration = int(packet['duration']) + elif 'pkt_duration' in packet: + duration = int(packet['pkt_duration']) + else: + logger.error('Impossible to find duration of packet %s' % packet) + return None + + return duration + + def getFramesInStream(inputFile, begin, end, streamKind, subStreamId=0): logger = logging.getLogger(__name__) infd = inputFile.fileno() @@ -537,7 +549,9 @@ def extractAllStreams(inputFile, begin, end, streams, filesPrefix, nbFrames, wid nbPackets = len(packets) logger.debug("Found %d packets to be extracted from audio track." % nbPackets) if(nbPackets > 0): - packetDuration = packets[0]['duration'] + packetDuration = getPacketDuration(packets[0]) + if packetDuration == None: + return None tmpname = '%s-%d.pcm' % (filesPrefix,audioID)