Advertisement
Guest User

Untitled

a guest
Sep 21st, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.70 KB | None | 0 0
  1. def openRaw(info):
  2.     ret = None
  3.    
  4.     command = [
  5.                 FFMPEG_BIN,
  6.                 '-i', 'raw.mkv',
  7.                 '-f', 'image2pipe',
  8.                 '-pix_fmt', 'rgb24',
  9.                 '-vcodec', 'rawvideo',
  10.                 '-']
  11.                
  12.     ret = subprocess.Popen(command, stdout = subprocess.PIPE, bufsize=((2**10)**2)*5)
  13.     return ret
  14.    
  15. def openOut(info):
  16.     # this does supply a context for with blocks. Magically.
  17.     ret = None
  18.    
  19.     _szStr = str(1280) + "x" + str(720)
  20.    
  21.     # new attempts
  22.     command = [
  23.                 FFMPEG_BIN,
  24.                 # input options
  25.                 '-f',       'rawvideo',
  26.                 '-vcodec',  'rawvideo',
  27.                 '-s',       _szStr, # size of one frame
  28.                 '-pix_fmt', 'rgb24',
  29.                 '-r',       str(info.fps), # frames per second
  30.                 '-i',       '-',           # The first input comes from a pipe
  31.                 '-i',       'raw.mkv',     # the second input is the raw file
  32.                 # output options
  33.                 '-vcodec', 'libx264',    # x264 you say?
  34.                 # '-preset', 'ultrafast',  # preset tuning, 1
  35.                 '-preset', 'slow',  # preset tuning, 1
  36.                 '-tune',   'animation',  # preset tuning, 2
  37.                 '-crf',    '0',          # lossless, you say?
  38.                 '-acodec', 'aac',        # aac - What?
  39.                 '-ac', '2',              # audio channel count, stereo
  40.                 '-ab', '384000',         # 384 kb/s (Youtube for stereo)
  41.                 # '-ab', '98000',         # 98k for testss
  42.                 '-aac_coder', 'twoloop', # fancy output tuner
  43.                 # muxer options
  44.                 '-map', '0:v:0',         # first inputs video
  45.                 '-map', '1:a:0',         # second inputs audio
  46.                 'out.mkv'
  47.               ]
  48.    
  49.     ret = subprocess.Popen(command, stdin=subprocess.PIPE, bufsize=(2**20))
  50.    
  51.     return ret
  52.  
  53. with openRaw(info) as vin:
  54.     with openOut(info) as vout:
  55.         while True:
  56.             raw_image = vin.stdout.read(info.width*info.height*3)
  57.            
  58.             if not raw_image:
  59.                 break
  60.            
  61.             else:
  62.                 rawImage = Image.frombytes(
  63.                                             "RGB",
  64.                                             (info.width, info.height),
  65.                                             raw_image
  66.                                           )
  67.                
  68.                 # video processing on new image happens here
  69.                 outImage = procImage(rawImage, globals)
  70.                
  71.                 vout.stdin.write(outImage.tobytes())
  72.                 vin.stdout.flush()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement