When ffmpeg video is intercepted, the DTS is out of order, resulting in the inability to intercept the video.

  Recently, in a request, I needed to batch intercept 10s videos from hls videos, and found that there was a small probability that the interception would fail.
The complete command for video interception is as follows: < /span>

ffmpeg -i https://file.xindoo.xyz/utopia-file/local/video/605d3af0a9cb469c91fbb309422e6672/playlist.m3u8 -r 15 -ss 19 -t 10.0 -b:v 4096k -vcodec libx264  12345.mp4

  At first I thought there was a problem with the video clips in hls. Later, I checked with my colleagues and found that in all cases of failure, when executing the ffmpeg command to intercept, it will report [mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fd6fa008780] DTS 0 < 1986554 out of orderspeed=0x [hls @ 0x7fd6fa004a40] DTS 0 < 1986554 out of order , follow this message We found that all failures were caused by splicing part of another video in m3u8.

  To understand this problem, we first need to explain what DTS is. DTS (Decoding TimeStamp) This is the time when video or audio frames should be decoded. This timestamp is also based on the playback start point, telling the player when it should start decoding this frame. In plain language, DTS is the position of each frame of the video relative to the starting event point of the video.

  In order to obtain videos between any time period flexibly and at low cost in our business, we choose to divide the original video into ts segments, select them as needed and regenerate an m3u8 file. Because the original video is not recorded continuously, there is a certain probability that the end of video A and the beginning of video B are spliced ​​into the same m3u8. In this case, the DTS of the last frame of video A and the DTS of the first frame of video B are definitely discontinuous, and "DTS 0 < 1986554 out of order" will be reported when intercepting, and ultimately the interception fails.

  How to solve? I tried many parameters, such as -vsync, -fflags +igndts, and even switched the ffmpeg version, but nothing could solve the problem. In the end, I used a stupid method, first save the video in hls format into mp4 and then intercept it from the mp4 to bypass this bug. The specific implementation is to split the above command into the following two:

# 先转存成mp4文件
ffmpeg -i https://file.xindoo.xyz/utopia-file/local/video/605d3af0a9cb469c91fbb309422e6672/playlist.m3u8 -c:v copy temp.mp4
# 然后从mp4文件中截取视频 
ffmpeg -i temp.mp4 -r 15 -ss 19 -t 10.0 -b:v 4096k -vcodec libx264  12345.mp4

Guess you like

Origin blog.csdn.net/xindoo/article/details/134220471