android - 如何在 Android 中使用 FFMPEG 库将 Youtube 视频与 MP4 合并?

标签 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);
    }

最佳答案

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

这里有这个库的一个实现:KotlinFFMpeg

关于android - 如何在 Android 中使用 FFMPEG 库将 Youtube 视频与 MP4 合并?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49001342/

相关文章:

ffmpeg - 使用 ffmpeg 下载 Internet 站点上发布的 HLS 格式视频时的间隔选项

ffmpeg - 我可以使用 av_write_frame() 而不是 av_interleaved_write_frame() 吗?

java - 未处理的异常 java.io.iOException

Android:在 native 电子邮件中打开自定义文件附件的问题

python - 如何使用 Python 捕获 x265.exe 的实时命令行输出?

ffmpeg - 将流式 MPEG-4 原始数据转换为 H.264

video - 使用 ffmpeg 校正偏色

java - webView.ontouch和button.onclick之间的冲突

android - 如何在 Spinner Android 中设置项目的文本颜色

android - 为什么纹理 View 中的相机预览比表面 View 中的相机预览模糊得多?