using ffmpeg to convert gif to mp4 , output doesn't play on android
Asked Answered
S

1

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.

Superstructure answered 3/8, 2015 at 7:3 Comment(2)
I think you could use ffmpeg -f gif -i file.gif -c:v libx264 outfile.mp4Gorblimey
Pl. refer to the below url unix.stackexchange.com/questions/40638/… 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.Mcguire
M
12

Try this:

ffmpeg -i file.gif -movflags faststart -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" out.mp4
Marguerite answered 27/5, 2018 at 17:54 Comment(3)
Could you explain what this does?Huth
@Huth 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: github.com/manateelazycat/deepin-screen-recorder/commit/…Chally
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.Chally

© 2022 - 2024 — McMap. All rights reserved.