简体   繁体   English

FFMPEG命令从图像(JPEG)+音频(.mp3)制作视频并在Whatsapp中分享视频

[英]Command of FFMPEG to make a video from Image(JPEG) + Audio(.mp3) & Share video in Whatsapp

I am trying to create a video .mp4 file from .mp3 audio & .jpeg image.我正在尝试从 .mp3 音频和 .jpeg 图像创建视频 .mp4 文件。

I am able to create a video and able to play it in video players on Android devices.我能够创建视频并能够在 Android 设备上的视频播放器中播放它。

But after creation of file when I tried to share that video in WhatsApp, at that time it shows a message "The file format not supported".但是当我尝试在 WhatsApp 中共享该视频时创建文件后,当时它显示一条消息“不支持文件格式”。

I am using below FFMPEG command:我正在使用以下 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);

And for sharing video, I am using code listed below:对于共享视频,我使用下面列出的代码:

  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"));
                    }
                });

I foundhere that I need to use H.264 + AAC.我在这里发现我需要使用 H.264 + AAC。 But I'm still not able to share video with supported file format .但是我仍然无法使用支持的文件格式共享视频

As already discussed in the comments the problem occurs due to the audio not to be encoded using AAC codec since -c:a copy was used on mp3 audio files.正如评论中已经讨论的那样,问题的发生是由于音频未使用 AAC 编解码器进行编码,因为-c:a copy用于mp3音频文件。

The solution to this is to tell ffmpeg to re-encode audio stream to AAC using -c:a aac .解决方案是告诉ffmpeg使用-c:a aac音频流重新编码-c:a aac More examples on how to encode AAC can also be found here .更多关于如何编码 AAC 的例子也可以在这里找到。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM