Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I Can't Upload This Video File (mp4) To Twitter

I tried to upload a video file (mp4) to Twitter but the site complained it couldn't be uploaded. It seems Twitter has some conditions in order to allow a video upload:

File Type: MP4 or MOV
Max Time: 2 minutes and 20 seconds
Minimum Resolution: 32 x 32
Maximum Resolution: 1920 x 1200
Aspect Ratios: 1:2.39 - 2.39:1 range (inclusive)
Maximum Frame rate: 40 fps
Maximum Video Bitrate: 25 Mbps

And here you are the general infos about the video I was trying to upload but Twitter kept saying there was a problem while processing it (the infos I got through mediainfo):

General
Complete name                            : tmp03.mp4
Format                                   : MPEG-4
Format profile                           : Base Media
Codec ID                                 : isom (isom/iso2/mp41)
File size                                : 6.71 MiB
Duration                                 : 2mn 15s
Overall bit rate mode                    : Constant
Overall bit rate                         : 417 Kbps
Encoded date                             : UTC 1904-01-01 00:00:00
Tagged date                              : UTC 1904-01-01 00:00:00
Writing application                      : Lavf58.29.100

Video
ID                                       : 1
Format                                   : MPEG-4 Visual
Format profile                           : Simple@L1
Format settings, BVOP                    : No
Format settings, QPel                    : No
Format settings, GMC                     : No warppoints
Format settings, Matrix                  : Default (H.263)
Codec ID                                 : 20
Duration                                 : 2mn 15s
Bit rate mode                            : Constant
Bit rate                                 : 281 Kbps
Width                                    : 720 pixels
Height                                   : 405 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Constant
Frame rate                               : 29.970 (30000/1001) fps
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Compression mode                         : Lossy
Bits/(Pixel*Frame)                       : 0.032
Stream size                              : 4.52 MiB (67%)
Writing library                          : Lavc58.54.100
Encoded date                             : UTC 1904-01-01 00:00:00
Tagged date                              : UTC 1904-01-01 00:00:00

Audio
ID                                       : 2
Format                                   : AAC
Format/Info                              : Advanced Audio Codec
Format profile                           : LC
Codec ID                                 : 40
Duration                                 : 2mn 15s
Duration_LastFrame                       : -19ms
Bit rate mode                            : Constant
Bit rate                                 : 129 Kbps
Channel(s)                               : 2 channels
Channel positions                        : Front: L R
Sampling rate                            : 48.0 KHz
Frame rate                               : 46.875 fps (1024 spf)
Compression mode                         : Lossy
Stream size                              : 2.07 MiB (31%)
Default                                  : Yes
Alternate group                          : 1
Encoded date                             : UTC 1904-01-01 00:00:00
Tagged date                              : UTC 1904-01-01 00:00:00

Can you tell me what's wrong with the video file??

Best regards!

like image 775
Marcelo Augusto Avatar asked Nov 26 '19 17:11

Marcelo Augusto


2 Answers

Twitter does not accept MPEG-4 Part 2 video. This is an old video format. Re-encode to H.264:

ffmpeg -i input.mp4 -c:v libx264 -crf 20 -preset slow -vf format=yuv420p -c:a aac -movflags +faststart output.mp4
  • If you get not divisible by 2 error see this answer.
  • If your input contains AAC audio you can stream copy instead of re-encoding by changing -c:a aac to -c:a copy to preserve the audio quality.
option explanation
-c:v libx264 Chooses video encoder libx264
-crf 20 x264 quality level
-preset slow x264 encoding speed vs compression efficiency preset
-vf format=yuv420p Ensures YUV 4:2:0 chroma subsampling for compatibility
-c:a aac Chooses audio encoder aac
-movflags +faststart Enables fast start: may allow Twitter to begin processing faster
like image 128
llogan Avatar answered Sep 17 '22 22:09

llogan


I tried all the commands from the other answers and non of them worked for me. So, I decided to do my own version:

ffmpeg -i input.mov \
 -vcodec libx264 -pix_fmt yuv420p -strict experimental \
 -r 30 -t 2:20 \
 -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
-strict experimental allows non standardized experimental things, experimental (unfinished/work in progress/not well tested) decoders and encoders
-r 30 sets the frame rate of the output file to 30 fps
-t 2:20 sets the duration to 2:20 mins. after that it will stop writing the output
-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
like image 41
Teocci Avatar answered Sep 18 '22 22:09

Teocci