gpt4 book ai didi

ffmpeg - 使用自定义 ByteChannel 读取时,IContainer.open() 失败

转载 作者:行者123 更新时间:2023-12-04 23:29:21 25 4
gpt4 key购买 nike

我正在尝试打开一个从自定义输入缓冲区读取而不是从媒体文件读取的 IContainer 对象。此自定义输入缓冲区的实现如下。

创建和打开容器的代码如下。

// Open up the container for READING
mInputCStore = new CStore();

IContainerFormat format = IContainerFormat.make();
if (format.setInputFormat("flv") < 0) {
throw new IllegalArgumentException("Failed to initialize the input format");
}

// Open up the container
mInputContainer = IContainer.make();
int retval = mInputContainer.open(mPlaybackContainerStore, IContainer.Type.READ, format);
if (retval < 0) {
// This little trick converts the non friendly integer return value into
// a slightly more friendly object to get a human-readable error name
IError error = IError.make(retval);
throw new IllegalArgumentException("could not open input container: " + mPlaybackContainerStore + "; Error: " + error.getDescription());
}

上面的代码抛出异常说——
Exception in thread "main" java.lang.IllegalArgumentException: could not open input container: com.client.video.ContainerStore@61981853; Error: Operation not permitted

在写入容器时使用相同的自定义缓冲区可成功运行。有人可以帮助我了解自定义缓冲区实现中缺少什么,就在 READ 模式下使用它以及它失败的原因是什么?
package test;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.ByteChannel;
import java.util.concurrent.ConcurrentLinkedQueue;

public class CStore implements ByteChannel {
private ConcurrentLinkedQueue<DataChunk> mChunkQueue = null;
private int mQueueSize = 0;

// constructor
public CStore(String type) {
mQueueSize = 0;
mChunkQueue = new ConcurrentLinkedQueue<DataChunk>();
mChunkQueue.clear();
}

@Override
public void close() throws IOException {
return;
}

@Override
public boolean isOpen() {
return false;
}

@Override
public int write(ByteBuffer buffer) throws IOException {
DataChunk chunk = new DataChunk(buffer);
mChunkQueue.add(chunk);
mQueueSize += chunk.getLength();
return 0;
}

public int read(ByteBuffer buffer) throws IOException {

int result = 0;

DataChunk chunk = mChunkQueue.poll();
if (chunk != null) {
buffer = chunk.getBuffer();
if (buffer != null) {
result = 0;
} else {
result = 1;
}
}

return result;
}
}

最佳答案

我打开了一个 IContainer 来读取 InputStream 的自定义实现。为此,您必须手动设置通常在从文件读取时自动检测到的信息(即:输入格式、编解码器、编解码器详细信息)。

// Example input stream (raw audio encoded with mulaw).
InputStream input = new FileInputStream("/tmp/test.ul");

// Manually set the input format.
IContainerFormat inputFormat = IContainerFormat.make();
inputFormat.setInputFormat("mulaw");

// Open the container.
IContainer container = IContainer.make();
container.open(input, inputFormat);

// Initialize the decoder.
IStreamCoder coder = container.getStream(0).getStreamCoder();
coder.setSampleRate(8000);
coder.setChannels(1);
coder.open(null, null);

您现在可以像往常一样从容器中读取数据 [即:container.readNextPacket(packet)]。

关于ffmpeg - 使用自定义 ByteChannel 读取时,IContainer.open() 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24921649/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com