gpt4 book ai didi

python - YouTube 没有从我的 FFmpeg 流向 RTMP 服务器接收任何数据

转载 作者:行者123 更新时间:2023-12-03 06:05:15 25 4
gpt4 key购买 nike

所以我在我的计算机上运行了一个 Python 程序,它每秒将相同的图像发送到 RTMP 服务器:它正在读取图像,然后发送数据。从控制台看来一切正常,但 YouTube 表示它没有收到任何数据。
这是我的代码:

import subprocess
import cv2
rtmp_url = "rtmp://b.rtmp.youtube.com/live2/<valid-rtmp-id>"

fps = 1.5

width = 600
height = 600

# command and params for ffmpeg
command = ['ffmpeg',
'-y',
'-f', 'rawvideo',
'-vcodec', 'rawvideo',
'-pix_fmt', 'bgr24',
'-s', "{}x{}".format(width, height),
'-r', str(fps),
'-i', '-',
'-c:v', 'libx264',
'-pix_fmt', 'yuv420p',
'-f', 'flv',
rtmp_url]

# using subprocess and pipe to fetch frame data
p = subprocess.Popen(command, stdin=subprocess.PIPE)

while True:
f = cv2.imread('assets/temporary.png')

p.stdin.write(f.tobytes())
我的控制台的输出是:
[rtmp @ 0x28d9940] Server response validating failed
<VideoCapture 0x7f60895dafb0>
ffmpeg version 3.4.8-0ubuntu0.2 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
configuration: --prefix=/usr --extra-version=0ubuntu0.2 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libavresample 3. 7. 0 / 3. 7. 0
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
Input #0, rawvideo, from 'pipe:':
Duration: N/A, start: 0.000000, bitrate: 12960 kb/s
Stream #0:0: Video: rawvideo (BGR[24] / 0x18524742), bgr24, 600x600, 12960 kb/s, 1.50 fps, 1.50 tbr, 1.50 tbn, 1.50 tbc
Stream mapping:
Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
[libx264 @ 0x5613ba2e3d40] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x5613ba2e3d40] profile High, level 2.2
[libx264 @ 0x5613ba2e3d40] 264 - core 152 r2854 e9a5903 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=1 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, flv, to 'rtmp://b.rtmp.youtube.com/live2/<key>':
Metadata:
encoder : Lavf57.83.100
Stream #0:0: Video: h264 (libx264) ([7][0][0][0] / 0x0007), yuv420p, 600x600, q=-1--1, 1.50 fps, 1k tbn, 1.50 tbc
Metadata:
encoder : Lavc57.107.100 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
frame= 55 fps=0.0 q=19.0 size= 20kB time=00:00:01.33 bit

最佳答案

YouTube 需要音频。使用 anullsrc filter生成静音音频。

import subprocess
import cv2
rtmp_url = "rtmp://b.rtmp.youtube.com/live2/<valid-rtmp-id>"

fps = 1.5

width = 600
height = 600

# command and params for ffmpeg
command = ['ffmpeg',
'-y',
'-f', 'rawvideo',
'-pixel_format', 'bgr24',
'-video_size', "{}x{}".format(width, height),
'-framerate', str(fps),
'-i', '-',
'-re',
'-f', 'lavfi',
'-i', 'anullsrc',
'-c:v', 'libx264',
'-c:a', 'aac',
'-vf', 'format=yuv420p',
'-f', 'flv',
rtmp_url]

# using subprocess and pipe to fetch frame data
p = subprocess.Popen(command, stdin=subprocess.PIPE)

while True:
f = cv2.imread('assets/temporary.png')

p.stdin.write(f.tobytes())
  • 我怀疑 YouTube 是否喜欢 1.5 fps,但我没有测试。如果是这种情况,请添加 -r 10输出选项。
  • 最好同时添加 -g , -b:v , -maxrate , 和 -bufsize streaming 时的选项.
  • 关于python - YouTube 没有从我的 FFmpeg 流向 RTMP 服务器接收任何数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64745099/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com