Как отправить кадр захвата камеры на потоковую передачу YouTube с помощью ffmpegPython

Программы на Python
Ответить Пред. темаСлед. тема
Anonymous
 Как отправить кадр захвата камеры на потоковую передачу YouTube с помощью ffmpeg

Сообщение Anonymous »


import subprocess import cv2 # YouTube streaming settings YOUTUBE_URL = "rtmp://a.rtmp.youtube.com/live2/" KEY = "..." # OpenCV camera setup cap = cv2.VideoCapture(0) cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640) cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480) # FFmpeg command for streaming command = [r"C:\utility\ffmpeg\ffmpeg-2024-02-22-git-76b2bb96b4-full_build\ffmpeg-2024-02-22-git-76b2bb96b4-full_build\bin\ffmpeg.exe", '-f', 'rawvideo', '-pix_fmt', 'bgr24', '-s', '640x480', '-i', '-', '-ar', '44100', '-ac', '2', '-acodec', 'pcm_s16le', '-f', 's16le', '-ac', '2', '-i', 'NUL', '-acodec', 'aac', '-ab', '128k', '-strict', 'experimental', '-vcodec', 'h264', '-pix_fmt', 'yuv420p', '-g', '50', '-vb', '1000k', '-profile:v', 'baseline', '-preset', 'ultrafast', '-r', '30', '-f', 'flv', f"{YOUTUBE_URL}/{KEY}",] # Open a subprocess with FFmpeg pipe = subprocess.Popen(command, stdin=subprocess.PIPE) while True: # Read a frame from the camera ret, frame = cap.read() if not ret: break # Display the frame cv2.imshow('Frame', frame) cv2.waitKey(1) # Wait for 1ms # Send the frame through the pipe for streaming pipe.stdin.write(frame.tobytes()) # Check for 'q' key press to stop streaming if cv2.waitKey(1) & 0xFF == ord('q'): break # Release resources cap.release() cv2.destroyAllWindows() I'm trying to implement capturing the camera screen using opencv and transmitting this frame to the YouTube streaming broadcast via ffmpeg. YouTube streaming does start when I run this code. However, it appears to be a black screen, not a camera screen. I don't see what the problem is.

I didn't even start streaming at first, but I changed the command option to various things, and when I ran the code, I succeeded in starting streaming. There are many references to transmitting mp4, but there are not many references to transmitting real-time capture. I'm going to process the camera screen using opencv and then send it to streaming. I don't know what the problem is. Please help me.


Источник: https://stackoverflow.com/questions/780 ... ing-ffmpeg
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Python»