我正在尝试将 hevc 视频从 RTSP 源复制到 mkv 容器中。
这作品:rtsp(hevc) -> out.hevc
然后out.hevc -> out.mkv
这不起作用 rtsp(hevc) -> out.mkv
工作如下:
ffmpeg -nostats -hide_banner -loglevel info -rtsp_transport tcp -i rtsp://xx -an -vcodec copy -bsf:v hevc_metadata=tick_rate=1 /tmp/out.hevc -y
[hevc @ 0x564864b07680] VPS 0 does not exist
Last message repeated 1 times
Input #0, rtsp, from 'rtsp://xx':
Metadata:
title : Media Presentation
Duration: N/A, start: 0.040000, bitrate: N/A
Stream #0:0: Video: hevc (Main), yuv420p(tv), 1280x720, 2 fps, 1 tbr, 90k tbn, 2 tbc
Output #0, hevc, to '/tmp/out.hevc':
Metadata:
title : Media Presentation
encoder : Lavf58.20.100
Stream #0:0: Video: hevc (Main), yuv420p(tv), 1280x720, q=2-31, 2 fps, 1 tbr, 2 tbn, 2 tbc
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
frame= 110 fps=1.2 q=-1.0 Lsize= 10165kB time=00:01:48.50 bitrate= 767.5kbits/s speed=1.15x
video:10165kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.000000%
并检查文件:
ffprobe -hide_banner /tmp/out.hevc
Input #0, hevc, from '/tmp/out.hevc':
Duration: N/A, bitrate: N/A
Stream #0:0: Video: hevc (Main), yuv420p(tv), 1280x720, 1 fps, 1 tbr, 1200k tbn, 1 tbc
完美!将其放入 matroska 容器中:
ffmpeg -nostats -hide_banner -loglevel error -i /tmp/out.hevc -an -vcodec copy -bsf:v hevc_metadata=tick_rate=1 /tmp/out.mkv -y
检查:
ffprobe -hide_banner /tmp/out.mkv
Input #0, matroska,webm, from '/tmp/out.mkv':
Metadata:
ENCODER : Lavf58.20.100
Duration: 00:01:50.00, start: 0.000000, bitrate: 757 kb/s
Stream #0:0: Video: hevc (Main), yuv420p(tv), 1280x720, 1 fps, 1 tbr, 1k tbn, 1 tbc (default)
Metadata:
DURATION : 00:01:50.000000000
但是当我尝试直接从 RTSP(hevc) -> Matroska(hevc) 转到时:
ffmpeg -nostats -hide_banner -loglevel info -rtsp_transport tcp -i rtsp://xx -an -vcodec copy -bsf:v hevc_metadata=tick_rate=1 -f matroska /tmp/out.mkv -y
[hevc @ 0x55fda6886840] VPS 0 does not exist
Last message repeated 1 times
Input #0, rtsp, from 'rtsp://xx':
Metadata:
title : Media Presentation
Duration: N/A, start: 0.040000, bitrate: N/A
Stream #0:0: Video: hevc (Main), yuv420p(tv), 1280x720, 2 fps, 1 tbr, 90k tbn, 2 tbc
Output #0, matroska, to '/tmp/out.mkv':
Metadata:
title : Media Presentation
encoder : Lavf58.20.100
Stream #0:0: Video: hevc (Main), yuv420p(tv), 1280x720, q=2-31, 2 fps, 1 tbr, 1k tbn, 90k tbc
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
[matroska @ 0x55fda6888900] 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
frame= 51 fps=1.3 q=-1.0 Lsize= 4637kB time=00:00:49.00 bitrate= 775.2kbits/s speed=1.28x
video:4636kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.034634%
并创建了无效文件:
ffprobe -hide_banner /tmp/out.mkv
[AVBSFContext @ 0x55b897eb1980] No start code is found.
/tmp/out.mkv: Invalid data found when processing input
此Timestamps are unset in a packet for stream 0
警告令人担忧。
但我猜这是可能的,但我一直无法找到正确的字节流魔法咒语来实现这一点。最终,我试图生成分段可搜索的 matroska 文件 ( -f segment -segment_format mkv -segment_time 3600 -strftime 1 camera01-%Y%m%d-%H%M%S.mkv
),但似乎在 ffmpeg 中陷入了更深的困境。
我尝试过-live 1
并且也hevc_mp4toannexb
没有效果。
有任何想法吗?
答案1
进行管道往返
ffmpeg -rtsp_transport tcp -i rtsp://xx -an -vcodec copy -bsf:v hevc_metadata=tick_rate=1 -f hevc - | ffmpeg -f hevc -i - -c copy out.mkv -y
ffmpeg 仅在第一个数据包中寻找编解码器额外数据,但 RTSP 输入似乎没有它。
答案2
由于我无法添加评论,我想分享一下这个错误已经被报告了 3 年。(就在这个问题最初被问到的时候)