循环播放MP4视频 [英] Looping an MP4 video

查看:997
本文介绍了循环播放MP4视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要连接一个硬件,该硬件期望来自摄像机的MPEG-4 RTP流(实际上是来自多个不同摄像机的多个流).我们想要做的是从一组小的.mp4文件中提供视频,这些文件无休止地循环播放. 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

我现在要尝试的是在服务器模式下使用libVLC,并带有"--loop"参数.此代码如下所示:

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.

有什么办法可以像连续不断(无止境)的流一样将其呈现给客户端吗?不需要VLC,但需要RTP MP4流.

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-不,我不是想抢博物馆.这是给模拟器的.

推荐答案

cvlc(CLI VLC)中运行等效的代码会导致无效输入",这可能是由于不连续(例如,不再需要ES来完成)播放...).

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...).

有一种方法可以使用FFmpeg来实现,但这不是很简单.如果有更简单的方法,我也想知道.

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..创建要播放的文件的播放列表(例如playlist.txt).没有播放列表循环选项,因此您需要根据需要重复播放列表中的文件.使用格式:

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'

从这里开始,您将使用concat多路分配器制作无缝流.您有两种选择:

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

2-A.使用RTP并手动提供SDP文件.每个端口只能使用一个流,因此,如果需要音频,则需要将其映射到第二个输出.

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

SDP显示在控制台输出中:

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..使用RTSP将流发送到支持该流的服务器(文档中指定了Darwin Streaming Server和Mischa Spiegelmock的RTSP服务器).您需要先安装和配置服务器,然后再执行以下操作:

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

然后在客户端上使用rtsp://server/stream_name.sdp.

*博物馆盗窃应使用自动机器人垃圾桶进行.

这篇关于循环播放MP4视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