如何在Android中使用FFMPEG库为MP4制作Youtube视频?

时间:2018-02-27 04:49:06

标签: android ffmpeg

这是我的代码

private void executeAudioVideo() {
        File moviesDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES);
        String filePrefix = "audio_video";
        String fileExtn = ".mp4";

        youtubeURL = "https://www.youtube.com/embed/oEKyXKL25FU";
        videoPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/video.mp4";

        File dest = new File(moviesDir, filePrefix + fileExtn);
        int fileNo = 0;
        while (dest.exists()) {
            fileNo++;
            dest = new File(moviesDir, filePrefix + fileNo + fileExtn);
        }
        filePath = dest.getAbsolutePath();

        String[] command = new String[]{"-y", "-i", videoPath, "-i", youtubeURL, "-filter_complex", "[0:a][1:a]amerge=inputs=2[a]", "-map", "0:v", "-map", "[a]", "-c:v", "copy", "-c:a", "libvorbis", "-ac", "2", "-shortest", filePath};

        Toast.makeText(this, filePath, Toast.LENGTH_SHORT).show();
        execFFmpegBinary(command);
    }

1 个答案:

答案 0 :(得分:0)

您可以使用此库实现此目的:FFmpeg-Android

此库有一个实现:KotlinFFMpeg