我的ffmpeg for android studio是用这个编译的:
编译'com.writingminds:FFmpegAndroid:0.3.2'
在下面的代码中,我有这行代码:
String [] complexCommand = {“ - i”,yourRealPath,“ - c:v”,“libx264”, “-crf”,“22”,“ - map”,“0”,“ - segment_time”,“6”,“ - g”,“9”, “-sc_threshold”,“0”,“ - force_key_frames”,“expr:gte(t,n_forced * 6)”, “-f”,“segment”,dest.getAbsolutePath()};
我想知道的事情:
这是我的代码:
/**
* Command for extracting images from video
*/
private void extractImagesVideo(int startMs, int endMs) {
File moviesDir = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES
);
String filePrefix = "extract_picture";
String fileExtn = ".jpg";
String yourRealPath = getPath(MainActivity.this, selectedVideoUri);
File dir = new File(moviesDir, "VideoEditor");
int fileNo = 0;
while (dir.exists()) {
fileNo++;
dir = new File(moviesDir, "VideoEditor" + fileNo);
}
dir.mkdir();
filePath = dir.getAbsolutePath();
File dest = new File(dir, filePrefix + "%03d" + fileExtn);
Log.d(TAG, "startTrim: src: " + yourRealPath);
Log.d(TAG, "startTrim: dest: " + dest.getAbsolutePath());
String[] complexCommand = {"-y", "-i", yourRealPath, "-an", "-r", "1/2", "-ss", "" + startMs / 1000, "-t", "" + (endMs - startMs) / 1000, dest.getAbsolutePath()};
execFFmpegBinary(complexCommand);
}
/**
* Executing ffmpeg binary
*/
private void execFFmpegBinary(final String[] command) {
try {
ffmpeg.execute(command, new ExecuteBinaryResponseHandler() {
@Override
public void onFailure(String s) {
Log.d(TAG, "FAILED with output : " + s);
}
@Override
public void onSuccess(String s) {
Log.d(TAG, "SUCCESS with output : " + s);
if (choice == 1 || choice == 2 || choice == 5 || choice == 6 || choice == 7) {
Intent intent = new Intent(MainActivity.this, PreviewActivity.class);
intent.putExtra(FILEPATH, filePath);
startActivity(intent);
} else if (choice == 3) {
Intent intent = new Intent(MainActivity.this, PreviewImageActivity.class);
intent.putExtra(FILEPATH, filePath);
startActivity(intent);
} else if (choice == 4) {
Intent intent = new Intent(MainActivity.this, AudioPreviewActivity.class);
intent.putExtra(FILEPATH, filePath);
startActivity(intent);
} else if (choice == 8) {
choice = 9;
reverseVideoCommand();
} else if (Arrays.equals(command, lastReverseCommand)) {
choice = 10;
concatVideoCommand();
} else if (choice == 10) {
File moviesDir = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_MOVIES
);
File destDir = new File(moviesDir, ".VideoPartsReverse");
File dir = new File(moviesDir, ".VideoSplit");
if (dir.exists())
deleteDir(dir);
if (destDir.exists())
deleteDir(destDir);
choice = 11;
Intent intent = new Intent(MainActivity.this, PreviewActivity.class);
intent.putExtra(FILEPATH, filePath);
startActivity(intent);
}
}
从以下网址下载代码:
答案 0 :(得分:1)
<强> 1 强>
-sc_threshold:场景变化灵敏度(范围在0 - 100之间)。在每次场景变换时,都会插入一个新的I帧。
-g:是GOP(图片组)。帧长度间隔。 GOP确定I帧之间的最大距离。额外提示:高GOP 使视频非常有效压缩。推荐值为250
-crf:恒定速率因子(CRF)定义平均期望质量而不是目标比特率。
<强> 2 强>
是的,可以使用FFMPEG库获取目前在视频容器中记录的每个帧。
Bonus:ffmpeg -i video.avi IMG%03d.jpg
- 用于获取每个帧并将其转换为jpg图像文件并将其存储在同一位置的示例命令。