When trying to go through an MP4 Video frame-by-frame in MediaPlayer, and a stopTime is defined, frames are skipped/not displayed when getting close to that defined stopTime.
Interestingly, this issue does not occur for every possible stopTime, but only for some. So far, I haven't been able to find a pattern.
I am using MacOS X, I'm not sure if this issue is also reproducable under a Windows or Linux environment.
To recreate this issue, I have created a testvideo with 25fps (40ms per frame) and overlayed it with the current frame using ffmpeg, which you can find here:
http://www54.zippyshare.com/v/yjOaPT8E/file.html
Steps to reproduce the problem:
- Adapt the path in the code to point to the given test video
- After starting the program, jump close to the defined stopTime using the "close to end" button
- Then, step through the video using the "+1 frame" button
- When getting close to the end, you should see frames being skipped
Code used to reproduce the issue:
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.VBox;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.stage.Stage;
import javafx.util.Duration;
public class MediaPlayerTest extends Application {
public static void main(String ... args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
VBox root = new VBox();
try {
Media media = new Media(new java.io.File("/path/to/testvideo.mp4").toURI().toString());
final MediaPlayer player = new MediaPlayer(media);
player.setStopTime(new Duration(40000));
Button button = new Button("close to end");
button.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
player.seek(new Duration(39000));
}
});
Button button2 = new Button("+1 frame");
button2.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
player.seek(player.getCurrentTime().add(new Duration(40)));
}
});
MediaView view = new MediaView(player);
view.setFitWidth(600);
root.getChildren().addAll(view, button, button2);
primaryStage.setScene(new Scene(root, 800, 600));
primaryStage.show();
} catch (Exception ex) {
}
}
}
Interestingly, this issue does not occur for every possible stopTime, but only for some. So far, I haven't been able to find a pattern.
I am using MacOS X, I'm not sure if this issue is also reproducable under a Windows or Linux environment.
To recreate this issue, I have created a testvideo with 25fps (40ms per frame) and overlayed it with the current frame using ffmpeg, which you can find here:
http://www54.zippyshare.com/v/yjOaPT8E/file.html
Steps to reproduce the problem:
- Adapt the path in the code to point to the given test video
- After starting the program, jump close to the defined stopTime using the "close to end" button
- Then, step through the video using the "+1 frame" button
- When getting close to the end, you should see frames being skipped
Code used to reproduce the issue:
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.VBox;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.stage.Stage;
import javafx.util.Duration;
public class MediaPlayerTest extends Application {
public static void main(String ... args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
VBox root = new VBox();
try {
Media media = new Media(new java.io.File("/path/to/testvideo.mp4").toURI().toString());
final MediaPlayer player = new MediaPlayer(media);
player.setStopTime(new Duration(40000));
Button button = new Button("close to end");
button.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
player.seek(new Duration(39000));
}
});
Button button2 = new Button("+1 frame");
button2.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
player.seek(player.getCurrentTime().add(new Duration(40)));
}
});
MediaView view = new MediaView(player);
view.setFitWidth(600);
root.getChildren().addAll(view, button, button2);
primaryStage.setScene(new Scene(root, 800, 600));
primaryStage.show();
} catch (Exception ex) {
}
}
}
- relates to
-
JDK-8088375 Mediaplayer not looping MP4 file on Mac OSX
- Closed