1

I need to interface with a piece of hardware that is expecting an MPEG-4 RTP stream from a camera (actually multiple streams from multiple different cameras). What we'd like to do is supply that video from a set of small .mp4 files, looped endlessly.1

What I'm trying right now is to use libVLC in server mode, with the "--loop" argument. The code for this looks like the following:

    libvlc_vlm_add_broadcast(vlc, "test", ("file:///" + video).c_str(),
                            "#rtp{dst=localhost,port=1234,sdp=rtsp://localhost:8080/test.sdp}",
                            1, broadcast_options, true, true);
    const auto play_result = libvlc_vlm_play_media(vlc, "test");

This seems to be working on my desktop, with one issue: I have to put the player on loop too. If I just ask the player to play the stream once, it stops when the end of the file from the server is reached.

Is there any way to get this to look to the client like one continuous (never-ending) stream? VLC isn't a requirement, but an RTP MP4 stream is.

1 - No, I'm not trying to rob a museum. This is for a simulator.

T.E.D.
  • 44,016
  • 10
  • 73
  • 134

1 Answers1

1

Running the equivalent of your code in cvlc (CLI VLC) results in a "dead input", probably due to a discontinuity (says no more ES to play...).

There is a way to do it using FFmpeg, but it's not very straight-forward. If there's an easier way I'd like to know as well.

1. Create a playlist of files to play (say playlist.txt). There is no playlist loop option so you need to repeat the files in the playlist as many times as you see fit. Use the format:

file '/path/to/file/1.mp4'    
file '/path/to/file/2.mp4'    
file '/path/to/file/3.mp4'    
[... repeat ...]    
file '/path/to/file/1.mp4'    
file '/path/to/file/2.mp4'    
file '/path/to/file/3.mp4'

From here on you'll use the concat demuxer to make a seamless stream. You have two options:

2-A. Use RTP and provide a SDP file manually. You can only use one stream per port so if you need audio you need to map it to a second output.

ffmpeg -re -f concat -i playlist.txt -an -vcodec mpeg4 -f rtp rtp://127.0.0.1:1234

The SDP is shown in the console output:

v=0
o=- 0 0 IN IP4 127.0.0.1
s=No Name
c=IN IP4 127.0.0.1
t=0 0
a=tool:libavformat 56.26.101
m=video 1234 RTP/AVP 96
b=AS:200
a=rtpmap:96 MP4V-ES/90000
a=fmtp:96 profile-level-id=1

2-B. Use RTSP to send the stream to a server supporting it (the documentation specifies Darwin Streaming Server and Mischa Spiegelmock’s RTSP server). You need to install and configure the servers before doing:

ffmpeg -re -f concat -i playlist.txt -an -vcodec mpeg4 -f rtsp rtsp://server:port/stream_name.sdp

Then use rtsp://server/stream_name.sdp on a client.

*A museum theft should be done using automated robot trash-cans.

aergistal
  • 29,947
  • 5
  • 70
  • 92
  • The real clients in this case are (from our perspective) black boxes hanging off an Ethernet link. That means we have to give them *exactly* what they are expecting, and their protocol doesn't say anything about RTSP (just RTP and MP4). So I'm not sure if RTSP and/or SDP are involved or not. The protocol docs bother to mention ICMP and ARP, so you'd think if RTSP or SDP were involved they would have said so. But perhaps RTP implies one or both of those, and this is just my ignorance showing? I'll give these a try and see what happens. – T.E.D. Apr 08 '15 at 20:47
  • I was kind of just picturing it being a continuous RTP/MP4 stream (broadcasting to a multicast address) that a client could jump into and out of on the fly. – T.E.D. Apr 08 '15 at 20:50
  • I thought you were using an SDP because your example command says `sdp=rtsp://localhost:8080/test.sdp`. Without the Session Description Protocol it might not know how to play the stream since FFmpeg uses a dynamic payload type ID (96) hence the need to map it to an actual stream type in the SDP. How did you test it so far? – aergistal Apr 08 '15 at 20:56
  • ...looking this over, it doesn't look like we are looping infinitely, but just repeating a finite amount of times (as specified in the playlist), right? – T.E.D. Apr 08 '15 at 20:56
  • yes, there's no playlist loop. Add content for 1 year : ) – aergistal Apr 08 '15 at 20:57
  • Ah, IC. That's the thing, I haven't tried this out against the actual black box yet, and I don't think what I have right now will work (due to the stream not continuing forever like a real MP4/RTP camera would). – T.E.D. Apr 08 '15 at 20:58
  • I would start with the black box specs. – aergistal Apr 08 '15 at 21:16