问题标签 [mediaextractor]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
1863 浏览

android - Android 媒体编解码器崩溃

我正在使用新的 API MediaCodec 和 MediaExtractor(可从 API 16 获得)构建一个 android 视频播放器应用程序。它通常运行良好,但有时我会崩溃并显示非常无意义的消息:

如果有人能让我更好地了解出了什么问题,那就太好了。崩溃通常发生在我打开视频、播放一点、退出、转到另一个视频时。它只发生很少的时间,但很烦人。

0 投票
2 回答
8689 浏览

android - 使用 MediaCodec 和 MediaExtractor 对视频进行解码和编码

我需要将视频解码为一系列位图,以便我能够修改它们,然后将它们压缩回 android 中的视频文件。

我计划通过使用getFrameAtTime并将其保存到图像序列来管理它。然后我可以修改序列中的图像并将其编码回电影。但我有两个问题:

  • 首先,当我读到它时,它getFrameAtTime是用于创建缩略图并且不能保证返回正确的帧。这使得视频滞后。
  • 其次,保存图像并读取它需要很长时间。

我读到使用 MediaExtractor 进行解码的正确方法,这很好,但我只有示例将其直接呈现为surfaceView. 我有什么办法可以将其转换outputBuffer为位图吗?

我需要它来让它与 16 及以上的 api 级别一起工作。

0 投票
1 回答
5383 浏览

android - 解码音频文件并重新编码为所需的 PCM 格式:44,100 kHz,2 通道,16 位

我想将音频文件解码为原始 PCM 数据,以将其流式传输到本地网络中的播放设备。为此,我使用 API 级别 16 引入的新MediaExtractorMediaCodec类。该设备要求 PCM 数据为 44,100 kHz,具有 2 个通道和 16 位样本大小。只要输入文件大致符合这些要求,它就可以正常工作。但是,每当我解码一个 MP3 文件时,它使用 - 例如 - 32,000 kHz 的采样率并且可能只有一个通道,然后我没有从 MediaCodec 类获得所需的输出。

看来我无法指定 MediaCodec 类的输出格式。所以我决定实例化另一个 MediaCodec 对象,将原始数据重新编码成我想要的格式。根据支持的媒体格式列表, Android 自 Android 4.1 起支持编码为 PCM/Wave。但是,我无法创建编码为 PCM/Wave 的 MediaCodec 对象。我尝试将各种 MIME 类型传递给 MediaCodec.createEncoderByType(type); 但我总是因 IOException 而失败:

你们中是否有人能够成功创建一个编码为 PCM/Wave 的 MediaCodec 实例,并且可以为我提供一个工作示例?

0 投票
1 回答
3589 浏览

android - 媒体提取器的问题

我试图在特定时间获取特定帧作为电影中的图像,使用MediaExtractorMediaCodec。如果满足以下条件,我可以成功:

  • 但是,我使用extractor.seekTo(time, MediaExtractor.SEEK_TO_PREVIOUS_SYNC);,这只给出最近的同步帧而不是目标帧。
  • 我使用 顺序提取所有帧extractor.advance();,但我需要获取目标帧而不是全部。

所以,我尝试以下方法:

这提供了正确的帧,但由于某种原因,图像已损坏。它看起来像正确的图像(我从成功案例中得到的图像),但有一些像素化和奇怪的雾度。

while-loop是成功案例和腐败案例之间唯一不同的地方。如何在不MediaExtractor损坏图像的情况下提前到特定时间(不仅仅是同步时间)?

0 投票
1 回答
1373 浏览

android - 样本的呈现时间迅速增长大于总持续时间

我正在使用 MediaCodec 解码音轨。我的解码类可以很好地播放音频。我正在尝试使用总曲目持续时间和总播放时间在 SeekBar 中显示曲目的进度。我有两个 long,一个以微秒为单位记录曲目的总持续时间,另一个以微秒为单位记录曲目的总播放时间。

我遇到的问题是播放的持续时间很快变得大于曲目的总持续时间。我不明白我要去哪里错了。

解码类中的长声明:

确定 ctor 中的总持续时间:

我将输入样本的时间添加到 currentTimeUs 的方法:

0 投票
1 回答
7004 浏览

android - 如何减少 MediaCodec 视频/avc 解码中的延迟

我在 Nexus 5 上运行的Grafika MediaCodec 示例代码中执行了MoviePlayer.java的一些简单计时。我在这些位置放置了一条日志语句:

在第 203 行之前

在第 244 行之后

我使用presentationTimeUs.

以下是 logcat 的摘录:

