import cv2
import subprocess as sp
cam = cv2.VideoCapture(0)
img_counter = 0
ret, frame = cam.read()
WIDTH = frame.shape[1]
HEIGHT = frame.shape[0]
RTMP_URL = 'rtmp://192.168.0.115:1935/live/test'
FPS = 24
def ffpemgtortmp(width, height, recivedrtmp_addr, fps):
print(recivedrtmp_addr)
command = ['ffmpeg',
'-y',
'-f', 'rawvideo',
'-vcodec', 'rawvideo',
'-pix_fmt', 'bgr24',
'-s', "{}x{}".format(width, height),
'-r', str(fps),
'-i', '-',
'-c:v', 'libx264',
'-pix_fmt', 'yuv420p',
'-preset', 'ultrafast',
'-f', 'flv',
recivedrtmp_addr]
print('command', command)
p = sp.Popen(command, stdin=sp.PIPE)
return p
def main():
p = ffpemgtortmp(WIDTH, HEIGHT, RTMP_URL, FPS)
while cam.isOpened():
ret, frame = cam.read()
#print(frame.shape[0])
p.stdin.write(frame.tostring())
print('send frame')
if __name__ == '__main__':
main()