コード例 #1
0
ファイル: ToProxy.java プロジェクト: 2php/jcodec
  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();
  }
コード例 #2
0
ファイル: Flattern.java プロジェクト: 2php/jcodec
 public void flattern(MovieBox movie, File video) throws IOException {
   Platform.deleteFile(video);
   SeekableByteChannel out = null;
   try {
     out = writableChannel(video);
     flatternChannel(movie, out);
   } finally {
     if (out != null) out.close();
   }
 }
コード例 #3
0
ファイル: Flattern.java プロジェクト: 2php/jcodec
 public static void main1(String[] args) throws Exception {
   if (args.length < 2) {
     System.out.println("Syntax: self <ref movie> <out movie>");
     System.exit(-1);
   }
   File outFile = new File(args[1]);
   Platform.deleteFile(outFile);
   SeekableByteChannel input = null;
   try {
     input = readableChannel(new File(args[0]));
     MovieBox movie = MP4Util.parseMovieChannel(input);
     new Flattern().flattern(movie, outFile);
   } finally {
     if (input != null) input.close();
   }
 }
コード例 #4
0
ファイル: Cut.java プロジェクト: 2php/jcodec
  public static void main1(String[] args) throws Exception {
    if (args.length < 1) {
      System.out.println(
          "Syntax: cut [-command arg]...[-command arg] [-self] <movie file>\n"
              + "\tCreates a reference movie out of the file and applies a set of changes specified by the commands to it.");
      System.exit(-1);
    }

    List<Slice> slices = new ArrayList<Slice>();
    List<String> sliceNames = new ArrayList<String>();

    boolean selfContained = false;
    int shift = 0;
    while (true) {
      if ("-cut".equals(args[shift])) {
        String[] pt = StringUtils.splitS(args[shift + 1], ":");
        slices.add(new Slice(parseInt(pt[0]), parseInt(pt[1])));
        if (pt.length > 2) sliceNames.add(pt[2]);
        else sliceNames.add(null);
        shift += 2;
      } else if ("-self".equals(args[shift])) {
        ++shift;
        selfContained = true;
      } else break;
    }
    File source = new File(args[shift]);

    SeekableByteChannel input = null;
    SeekableByteChannel out = null;
    List<SeekableByteChannel> outs = new ArrayList<SeekableByteChannel>();
    try {
      input = readableChannel(source);
      MovieBox movie = createRefMovie(input, "file://" + source.getCanonicalPath());
      List<MovieBox> slicesMovs;
      if (!selfContained) {
        out =
            writableChannel(
                new File(
                    source.getParentFile(),
                    JCodecUtil2.removeExtension(source.getName()) + ".ref.mov"));
        slicesMovs = new Cut().cut(movie, slices);
        MP4Util.writeMovie(out, movie);
      } else {
        out =
            writableChannel(
                new File(
                    source.getParentFile(),
                    JCodecUtil2.removeExtension(source.getName()) + ".self.mov"));
        slicesMovs = new Cut().cut(movie, slices);
        new Strip().strip(movie);
        new Flattern().flatternChannel(movie, out);
      }
      saveSlices(slicesMovs, sliceNames, source.getParentFile());
    } finally {
      if (input != null) input.close();
      if (out != null) out.close();
      for (SeekableByteChannel o : outs) {
        o.close();
      }
    }
  }