【发布时间】:2020-05-30 01:07:36
【问题描述】:
我正面临当前的问题。 我有一个包含 100 个位图的数组。这些是我从视图中截取的屏幕截图。 我使用 JCodec 制作视频,但速度很慢。我希望用 FFmpeg 得到更好的结果
现在我想使用 FFmpeg 库。有人问了类似的问题,但我不知道如何使用 ffmpeg 以及如何在我的特定情况下使用它。我所看到的都是奇怪的复杂命令,请参阅:
File dir = your directory where image stores;
String filePrefix = "picture"; //imagename prefix
String fileExtn = ".jpg";//image extention
filePath = dir.getAbsolutePath();
File src = new File(dir, filePrefix + "%03d" + fileExtn);// image name should ne picture001, picture002,picture003 soon ffmpeg takes as input valid
complexCommand = new String[]{"-i", src + "", "-c:v", "libx264", "-c:a", "aac", "-vf", "setpts= 2*PTS”、“-pix_fmt”、“yuv420p”、“-crf”、“10”、“-r”、“15”、“-shortest”、“-y”、“/storage/emulated/0/ " + app_name + "/Video/" + app_name + "_Video" + number + ".mp4"};
问题是,在这种情况下,他使用的是路径。我需要它来自一个数组。而且我不知道如何处理字符串(ComplexCommands):/ 我的位图是这样的:
位图[]位图=新位图[100];
这是稍后填写的。
如果有人正在搜索如何使用 JCodec:
try {
out = NIOUtils.writableFileChannel( Environment.getExternalStorageDirectory().getAbsolutePath()+"/***yourpath***/output"+System.currentTimeMillis()+".mp4");
// for Android use: AndroidSequenceEncoder
AndroidSequenceEncoder encoder = new AndroidSequenceEncoder(out, Rational.R(25, 1));
for (int i = 0 ; i < 100 ; i++) {
// Generate the image, for Android use Bitmap
// Encode the image
System.out.println("LOO2P"+i);
encoder.encodeImage(bitmaps[i]);
}
// Finalize the encoding, i.e. clear the buffers, write the header, etc.
encoder.finish();
} catch (FileNotFoundException e) {
System.out.println("fNF");
e.printStackTrace();
} catch (IOException e) {
System.out.println("IOE");
e.printStackTrace();
} finally {
System.out.println("IOSSE");
NIOUtils.closeQuietly(out);
}
【问题讨论】:
标签: android arrays video ffmpeg bitmap