Warning: session_start(): open(/var/lib/php/sessions/sess_pjg45nqfdsd05vt4rk6mpt2lvb, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
!7
// from https://github.com/vzhn/ffmpeg-java-samples/blob/master/src/main/java/WebcamCapture.java
/*lib 1400538
lib 1400539
lib 1400540
lib 1400541
lib 1400542*/
lib 1400543 // javacpp ffmpeg examples for linux x64
import org.bytedeco.javacpp.avcodec;
import util.Canvas;
import static org.bytedeco.javacpp.avcodec.av_packet_unref;
import static org.bytedeco.javacpp.avdevice.avdevice_register_all;
import static org.bytedeco.javacpp.avformat.*;
import static org.bytedeco.javacpp.avutil.*;
p { new WebcamCapture().start(); }
sclass WebcamCapture {
public static final int WIDTH = 800;
public static final int HEIGHT = 600;
private Canvas canvas;
private void start() throws IOException {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setLayout(new BorderLayout());
canvas = new Canvas();
frame.add(canvas, BorderLayout.CENTER);
frame.setVisible(true);
frame.setSize(WIDTH, HEIGHT);
startCapture();
}
private void startCapture() throws IOException {
av_log_set_level(AV_LOG_VERBOSE);
avdevice_register_all();
AVInputFormat v4l2 = av_find_input_format("v4l2");
if (v4l2 == null) {
throw new RuntimeException("v4l2 not found");
}
AVFormatContext v4l2Device = avformat_alloc_context();
if (v4l2Device == null) {
throw new RuntimeException("failed to alloc AVFormatContext");
}
AVDictionary options = new AVDictionary();
av_dict_set(options, "input_format", "mjpeg", 0);
if(avformat_open_input(v4l2Device, "/dev/video0", v4l2, options) != 0) {
throw new RuntimeException("Couldn't open input stream.\n");
}
av_dict_free(options);
av_dump_format(v4l2Device, 0, "", 0);
if (v4l2Device.nb_streams() == 0) {
throw new RuntimeException("Stream not found!");
}
avcodec.AVPacket pkt = new avcodec.AVPacket();
while (true) {
av_read_frame(v4l2Device, pkt);
byte[] data = new byte[pkt.size()];
pkt.data().get(data);
av_packet_unref(pkt);
canvas.setImage(ImageIO.read(new ByteArrayInputStream(data)));
}
}
}