23

I would like to use ffmpeg to convert an mp4 to 'low size' mp4 ...

I need an mp4 file with h263 video and aac audio (or some other settings supported by low cost mobile.) My main concern is that the video be playable on most devices.

What would be some possible ffmpeg commands to accomplish this?

Thanks in advance.

Notepad
  • 1,659
  • 1
  • 12
  • 14

3 Answers3

50

There are numerous ways to encode mp4 videos, and encoding them for mobile devices is even more complex. I'm not sure what you mean by "low cost mobile" do you mean low cost as in the device, or the bandwidth needed to play said video?

Either way, here a post to get you going: H.264 WEB VIDEO ENCODING TUTORIAL WITH FFMPEG

Examples

Here are some ffmpeg examples from the post ...

“Standard” web video (480p at 500kbit/s):

ffmpeg -i input_file.avi -vcodec libx264 -vprofile high -preset slow -b:v 500k -maxrate 500k -bufsize 1000k -vf scale=-1:480 -threads 0 -acodec libvo_aacenc -b:a 128k output_file.mp4

360p video for older mobile phones (360p at 250kbit/s in baseline profile):

ffmpeg -i inputfile.avi -vcodec libx264 -vprofile baseline -preset slow -b:v 250k -maxrate 250k -bufsize 500k -vf scale=-1:360 -threads 0 -acodec libvo_aacenc -ab 96k output.mp4

480p video for iPads and tablets (480p at 400kbit/s in main profile):

ffmpeg -i inputfile.avi -vcodec libx264 -vprofile main -preset slow -b:v 400k -maxrate 400k -bufsize 800k -vf scale=-1:480 -threads 0 -acodec libvo_aacenc -ab 128k output.mp4

High-quality SD video for archive/storage (PAL at 1Mbit/s in high profile):

ffmpeg -i inputfile.avi -vcodec libx264 -vprofile high -preset slower -b:v 1000k -vf scale=-1:576 -threads 0 -acodec libvo_aacenc -ab 196k output.mp4

Bitrates, scale and profiles ...

From the examples there, some of the key things you might need to pay attention to are ...

-b:v 500k

-b:a 128k

Those are bitrates of the video v and audio a, the lower the number the lower the quality but also the better it might 'play' on a low end device.

scale=-1:480

That will scale the video down to a smaller size, see more info about that in the post)

-vprofile baseline

This seemly odd baseline (or another appropriate profile parameter) can be important when encoding for certain lower-cost (e.g. Android) devices ...

Baseline Profile (BP)

Primarily for low-cost applications that require additional data loss robustness, this profile is used in some videoconferencing and mobile applications. This profile includes all features that are supported in the Constrained Baseline Profile, plus three additional features that can be used for loss robustness (or for other purposes such as low-delay multi-point video stream compositing). The importance of this profile has faded somewhat since the definition of the Constrained Baseline Profile in 2009. All Constrained Baseline Profile bitstreams are also considered to be Baseline Profile bitstreams, as these two profiles share the same profile identifier code value.

Justin Jenkins
  • 26,590
  • 6
  • 68
  • 1,285
  • this all conversion, my input and output file is of same format. – Notepad Nov 28 '12 at 09:06
  • I'm trying to convert an AVI to MP4 with your 360p command but "-acodec libvo_aacenc -ab 128k" is not working, if I replace it with "-acodec copy", it works, Its error is "Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height". Should i set more parameters for audio? if yes, what are does params? – Uchiha_Sasuke Feb 22 '14 at 15:51
  • 2
    @user1202498 `-acodec copy` will not actually encode your audio at all but instead just copy the audio stream from the old file into the new one. If you have support for `libvo_aacenc` (do you?) you shouldn't have to set anything special. You can also try `-codec:a aac -strict experimental` to use ffmpeg's native aac encoding. – Justin Jenkins Feb 26 '14 at 19:27
  • Thank you very much, all the solutions out there are having outdated parameters – Imal Hasaranga Perera Apr 03 '15 at 07:02
  • 1
    what about `-movflags +faststart` output option in order to "move some information to the beginning of your file and allow the video to begin playing before it is completely downloaded" — https://trac.ffmpeg.org/wiki/Encode/H.264#faststartforwebvideo ? – abernier Nov 13 '16 at 11:10
  • also `width not divisible by 2 (853x480)` – ar2015 Mar 16 '18 at 07:26
0
 ffmpeg.exe -i "input.mp4" -vcodec mpeg4 -preset slower -b:v 1000k -vf "scale=640:480,setsar=1,fps=30,pad=640:480:0:0" -acodec aac -ac 2 -ar 22050 -ab 128k "output (480p).mp4"
ouflak
  • 2,458
  • 10
  • 44
  • 49
  • 4
    While this code may solve the question, [including an explanation](//meta.stackexchange.com/q/114762) of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please [edit] your answer to add explanations and give an indication of what limitations and assumptions apply. – Yunnosch Nov 03 '21 at 12:59
  • 1
    @Yunnosch's point is always important, but it's _especially_ important when there's already an accepted answer that's been validated by the community. Under what conditions might your approach be preferred? Are you taking advantage of new capabilities? – Jeremy Caney Nov 04 '21 at 00:27
-1

I found answer,Thanks for help anyway.

ffmpeg -i $input_file -s $size $output_file

$size : 320X400 or any WidthXHeight

Notepad
  • 1,659
  • 1
  • 12
  • 14
  • 2
    This does not answer your question. Justin Jenkins' answer was more complete and insightful. The linked blog post also provided more details to answer this complex question of encoding video for mobile devices. – Arko Jun 11 '13 at 10:03
  • this just do rotation without any modification ,exactly what i want , i do not wanted the documentation link – Notepad Jun 12 '13 at 09:19
  • @Susheel: That command line doesn't do rotation at all, it does a resize - without setting codecs or bitrates (which are what the question was asking for). – Mark K Cowan Jul 08 '14 at 21:03