9

I just use the following command to convert a gif file to mp4 but the resulting mp4 file doesn't play in android default video player .
what did I wrong ?
is there any aditional steps should I take to produce android playable mp4 files ?

$ ffmpeg -f gif -i infile.gif outfile.mp4

my test gif file : Test Gif File
My desktop played the output.mp4 very well using VLC Media Player and also MX Player on my android device played the video file without any error.

Mahdi
  • 150
  • 1
  • 1
  • 10
  • 2
    I think you could use ffmpeg -f gif -i file.gif -c:v libx264 outfile.mp4 – Ramin Mousavi Aug 03 '15 at 08:18
  • 1
    Pl. refer to the below url http://unix.stackexchange.com/questions/40638/how-to-do-i-convert-an-animated-gif-to-an-mp4-or-mv4-on-the-command-line Another way to convert GIF animation to video: ffmpeg -i your_gif.gif -c:v libvpx -crf 12 -b:v 500K output.mp4 -crf values can go from 4 to 63. Lower values mean better quality. -b:v is the maximum allowed bitrate. Higher means better quality. – shri Aug 03 '15 at 09:34

1 Answers1

10

Try this:

ffmpeg -i file.gif -movflags faststart -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" out.mp4
DeiDei
  • 10,205
  • 6
  • 55
  • 80
kuceb
  • 16,573
  • 7
  • 42
  • 56
  • Could you explain what this does? – Tom Dec 03 '18 at 14:49
  • @Tom the default codec is `yuv444p` which apparently can't be played in some mobile browsers (read: Mobile Safari and probably older mobile browsers in general). I googled the cryptic scale argument and found this: https://github.com/manateelazycat/deepin-screen-recorder/commit/a49612faed28fc70a98aa117839cc67d96b99761 – SidOfc May 22 '20 at 14:45
  • 1
    Additionally, Safari I think only plays the file if both width and height are divisible by 2 which is what the cryptic `-vf "scale=trunc(iw/2)*2:trunc(ih/2)*2"` line "fixes" for you. – SidOfc May 22 '20 at 14:47