Problem getting FFmpeg to convert RSTP to MP4

Over the last 2 days I have been pulling my hair out trying to get my ptz camera to display on dashboard via FFmpeg in exec node and kevinGodell/node-red-contrib-mp4frag and node-red-contrib-ui-mp4frag

I have read every post and trying as many exec node FFmpeg cmd lines as I have seen all without success, the best I get was ..
ffmpeg -i rtsp://192.168.0.67:554/user=admin_password=mkNJWdWL_channel=1_stream=1.sdp?real_stream -an -c:v copy -f mp4 -movflags +frag_keyframe+empty_moov+default_base_moof pipe:1

Which does not output anything (exec node blue pid:*** frag nodes green: reset & unloaded) but I do get a buffer showing up on a debug node connected to the exec node when I stop the flow also I get ..
Command failed: ffmpeg -i rtsp://192.168.0.67:554/user=admin_password=mkNJWdWL_channel=1_stream=0.sdp?real_stream -an -c:v copy -f mp4 -movflags +frag_keyframe+empty_moov+default_base_moof pipe:1
ffmpeg version 4.1.6-1~deb10u1+rpt1 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 8 (Raspbian 8.3.0-6+rpi1)

camera is 3MP 2MP HD PTZ Auto Tracking WiFi Camera AI Humanoid Detection Outdoor IP Camera Two Way Audio IR Night Vision CCTV Surveillance|Surveillance Cameras| - AliExpress same one as SuperNinja I think

I'm really struggling here, any help would be most appreciated

My Setup..
rpi 3b with fresh install of latest 2021-01-11-raspios-buster-armhf.img
fresh install of node-red 1.2.7 and dashboard 2.27.0 node v12.20.1
Barts onvif nodes work with all the examples successfully inc image preview and ptz control.
kevinGodell nodes work with all the examples successfully.
if I open ispy I can select add camera and get video, indicated url rtsp://192.168.0.67:554/user=admin_password=mkNJWdWL_channel=1_stream=0.sdp?real_stream
I can open VLC open media add above url in 'network URL:' press play and get video.

image

In the node configurations, what player have you defined? Could you try with hls.js in first position

For ffmpeg, I think maybe try the below that I think is the latest type of recommendations

`ffmpeg -i rtsp://192.168.0.67:554/user=admin_password=mkNJWdWL_channel=1_stream=1.sdp?real_stream -an -c:v copy -f mp4 -movflags +frag_every_frame+empty_moov+default_base_moof -min_frag_duration 500000 pipe:1`

Just to make sure your ffmpeg is good, try running the command on the command line first, but change the output to be testvideo.mp4 instead of pipe:1. Stop the command after a few seconds and try to play the video.

Hi krambriw thanks for response hls.js in first position and latest ffmpeg recommendation both have exactly same result as in post 1.

Hi kevinGodell thanks for your response also result as follows ..
Note the resulting testvideo.mp4 file does play when i transferred it to windows and played it.

