简体   繁体   中英

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 -4 "rtsp://192.168.41.185/rtsp_tunnel?h26x=4&line=1&inst=2" > movie.mp4

I can do the same using 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. 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. 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 .

Is FFmpeg so much faster doing this than openRTSP?

Can I optimize the MP4 encoding in openRTSP somehow?

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. I recorded exactly 60 seconds, and as suggested, I used ffprobe to get more information about the bitstream:

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.
  • Issue #2:The duration is 4:00, but should be 1:00

For issue #1: That may be my fault . I should have manually specified the frame rate as openRTSP doesn't get it from the stream. I should have specified the option -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. 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. So when I double the frame rate to -f 60 everything is all right.

Maybe someone can confirm my guess?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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