FFMpeg复制直播(仅限60s文件) [英] FFMpeg Copy Live Stream (Limit to 60s file)

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

问题描述

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

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秒.假设在121s处有一个KF,所以第二段的长度为66至121s = 55s.检查细分时要记住一些事情.

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复制直播(仅限60s文件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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