FFMpeg 复制直播流(限制为 60s 文件)
FFMpeg Copy Live Stream (Limit to 60s file)
我目前有一种获取直播流并在直播时开始本地下载的有效方法。
ffmpeg -i source_hls.m3u8 -c copy output.mkv -y
问题是我实际上并不想保存整个东西,我只是定期 运行 在 output.mkv 命令上创建另一个命令来创建部分直播流的剪辑。
我想知道是否可以将 output.mkv 文件限制为只有 60 秒长,这样一旦流超过 1 分钟,它就会切断旧视频并由新的滚动视频替换.
这可能吗?
你可以接近,使用分段复用器。
ffmpeg -i source_hls.m3u8 -c copy -f segment -segment_time 60 -segment_wrap 2 -reset_timestamps 1 out%02d.mkv -y
这将写入 out00.mkv,然后写入 out01.mkv,然后覆盖 out00.mkv,接下来覆盖 out01.mkv 等等。
分段时间设置为60秒,所以每段时间在60秒左右。拆分的目标是输入的 60,120,180,240... 秒。但是,视频流将仅在分割目标处或之后的关键帧处分割。所以,如果 t=59 之后的第一个关键帧是 66,那么第一个片段的长度将是 66s。下一个目标是 120s。假设在 121s 处有一个 KF,那么第二段的长度为 66 到 121s = 55s。检查细分时需要注意的事项。
检查文件修改时间以查看哪个段包含较早的数据。
如果要减少剩余时间,减少segment_time并相应增加segment_wrap。 segment_time x segment_wrap
应该是 target saved duration + segment_time
长。
迟到的答案,但您可以使用 -t duration
,即:
ffmpeg -y -t 60 -i source_hls.m3u8 -c copy output.mkv
来自ffmpeg docs:
-t duration (input/output)
When used as an input option (before -i
), limit the duration of data
read from the input file.
When used as an output option (before an output url), stop writing the
output after its duration reaches duration.
duration must be a time duration specification, see (ffmpeg-utils)the
Time duration section in the ffmpeg-utils(1)
manual.
-to and -t are mutually exclusive and -t has priority.
-t
参数示例:
11
- 11 秒
11.111
- 11.111 秒
1:11:11
- 11 小时 11 分 11 秒
我目前有一种获取直播流并在直播时开始本地下载的有效方法。
ffmpeg -i source_hls.m3u8 -c copy output.mkv -y
问题是我实际上并不想保存整个东西,我只是定期 运行 在 output.mkv 命令上创建另一个命令来创建部分直播流的剪辑。
我想知道是否可以将 output.mkv 文件限制为只有 60 秒长,这样一旦流超过 1 分钟,它就会切断旧视频并由新的滚动视频替换.
这可能吗?
你可以接近,使用分段复用器。
ffmpeg -i source_hls.m3u8 -c copy -f segment -segment_time 60 -segment_wrap 2 -reset_timestamps 1 out%02d.mkv -y
这将写入 out00.mkv,然后写入 out01.mkv,然后覆盖 out00.mkv,接下来覆盖 out01.mkv 等等。
分段时间设置为60秒,所以每段时间在60秒左右。拆分的目标是输入的 60,120,180,240... 秒。但是,视频流将仅在分割目标处或之后的关键帧处分割。所以,如果 t=59 之后的第一个关键帧是 66,那么第一个片段的长度将是 66s。下一个目标是 120s。假设在 121s 处有一个 KF,那么第二段的长度为 66 到 121s = 55s。检查细分时需要注意的事项。
检查文件修改时间以查看哪个段包含较早的数据。
如果要减少剩余时间,减少segment_time并相应增加segment_wrap。 segment_time x segment_wrap
应该是 target saved duration + segment_time
长。
迟到的答案,但您可以使用 -t duration
,即:
ffmpeg -y -t 60 -i source_hls.m3u8 -c copy output.mkv
来自ffmpeg docs:
-t duration (input/output)
When used as an input option (before
-i
), limit the duration of data read from the input file.When used as an output option (before an output url), stop writing the output after its duration reaches duration.
duration must be a time duration specification, see (ffmpeg-utils)the Time duration section in the ffmpeg-utils(1) manual.
-to and -t are mutually exclusive and -t has priority.
-t
参数示例:
11
- 11 秒11.111
- 11.111 秒1:11:11
- 11 小时 11 分 11 秒