sawpawan / javacv

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

Conversion of audio in FFMpegFrameGrabber #316

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
- Calling to setSampleFormat won't convert FLT/FLTP to Short/Byte

What is the expected output? What do you see instead?
- Sample format is not converted

What version of the product are you using? On what operating system?
- Android, JavaCV 0.5

Please provide any additional information below.

Original issue reported on code.google.com by klomm...@gmail.com on 9 May 2013 at 3:11

GoogleCodeExporter commented 8 years ago
Yes, that's right, it's not supported yet. If you have some changes to 
contribute, please attach them here for review! Thanks

Original comment by samuel.a...@gmail.com on 10 May 2013 at 7:51

GoogleCodeExporter commented 8 years ago
BTW, FFmpegFrameRecorder does support audio conversion, so it should be 
possible to refer to it and do something similar in FFMpegFrameGrabber.

Original comment by samuel.a...@gmail.com on 11 May 2013 at 9:50

GoogleCodeExporter commented 8 years ago
I am going to upload the changes i've made to FFMpegFrameGrabber once i have it 
sorted.

Thanks

Original comment by klomm...@gmail.com on 19 May 2013 at 4:27

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Hi, I'm facing the same problem. Could anyone provide the fix of 
FFMpegFrameGrabber?
I really need it asap.

Thanks

Original comment by trieutri...@gmail.com on 20 Jul 2013 at 4:05

GoogleCodeExporter commented 8 years ago
Hi, I'm desperate, I do not get sound on this file to sound good. The ringing 
sound is full of noise. Can someone help me out? or show me how I do it? Thank 
you very much.

       FFmpegFrameGrabber grabber = new FFmpegFrameGrabber("c:\\com4j\\video.avi");
        //    Stream #0:1: Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, stereo, fltp, 192 kb/s
        grabber.setSampleFormat(avcodec.AV_CODEC_ID_AC3);
        grabber.start();
        CanvasFrame cff = new CanvasFrame("Playing");

        System.out.println("Caneles de audio: " +grabber.getAudioChannels());
        System.out.println("Samplerate: " +grabber.getSampleRate());
        System.out.println("getSampleFormat: " +grabber.getSampleFormat());
        //AudioFormat audioFormat = new AudioFormat(grabber.getSampleRate(), 192, grabber.getAudioChannels(), true, false);
        AudioFormat audioFormat = new AudioFormat(grabber.getSampleRate(), 16, grabber.getAudioChannels(), true, true);

        DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat);
        SourceDataLine soundLine = (SourceDataLine) AudioSystem.getLine(info);
        soundLine.open(audioFormat);
        soundLine.start();

        while(true) {
            Frame frame = grabber.grabFrame();

            if(frame != null) {
                if(frame.image != null) {
                    cff.showImage(frame.image);
                }
                else if(frame.samples != null) {

                    FloatBuffer baSamples = (FloatBuffer) frame.samples[0];
                    //ByteBuffer byteBuffer = ByteBuffer.allocate(baSamples.capacity() * 4);

                    byte[] output = new byte[baSamples.capacity() * 4];
                    ByteBuffer.wrap(output).asFloatBuffer().put(baSamples);

                    soundLine.write(output, 0, output.length);

                }

            }
            else {
                break;
            }
        } 

Original comment by rafaaran...@gmail.com on 30 Mar 2014 at 1:24