问题描述
我想将 .mp4 视频转换为 HLS(.m3u8) 格式。我正在使用 https://github.com/tanersener/mobile-ffmpeg 库来完成我们的任务。我正在创建一种方法来完成任务。
fun convertFileInHLS(sourceFilePath: String,destFilePath: String,context: Context) {
val desFilePath = getVideoDir(context)!!.path
val desFinalFilePath = File(desFilePath,"filename.m3u8").path
val hlsFileCommand = "ffmpeg -i ${sourceFilePath} -codec: copy -start_number 0 -hls_time 10 -hls_list_size 0 -f hls ${desFinalFilePath}"
//val hlsFileCommand = "-i ${sourceFilePath} -c:v mpeg4 ${destFilePath}"
Log.i(TAG,"hlsFileCommand:${hlsFileCommand}")
//-i file1.mp4 -c:v mpeg4 file2.mp4
val executionId = FFmpeg.executeAsync(hlsFileCommand) { executionId,returnCode ->
Log.i(TAG,"executionId:${executionId}")
if (returnCode == RETURN_CODE_SUCCESS) {
Log.i(TAG,"Async command execution completed successfully.")
} else if (returnCode == RETURN_CODE_CANCEL) {
Log.i(TAG,"Async command execution cancelled by user.")
} else {
Log.i(TAG,String.format("Async command execution Failed with returnCode=%d.",returnCode))
}
}
}
我正在使用 FFmpeg 命令
val hlsFileCommand = "ffmpeg -i ${sourceFilePath} -codec: copy -start_number 0 -hls_time 10 -hls_list_size 0 -f hls ${desFinalFilePath}"
其中sourceFilePath
=
/storage/emulated/0/Android/data/com.arthenica.mobileffmpeg.test/files/video/2021_0417_001639.mp4
和 desFinalFilePath
=
/storage/emulated/0/Android/data/com.arthenica.mobileffmpeg.test/files/video/2021_0417_001639.mp4
当我运行此代码时,它返回 executionId=3003 并返回代码=1。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)