如何使用 Web 服务从 VLC (linux) 流式传输到 iPod(完整过程)?
我想使用 VLC 将 Linux 中的网络摄像头流式传输到 iPod。从我在网络上看到的情况来看,最简单的方法是使用网络服务器,然后从 iPod 访问它,如下所示:
NSString *url = @"http://www.example.com/path/to/movie.mp4";
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:url]];
[moviePlayer play];
我以前从未使用过网络服务,想知道如何实现整个过程。谢谢
编辑:设置 linux/vlc/segmenter 后,这是我在运行 Warren 的评论并退出 vlc 后在终端中得到的结果:
VLC media player 1.1.4 The Luggage (revision exported)
Blocked: call to unsetenv("DBUS_ACTIVATION_ADDRESS")
Blocked: call to unsetenv("DBUS_ACTIVATION_BUS_TYPE")
[0x87bc914] main libvlc: Running vlc with the default interface. Use 'cvlc' to use vlc without interface.
Blocked: call to setlocale(6, "")
Blocked: call to sigaction(17, 0xb71840d4, 0xb7184048)
Warning: call to signal(13, 0x1)
Warning: call to signal(13, 0x1)
Warning: call to srand(1309581991)
Warning: call to rand()
Blocked: call to setlocale(6, "")
(process:4398): Gtk-WARNING **: Locale not supported by C library.
Using the fallback 'C' locale.
Warning: call to signal(13, 0x1)
Warning: call to signal(13, 0x1)
Blocked: call to setlocale(6, "")
Could not open input file, make sure it is an mpegts file: -1
帮助我理解这一切吗?谢谢!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您显示的 URL 假定视频是预先录制的。
对于传输到 iOS 设备的实时 HTTP 流式传输,URL 将以
.m3u
或.m3u8
结尾,这是常见的播放列表格式类型。 (它是 Icecast 播放列表格式的扩展版本,记录在 此 IETF 草案。)此播放列表告诉 iOS 设备如何查找它将依次检索的其他文件,以便流式传输视频。第一个棘手的部分是生成视频流。与所有其他 iOS 兼容媒体文件不同,实时 HTTP 流媒体需要 MPEG-2 传输流 (.ts) 容器,而不是 MPEG-4 第 14 部分容器(.mp4、.m4v)。如您所料,视频编解码器仍然是 H.264,音频编解码器仍然是 AAC。
像这样的命令应该可以工作:
这是一个很长的命令。为了清楚起见,我刚刚将其分解,并解决了 SO 的格式样式限制。如果您愿意,可以删除反斜杠和空格以使其成为单行。有关帮助,请参阅 VLC 流媒体 HOWTO弄清楚这一切意味着什么,以及如何调整它。
/dev/camera
位可能需要调整,并且您可能想根据 Apple 的最佳实践技术说明 (#TN 2224) 以适合您的目标 iOS 设备功能。下一个棘手的部分是从实时视频源生成此播放列表文件和视频片段文件。
Apple 提供了一个名为
mediastreamsgementer
的程序它可以做到这一点,但它不是开源的,它只能在 OS X 上运行,而且甚至不能免费下载。 (它是 Snow Leopard 的一部分,但除此之外,您必须加入 Apple 的开发者计划才能下载副本。)Chase Douglas 制作了一个 基本分段器,它是针对 libavformat 构建的rel="nofollow noreferrer">ffmpeg。 此处有一个较新的变体,它具有多种改进。
要将其与上面的
vlc
相机捕获和编码命令结合使用,请将> 替换为test.ts
部分是这样的:这通过分段器传输 VLC 的视频输出,分段器将 TS 分成 10 秒的块,并维护告诉 iOS 的
test.m3u8
播放列表文件设备如何查找段文件。-
参数告诉分段器视频流正在通过管道传输到其标准输入,而不是来自文件。末尾的 URL 片段被添加到 M3U 文件中提到的文件名上。完成所有这些后,Cocoa Touch 代码唯一需要的调整是它应该访问
test.m3u8
而不是movie.mp4
。The URL you show assumes the video is prerecorded.
For live HTTP streaming to an iOS device, the URL will instead end in
.m3u
or.m3u8
, which is a common playlist format type. (It is an extended version of the Icecast playlist format, documented in this IETF draft.) This playlist tells the iOS device how to find the other files it will retrieve, in series, in order to stream the video.The first tricky bit is producing the video stream. Unlike all other iOS compatible media files, live HTTP streaming requires an MPEG-2 transport stream (.ts) container, rather than an MPEG-4 part 14 container (.mp4, .m4v). The video codec is still H.264 and the audio AAC, as you might expect.
A command something like this should work:
This is all one long command. I've just broken it up for clarity, and to work around SO's formatting style limits. You can remove the backslashes and whitespace to make it a single long line, if you prefer. See the VLC Streaming HOWTO for help on figuring out what all that means, and how to adjust it.
The
/dev/camera
bit will probably have to be adjusted, and you may want to fiddle with the A/V encoding parameters based on Apple's best practices tech note (#TN 2224) to suit your target iOS device capabilites.The next tricky bit is producing this playlist file and the video segment files from the live video feed.
Apple offers a program called
mediastreamsgementer
which does this, but it's not open source, it only runs on OS X, and it isn't even freely downloadable. (It comes as part of Snow Leopard, but otherwise, you have to be in Apple's developer program to download a copy.)Chase Douglas has produced a basic segmenter which builds against
libavformat
from ffmpeg. There is a newer variant here which has various improvments.To combine this with the
vlc
camera capture and encoding command above, replace the> test.ts
part with something like this:This pipes VLC's video output through the segmenter, which breaks the TS up into 10 second chunks and maintains the
test.m3u8
playlist file that tells the iOS device how to find the segment files. The-
argument tells the segmenter that the video stream is being piped into its standard input, rather than coming from a file. The URL fragment at the end gets prepended onto the file names mentioned in the M3U file.Having done all that, the only adjustment that should be needed for your Cocoa Touch code is that it should be accessing
test.m3u8
instead ofmovie.mp4
.