How to use startPushingFileToMegaphone
I am using FFmpegKit to convert an MP3 file to PCM, then converting the PCM file to Opus, and sending the Opus data to the startPushingFileToMegaphone function.
When sending the data, I store the Opus File in the file class of FileInfo and set the UploadType.ViIce_File. In this case, I am sending a byteArray with a value of null. Is this the correct way to do it?
Please provide feedback on any mistakes.
//megaphone function
val droneFileInfo = DroneMegaphoneFileInfo(uploadType = DroneMegaphoneUploadType.VOICE_FILE, file = sendFile ,data = null) DroneManager.getMegaphoneManager().startPushingFileToMegaphone(droneFileInfo)
//ffmpeg function
fun convertMp3ToPcm(inputFile: File): File? {
val outputFile = File(inputFile.parent, inputFile.nameWithoutExtension + ".pcm")
// FFmpeg 명령어 배열
//val command = "-i ${inputFile.absolutePath} -f s16le -ar 44100 -ac 2 ${outputFile.absolutePath}"
//val command = "-i ${inputFile.absolutePath} -ac 1 -ar 48000 -b:a 64000 -c:a libopus ${outputFile.absolutePath}"
// val command = "-i ${inputFile.absolutePath} -f s16le -ar 16000 -ac 1 ${outputFile.absolutePath}"
// val command = "-i ${inputFile.absolutePath} -f s16le -ac pcm_s16le -ac 1 -ar 16000 ${outputFile.absolutePath}"
val command = "-i ${inputFile.absolutePath} -f s16le -ac 1 -ar 16000 ${outputFile.absolutePath}"
//val command = "-i ${inputFile.absolutePath} -acodec pcm_s16le -ar 44100 -ac 2 ${outputFile.absolutePath}"
// 명령어 실행
val session: FFmpegSession = FFmpegKit.execute(command)
// 실행 결과 확인
if (session.returnCode.isValueSuccess) {
Log.d("FFmpegKit", "MP3에서 PCM 변환 성공: ${outputFile.absolutePath}")
return outputFile
} else {
Log.e("FFmpegKit", "MP3에서 PCM 변환 실패")
return null
}
}
fun convertPcmToOpus(pcm: File): File? { if (!pcm.exists()) { println("파일이 존재하지 않습니다: ${pcm.absolutePath}") return null }
val opusOutputFile = File(pcm.parent, pcm.nameWithoutExtension + ".opus") // 같은 폴더에 .opus 파일 생성
// val command = "-f s16le -ar 16000 -ac 1 -i ${pcm.absolutePath} -c:a libopus -b:a 16k -vbr off -compression_level 0 ${opusOutputFile.absolutePath}"
// val command = "-f s16le -ar 16000 -ac 1 -i ${pcm.absolutePath} -c:a libopus -b:a 32k -vbr on -compression_level 10 ${opusOutputFile.absolutePath}"
val command = "-f s16le -ar 16000 -ac 1 -i ${pcm.absolutePath} -c:a libopus -b:a 16k -vbr off -compression_level 0 ${opusOutputFile.absolutePath}"
val session = FFmpegKit.execute(command)
return if (session.returnCode.isValueSuccess) {
println("변환 성공: ${opusOutputFile.absolutePath}")
opusOutputFile // 변환된 Opus 파일 반환
} else {
println("변환 실패: ${session.failStackTrace}")
null // 변환 실패 시 null 반환
}
}
Agent comment from YIGUI LIU in Zendesk ticket #133905:
Dear Developer,
You can refer to the documentation of the startPushingFileToMegaphone interface as follows, which has descriptions of relevant input parameters:
https://developer.dji.com/api-reference-v5/android-api/Components/IMegaphoneManager/IMegaphoneManager.html?search=startpushingfiletomegaphone&i=0&#imegaphonemanager_startpushingfiletomegaphone_inline
Regarding the use of FFmpegKit, we cannot provide relevant support. As long as the requirements of 16-bit width, 1 channel, and a sampling rate of 32K or 16K are met.
For the implementation method in the MSDK sample, you can refer to the FAQ: How to convert the mp3 file to an opus file: https://sdk-forum.dji.net/hc/en-us/articles/16710729420697-How-to-convert-the-mp3-file-to-an-opus-file
When using startPushingFileToMegaphone to upload audio files, there is a known issue currently. Only audio files with a sampling rate of 32K are supported. It is expected that support for audio files with a sampling rate of 16K will be available after the MSDK 5.14.0 update.
When using sendRealTimeDataToMegaphone to upload audio files, the currently supported sampling rate is 16K. You can also use this interface to upload audio files with a 16K sampling rate.
Megaphone Tutorial: https://developer.dji.com/doc/mobile-sdk-tutorial/en/tutorials/payload.html
Best Regards,
DJI Innovations SDK Technical Support Team
°°°