Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 管道pi和x27;将opencv视频转换为ffmpeg,用于Youtube流媒体_Python 3.x_Opencv_Ffmpeg_Raspberry Pi_Opencv3.1 - Fatal编程技术网

Python 3.x 管道pi和x27;将opencv视频转换为ffmpeg,用于Youtube流媒体

Python 3.x 管道pi和x27;将opencv视频转换为ffmpeg,用于Youtube流媒体,python-3.x,opencv,ffmpeg,raspberry-pi,opencv3.1,Python 3.x,Opencv,Ffmpeg,Raspberry Pi,Opencv3.1,这是一个使用OpenCV读取picam的小python3脚本: #picamStream.py import sys, os from picamera.array import PiRGBArray from picamera import PiCamera import time import cv2 # initialize the camera and grab a reference to the raw camera capture camera = PiCamera() cam

这是一个使用OpenCV读取picam的小python3脚本:

#picamStream.py

import sys, os
from picamera.array import PiRGBArray
from picamera import PiCamera
import time
import cv2

# initialize the camera and grab a reference to the raw camera capture
camera = PiCamera()
camera.resolution = (960, 540)
camera.framerate = 30
rawCapture = PiRGBArray(camera, size=(960, 540))

# allow the camera to warmup
time.sleep(0.1)

# capture frames from the camera
for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):

    image = frame.array

    # ---------------------------------
    # .
    # Opencv image processing goes here
    # .
    # ---------------------------------

    os.write(1, image.tostring())

    # clear the stream in preparation for the next frame
    rawCapture.truncate(0)

# end
我正试图通过管道将其传输到ffmpeg到Youtube流

我的理解是,我需要参考下面两个命令,以某种方式提出一个新的ffmpeg命令

将picam实时视频传输到ffmpeg,用于Youtube流媒体。 raspivid-o--t0-vf-hf-w960-h540-fps25-b1000000 | ffmpeg-re-ar44100-ac2-acodec pcm_s16le-fs16le-ac2-i/dev/zero-fh264-i--vcodec copy-acodec aac-ab 128k-g50-strict experical-f flvrtmp://a.rtmp.youtube.com/live2/[流键]

将OPENCV原始视频传输到mp4文件的ffmpeg。 python3 picamStream.py | ffmpeg-f原始视频-像素格式bgr24-视频大小960x540-帧速率30-i-foo.mp4


到目前为止,我运气不好。有人能帮我吗?

这是我在raspberry pi中使用的程序

#main.py

import subprocess 
import cv2

cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)

command = ['ffmpeg',
            '-f', 'rawvideo',
            '-pix_fmt', 'bgr24',
            '-s','640x480',
            '-i','-',
            '-ar', '44100',
            '-ac', '2',
            '-acodec', 'pcm_s16le',
            '-f', 's16le',
            '-ac', '2',
            '-i','/dev/zero',   
            '-acodec','aac',
            '-ab','128k',
            '-strict','experimental',
            '-vcodec','h264',
            '-pix_fmt','yuv420p',
            '-g', '50',
            '-vb','1000k',
            '-profile:v', 'baseline',
            '-preset', 'ultrafast',
            '-r', '30',
            '-f', 'flv', 
            'rtmp://a.rtmp.youtube.com/live2/[STREAMKEY]']

pipe = subprocess.Popen(command, stdin=subprocess.PIPE)

while True:
    _, frame = cap.read()
    pipe.stdin.write(frame.tostring())

pipe.kill()
cap.release()
Youtube需要音频源,所以使用-i/dev/zero

我希望它能帮助你