Android FFMPEG:图像到mp4视频转换

时间:2017-07-19 11:16:18

标签: android video ffmpeg

我已经尝试了许多可能的命令行选项与ffmpeg,但是没有让它工作。 Heres是我的命令文件生成器方法:

 private String[] generateCommandFile() {
    ArrayList<String> cmd = new ArrayList<>();

    cmd.add("-y");
    cmd.add("-f");
    cmd.add("concat");
    cmd.add("-safe");
    cmd.add("0");
    cmd.add("-i");
    String picturesTextFile = generateMergingFilesTexts();
    if (picturesTextFile == null) {
        return null;
    }
    cmd.add(picturesTextFile);
    cmd.add("-i");
    String audioTextFile;
    if (numberOfAudioFiles > 1) {
        audioTextFile = generateAudioFilesTexts();
    } else {
        audioTextFile = getAudioFilePath(audioRecordingFileName + Integer.toString(1));
    }

    cmd.add(audioTextFile);

    cmd.add("-vsync");
    cmd.add("vfr");
    cmd.add("-pix_fmt");
    cmd.add("yuv420p");

    String currentDateTimeString = new SimpleDateFormat("dd MMMM yyyy", Locale.US).format(Calendar.getInstance().getTime());
    File dirOut = new File(this.getExternalFilesDir(null), "D:T:" + currentDateTimeString);
    if (!dirOut.exists()) {
        dirOut.mkdirs();
    }
    directoryPath = dirOut.getAbsolutePath();
    File fileOut = new File(dirOut, "T__" + Long.toString(totalTime) + "__P__" + Integer.toString(picturesModelInfo.getNumberOfShots()) + ".mp4");
    cmd.add(fileOut.getAbsolutePath());
    Log.d(TAG, "Saving File At " + fileOut.getAbsolutePath());

    String[] finalCommand = new String[cmd.size()];

    for (int i = 0; i < cmd.size(); i++) {
        finalCommand[i] = cmd.get(i);
    }

    String finalString = "";
    for (String command : finalCommand) {
        finalString += command;
    }

    Log.d(TAG, "Final Command Is " + finalString);
    return finalCommand;
}

这是我的最终命令

-y-fconcat-safe0-i/storage/emulated/0/Android/data/com.essentialsln.memtalk/files/pictures_merging.txt-i/storage/emulated/0/Android/data/com.essentialsln.memtalk/files/AudioRecording1.3gp-vsyncvfr-pix_fmtyuv420p/storage/emulated/0/Android/data/com.essentialsln.memtalk/files/D:T:19 July 2017/T__2__P__3.mp4

主要问题是视频无法在Android默认播放器中播放 - 显示(&#34;无法播放视频,不支持的文件类型&#34;),但它适用于VLC程序。 ))

Anu建议?

由于

0 个答案:

没有答案