Esempio n. 1
0
  private static void mux(FramesMP4MuxerTrack track, File f) throws IOException {
    MappedH264ES es = new MappedH264ES(NIOUtils.map(f));

    ArrayList<ByteBuffer> spsList = new ArrayList<ByteBuffer>();
    ArrayList<ByteBuffer> ppsList = new ArrayList<ByteBuffer>();
    Packet frame = null;
    while ((frame = es.nextFrame()) != null) {
      ByteBuffer data = frame.getData();
      H264Utils.wipePS(data, spsList, ppsList);
      H264Utils.encodeMOVPacket(data);
      MP4Packet pkt = new MP4Packet(new Packet(frame, data), frame.getPts(), 0);
      System.out.println(pkt.getFrameNo());
      track.addFrame(pkt);
    }
    addSampleEntry(track, es.getSps(), es.getPps());
  }
Esempio n. 2
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();
  }