Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def openRaw(info):
- ret = None
- command = [
- FFMPEG_BIN,
- '-i', 'raw.mkv',
- '-f', 'image2pipe',
- '-pix_fmt', 'rgb24',
- '-vcodec', 'rawvideo',
- '-']
- ret = subprocess.Popen(command, stdout = subprocess.PIPE, bufsize=((2**10)**2)*5)
- return ret
- def openOut(info):
- # this does supply a context for with blocks. Magically.
- ret = None
- _szStr = str(1280) + "x" + str(720)
- # new attempts
- command = [
- FFMPEG_BIN,
- # input options
- '-f', 'rawvideo',
- '-vcodec', 'rawvideo',
- '-s', _szStr, # size of one frame
- '-pix_fmt', 'rgb24',
- '-r', str(info.fps), # frames per second
- '-i', '-', # The first input comes from a pipe
- '-i', 'raw.mkv', # the second input is the raw file
- # output options
- '-vcodec', 'libx264', # x264 you say?
- # '-preset', 'ultrafast', # preset tuning, 1
- '-preset', 'slow', # preset tuning, 1
- '-tune', 'animation', # preset tuning, 2
- '-crf', '0', # lossless, you say?
- '-acodec', 'aac', # aac - What?
- '-ac', '2', # audio channel count, stereo
- '-ab', '384000', # 384 kb/s (Youtube for stereo)
- # '-ab', '98000', # 98k for testss
- '-aac_coder', 'twoloop', # fancy output tuner
- # muxer options
- '-map', '0:v:0', # first inputs video
- '-map', '1:a:0', # second inputs audio
- 'out.mkv'
- ]
- ret = subprocess.Popen(command, stdin=subprocess.PIPE, bufsize=(2**20))
- return ret
- with openRaw(info) as vin:
- with openOut(info) as vout:
- while True:
- raw_image = vin.stdout.read(info.width*info.height*3)
- if not raw_image:
- break
- else:
- rawImage = Image.frombytes(
- "RGB",
- (info.width, info.height),
- raw_image
- )
- # video processing on new image happens here
- outImage = procImage(rawImage, globals)
- vout.stdin.write(outImage.tobytes())
- vin.stdout.flush()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement