decoder multithreading
This commit is contained in:
		
							
								
								
									
										19
									
								
								pve.py
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								pve.py
									
									
									
									
									
								
							@ -14,6 +14,7 @@
 | 
			
		||||
# You should have received a copy of the GNU General Public License along with People's Video Editor.
 | 
			
		||||
# If not, see <https://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
import multiprocessing
 | 
			
		||||
import cProfile
 | 
			
		||||
 | 
			
		||||
from pyav.demuxer import Demuxer
 | 
			
		||||
@ -25,10 +26,15 @@ print(f"nb_streams  = {demuxer.nb_streams}")
 | 
			
		||||
print(f"video codec = {demuxer.video_stream.codec.description()}")
 | 
			
		||||
print(f"audio codec = {demuxer.audio_stream.codec.description()}")
 | 
			
		||||
 | 
			
		||||
video_decoder = Decoder(demuxer.video_stream)
 | 
			
		||||
audio_decoder = Decoder(demuxer.audio_stream)
 | 
			
		||||
cpu_count = multiprocessing.cpu_count()
 | 
			
		||||
 | 
			
		||||
num_frames = 0
 | 
			
		||||
print(f"using {cpu_count} threads for video decoding")
 | 
			
		||||
 | 
			
		||||
video_decoder = Decoder(demuxer.video_stream, cpu_count)
 | 
			
		||||
audio_decoder = Decoder(demuxer.audio_stream, 1)
 | 
			
		||||
 | 
			
		||||
num_video_frames = 0
 | 
			
		||||
num_audio_frames = 0
 | 
			
		||||
 | 
			
		||||
with cProfile.Profile() as pr:
 | 
			
		||||
    while True:
 | 
			
		||||
@ -36,13 +42,12 @@ with cProfile.Profile() as pr:
 | 
			
		||||
        eof = (packet is None)
 | 
			
		||||
        if eof or demuxer.video_stream.contains(packet):
 | 
			
		||||
            video_frames = video_decoder.decode(packet)
 | 
			
		||||
            num_frames += len(video_frames)
 | 
			
		||||
            # print(f"decoded {len(video_frames)} video frames")
 | 
			
		||||
            num_video_frames += len(video_frames)
 | 
			
		||||
        if eof or demuxer.audio_stream.contains(packet):
 | 
			
		||||
            audio_frames = audio_decoder.decode(packet)
 | 
			
		||||
            # print(f"decoded {len(audio_frames)} audio frames")
 | 
			
		||||
            num_audio_frames += len(audio_frames)
 | 
			
		||||
        if eof:
 | 
			
		||||
            break
 | 
			
		||||
 | 
			
		||||
print(f"num frames: {num_frames}")
 | 
			
		||||
print(f"num video frames: {num_video_frames}, audio frames: {num_audio_frames}")
 | 
			
		||||
pr.print_stats()
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user