Audio and video recording - solution mostly complete...

1,285 views
Skip to first unread message

EdS

unread,
Nov 18, 2013, 11:14:57 PM11/18/13
to xuggle...@googlegroups.com
I would like to record video and audio together and have got much of the way there but there's an issue with the audio playing before the video and possibly not the same length...

I have a feeling my problem is the length of the audio samples but i'm not sure how best to fix it; please could you help? Code:


import com.github.sarxos.webcam.Webcam;
import com.github.sarxos.webcam.WebcamResolution;
import com.xuggle.ferry.IBuffer;
import java.awt.Dimension;
import java.awt.image.BufferedImage;
import java.io.File;

import com.xuggle.mediatool.IMediaWriter;
import com.xuggle.mediatool.MediaListenerAdapter;
import com.xuggle.mediatool.ToolFactory;
import com.xuggle.mediatool.event.IAddStreamEvent;
import com.xuggle.xuggler.IAudioSamples;
import com.xuggle.xuggler.IAudioSamples.Format;
import com.xuggle.xuggler.ICodec;
import com.xuggle.xuggler.IContainer;
import com.xuggle.xuggler.IPixelFormat;
import com.xuggle.xuggler.IRational;
import com.xuggle.xuggler.IStream;
import com.xuggle.xuggler.IStreamCoder;
import com.xuggle.xuggler.IVideoPicture;
import com.xuggle.xuggler.TestAudioSamplesGenerator;
import com.xuggle.xuggler.io.XugglerIO;
import com.xuggle.xuggler.video.ConverterFactory;
import com.xuggle.xuggler.video.IConverter;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.util.List;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.TargetDataLine;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;


public class Encoder {
public static int audioTime = 0;
public static long start = System.currentTimeMillis();
public static IMediaWriter writer;

public static void main(String[] args) throws Throwable {
JFrame window = new JFrame("vid");
window.setVisible(true);

File file = new File("output.mov");

List<Webcam> list = Webcam.getWebcams();

for (int i = 0; i < list.size(); i++) {
try {
Webcam cam = list.get(i);
System.out.println("Found this Camera : "+cam.getName());
BufferedImage image = cam.getImage();
} catch (Exception e) {
System.out.println("Exception in cam : " + i);
}
}


writer = ToolFactory.makeWriter(file.getName());
Dimension size = WebcamResolution.QVGA.getSize();

Webcam webcam = Webcam.getDefault();
webcam.setViewSize(size);
webcam.open(true);

writer.addVideoStream(0, 0, ICodec.ID.CODEC_ID_H264, size.width, size.height);
writer.addAudioStream(1, 0, ICodec.ID.CODEC_ID_AAC, 2, 44100);


long time = (System.currentTimeMillis() - start) * 1000;
for (int i = 0; i < 100; i++) {

System.out.println("Capture frame " + i);

BufferedImage image = ConverterFactory.convertToType(webcam.getImage(), BufferedImage.TYPE_3BYTE_BGR);
IConverter converter = ConverterFactory.createConverter(image, IPixelFormat.Type.YUV420P);

long len = (System.currentTimeMillis() - start) * 1000 - time;
time = (System.currentTimeMillis() - start) * 1000;

IVideoPicture frame = converter.toPicture(image, time);
frame.setKeyFrame(i == 0);
frame.setQuality(0);

writer.encodeVideo(0, frame);


IAudioSamples samples = customAudioStream(len);
writer.encodeAudio(1, samples);


window.setSize(200,200);
window.getContentPane().removeAll();
window.getContentPane().add(new JLabel(new ImageIcon(image)));
window.getContentPane().validate();
window.getContentPane().invalidate();
window.getContentPane().repaint();

// 10 FPS
Thread.sleep(0,500);

}

writer.close();
window.dispose();

System.out.println("Video recorded in file: " + file.getAbsolutePath());
}

public static IAudioSamples customAudioStream(long length){

// audio parameters
int channelCount = 2;
int sampleRate = 44100;
int len = (int)length/1000;

IContainer container = writer.getContainer();
IStream stream = container.getStream(1);
int sampleCount = stream.getStreamCoder().getDefaultAudioFrameSize();

// create a place for audio samples
IAudioSamples samples = IAudioSamples.make(1024*5, channelCount, IAudioSamples.Format.FMT_S16);

TargetDataLine line = null;
AudioFormat audioFormat = new AudioFormat(sampleRate, (int)16, channelCount, true, false);
DataLine.Info info = new DataLine.Info(TargetDataLine.class, audioFormat);
try {
line = (TargetDataLine) AudioSystem.getLine(info);
line.open(audioFormat);
} catch (LineUnavailableException ex) {
System.out.println("ERROR: "+ex.toString());
}

line.start();
byte[] data = new byte[4096*5];
int sz = line.read(data, 0, data.length);

samples.put(data, 0, 0, sz);
audioTime += (sz);

double sAudioTime = (audioTime)/44.1000;

samples.setComplete(true, sz/4, sampleRate, channelCount, Format.FMT_S16, audioTime/4);

System.out.println(len + " : " + sampleCount + " : " + data.length + " : " + sz + " : " + audioTime + " : " + line.available());
return(samples);
}

}


