Media player performance on Mac
Robert Krüger
krueger at lesspain.de
Thu Mar 5 10:06:02 UTC 2015
I am running 10.10.1 and the video is a standard h.264 export from FCPX, so
nothing special. I have tried other plain h.264 videos (an iTunes trailer)
with the same result. Have you tried it on Mac?
Another thing that is strange is that files with mov-Extensions do not seem
to be allowed. I had to rename a file to mp4 for it to be accepted. That
feels a bit weird, if the underlying framework is really AVFoundation.
This is the code I used for testing:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.FlowPane;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.stage.Stage;
import java.util.List;
/**
* Simple Media Player Example
*/
public class MediaPlayerExample extends Application {
@Override
public void start(Stage stage) throws Exception {
FlowPane pane = new FlowPane();
final List<String> args = getParameters().getRaw();
if(args.isEmpty()){
throw new IllegalStateException("no file specified");
}
final String file = args.get(0);
final Media media = new Media(file);
final MediaPlayer player = new MediaPlayer(media);
MediaView mediaView = new MediaView(player);
mediaView.setOnMouseClicked((e)->{
if(player.getStatus() == MediaPlayer.Status.PAUSED){
player.play();
} else if(player.getStatus() == MediaPlayer.Status.PLAYING){
player.pause();
}
});
mediaView.setFitWidth(800);
mediaView.setFitHeight(600);
pane.getChildren().add(mediaView);
final Scene scene = new Scene(pane);
stage.setScene(scene);
stage.setTitle(getClass().getSimpleName());
stage.sizeToScene();
stage.show();
player.play();
}
public static void main(String[] args) {
launch(args);
}
}
On Wed, Mar 4, 2015 at 8:28 PM, David DeHaven <david.dehaven at oracle.com>
wrote:
>
> > I just put a MediaView with a MediaPlayer into a FlowPane and displayed
> it.
> > Playing a Full-HD H.264 file consumes between 40 and 60% of CPU. Playing
> > the same file in Quicktime consumes about 3-4% CPU. What is the reason
> for
> > the dramatic difference? Is the player subsystem not using hardware
> > acceleration for decoding h.264? Is it something else intrinsic to
> > MediaPlayer oder MediaView? I thought 8u40's media support was build on
> top
> > of the AVFoundation framework and thus could compete with native players.
> > Can I set a flag to force hardware acceleration? Is something being done
> > about this? I am a bit worried that an application built on top of this
> > would just eat up our users' battery like crazy.
>
> Can you link a sample of a movie that’s causing that much of a performance
> difference? There will always be a slight difference, but it should not be
> that much.
>
> Could also be helpful to know more details about the environment you’re
> running in. Keep in mind the new AVFoundation code is only supported on
> 10.8 and later due to the lack of certain required APIs in 10.7 and 10.6.
>
> -DrD-
>
>
--
Robert Krüger
Managing Partner
Lesspain GmbH & Co. KG
www.lesspain-software.com
More information about the openjfx-dev
mailing list