|  |  | @ -3,7 +3,6 @@ import os | 
			
		
	
		
		
			
				
					
					|  |  |  | import pickle |  |  |  | import pickle | 
			
		
	
		
		
			
				
					
					|  |  |  | import struct |  |  |  | import struct | 
			
		
	
		
		
			
				
					
					|  |  |  | import subprocess |  |  |  | import subprocess | 
			
		
	
		
		
			
				
					
					|  |  |  | import tempfile |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | import threading |  |  |  | import threading | 
			
		
	
		
		
			
				
					
					|  |  |  | from enum import IntEnum |  |  |  | from enum import IntEnum | 
			
		
	
		
		
			
				
					
					|  |  |  | from functools import wraps |  |  |  | from functools import wraps | 
			
		
	
	
		
		
			
				
					|  |  | @ -168,31 +167,21 @@ def rgb24tonv12(rgb): | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | def decompress_video_data(rawdat, vid_fmt, w, h, pix_fmt): |  |  |  | def decompress_video_data(rawdat, vid_fmt, w, h, pix_fmt): | 
			
		
	
		
		
			
				
					
					|  |  |  |   # using a tempfile is much faster than proc.communicate for some reason |  |  |  |   threads = os.getenv("FFMPEG_THREADS", "0") | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |   cuda = os.getenv("FFMPEG_CUDA", "0") == "1" | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |   with tempfile.TemporaryFile() as tmpf: |  |  |  |   args = ["ffmpeg", "-v", "quiet", | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     tmpf.write(rawdat) |  |  |  |           "-threads", threads, | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     tmpf.seek(0) |  |  |  |           "-hwaccel", "none" if not cuda else "cuda", | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |           "-c:v", "hevc", | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     threads = os.getenv("FFMPEG_THREADS", "0") |  |  |  |           "-vsync", "0", | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     cuda = os.getenv("FFMPEG_CUDA", "0") == "1" |  |  |  |           "-f", vid_fmt, | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     args = ["ffmpeg", |  |  |  |           "-flags2", "showall", | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             "-threads", threads, |  |  |  |           "-i", "-", | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             "-hwaccel", "none" if not cuda else "cuda", |  |  |  |           "-threads", threads, | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             "-c:v", "hevc", |  |  |  |           "-f", "rawvideo", | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             "-vsync", "0", |  |  |  |           "-pix_fmt", pix_fmt, | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             "-f", vid_fmt, |  |  |  |           "-"] | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             "-flags2", "showall", |  |  |  |   dat = subprocess.check_output(args, input=rawdat) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             "-i", "pipe:0", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             "-threads", threads, |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             "-f", "rawvideo", |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             "-pix_fmt", pix_fmt, |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             "pipe:1"] |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     with subprocess.Popen(args, stdin=tmpf, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL) as proc: |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |       # dat = proc.communicate()[0] |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |       dat = proc.stdout.read() |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |       if proc.wait() != 0: |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         raise DataUnreadableError("ffmpeg failed") |  |  |  |  | 
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |   if pix_fmt == "rgb24": |  |  |  |   if pix_fmt == "rgb24": | 
			
		
	
		
		
			
				
					
					|  |  |  |     ret = np.frombuffer(dat, dtype=np.uint8).reshape(-1, h, w, 3) |  |  |  |     ret = np.frombuffer(dat, dtype=np.uint8).reshape(-1, h, w, 3) | 
			
		
	
	
		
		
			
				
					|  |  | 
 |