Java 类org.apache.commons.lang3.math.Fraction 实例源码

项目:ffmpeg-cli-wrapper    文件:Progress.java   
public Progress(
    long frame,
    float fps,
    long bitrate,
    long total_size,
    long out_time_ns,
    long dup_frames,
    long drop_frames,
    float speed,
    Status status) {
  this.frame = frame;
  this.fps = Fraction.getFraction(fps);
  this.bitrate = bitrate;
  this.total_size = total_size;
  this.out_time_ns = out_time_ns;
  this.dup_frames = dup_frames;
  this.drop_frames = drop_frames;
  this.speed = speed;
  this.status = status;
}
项目:ffmpeg-cli-wrapper    文件:FractionAdapter.java   
@Override
public Fraction read(JsonReader reader) throws IOException {
  JsonToken next = reader.peek();

  if (next == JsonToken.NULL) {
    reader.nextNull();
    return null;
  }

  if (next == JsonToken.NUMBER) {
    return Fraction.getFraction(reader.nextDouble());
  }

  String fraction = reader.nextString().trim();

  // Ambiguous as to what 0/0 is, but FFmpeg seems to think it's zero
  if (zeroByZero != null && "0/0".equals(fraction)) {
    return zeroByZero;
  }

  // Another edge cases is invalid files sometimes output 1/0.
  if (divideByZero != null && fraction.endsWith("/0")) {
    return divideByZero;
  }

  return Fraction.getFraction(fraction);
}
项目:ffmpeg-cli-wrapper    文件:FractionAdapter.java   
@Override
public void write(JsonWriter writer, Fraction value) throws IOException {
  if (value == null) {
    writer.nullValue();
    return;
  }
  writer.value(value.toProperString());
}
项目:ffmpeg-cli-wrapper    文件:VideoEncodingOptions.java   
@ConstructorProperties({
  "enabled",
  "codec",
  "frame_rate",
  "width",
  "height",
  "bit_rate",
  "frames",
  "video_filter",
  "preset"
})
public VideoEncodingOptions(
    boolean enabled,
    String codec,
    Fraction frame_rate,
    int width,
    int height,
    long bit_rate,
    Integer frames,
    String filter,
    String preset) {
  this.enabled = enabled;
  this.codec = codec;
  this.frame_rate = frame_rate;
  this.width = width;
  this.height = height;
  this.bit_rate = bit_rate;
  this.frames = frames;
  this.filter = filter;
  this.preset = preset;
}
项目:ffmpeg-cli-wrapper    文件:Frame.java   
protected Map<String, Object> readMetaData(NutDataInputStream in) throws IOException {
  Map<String, Object> data = new TreeMap<String, Object>();
  long count = in.readVarLong();
  for (int i = 0; i < count; i++) {
    String name = new String(in.readVarArray(), StandardCharsets.UTF_8);
    long type = in.readSignedVarInt();
    Object value;

    if (type == -1) {
      value = new String(in.readVarArray(), StandardCharsets.UTF_8);

    } else if (type == -2) {
      String k = new String(in.readVarArray(), StandardCharsets.UTF_8);
      String v = new String(in.readVarArray(), StandardCharsets.UTF_8);
      value = k + "=" + v; // TODO Change this some how

    } else if (type == -3) {
      value = in.readSignedVarInt();

    } else if (type == -4) {
      /*
       * t (v coded universal timestamp) tmp v id= tmp % time_base_count value= (tmp /
       * time_base_count) * timeBase[id]
       */
      value = in.readVarLong(); // TODO Convert to timestamp

    } else if (type < -4) {
      long denominator = -type - 4;
      long numerator = in.readSignedVarInt();
      value = Fraction.getFraction((int) numerator, (int) denominator);

    } else {
      value = type;
    }

    data.put(name, value);
  }
  return data;
}
项目:ffmpeg-cli-wrapper    文件:FFmpegUtils.java   
private static Gson setupGson() {
  GsonBuilder builder = new GsonBuilder();

  builder.registerTypeAdapterFactory(new LowercaseEnumTypeAdapterFactory());
  builder.registerTypeAdapter(Fraction.class, new FractionAdapter());
  builder.registerTypeAdapter(
      FFmpegDisposition.class, new NamedBitsetAdapter<>(FFmpegDisposition.class));

  return builder.create();
}
项目:ffmpeg-cli-wrapper    文件:FractionAdapterTest.java   
@Test
public void testRead() {
  for (TestData test : readTests) {
    Fraction f = gson.fromJson(test.s, Fraction.class);
    assertThat(f, equalTo(test.f));
  }
}
项目:ffmpeg-cli-wrapper    文件:FractionAdapterTest.java   
@Test
public void testZerosRead() {
  for (TestData test : zerosTests) {
    Fraction f = gson.fromJson(test.s, Fraction.class);
    assertThat(f, equalTo(test.f));
  }
}
项目:ffmpeg-cli-wrapper    文件:RawHandlerStreamToAudioFormatTest.java   
public RawHandlerStreamToAudioFormatTest(
    String fourcc, int sampleRateNum, int sampleRateDenom, int channels, AudioFormat expected) {
  stream = new StreamHeaderPacket();
  stream.type = StreamHeaderPacket.AUDIO;
  stream.fourcc = fourcc.getBytes(StandardCharsets.ISO_8859_1);
  stream.sampleRate = Fraction.getFraction(sampleRateNum, sampleRateDenom);
  stream.channels = channels;

  this.expected = expected;
}
项目:ffmpeg-cli-wrapper    文件:FFprobeTest.java   
@Test
public void testProbeDivideByZero() throws IOException {
  // https://github.com/bramp/ffmpeg-cli-wrapper/issues/10
  FFmpegProbeResult info = ffprobe.probe(Samples.divide_by_zero);
  assertFalse(info.hasError());

  assertThat(info.getStreams().get(1).codec_time_base, is(Fraction.ZERO));

  // System.out.println(FFmpegUtils.getGson().toJson(info));
}
项目:web2app    文件:ImagesGenBuilder.java   
public Size scale(Fraction ratio) {
    return new Size(
            width == null ? null : scale(width, ratio),
            height == null ? null : scale(height, ratio)
    );
}
项目:web2app    文件:ImagesGenBuilder.java   
public int scale(int value, Fraction ratio) {
    return ratio.multiplyBy(Fraction.getFraction(value, 1)).intValue();
}
项目:learningJava    文件:FractionExample.java   
public static void main(String[] args) {
    Fraction fraction = Fraction.getFraction(1, 3, 4);
    double value = fraction.doubleValue();
    System.out.println(value);
}
项目:ffmpeg-cli-wrapper    文件:FractionAdapter.java   
public FractionAdapter() {
  this(Fraction.ZERO, Fraction.ZERO);
}
项目:ffmpeg-cli-wrapper    文件:FractionAdapter.java   
private FractionAdapter(Fraction zeroByZero, Fraction divideByZero) {
  this.zeroByZero = zeroByZero;
  this.divideByZero = divideByZero;
}
项目:ffmpeg-cli-wrapper    文件:StreamHeaderPacket.java   
@Override
protected void readBody(NutDataInputStream in) throws IOException {

  id = in.readVarInt();
  type = in.readVarLong();
  fourcc = in.readVarArray();

  if (fourcc.length != 2 && fourcc.length != 4) {
    // TODO In future fourcc could be a different size, but for sanity checking lets leave this
    // check in.
    throw new IOException("Unexpected fourcc length: " + fourcc.length);
  }

  timeBaseId = in.readVarInt();
  msbPtsShift = in.readVarInt();
  if (msbPtsShift >= 16) {
    throw new IOException("invalid msbPtsShift " + msbPtsShift + " want < 16");
  }
  maxPtsDistance = in.readVarInt();
  decodeDelay = in.readVarLong();
  flags = in.readVarLong();
  codecSpecificData = in.readVarArray();

  if (type == VIDEO) {
    width = in.readVarInt();
    height = in.readVarInt();

    if (width == 0 || height == 0) {
      throw new IOException("invalid video dimensions " + width + "x" + height);
    }

    sampleWidth = in.readVarInt();
    sampleHeight = in.readVarInt();

    // Both MUST be 0 if unknown otherwise both MUST be nonzero.
    if ((sampleWidth == 0 || sampleHeight == 0) && sampleWidth != sampleHeight) {
      throw new IOException(
          "invalid video sample dimensions " + sampleWidth + "x" + sampleHeight);
    }

    colorspaceType = in.readVarLong();

  } else if (type == AUDIO) {
    int samplerateNum = in.readVarInt();
    int samplerateDenom = in.readVarInt();
    sampleRate = Fraction.getFraction(samplerateNum, samplerateDenom);
    channels = in.readVarInt();
  }
}
项目:ffmpeg-cli-wrapper    文件:AbstractFFmpegStreamBuilder.java   
public T setVideoFrameRate(double frame_rate) {
  return setVideoFrameRate(Fraction.getFraction(frame_rate));
}
项目:ffmpeg-cli-wrapper    文件:FractionAdapterTest.java   
@BeforeClass
public static void setupGson() {
  GsonBuilder builder = new GsonBuilder();
  builder.registerTypeAdapter(Fraction.class, new FractionAdapter());
  gson = builder.create();
}
项目:ffmpeg-cli-wrapper    文件:FractionAdapterTest.java   
public TestData(String s, Fraction f) {
  this.s = s;
  this.f = f;
}
项目:OpenModsLib    文件:CalcState.java   
@Override
public Calculator<?, ExprType> newCalculator(final SenderHolder holder) {
    final Calculator<Fraction, ExprType> calculator = FractionCalculatorFactory.createDefault();

    calculator.environment.setGlobalSymbol("_x", () -> Fraction.getFraction(holder.getX(), 1));

    calculator.environment.setGlobalSymbol("_y", () -> Fraction.getFraction(holder.getY(), 1));

    calculator.environment.setGlobalSymbol("_z", () -> Fraction.getFraction(holder.getZ(), 1));

    return calculator;
}
项目:ffmpeg-cli-wrapper    文件:AbstractFFmpegStreamBuilder.java   
/**
 * Sets the video's frame rate
 *
 * @param frame_rate Frames per second
 * @return this
 * @see net.bramp.ffmpeg.FFmpeg#FPS_30
 * @see net.bramp.ffmpeg.FFmpeg#FPS_29_97
 * @see net.bramp.ffmpeg.FFmpeg#FPS_24
 * @see net.bramp.ffmpeg.FFmpeg#FPS_23_976
 */
public T setVideoFrameRate(Fraction frame_rate) {
  this.video_enabled = true;
  this.video_frame_rate = checkNotNull(frame_rate);
  return getThis();
}
项目:ffmpeg-cli-wrapper    文件:AbstractFFmpegStreamBuilder.java   
/**
 * Set the video frame rate in terms of frames per interval. For example 24fps would be 24/1,
 * however NTSC TV at 23.976fps would be 24000 per 1001.
 *
 * @param frames The number of frames within the given seconds
 * @param per The number of seconds
 * @return this
 */
public T setVideoFrameRate(int frames, int per) {
  return setVideoFrameRate(Fraction.getFraction(frames, per));
}