简体   繁体   English

如何将openRTSP中的MP4文件编码优化到与FFmpeg相同的水平?

[英]How can I optimize MP4 file encoding in openRTSP to the same level as FFmpeg?

I currently receive and store a RTSP stream from a camera with openRTSP with a command like this: 我目前使用以下命令从带有openRTSP的摄像机接收和存储RTSP流:

openRTSP -4 "rtsp://192.168.41.185/rtsp_tunnel?h26x=4&line=1&inst=2" > movie.mp4

I can do the same using FFmpeg: 我可以使用FFmpeg做同样的事情:

ffmpeg -i "rtsp://192.168.41.185/rtsp_tunnel?h26x=4&line=1&inst=2" -vcodec copy movie.mp4

The video frames from the camera are 1280x720 (H.264) at around 30 fps and have a milliseconds timestamp stamped in. When I view the movie.mp4 created by ffmpeg it looks pretty nice, the seconds stamped into the video stream seem rather accurate. 摄像机的视频帧为1280x720(H.264),约30 fps,并标记了毫秒级的时间戳。当我查看由ffmpeg创建的movie.mp4时,它看起来非常漂亮,标记在视频流中的秒数似乎相当准确。 On the contrary, if I view the movie.mp4 created by openRTSP, the seconds in the video timestamp last definitively longer than the ones in reality. 相反,如果我查看由openRTSP创建的movie.mp4,则视频时间戳记中的秒数肯定比实际中的秒数更长。 So one second on video could last two seconds in reality. 因此,一秒钟的视频实际上可以持续两秒钟。 I made several tests, and it is not an issue of network performance or of handling the messages received from the camera. 我进行了几次测试,这不是网络性能或处理从相机接收到的消息的问题。 The reason seems to be the part where the messages are encoded into this MP4 container . 原因似乎是消息被编码到此MP4容器中的部分

Is FFmpeg so much faster doing this than openRTSP? FFmpeg这样做比openRTSP快得多吗?

Can I optimize the MP4 encoding in openRTSP somehow? 我可以通过某种方式优化openRTSP中的MP4编码吗?

Okay, it is not a performance issue, but rather in issue that openRTSP is not able to detect the correct frame rate from the RTSP stream. 好的,这不是性能问题,而是问题在于,openRTSP无法从RTSP流中检测正确的帧速率。 I recorded exactly 60 seconds, and as suggested, I used ffprobe to get more information about the bitstream: 我恰好记录了60秒,并且按照建议,我使用ffprobe获得了有关比特流的更多信息:

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'output-00000-00060.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isom
    creation_time   : 2018-07-02 03:30:01
  Duration: 00:04:00.13, start: 0.000000, bitrate: 46 kb/s
    Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuvj420p(pc, bt470bg/bt470bg/iec61966-2-1), 1280x720 [SAR 561:560 DAR 187:105], 45 kb/s, 15 fps, 15 tbr, 600 tbn, 1200 tbc (default)
    Metadata:
      creation_time   : 2018-07-02 03:30:01
      handler_name    : ?Apple Alias Data Handler
      encoder         : H.264

Two things are wrong: 有两件事是错误的:

  • Issue #1: The frame rate is not 15 fps, but the camera is configured to try to send 30 fps. 问题#1:帧频不是15 fps,但是相机配置为尝试发送30 fps。
  • Issue #2:The duration is 4:00, but should be 1:00 问题2:持续时间为4:00,但应为1:00

For issue #1: That may be my fault . 对于问题1:这可能是我的错 I should have manually specified the frame rate as openRTSP doesn't get it from the stream. 我应该手动指定帧速率,因为openRTSP不能从流中获取帧速率。 I should have specified the option -f 30 . 我应该指定选项-f 30

For issue #2: After giving the option -f 30 I still get a video file with a duration of 2:00 instead 1.00. 对于问题2:在提供-f 30选项后,我仍然获得了时长为2:00而不是1.00的视频文件。 I guess that the problem is that the camera sends its data in progressive mode, and not in interlaced mode. 我想问题是相机以逐行模式而不是隔行模式发送数据。 Maybe openRTSP's default is interlaced mode. 也许openRTSP的默认设置是隔行模式。 So when I double the frame rate to -f 60 everything is all right. 因此,当我将帧速率翻倍至-f 60一切都很好。

Maybe someone can confirm my guess? 也许有人可以证实我的猜测?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM