taskman
taskman

Reputation: 53

Generate video with ffmpeg to play using JavaFX

People always say to post a new question so I am posting a new question that relates to Generate video with ffmpeg for JavaFX MediaPlayer

The images I use can be downloaded from here https://www.dropbox.com/s/mt8yblhfif113sy/temp.zip?dl=0. It is a 2.2GB zip file with 18k images, still uploading, might take some time. The images are slices of a 3D object. I need to display images every 10ms to 20ms. I tried it with Java, but just couldn't get faster than 30ms+ so now I am trying to generate a video that will display images as fast as I want without worrying about memory or CPU power.

People will be using my software to slice the objects and then generate the videos to be played later one. The player might run on a cheap laptop or might run on a Raspberry Pi. I need to make sure the slicer will work on any OS and that people don't need to install too much extra stuff to make it work. It would be best if I can just include everything that is needed in the download of the app.

I also posted here https://ffmpeg.zeranoe.com/forum/viewtopic.php?f=15&t=2474&sid=4f7a752f909202fbec19afc9edaf418c

I am using Windows 7 and I have VLC installed. The ffmpeg version is

ffmpeg version N-72276-gf99fed7 Copyright (c) 2000-2015 the FFmpeg developers
  built with gcc 4.9.2 (GCC)

I also tried the command lines posted on the linked question

This line produced the video and JavaFX didn't have any errors

ffmpeg -f image2 -r 50 -i "Mandibular hollow 1 micron.gizmofill%d.gizmoslice.jpg" -s 1638x1004 -vcodec mpeg4 -qscale 1 -f mp4 Timelapse.mp4

enter image description here

This line also produced the video, but JavaFX had an error: "Caused by: MediaException: MEDIA_UNSUPPORTED : Unrecognized file signature!"

ffmpeg -f image2 -r 50 -i "Mandibular hollow 1 micron.gizmofill%d.gizmoslice.jpg" -s 1920x1080 -vcodec mpeg4 -qscale 1 Timelapse.avi

enter image description here

I also tried this two pass encoding I believe. It produced the video, but didn't play

ffmpeg -r 50 -i "Mandibular hollow 1 micron.gizmofill%d.gizmoslice.jpg" -s 1638x1004 -r 50 -b:v 1550k -bt 1792k -vcodec libx264 -pass 1 -an combined50.flv && ffmpeg -y -r 50 -i "Mandibular hollow 1 micron.gizmofill%d.gizmoslice.jpg" -s 1638x1004 -r 50 -b:v 1550k -bt 1792k -vcodec libx264 -pass 2 -vpre hq -acodec libfaac -ab 128k combined50.flv

This is my JavaFX code. As you can see I tried the Oracle video and that worked fine.

public class FXMLDocumentController implements Initializable {

    @FXML
    private Label label;

    @FXML
    private MediaView mediaView;

    @FXML
    private void handleButtonAction(ActionEvent event) {
        System.out.println("You clicked me!");

//        final File f = new File("http://download.oracle.com/otndocs/products/javafx/oow2010-2.flv");
        final File f = new File("C:/Users/kobus/Dropbox/JavaProjects/Gizmetor/temp/Timelapse.avi");

//        "C:/Users/kobus/Dropbox/JavaProjects/Gizmetor/temp/combined50.avi.flv"
//        http://download.oracle.com/otndocs/products/javafx/oow2010-2.flv

        Media media = new Media(f.toURI().toString());
//        Media media = new Media("http://download.oracle.com/otndocs/products/javafx/oow2010-2.flv");
        MediaPlayer mediaPlayer = new MediaPlayer(media);
        mediaPlayer.setAutoPlay(true);

        mediaPlayer.play();
        mediaView.setMediaPlayer(mediaPlayer);
        label.setText("Hello World!");
        System.out.println(mediaPlayer.isAutoPlay());

//        mediaView
    }

    @Override
    public void initialize(URL url, ResourceBundle rb) {
        // TODO
    }

}

Upvotes: 0

Views: 1890

Answers (1)

Roland
Roland

Reputation: 18415

You need to encode the video in a format that JavaFX can play back.

Check out the list of supported media types.

Upvotes: 1

Related Questions