1

Xugglerを使用して映画(.mp4)をオーディオ(.mp3)に変換しようとしています。私はOSXで処理を使用しています。

 IMediaReader reader = ToolFactory.makeReader("/Users/nouv/Desktop/video1.mp4");
 IMediaWriter writer = ToolFactory.makeWriter("/Users/nouv/Desktop/audioOutput.mp3", reader);
 int sampleRate = 22050;
 int channels = 1;
 writer.addAudioStream(0, 0, ICodec.ID.CODEC_ID_MP3, channels, sampleRate);

 reader.addListener(writer);
 try {
   while (reader.readPacket() == null)
           ;
 } finally {}

このエラーが発生しました:IllegalArgumentException:stream[0]はビデオではありません

Exception in thread "Animation Thread" java.lang.IllegalArgumentException: stream[0] is not video
at com.xuggle.mediatool.MediaWriter.encodeVideo(MediaWriter.java:754)
at com.xuggle.mediatool.MediaWriter.encodeVideo(MediaWriter.java:783)
at com.xuggle.mediatool.MediaWriter.onVideoPicture(MediaWriter.java:1434)
at com.xuggle.mediatool.AMediaToolMixin.onVideoPicture(AMediaToolMixin.java:166)
at com.xuggle.mediatool.MediaReader.dispatchVideoPicture(MediaReader.java:610)
at com.xuggle.mediatool.MediaReader.decodeVideo(MediaReader.java:519)
at com.xuggle.mediatool.MediaReader.readPacket(MediaReader.java:475)
at xuggle.setup(xuggle.java:135)
at processing.core.PApplet.handleDraw(PApplet.java:2117)
at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:193)
at processing.core.PApplet.run(PApplet.java:2020)
at java.lang.Thread.run(Thread.java:680)

.mp4、.mov、.flvムービーを試してみましたが、同じエラーが発生します。

4

1 に答える 1

3

IContainerコンテナ=IContainer.make();

    int result = container.open(inputFilename, IContainer.Type.READ, null);
     // check if the operation was successful
      if (result<0)
          throw new RuntimeException("Failed to open media file");

      int numStreams = container.getNumStreams();

      int audioStreamId = -1;

      IContainer writer = IContainer.make();
      writer.open(outputFilename, IContainer.Type.WRITE, IContainerFormat.make());



      for (int i=0; i<numStreams; i++) {

          IStream stream = container.getStream(i);
          IStreamCoder coder = stream.getStreamCoder();
          IStreamCoder audioCoder = IStreamCoder.make(IStreamCoder.Direction.ENCODING, coder);

          if( coder.getCodecType() == ICodec.Type.CODEC_TYPE_AUDIO){
              coder.open(IMetaData.make(), IMetaData.make());
              audioStreamId = i;

              ICodec inputCodec = ICodec.findDecodingCodec(ICodec.ID.CODEC_ID_MP3);
              if (inputCodec == null)
                  throw new IllegalArgumentException("could not find input codec id");

              if (audioStreamId == -1)
                  throw new RuntimeException("could not find audio stream in container: "+inputFilename);

              writer.addNewStream(audioCoder);
              if(writer.writeHeader() == 0)
              {

                  IPacket packet = IPacket.make();
                  while(container.readNextPacket(packet) >= 0){

                      if(packet.getStreamIndex() == audioStreamId)
                      {
                          if(coder.isOpen()){

                              writer.writePacket(packet);

                          } else {throw new RuntimeException("Could not open Coder"); }
                      }
                  }
              }else {throw new RuntimeException("Header not Written for writer container.");}
          }

          coder.close(); audioCoder.close();
      }
      writer.writeTrailer();
      writer.close();

お役に立てれば... :)

于 2013-02-24T08:06:02.503 に答える