gpt4 book ai didi

ffmpeg mp4 到 hls vod,提取片段持续时间,无需重新编码

转载 作者:行者123 更新时间:2023-12-04 23:11:44 26 4
gpt4 key购买 nike

您好,我有 h264 mp4 文件。我想要做的是将其转换为 hls 而无需重新编码。这可以通过以下方式实现:

ffmpeg -i input.mp4 -c copy -force_key_frames "expr:gte(t,n_forced*4)" -hls_time 4 -hls_playlist_type vod -hls_segment_type mpegts vid.m3u8
但是这个问题是它不会创建提取段持续时间:
$ for f in *.ts; do echo -n "$f,"; ffprobe -v error -show_entries format=duration -sexagesimal -of csv=p=0 "$f"; done
vid0.ts,0:00:04.837700
vid1.ts,0:00:05.587200
vid2.ts,0:00:06.006200
vid3.ts,0:00:01.368200
vid4.ts,0:00:02.693867
我不相信我不能在没有编码的情况下插入关键帧。
当我运行时:
ffmpeg -i input.mp4 -codec:v libx264 -force_key_frames "expr:gte(t,n_forced*4)" -hls_time 4 -hls_playlist_type vod -hls_segment_type mpegts vid.m3u8
它的作品,但这是资源密集型的,因为它重新编码视频。
因此,我正在寻找实现这一目标的最佳方法,同时尽可能使用最少的资源。

最佳答案

使用 -c copy 时只能在关键帧上分割(流复制)。因此,如果您需要更准确的拆分,则需要重新编码。
来自 segment muxer documentation :

Note that if you want accurate splitting for a video file, you need tomake the input key frames correspond to the exact splitting timesexpected by the segmenter, or the segment muxer will start the newsegment with the key frame found next after the specified start time.


省略 -c copy并将关键帧间隔设置为等于您的 -hls_time (或 -segment_time 如果使用分段复用器):
ffmpeg -i input -f segment -segment_time 4 -force_key_frames "expr:gte(t,n_forced*4)" -reset_timestamps 1 output_%04d.mp4
如果您希望以帧而不是秒来声明关键帧间隔,请使用 -g而不是 -force_key_frames (但不要同时使用)。

关于ffmpeg mp4 到 hls vod,提取片段持续时间,无需重新编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65761346/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com