【发布时间】:2012-01-30 17:23:48
【问题描述】:
我正在使用 vlcj 在我的 Java 程序中捕获屏幕。因此我使用以下代码:
public static void main(final String[] args) {
NativeLibrary.addSearchPath("vlc", "/Applications/VLC.app/Contents/MacOS/lib/");
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new CaptureTest().start("screen://");
}
});
}
public CaptureTest() {
factory = new MediaPlayerFactory();
mediaPlayer = (HeadlessMediaPlayer) factory.newMediaPlayer();
}
private void start(String mrl) {
File dir = new File(System.getProperty("user.home"), "Videos");
dir.mkdirs();
DateFormat df = new SimpleDateFormat("yyyyMMdd-HHmmss");
String fileName = dir.getAbsolutePath() + "/Capture-" + df.format(new Date()) + ".mp4";
String[] options = {
":sout=#transcode{vcodec=h264,acodec=mp4a}:std{mux=mp4,access=file,dst=" + fileName + "}", ":input-slave=screen://"
};
mediaPlayer.playMedia(mrl, options);
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
mediaPlayer.stop();
mediaPlayer.release();
}
问题是视频输出文件只有4KB,无法播放。谁能帮我?我在 Mac OS 10.6.8 上,我使用 VLC 1.1.12 和 vlcj 1.1.5
【问题讨论】:
-
你的意思是你想用 VLC 做截屏?
-
您是否通过 VLC 命令本身而不是 Java 测试了 :sout 命令选项,以查看它在您的 PC 设置上是否正常工作?
-
如果不起作用,请尝试以下链接中给出的VLC命令行选项opensource.about.com/od/tutorials/ss/…
-
如果 :sout 命令选项中的
dst参数的文件名之间有空格,您可能需要将双引号转义如下"dst=\"" + filename + "\"" -
不,我不想截屏。我想记录我的桌面。我在控制台(Mac OS)上测试了以下内容: /Applications/VLC.app/Contents/MacOS/VLC screen:// --sout="#transcode{vcodec=h264,acodec=mp4a}:std{access=file, mux=mp4,dst=/User/test/Desktop/test.mp4}" 这按预期工作,它记录了我的屏幕。文件名中没有空格。也许你可以给我一个 Java 示例,它可以与 mp4 和 h264 一起使用?