使用FFmpegFrameRecorder合并音频文件

时间:2015-06-01 12:28:40

标签: android audio ffmpeg

我已经使用ffmpegframerecorder成功合并(不连接)两个.aac音频文件,但输出文件非常慢。 以下是我使用过的代码。 有什么我可以用来加速输出音频文件。它与帧速率有关吗?

FFmpegFrameGrabber frameGrabber =
                new FFmpegFrameGrabber("storage/sdcard0/Audio/audio.aac");      
        f=new File("/storage/sdcard0/Audio/audnew.aac");
        try {
            f.createNewFile();
        } catch (IOException e2) {
            // TODO Auto-generated catch block
            Log.d("def",e2.getLocalizedMessage());
        }
       FFmpegFrameGrabber grabber1 = new FFmpegFrameGrabber("/storage/sdcard0/Audio/smoke.aac");
        try {
            frameGrabber.start();
            grabber1.start();
        } catch (org.bytedeco.javacv.FrameGrabber.Exception e1) {
            // TODO Auto-generated catch block
            Log.d("here",e1.getLocalizedMessage());
        } 
        FFmpegFrameRecorder recorde = new FFmpegFrameRecorder(f, frameGrabber.getAudioChannels());
        try {
            recorde.setAudioCodec(AV_CODEC_ID_AAC);
            Log.d("12","here");
            recorde.setFrameRate(12);
            recorde.start();
            Frame frame1 = new Frame();
            Frame frame2 = new Frame();
            for (int i=0;i<1000000;i++)
            {
                frame1 = grabber1.grabFrame();
                frame2 = frameGrabber.grabFrame();
                if (frame1==null || frame2==null) {
                    Log.d("er","Failed cvQueryFrame");
                    frameGrabber.release();
                    grabber1.release();
                    break;
                }
                recorde.record(frame1);
                recorde.record(frame2);

            }
            recorde.stop();
            grabber1.stop();

        }catch(Exception e){
            Log.d("abc", e.getLocalizedMessage());
        }

1 个答案:

答案 0 :(得分:0)

frame frame1,frame2 = null;

            while ((frame1 = grabber1.grabFrame()) != null ||
                    (frame2 = grabber2.grabFrame()) != null) {

                recorder.record(frame1);
                recorder.record(frame2);

            }

使用它代替For Loop