这是命令。我正在尝试将音频合并到视频中。
val tempFile = File(requireActivity().cacheDir, "output.mp4")
tempFile.createNewFile()
Log.e(TAG, ": " + tempFile.length())
val command: String = "ffmpeg \\\n" +
" -i $video \\\n" +
" -i $audio \\\n" +
" -c:v copy \\\n" +
" -c:a copy \\\n" +
" -shortest \\\n" +
" -f mp4 \\\n" +
" ${tempFile.absolutePath}"
命令变为:
ffmpeg \
-i /data/user/0/com.rohaitas.example/cache/temp_video.mp4 \
-i /data/user/0/com.rohaitas.example/cache/temp_audio.mp3 \
-c:v copy \
-c:a copy \
-shortest \
-f mp4 \
/data/user/0/com.rohaitas.example/cache/output.mp4
[NULL @ 0xb4000076a3da3b00] 无法找到合适的输出格式 对于“ffmpeg”ffmpeg:无效参数
依赖性
implementation 'com.arthenica:ffmpeg-kit-full:5.1'
Command failed with state COMPLETED and rc 1.null
Stream #1:0
Audio: mp3, 48000 Hz, stereo, fltp, 199 kb/s
Metadata:
encode:
Lavc59.18
[NULL @ 0xb4000076a6f4ec80] Unable to find a suitable output format for 'ffmpeg'
ffmpeg: Invalid argument
刚刚成功解决了问题,现在不再出现错误。
val tempFile = File(requireActivity().cacheDir, "output.mp4")
tempFile.createNewFile();
val command= StringBuilder()
.append("-y") //overWrite
.append(" -i ").append(video) // video
.append(" -i ").append(audio) // audio
.append(" -c:v ").append("copy")
.append(" -c:a ").append("copy")
.append(" -shortest ") // shortest from both
.append(" -f ").append("mp4 ")
.append(tempFile.absolutePath)
val session = FFmpegKit.execute(command.toString())