1

我想通过使用ffmpeg将图像序列转换为android sdcard中的视频...如何在android中使用该波纹管... ffmpeg -f image2 -i img%4d.png video.mp4。

我试试这一行 File dir = new File("/mnt/sdcard");

           // create a process and execute notepad.exe and currect environment

          try {

            Process p = Runtime.getRuntime().exec("ffmpeg -f image2 -i img%4d.png video_test.mp4",null,dir);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }   

但我得到 java.io.ioexception environment null,directory null error....

4

1 回答 1

0

它工作了一个 android javacv/opencv.so 试试这个代码,

              String path =SCREENSHOT_FOLDER2; 

            File folder = new File(path);


                listOfFiles = folder.listFiles();  
                if(listOfFiles.length>0)
                {









              iplimage = new opencv_core.IplImage[listOfFiles.length];


               for (int j = 0; j < listOfFiles.length; j++) {

                 String files="";       

               if (listOfFiles[j].isFile()) 
               {
               files = listOfFiles[j].getName();

                 }   


                String[] tokens = files.split("\\.(?=[^\\.]+$)");
               String name=tokens[0]; 

                System.out.println(" j " + name);




              iplimage[j]=cvLoadImage("/mnt/sdcard/images/"+name+".png");


               }

            } 



                File videopath = new File(SCREENSHOT_FOLDER3);
                videopath.mkdirs();
                 newFFmpegFrameRecord recorder = new newFFmpegFrameRecord(SCREENSHOT_FOLDER3+"video"+System.currentTimeMillis()+".mp4",320,480);

                 try {
                     recorder.setCodecID(CODEC_ID_MPEG4); //CODEC_ID_MPEG4       
                     //CODEC_ID_MPEG1VIDEO
                     recorder.setBitrate(sampleVideoBitRate);
                     recorder.setFrameRate(10);                     
                     recorder.setPixelFormat(PIX_FMT_YUV420P); //PIX_FMT_YUV420P


                     recorder.start();

                     int x = 0;
                     int y = 0;
                    for (int i=0;i< 300 && x<iplimage.length;i++)

                       {

                         recorder.record(image[x]);

                        if (i>(y+10)) {
                            y=y+1;
                            x++;
                        }

                        }
                     recorder.stop();
                    }
                 catch (Exception e){
                     e.printStackTrace();
                   }
于 2012-12-07T09:56:42.260 回答