libavutil 56. 22.100 / 56. 22.100
libavcodec 58. 35.100 / 58. 35.100
libavformat 58. 20.100 / 58. 20.100
libavdevice 58. 5.100 / 58. 5.100
libavfilter 7. 40.101 / 7. 40.101
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 3.100 / 5. 3.100
libswresample 3. 3.100 / 3. 3.100
libpostproc 55. 3.100 / 55. 3.100
Guessed Channel Layout for Input Stream #0.1 : mono
Input #0, rtsp, from 'rtsp://192.168.0.67:554/user=admin_password=mkNJWdWL_channel=1_stream=1.sdp?real_stream':
Metadata:
title : RTSP Session
Duration: N/A, start: 0.000000, bitrate: N/A
Stream #0:0: Video: h264 (Main), yuv420p(progressive), 640x360, 12 fps, 12 tbr, 90k tbn, 24 tbc
Stream #0:1: Audio: pcm_alaw, 8000 Hz, mono, s16, 64 kb/s
Output #0, mp4, to 'testvideo.mp4':
Metadata:
title : RTSP Session
encoder : Lavf58.20.100
Stream #0:0: Video: h264 (Main) (avc1 / 0x31637661), yuv420p(progressive), 640x360, q=2-31, 12 fps, 12 tbr, 90k tbn, 90k tbc
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
[mp4 @ 0x1a34c40] Non-monotonous DTS in output stream 0:0; previous: 45000, current: 7500; changing to 45001. This may result in incorrect timestamps in the output file.
[mp4 @ 0x1a34c40] Non-monotonous DTS in output stream 0:0; previous: 45001, current: 15000; changing to 45002. This may result in incorrect timestamps in the output file.
[mp4 @ 0x1a34c40] Non-monotonous DTS in output stream 0:0; previous: 45002, current: 22500; changing to 45003. This may result in incorrect timestamps in the output file.
[mp4 @ 0x1a34c40] Non-monotonous DTS in output stream 0:0; previous: 45003, current: 30000; changing to 45004. This may result in incorrect timestamps in the output file.
[mp4 @ 0x1a34c40] Non-monotonous DTS in output stream 0:0; previous: 45004, current: 37500; changing to 45005. This may result in incorrect timestamps in the output file.
[mp4 @ 0x1a34c40] Non-monotonous DTS in output stream 0:0; previous: 45005, current: 45000; changing to 45006. This may result in incorrect timestamps in the output file.
[rtsp @ 0x19d6270] max delay reached. need to consume packetbitrate= 90.9kbits/s speed=0.951x
[rtsp @ 0x19d6270] RTP: missed 1 packets
[rtsp @ 0x19d6270] max delay reached. need to consume packet
[rtsp @ 0x19d6270] RTP: missed 30 packets
[rtsp @ 0x19d6270] max delay reached. need to consume packet
[rtsp @ 0x19d6270] RTP: missed 2 packets
[rtsp @ 0x19d6270] max delay reached. need to consume packet
[rtsp @ 0x19d6270] RTP: missed 12 packets
[rtsp @ 0x19d6270] max delay reached. need to consume packetbitrate= 76.3kbits/s speed=1.23x
[rtsp @ 0x19d6270] RTP: missed 122 packets
[rtsp @ 0x19d6270] max delay reached. need to consume packet
[rtsp @ 0x19d6270] RTP: missed 1 packets
[rtsp @ 0x19d6270] max delay reached. need to consume packetbitrate= 80.5kbits/s speed=1.14x
[rtsp @ 0x19d6270] RTP: missed 4 packets
[rtsp @ 0x19d6270] max delay reached. need to consume packet
[rtsp @ 0x19d6270] RTP: missed 1 packets
[rtsp @ 0x19d6270] max delay reached. need to consume packetbitrate= 83.3kbits/s speed=1.14x
[rtsp @ 0x19d6270] RTP: missed 2 packets
[rtsp @ 0x19d6270] max delay reached. need to consume packetbitrate= 85.4kbits/s speed=1.13x
[rtsp @ 0x19d6270] RTP: missed 2 packets
[rtsp @ 0x19d6270] max delay reached. need to consume packetbitrate= 83.6kbits/s speed=1.12x
[rtsp @ 0x19d6270] RTP: missed 3 packets
[rtsp @ 0x19d6270] max delay reached. need to consume packet
[rtsp @ 0x19d6270] RTP: missed 1 packets
[rtsp @ 0x19d6270] max delay reached. need to consume packetbitrate= 83.0kbits/s speed=1.14x
[rtsp @ 0x19d6270] RTP: missed 1 packets
[rtsp @ 0x19d6270] max delay reached. need to consume packetbitrate= 82.3kbits/s speed= 1.1x
[rtsp @ 0x19d6270] RTP: missed 11 packets
[rtsp @ 0x19d6270] max delay reached. need to consume packet
[rtsp @ 0x19d6270] RTP: missed 3 packets
[rtsp @ 0x19d6270] max delay reached. need to consume packetbitrate= 82.4kbits/s speed= 1.1x
[rtsp @ 0x19d6270] RTP: missed 1 packets
[rtsp @ 0x19d6270] max delay reached. need to consume packetbitrate= 82.2kbits/s speed=1.09x
[rtsp @ 0x19d6270] RTP: missed 5 packets
[rtsp @ 0x19d6270] max delay reached. need to consume packet
[rtsp @ 0x19d6270] RTP: missed 2 packets
frame= 242 fps= 12 q=-1.0 Lsize= 236kB time=00:00:22.83 bitrate= 84.7kbits/s speed=1.09x
video:229kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 3.169487%

