import quicktime.*; import quicktime.io.*; import quicktime.std.image.*; import quicktime.std.movies.media.*; import quicktime.std.movies.*; import quicktime.std.*; import quicktime.qd.*; import quicktime.util.QTPointer; import java.io.*; public class CaptionAdder { public static void main (String args[]) { if (args.length != 1){ System.out.println("Usage: java CaptionAdder [input_filename]"); } else { try { QTSession.open(); System.out.println ("QuickTime version: " + QTSession.getMajorVersion() + "." + QTSession.getMinorVersion()); QTFile qtfile = new QTFile(new File(args[0])); DataRef urlMovie = new DataRef ("file://" + qtfile.getPath()); Movie movie = Movie.fromDataRef (urlMovie,StdQTConstants.newMovieActive); float textTrackHeight = 32; QDRect movieBounds = movie.getNaturalBoundsRect(); float movieWidth = movieBounds.getWidthF(); float movieHeight = movieBounds.getHeightF(); Track textTrack = movie.addTrack(movieWidth, textTrackHeight, 0); Matrix textTrackMatrix = textTrack.getMatrix(); textTrackMatrix.translate (0, movieHeight - textTrackHeight); textTrack.setMatrix (textTrackMatrix); textTrack.setEnabled (true); int movieTimeScale = movie.getTimeScale(); TextMedia textMedia = new TextMedia (textTrack, movieTimeScale); QDRect textBounds = new QDRect (movieWidth, movieHeight); textMedia.beginEdits(); TimeInfo sampleTime = new TimeInfo (0, movie.getDuration()/2); String text = new String ("1234 Main St. - Listing price: $164,000"); TextMediaHandler textMediaHandler = textMedia.getTextHandler(); QTPointer textPointer = new QTPointer ( text.length() + 1, true ); textPointer.copyFromArray ( 0, text.getBytes(), 0, text.length() ); textMediaHandler.addTextSample ( textPointer, QDFont.getFNum("Times"), 16, 0, QDColor.white, QDColor.black, QDConstants.teCenter, textBounds, StdQTConstants.dfClipToTextBox | StdQTConstants.dfKeyedText, 0,0,0, null, sampleTime.duration ); textMedia.endEdits(); textTrack.insertMedia (sampleTime.time, 0, sampleTime.duration, 1 ); OpenMovieFile outStream = OpenMovieFile.asWrite (qtfile); movie.updateResource (outStream, StdQTConstants.movieInDataForkResID, qtfile.getName()); } catch (Exception e) { e.printStackTrace(); QTSession.close(); System.exit(0); } QTSession.close(); // end else } System.out.println ("complete."); //end method } } |
视频格式 | 数据率 | 尺寸 | 帧率 |
H.264 视频 | 最高 768 Kbps | 320 x 240 像素 | 30 fps |
MPEG-4 视频 | 最高 2.5 Mbps | 480 x 480 像素 | 30 fps |
import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.IOException; import quicktime.*; import quicktime.io.*; import quicktime.qd.*; import quicktime.std.*; import quicktime.std.clocks.*; import quicktime.std.StdQTConstants; import quicktime.std.image.*; import quicktime.std.movies.*; import quicktime.std.movies.media.*; import quicktime.std.qtcomponents.*; import quicktime.util.*; import quicktime.app.view.*; public class MovieConverter extends JFrame implements Errors, ActionListener{ QTComponent component = null; JPanel jpanel = null; Button selectButton = null; public static void main (String args[]) { try{ new MovieConverter(); } catch(Exception e){ System.out.println(e); } } public MovieConverter(){ super("Movie Converter"); try { QTSession.open(); } catch (Exception e) { e.printStackTrace(); QTSession.close(); } jpanel = new JPanel(); this.setContentPane(jpanel); selectButton = new Button ("Select a File to Convert"); selectButton.addActionListener(this); jpanel.add (selectButton); addWindowListener(new WindowAdapter () { public void windowClosing (WindowEvent e) { QTSession.close(); dispose(); } public void windowClosed (WindowEvent e) { System.exit(0); } }); this.pack(); this.setVisible(true); } public void actionPerformed (ActionEvent event) { exportMovie(); } void displayMovie (Movie m) throws QTException { component = QTFactory.makeQTComponent (new MovieController (m)); jpanel.add ((Component)component); jpanel.remove(selectButton); pack(); } void exportMovie () { try{ FileDialog fileDialog = new FileDialog (this, "Choose Movie to Export...", FileDialog.LOAD); fileDialog.show(); if (fileDialog.getFile() == null) return; QTFile movieFile = new QTFile (fileDialog.getDirectory() + fileDialog.getFile()); Movie movie = Movie.fromFile (OpenMovieFile.asRead(movieFile)); if (component != null) { component.setMovieController(new MovieController(movie)); } else { displayMovie (movie); } new Thread (new Exporter(movie)).start(); } catch (QTException err) { err.printStackTrace(); } } } |