Ask Your Question
0

Only a few video codecs

asked 2016-06-09 08:16:53 -0600

Kristian gravatar image

updated 2016-06-13 03:18:54 -0600

Hello,

I am using OpenCV with java to record a Webcam video. If I use the "-1" fourCC prameter creating the video writer I get a list of all useable codecs at runtime. In my case this list only contains ca. 5 codecs. No MPEG, no h.264... I already installed codec packs like KLite but I won't get more codecs.

Can anybody tell me how to get more codecs?

Thank you. Kristian

P.s.: I am using Eclipse

edit retag flag offensive close merge delete

Comments

About h.264 you will need h264 from cisco

LBerger gravatar imageLBerger ( 2016-06-09 09:05:02 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-06-13 06:01:05 -0600

Kristian gravatar image

Hello,

thank you for your hint.

I downloaded the openh264-1.5.0-win64msvc.dll but I can't find a way to install it onto my Windows system.

Do you can help me out?

edit flag offensive delete link more

Comments

This dll must be installed in directory included in var system path or same directory than opencvffmpeg.dll. See this issue

LBerger gravatar imageLBerger ( 2016-06-13 06:18:35 -0600 )edit

I installed OpenCV the way it is descriped here.

Than I configured Eclipse like they say here.

Than I copied the .dll to the place you sugested.

I still can only select one of these codecs:

  • Microsoft RLE
  • Microsoft Video 1
  • Intel IYUV Codec
  • Intel IYUV Codec (Yes, twice)
  • Cinepac Codec from Radius
  • Uncompressed

Here is my code:

import java.awt.Graphics; import java.awt.Image; import java.awt.image.BufferedImage; import java.awt.image.ImageObserver; import java.io.ByteArrayInputStream;

import javax.imageio.ImageIO; import javax.swing.JPanel;

import org.opencv.core.Core; import org.opencv.core.Mat;

Kristian gravatar imageKristian ( 2016-06-15 02:14:58 -0600 )edit

import org.opencv.core.MatOfByte; import org.opencv.core.Size; import org.opencv.imgcodecs.Imgcodecs; import org.opencv.videoio.VideoCapture; import org.opencv.videoio.VideoWriter; import org.opencv.videoio.Videoio;

public class KriPanel extends JPanel implements Runnable {

private int count = 0;
private VideoCapture camSource = null;
private Mat frame;
private MatOfByte mem;
private VideoWriter oVideoWriter;
private int cameraID;
private String cameraIP;
private Boolean run = false;
private String fileName;

public KriPanel(int cameraID, String cameraIP, String fileName) {
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME); // load native library of opencv
    this.setSize(105, 160);
    this.setVisible(true);
    initComponents();
    this.cameraID = cameraID;
    this.cameraIP = cameraIP;
Kristian gravatar imageKristian ( 2016-06-15 02:16:36 -0600 )edit

this.cameraID = 1; this.fileName = fileName; frame = new Mat(); mem = new MatOfByte(); }

@Override
public void run() {
    System.out.println("Run");
    synchronized (this) {
        while (true) {
            if (camSource.grab()) {
                try {
                    camSource.retrieve(frame);
                    Imgcodecs.imencode(".bmp", frame, mem);
                    Image im = ImageIO.read(new ByteArrayInputStream(mem.toArray()));
                    BufferedImage buff = (BufferedImage) im;
                    this.setVisible(true);
                    Graphics g = this.getGraphics();
                    oVideoWriter.write(frame);
                    System.out.println("Width: " +this.getWidth() +" Height: "+this.getHeight());
                    if(g.drawImage(buff, 0, 0, this.getWidth(), this.getHeight(), 0, 0, this.getWidth(), this.getHeight(), null));
                } catch (Exception ex) {
                    ex.printStackTrace();
Kristian gravatar imageKristian ( 2016-06-15 02:17:27 -0600 )edit

} } } } }

private void initComponents() {
    if (cameraID != 42) {
        camSource = new VideoCapture(cameraID);
    } else {
        camSource = new VideoCapture(cameraIP);
    }
    if (!camSource.isOpened()) {
        System.out.println("Camera Error");
    } else {
        System.out.println("Camera OK");
    }

    Size frameSize = new Size((int) camSource.get(Videoio.CAP_PROP_FRAME_WIDTH),
            (int) camSource.get(Videoio.CAP_PROP_FRAME_HEIGHT));

    //int fourCC = oVideoWriter.fourcc('X', '2', '6', '4');
    //System.out.println("FourCC:" +fourCC);        
    oVideoWriter = new VideoWriter("test.avi", -1, 20, frameSize, true);

}

}

Kristian gravatar imageKristian ( 2016-06-15 02:17:54 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-06-09 08:16:53 -0600

Seen: 760 times

Last updated: Jun 13 '16