Question

I am now creating a music slide mp4 video and going to play it in android device with ffmpeg.

I used the following command to accomplish this mission.

The first one is to inputting a batch of jpg files and convert it to a mp4 file.

1.)C:/xampp/htdocs/bin/ffmpeg -y -r 1/5 -i C:/xampp/htdocs/bin/%03d.jpg -c:v libx264 -profile:v baseline -level 3.0 -r 30 -pix_fmt yuv420p C:/xampp/htdocs/bin/out.mp4

The second one is to putting the audio to the previous created video.

2.)C:/xampp/htdocs/bin/ffmpeg -i C:/xampp/htdocs/bin/out.mp4 -i C:/xampp/htdocs/upload/1.mp3 -y -map 0 -map 1 -codec copy -shortest C:/xampp/htdocs/bin/haha.mp4"

Both of the command are correct and created the mp4 file. However only out.mp4 can be played in android deivce while haha.mp4 cannot.

So it seems the audio track violate the android mp4 requirement. What should the second command be so that i can play the mp4 file in android device.

Was it helpful?

Solution

Some devices do not like MP3 audio in MP4 container. AAC audio is more common. A simple command:

ffmpeg -i video -i audio -map 0:v -map 1:a -codec:v copy -codec:a aac \
-strict experimental -b:a 192k -shortest output.mp4

Note that I changed -map 0 -map 1 to -map 0:v -map 1:a to be more specific, because you probably do not want ffmpeg to include any album art from the audio input (it would create an additional, separate video stream).

A more specific command for your case. You can do everything in one command instead of two:

ffmpeg -framerate 1/5 -i %03d.jpg -i audio.mp3 -map 0:v -map 1:a -c:v libx264 \
-profile:v baseline -level 3.0 -r 30 -pix_fmt yuv420p -c:a aac \
-strict experimental -b:a 192k -shortest output.mp4
  • This example uses the native FFmpeg AAC encoder. It is considered experimental, so results may vary, but it is not a terrible encoder with enough bitrate.

  • If you have other AAC encoders supported by your ffmpeg then refer to the FFmpeg and AAC Encoding Guide for additional suggestions, examples, and information.

  • You may experience several issues, such as frames being skipped, when making a video from images. See the answer to FFmpeg slideshow from images - only one frame shown for solutions.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top