If there's a better way to do this I'm all ears also.
Thanks!
Ed

Message has been deleted
Message has been deleted

Neel

unread,
Nov 19, 2013, 4:06:09 AM11/19/13
to xuggle...@googlegroups.com
Hi,

I have used same code for ip camera.
I am getting following error

"The passed image is of type #1 but is required to be of BufferedImage type #5."

following is my code where i am trying to get the images from camera stream(dis is the stream of my camera,image is the BufferedImage object)

       1      JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(dis);
2 image = decoder.decodeAsBufferedImage();
  3 BufferedImage finalImage = ConverterFactory.convertToType(image, BufferedImage.TYPE_3BYTE_BGR);
       4      IConverter converter = ConverterFactory.createConverter(finalImage, IPixelFormat.Type.YUV420P);
            
             
        5    IVideoPicture frame = converter.toPicture(image, System.nanoTime() - startTime);
        6   frame.setKeyFrame(cnt==0);
        7    frame.setQuality(0);
             
        8    writer.encodeVideo(0, frame);
9  IAudioSamples samples = IPCameraUtility.customAudioStream(len,writer);
      10    writer.encodeAudio(1, samples);

Its showing me error for line no 5.
Please tell me what is wrong.

Thanks,
Neel

EdS

unread,
Nov 20, 2013, 1:31:48 PM11/20/13
to xuggle...@googlegroups.com
try:
IVideoPicture frame = converter.toPicture(finalImage, System.nanoTime() - startTime);
Good luck.

Nilesh Bedade

unread,
Nov 22, 2013, 1:25:24 AM11/22/13
to xuggle...@googlegroups.com
Hi,

My earlier problem is solved.
Thank you for the help.

Now i am getting following error while creating audio samples in method 'customAudioStream()'

"No line matching interface TargetDataLine supporting format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian is supported"

for line 

" line = (TargetDataLine) AudioSystem.getLine(info);"

I have edited and tried  with 8 bit mono audio format,but it still showing the same error.

Thanks,
Neel


--
You received this message because you are subscribed to a topic in the Google Groups "xuggler-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/xuggler-users/lInnch7Q3yI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to xuggler-user...@googlegroups.com.
To post to this group, send email to xuggle...@googlegroups.com.
Visit this group at http://groups.google.com/group/xuggler-users.
For more options, visit https://groups.google.com/groups/opt_out.

Nilesh Bedade

unread,
Nov 26, 2013, 12:47:32 AM11/26/13
to xuggle...@googlegroups.com
Hi David,

The camera is having built in microphone and i want to record the audio from it.
Will the above code work for built in microphone also?

Thanks,
Neel

Yuvraj Kakkar

unread,
Nov 27, 2013, 1:37:59 AM11/27/13
to xuggle...@googlegroups.com
Just try this piece of code. May be this will help you to find better way to carry out your task.

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Calendar;
import java.util.List;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.WindowConstants;
import com.lti.civil.CaptureDeviceInfo;
import com.lti.civil.CaptureException;
import com.lti.civil.CaptureObserver;
import com.lti.civil.CaptureStream;
import com.lti.civil.CaptureSystem;
import com.lti.civil.CaptureSystemFactory;
import com.lti.civil.DefaultCaptureSystemFactorySingleton;
import com.lti.civil.Image;
import com.lti.civil.awt.AWTImageConverter;
import com.sun.media.jai.codecimpl.JPEGCodec;
import com.sun.media.jai.codecimpl.JPEGImageEncoder;


