42

I have two videos (.mp4) files. One uploads to whatsapp and another does not.

Using ffmpeg I checked their properties:

a) Properties of video which uploads:

  Duration: 00:00:56.45, start: 0.148000, bitrate: 1404 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1080x1080, 1359 kb/s, 23.98 fps, 23.98 tbr, 90k tbn, 47.95 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: aac (HE-AACv2) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 47 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
At least one output file must be specified

b) video which does not upload to whatsapp (because its says format not supported)

  Duration: 00:00:56.10, start: 0.000000, bitrate: 543 kb/s
    Stream #0:0: Video: h264 (High) (H264 / 0x34363248), yuv420p, 1080x1080 [SAR 1:1 DAR 1:1], 464 kb/s, 23.98 fps, 23.98 tbr, 23.98 tbn, 47.95 tbc
    Stream #0:1: Audio: aac (LC) ([255][0][0][0] / 0x00FF), 48000 Hz, stereo, fltp, 56 kb/s

The difference in video I noticed:

(avc1 / 0x31637661) vs (H264 / 0x34363248)

1359 kb/s vs 464 kb/s

90k tbn vs 23.98 tbn

What can be the reason?

Also the second video is not being played in Android.

The link for the video is https://drive.google.com/open?id=0B4UM6vTHw4pyMExQQ1lxZGp0N2c

Braiam
  • 1
  • 11
  • 50
  • 74
Santhosh
  • 7,522
  • 13
  • 60
  • 145
  • Are you generating the 2nd video using ffmpeg? – Gyan Oct 08 '16 at 12:23
  • 1
    The same question was asked [here](https://www.reddit.com/r/ffmpeg/comments/564kyc/ffmpeg_whatsapp_video_format_not_supported/?st=ivjxdi0v&sh=848ce7eb) and there's a solution there. – Andrew Nov 15 '16 at 20:06

4 Answers4

98

There are some options for a better compatibility:

ffmpeg -i broken.mp4 -c:v libx264 -profile:v baseline -level 3.0 -pix_fmt yuv420p working.mp4

With -profile:v baseline -level 3.0 you make the file more compatible with most older players, including WhatsApp ;). Although, this disables some advanced features.

-pix_fmt yuv420p is necessary to compile to baseline (YUV planar color space with 4:2:0 chroma subsampling).

Also, you can adjust other options as bitrate, framerate, audio, etc.

Source: H.264 docs

Mario Mey
  • 1,377
  • 1
  • 12
  • 13
  • 1
    in my case the problem came out to be the pix_fmt which was not yuv420p – Aurangzeb Nov 27 '17 at 10:26
  • Nice thanks, worked like a charm! If only Kazam could use these settings right away it would make it easier to screencap and share. – CodeMonkey Dec 16 '17 at 12:26
  • Setting `-pix_fmt yuv420p` is needed when converting from GIF. – arielCo Apr 26 '20 at 20:57
  • 1
    Seriously, this worked great, but how, how can you possibly know this massive command line?? – Caio Mars Nov 14 '21 at 00:13
  • 2
    @CaioMar I really don't remember how did I get it. I think by researching in ffmpeg H264 documentation and "try and failure". It's all about "compatibility"... and h264 encoding has options for that . – Mario Mey Nov 15 '21 at 16:32
  • So frustrating that this no longer works :( – Jamie Hutber Apr 25 '22 at 20:40
  • 1
    @JamieHutber I still use this command. Not only that, I think that WhatsApp Web is more flexible than before, that it accept more formats. What's your ffmpeg version? – Mario Mey Apr 26 '22 at 09:25
  • Interesting. I wonder indeed then. `ffmpeg version 4.2.4-1ubuntu0.1 Copyright` I have the same script, it has not changed. But now they do not work. Let me look to upgrade ffmpeg – Jamie Hutber Apr 26 '22 at 09:39
  • 1
    Would you believe it... whatsapp just released an update that fixed this!!! Within the last 10mins :D Now the files are working – Jamie Hutber Apr 26 '22 at 10:55
8

Copied from https://www.reddit.com/r/ffmpeg/comments/564kyc/ffmpeg_whatsapp_video_format_not_supported/?st=ivjxdi0v&sh=848ce7eb

ffmpeg -i brokenvideo.mp4 -c:v libx264 -c:a aac fixedvideo.mp4

Also had to apply this fix: FFMPEG (libx264) "height not divisible by 2"

Community
  • 1
  • 1
brauliobo
  • 5,204
  • 4
  • 28
  • 33
  • 2
    This command will re-encode the video and audio. I bet this is just a matter of the video tag. Try `ffmpeg -i broken.mp4 -c copy -vtag avc1 fixed.mp4` – Gyan Jan 01 '17 at 05:02
5

This is worked for me in 2020

ffmpeg -i broken.mp4 -c:v libx264 -profile:v high -level 3.0 -pix_fmt yuv420p -brand mp42 fixed.mp4
jenkas
  • 747
  • 10
  • 15
2

I tried all previous commands and I got some errors. I was able to encode my video using this command and here is the explanation and why I set it up like this for a better compatibility:

ffmpeg -i input.mp4 \
 -c:v libx264 -pix_fmt yuv420p \
 -profile:v baseline -level 3.0 
 -vf "pad=ceil(iw/2)*2:ceil(ih/2)*2" -vb 1024k \
 -acodec aac -ar 44100 -ac 2\
 -minrate 1024k -maxrate 1024k -bufsize 1024k \
 -movflags +faststart \
 output.mp4
  • If your input contains AAC audio you can stream copy instead of re-encoding by changing -acodec aac -ar 44100 -ac 2 to -acodec copy to preserve the audio quality.
option explanation
-vcodec libx264 Chooses video encoder libx264
-pix_fmt yuv420p Ensures YUV 4:2:0 chroma subsampling for compatibility
-profile:v baseline Set the encoding profile to baseline. Used primarily for low-cost applications that require additional data loss robustness
-level 3.0 Set the operating point level to 3.0 which is necessary to have compatibility with WhatsApp
-vf "pad=ceil(iw/2)*2:ceil(ih/2)*2" If you get not divisible by 2 error see
-acodec aac Chooses audio encoder aac
-minrate 1024k set min bitrate tolerance to 1024k (in bits/s). It is of little use elsewise
-maxrate 1024k set max bitrate tolerance to 1024k (in bits/s). Requires bufsize to be set
-bufsize 1024k set rate-control buffer size to 1024k (in bits)
-movflags +faststart enables fast start for streaming
Teocci
  • 5,312
  • 1
  • 41
  • 41
  • Just tried it and works, after trying a different version down here that apparently stopped working now. April 2022. – Javier Villa Apr 15 '22 at 12:24