gpt4 book ai didi

ffmpeg - YouTube 直播静音检测

转载 作者:行者123 更新时间:2023-12-04 23:22:49 35 4
gpt4 key购买 nike

我正在尝试监视 YouTube 直播是否静音,以便能够重新启动 ffmpeg 广播。在不违反 YouTube ToS 的情况下,您将如何实现这一目标?

我尝试使用 YouTube API,但 health.status 仅支持 Live 流,但不支持广播。

我想出了 youtube-dl 的想法,捕获 m3u8 并使用静音检测运行 ffmpeg,但现在我不知何故被卡住了。

获取格式

youtube-dl --list-formats https://www.youtube.com/watch?v=BiHequcIiNw

获取 m3u8 list
youtube-dl -f 91 -g https://www.youtube.com/watch?v=BiHequcIiNw

运行ffprobe
ffprobe -v quiet -print_format json -show_streams https://manifest.googlevideo.com/api/manifest/hls_playlist/expire/1588936061/ei/Hem0Xp35EZLl1wLLhYaYCA/ip/2a02:1205:c6bb:4590:301f:6186:c624:f2ba/id/BiHequcIiNw.0/itag/91/source/yt_live_broadcast/requiressl/yes/ratebypass/yes/live/1/goi/160/sgoap/gir%3Dyes%3Bitag%3D139/sgovp/gir%3Dyes%3Bitag%3D160/hls_chunk_host/r3---sn-nfpnnjvh-9and.googlevideo.com/playlist_duration/30/manifest_duration/30/vprv/1/playlist_type/DVR/initcwndbps/13630/mh/GY/mm/44/mn/sn-nfpnnjvh-9and/ms/lva/mv/m/mvi/2/pl/48/dover/11/keepalive/yes/fexp/23882513/mt/1588914375/disable_polymer/true/sparams/expire,ei,ip,id,itag,source,requiressl,ratebypass,live,goi,sgoap,sgovp,playlist_duration,manifest_duration,vprv,playlist_type/sig/AOq0QJ8wRgIhALApv3H2YEE2GLTXIyRxw8Fu8espLgRThUfhi97DIS6-AiEAsT_4bwAfsihK6zsrKgaxMYTemlAr8BXnBTwuhwe3aAE%3D/lsparams/hls_chunk_host,initcwndbps,mh,mm,mn,ms,mv,mvi,pl/lsig/AG3C_xAwRQIgRG3c1ww23Jokzk6vfAfeZlhwEanWG_9GmwRip81v65cCIQDg1Y9pXWS4bUjpKpZ90c3icp4slmAzhQJPn2gqW0UOeQ%3D%3D/playlist/index.m3u8

但是如果流向上或向下,我在 json 中没有发现差异。任何提示我如何监控 m3u8 如果它是向上或向下?

最佳答案

这是我想出的解决方案

!/bin/bash
#
# YouTube live broadcast monitor
#
cd /var/azuracast/videostream/
youtubeURL=https://www.youtube.com/watch?v=BiHequcIiNw
# Get YouTube Manifest 1
youtube-dl -4 -f 91 -g $youtubeURL > manifest1.txt
# Probe Manifest 1
ffprobe -v quiet -print_format json -show_streams "$(<manifest1.txt)" > json1.txt
sleep 2
youtube-dl -4 -f 91 -g $youtubeURL > manifest2.txt
ffprobe -v quiet -print_format json -show_streams "$(<manifest2.txt)" > json2.txt
# do we have a valid json
starttime=$(cat json1.txt | jq '.streams[].start_time')
if [ -z "$starttime" ]; then
echo "$(date)" "Error: No start_time" "$starttime"
exit 1
fi
# compare the ffprobe json, if they are the same, the live stream stopped
if cmp -s json1.txt json2.txt; then
echo "$(date)" "Stream Down"
# restart stream
docker-compose restart videostream
echo "$(date)" "Stream Up"
sleep 20
else
echo "$(date)" "Stream Up"
fi

关于ffmpeg - YouTube 直播静音检测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61672285/

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