我发现从第一个输入缓冲区排队到相应的输出缓冲区出队的时间差是 50 毫秒。对于硬件加速解码来说,这似乎需要很多时间。

有没有办法减少这种延迟?

0 投票
1 回答
7795 浏览

android - Android MediaMuxer 无法停止

我正在尝试使用 MediaCodec、MediaExtractor 和 MediaMuxer 来生成 mp4 文件。EveryThing 似乎工作正常,但是当我调用 MediaMuxer.stop 时出现错误。MP4 文件已创建,但我无法使用播放器播放。

这是我的日志:

任何线索为什么停止失败?

0 投票
1 回答
4153 浏览

android - 使用 Ogg 音频文件搜索时 MediaCodec.dequeueOutputBuffer 超时

播放 .ogg 文件时,在调用 MediaExtractor.seekTo() 后,.dequeueOutputBuffer() 总是超时,MediaCodec.INFO_TRY_AGAIN_LATER。这会导致问题,因为我正在尝试创建近乎无缝的搜索。最大阻塞时间无关紧要,无论设置多长时间它总是超时。

所有 .ogg 文件都会发生这种情况,而没有其他音频文件类型。

这是相关代码,超时发生在

每次使用 .ogg 文件调用 seekTo() 后都会发生这种情况,有没有办法纠正这个问题?

这是在 seekTo() 之前和之后唯一的 logcat,AudioTrack 上的缓冲区不足是由于我目前为 dequeueOutputBuffer() 设置的 1 秒超时

另外我应该注意到对 seekTo() 和 decodeChunk() 的调用发生在不同的线程上,但它们在同一个对象上同步。

0 投票
3 回答
14481 浏览

android - Android MediaExtractor 和 mp3 流

我正在尝试使用 MediaExtractor/MediaCodec 播放 mp3 流。由于延迟和长缓冲区大小,MediaPlayer 是不可能的。

我发现的唯一示例代码是:http ://dpsm.wordpress.com/category/android/

代码示例只是部分(?)并使用文件而不是流。

我一直在尝试调整此示例以播放音频流,但我无法理解它应该如何工作。像往常一样的 Android 文档没有帮助。

我知道首先我们获取有关流的信息,大概使用此信息设置 AudioTrack(代码示例确实包括 AudioTrack 初始化?),然后打开输入缓冲区和输出缓冲区。

我已经为此重新创建了代码,我猜可能是缺少的部分,但没有音频输出。

有人可以指出我正确的方向以了解这应该如何工作吗?

编辑:添加 logcat 输出以获得额外的想法。

0 投票
1 回答
4600 浏览

android - Inconsistent sample time / presentation time during video decoding

I'm writing an APP that can encode video by camera input and process video by decode-edit-encode steps. For the camera, I use the Camera class rather than Intent to configure the details settings of the camera. Then I feed the camera frames to the encoder (MediaCodec in API 16) and the muxer (I use ffmpeg muxer since I want to work on 4.1 Devices).

I measure the time code of camera frames by system nano time, and select a subset of frames to fit a desired FPS (currently 15). There are some small "noises" in the time values, for example (in ms): 0, 60718, 135246, 201049, ... rather than 0, 66000, 133000, 200000, ... .

After some trying of configuring the muxer correctly (As this question), I can produce a video (with AVC codec) that can be playback by the video player on devices. The playback speed is correct so I think the video should have correct time information of the frames.

However, I got a problem when I try to decode the video to perform the video editting process. I use the standard video extract/decode steps as these samples, like this:

The sample time from getSampleTime() has correct value as I encode the video. (e.g., they are exactly 0, 60718, 135246, 201049, ... in us). It is also the presentation time in the input of decoder.queueInputBuffer(). When the decoder proceeds to decode this frame, I get the frame time by:

I expect to set the same time sequence as the one in decoder input, but I get a lot of 0's from the BufferInfo at decoder output. The decoded frame contents seems to be correct, but most of the presentation time values are 0. Only the last few frames has correct presentation time.

I test the whole same process on a device with Android 4.3 (even with the same ffmpeg muxer rather than MediaMuxer in API 18), and everything looks fine. On 4.1/4.2 devices, if I capture the video by the built-in camera APP on the device and then decode the video, then the presentation time is also correct although the time values also have noises due to camera delay.

What's wrong with the video or the decode process, when the video can be playbacked and decoded normally, but with correct sample time and bad presentation time? I may have to use a workaround to measure the presentation time by the sample time (It's easy by using a queue), but I want to figure out if there is any missing part in my work.