FFMpeg 复制实时流(限制为 60 秒文件) [英] FFMpeg Copy Live Stream (Limit to 60s file)

查看:58
本文介绍了FFMpeg 复制实时流(限制为 60 秒文件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一种有效的方法来获取实时流并在它仍处于实时状态时开始在本地下载它.

I currently have a working way to get a live stream and start downloading it locally while it is still live.

ffmpeg -i source_hls.m3u8 -c copy output.mkv -y

问题是我实际上并不想保存整个内容,我只是定期在 output.mkv 命令上运行另一个命令来创建部分实时流的剪辑.

The problem is I do not actually want to save the entire thing, I just periodically run another command on the output.mkv command to create a clip of part of the live stream.

我想知道是否可以将 output.mkv 文件限制为只有 60 秒长,这样一旦流超过 1 分钟,它就会切断旧视频并被新的滚动视频替换.

I was wondering if it was possible to limit the output.mkv file to be only 60s long so once the stream goes over 1 minute it will just cut off the old video and be replaced by the new rolling video.

这是可能还是不可能?

推荐答案

你可以接近,使用段复用器.

You can come close, using the segment muxer.

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,依此类推.

This will write to out00.mkv, then out01.mkv, then overwrite out00.mkv, next overwrite out01.mkv and so on.

段时间设置为 60 秒,因此每个段将在 60 秒左右.拆分的目标是输入的 60,120,180,240... 秒.但是,视频流将仅在分割目标处或之后的关键帧处被分割.所以,如果 t=59 之后的第一个关键帧是 66,那么第一个片段将是 66s 长.下一个目标是 120 秒.假设在 121 秒有一个 KF,所以第二段将是 66 到 121 秒 = 55 秒长.检查段时要记住的一些事情.

The segment time is set at 60 seconds, so each segment will be around 60 seconds. The targets for splitting are 60,120,180,240... seconds of the input. However, video streams will be only be split at keyframes at or after the split target. So, if the first keyframe after t=59 is at 66, then the first segment will be 66s long. The next target is 120s. Let's say there's a KF at 121s, so the 2nd segment will be 66 to 121s = 55s long. Something to keep in mind when checking the segments.

检查文件修改时间以查看哪个段包含较早的数据.

Check the file modification times to see which segment contains the earlier data.

如果要减少剩余时长,相应减少segment_time和增加segment_wrap.segment_time x segment_wrap 应该是 target Saved duration + segment_time 长.

If you want to reduce the surplus duration, decrease segment_time and increase segment_wrap correspondingly. segment_time x segment_wrap should be target saved duration + segment_time long.

这篇关于FFMpeg 复制实时流(限制为 60 秒文件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