我正在尝试将具有此输出的。ts文件转换为mkv:
ffmpeg version 4.3.1 Copyright (c) 2000-2020 the FFmpeg developers
built with Apple clang version 12.0.0 (clang-1200.0.32.27)
configuration: --prefix=/usr/local/Cellar/ffmpeg/4.3.1_4 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-libsoxr --enable-videotoolbox --disable-libjack --disable-indev=jack
libavutil 56. 51.100 / 56. 51.100
libavcodec 58. 91.100 / 58. 91.100
libavformat 58. 45.100 / 58. 45.100
libavdevice 58. 10.100 / 58. 10.100
libavfilter 7. 85.100 / 7. 85.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 7.100 / 5. 7.100
libswresample 3. 7.100 / 3. 7.100
libpostproc 55. 7.100 / 55. 7.100
[mp3float @ 0x7fbd6282b200] Header missing
[mpegts @ 0x7fbd62809000] PES packet size mismatch
[mpegts @ 0x7fbd62809000] Packet corrupt (stream = 2, dts = 7125804577).
[mpegts @ 0x7fbd62809000] PES packet size mismatch
[mpegts @ 0x7fbd62809000] Packet corrupt (stream = 2, dts = 7125804577).
[mpegts @ 0x7fbd62809000] PES packet size mismatch
[mpegts @ 0x7fbd62809000] Packet corrupt (stream = 1, dts = 7125790091).
Input #0, mpegts, from '/Users/"User"/Downloads/input.ts':
Duration: 02:11:32.82, start: 71283.837456, bitrate: 17149 kb/s
Program 1
Stream #0:0[0x1004]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuvj420p(pc, bt709, progressive), 1280x720 [SAR 1:1 DAR 16:9], 50 fps, 2.08 tbr, 90k tbn, 100 tbc
Stream #0:1[0x1104](swe): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, fltp, 256 kb/s
Stream #0:2[0x704](swe): Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, 5.1(side), fltp, 640 kb/s
要做到这一点,我使用以下命令:
ffmpeg -i input.ts -c copy output.mkv
但是转换失败,出现以下错误:
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:2 -> #0:1 (copy)
Press [q] to stop, [?] for help
[matroska @ 0x7fb8c1808200] 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 @ 0x7fb8c1808200] Can't write packet with unknown timestamp
av_interleaved_write_frame(): Invalid argument
[matroska @ 0x7fb8c1808200] Can't write packet with unknown timestamp
Error writing trailer of output.mkv: Invalid argument
frame= 27 fps=0.0 q=-1.0 Lsize= 74kB time=00:00:00.85 bitrate= 705.5kbits/s speed= 99x
video:1092kB audio:35kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Conversion failed!
我该怎么做才能解决这个问题?我已经尝试在开始时添加-fflags +genpts
,但它失败了。
编辑:我用MKVToolNix解决了这个问题。
对于有此问题的其他人,我有一个类似的问题,通过在输入之前添加-fflags +genpts
并让它为我生成缺失的时间戳来解决。
ffmpeg -fflags +genpts -i input.ts -c copy output.mkv
编辑:
另一种解决方案可能是将其带到mp4
而不是mkv
(可能使用它作为中间人,然后再带到mkv
)。
极端情况下:
我遇到了一个场景,基本上需要"核";选择将视频以其设置的帧率转换为原始流文件,然后将其与音频一起拉回mp4
容器。
首先找到帧率它应该是
ffprobe -v quiet -loglevel panic -show_entries stream=avg_frame_rate -print_format flat -select_streams v <my_video>
它会输出类似streams.stream.0.avg_frame_rate="60000/1001"
的内容我们关心的是引号里面的内容,60000/1001
以设定的帧率将流转换为自身的原始格式。例如,H264将进入.h264
容器。
ffmpeg -fflags +genpts -ignore_editlist 1 -r 60000/1001 -i <my_video> -c:v copy -map 0:v -r 60000/1001 temp.h264
然后将原始音轨从临时文件-map 0:v -c:v copy
中带回来,并将音频-map 1:a -c:a copy
和原始字幕-map 1:s -c:s copy
混合。
ffmpeg -fflags +genpts -r 60000/1001 -i temp.h264 -i <my_video> -c:v copy -map 0:v -map 1:a -map 1:s -c:a copy -c:s copy fixed_video.mp4
尝试使用-ss
标志运行
ffmpeg -ss 0:01 -i input.ts -c copy output.mkv