1

I have array of Image in JavaFx. I want create a clip video (animation) from those images, including sound file. How Can I achieve this?

NOTE: I want to get a video file at the end of the process (avi, mp4 ...).

This is my array:

Image[] frames

I tried use "keyFrame" class... but without success:

        ImageView destImageView = new ImageView();
        Group group;
        group = new Group();
        group.setTranslateX(300);
        group.setTranslateY(450);

        Image[] frames = m.getFrames();
        KeyFrame[] kf = new KeyFrame[frames.length];
        for(int i=0;i<frames.length;i++){
            kf[0] =new KeyFrame(new Duration(0), new EventHandler<ActionEvent>() {
                @Override
                public void handle(ActionEvent event) {
//                  destImageView.setImage();
//                  group.getChildren().setAll(destImageView);

                }
            });
        }
Ramz
  • 207
  • 1
  • 2
  • 15
  • This question is `too broad` and unless asked with specific scenario's and supplied with tried code, is most likely to get closed. – ItachiUchiha Apr 15 '15 at 20:46
  • 1
    You can create a [sprite animation](http://blog.netopyr.com/2012/03/09/creating-a-sprite-animation-with-javafx/) or a [cat whack animation](http://stackoverflow.com/questions/23440980/how-show-specific-part-of-an-image-in-javafx), but really that is nothing like producing an avi or mp4, so I doubt that doing so will not help you achieve your end goal - there is no in-built avi/mp4 export function in the JavaFX core libraries. – jewelsea Apr 15 '15 at 21:43
  • What about the sound Ramz? (I'm asking you) What is your question? – jewelsea Apr 15 '15 at 22:06
  • @jewelsea I want add a sound to the animation. – Ramz Apr 15 '15 at 22:13
  • You can use a [MediaPlayer](https://docs.oracle.com/javase/8/javafx/api/javafx/scene/media/MediaPlayer.html) or an [AudioClip](http://docs.oracle.com/javase/8/javafx/api/javafx/scene/media/AudioClip.html) to playback audio using JavaFX. Read the [JavaFX media documentation](http://docs.oracle.com/javase/8/javafx/media-tutorial/overview.htm). – jewelsea Apr 16 '15 at 00:06

1 Answers1

0

You can use

javax.imageio.ImageIO.write(javafx.embed.swing.SwingFXUtils.fromFXImage(frame, null), "png", new File(directory, fileName));

to save each image as a png file.

Make sure to give the frames sequentially numbered filenames, e.g. img0000.png, img0001.png etc..

Then use ImageJ/Fiji (https://imagej.net/Fiji/Downloads) to import the image sequence and save as an avi file. Alternatively, as ImageJ is open-source and written in Java you could import and use directly the ImageJ class

ij.plugin.filter.AVI_Writer

You could then convert it to an mp4 or other format using VLC Player, for example.

teraspora
  • 415
  • 4
  • 17