我想通过使用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环境null,目录null错误....
答案 0 :(得分: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();
}