Xuggle编解码器识别失败

发布于 2024-08-31 00:47:06 字数 3841 浏览 2 评论 0原文

我正在尝试运行以下 Xuggle 代码:

public static boolean convert(String stream) throws IOException, InterruptedException {

  IMediaReader reader = ToolFactory.makeReader(stream + ".flv");

  IMediaWriter writer = ToolFactory.makeWriter(stream + ".mp3", reader);
  reader.addListener(writer);

  while (reader.readPacket() != null)
   ;

  return true;
}

其中stream 是文件路径。但我遇到以下异常:

java.lang.IllegalArgumentException: could not find input codec id
 at com.xuggle.xuggler.IContainerFormat.establishOutputCodecId(IContainerFormat.java:393)
 at com.xuggle.xuggler.IContainerFormat.establishOutputCodecId(IContainerFormat.java:327)
 at com.xuggle.xuggler.IContainerFormat.establishOutputCodecId(IContainerFormat.java:300)
 at com.xuggle.mediatool.MediaWriter.addStreamFromContainer(MediaWriter.java:1141)
 at com.xuggle.mediatool.MediaWriter.getStream(MediaWriter.java:1046)
 at com.xuggle.mediatool.MediaWriter.encodeAudio(MediaWriter.java:837)
 at com.xuggle.mediatool.MediaWriter.onAudioSamples(MediaWriter.java:1448)
 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 <package_name>MediaFile.convert(MediaFile.java:66)
 at <package_name>.MediaFileTest.shouldConvertExistingFLV(MediaFileTest.java:32)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
 at java.lang.reflect.Method.invoke(Unknown Source)
 at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
 at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
 at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
 at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
 at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
 at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
 at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73)
 at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
 at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
 at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
 at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
 at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
 at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
 at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
 at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
 at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

单元测试如下:

 @Test
 public void shouldConvertExistingFLV() throws IOException, InterruptedException {
  String str = "C:\\Program Files\\Wowza Media Systems\\Wowza Media Server 2\\content\\Extremists";
  boolean result = MediaFile.convert(str);
  assertTrue(result);
 }

那么,为什么他找不到编解码器,因为我正在测试简单的 flv 到 mp3 转换?

I'm trying to run the following Xuggle code:

public static boolean convert(String stream) throws IOException, InterruptedException {

  IMediaReader reader = ToolFactory.makeReader(stream + ".flv");

  IMediaWriter writer = ToolFactory.makeWriter(stream + ".mp3", reader);
  reader.addListener(writer);

  while (reader.readPacket() != null)
   ;

  return true;
}

Where stream is the file path. But I'm getting the following exception:

java.lang.IllegalArgumentException: could not find input codec id
 at com.xuggle.xuggler.IContainerFormat.establishOutputCodecId(IContainerFormat.java:393)
 at com.xuggle.xuggler.IContainerFormat.establishOutputCodecId(IContainerFormat.java:327)
 at com.xuggle.xuggler.IContainerFormat.establishOutputCodecId(IContainerFormat.java:300)
 at com.xuggle.mediatool.MediaWriter.addStreamFromContainer(MediaWriter.java:1141)
 at com.xuggle.mediatool.MediaWriter.getStream(MediaWriter.java:1046)
 at com.xuggle.mediatool.MediaWriter.encodeAudio(MediaWriter.java:837)
 at com.xuggle.mediatool.MediaWriter.onAudioSamples(MediaWriter.java:1448)
 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 <package_name>MediaFile.convert(MediaFile.java:66)
 at <package_name>.MediaFileTest.shouldConvertExistingFLV(MediaFileTest.java:32)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
 at java.lang.reflect.Method.invoke(Unknown Source)
 at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
 at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
 at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
 at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
 at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
 at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
 at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73)
 at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
 at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
 at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
 at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
 at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
 at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
 at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
 at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
 at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

The unit test is the following:

 @Test
 public void shouldConvertExistingFLV() throws IOException, InterruptedException {
  String str = "C:\\Program Files\\Wowza Media Systems\\Wowza Media Server 2\\content\\Extremists";
  boolean result = MediaFile.convert(str);
  assertTrue(result);
 }

So, why can't he find the codec, since I'm testing for a simple flv to mp3 conversion?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

却一份温柔 2024-09-07 00:47:06

如果您的源是真正的 flv 流(没有奇怪的编解码器信息),那么这应该可以工作。我能想到这里只会出现两个问题:

  • 在编写器开始编码之前没有足够的元数据信息进来。例如,尚未检测到编解码器。
  • 传入视频由于其对于 mp3 容器类型无效而导致失败。编写一个媒体工具来忽略视频。

希望有帮助

If your source is a true flv stream (no odd codec info) then this should work. There are only two problems I can think of that would arise here:

  • There is not enough meta data info coming in before the writer starts to encode. For instance the codecs have not been detected.
  • The incoming video is causing the failure due to its being invalid for the mp3 container type. Write a media tool to ignore the video.

Hope that helps

南风起 2024-09-07 00:47:06

诀窍在于在 Writer 上添加音频流来创建。此代码片段适用于我从 flv 中提取音频流并将其转码为 mp3。

     IMediaReader reader = ToolFactory.makeReader(filename + ".flv");
     IMediaWriter writer = ToolFactory.makeWriter(filename + ".mp3", reader);
     int sampleRate = 22050;
     int channels = 1;
     writer.addAudioStream(0, 0, ICodec.ID.CODEC_ID_MP3, channels, sampleRate);

     reader.addListener(writer);
     while (reader.readPacket() == null)
               ;

The trick lies in creating in adding an audio stream on the Writer. This code snippet works for me in extracting an audio stream from a flv and transcoding it to an mp3.

     IMediaReader reader = ToolFactory.makeReader(filename + ".flv");
     IMediaWriter writer = ToolFactory.makeWriter(filename + ".mp3", reader);
     int sampleRate = 22050;
     int channels = 1;
     writer.addAudioStream(0, 0, ICodec.ID.CODEC_ID_MP3, channels, sampleRate);

     reader.addListener(writer);
     while (reader.readPacket() == null)
               ;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文