Add a function to retrieve packet duration compatible with multiple ffmpeg versions.

This commit is contained in:
Frédéric Tronel
2023-12-02 21:11:59 +01:00
parent 9a8f97a278
commit 1ed4bbf6df

View File

@@ -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)