结合了图像转换成音频文件,并在Android的视频文件编程 [英] Combine an image into audio file and make a video file in android programmatically

查看:153
本文介绍了结合了图像转换成音频文件,并在Android的视频文件编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读的ffmpeg libray的教程为音频file.but较为复杂,收到错误的环境价值null.I用Google搜索了很多,但没有找到任何解决办法。图像结合

I read the tutorial of ffmpeg libray to combine the image into audio file.but is more complex and getting error environment value is null.I googled a lot but didn't found any solution.

有没有办法在Android中,我们可以合并在音频文件的图像,使视频文件。

Is there any way in android we can merge an image in audio file and make a video file.

在此先感谢....

推荐答案

我没有编译FFMPEG,只是我用 javacv为安卓并解决了我的问题,结合音频和图像,并使其为视频文件。 脚步: 首先按照此处提供的步骤,然后将下面的code。在您的活动,并确保更改输入文件和输出文件的路径。

I didnt compiled FFMPEG, simply I used javacv for android and resolved my problem to combine audio and image and make it as video file. Steps: First Follow the steps provided here and then place the below code in your activity and make sure that to change the path of input files and output file.

 new AsyncTask<Void, Void, Void>() {
            ProgressDialog dialog;
            FFmpegFrameRecorder recorder;
            protected void onPreExecute() {
                dialog = new ProgressDialog(RecordActivity.this);
                dialog.setMessage("Genrating video, Please wait.........");
                dialog.setCancelable(false);
                dialog.show();
            };

            @Override
            protected Void doInBackground(Void... arg0) {

                File folder = Environment.getExternalStorageDirectory();
                String path = folder.getAbsolutePath() + "/DCIM/Camera";
               // ArrayList<String> paths = (ArrayList<String>) getListOfFiles(path, "jpg");
                long millis = System.currentTimeMillis();

                videoPath = path + "/" + "test_sham_"+millis+".3gp";

                try {



                //audio grabber
                FrameGrabber grabber2 = new FFmpegFrameGrabber(folder.getAbsolutePath()+"/Samsung/Music/Over_the_horizon.mp3"); 

                //video grabber
                FrameGrabber grabber1 = new FFmpegFrameGrabber(path+"/20140527_133034.jpg"); 
                    grabber1.start();

                    grabber2.start();

                  recorder = new FFmpegFrameRecorder(path
                          + "/" + "test_sham_"+millis+".3gp",  grabber1.getImageWidth(), grabber1.getImageHeight(),2);

                    //recorder.setVideoCodec(5);
                    recorder.setVideoCodec(avcodec.AV_CODEC_ID_MPEG4);
                     // recorder.setVideoCodec(avcodec.AV_CODEC_ID_MP4ALS);

                    recorder.setFormat("3gp");
                  //  recorder.setFormat("mp4");
                    recorder.setFrameRate(frameRate);
                    recorder.setSampleRate(grabber2.getSampleRate());
                    recorder.setVideoBitrate(30);
                    startTime = System.currentTimeMillis();
                    recorder.start();

                    Frame frame1, frame2 = null; 

                    while ((frame1 = grabber1.grabFrame()) != null || 

                          (frame2 = grabber2.grabFrame()) != null) { 

                        recorder.record(frame1); 

                        recorder.record(frame2); 

                    } 

                    recorder.stop(); 

                    grabber1.stop(); 

                    grabber2.stop(); 




                    System.out.println("Total Time:- " + recorder.getTimestamp());

                } catch (Exception e) {
                    e.printStackTrace();
                }

                return null;
            }

            protected void onPostExecute(Void result) {
                dialog.dismiss();
                Intent intent = new Intent(Intent.ACTION_VIEW); 
                intent.setDataAndType(Uri.parse(videoPath), "video/3gp");
                startActivity(intent);
                Toast.makeText(RecordActivity.this, "Done:::"+videoPath, Toast.LENGTH_SHORT)
                        .show();
            };
        }.execute();

有关引用:<一href="http://stackoverflow.com/questions/23775173/video-creation-with-images-and-audio-in-android">ref1, REF2

这篇关于结合了图像转换成音频文件,并在Android的视频文件编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