尽管重采样了音频过滤器,但tsmp和m3u8文件的ffmpeg切割不准确 [英] Ffmpeg inaccurate cutting with ts and m3u8 files despite resamping audio filter

查看:71
本文介绍了尽管重采样了音频过滤器,但tsmp和m3u8文件的ffmpeg切割不准确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要准确地查找和剪切视频.一些在线消息人士说,将-ss放在消息源的前面或后面.结果对我来说是一样的.在下面的示例中,开始时间准确,但持续时间不准确.

I need to accurately seek and cut a video. Some online sources say put -ss in front or after the source. The result is the same for me. In the examples below, the start time is accurate but the duration is not accurate.

ffmpeg -y -ss 00:00:05 -t 00:00:05 -i output.ts 5s.wav
ffprobe 5s.wav

Duration: 00:00:04.74

ffmpeg -y -i output.ts -ss 00:00:05 -t 00:00:05 5s.wav
ffprobe 5s.wav

Duration: 00:00:04.74

有时起点不准确,但持续时间正确.通过剪切ts文件和剪切未压缩的wav文件,然后聆听两者,这显然是可以听见的.

Sometimes the starting point is not accurate but the duration is. This is clearly audible by cutting the ts file and cutting an uncompressed wav file, and listening to both.

ffmpeg -y -i output.ts -ss 00:00:15 -t 00:00:05 5s.wav

ffmpeg -y -i output.wav -ss 00:00:15 -t 00:00:05 5s-reference.wav

解决启动时间问题的方法是,如果我使用一个包含每个关键帧字节偏移量的m3u8文件,并且将-ss选项放在源文件前面(如果我将它放在源文件后面,则启动时间不准确)但持续时间是准确的):

What fixes the starting time is if I use an m3u8 file that contains the byte offset for every keyframe AND I put the -ss option in front of the source file (if I put it after the source, the start time is inaccurate but the duration is accurate):

ffmpeg -y -ss 00:00:15 -t 00:00:05 -i output.m3u8 5s.wav

这确定了开始时间,但持续时间在不使用m3u8文件的情况下(持续时间仅为4.47s).

This fixes the start time but the duration is at the location that I would get had I used no m3u8 file (duration is just 4.47s).

似乎涉及不同的时间戳记,有时一个或另一个会被使用.

It seems different timestamps are involved, and sometimes one or the other gets used.

ts文件是通过捕获UDP流并将其与ffmpeg和-codec:v复制存储在一起生成的.

The ts file was generated by capturing a UDP stream and storing it with ffmpeg and -codec:v copy.

ffmpeg损坏了还是ts文件?如何解决此问题或修复ts文件?我意识到,视频的开始时间晚于音频的开始时间,这可能是因为视频不是以关键帧开始的.我可以在第一个关键帧之后让ffmpeg启动-codec:v副本吗?我还注意到的是,使用ffprobe报告开始:1.400000".我可以强迫它从0开始吗?

Is ffmpeg broken, or the ts file? How do I work around this issue or fix the ts file? What I realize is that the video starts later than the audio, probably because the video does not start with a keyframe. Can I get ffmpeg to start the -codec:v copy after the first keyframe? What I also notice is that using ffprobe reports "start: 1.400000". Can I force it to start at 0?

任何提示将不胜感激.

我尝试了ffmpeg 4.3.1和ffmpeg git-2020-07-24-21442a8.

I tried both ffmpeg 4.3.1 and ffmpeg git-2020-07-24-21442a8.

output.*文件的生成如下.语句"af aresample = async = 1"应该根据填充丢失的音频,不同.添加此语句在准确性或持续时间方面没有区别.问题不是重复.

The output.* files were generated as follows. The statement "af aresample=async=1" should fill missing audio according to Duration of source video and subtracted audio are different. Adding this statement makes no difference in terms of accuracy or duration. The question is not a duplicate.

ffmpeg -i udp://example:port ^
-af aresample=async=1 ^
-codec:v copy ^
-codec:a aac -ac 2 -ar 44100 -b:a 160k ^
-hls_time 4 -hls_flags single_file -hls_list_size 0 -hls_segment_filename output.ts -hls_segment_type mpegts output.m3u8 ^
-codec:a pcm_s16le -bitexact -ar 11025 -ac 1 output.wav

推荐答案

以HLS作为输入,使用

With HLS as input, use

ffmpeg -y -ss 00:00:13 -copyts -start_at_zero -i input.m3u8 -af aresample=async=1 -ss 15 -to 20 -map 0:a ts-cut-m3u8.wav

由于TS段没有全局索引,因此比实际入口早一些搜索,因此从下一个关键帧开始进行多路分离器搜索.由于要复制时间戳,因此请使用输出ss/to设置范围.aresample将填补时间戳记间隔(如果有).对于此输入,在15到20的范围内没有任何输入.在5s左右有一个较早的版本.

Seek a bit earlier than the actual inpoint since TS segments have no global index and hence demuxer seek will start from the next keyframe. Since timestamps are being copied, use output ss/to to set range. aresample will plug timestamp gaps if any. For this input, in the 15 to 20 range there aren't any. There's one earlier at around the 5s mark.

这篇关于尽管重采样了音频过滤器,但tsmp和m3u8文件的ffmpeg切割不准确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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