YouTube直播静音检测

问题描述 投票:0回答:1

我想监控YouTube直播的沉默,以便能够重新启动ffmpeg广播。你如何在不违反YouTube ToS的情况下实现这一点?

我试过用YouTube API,但health.status只支持直播流,不支持广播。

我想到了用youtube-dl,抓取m3u8,然后用silencedetect运行ffmpeg,但现在我不知怎么卡住了。

获取格式

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

获取m3u8清单

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是上升还是下降?

ffmpeg youtube-api monitoring health-monitoring
1个回答
0
投票

这是我的解决方案,我想出了

!/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
© www.soinside.com 2019 - 2024. All rights reserved.