I have two videos (.mp4) files. One uploads to whatsapp and another does not.
我有两个视频(.mp4)文件。一个上传到WhatsApp,另一个不上传。
Using ffmpeg I checked their properties:
我使用ffmpeg检查了它们的属性:
a) Properties of video which uploads:
A)上传的视频的属性:
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)
B)不上传到WhatsApp的视频(因为它说格式不受支持)
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)
(avc1/0x31637661)vs(H264/0x34363248)
1359 kb/s
vs 464 kb/s
1359kb/S vs 464kb/S
90k tbn
vs 23.98 tbn
90K TBN与23.98 TBN
What can be the reason?
可能的原因是什么?
Also the second video is not being played in Android.
此外,第二个视频没有在Android上播放。
The link for the video is https://drive.google.com/open?id=0B4UM6vTHw4pyMExQQ1lxZGp0N2c
该视频的链接为https://drive.google.com/open?id=0B4UM6vTHw4pyMExQQ1lxZGp0N2c
更多回答
Are you generating the 2nd video using ffmpeg?
您正在使用ffmpeg生成第二个视频吗?
The same question was asked here and there's a solution there.
同样的问题在这里被问到了,那里有一个解决方案。
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
Ffmpeg-i broken.mp4-c:v libx264-配置文件:v基线级别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.
使用-Profile:v Baseline-Level 3.0,您可以使文件与大多数较旧的播放器更兼容,包括WhatsApp;)。不过,这会禁用一些高级功能。
-pix_fmt yuv420p
is necessary to compile to baseline (YUV planar color space with 4:2:0 chroma subsampling).
-pix_fmt yuv420p是编译为基线所必需的(具有4:2:0色度次采样的YUV平面色彩空间)。
Also, you can adjust other options as bitrate, framerate, audio, etc.
此外,您还可以调整其他选项,如比特率、帧速率、音频等。
Source: H.264 docs
来源:H.264文档
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 |
Note about faststart
Normally, a MP4 file has all its metadata packets stored at the end of the file, in data units named atoms. The mdat
atom is located before the moov
atom. If the file is created by adding the -movflags faststart
, the moov
atom is moved at the beginning of the MP4 file. By using this option, the moov
atom is located before the mdat
atom. This allows video playback to begin before the file has been completely downloaded.
通常,MP4文件的所有元数据包都存储在文件的末尾,存储在名为ATOM的数据单元中。Mdat原子位于moov原子之前。如果该文件是通过添加-mov FastStart创建的,则moov原子将移动到MP4文件的开头。通过使用该选项,moov原子位于mdat原子之前。这允许在文件完全下载之前开始视频回放。
Copied from https://www.reddit.com/r/ffmpeg/comments/564kyc/ffmpeg_whatsapp_video_format_not_supported/?st=ivjxdi0v&sh=848ce7eb
从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"
我还不得不应用这个修正:FFmpeg(Libx264)“高度不能被2整除”
This is worked for me in 2020
这对我在2020年很管用
ffmpeg -i broken.mp4 -c:v libx264 -profile:v high -level 3.0 -pix_fmt yuv420p -brand mp42 fixed.mp4
2023-01-22 I used the most upvoted answer format and it worked for video, but audio was not working on iPhones. Here's what worked for me:
2023-01-22我使用了最受欢迎的答案格式,它对视频有效,但音频在iPhone上不起作用。以下是对我起作用的方法:
ffmpeg -i broken.mp4 -c:v libx264 -profile:v baseline -level 3.0 -pix_fmt yuv420p -ac 2 working.mp4
I had to add -ac 2
because the audio format I had wasn't seen as stereo by iOS.
我不得不添加-ac 2,因为我的音频格式在iOS中并不是立体声格式。
Copying @teocci's answer for powershell:
复制@teocci对PowerShell的回答:
ffmpeg -i 'input.mp4' `
-c:v libx264 -pix_fmt yuv420p `
-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 you video already has aac:
如果您的视频已有AAC:
ffmpeg -i 'input.mp4' `
-c:v libx264 -pix_fmt yuv420p `
-vf "pad=ceil(iw/2)*2:ceil(ih/2)*2" -vb 1024k `
-acodec copy `
-minrate 1024k -maxrate 1024k -bufsize 1024k `
-movflags +faststart `
output.mp4
Check out the original answer for mode details. Not allowed to comment so posting an answer instead
有关模式的详细信息,请查看原始答案。不允许发表评论,因此改为发布答案
更多回答
in my case the problem came out to be the pix_fmt which was not yuv420p
在我的例子中,问题是pix_fmt,而不是yuv420p
Seriously, this worked great, but how, how can you possibly know this massive command line?? 🙌
说真的,这很有效,但是你怎么,你怎么可能知道这个庞大的命令行??🙌
@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 😉.
@CaioMar我真的不记得我是怎么得的了。我认为通过研究ffmpeg h264文档和“尝试并失败”。这都是关于“兼容性”..。而H.64编码具有用于该😉的选项。
@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?
@JamieHutber我仍然使用这个命令。不仅如此,我认为WhatsApp Web比以前更灵活,它可以接受更多的格式。你的ffmpeg版本是什么?
Would you believe it... whatsapp just released an update that fixed this!!! Within the last 10mins :D Now the files are working
你相信吗..。WhatsApp刚刚发布了修复此问题的更新!在过去的10分钟内:D现在文件正在工作
Just tried it and works, after trying a different version down here that apparently stopped working now. April 2022.
只是试了试,在尝试了一个不同的版本后,现在显然不起作用了。2022年4月。
Does the +faststart benefit Whatsapp ? Also, can you use -movflags with .mp4 and not just .mov ?
+FastStart是否会让Whatsapp受益?此外,您是否可以对.mp4而不只是.mov使用-mov标志?
None worked from "whatsapp web". Had to move file to the phone to upload from app and it works now
在“WhatsApp web”网站上,没有一条是有效的。我必须将文件移动到手机上才能从应用程序上传,现在可以使用了
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
此命令将对视频和音频进行重新编码。我打赌这只是视频标签的问题。尝试ffmpeg-i broken.mp4-c Copy-vtag avc1 fix ed.mp4
same (and the others didn't)
相同的(其他人则不是)
I don't find -brand mp42
as an option of ffmpeg or H264 encoding. Maybe this is from MP4Box (here). If you want to set fourcc as mp42
with ffmpeg, then you shoud use -tag:v mp42
.
我没有发现品牌mp42作为ffmpeg或h264编码的选项。也许这是来自MP4Box(这里)。如果您想用ffmpeg将Fourcc设置为mp42,那么您应该使用-tag:v mp42。
Doesn't seem to be working for me, in 2022
似乎对我不起作用,2022年
我是一名优秀的程序员,十分优秀!