keke77 / javacv

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

Merge video and audio gives strange result #393

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Run the provided code
2.
3.

What is the expected output? What do you see instead?
Merge of video and audio without breaking the audio

What version of the product are you using? On what operating system?
Latest, android 4.3

Please provide any additional information below.
I'm trying to merge a video and audio file. It works ..almost. 
The resulting video get some strange distorsion. Listen 2 secs in _m.mp4 and 
you'll know what I mean. What's going on here? I've tried several audio and 
video files and I always get the same result. 

        FrameGrabber videoFrames = new FFmpegFrameGrabber(Environment.getExternalStorageDirectory() + "/Untitled-1.mp4");
        FrameGrabber audioFrames = new FFmpegFrameGrabber(Environment.getExternalStorageDirectory() + "/file5.wav");

        videoFrames.start();
        audioFrames.start();

        FrameRecorder recorder = new FFmpegFrameRecorder(Environment.getExternalStorageDirectory() + "/_m.mp4",
                videoFrames.getImageWidth(), videoFrames.getImageHeight(),
                audioFrames.getAudioChannels());

        recorder.setFrameRate(videoFrames.getFrameRate());
        recorder.setSampleRate(audioFrames.getSampleRate());
        recorder.setFormat("mp4");
        recorder.start();

        Frame frameVideo, frameAudio;

        while(true)
        {

            frameVideo = videoFrames.grabFrame();
            frameAudio = audioFrames.grabFrame();

            if(frameVideo == null || frameAudio == null) break;

            recorder.record(frameVideo);

            recorder.record(frameAudio);
        }

        recorder.stop();
        videoFrames.stop();
        audioFrames.stop();

Original issue reported on code.google.com by jo...@sparklingzoo.se on 9 Dec 2013 at 10:01

Attachments:

GoogleCodeExporter commented 9 years ago
Here's the merge. 

Original comment by jo...@sparklingzoo.se on 9 Dec 2013 at 10:04

Attachments:

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I opened the original wav and the mp4 in Audacity and check this out. What am I 
doing wrong here?

Original comment by jo...@sparklingzoo.se on 9 Dec 2013 at 10:30

Attachments:

GoogleCodeExporter commented 9 years ago
The problem is that Untitled-1.mp4 also contains audio frames. Since it's 
mostly silence though we can easily fix that by ignoring them, with a condition 
like this: 
    if (frameVideo.image != null)
        recorder.record(frameVideo);

So, it's not an issue with JavaCV... Please post your questions on the mailing 
list next time if possible, thanks!

Original comment by samuel.a...@gmail.com on 15 Dec 2013 at 6:41