Closing of memory filedescriptor right after their usage (to save memory).
This commit is contained in:
		
							
								
								
									
										13
									
								
								removeads.py
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								removeads.py
									
									
									
									
									
								
							| @@ -458,6 +458,7 @@ def extractAllStreams(inputFile, begin, end, streams, filesPrefix, nbFrames, wid | |||||||
|         videoID=0 |         videoID=0 | ||||||
|         audioID=0 |         audioID=0 | ||||||
|         subTitleID=0 |         subTitleID=0 | ||||||
|  |         memfds = [] | ||||||
|         for stream in streams: |         for stream in streams: | ||||||
|             if stream['codec_type'] == 'video': |             if stream['codec_type'] == 'video': | ||||||
|                 logger.info("Extracting video stream v:%d" % videoID) |                 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'] |                 codec = stream['codec_name'] | ||||||
|                 imagesBytes, memfd = extractPictures(inputFile=inputFile, begin=begin, nbFrames=nbFrames, width=width, height=height) |                 imagesBytes, memfd = extractPictures(inputFile=inputFile, begin=begin, nbFrames=nbFrames, width=width, height=height) | ||||||
|                 if imagesBytes == None: |                 if imagesBytes == None: | ||||||
|                     sys.exit(-1) |                     exit(-1) | ||||||
|  |                  | ||||||
|  |                 memfds.append(memfd) | ||||||
|                  |                  | ||||||
|                 if dumpMemFD: |                 if dumpMemFD: | ||||||
|                     dumpPPM(imagesBytes, '%s-%d' % (filesPrefix,videoID), temporaries) |                     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) |                 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: |                 if dumpMemFD: | ||||||
|                     try: |                     try: | ||||||
|                         output = open(tmpname,'w') |                         output = open(tmpname,'w') | ||||||
| @@ -575,6 +583,9 @@ def extractAllStreams(inputFile, begin, end, streams, filesPrefix, nbFrames, wid | |||||||
|          |          | ||||||
|             temporaries.append(output) |             temporaries.append(output) | ||||||
|          |          | ||||||
|  |         for memfd in memfds: | ||||||
|  |             close(memfd) | ||||||
|  |          | ||||||
|         return output |         return output | ||||||
|          |          | ||||||
|     else: |     else: | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user