public class TestWebCam implements CaptureObserver{

JButton start = null;
JButton shot = null;
JButton stop = null;
CaptureStream captureStream = null;
boolean takeShot=false;

public TestWebCam() {
CaptureSystemFactory factory = DefaultCaptureSystemFactorySingleton.instance();
CaptureSystem system;
try {
system = factory.createCaptureSystem();
system.init();
List list = system.getCaptureDeviceInfoList();
int i = 0;
if (i < list.size()) {
CaptureDeviceInfo info = (CaptureDeviceInfo) list.get(i);
System.out.println((new StringBuilder()).append("Device ID ").append(i).append(": ").append(info.getDeviceID()).toString());
System.out.println((new StringBuilder()).append("Description ").append(i).append(": ").append(info.getDescription()).toString());
captureStream = system.openCaptureDeviceStream(info.getDeviceID());
captureStream.setObserver(TestWebCam.this);
}
} catch (CaptureException ex) {
ex.printStackTrace();
}
//UI work of the program
JFrame frame = new JFrame();
frame.setSize(7000, 800);
JPanel panel = new JPanel();
frame.setContentPane(panel);
frame.setVisible(true);
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
start = new JButton("Start");
stop = new JButton("Stop");
shot = new JButton("Shot");
panel.add(start);
panel.add(stop);
panel.add(shot);
panel.revalidate();
start.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
captureStream.start();
} catch (CaptureException ex) {
ex.printStackTrace();
}
}
});
stop.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
captureStream.stop();
} catch (CaptureException ex) {
ex.printStackTrace();
}
}
});
shot.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
takeShot=true;
}
});
}


@Override
public void onError(CaptureStream arg0, CaptureException arg1) {
System.out.println("Error");
}

@Override

public void onNewImage(CaptureStream stream, Image image) {
//if(!takeShot) return;
//takeShot=false;
System.out.println("New Image Captured");
byte bytes[] = null;
try {
if (image == null) {
bytes = null;
return;
}
try {
ByteArrayOutputStream os = new ByteArrayOutputStream();
JPEGImageEncoder jpeg = (JPEGImageEncoder) JPEGCodec.createImageEncoder("jpeg",os, null);
jpeg.encode(AWTImageConverter.toBufferedImage(image));
os.close();
bytes = os.toByteArray();
} catch (IOException e) {
e.printStackTrace();
bytes = null;
} catch (Throwable t) {
t.printStackTrace();
bytes = null;
}
if (bytes == null) {
return;
}
ByteArrayInputStream is = new ByteArrayInputStream(bytes);

File file = new File("C:\\Users\\Desktop\\yuvi\\img" + Calendar.getInstance().getTimeInMillis() + ".jpg");
FileOutputStream fos = new FileOutputStream(file);
fos.write(bytes);
fos.close();
BufferedImage myImage = ImageIO.read(file);
shot.setText("");
shot.setIcon(new ImageIcon(myImage));
shot.revalidate();
} catch (IOException ex) {
ex.printStackTrace();
}
}


public static void main(String[] args) {
TestWebCam test = new TestWebCam();
SoundRecorder sr=new SoundRecorder();
sr.start();
}

}

Carlo Politi

unread,
Mar 25, 2014, 2:01:47 PM3/25/14
to xuggle...@googlegroups.com
Hello everybody... maybe i'm opening a closed problem but i cannot solve this problem... I need to capture audio and video from webcam in Java but if i run the source code of EdS, i get this error:

18:50:35.682 [main] INFO com.github.sarxos.webcam.Webcam - WebcamDefaultDriver capture driver will be used
18:50:35.717 [webcam-discovery-service] DEBUG c.g.s.w.d.b.WebcamDefaultDriver - Searching devices
18:50:36.457 [webcam-discovery-service] DEBUG c.g.s.w.d.b.WebcamDefaultDriver - Found device ASUS USB2.0 Webcam 0
Found this Camera : ASUS USB2.0 Webcam 0
18:50:38.112 [main] DEBUG com.github.sarxos.webcam.Webcam - Setting new resolution 320x240
18:50:38.113 [main] DEBUG com.github.sarxos.webcam.WebcamLock - Lock Webcam ASUS USB2.0 Webcam 0
18:50:38.122 [atomic-processor-1] INFO c.g.s.webcam.ds.cgt.WebcamOpenTask - Opening webcam ASUS USB2.0 Webcam 0
18:50:38.123 [atomic-processor-1] DEBUG c.g.s.w.d.b.WebcamDefaultDevice - Opening webcam device ASUS USB2.0 Webcam 0
18:50:38.123 [atomic-processor-1] DEBUG c.g.s.w.d.b.WebcamDefaultDevice - Webcam device 0 starting session, size java.awt.Dimension[width=320,height=240]
18:50:39.441 [atomic-processor-1] DEBUG c.g.s.w.d.b.WebcamDefaultDevice - Webcam device session started
18:50:39.443 [atomic-processor-1] DEBUG c.g.s.w.d.b.WebcamDefaultDevice - Initialize buffer
18:50:39.473 [webcam-discovery-service] DEBUG c.g.s.w.d.b.WebcamDefaultDriver - Searching devices
18:50:43.074 [atomic-processor-1] DEBUG c.g.s.w.d.b.WebcamDefaultDevice - Webcam device is now open
18:50:43.074 [main] DEBUG com.github.sarxos.webcam.Webcam - Webcam is now open ASUS USB2.0 Webcam 0
18:50:43.091 [webcam-discovery-service] DEBUG c.g.s.w.d.b.WebcamDefaultDriver - Found device ASUS USB2.0 Webcam 0
18:50:43.098 [main] DEBUG c.github.sarxos.webcam.WebcamUpdater - Webcam updater has been started
Capture frame 0
190 : 576 : 20480 : 20480 : 20480 : 23616
Capture frame 1
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
691 : 576 : 20480 : 0 : 20480 : 0
Capture frame 2
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
32 : 576 : 20480 : 0 : 20480 : 0
Capture frame 3
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
40 : 576 : 20480 : 0 : 20480 : 0
Capture frame 4
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
31 : 576 : 20480 : 0 : 20480 : 0
Capture frame 5
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
39 : 576 : 20480 : 0 : 20480 : 0
Capture frame 6
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
41 : 576 : 20480 : 0 : 20480 : 0
Capture frame 7
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
29 : 576 : 20480 : 0 : 20480 : 0
Capture frame 8
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
34 : 576 : 20480 : 0 : 20480 : 0
Capture frame 9
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
30 : 576 : 20480 : 0 : 20480 : 0
Capture frame 10
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
29 : 576 : 20480 : 0 : 20480 : 0
Capture frame 11
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
27 : 576 : 20480 : 0 : 20480 : 0
Capture frame 12
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
29 : 576 : 20480 : 0 : 20480 : 0
Capture frame 13
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
34 : 576 : 20480 : 0 : 20480 : 0
Capture frame 14
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
30 : 576 : 20480 : 0 : 20480 : 0
Capture frame 15
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
33 : 576 : 20480 : 0 : 20480 : 0
Capture frame 16
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
31 : 576 : 20480 : 0 : 20480 : 0
Capture frame 17
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
28 : 576 : 20480 : 0 : 20480 : 0
Capture frame 18
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
27 : 576 : 20480 : 0 : 20480 : 0
Capture frame 19
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
28 : 576 : 20480 : 0 : 20480 : 0
Capture frame 20
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
28 : 576 : 20480 : 0 : 20480 : 0
Capture frame 21
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
28 : 576 : 20480 : 0 : 20480 : 0
Capture frame 22
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
30 : 576 : 20480 : 0 : 20480 : 0
Capture frame 23
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
28 : 576 : 20480 : 0 : 20480 : 0
Capture frame 24
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
26 : 576 : 20480 : 0 : 20480 : 0
Capture frame 25
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
27 : 576 : 20480 : 0 : 20480 : 0
Capture frame 26
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
29 : 576 : 20480 : 0 : 20480 : 0
Capture frame 27
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
28 : 576 : 20480 : 0 : 20480 : 0
Capture frame 28
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
27 : 576 : 20480 : 0 : 20480 : 0
Capture frame 29
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
27 : 576 : 20480 : 0 : 20480 : 0
Capture frame 30
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
27 : 576 : 20480 : 0 : 20480 : 0
Capture frame 31
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
27 : 576 : 20480 : 0 : 20480 : 0
Capture frame 32
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
28 : 576 : 20480 : 0 : 20480 : 0
Capture frame 33
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
26 : 576 : 20480 : 0 : 20480 : 0
Capture frame 34
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
26 : 576 : 20480 : 0 : 20480 : 0
Capture frame 35
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
25 : 576 : 20480 : 0 : 20480 : 0
Capture frame 36
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
26 : 576 : 20480 : 0 : 20480 : 0
Capture frame 37
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
28 : 576 : 20480 : 0 : 20480 : 0
Capture frame 38
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
29 : 576 : 20480 : 0 : 20480 : 0
Capture frame 39
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
28 : 576 : 20480 : 0 : 20480 : 0
Capture frame 40
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
27 : 576 : 20480 : 0 : 20480 : 0
Capture frame 41
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
28 : 576 : 20480 : 0 : 20480 : 0
Capture frame 42
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
33 : 576 : 20480 : 0 : 20480 : 0
Capture frame 43
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
29 : 576 : 20480 : 0 : 20480 : 0
Capture frame 44
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
28 : 576 : 20480 : 0 : 20480 : 0
Capture frame 45
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
29 : 576 : 20480 : 0 : 20480 : 0
Capture frame 46
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
31 : 576 : 20480 : 0 : 20480 : 0
Capture frame 47
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
28 : 576 : 20480 : 0 : 20480 : 0
Capture frame 48
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
33 : 576 : 20480 : 0 : 20480 : 0
Capture frame 49
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
38 : 576 : 20480 : 0 : 20480 : 0
Capture frame 50
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
27 : 576 : 20480 : 0 : 20480 : 0
Capture frame 51
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
27 : 576 : 20480 : 0 : 20480 : 0
Capture frame 52
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
28 : 576 : 20480 : 0 : 20480 : 0
Capture frame 53
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
32 : 576 : 20480 : 0 : 20480 : 0
Capture frame 54
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
29 : 576 : 20480 : 0 : 20480 : 0
Capture frame 55
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
23 : 576 : 20480 : 0 : 20480 : 0
Capture frame 56
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
24 : 576 : 20480 : 0 : 20480 : 0
Capture frame 57
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
23 : 576 : 20480 : 0 : 20480 : 0
Capture frame 58
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
23 : 576 : 20480 : 0 : 20480 : 0
Capture frame 59
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
22 : 576 : 20480 : 0 : 20480 : 0
Capture frame 60
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
30 : 576 : 20480 : 0 : 20480 : 0
Capture frame 61
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
22 : 576 : 20480 : 0 : 20480 : 0
Capture frame 62
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
22 : 576 : 20480 : 0 : 20480 : 0
Capture frame 63
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
23 : 576 : 20480 : 0 : 20480 : 0
Capture frame 64
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
28 : 576 : 20480 : 0 : 20480 : 0
Capture frame 65
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
23 : 576 : 20480 : 0 : 20480 : 0
Capture frame 66
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
21 : 576 : 20480 : 0 : 20480 : 0
Capture frame 67
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
22 : 576 : 20480 : 0 : 20480 : 0
Capture frame 68
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
21 : 576 : 20480 : 0 : 20480 : 0
Capture frame 69
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
23 : 576 : 20480 : 0 : 20480 : 0
Capture frame 70
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
21 : 576 : 20480 : 0 : 20480 : 0
Capture frame 71
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
22 : 576 : 20480 : 0 : 20480 : 0
Capture frame 72
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
21 : 576 : 20480 : 0 : 20480 : 0
Capture frame 73
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
21 : 576 : 20480 : 0 : 20480 : 0
Capture frame 74
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
21 : 576 : 20480 : 0 : 20480 : 0
Capture frame 75
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
21 : 576 : 20480 : 0 : 20480 : 0
Capture frame 76
18:50:46.092 [webcam-discovery-service] DEBUG c.g.s.w.d.b.WebcamDefaultDriver - Searching devices
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
20 : 576 : 20480 : 0 : 20480 : 0
Capture frame 77
18:50:46.117 [webcam-discovery-service] DEBUG c.g.s.w.d.b.WebcamDefaultDriver - Found device ASUS USB2.0 Webcam 0
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
24 : 576 : 20480 : 0 : 20480 : 0
Capture frame 78
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
22 : 576 : 20480 : 0 : 20480 : 0
Capture frame 79
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
22 : 576 : 20480 : 0 : 20480 : 0
Capture frame 80
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
22 : 576 : 20480 : 0 : 20480 : 0
Capture frame 81
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
23 : 576 : 20480 : 0 : 20480 : 0
Capture frame 82
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
23 : 576 : 20480 : 0 : 20480 : 0
Capture frame 83
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
27 : 576 : 20480 : 0 : 20480 : 0
Capture frame 84
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
26 : 576 : 20480 : 0 : 20480 : 0
Capture frame 85
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
31 : 576 : 20480 : 0 : 20480 : 0
Capture frame 86
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
27 : 576 : 20480 : 0 : 20480 : 0
Capture frame 87
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
21 : 576 : 20480 : 0 : 20480 : 0
Capture frame 88
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
21 : 576 : 20480 : 0 : 20480 : 0
Capture frame 89
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
20 : 576 : 20480 : 0 : 20480 : 0
Capture frame 90
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
17 : 576 : 20480 : 0 : 20480 : 0
Capture frame 91
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
18 : 576 : 20480 : 0 : 20480 : 0
Capture frame 92
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
18 : 576 : 20480 : 0 : 20480 : 0
Capture frame 93
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
18 : 576 : 20480 : 0 : 20480 : 0
Capture frame 94
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
17 : 576 : 20480 : 0 : 20480 : 0
Capture frame 95
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
17 : 576 : 20480 : 0 : 20480 : 0
Capture frame 96
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
17 : 576 : 20480 : 0 : 20480 : 0
Capture frame 97
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
18 : 576 : 20480 : 0 : 20480 : 0
Capture frame 98
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
21 : 576 : 20480 : 0 : 20480 : 0
Capture frame 99
ERROR: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
19 : 576 : 20480 : 0 : 20480 : 0
Video recorded in file: C:\Users\Carlo\Documents\NetBeansProjects\recordvideo\output.mov
18:50:48.069 [shutdown-hook-1] INFO c.g.sarxos.webcam.WebcamShutdownHook - Automatic ASUS USB2.0 Webcam 0 deallocation
18:50:48.069 [shutdown-hook-1] INFO com.github.sarxos.webcam.Webcam - Disposing webcam ASUS USB2.0 Webcam 0
18:50:48.085 [atomic-processor-1] DEBUG c.g.s.w.d.b.WebcamDefaultDevice - Disposing webcam device ASUS USB2.0 Webcam 0
18:50:48.085 [atomic-processor-1] DEBUG c.g.s.w.d.b.WebcamDefaultDevice - Closing webcam device
18:50:48.246 [shutdown-hook-1] DEBUG com.github.sarxos.webcam.Webcam - Webcam disposed ASUS USB2.0 Webcam 0