Oh sorry I think the missed packets were because VLC was still running the stream.
I closed it down and retested here are is the result ..

libavutil 56. 22.100 / 56. 22.100
libavcodec 58. 35.100 / 58. 35.100
libavformat 58. 20.100 / 58. 20.100
libavdevice 58. 5.100 / 58. 5.100
libavfilter 7. 40.101 / 7. 40.101
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 3.100 / 5. 3.100
libswresample 3. 3.100 / 3. 3.100
libpostproc 55. 3.100 / 55. 3.100
Guessed Channel Layout for Input Stream #0.1 : mono
Input #0, rtsp, from 'rtsp://192.168.0.67:554/user=admin_password=mkNJWdWL_channel=1_stream=1.sdp?real_stream':
Metadata:
title : RTSP Session
Duration: N/A, start: 0.000000, bitrate: N/A
Stream #0:0: Video: h264 (Main), yuv420p(progressive), 640x360, 12 fps, 12 tbr, 90k tbn, 24 tbc
Stream #0:1: Audio: pcm_alaw, 8000 Hz, mono, s16, 64 kb/s
Output #0, mp4, to 'testvideo.mp4':
Metadata:
title : RTSP Session
encoder : Lavf58.20.100
Stream #0:0: Video: h264 (Main) (avc1 / 0x31637661), yuv420p(progressive), 640x360, q=2-31, 12 fps, 12 tbr, 90k tbn, 90k tbc
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
[mp4 @ 0x1b60420] Non-monotonous DTS in output stream 0:0; previous: 45000, current: 7500; changing to 45001. This may result in incorrect timestamps in the output file.
[mp4 @ 0x1b60420] Non-monotonous DTS in output stream 0:0; previous: 45001, current: 15000; changing to 45002. This may result in incorrect timestamps in the output file.
[mp4 @ 0x1b60420] Non-monotonous DTS in output stream 0:0; previous: 45002, current: 22500; changing to 45003. This may result in incorrect timestamps in the output file.
[mp4 @ 0x1b60420] Non-monotonous DTS in output stream 0:0; previous: 45003, current: 30000; changing to 45004. This may result in incorrect timestamps in the output file.
[mp4 @ 0x1b60420] Non-monotonous DTS in output stream 0:0; previous: 45004, current: 37500; changing to 45005. This may result in incorrect timestamps in the output file.
[mp4 @ 0x1b60420] Non-monotonous DTS in output stream 0:0; previous: 45005, current: 45000; changing to 45006. This may result in incorrect timestamps in the output file.
frame= 150 fps= 15 q=-1.0 Lsize= 161kB time=00:00:12.41 bitrate= 106.0kbits/s speed=1.22x
video:156kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 2.863517%

OK I got it working ... seams I made a mistake exec needs to be in spawn mode ..

Command
ffmpeg -i rtsp://192.168.0.67:554/user=admin_password=mkNJWdWL_channel=1_stream=1.sdp?real_stream -an -c:v copy -f mp4 -movflags +frag_every_frame+empty_moov+default_base_moof -min_frag_duration 500000 pipe:1

and it works best with player set like ..

image

Thanks everyone for your help I am so happy now...

Great, that's the most important piece. These nodes does really work well!

Yeh they really are great, the reason I wasn't in spawn mode is I tried every thing humanly possible to get it to work, every combination in every node, but for sure the light at the end of the tunnel came with your advice to make a testvideo.mp4 file that proved the ffpeg command was working, that's a great debugging tool for anyone following this.

Thanks again.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.