使用非标准协议流式传输视频
我的公司生产专门用于流式传输直播和录制视频的 DVR。该视频使用标准 MPEG-4 编解码器进行编码,因此 Android 中的编解码器应该不会遇到任何问题。但是,视频是使用非标准文件格式录制的,并使用我们的专有协议进行流式传输(除其他外,我们在每帧视频中嵌入了附加数据,例如水印)。有什么方法可以让我的流拉出帧并让它在 Android 设备上播放吗?
谢谢!
My company makes DVRs that specialize in streaming live and recorded video. The video is encoded using standard MPEG-4 codecs so the codecs in Android should have no trouble with them. However, the video is recorded using non-standard file formats and is streamed using our proprietary protocol (among other things we embed additional data such as watermarks with each frame of video). Is there any way I can take my stream pull out the frames and have it play on an Android device?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Android 有
java.net.Socket
,因此理论上您可以为专有流编写客户端。但是,我不知道如何利用现有的 Android 播放功能(例如MediaPlayer
)。它似乎只支持播放文件或URL。输入流明显丢失。Android has
java.net.Socket
, so in theory you can write a client for the proprietary stream. However, I don't know how you could take advantage the existing Android playback functionality (e.g.MediaPlayer
). It only seems to support playing a file or a URL. InputStream is noticeably missing.您可以创建一个套接字,获取它的“文件描述符”,并将其提供给
MediaPlayer.setDataSource()
。实际上我不久前也做过类似的事情,所以这种方法已经在现场进行了测试。
我完全忘记了如何从套接字中提取文件描述符,但我认为使用反射(或更可能是本机代码),您可以在套接字上获取“
impl
”成员,它是 LocalSocket 或其他东西,并且有一个“fd
”成员。谷歌搜索没有找到任何人描述这一点,因此您必须自己探索确切的成员名称和详细信息。容器格式必须是 Android 系统可以识别的格式;如有必要,您可以使用 native 代码创建 pipe 以便您可以使用线程将自定义容器重新打包为 Android 支持的动态容器。
我想到 Android 很有可能播放“原始”H.263 和 H.264BP 或其他内容,但我还没有对此进行测试。 AVI 显然不适合流媒体 - 您可能必须将视频分成 AVI 的小块,并不断交换这些块 - 或者您可能会探索 FLV 或 Matroska 受支持,但要小心 - 支持的容器格式的确切组合可能因设备或版本而异。
You can create a socket, take it's "file descriptor", and give that to the
MediaPlayer.setDataSource()
.I have actually done something similiar to this a while back, so this approach is tested in the field.
I forget exactly how to extract the file descriptor from a socket, but I think that using reflection - or more likely native code - you can get an '
impl
' member on the socket which is a LocalSocket or something, and has a 'fd
' member. Googling has not found anyone describing this, so you'll have to explore the exact member names and details yourself.The container format will have to be something that is recognised by the Android system; if necessary you can use native code to create a pipe so that you can repackage your custom container into something that Android supports on-the-fly using a thread.
It occurs to me that there's a good chance that Android plays 'raw' H.263 and H.264BP or whatever, but I have not tested this. AVI is obviously not ideal for streaming - you might have to split your video up into short chunks of AVI, and keep swapping these blocks - or you might explore if FLV or Matroska is supported, but be cautious - the exact mix of supported container formats might differ from device to device, or from release to release.
有几个开源库(例如 ffmpeg /live555)可以解决您的问题。我使用 ffmpeg 库来编码/解码音频/视频文件。 ffmpeg 也有可用的 java 移植。您还可以提取视频的帧数据和元数据(比特率、深度级别等......)
there are several open source libraries like ffmpeg /live555 that can solove your problems . I worked around ffmpeg library to enode/decode audio/ video files . there is java porting available for ffmpeg too . you can pull frame data of your video and metadata as well (bit rate , depth level etc..)