chrisnp / javacv

Automatically exported from code.google.com/p/javacv
GNU General Public License v2.0
0 stars 0 forks source link

Unable to record with sample code on #493

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.Create maven java project in eclipse
2. specify javacv 0.9 in pom and configure native *.so files path in eclipse
3. Run this sample program , look at the answer code
http://stackoverflow.com/questions/14070370/how-to-capture-and-record-video-from
-webcam-using-javacv

What is the expected output? What do you see instead?
I should have a video file recorded from my webcam

I am getting exception - 

HIGHGUI ERROR: V4L: Property <unknown property string>(16) not supported by 
device
HIGHGUI ERROR: V4L2: Unable to get property <unknown property string>(5) - 
Invalid argument
HIGHGUI ERROR: V4L2: Unable to get property <unknown property string>(5) - 
Invalid argument
framerate = -1.0
Output #0, mp4, to 'output.mp4':
    Stream #0:0: Video: mpeg4, yuv422p9le, 640x480, q=2-31, 10485 kb/s, 30 tbc
[mpeg4 @ 0x7f65d8312720] Specified pixel format yuv422p9le is invalid or not 
supported
Exception in thread "main" org.bytedeco.javacv.FrameRecorder$Exception: 
avcodec_open2() error -22: Could not open video codec.
    at org.bytedeco.javacv.FFmpegFrameRecorder.startUnsafe(FFmpegFrameRecorder.java:495)
    at org.bytedeco.javacv.FFmpegFrameRecorder.start(FFmpegFrameRecorder.java:268)
    at com.rrdtech.record.Demo.main(Demo.java:32)

I can see  it says pixel format is not correct, how should I determine which 
one to use and also the video codec!

What version of the product are you using? On what operating system?
0.9 of javacv, running ubuntu 12.04, 

Please provide any additional information below.

I have also installed v4l2 and have ffmpeg path set up.

Thanks
Arvind

Original issue reported on code.google.com by dass.arv...@gmail.com on 22 Nov 2014 at 7:31

GoogleCodeExporter commented 8 years ago
Do NOT use AV_PIX_FMT_YUV422P9LE. Instead please try to use AV_PIX_FMT_YUV420P.

And please post your questions on the mailing list next time if possible, thank 
you.

Original comment by samuel.a...@gmail.com on 23 Nov 2014 at 1:28

GoogleCodeExporter commented 8 years ago
Hi Samual

Alright,I will make sure I use mailing list from now onwards . 
AV_PIX_FMT_YUV420P did the trick . Looks like I need to go back to basics . BTW 
recording worked but no sound was there. Any Ideas ?

Thanks
Arvind

Original comment by dass.arv...@gmail.com on 23 Nov 2014 at 7:47

GoogleCodeExporter commented 8 years ago
To get sound, we have to record audio from somewhere. There's a sample for 
Android here for that:
https://github.com/bytedeco/javacv/blob/master/samples/RecordActivity.java
But nothing for Java SE yet. If you'd like to provide a sample that works with 
Java Sound:
https://docs.oracle.com/javase/tutorial/sound/capturing.html
It would be very welcome. Let me know! Thanks

Original comment by samuel.a...@gmail.com on 23 Nov 2014 at 12:47

GoogleCodeExporter commented 8 years ago
There are wonderful people on the internet, I found this recording code . Will 
work more on this, 

package com.volcare.audiosys;

import javax.sound.sampled.*;
import java.io.*;

/**
 * A sample program is to demonstrate how to record sound in Java
 * author: www.codejava.net
 */
public class JavaSoundRecorder {
    // record duration, in milliseconds
    static final long RECORD_TIME = 10000;  // 1 minute

    // path of the wav file
    File wavFile = new File("/home/arvind/RecordAudio.wav");

    // format of audio file
    AudioFileFormat.Type fileType = AudioFileFormat.Type.WAVE;

    // the line from which audio data is captured
    TargetDataLine line;

    /**
     * Defines an audio format
     */
    AudioFormat getAudioFormat() {
        float sampleRate = 16000;
        int sampleSizeInBits = 8;
        int channels = 2;
        boolean signed = true;
        boolean bigEndian = true;
        AudioFormat format = new AudioFormat(sampleRate, sampleSizeInBits,
                                             channels, signed, bigEndian);
        return format;
    }

    /**
     * Captures the sound and record into a WAV file
     */
    void start() {
        try {
            AudioFormat format = getAudioFormat();
            DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);

            // checks if system supports the data line
            if (!AudioSystem.isLineSupported(info)) {
                System.out.println("Line not supported");
                System.exit(0);
            }
            line = (TargetDataLine) AudioSystem.getLine(info);
            line.open(format);
            line.start();   // start capturing

            System.out.println("Start capturing...");

            AudioInputStream ais = new AudioInputStream(line);

            System.out.println("Start recording...");

            // start recording
            AudioSystem.write(ais, fileType, wavFile);

        } catch (LineUnavailableException ex) {
            ex.printStackTrace();
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
    }

    /**
     * Closes the target data line to finish capturing and recording
     */
    void finish() {
        line.stop();
        line.close();
        System.out.println("Finished");
    }

    /**
     * Entry to run the program
     */
    public static void main(String[] args) {
        final JavaSoundRecorder recorder = new JavaSoundRecorder();

        // creates a new thread that waits for a specified
        // of time before stopping
        Thread stopper = new Thread(new Runnable() {
            public void run() {
                try {
                    Thread.sleep(RECORD_TIME);
                } catch (InterruptedException ex) {
                    ex.printStackTrace();
                }
                recorder.finish();
            }
        });

        stopper.start();

        // start recording
        recorder.start();
    }
}

Original comment by dass.arv...@gmail.com on 24 Nov 2014 at 12:48