使用 ffmpeg 连接 mkvs 时出现问题:如何正确设置时间戳?

Issue when concatenating mkvs using ffmpeg: How to set timestamps properly?

我尝试使用以下命令将 2 个 mkv 视频与 ffmpeg 连接起来:

ffmpeg -i file-01.mkv -f mpegts -c copy -bsf:v h264_mp4toannexb file-01.mpeg.ts
ffmpeg -i file-02.mkv -f mpegts -c copy -bsf:v h264_mp4toannexb file-02.mpeg.ts
ffmpeg -isync -i "concat:file-01.mpeg.ts|file-02.mpeg.ts" -f matroska
-c copy output.mkv

但是,我收到以下错误:

[matroska @ 0x7fc72a000600] Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly [matroska @ 0x7fc72a000600] Can't write packet with unknown timestamp av_interleaved_write_frame(): Invalid argument

如何设置时间戳?

好的,请尝试以下步骤:

ffmpeg -i file-01.mkv -c copy -map v 01.mp4
ffmpeg -i file-02.mkv -c copy -map v 02.mp4
ffmpeg -i 01.mp4 -i file-01.mkv -map 0:v -map 1:a -c copy -bsf:v h264_mp4toannexb file-01.mpeg.ts
ffmpeg -i 02.mp4 -i file-02.mkv -map 0:v -map 1:a -c copy -bsf:v h264_mp4toannexb file-02.mpeg.ts
ffmpeg -i "concat:file-01.mpeg.ts|file-02.mpeg.ts" -f matroska
-c copy output.mkv

一些 H.264 流的数据包没有 PTS 值。 FFmpeg 随意支持混合这些流。

本身不一定是解决方案,但 mkvmerge 最终对我有用。也简单得多:

mkvmerge -o "merged.mkv" "file1.mkv" +"file2.mkv"