【问题标题】:Command of FFMPEG to make a video from Image(JPEG) + Audio(.mp3) & Share video in WhatsappFFMPEG 命令从图像(JPEG)+ 音频(.mp3)制作视频并在 Whatsapp 中分享视频
【发布时间】:2018-11-22 04:50:03
【问题描述】:

我正在尝试从 .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"));
                    }
                });

我发现here 我需要使用 H.264 + AAC。 但我仍然无法分享支持文件格式的视频

【问题讨论】:

  • 你用什么将图像转换为视频?
  • 我只使用 FFMPEG 来结合图像 + 音频来获得视频 [.mp4] 输出。 @AndroidUser
  • @NeelMevada 你能分享你创建的 mp4 文件吗?
  • @NeelMevada 另一个问题,你为什么不设置 shareIntent.setType("video/mp4");用于 mp4 文件?
  • @incBrain 感谢您的支持。在此命令中使用 AAC 音频编解码器已解决此问题。现在我正在使用 -c:a aac 并且运行良好。

标签: android video android-ffmpeg


【解决方案1】:

正如在 cmets 中已经讨论的那样,由于在 mp3 音频文件上使用了 -c:a copy,因此无法使用 AAC 编解码器对音频进行编码。

解决方案是告诉ffmpeg 使用-c:a aac 将音频流重新编码为AAC。 更多关于如何编码 AAC 的例子也可以在here找到。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-09-06
    • 1970-01-01
    • 1970-01-01
    • 2012-05-24
    • 1970-01-01
    • 1970-01-01
    • 2021-08-11
    • 2020-08-25
    相关资源
    最近更新 更多