# Problem getting FFmpeg to convert RSTP to MP4

**URL:** <https://discourse.nodered.org/t/problem-getting-ffmpeg-to-convert-rstp-to-mp4/39867>\
**Category:** General\
**Created:** [27 January 2021 11:58 UTC](https://discourse.nodered.org/t/problem-getting-ffmpeg-to-convert-rstp-to-mp4/39867 "2021-01-27T11:58:52Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dave/32/10827_2.png) [@Dave](https://discourse.nodered.org/u/Dave)\
**Post date:** [27 January 2021 11:58 UTC](https://discourse.nodered.org/t/problem-getting-ffmpeg-to-convert-rstp-to-mp4/39867/1 "2021-01-27T11:58:52Z")

</div>

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](https://www.aliexpress.com/item/4000785637334.html?spm=a2g0s.9042311.0.0.27424c4dzFHdJT) 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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/a/3a962c45ebe7c8d68334d322553404f65bffb70c.png)

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [27 January 2021 12:50 UTC](https://discourse.nodered.org/t/problem-getting-ffmpeg-to-convert-rstp-to-mp4/39867/2 "2021-01-27T12:50:52Z")

</div>

> [@Dave](#):
>
> node-red-contrib-ui-mp4frag

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

```auto
`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`

```

---

<div class="post-metadata">

**Author:** ![kevinGodell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kevingodell/32/27040_2.png) [@kevinGodell](https://discourse.nodered.org/u/kevinGodell)\
**Post date:** [27 January 2021 13:00 UTC](https://discourse.nodered.org/t/problem-getting-ffmpeg-to-convert-rstp-to-mp4/39867/3 "2021-01-27T13:00:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Dave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dave/32/10827_2.png) [@Dave](https://discourse.nodered.org/u/Dave)\
**Post date:** [27 January 2021 13:22 UTC](https://discourse.nodered.org/t/problem-getting-ffmpeg-to-convert-rstp-to-mp4/39867/4 "2021-01-27T13:22:48Z")

</div>

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%

---

<div class="post-metadata">

**Author:** ![Dave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dave/32/10827_2.png) [@Dave](https://discourse.nodered.org/u/Dave)\
**Post date:** [27 January 2021 13:30 UTC](https://discourse.nodered.org/t/problem-getting-ffmpeg-to-convert-rstp-to-mp4/39867/5 "2021-01-27T13:30:34Z")

</div>

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%

---

<div class="post-metadata">

**Author:** ![Dave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dave/32/10827_2.png) [@Dave](https://discourse.nodered.org/u/Dave)\
**Post date:** [27 January 2021 14:08 UTC](https://discourse.nodered.org/t/problem-getting-ffmpeg-to-convert-rstp-to-mp4/39867/6 "2021-01-27T14:08:14Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/c/ec85aef09fe7231cc7563ff9f3a84b4cf9327ed2.png)

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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/4/9459bbad54a5962e299717690c5d3cefb63af237.png)

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

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [27 January 2021 14:14 UTC](https://discourse.nodered.org/t/problem-getting-ffmpeg-to-convert-rstp-to-mp4/39867/7 "2021-01-27T14:14:28Z")

</div>

> [@Dave](#):
>
> happy now...

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

---

<div class="post-metadata">

**Author:** ![Dave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dave/32/10827_2.png) [@Dave](https://discourse.nodered.org/u/Dave)\
**Post date:** [27 January 2021 14:23 UTC](https://discourse.nodered.org/t/problem-getting-ffmpeg-to-convert-rstp-to-mp4/39867/8 "2021-01-27T14:23:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [10 February 2021 14:24 UTC](https://discourse.nodered.org/t/problem-getting-ffmpeg-to-convert-rstp-to-mp4/39867/9 "2021-02-10T14:24:37Z")

</div>

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