gpt4 book ai didi

FFmpeg:将视频/音频流循环到 YouTube Live

转载 作者:行者123 更新时间:2023-12-04 22:54:47 26 4
gpt4 key购买 nike

我正在使用此脚本流式传输 30 秒 .mp4 .mp3 中带有 2 分钟音轨的视频文件格式:

#! /bin/bash

VBR="1500k"
FPS="30"
QUAL="ultrafast"
YOUTUBE_URL=" rtmp://a.rtmp.youtube.com/live2"
YOUTUBE_KEY="**********"
VIDEO_SOURCE="test_video_4.mp4"
AUDIO_SOURCE="test_audio_3.mp3"
AUDIO_ENCODER="aac"

ffmpeg \
-stream_loop -1 \
-re \
-i "$VIDEO_SOURCE" \
-thread_queue_size 512 \
-i "$AUDIO_SOURCE" \
-c:v libx264 -preset $QUAL -r $FPS -g $(($FPS *2)) -b:v $VBR \
-c:a $AUDIO_ENCODER -threads 6 -ar 44100 -b:a 128k -bufsize 512k -pix_fmt yuv420p \
-fflags +shortest -max_interleave_delta 50000 \
-f flv $YOUTUBE_URL/$YOUTUBE_KEY
音频和视频都在第一次正确播放,视频在音频播放完成时循环播放(因为它更短)。唯一的问题是 音频循环不起作用并且一旦音频第一次完成,流就会停止。
这是日志:

ffmpeg version 4.3.1 Copyright (c) 2000-2020 the FFmpeg developers
built with Apple clang version 12.0.0 (clang-1200.0.32.27)
configuration: --prefix=/usr/local/Cellar/ffmpeg/4.3.1_4--enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-libsoxr --enable-videotoolbox --disable-libjack --disable-indev=jack libavutil 56. 51.100 / 56. 51.100 libavcodec 58. 91.100 / 58. 91.100 libavformat 58. 45.100 /58. 45.100 libavdevice 58. 10.100 / 58. 10.100 libavfilter 7. 85.100 / 7. 85.100 libavresample 4. 0. 0 / 4. 0. 0 libswscale 5. 7.100 / 5. 7.100 libswresample 3. 7.100 /3. 7.100 libpostproc 55. 7.100 / 55. 7.100 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'test_video_4.mp4': Metadata:major_brand : mp42minor_version : 1compatible_brands: isommp41mp42creation_time : 2020-11-27T18:38:02.000000Z Duration: 00:00:39.46, start: 0.000000, bitrate: 12081 kb/sStream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 1280x720 [SAR 1:1 DAR 16:9], 12033kb/s, 23.98 fps, 23.98 tbr, 24k tbn, 48k tbc (default)Metadata:creation_time : 2020-11-27T18:38:02.000000Zhandler_name : Core Media Video Input #1, mp3, from 'test_audio_3.mp3': Metadata:genre : Cinematicalbum : YouTube Audio Librarytitle : Test Titleartist : Test Artist Duration: 00:02:12.21, start: 0.025057, bitrate: 320 kb/sStream #1:0: Audio: mp3, 44100 Hz, stereo, fltp, 320 kb/sMetadata:encoder : LAME3.99r Stream mapping: Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264)) Stream #1:0 -> #0:1 (mp3 (mp3float) -> aac (native)) Press [q] to stop, [?] for help [libx264 @0x7fa825031600] VBV maxrate unspecified, assuming CBR [libx264 @0x7fa825031600] using SAR=1/1 [libx264 @ 0x7fa825031600] using cpucapabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2 [libx264 @0x7fa825031600] profile Constrained Baseline, level 3.1, 4:2:0, 8-bit[libx264 @ 0x7fa825031600] 264 - core 161 r3027 4121277 - H.264/MPEG-4AVC codec - Copyleft 2003-2020 - http://www.videolan.org/x264.html -options: cabac=0 ref=1 deblock=0:0:0 analyse=0:0 me=dia subme=0 psy=1psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=08x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0keyint=60 keyint_min=6 scenecut=0 intra_refresh=0 rc_lookahead=0rc=cbr mbtree=0 bitrate=1500 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69qpstep=4 vbv_maxrate=1500 vbv_bufsize=512 nal_hrd=none filler=0ip_ratio=1.40 aq=0 Output #0, flv, to'rtmp://a.rtmp.youtube.com/live2/*****':
Metadata:major_brand : mp42minor_version : 1compatible_brands: isommp41mp42encoder : Lavf58.45.100Stream #0:0(und): Video: h264 (libx264) ([7][0][0][0] / 0x0007), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], q=-1--1, 1500 kb/s,30 fps, 1k tbn, 30 tbc (default)Metadata:creation_time : 2020-11-27T18:38:02.000000Zhandler_name : Core Media Videoencoder : Lavc58.91.100 libx264Side data:cpb: bitrate max/min/avg: 0/0/1500000 buffer size: 512000 vbv_delay: N/AStream #0:1: Audio: aac (LC) ([10][0][0][0] / 0x000A), 44100 Hz, stereo, fltp, 128 kb/sMetadata:encoder : Lavc58.91.100 aac Larger timestamp than 24-bit: 0xffff9b44kB time=00:02:37.43 bitrate=1292.6kbits/sspeed=0.995x [flv @ 0x7fa825032800] Failed to update header withcorrect duration. [flv @ 0x7fa825032800] Failed to update header withcorrect filesize. frame= 3790 fps= 24 q=-1.0 Lsize= 24962kBtime=00:02:38.03 bitrate=1294.0kbits/s speed=0.997x video:22719kBaudio:2081kB subtitle:0kB other streams:0kB global headers:0kB muxingoverhead: 0.656017% [libx264 @ 0x7fa825031600] frame I:64 AvgQP:36.43 size: 38436 [libx264 @ 0x7fa825031600] frame P:3726 AvgQP:28.61 size: 5583 [libx264 @ 0x7fa825031600] mb I I16..4: 100.0%0.0% 0.0% [libx264 @ 0x7fa825031600] mb P I16..4: 3.3% 0.0% 0.0% P16..4: 13.6% 0.0% 0.0% 0.0% 0.0% skip:83.1% [libx264 @0x7fa825031600] coded y,uvDC,uvAC intra: 57.8% 71.6% 47.8% inter: 6.0%7.1% 2.1% [libx264 @ 0x7fa825031600] i16 v,h,dc,p: 21% 39% 23% 18% [libx264 @ 0x7fa825031600] i8c dc,h,v,p: 36% 38% 16% 10% [libx264 @0x7fa825031600] kb/s:1177.39 [aac @ 0x7fa82502d800] Qavg: 179.328Exiting normally, received signal 2.

最佳答案

也循环播放音频:

ffmpeg \
-stream_loop -1 \
-re \
-i "$VIDEO_SOURCE" \
-thread_queue_size 512 \
-stream_loop -1 \
-re \
-i "$AUDIO_SOURCE" \
-c:v libx264 -preset $QUAL -r $FPS -g $(($FPS *2)) -b:v $VBR -bufsize 3000k -maxrate $VBR \
-c:a $AUDIO_ENCODER -ar 44100 -b:a 128k -pix_fmt yuv420p \
-f flv $YOUTUBE_URL/$YOUTUBE_KEY
  • -fflags +shortest -max_interleave_delta 50000用于在最短输入结束时结束输出,但现在两个输入都无限循环,您不希望您的流停止。所以我删除了这些选项。
  • 修复了您的 -bufsize并添加了 -maxrate启用推荐用于流式传输的 VBV。见 this answer有关该无处不在的脚本的一些一般性建议。
  • 已删除 -threads .让编码器自动选择最佳值。
  • 关于FFmpeg:将视频/音频流循环到 YouTube Live,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65041956/

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