我目前有问题,让vlcj 4旋转了一个视频。我可以让应用程序运行,但似乎遇到了一个问题 videoPixelBuffer
没有示例化。下面的代码来自主页上的pixelbuffer教程。我一直试图理解它是如何的函数,但看不到示例化 videoPixelBuffer
有人打过电话。我试图手动调用它也没有工作。我认为问题在于 videoPixelBuffer
,但无法找到解决此问题的方法。
有什么想法吗?
下面你会看到我正在使用的代码和我得到的错误消息。下面是演示的github repo的链接(https://github.com/caprica/vlcj-javafx/blob/pixelbuffer-test/src/test/java/uk/co/caprica/vlcj/javafx/test/writableimagedemo.java)
版本:
vlcj 4.1.0版本
阀控3.0.8
开放JDK 13
开放JFX 13
代码:
package player;
import java.nio.ByteBuffer;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.scene.image.ImageView;
import javafx.scene.image.PixelBuffer;
import javafx.scene.image.PixelFormat;
import javafx.scene.image.WritableImage;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import uk.co.caprica.vlcj.factory.MediaPlayerFactory;
import uk.co.caprica.vlcj.player.base.MediaPlayer;
import uk.co.caprica.vlcj.player.embedded.EmbeddedMediaPlayer;
import uk.co.caprica.vlcj.player.embedded.videosurface.CallbackVideoSurface;
import uk.co.caprica.vlcj.player.embedded.videosurface.VideoSurfaceAdapters;
import uk.co.caprica.vlcj.player.embedded.videosurface.callback.BufferFormat;
import uk.co.caprica.vlcj.player.embedded.videosurface.callback.BufferFormatCallback;
import uk.co.caprica.vlcj.player.embedded.videosurface.callback.RenderCallback;
import uk.co.caprica.vlcj.player.embedded.videosurface.callback.format.RV32BufferFormat;
public class Test extends Application {
private MediaPlayerFactory mediaPlayerFactory;
private EmbeddedMediaPlayer embeddedMediaPlayer;
private WritableImage videoImage;
private PixelBuffer<ByteBuffer> videoPixelBuffer;
private ImageView videoImageView;
@Override
public void init() {
mediaPlayerFactory = new MediaPlayerFactory();
embeddedMediaPlayer = mediaPlayerFactory.mediaPlayers().newEmbeddedMediaPlayer();
embeddedMediaPlayer.videoSurface().set(new FXCallbackVideoSurface());
}
@Override
public final void start(Stage primaryStage) throws Exception {
StackPane root = new StackPane();
root.setStyle("-fx-background-color: black;");
videoImageView = new ImageView();
videoImageView.setPreserveRatio(true);
videoImageView.fitWidthProperty().bind(root.widthProperty());
videoImageView.fitHeightProperty().bind(root.heightProperty());
root.getChildren().add(videoImageView);
Scene scene = new Scene(root, 1200, 675);
primaryStage.setScene(scene);
primaryStage.show();
String mrl = getParameters().getRaw().get(0);
embeddedMediaPlayer.media().play(mrl);
}
@Override
public final void stop() throws Exception {
embeddedMediaPlayer.controls().stop();
embeddedMediaPlayer.release();
mediaPlayerFactory.release();
}
private class FXCallbackVideoSurface extends CallbackVideoSurface {
FXCallbackVideoSurface() {
super(new FXBufferFormatCallback(), new FXRenderCallback(), true, VideoSurfaceAdapters.getVideoSurfaceAdapter());
}
}
private class FXBufferFormatCallback implements BufferFormatCallback {
private int sourceWidth;
private int sourceHeight;
@Override
public BufferFormat getBufferFormat(int sourceWidth, int sourceHeight) {
this.sourceWidth = sourceWidth;
this.sourceHeight = sourceHeight;
return new RV32BufferFormat(sourceWidth, sourceHeight);
}
public void allocatedBuffers(ByteBuffer[] buffers) {
assert buffers[0].capacity() == sourceWidth * sourceHeight * 4;
PixelFormat<ByteBuffer> pixelFormat = PixelFormat.getByteBgraPreInstance();
videoPixelBuffer = new PixelBuffer<>(sourceWidth, sourceHeight, buffers[0], pixelFormat);
videoImage = new WritableImage(videoPixelBuffer);
videoImageView.setImage(videoImage);
}
}
private class FXRenderCallback implements RenderCallback {
@Override
public void display(MediaPlayer mediaPlayer, ByteBuffer[] nativeBuffers, BufferFormat bufferFormat) {
Platform.runLater(() -> {
videoPixelBuffer.updateBuffer(pb -> null);
});
}
}
public static void main(String[] args) {
launch(args);
}
}
class WritableImageDemoLauncher {public static void main(String[] args) {Test.main(args);}}
错误消息:
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
at player.Test$FXRenderCallback.lambda$0(Test.java:110)
at javafx.graphix/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(AcessController.java:391)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:92)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop(WinApplication.java:174)
at java.base/java.lang.Thread.run(Thread.java:830)
测试。java:110 is 以下行: videoPixelBuffer.updateBuffer(pb -> null);
暂无答案!
目前还没有任何答案,快来回答吧!