I'm running Windows 7 Pro with Java 7, using the following JAR in my project (and no MAVEN):

bridj-0.7-20131007.003529-54.jar
logback-classic-1.1.1.jar
logback-core-1.1.1.jar
slf4j-api-1.7.6.jar
webcam-capture-0.3.10-RC6.jar
xuggle-xuggler-5.4.jar

Thanks...

Michael Jordan

unread,
Mar 26, 2014, 3:56:11 PM3/26/14
to xuggle...@googlegroups.com
Somewhere or other there's a way to print out what formats the targetdataline supports. I would try starting with that. Most likely you're reading either in the wrong format or from the wrong line.



--
You received this message because you are subscribed to the Google Groups "xuggler-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xuggler-user...@googlegroups.com.

To post to this group, send email to xuggle...@googlegroups.com.
Visit this group at http://groups.google.com/group/xuggler-users.
For more options, visit https://groups.google.com/d/optout.

Arafat Hossain

unread,
Jan 30, 2017, 12:35:01 PM1/30/17
to xuggler-users
Please refers the below code. I think it will work properly.


   
public static int record_time = 10; // recording time is 10s
   
public static int fps = 30;
   
   
public static final int CHANNEL_COUNT = 2;
   
public static final int SAMPLE_RATE = 44100;

   
private static final Format soundFormat = Format.FMT_S16;
   
