FFMpeg Copy Live Stream (Limit to 60s file)

后端 未结 2 2028
灰色年华
灰色年华 2020-12-21 08:17

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

相关标签:
2条回答
  • 2020-12-21 08:28

    Late answer, but you can use -t duration, i.e.:

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

    From 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 argument examples:

    • 55 - 55 seconds
    • 12:03:45 - 12 hours, 03 minutes and 45 seconds
    • 23.189 - 23.189 seconds
    0 讨论(0)
  • 2020-12-21 08:38

    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
    

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

    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.

    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.

    0 讨论(0)
提交回复
热议问题