Getting a Pict from a Movie
If you’re working with movies, you’ll probably want to be able to get a pict from some arbitrary time in the movie. You could use this for identifying movies via thumbnail icons, identifying segments on a timeline GUI, etc. This action is so common, and it’s really easy.
How do I do that?
To grab a movie at a certain time, you just need a one-line call to
Movie.getPict( )
, as
exercised by the dumpToPict( ) method shown here:
Note
Notice I don’t say “grab the current movie frame” because the movie could have other on-screen elements like text, sprites, other movies, etc., not just one frame of one video track.
public void dumpToPict ( ) {
try {
float oldRate = movie.getRate( );
movie.stop( );
Pict pict = movie.getPict(movie.getTime( ));
String absPictPath =
(new File ("movie.pict")).getAbsolutePath( );
pict.writeToFile (new File (absPictPath));
movie.setRate (oldRate);
} catch (Exception e) {
e.printStackTrace( );
}
}This method stops the movie if it’s playing and
stores the previous play rate. Then it creates a
Pict on the movie’s current time
and saves it to a file called movie.pict. Then
it restarts the movie.
Note
The downloadable book code exercises this in a demo called PictFromMovie. Run it with ant run-ch05-pictfrommovie.
What about . . .
. . . not stopping the movie? I haven’t had good results with this call unless the movie is stopped. At best, it makes the playback choppy for a few seconds; at worst, it crashes.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access