'python ffmpeg streaming to rtmp server "Unable to find a suitable output format"
I am trying to write a code to send the face redacted video to a rtmp stream. I am stuck at this error
[NULL @ 000002b631764dc0] Unable to find a suitable output format for 'rtmp://f7a22cf83cc841ceaf6f.channel.media.azure.net:1935/live/ffd956a1'
rtmp://f7a22cf83cc841ceaf6f.channel.media.azure.net:1935/live/5ffd956a1: Invalid argument
import cv2
import subprocess
rtmp_url = "rtmp://f7a22cf83cc841ceaf6f.channel.media.azure.net:1935/live/5ffd956a1"
video_cam = cv2.VideoCapture(0)
# gather video info to ffmpeg
fps = int(video_cam.get(cv2.CAP_PROP_FPS))
width = int(video_cam.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(video_cam.get(cv2.CAP_PROP_FRAME_HEIGHT))
print(width)
command = ['ffmpeg',
'-loglevel', 'error',
'-y',
# Input
'-f', 'rawvideo',
'-vcodec', 'rawvideo',
'-pix_fmt', 'bgr24',
'-s', str(width) + 'x' + str(height),
'-r', str(fps),
# Output
'-i', '-',
'-c:v', 'libx264',
'-preset', 'ultrafast',
'-vcodec', 'h264',
rtmp_url
]
print(command)
# using subprocess and pipe to fetch frame data
p = subprocess.Popen(command, stdin=subprocess.PIPE)
while True:
ret, image_frame = video_cam.read()
face_cascade = cv2.CascadeClassifier('Resources/haarcascade_frontalface_alt.xml')
faces = face_cascade.detectMultiScale(image_frame,1.3,5)
for (x,y,w,h) in faces:
cv2.rectangle(image_frame,(x,y),(x+w,y+h),(255.0,0),3)
face_color = image_frame[y:y + h, x:x + w]
blur = cv2.GaussianBlur(face_color, (51, 51), 0)
image_frame[y:y + h, x:x + w] = blur
cv2.imshow('Face Detected',image_frame)
# write to pipe
p.stdin.write(image_frame.tobytes())
if cv2.waitKey(1) & 0xFF == ord('q'):
break
video_cam.release()
cv2.destroyAllWindows()
This is the output of my ffmpeg command, if i print the command variable
['ffmpeg', '-loglevel', 'error', '-y', '-f', 'rawvideo', '-vcodec', 'rawvideo', '-pix_fmt', 'bgr24', '-s', '640x480', '-r', '30', '-i', '-', '-c:v', 'libx264', '-preset', 'ultrafast', '-vcodec', 'h264', 'rtmp://f7a22cf83cc841ceaf6fd7d2bd7fb019.channel.media.azure.net:1935/live/c9c612df89ca4722b942c425ffd956a1']
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
