2

I am trying to create a video .mp4 file from .mp3 audio & .jpeg image.

I am able to create a video and able to play it in video players on Android devices.

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".

I am using below FFMPEG command:

"-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 found here that I need to use H.264 + AAC. But I'm still not able to share video with supported file format.

Dimitri Podborski
  • 3,714
  • 3
  • 19
  • 31
  • what you used to convert images to Video? – Developer Nov 22 '18 at 05:37
  • I am using FFMPEG only to **combine Image + Audio to get Video [.mp4] output.** @AndroidUser – Neel Mevada Nov 22 '18 at 06:20
  • @NeelMevada can you share the mp4 file you created? – Dimitri Podborski Nov 23 '18 at 02:59
  • @NeelMevada another question, why didn't you set shareIntent.setType("video/mp4"); for mp4 file? – Dimitri Podborski Nov 23 '18 at 03:02
  • its also a possible duplicate of [this post](https://stackoverflow.com/questions/45744296/intent-image-share-file-format-not-supported) – Dimitri Podborski Nov 23 '18 at 03:11
  • @incBrain I tried with video/mp4 but same issue occures. [link](https://stackoverflow.com/questions/45744296/intent-image-share-file-format-not-supported) >> This post is related to Image and I am able to share image to whatsapp. I am getting an issue in sending Videos Only. Thank you in advance for your help ! – Neel Mevada Nov 23 '18 at 04:32
  • @NeelMevada ok so if you are able to do it with the image using similar approach its good. I can try to take a deeper look at the mp4 file you created, maybe I can figure something out. One thing which I can see from your ffmpeg options is -c:a copy while you are using .mp3. this will not create AAC audio. Try to remove -c:a copy (ffmpeg should do aac by default, if not specify aac audio codec in the options) – Dimitri Podborski Nov 23 '18 at 06:08
  • 1
    @incBrain Thank you for your support. This is been resolved with using AAC audio codec in this command. now i am using -c:a aac and it runs well. – Neel Mevada Dec 03 '18 at 10:44

1 Answers1

1

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.

The solution to this is to tell ffmpeg to re-encode audio stream to AAC using -c:a aac. More examples on how to encode AAC can also be found here.

Dimitri Podborski
  • 3,714
  • 3
  • 19
  • 31