问题描述
||
我正在尝试使用Xuggle从本地读取mov文件。
这给了我以下错误:
30-mag-2011 15.56.55 com.xuggle.ferry.NativeLogger log
GRAVE: [mov,mp4,m4a,3gp,3g2,mj2 @ 0x102840600] moov atom not found
问题是直到两分钟之前它都没有给出任何错误并且代码是相同的。
但是,我发现了这一点:
如果我使用字节数组打开IContainer,它将无法正常工作并出现错误:
ByteArrayInputStream b = new ByteArrayInputStream(file);
DataInputStream data = new DataInputStream(b);
IContainer container = IContainer.make();
if (container.open(data,null) < 0)
throw new IllegalArgumentException(\"E001 - Cannot open the container\");
如果我使用一个临时文件打开IContainer,它将起作用。
File temp = File.createTempFile(\"temp_\",\".mov\");
try
{
FileOutputStream fos = new FileOutputStream(temp);
fos.write(file);
fos.close();
}
catch(FileNotFoundException e)
{
System.out.println(e);
}
IContainer container = IContainer.make();
if (container.open(temp.toString(),IContainer.Type.READ,null) < 0)
throw new IllegalArgumentException(\"E001 - Cannot open the container\");
有什么建议么?
解决方法
将ByteArrayInput分配给DataInputStream时,它可能会丢失一些数据。检查它们的avaiable()值是否相同。
, 刚发现这个问题。
使用容器之前,请先设置其缓冲区大小
container.setInputBufferLength(b.available());
, 我意识到这是一个旧线程,但是在研究自己的问题时遇到了这个问题,上面发布的解决方案都无济于事。
就我而言,我遇到了通过Adobe Media Encoder传递的H264 / mov文件的问题。事实证明,AME正在把MOOV ATOM放在Xuggle无法轻易找到的位置。我猜在文件末尾。
对我来说,解决方案有两个方面。 A)我需要传递Xuggle一个RandomAccessFile,以便它可以来回搜索以找到MOOV ATOM。 (无法搜索FileInputStreams)B)我必须配置Container格式,在线上的许多文档和教程都将其保留为空,这取决于Xuggle进行自动检测。
RandomAccessFile f = new RandomAccessFile(\"C:/MyMovie.mov\",\"r\");
IContainer container = IContainer.make();
IContainerFormat format = IContainerFormat.make();
if (format.setInputFormat(\"mov\") < 0)
System.out.println(\"Error setting format\");
int result = container.open(f,IContainer.Type.READ,format);
希望这对某人有帮助。