public void finish() throws IOException {

    videoTrack.addSampleEntry(MP4Muxer.videoSampleEntry(imageType, size, ENCODER_NAME));

    // Write MP4 header and finalize recording
    if (af != null) audioTrack.addSampleEntry(MP4Muxer.audioSampleEntry(af));

    muxer.writeHeader();
    NIOUtils.closeQuietly(ch);
  }
  public void addFrame(int width, int height, ByteBuffer buff, long timeScaleFPS, long duration)
      throws IOException {
    if (size == null) {
      size = new Size(width, height);
      videoTrack.addSampleEntry(MP4Muxer.videoSampleEntry(imageType, size, ENCODER_NAME));

      if (af != null) audioTrack.addSampleEntry(MP4Muxer.audioSampleEntry(af));
    }

    // Add packet to video track

    videoTrack.addFrame(
        new MP4Packet(buff, frameNo, timeScaleFPS, duration, frameNo, true, null, frameNo, 0));

    frameNo++;
  }
Пример #3
0
  public static void main(String[] args) throws Exception {
    if (args.length < 2) {
      System.out.println("Syntax: <in.mov> <out.mov>");
      return;
    }

    SeekableByteChannel input = readableChannel(new File(args[0]));
    MP4Demuxer demuxer = new MP4Demuxer(input);
    SeekableByteChannel output = writableChannel(new File(args[1]));
    MP4Muxer muxer = MP4Muxer.createMP4Muxer(output, Brand.MOV);

    AbstractMP4DemuxerTrack inVideo = demuxer.getVideoTrack();
    VideoSampleEntry entry = (VideoSampleEntry) inVideo.getSampleEntries()[0];
    int width = entry.getWidth();
    int height = entry.getHeight();
    ProresToProxy toProxy = new ProresToProxy(width, height, 65536);
    FramesMP4MuxerTrack outVideo = muxer.addTrack(TrackType.VIDEO, (int) inVideo.getTimescale());

    TrackHeaderBox th = inVideo.getBox().getTrackHeader();
    System.out.println(toProxy.getFrameSize());
    int frame = 0;
    long from = System.currentTimeMillis();
    long last = from;
    MP4Packet pkt = null;
    while ((pkt = (MP4Packet) inVideo.nextFrame()) != null) {
      ByteBuffer out = ByteBuffer.allocate(pkt.getData().remaining());
      toProxy.transcode(pkt.getData(), out);
      out.flip();
      outVideo.addFrame(MP4Packet.createMP4PacketWithData(pkt, out));
      frame++;
      long cur = System.currentTimeMillis();
      if (cur - last > 5000) {
        System.out.println(((1000 * frame) / (cur - from)) + " fps");
        last = cur;
      }
    }
    entry.setMediaType("apco");
    outVideo.addSampleEntry(entry);

    muxer.writeHeader();
    output.close();
    input.close();
  }
Пример #4
0
  private static void addSampleEntry(
      FramesMP4MuxerTrack track, SeqParameterSet[] spss, PictureParameterSet[] ppss) {
    SeqParameterSet sps = spss[0];
    Size size = new Size((sps.pic_width_in_mbs_minus1 + 1) << 4, getPicHeightInMbs(sps) << 4);

    SampleEntry se = MP4Muxer.videoSampleEntry("avc1", size, "JCodec");

    avcC = new AvcCBox(sps.profile_idc, 0, sps.level_idc, write(spss), write(ppss));
    se.add(avcC);
    track.addSampleEntry(se);
  }
Пример #5
0
  public static void main(String[] args) throws Exception {
    if (args.length < 2) {
      System.out.println(
          "Syntax: <in.264> <out.mp4>\n"
              + "\tWhere:\n"
              + "\t-q\tLook for stream parameters only in the beginning of stream");
      return;
    }

    File in = new File(args[0]);
    File out = new File(args[1]);

    SeekableByteChannel file = writableFileChannel(out);
    MP4Muxer muxer = new MP4Muxer(file);
    FramesMP4MuxerTrack track = muxer.addTrackForCompressed(TrackType.VIDEO, 25);

    mux(track, in);

    muxer.writeHeader();

    file.close();
  }