您需要录制直播。
按时间或文件大小拆分,即录制广播并将其“随时随地”拆分为多个片段,以便立即开始编辑,而无需等待流结束。
目前,这个任务有几个库:
- Youtube-dl(废弃)
- 直播者(废弃)
- Streamlink(支持)
在线播放的问题是帧数可变(录制游戏),在 Sony Vegas 或 Adobe Premiere 中无法正常编辑(声音和视频不同步)(尽管在最新版本的 Adobe Premiere 中它们有支持可变数量的帧,但效果很差或根本不工作)
在此之前,我尝试使用 youtube-dl + ffmpeg 渲染到固定数量的帧来解决这个问题,但这会将我的笔记本电脑(i7,8 个线程,2.4 Gz)加载到 100%,这不允许使用安装与记录以前的情节并行。
我把这项任务推迟到更好的时候。
现在我决定使用streamlink返回。
虽然我正在尝试不渲染到恒定数量的帧。有必要实现视频的分段(按时间或文件大小)。但我不知道如何实现它。
当然,您可以在 Python 中运行一个 bat 文件,在其中启动 streamlink,并在 Python 中检查经过的时间,并在该过程结束时,减少该过程并重新开始。这里的问题是streamlink启动的时间比较长,在这期间会经过几秒的广播,不合适。
从streamlink的能力来看,这些是:
--hls-start-offset [HH:]MM:SS - Время, которое нужно пропустить с начала потока. Для потоков в реальном времени это отрицательное смещение от конца потока (перемотка назад).
--hls-duration [HH:]MM:SS - Ограничить продолжительность воспроизведения, полезно для просмотра сегментов потока. Фактическая продолжительность может быть немного больше, поскольку она округляется до ближайшего сегмента HLS.
По умолчанию: не ограничено .
我使用第二个命令并编写了一个 cmd - 脚本
:loop
set day=%DATE:~0,2%
set month=%DATE:~3,2%
set year=%DATE:~6,4%
set hour=%TIME:~0,2%
set minute=%TIME:~3,2%
set second=%TIME:~6,2%
set YYYYMMDD=%hour%_%minute%_%second%_%day%_%month%_%year%
streamlink --hls-live-edge 99999 --hls-segment-threads 10 --ringbuffer-size 1024M --hls-duration 00:05:00 -o %YYYYMMDD%.ts https://www.twitch.tv/makatao best
goto loop
但不幸的是,差距非常大。而且,如果我在视频中指定了5分钟,那么下一个将不会在5分钟或更多,而是不到5分钟开始。因此,需要在某个时间点将不同的视频相互同步,这也不是方便的
有没有人有什么建议?(频道选择了第一个可用的)
我的代码将 CPU 加载到 100% 以下
cls && @echo off & setlocal enableextensions enabledelayedexpansion
set "_tag_00=https://www.youtube.com/watch?v=aiHqRt-mqxo"
set "_tag_01=--ignore-errors --abort-on-error --ignore-config --flat-playlist --geo-bypass "
set "_tag_02=--restrict-filenames --no-part --no-cache-dir --write-thumbnail --prefer-ffmpeg "
set "_tag_03=--ffmpeg-location .\ --postprocessor-args -i "%%(title)s.%%(ext)s" -vf fps^=fps^=60^,"
set "_tag_04=scale^=1920x1080 -c:v libx264 -b:v 500k -preset superfast -c:a copy -f segment -segment_time "
set "_tag_05=60 %%^(title^)s.mp4"
youtube-dl "!_tag_00!" -f "bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best" -o "%%^(title^)s.%%^(ext^)s" !_tag_1!!_tag_2!!_tag_3!!_tag_4!!_tag_5!
Pause
代码 2(按持续时间拆分)
cls && @echo off & setlocal enableextensions enabledelayedexpansion
:: do some with the bat file, after then, for all links need `call :_yd_dl` %1
call :_yd_dl %1
echo/ is done^^!!
goto :eof
:_yd_dl
set "_tag_00=https://www.twitch.tv/ninja"
set "_tag_01= -t 00:60:00 -v error -stats -vf fps=fps=60,scale=1920x1080 -c:v libx264 -preset superfast -c:a copy "
for /f %%i in ('.\youtube-dl.exe -g !_tag_00! ^<nul ') do .\ffmpeg.exe -i "%%i" !_tag_01! .\output.mp4
exit /b
更新写了一个脚本
def refactor(second):
if str(second)[0] == "-":
number_sign = "-"
second = int(str(second)[1:])
else:
number_sign = ""
current_hours = str(second // 3600)
remainder_second = second % 3600
current_minutes = str(remainder_second // 60)
current_seconds = str(remainder_second % 60)
if len(current_hours) == 1:
current_hours = "0" + current_hours
if len(current_minutes) == 1:
current_minutes = "0" + current_minutes
if len(current_seconds) == 1:
current_seconds = "0" + current_seconds
text_time = number_sign + current_hours + ":" + current_minutes + ":" + current_seconds
return text_time
def run():
duration = 60
time_stream = 0
print(refactor(time_stream))
while True:
current_time_date = datetime.datetime.now().strftime("%H.%M.%S_%d_%m_%Y")
subprocess.call(["streamlink", "--hls-live-edge", "99999", "--hls-segment-threads", "10", "--ringbuffer-size", "1024M", "--hls-duration", refactor(duration), "--hls-start-offset", refactor(time_stream),"-o", current_time_date + ".ts", "https://www.twitch.tv/csruhub", "best"])
time_stream =+ duration
time.sleep(10)
他把它分成几个部分,但问题是他按时开始,但只有在部分结束时才完成。
事实证明,这些部分是相互叠加的。所以这个问题仍然是相关的。
该脚本从现场直播中录制视频,将其分成大约 10 分钟的片段(直到当前片段结束)。