要在Android上将M3U8文件转换为MP4文件,可以使用FFmpeg库。下面是一个简单的示例代码,可用于将M3U8 URL转换为MP4文件:
首先,在您的应用程序级别build.gradle文件中添加以下依赖项:
复制代码
implementation 'com.arthenica:mobile-ffmpeg-full-gpl:4.4.LTS'
然后,可以使用以下方法来将M3U8 URL转换为MP4文件:
import com.arthenica.mobileffmpeg.FFmpeg;
import com.arthenica.mobileffmpeg.FFmpegExecution;
import com.arthenica.mobileffmpeg.FFmpegExecutionCallback;
public void convertM3U8toMP4(String m3u8Url, String outputFilePath) {
// 构建FFmpeg命令
String[] command = new String[]{"-i", m3u8Url, "-c", "copy", outputFilePath};
// 执行FFmpeg命令
FFmpegExecution execution = FFmpeg.executeAsync(command, new FFmpegExecutionCallback() {
@Override
public void onExecutionStarted() {
// 命令已开始执行
}
@Override
public void onExecutionProgress(float progress) {
// 命令正在执行,进度由0到1
}
@Override