From 124772aaeb572c3c5250b7a3d04a0c9c9de23061 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Tronel?= Date: Sat, 2 Dec 2023 17:29:36 +0100 Subject: [PATCH] Closing of memory filedescriptor right after their usage (to save memory). --- removeads.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/removeads.py b/removeads.py index cff3e6f..206cf89 100755 --- a/removeads.py +++ b/removeads.py @@ -458,6 +458,7 @@ def extractAllStreams(inputFile, begin, end, streams, filesPrefix, nbFrames, wid videoID=0 audioID=0 subTitleID=0 + memfds = [] for stream in streams: if stream['codec_type'] == 'video': logger.info("Extracting video stream v:%d" % videoID) @@ -485,7 +486,9 @@ def extractAllStreams(inputFile, begin, end, streams, filesPrefix, nbFrames, wid codec = stream['codec_name'] imagesBytes, memfd = extractPictures(inputFile=inputFile, begin=begin, nbFrames=nbFrames, width=width, height=height) if imagesBytes == None: - sys.exit(-1) + exit(-1) + + memfds.append(memfd) if dumpMemFD: dumpPPM(imagesBytes, '%s-%d' % (filesPrefix,videoID), temporaries) @@ -517,6 +520,11 @@ def extractAllStreams(inputFile, begin, end, streams, filesPrefix, nbFrames, wid soundBytes , memfd = extractSound(inputFile=inputFile, begin=begin, nbPackets=nbPackets, packetDuration=packetDuration, outputFileName=tmpname, sampleRate=sampleRate, nbChannels=nbChannels) + if soundBytes == None: + exit(-1) + + memfds.append(memfd) + if dumpMemFD: try: output = open(tmpname,'w') @@ -575,6 +583,9 @@ def extractAllStreams(inputFile, begin, end, streams, filesPrefix, nbFrames, wid temporaries.append(output) + for memfd in memfds: + close(memfd) + return output else: