Xuggler不转换.webm文件? [英] Xuggler not converting a .webm file?

查看:214
本文介绍了Xuggler不转换.webm文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Xuggler将.mov文件转换为.webm,该文件应该作为FFMPEG支持.webm文件。

I'm trying simply to convert a .mov file into .webm using Xuggler, which should work as FFMPEG supports .webm files.

这是我的代码:

    IMediaReader reader = ToolFactory.makeReader("/home/user/vids/2.mov");
    reader.addListener(ToolFactory.makeWriter("/home/user/vids/2.webm", reader));
    while (reader.readPacket() == null);
    System.out.println( "Finished" );

运行时,我收到此错误:

On running this, I get this error:

[main] ERROR org.ffmpeg - [libvorbis @ 0x8d7fafe0] Specified sample_fmt is not supported.
[main] WARN  com.xuggle.xuggler - Error: could not open codec (../../../../../../../csrc/com/xuggle/xuggler/StreamCoder.cpp:831)
Exception in thread "main" java.lang.RuntimeException: could not open stream com.xuggle.xuggler.IStream@-1921013728[index:1;id:0;streamcoder:com.xuggle.xuggler.IStreamCoder@-1921010088[codec=com.xuggle.xuggler.ICodec@-1921010232[type=CODEC_TYPE_AUDIO;id=CODEC_ID_VORBIS;name=libvorbis;];time base=1/44100;frame rate=0/0;sample rate=44100;channels=1;];framerate:0/0;timebase:1/90000;direction:OUTBOUND;]: Operation not permitted
    at com.xuggle.mediatool.MediaWriter.openStream(MediaWriter.java:1192)
    at com.xuggle.mediatool.MediaWriter.getStream(MediaWriter.java:1052)
    at com.xuggle.mediatool.MediaWriter.encodeAudio(MediaWriter.java:830)
    at com.xuggle.mediatool.MediaWriter.onAudioSamples(MediaWriter.java:1441)
    at com.xuggle.mediatool.AMediaToolMixin.onAudioSamples(AMediaToolMixin.java:89)
    at com.xuggle.mediatool.MediaReader.dispatchAudioSamples(MediaReader.java:628)
    at com.xuggle.mediatool.MediaReader.decodeAudio(MediaReader.java:555)
    at com.xuggle.mediatool.MediaReader.readPacket(MediaReader.java:469)
    at com.mycompany.xugglertest.App.main(App.java:13)
Java Result: 1

任何想法?

推荐答案

Xuggler 不一定允许您设置 IAudioSamples 的采样率。您需要使用 IAudioResampler

There's a funky thing going on with Xuggler where it doesn't always allow you to set the sample rate of IAudioSamples. You'll need to use an IAudioResampler.

有一段时间我想知道这一点。 Marty的这篇文章有很多帮助,尽管他的代码已经过时了现在。

Took me a while to figure this out. This post by Marty helped a lot, though his code is outdated now.

这是您如何解决它。

假设音频输入已正确设置,导致$ code> IStreamCoder 调用 audioCoder

I'm assuming here that audio input has been properly set up, resulting in an IStreamCoder called audioCoder.

完成之后,您可能会启动一个 IMediaWriter 并添加如下所示的音频流:

After that's done, you are probably initiating an IMediaWriter and adding an audio stream like so:

final IMediaWriter oggWriter = ToolFactory.makeWriter(oggOutputFile);

// Using stream 1 'cause there is also a video stream.
// For an audio only file you should use stream 0.
oggWriter.addAudioStream(1, 1, ICodec.ID.CODEC_ID_VORBIS, 
                         audioCoder.getChannels(), audioCoder.getSampleRate());

现在创建一个 IAudioResampler

IAudioResampler oggResampler = IAudioResampler.make(audioCoder.getChannels(), 
                                                   audioCoder.getChannels(), 
                                                   audioCoder.getSampleRate(),
                                                   audioCoder.getSampleRate(),  
                                                   IAudioSamples.Format.FMT_FLT, 
                                                   audioCoder.getSampleFormat());

并告诉您的 IMediaWriter 更新到示例格式:

And tell your IMediaWriter to update to its sample format:

// The stream 1 here is consistent with the stream we added earlier.
oggWriter.getContainer().getStream(1).getStreamCoder().
                         setSampleFormat(IAudioSamples.Format.FMT_FLT);





编码期间



您目前可能正在启动一个 IAudioSamples 并填充音频数据,如下所示:

.

During encoding

You are currently probably initiating an IAudioSamples and filling it with audio data, like so:

IAudioSamples audioSample = IAudioSamples.make(512, audioCoder.getChannels(), 
                                                    audioCoder.getSampleFormat());

int bytesDecoded = audioCoder.decodeAudio(audioSample, packet, offset);

现在为我们重新采样的数据启动一个IAudioSamples :

Now initiate an IAudioSamples for our resampled data:

IAudioSamples vorbisSample = IAudioSamples.make(512, audioCoder.getChannels(),
                                                IAudioSamples.Format.FMT_FLT);

最后,重新取样音频数据并写入结果:

Finally, resample the audio data and write the result:

oggResampler.resample(vorbisSample, audioSample, 0);

oggWriter.encodeAudio(1, vorbisSample);  





最后想法



只是提示您的输出文件播放良好:

.

Final thought

Just a hint to get your output files to play well:


  • 如果您使用音频和同一容器内的视频,则音频和视频数据包应按照每个数据包的时间戳高于先前数据包的顺序写入。所以你几乎肯定会需要一种替代编写音频和视频的缓冲机制。

这篇关于Xuggler不转换.webm文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