Boa Tarde, Pessoal,
Estou desenvolvendo um aplicativo para captura e reprodução de vídeo e áudio, usando a biblioteca vlcj e o player vlc.
Consigo gravar os vídeos e o áudio em cada sistema operacional, bem como reproduzir no respectivo sistema em que foi gerado, mas os vídeos gerados no linux (Ubuntu Linux 12.04 LTS) não conseguem ser reproduzidos no Windows XP SP3, e os gravados no Windows, não conseguem ser reproduzidos no Linux.
Abaixo segue o código para gravação em Windows:
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;
import java.io.File;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import com.sun.jna.NativeLibrary;
import uk.co.caprica.vlcj.player.MediaPlayerFactory;
import uk.co.caprica.vlcj.player.embedded.EmbeddedMediaPlayer;
import uk.co.caprica.vlcj.player.embedded.videosurface.CanvasVideoSurface;
public class CaptureTest extends VlcjTest {
private JFrame frame;
private JPanel contentPane;
private Canvas canvas;
private MediaPlayerFactory factory;
private EmbeddedMediaPlayer mediaPlayer;
private CanvasVideoSurface videoSurface;
public static void main(final String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
// new CaptureTest().start(args[0]);
new CaptureTest().start("dshow://");
}
});
}
public CaptureTest() {
NativeLibrary.addSearchPath("libvlc",
"C:\\Arquivos de programas\\VideoLAN\\VLC");
NativeLibrary.addSearchPath("libvlccore",
"C:\\Arquivos de programas\\VideoLAN\\VLC");
canvas = new Canvas();
canvas.setBackground(Color.black);
contentPane = new JPanel();
contentPane.setBackground(Color.black);
contentPane.setLayout(new BorderLayout());
contentPane.add(canvas, BorderLayout.CENTER);
frame = new JFrame("Capture");
frame.setContentPane(contentPane);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocation(50, 50);
frame.setSize(800, 600);
factory = new MediaPlayerFactory("--no-video-title-show");
mediaPlayer = factory.newEmbeddedMediaPlayer();
videoSurface = factory.newVideoSurface(canvas);
mediaPlayer.setVideoSurface(videoSurface);
}
private void start(String mrl) {
frame.setVisible(true);
File dir = new File(System.getProperty("user.home"), "Videos");
dir.mkdirs();
DateFormat df = new SimpleDateFormat("yyyyMMdd-HHmmss");
String fileName = dir.getAbsolutePath() + "/Capture-Windows-"
+ df.format(new Date()) + ".mpg";
String[] options = {
":sout=#transcode{mux=mpeg1,vcodec=mp4v,vb=4096,scale=1,acodec=mpga,ab=128,channels=2,samplerate=44100}:duplicate{dst=file{dst="
+ fileName + "},dst=display}", ":input-slave=dshow://hw:0,0" };
mediaPlayer.playMedia(mrl, options);
}
}
E aqui abaixo, segue o código para gravação em Linux:
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;
import java.io.File;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import com.sun.jna.NativeLibrary;
import uk.co.caprica.vlcj.player.MediaPlayerFactory;
import uk.co.caprica.vlcj.player.embedded.EmbeddedMediaPlayer;
import uk.co.caprica.vlcj.player.embedded.videosurface.CanvasVideoSurface;
public class CaptureTest extends VlcjTest {
private JFrame frame;
private JPanel contentPane;
private Canvas canvas;
private MediaPlayerFactory factory;
private EmbeddedMediaPlayer mediaPlayer;
private CanvasVideoSurface videoSurface;
public static void main(final String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
// new CaptureTest().start(args[0]);
new CaptureTest().start("v4l2:///dev/video0");
}
});
}
public CaptureTest() {
NativeLibrary.addSearchPath("libvlc", "/usr/lib");
NativeLibrary.addSearchPath("libvlccore", "/usr/lib");
canvas = new Canvas();
canvas.setBackground(Color.black);
contentPane = new JPanel();
contentPane.setBackground(Color.black);
contentPane.setLayout(new BorderLayout());
contentPane.add(canvas, BorderLayout.CENTER);
frame = new JFrame("Capture");
frame.setContentPane(contentPane);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocation(50, 50);
frame.setSize(800, 600);
factory = new MediaPlayerFactory("--no-video-title-show");
mediaPlayer = factory.newEmbeddedMediaPlayer();
videoSurface = factory.newVideoSurface(canvas);
mediaPlayer.setVideoSurface(videoSurface);
}
private void start(String mrl) {
frame.setVisible(true);
File dir = new File(System.getProperty("user.home"), "Videos");
dir.mkdirs();
DateFormat df = new SimpleDateFormat("yyyyMMdd-HHmmss");
String fileName = dir.getAbsolutePath() + "/Capture-Linux-"
+ df.format(new Date()) + ".mpg";
String[] options = {
":sout=#transcode{mux=mpeg1,vcodec=mp4v,vb=4096,scale=1,acodec=mpga,ab=128,channels=2,samplerate=44100}:duplicate{dst=file{dst="
+ fileName + "},dst=display}", ":input-slave=v4l2://hw:0,0" };
mediaPlayer.playMedia(mrl, options);
}
}
Alguém poderia dar uma ajuda?
Atenciosamente,
Augusto Cesar