Add a function to retrieve packet duration compatible with multiple ffmpeg versions.
This commit is contained in:
16
removeads.py
16
removeads.py
@@ -250,6 +250,18 @@ def getTSFrame(frame):
|
|||||||
ts = timedelta(seconds=pts_time)
|
ts = timedelta(seconds=pts_time)
|
||||||
return ts
|
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):
|
def getFramesInStream(inputFile, begin, end, streamKind, subStreamId=0):
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
infd = inputFile.fileno()
|
infd = inputFile.fileno()
|
||||||
@@ -537,7 +549,9 @@ def extractAllStreams(inputFile, begin, end, streams, filesPrefix, nbFrames, wid
|
|||||||
nbPackets = len(packets)
|
nbPackets = len(packets)
|
||||||
logger.debug("Found %d packets to be extracted from audio track." % nbPackets)
|
logger.debug("Found %d packets to be extracted from audio track." % nbPackets)
|
||||||
if(nbPackets > 0):
|
if(nbPackets > 0):
|
||||||
packetDuration = packets[0]['duration']
|
packetDuration = getPacketDuration(packets[0])
|
||||||
|
if packetDuration == None:
|
||||||
|
return None
|
||||||
|
|
||||||
tmpname = '%s-%d.pcm' % (filesPrefix,audioID)
|
tmpname = '%s-%d.pcm' % (filesPrefix,audioID)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user