private static final int BYTE_DEPTH = soundFormat.swigValue() + 1;
   
private static final int BIT_DEPTH = 8 * BYTE_DEPTH;

   
private static int audioTime = 0;
   
private static TargetDataLine audioLine = null;
   
private static AudioFormat audioFormat = null;

   
   
public static void main(String[] args) throws Throwable {
       
JFrame window = new JFrame("vid");
        window
.setVisible(true);

       
File file = new File("output.mov");

       
List<Webcam> list = Webcam.getWebcams();

       
for (int i = 0; i < list.size(); i++) {
               
try {
                   
Webcam cam = list.get(i);
                   
System.out.println("Found this Camera : "+cam.getName());
                   
BufferedImage image = cam.getImage();
               
} catch (Exception e) {
                   
System.out.println("Exception in cam : " + i);
               
}
       
}
       
       
        writer
= ToolFactory.makeWriter(file.getName());            
       
Dimension size = WebcamResolution.QVGA.getSize();

       
Webcam webcam = Webcam.getDefault();
        webcam
.setViewSize(size);
        webcam
.open(true);

        writer
.addVideoStream(0, 0, ICodec.ID.CODEC_ID_H264, size.width, size.height);
        writer
.addAudioStream(1, 0, ICodec.ID.CODEC_ID_AAC, 2, 44100);
       
       
long time = (System.currentTimeMillis() - start) * 1000;

       
        openAudioRecorder
();

       
       
for (int i = 0; i < 100; i++) {
           
System.out.println("Capture frame " + i);
               
           
BufferedImage image = ConverterFactory.convertToType(webcam.getImage(), BufferedImage.TYPE_3BYTE_BGR);
           
IConverter converter = ConverterFactory.createConverter(image, IPixelFormat.Type.YUV420P);

       
           
IVideoPicture frame = converter.toPicture(image, (System.currentTimeMillis() - start) * 1000);

            frame
.setKeyFrame(i == 0);
            frame
.setQuality(0);

            writer
.encodeVideo(0, frame);

           
            writer
.encodeAudio(1, getAudioSamples(fps));


                               
            window
.setSize(200,200);
            window
.getContentPane().removeAll();
            window
.getContentPane().add(new JLabel(new ImageIcon(image)));
            window
.getContentPane().validate();
            window
.getContentPane().invalidate();
            window
.getContentPane().repaint();
       
}


        closeAudioRecorder
();

       
        writer
.close();
        window
.dispose();

       
System.out.println("Video recorded in file: " + file.getAbsolutePath());
   
}


   
private static AudioFormat getAudioFormat() {
       
if (audioFormat == null) {
            audioFormat
= new AudioFormat(SAMPLE_RATE, BIT_DEPTH, CHANNEL_COUNT, true, false);
       
}

       
return audioFormat;
   
}

   
public static void openAudioRecorder() throws LineUnavailableException {
       
DataLine.Info info = new DataLine.Info(TargetDataLine.class, getAudioFormat());

        audioLine
= (TargetDataLine) AudioSystem.getLine(info);
        audioLine
.open(getAudioFormat());

        audioTime
= 0;
   
}

   
public static IAudioSamples getAudioSamples(int fps) {
       
if (fps <= 0)
            fps
= 1;

       
IAudioSamples samples = IAudioSamples.make(SAMPLE_RATE / fps, CHANNEL_COUNT, soundFormat);

        audioLine
.start();
       
byte[] data = new byte[(SAMPLE_RATE * BYTE_DEPTH * CHANNEL_COUNT) / fps];
       
int sz = audioLine.read(data, 0, data.length);


        samples
.put(data, 0, 0, sz);
        audioTime
+= (sz);


        samples
.setComplete(true, sz / (BYTE_DEPTH * CHANNEL_COUNT), SAMPLE_RATE, CHANNEL_COUNT, soundFormat,
                audioTime
/ (BYTE_DEPTH * CHANNEL_COUNT));

       
return samples;
   
}

   
public static void closeAudioRecorder() {
       
if (audioLine != null) {
            audioLine
.close();
            audioLine
= null;
       
}
   
}
}

Reply all
Reply to author
Forward
0 new messages