简体   繁体   English

如何将 jpeg 帧与未压缩的 mono 音频组合成 h264 stream 或开箱即用的 web 浏览器处理的任何其他格式?

[英]How to combine jpeg frames with uncompressed mono audio into an h264 stream or any other format processed by web browsers out of the box?

So I have an esp32 which captures images and sound.所以我有一个捕捉图像和声音的 esp32。 The esp32-camera library already returns the jpeg encoded buffer. esp32-camera库已经返回了 jpeg 编码的缓冲区。 The audio however is uncompressed and is just a digital representation of signal strength at high sample rate.然而,音频是未压缩的,只是高采样率下信号强度的数字表示。

I use esp32 to host a webpage which contains <image> element and a JavaScript snippet, which constantly sends GET requests to a branching url for image data and updates the element.我使用 esp32 托管一个网页,其中包含<image>元素和一个 JavaScript 片段,它不断向分支 url 发送 GET 请求以获取图像数据并更新该元素。 This approach is not very good, especially that now I've added audio capabilities to the circuit.这种方法不是很好,特别是现在我已经在电路中添加了音频功能。

I'm curious if it would be possible to combine jpeg encoded frames and some audio data into a chunk of h264 and then send it directly as a response to a GET request making it a stream?我很好奇是否可以将 jpeg 编码帧和一些音频数据组合成一块 h264,然后将其作为对 GET 请求的响应直接发送,使其成为 stream?

This not only would simplify the whole serving multiple webpages thing, but also remove the issues of syncing the audio and video if they are sent separately.这不仅会简化整个为多个网页提供服务的过程,而且还会消除单独发送音频和视频时同步的问题。

In particular I'm also curious how easy would it be to do on esp32 since it doesn't have a whole bunch of ram and computational power.特别是我也很好奇在 esp32 上做起来有多容易,因为它没有一大堆 ram 和计算能力。 It would be challenging to find or port large libraries which could help as well, so i guess I would have to code it myself.找到或移植也有帮助的大型库将是一项挑战,所以我想我必须自己编写代码。

I also am not sure if h264 is the best option.我也不确定 h264 是否是最佳选择。 I know its supported on most browser out of the box and is using jpeg compression behind the scenes for the frames, but perhaps a simpler format exists which is also widely supported.我知道大多数浏览器都支持它开箱即用,并且在幕后对帧使用 jpeg 压缩,但也许存在一种更简单的格式,它也得到广泛支持。

So to sum it up: Is h264 a best bet in the provided context?总结一下:在提供的上下文中,h264 是最好的选择吗? Is combining jpeg and uncompressed mono audio into h264 possible in the provided context?在提供的上下文中是否可以将 jpeg 和未压缩的 mono 音频组合成 h264? If an answer to either of previous questions is a no, what alternatives do i have if any?如果对前面任何一个问题的回答是否定的,我有什么选择(如果有的话)?

I'm curious if it would be possible to combine jpeg encoded frames and some audio data into a chunk of h264 and then send it directly as a response to a GET request making it a stream?我很好奇是否可以将 jpeg 编码帧和一些音频数据组合成一块 h264,然后将其作为对 GET 请求的响应直接发送,使其成为 stream?

H.264 is a video codec. H.264 是一种视频编解码器。 It doesn't have anything to do with audio.它与音频没有任何关系。

I know its supported on most browser out of the box and is using jpeg compression behind the scenes for the frames我知道它在大多数开箱即用的浏览器上都受支持,并且在幕后对帧使用 jpeg 压缩

No, this isn't true.不,这不是真的。 H.264 is its own thing. H.264 是它自己的东西。 It's far more powerful than JPEG and is specifically designed for motion, whereas JPEG was not.它比 JPEG 强大得多,并且专为运动而设计,而 JPEG 则不是。

You need a few things:你需要一些东西:

  • A video codec, to efficiently handle your frames.一种视频编解码器,可有效处理您的帧。 Most of these embedded camera libraries can give you an MJPEG stream. I'd use that if possible.这些嵌入式相机库中的大多数都可以为您提供 MJPEG stream。如果可能,我会使用它。 I don't think your ESP32 has other video encoding capability, does it?我不认为你的 ESP32 有其他视频编码能力,是吗? H.264 is a good choice, but only if you can actually encode it. H.264 是一个不错的选择,但前提是您可以实际对其进行编码。

  • A container format, to aid in streaming your audio and video streams together.一种容器格式,有助于将音频和视频流一起传输。 ISOBMFF/MP4 is common, as is WebM/Matroska. ISOBMFF/MP4 很常见,WebM/Matroska 也是。

If you're only streaming to a single client (which seems likely given the limited horsepower of the board), and if you have enough capability to do the audio/video encoding, you can generate a WebM stream on the fly that is directly playable in a <video> element.如果您只流式传输到单个客户端(考虑到板的功率有限,这似乎很可能),并且如果您有足够的能力进行音频/视频编码,则可以即时生成可直接播放的 WebM stream在<video>元素中。 This seems exactly what you are asking for.这似乎正是您所要求的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将python中的async = false添加到Gstreamer splitmuxsink元素音频/视频/ H264组合 - How do I add async=false in python to a Gstreamer splitmuxsink element Audio/video/H264 combined 如何从 H.264 帧和音频帧的集合创建 mp4 文件? - How do I create an mp4 file from a collection of H.264 frames and audio frames? ffmpeg:将两个单声道现场音频流组合为单个立体声流 - ffmpeg: combine two mono live audio stream to single stereo stream iOS 浏览器是否支持带有 h264 视频和 4 个(或更多)AAC 音频通道的 mp4? - Is there iOS browser support for mp4 with h264 video and 4 (or more) AAC audio channels? 如何使用ffmpeg改变mp4文件的h264属性、yuv、fps、tbr、tbn、tbc? - How to use ffmpeg to change the h264 properties, yuv, fps, tbr, tbn, and tbc of an mp4 file? 处理后的音频编解码器 Web 音频 Api - Codec of processed audio with Web Audio Api 任何基于非 Chromium 的 web 浏览器都无法加载某些 H264-mp4 视频 - Some H264-mp4 videos can't be loaded by any non-Chromium based web browser 网络音频 API - 立体声到单声道 - Web Audio API - Stereo to Mono 将音频流URL与wpaudio或任何其他此类脚本一起使用 - Using an audio stream URL with wpaudio or any other such script 如何在网络上连续流式传输音频 - How to continously stream audio over the web
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM