如何使用FFmpeg将网络摄像头直播到YouTube? [英] How to livestream a webcam to YouTube with FFmpeg?

查看:440
本文介绍了如何使用FFmpeg将网络摄像头直播到YouTube?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将我的网络摄像头的实时流发送到YouTube.我可以按照 YouTube指南进行第8步.流连接"告诉我无数据"和上线"按钮保持不可单击状态.可以在

I want to send the livestream of my webcam to YouTube. I can follow YouTube's guide up to step 8. "Stream Connection" tells me there is "No data" and the button "Go Live" remains unclickable. A screenshot of this situation can be seen at

作为编码软件,我正计划使用FFmpeg,因为它可以从目标平台(带有Raspbian的Raspberry Pi)运行.使用video4linux2支持的USB网络摄像头.

As encoding software, I was planning on using FFmpeg because it can run from the target platform, a Raspberry Pi with Raspbian. A USB webcam supported by video4linux2 is used.

FFmpeg的Wiki 表明,可以通过以下方式完成文件流传输:

FFmpeg's wiki shows that streaming a file can be done with the following:

ffmpeg -re -i input.mkv \
-c:v libx264 -preset veryfast -maxrate 3000k \
-bufsize 6000k -pix_fmt yuv420p -g 50 -c:a aac -b:a 160k -ac 2 \
-ar 44100 -f flv rtmp://live.twitch.tv/app/<stream key>

我通过以下方式修改了此命令: 1.它使用-f v4l2 -i /dev/video0从网络摄像头获取视频流. 2.它不使用-an广播任何音频. 3.它广播到YouTube的RTMP服务器rtmp://a.rtmp.youtube.com/live2/<stream key>

I modified this command in the following ways: 1. It takes the video stream from the webcam with -f v4l2 -i /dev/video0. 2. It does not broadcast any audio with -an. 3. It broadcasts to YouTube's RTMP server, rtmp://a.rtmp.youtube.com/live2/<stream key>

命令的最终版本现在是:

The final version of the command is now:

RTMP_URL="rtmp://a.rtmp.youtube.com/live2"
STREAM_KEY="secr-etse-cret-secr"
OUTPUT=$RTMP_URL/$STREAM_KEY
ffmpeg -re -f v4l2 -i /dev/video0 \
-c:v libx264 -preset veryfast -maxrate 3000k \
-bufsize 6000k -pix_fmt yuv420p -g 50 -an \
-f flv $OUTPUT

当我运行此命令时,我希望几秒钟后流连接"将变为无数据"之外的其他内容,但这不会发生.

When I run this command, I would expect that "Stream connection" would change to something else than "No data" after a few seconds, but that does not happen.

我尝试使用以下方式将流记录到本地文件中:

I have tried recording the stream to a local file with:

ffmpeg -re -f v4l2 -i /dev/video0 \
-c:v libx264 -preset veryfast -maxrate 3000k \
-bufsize 6000k -pix_fmt yuv420p -g 50 -an \
-f flv test.flv

这很好.这向我证明了问题在于如何使视频流被YouTube接受.

This worked fine. That demonstrates to me that the issue is with getting the video stream accepted by YouTube.

推荐答案

下面的代码在Windows上可以很好地运行,您可以根据需要进行调整

The code below works very well using Windows, you may adjust to fit for your need

ffmpeg -loglevel debug -threads:v 2 -threads:a 8 -filter_threads 2 -thread_queue_size 512  -f dshow -i video="HP Wide Vision HD" -f dshow -i audio="Microphone Array (Realtek Audio)" -pix_fmt yuv420p -c:v libx264 -qp:v 19 -profile:v high -rc:v cbr_ld_hq -level:v 4.2 -r:v 60 -g:v 120 -bf:v 3 -refs:v 16 -f flv rtmp://youtube_stream_url/stream_key

这篇关于如何使用FFmpeg将网络摄像头直播到YouTube?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