使用 ffmpeg 将 TS-Stream 转换为 MKV

Convert TS-Stream to MKV with ffmpeg

我正在使用 ffmpeg 3.2.7,但在将 ts 文件无损转换为 mkv 时遇到问题。 源文件是使用 dumprtp(来自 dvbstream 0.5)记录的转储 IPTV 流。

ffmpeg -i Test.ts -map 0:0 -map 0:2 -vcodec copy -acodec copy -f matroska Test.mkv

转换成功,但输出文件每隔几秒像素化一次。

当我用 MKVToolnix 转换它时,一切看起来都很好。

有人能解决这个问题吗? 也许有一些正确同步流的选项?

这是一个示例输出:

# ffmpeg -i Test.ts -map 0:0 -map 0:2 -vcodec copy -acodec copy -f matroska Test.mkv
ffmpeg version 3.2.7 Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 6.3.0 (OpenWrt GCC 6.3.0 r212-46f973b)
  configuration: --enable-cross-compile --cross-prefix=i486-openwrt-linux-gnu- --arch=i386 --target-os=linux --prefix=/opt --pkg-config=pkg-config --enable-shared --enable-static --enable-pthreads --enable-zlib --disable-doc --disable-debug --disable-lzma --disable-vaapi --disable-vdpau --disable-outdevs --enable-avresample --enable-libopus --enable-small --enable-gpl --enable-libmp3lame --enable-libx264
  libavutil      55. 34.101 / 55. 34.101
  libavcodec     57. 64.101 / 57. 64.101
  libavformat    57. 56.101 / 57. 56.101
  libavdevice    57.  1.100 / 57.  1.100
  libavfilter     6. 65.100 /  6. 65.100
  libavresample   3.  1.  0 /  3.  1.  0
  libswscale      4.  2.100 /  4.  2.100
  libswresample   2.  3.100 /  2.  3.100
  libpostproc    54.  1.100 / 54.  1.100
[mpegts @ 0x81f6280] changing packet size to 192
[mpegts @ 0x81f6280] changing packet size to 188
[mpegts @ 0x81f6280] changing packet size to 192
[NULL @ 0x81f9580] SPS unavailable in decode_picture_timing
[NULL @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] decode_slice_header error
[h264 @ 0x81f9580] no frame!
[mpegts @ 0x81f6280] changing packet size to 188
[mpegts @ 0x81f6280] changing packet size to 192
[mpegts @ 0x81f6280] changing packet size to 188
[mpegts @ 0x81f6280] changing packet size to 192
[mpegts @ 0x81f6280] changing packet size to 188
[mpegts @ 0x81f6280] changing packet size to 192
[mpegts @ 0x81f6280] changing packet size to 188
[mpegts @ 0x81f6280] changing packet size to 192
[mpegts @ 0x81f6280] changing packet size to 188
[mpegts @ 0x81f6280] changing packet size to 192
[mpegts @ 0x81f6280] changing packet size to 188
[mpegts @ 0x81f6280] changing packet size to 192
[mpegts @ 0x81f6280] changing packet size to 188
[mpegts @ 0x81f6280] changing packet size to 192
[mpegts @ 0x81f6280] changing packet size to 188
[mpegts @ 0x81f6280] changing packet size to 192
[mpegts @ 0x81f6280] changing packet size to 188
[mpegts @ 0x81f6280] changing packet size to 192
[mpegts @ 0x81f6280] changing packet size to 188
[mpegts @ 0x81f6280] changing packet size to 192
[mpegts @ 0x81f6280] changing packet size to 188
[mpegts @ 0x81f6280] changing packet size to 192
[mpegts @ 0x81f6280] changing packet size to 188
[mpegts @ 0x81f6280] changing packet size to 192
[mpegts @ 0x81f6280] changing packet size to 188
[mpegts @ 0x81f6280] changing packet size to 192
[mpegts @ 0x81f6280] changing packet size to 188
[mpegts @ 0x81f6280] changing packet size to 192
[mpegts @ 0x81f6280] changing packet size to 188
[mpegts @ 0x81f6280] changing packet size to 192
[mpegts @ 0x81f6280] changing packet size to 188
[mpegts @ 0x81f6280] changing packet size to 192
[mpegts @ 0x81f6280] changing packet size to 188
[mpegts @ 0x81f6280] changing packet size to 192
[mpegts @ 0x81f6280] changing packet size to 188
[mpegts @ 0x81f6280] changing packet size to 192
[mpegts @ 0x81f6280] changing packet size to 188
[mp3 @ 0x81fb860] Header missing
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] decode_slice_header error
[h264 @ 0x81f9580] no frame!
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] decode_slice_header error
[h264 @ 0x81f9580] no frame!
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] decode_slice_header error
[h264 @ 0x81f9580] no frame!
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] decode_slice_header error
[h264 @ 0x81f9580] no frame!
[mp3 @ 0x81fb860] Header missing
    Last message repeated 1 times
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] decode_slice_header error
[h264 @ 0x81f9580] no frame!
[mp3 @ 0x81fb860] Header missing
    Last message repeated 3 times
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] decode_slice_header error
[h264 @ 0x81f9580] no frame!
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] decode_slice_header error
[h264 @ 0x81f9580] no frame!
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] decode_slice_header error
[h264 @ 0x81f9580] no frame!
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] decode_slice_header error
[h264 @ 0x81f9580] no frame!
[mp3 @ 0x81fb860] Header missing
    Last message repeated 1 times
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] decode_slice_header error
[h264 @ 0x81f9580] no frame!
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] decode_slice_header error
[h264 @ 0x81f9580] no frame!
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] decode_slice_header error
[h264 @ 0x81f9580] no frame!
[mp3 @ 0x81fb860] Header missing
    Last message repeated 3 times
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] decode_slice_header error
[h264 @ 0x81f9580] no frame!
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] decode_slice_header error
[h264 @ 0x81f9580] no frame!
[mp3 @ 0x81fb860] Header missing
    Last message repeated 1 times
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] decode_slice_header error
[h264 @ 0x81f9580] no frame!
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] decode_slice_header error
[h264 @ 0x81f9580] no frame!
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] decode_slice_header error
[h264 @ 0x81f9580] no frame!
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] decode_slice_header error
[h264 @ 0x81f9580] no frame!
[mp3 @ 0x81fb860] Header missing
    Last message repeated 1 times
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] decode_slice_header error
[h264 @ 0x81f9580] no frame!
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] decode_slice_header error
[h264 @ 0x81f9580] no frame!
[mp3 @ 0x81fb860] Header missing
    Last message repeated 1 times
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] decode_slice_header error
[h264 @ 0x81f9580] no frame!
[mp3 @ 0x81fb860] Header missing
    Last message repeated 1 times
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] decode_slice_header error
[h264 @ 0x81f9580] no frame!
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] decode_slice_header error
[h264 @ 0x81f9580] no frame!
[mp3 @ 0x81fb860] Header missing
    Last message repeated 1 times
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] decode_slice_header error
[h264 @ 0x81f9580] no frame!
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] decode_slice_header error
[h264 @ 0x81f9580] no frame!
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] decode_slice_header error
[h264 @ 0x81f9580] no frame!
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] decode_slice_header error
[h264 @ 0x81f9580] no frame!
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] decode_slice_header error
[h264 @ 0x81f9580] no frame!
[mp3 @ 0x81fb860] Header missing
    Last message repeated 7 times
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] SPS unavailable in decode_picture_timing
[h264 @ 0x81f9580] non-existing PPS 0 referenced
[h264 @ 0x81f9580] decode_slice_header error
[h264 @ 0x81f9580] no frame!
[mp3 @ 0x81fb860] Header missing
    Last message repeated 1 times
