FFMPEG_BIN = 'ffmpeg' SOURCE = 'YOUR RTMP INPUT STREAM HERE' DESTINATION = 'YOUR RTMP PROCESSED OUTPUT STREAM' FRAME_WIDTH = 1280 FRAME_HEIGHT = 720 import subprocess as sp cmd_video_only_in = [ FFMPEG_BIN, '-i', SOURCE, '-f', 'image2pipe', '-pix_fmt', 'bgr24', '-vcodec', 'rawvideo','-'] video_input_stream = sp.Popen(cmd_video_only_in, stdout=sp.PIPE, bufsize=FRAME_WIDTH*FRAME_HEIGHT*3, shell=False) cmd_processed_stream_out = [FFMPEG_BIN,'-y','-thread_queue_size', '1024','-f', 'rawvideo', '-pix_fmt', 'bgr24', '-video_size', str(FRAME_WIDTH)+'X'+str(FRAME_HEIGHT),'-i','-','-itsoffset','-2','-i', SOURCE,'-map','0:v:0','-map','1:a:0','-vcodec','libx264','-pix_fmt','yuv420p','-acodec','copy','-preset','ultrafast','-f','flv',DESTINATION] processed_output_stream = sp.Popen(cmd_processed_stream_out, stdin=sp.PIPE, shell=False) import cv2 import numpy as np import time while (True): raw_image = video_input_stream.stdout.read(FRAME_WIDTH*FRAME_HEIGHT*3) image = np.fromstring(raw_image, dtype='uint8') image = image.reshape((FRAME_HEIGHT,FRAME_WIDTH,3)) #Process the image TODO processed_output_stream.stdin.write(image.tostring()) video_input_stream.stdout.flush() if cv2.waitKey(25) & 0xFF == ord('q'): video_input_stream.terminate() processed_output_stream.stdin.close() processed_output_stream.terminate() break