Python-Opencv Write x264 video on memory buffer
<p>I have a problem for writing x264 video(or single frame) on memory buffer. In opencv for images, imencode and imdecode do this task. But i want save x264 video frame for lower memory usage and sending on internet. I am able to with jpeg but jpeg size bigger than x264 video frame and quality much worser. I searched but i can't find how i write video frame on buffer. </p>

<p>Here is the example code to taking frames on webcam</p>

<pre><code>        import numpy as np
        import cv2


        cap = cv2.VideoCapture(0)
        cap.set(3,320)
        cap.set(4,240)
        cap.set(5,30)
        # Define the codec and create VideoWriter object
        fourcc = cv2.VideoWriter_fourcc(*'x264')
        out = cv2.VideoWriter('.....sample.avi',fourcc, 30.0, (320,240))

        while(cap.isOpened()):
            ret, frame = cap.read()
            if ret==True:
                cv2.imshow('frame',frame)
                out.write(frame) #I want to write memory not disk
                if cv2.waitKey(1) &amp; 0xFF == ord('q'):
                    break
            else:
                break

        # Release everything if job is finished
        cap.release()
        out.release()
        cv2.destroyAllWindows()
</code></pre>