How to use ffmpeg-python to streaming webcam on facebook

Viewed 40

That's my code, so as i run it, facebook alerts "No audio on incoming stream".

How can i streaming my webcam with audio?

Not forgetting that I want to manipulate the images during the transmission, so the while reason.

import ffmpeg
import cv2
        
input = ffmpeg.input('pipe:', r='6')
        
process = (
    input.filter('fps', fps=50, round='up')
    .output(
        "rtmps://live-api-s.facebook.com:443/rtmp/xxxxxxxxxxxxxxxxxxxxx", 
        acodec='aac', 
        ac=1, 
        ar='16k',
        vcodec='libx264', 
        #acodec='aac',
        pix_fmt='yuv420p', 
        preset='veryfast',
        r='20', 
        g='50', 
        video_bitrate='1.4M', 
        maxrate='2M', 
        bufsize='2M', 
        segment_time='6',
        format='flv'
    )
    .global_args("-re")
    .run_async(pipe_stdin=True)
)
        
        
        
def camera_video():
    try:
        
        while True:
            ret, img = cap.read()
            if ret:
                #bs = img.tobytes()
                ret2, frame2 = cv2.imencode('.png', img)
                process.stdin.write(frame2.tobytes())
                # cv2.imshow('frame', img)
            if cv2.waitKey(1) & 0xFF == ord('q'):
                break
    except:
        # close output window
        cv2.destroyAllWindows()
        cap.release()
        
        
cap = cv2.VideoCapture(0)
camera_video()

cv2.destroyAllWindows()
cap.release()
0 Answers
Related