[英]Command of FFMPEG to make a video from Image(JPEG) + Audio(.mp3) & Share video in Whatsapp
我正在尝试从 .mp3 音频和 .jpeg 图像创建视频 .mp4 文件。
我能够创建视频并能够在 Android 设备上的视频播放器中播放它。
但是当我尝试在 WhatsApp 中共享该视频时创建文件后,当时它显示一条消息“不支持文件格式”。
我正在使用以下 FFMPEG 命令:
"-loop 1 -r 1 -i " + imageFilePath + " -i " + audioFilePath + " -c:v libx264 -crf 27 -tune stillimage -c:a copy -pix_fmt yuv420p -preset ultrafast -shortest " + pathOutputVideo(sectionName);
对于共享视频,我使用下面列出的代码:
MediaScannerConnection.scanFile(ShareQuestionAudioActivity.this, new String[]{FfmpegController.pathOutputVideo(qModel.getSectionName().toUpperCase().replaceAll(" ", "_"))},
null, new MediaScannerConnection.OnScanCompletedListener() {
public void onScanCompleted(String path, Uri uri) {
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("video/*");
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(FfmpegController.pathOutputVideo(qModel.getSectionName().toUpperCase().replaceAll(" ", "_"))));
startActivity(Intent.createChooser(shareIntent, "Share Question"));
}
});
我在这里发现我需要使用 H.264 + AAC。 但是我仍然无法使用支持的文件格式共享视频。
正如评论中已经讨论的那样,问题的发生是由于音频未使用 AAC 编解码器进行编码,因为-c:a copy
用于mp3
音频文件。
解决方案是告诉ffmpeg
使用-c:a aac
音频流重新编码-c:a aac
。 更多关于如何编码 AAC 的例子也可以在这里找到。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.