예제 #1
0
 @Test
 public void flvNellymoserTest() throws Exception {
   logger.info("flvNellymoserTest");
   Muxer muxer =
       Muxer.make(this.getClass().getCanonicalName() + ".flv_nellymoser.flv", null, null);
   Encoder encoder = Encoder.make(Codec.findEncodingCodec(Codec.ID.CODEC_ID_NELLYMOSER));
   Type findType = null;
   for (Type type : encoder.getCodec().getSupportedAudioFormats()) {
     if (findType == null) {
       findType = type;
     }
     if (type == Type.SAMPLE_FMT_S16) {
       findType = type;
       break;
     }
   }
   logger.info(findType.toString());
   int sampleRate = 44100;
   encoder.setSampleRate(sampleRate);
   Rational encoderTimeBase = Rational.make(1, sampleRate);
   encoder.setTimeBase(encoderTimeBase);
   encoder.setChannels(1);
   encoder.setChannelLayout(Layout.CH_LAYOUT_MONO);
   encoder.setSampleFormat(findType);
   encoder.setFlag(Flag.FLAG_GLOBAL_HEADER, true);
   encoder.open(null, null);
   muxer.addNewStream(encoder);
   processConvert(muxer, encoder);
   logger.info("done");
 }
예제 #2
0
  private void processConvert(Muxer muxer, Encoder encoder) throws Exception {
    muxer.open(null, null);
    MediaPacket packet = MediaPacket.make();
    MediaAudio samples = beepSamples();
    logger.info(samples.toString());
    if (samples.getSampleRate() != encoder.getSampleRate()
        || samples.getFormat() != encoder.getSampleFormat()
        || samples.getChannelLayout() != encoder.getChannelLayout()) {
      final MediaAudioResampler resampler =
          MediaAudioResampler.make(
              encoder.getChannelLayout(),
              encoder.getSampleRate(),
              encoder.getSampleFormat(),
              samples.getChannelLayout(),
              samples.getSampleRate(),
              samples.getFormat());
      resampler.open();
      MediaAudio spl =
          MediaAudio.make(
              samples.getNumSamples(),
              encoder.getSampleRate(),
              encoder.getChannels(),
              encoder.getChannelLayout(),
              encoder.getSampleFormat());
      resampler.resample(spl, samples);
      logger.info(spl.toString());
      logger.info("{}", spl.getNumSamples());
      Assert.assertEquals(spl.getNumSamples(), samples.getNumSamples());
      samples = spl;
    }
    logger.info(samples.toString());

    // we only have one set of samples.
    encoder.encodeAudio(packet, samples);
    logger.info("{}", packet);
    if (packet.isComplete()) muxer.write(packet, false);

    // Flush the encoders
    do {
      encoder.encodeAudio(packet, null);
      logger.info("{}", packet);
      if (packet.isComplete()) {
        muxer.write(packet, false);
      }
    } while (packet.isComplete());
    muxer.close();
  }