首页 > 解决方案 > 使用 ffmpeg 从 RTSP 流中捕获 CPU 使用率低的图像

问题描述

我正在使用 ffmpeg 在受限环境(小内存、磁盘和 CPU)中从 RTSP 流中捕获图像。我收到了很多损坏的图像,并且从 ffmpeg 日志中得到了如下错误:

[rtsp @ 0x7f164aca1220] max delay reached. need to consume packet
[rtsp @ 0x7f164aca1220] RTP: missed 21 packets
[h264 @ 0x7f164e7b31a0] error while decoding MB 118 17, bytestream -15
[h264 @ 0x7f164e7b31a0] concealing 6051 DC, 6051 AC, 6051 MV errors in P frame
[rtsp @ 0x7f164aca1220] max delay reached. need to consume packet
[rtsp @ 0x7f164aca1220] RTP: missed 155 packets
[h264 @ 0x7f164e7b31a0] error while decoding MB 61 19, bytestream -9
[h264 @ 0x7f164e7b31a0] concealing 5868 DC, 5868 AC, 5868 MV errors in P frame
[rtsp @ 0x7f164aca1220] max delay reached. need to consume packet
[rtsp @ 0x7f164aca1220] RTP: missed 5 packets
[h264 @ 0x7f164e7b31a0] error while decoding MB 68 45, bytestream -5
[h264 @ 0x7f164e7b31a0] concealing 2741 DC, 2741 AC, 2741 MV errors in P frame
[rtsp @ 0x7f164aca1220] max delay reached. need to consume packet
[rtsp @ 0x7f164aca1220] RTP: missed 4 packets
[h264 @ 0x7f164e7b31a0] error while decoding MB 40 48, bytestream -9
[h264 @ 0x7f164e7b31a0] concealing 2409 DC, 2409 AC, 2409 MV errors in P frame
[rtsp @ 0x7f164aca1220] max delay reached. need to consume packet
[rtsp @ 0x7f164aca1220] RTP: missed 243 packets
Input #0, rtsp, from 'rtsp://******:
version=1.0&action=getRTSPStream&ChannelID=1&ChannelName=Channel1
      Duration: N/A, start: 2.393333, bitrate: N/A
        Stream #0:0: Video: h264 (Main), yuvj420p(pc, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 15 fps, 20 tbr, 90k tbn, 30 tbc
    Output #0, image2, to 'frames/image6.jpg':
      Metadata:
        title           : Media Presentation
        comment         : StreamingSetting?version=1.0&action=getRTSPStream&ChannelID=1&ChannelName=Channel1
        encoder         : Lavf57.56.101
        Stream #0:0: Video: mjpeg, yuvj420p(pc), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 20 fps, 20 tbn, 20 tbc
        Metadata:
          encoder         : Lavc57.64.101 mjpeg
        Side data:
          cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
    Stream mapping:
      Stream #0:0 -> #0:0 (h264 (native) -> mjpeg (native))

我尝试了几种不同的方法来解决这些错误,例如像这样使用 TCP 协议:

"ffmpeg -nostats -loglevel 0 -rtsp_transport tcp -y -i rtsp://****** -vframes 1 frames/image" + str(count)  +".jpg"

但它不起作用。

我在 ffmpeg 拍摄图像时检查了 CPU 使用率,发现 CPU 使用率高达 99%。而且我认为损坏的图像很可能是由高 CPU 使用率引起的。我阅读了几篇文章来解决 ffmpeg 高 CPU 问题,同时捕获视频而不是图像,例如这个链接

但是,在使用 ffmpeg 从 RTSP 流中捕获图像时,我们是否有任何命令选项来减少 CPU 使用率?

非常感谢您!

标签: ffmpegcpu-usagertsp

解决方案


推荐阅读