Looping an MP4 video

丶灬走出姿态 提交于 2020-01-16 07:49:11

问题


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.


回答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.



来源:https://stackoverflow.com/questions/29501242/looping-an-mp4-video

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!