[h264 @ 0x81f9580] reference picture missing during reorder
    Last message repeated 1 times
[h264 @ 0x81f9580] Missing reference picture, default is 2147483647
    Last message repeated 1 times
[h264 @ 0x81f9580] mmco: unref short failure
    Last message repeated 1 times
[h264 @ 0x81f9580] number of reference frames (0+5) exceeds max (4; probably corrupt input), discarding one
[mp3 @ 0x81fb860] Header missing
    Last message repeated 3 times
[h264 @ 0x81f9580] reference picture missing during reorder
    Last message repeated 2 times
[h264 @ 0x81f9580] Missing reference picture, default is 65627
    Last message repeated 2 times
[mp3 @ 0x81fb860] Header missing
    Last message repeated 1 times
[h264 @ 0x81f9580] mmco: unref short failure
    Last message repeated 3 times
[h264 @ 0x81f9580] Increasing reorder buffer to 2
[mp3 @ 0x81fb860] Header missing
    Last message repeated 295 times
[mpegts @ 0x81f6280] changing packet size to 192
[mpegts @ 0x81f6280] changing packet size to 188
[mp3 @ 0x81fb860] Header missing
    Last message repeated 13 times
[mpegts @ 0x81f6280] changing packet size to 192
[mpegts @ 0x81f6280] changing packet size to 188
[mp3 @ 0x81fb860] Header missing
    Last message repeated 2 times
[mpegts @ 0x81f6280] decoding for stream 1 failed
[mpegts @ 0x81f6280] changing packet size to 192
[mpegts @ 0x81f6280] changing packet size to 188
[mpegts @ 0x81f6280] changing packet size to 192
[mpegts @ 0x81f6280] changing packet size to 188
[mpegts @ 0x81f6280] PES packet size mismatch
    Last message repeated 1 times
