开发者

Can I use Xuggler to encode video/audio to a byte array?

It seems all methods expect either files or url开发者_开发问答s. I see some methods that work with OutputStream, but I haven't managed to open an IContainer using one of those methods; I always get an invalid return value.


Create your own IURLProtocolHandler interface and pass to IContainer.open(...) to open any type of media type you want.


You can look at this answer I posted on another question to write to an OutputStream (which could easily be a ByteArrayOutputStream).

This gist of it would be to use com.xuggle.xuggler.io.XugglerIO to map from an OutputStream to a special kind of file URL so that FFMPEG can access the stream.

IMediaWriter writer = ToolFactory.makeWriter(XugglerIO.map(outputStream));

Keep in mind that you'll now have to manually set your format (because it can't detect it from the filename). For example:

IContainerFormat containerFormat = IContainerFormat.make();
containerFormat.setOutputFormat("ogg", null, "application/ogg");
writer.getContainer().setFormat(containerFormat);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