Make exact mp4 (H264) format for uploading to youtube

Solution 1:

YouTube should be able to use almost anything you feed to it. It will always transcode your video no matter what exact formats you supply – for example because it needs to provide different resolutions or other containers such as FLV or WebM for your video, even if it's in an MP4 container when uploaded.

A basic command to produce video for YouTube would be:

ffmpeg -i input.avi -c:v libx264 -c:a aac -strict experimental -b:a 192k out.mp4

You'll just have to change the quality, and eventually framerate with -r and video size with -s:v to match the advanced encoding specifications, so your video is not pillar- or letterboxed (i.e. with black borders).

For more options and a general introduction to FFmpeg, please read our blog entry: FFmpeg: The ultimate Video and Audio Manipulation Tool


But you're creating a video with one image that loops, so you need to tell FFmpeg to loop the image with -loop 1 for the amount of time specified by -t, e.g. 5 minutes:

ffmpeg -loop 1 -f image2 -i image.jpg -c:v libx264 -t 00:05:00.000 out.mp4

With an audio stream, just add the second -i parameter:

ffmpeg -loop 1 -f image2 -i image.jpg -i audio.mp3 -c:v libx264 -c:a aac -strict experimental -b:a 192k -t 00:05:00.000 out.mp4

FFmpeg will then map the streams automatically, your image to h.264 video and your audio to AAC:

Stream mapping:
  Stream #0:0 -> #0:0 (mjpeg -> libx264)
  Stream #1:0 -> #0:1 (mp3 -> aac)

This video should be compatible with YouTube, with a frame rate of 25. If you want to change that, use -r and set another frame rate. I've successfully uploaded video to YouTube with a frame rate of 1 – because it doesn't really matter if you have just one image and an audio track in the background looping.

Solution 2:

These options work for me, as in: the video doesn't undergo further processing/re-encoding by youtube after upload.

ffmpeg -i SOURCE -c:v libx264 -flags:v "+cgop" -g 15 -bf 1 -coder ac -profile:v high -crf 25 -pix_fmt yuv420p -c:a aac -strict -2 -b:a 384k -r:a 48000 -movflags faststart OUTPUT.mp4

You might want to try -bf 2 instead of 1, but it resulted in re-encode in my test. To get higher video quality, lower the -crf setting, generally 20-28 is the recommended range with lower values producing higher quality. I haven't tried doing two-pass encoding, cbr or abr, but it should work. You can also lower the audio to 192k bitrate.

IMPORTANT: Note that you'll need to set -g X to be half of your frame rate. In this example I'm encoding a 30fps video so I've set GOP to 15. If your source is 24fps, set it to 12, if it's 60fps, set it to 30.

I know this is an old question, but it's the first result on Google when you search for "ffmpeg options for youtube".

Edit: I got these options from https://www.virag.si/2015/06/encoding-videos-for-youtube-with-ffmpeg/