[mpegts @ 0x81f6280] Could not find codec parameters for stream 1 (Audio: mp3, 0 channels, s16p): unspecified frame size
Consider increasing the value for the 'analyzeduration' and 'probesize' options
Input #0, mpegts, from 'Test.ts':
  Duration: 00:01:00.54, start: 48882.340000, bitrate: 3181 kb/s
    Stream #0:0[0x100]: Video: h264, yuv420p(tv, bt470bg, top first), 720x576 [SAR 16:11 DAR 20:11], 25 fps, 50 tbr, 90k tbn, 50 tbc
    Stream #0:1[0x103]: Audio: mp3, 0 channels, s16p
    Stream #0:2[0x102]: Audio: mp2, 48000 Hz, stereo, s16p, 192 kb/s
    Stream #0:3[0x101]: Audio: ac3, 48000 Hz, stereo, fltp, 384 kb/s
Output #0, matroska, to 'Test.mkv':
  Metadata:
    encoder         : Lavf57.56.101
    Stream #0:0: Video: h264 (H264 / 0x34363248), yuv420p(tv, bt470bg, top first), 720x576 [SAR 16:11 DAR 20:11], q=2-31, 25 fps, 50 tbr, 1k tbn, 90k tbc
    Stream #0:1: Audio: mp2 (P[0][0][0] / 0x0050), 48000 Hz, stereo, 192 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:2 -> #0:1 (copy)
Press [q] to stop, [?] for help
[mpegts @ 0x81f6280] changing packet size to 192
[mpegts @ 0x81f6280] changing packet size to 188
[mpegts @ 0x81f6280] changing packet size to 192
[mpegts @ 0x81f6280] changing packet size to 188
[mpegts @ 0x81f6280] changing packet size to 192
[mpegts @ 0x81f6280] changing packet size to 188
[mpegts @ 0x81f6280] changing packet size to 192
[mpegts @ 0x81f6280] changing packet size to 188
[mpegts @ 0x81f6280] changing packet size to 192
[mpegts @ 0x81f6280] changing packet size to 188
[mpegts @ 0x81f6280] changing packet size to 192
[mpegts @ 0x81f6280] changing packet size to 188
[mpegts @ 0x81f6280] changing packet size to 192
[mpegts @ 0x81f6280] changing packet size to 188
[mpegts @ 0x81f6280] changing packet size to 192
[mpegts @ 0x81f6280] changing packet size to 188
[mpegts @ 0x81f6280] changing packet size to 192
[mpegts @ 0x81f6280] changing packet size to 188
[mpegts @ 0x81f6280] changing packet size to 192
[mpegts @ 0x81f6280] changing packet size to 188
[mpegts @ 0x81f6280] changing packet size to 192
[mpegts @ 0x81f6280] changing packet size to 188
[mpegts @ 0x81f6280] changing packet size to 192
[mpegts @ 0x81f6280] changing packet size to 188
[mpegts @ 0x81f6280] changing packet size to 192
[mpegts @ 0x81f6280] changing packet size to 188
[mpegts @ 0x81f6280] changing packet size to 192
[mpegts @ 0x81f6280] changing packet size to 188
[mpegts @ 0x81f6280] changing packet size to 192
[mpegts @ 0x81f6280] changing packet size to 188
[mpegts @ 0x81f6280] changing packet size to 192
[mpegts @ 0x81f6280] changing packet size to 188
[mpegts @ 0x81f6280] changing packet size to 192
[mpegts @ 0x81f6280] changing packet size to 188
[mpegts @ 0x81f6280] changing packet size to 192
[mpegts @ 0x81f6280] changing packet size to 188
[mpegts @ 0x81f6280] changing packet size to 192
[mpegts @ 0x81f6280] changing packet size to 188
[mpegts @ 0x81f6280] changing packet size to 192
[mpegts @ 0x81f6280] changing packet size to 188
[mpegts @ 0x81f6280] changing packet size to 192
[mpegts @ 0x81f6280] changing packet size to 188
[mpegts @ 0x81f6280] changing packet size to 192
[mpegts @ 0x81f6280] changing packet size to 188
[mpegts @ 0x81f6280] changing packet size to 192
[mpegts @ 0x81f6280] changing packet size to 188
[mpegts @ 0x81f6280] changing packet size to 192
[mpegts @ 0x81f6280] changing packet size to 188
[mpegts @ 0x81f6280] changing packet size to 192
.
.
.
[mpegts @ 0x81f6280] changing packet size to 188
[mpegts @ 0x81f6280] changing packet size to 192
    [mpegts @ 0x81f6280] changing packet size to 188
[mpegts @ 0x81f6280] PES packet size mismatch
frame= 2971 fps=2674 q=-1.0 Lsize=   17441kB time=00:00:59.90 bitrate=2385.2kbits/s speed=53.9x    
video:16037kB audio:1410kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

谢谢

我无法重现您使用多个播放器正常播放的输入流。 .ts 在所有播放器中看起来比 mkv 更好,我猜是由于 .ts 中的纠错信息,但最终它不能 100% 正常播放。查看 ffplay 的输出,有很多与 mpeg 相关的错误,这意味着您的流转储中没有所有视频数据来正确解码。

不幸的是,我担心您无法在不进行解码和重新编码的情况下将碎片化的 .ts 文件中的直接流复制到帧精确容器中。