Android 中的视频流:处理格式和标头

发布于 2024-11-05 13:20:37 字数 1669 浏览 0 评论 0原文

我目前正在尝试从 Android 设备流式传输实时视频。不幸的是,我无法读取通过网络获得的流。

我发现问题是由于录制视频所使用的格式(ISO 媒体、MPEG v4 系统、3GPP)造成的。

以下是我初始化录像机的方法:

    // Sources
    recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
    recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);

    // HD
    CamcorderProfile highProfile = CamcorderProfile
            .get(CamcorderProfile.QUALITY_HIGH);
    recorder.setProfile(highProfile);
    recorder.setOutputFile(PATH);

如果当前正在拍摄视频(仍在 FS 上写入),则以下是我读取文件开头时得到的内容(我使用 $ adb pull /sdcard/ 获取该文件video) :

MacBook-Romain:result rbochet$ hexdump video-current.mp4 | head -2
0000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0000010 00 00 00 00 00 00 00 00 00 00 00 08 6d 64 61 74

当录制结束时,标题看起来像这样:

MacBook-Romain:result rbochet$ hexdump video.mp4 | head -2
0000000 00 00 00 18 66 74 79 70 33 67 70 34 00 00 03 00
0000010 33 67 70 34 33 67 70 36 00 07 56 83 6d 64 61 74

事实上,这种方法并不是直播的最佳方法,因为我们只是不知道文件会有多长和多大......

问题:我该如何进行实际流媒体播放? 我看到的解决方案之一是发送小块,但我认为这个解决方案实际上很糟糕......应该存在更好的东西,因为诸如 SipDroid 之类的程序能够进行流式传输。 如果你能理解他们的代码,你能解释一下吗?我查看了 代码,但对我来说不太清楚。

该代码将作为开源发布,因此每个寻找解决这种棘手情况的方法的人都会享受您的帮助(我知道 SO 上有很多类似的线程)。

这是基本相机应用程序的代码: https://github.com/rbochet/Simple-Camera -App

感谢您的帮助。

I'm currently trying to stream live video from an Android device. Unfortunately, I am unable to read the stream I got through the network.

I figured out that the problem is due to the format used for recording video (ISO Media, MPEG v4 system, 3GPP).

Here is how I initialize the recorder:

    // Sources
    recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
    recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);

    // HD
    CamcorderProfile highProfile = CamcorderProfile
            .get(CamcorderProfile.QUALITY_HIGH);
    recorder.setProfile(highProfile);
    recorder.setOutputFile(PATH);

If the video is currently filmed (still writing on the FS), here is what I get when I read the start of the file (I got that file with $ adb pull /sdcard/video) :

MacBook-Romain:result rbochet$ hexdump video-current.mp4 | head -2
0000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0000010 00 00 00 00 00 00 00 00 00 00 00 08 6d 64 61 74

When the recording ends, the header looks like this:

MacBook-Romain:result rbochet$ hexdump video.mp4 | head -2
0000000 00 00 00 18 66 74 79 70 33 67 70 34 00 00 03 00
0000010 33 67 70 34 33 67 70 36 00 07 56 83 6d 64 61 74

The fact is that this method is not the best for live streaming, as we just do not know how long and big the file will be…

Question: How can I do to actual streaming?
One of the solution I see is sending small chunks, but I think this solution actually sucks... Something better should exist, as program such as SipDroid are able to stream.
If you are able to understand their code, can you explain it? I had a look at the code, but it was not that clear for me.

The code will be released as open source, so your help will be enjoyable by everyone who looks for a way to solve this tricky situation (I know there are lots of similar threads on SO).

Here is the code of the basic camera app: https://github.com/rbochet/Simple-Camera-App

Thanks for your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文