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

标签 ffmpeg xuggler xuggle

我正在尝试打开一个从自定义输入缓冲区读取而不是从媒体文件读取的 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/

相关文章:

c# - 在使用 ffmpeg 和 ffserver 的情况下,数据流如何?

javascript - 连接音频 blob

c++ - 使用 FFmpeg API 将 RTP 负载数据写入音频文件

java - Xuggler NoClassDefFoundError

java - 如何将 .mov、.avi、.wmv 转换为 mp4

c++ - 在输入和输出之间使用不同数量的样本编码音频 ffmpeg C++

java - Xuggler 生成错误消息

Java - xuggle/ffmpeg - 未找到 mov 原子

java - xuggle-xuggler 5.4 编码音频时出现 NullPointerException

java - xuggle并发转码