Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ffmpeg command to create mp4 video sharable to Instagram, etc

I'm creating an mp4 video in my Android application by combining a static 1080x1080 .png image with 24/48 .wav audio, trying to generate a file that is compatible with and can be shared to social media platforms, such as Facebook and Instagram (feed).

When I attempt to share the videos I've created, they load and preview in the Instagram app (tested on both Android and iOS), but after hitting the "Share" button on the final step, the UI returns to my feed and the upload progress immediately switches to "Not Posted Yet. Try Again". If I then tap the retry button, I immediately get a dialog stating "Couldn't Post Video" "There was a problem rendering your video. If this keeps happening, you may have to use another video."

I'm using ffmpeg (via tanersener's mobile-ffmpeg library) to do this.

All of the documentation I've found this far does not show highly specific details for upload requirements for Instagram. I'm using AAC for audio, and h.264 (libx264) for video. The sample I'm using has a duration of 30 seconds. The PNG, as mentioned above, is 1080x1080.

I've taken Android out of the picture by using cmd-line ffmpeg on my Mac with the same input files and testing many variations of parameters, none of which create an uploadable video.

I have a similar .mp4 file created by our iOS app (not using ffmpeg), which I brought over to my Android device and it uploads successfully. I've also sent my .mp4 file to the iOS device and it will not upload, so it seems likely it's an encoding issue of some sort.

I have yet to find a combination of ffmpeg parameters that generate a video that can be successfully shared to Instagram.

Is there a way to get verbose logs from Instagram to have some sort of idea why it's rejecting the files?

This is the ffmpeg command I've been concentrating on:

ffmpeg -i test.wav -i test.png -c:a aac -b:a 256k -ar 44100 -c:v libx264 -b:v 5M -r 30 -pix_fmt yuv420p -preset faster -tune stillimage test.mp4

I've tried all sorts of variations of video and audio bitrates, framerates, scaling, presets, tunes, profiles, etc. But no luck as of yet.

Does anyone have a working ffmpeg command for generating videos for Instagram?

like image 570
Ken Rothman Avatar asked Feb 05 '19 14:02

Ken Rothman


People also ask

Does Instagram use FFmpeg?

This guide describes various FFmpeg encoding presets that can be used to help improve your video quality output when uploading to Instagram. These settings can also be applied to other encoders, such as Handbrake.

Does FFmpeg work with mp4?

FFmpeg can input most container formats natively, including MP4, . ts, MOV, AVI, Y4M, MKV, and many others.


1 Answers

Your visual input is just one frame. I suspect IG doesn't like this. Loop it to make a video stream out of it.

ffmpeg -i test.wav -loop 1 -i test.png -c:a aac -b:a 256k -ar 44100 -c:v libx264 -pix_fmt yuv420p -preset faster -tune stillimage -shortest test.mp4

(Manual bitrate isn't usually necessary for libx264)

like image 109
Gyan Avatar answered Oct 02 '22 08:10

Gyan