7

With ffmpeg I'm converting video from mp3 and picture to upload it to youtube. After upload, conversion fails. Reasons are unknown. I believe the problem is in format. By the way If I'm uploading file 5 minutes length, it fails if I upload 30 seconds of this file it succeeds.

I have donwload mp4 file from youtube. Then I uploaded it, it is done very fast. So a nice solution would be to convert videos to the same format that is done by google.

I got the following output by mpeg:

ffmpeg version N-44264-g070b0e1 Copyright (c) 2000-2012 the FFmpeg developers
  built on Sep  7 2012 17:38:57 with gcc 4.7.1 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-pthreads --enable-runt
ime-cpudetect --enable-avisynth --enable-bzlib --enable-frei0r --enable-libass -
-enable-libcelt --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-l
ibfreetype --enable-libgsm --enable-libmp3lame --enable-libnut --enable-libopenj
peg --enable-librtmp --enable-libschroedinger --enable-libspeex --enable-libtheo
ra --enable-libutvideo --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-li
bvorbis --enable-libvpx --enable-libx264 --enable-libxavs --enable-libxvid --ena
ble-zlib
  libavutil      51. 72.100 / 51. 72.100
  libavcodec     54. 55.100 / 54. 55.100
  libavformat    54. 25.105 / 54. 25.105
  libavdevice    54.  2.100 / 54.  2.100
  libavfilter     3. 16.100 /  3. 16.100
  libswscale      2.  1.101 /  2.  1.101
  libswresample   0. 15.100 /  0. 15.100
  libpostproc    52.  0.100 / 52.  0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'youtubetrack0.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2012-10-02 22:58:57
  Duration: 00:06:46.66, start: 0.000000, bitrate: 176 kb/s
    Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yu
v420p, 450x360, 78 kb/s, 6 fps, 6 tbr, 12 tbn, 12 tbc
    Metadata:
      creation_time   : 1970-01-01 00:00:00
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, s16, 95
kb/s
    Metadata:
      creation_time   : 2012-10-02 22:58:57
      handler_name    : IsoMedia File Produced by Google, 5-11-2011

Is it possible to construct ffmpeg parameters so that that would give the same format that google internally does? Is the information above sufficient?

I couldn't construct needed params.

For example I don't understand how to set tbn and what 95 kb/s mean in "Stream #0:1(und): Audio:".

Now I just do: ffmpeg -i videoimage.jpg -i audio.mp3 video.mp4

Info I've got:

ffmpeg version N-44998-gdf82454 Copyright (c) 2000-2012 the FFmpeg developers
  built on Oct  2 2012 23:03:12 with gcc 4.7.1 (GCC)
  configuration: --disable-static --enable-shared --enable-gpl --enable-version3
 --disable-pthreads --enable-runtime-cpudetect --enable-avisynth --enable-bzlib
--enable-frei0r --enable-libass --enable-libcelt --enable-libopencore-amrnb --en
able-libopencore-amrwb --enable-libfreetype --enable-libgsm --enable-libmp3lame
--enable-libnut --enable-libopenjpeg --enable-librtmp --enable-libschroedinger -
-enable-libspeex --enable-libtheora --enable-libutvideo --enable-libvo-aacenc --
enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --enab
le-libxavs --enable-libxvid --enable-zlib
  libavutil      51. 73.101 / 51. 73.101
  libavcodec     54. 63.100 / 54. 63.100
  libavformat    54. 29.105 / 54. 29.105
  libavdevice    54.  3.100 / 54.  3.100
  libavfilter     3. 19.102 /  3. 19.102
  libswscale      2.  1.101 /  2.  1.101
  libswresample   0. 16.100 /  0. 16.100
  libpostproc    52.  1.100 / 52.  1.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf54.25.105
  Duration: 00:06:46.81, start: 0.000000, bitrate: 129 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuvj420p, 450x360,
 3392 kb/s, 25 fps, 25 tbr, 25 tbn, 50 tbc
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, s16, 127
 kb/s
    Metadata:
      handler_name    : SoundHandler

This video fails the conversion on youtube.

I also tried to use other vcode parmam and extensions of output file (mp4, wmv, avi) but failed too.

Would be greatful for help.

1
  • 2
    Please include the full, uncut console output and the command you were using to genereate the video in the first place. Also, please don't truncate your second output either. While you're at it, please install the latest version of FFmpeg – then we can probably help you further. YouTube will always reencode your video… but following this should help: Advanced encoding specifications
    – slhck
    Oct 4, 2012 at 6:15

2 Answers 2

9

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.

4
  • Thank you very much. I dind't use loop because ffmpeg converted to video without it and it played well in player. It was a mistake. What do you think is it worth to work on parameters of conversion to speed up uploads of such videos? I mean to make resulting videos maximum fit for parameters that converted by google and downloaded mp4 has (if I upload such video, conversion process takes less time)?
    – WHITECOLOR
    Oct 4, 2012 at 9:30
  • Well, you obviously want to supply the best quality content to YouTube so you won't lose as much when they transcode it again. That in turn won't speed up your upload because the file size is huge. YouTube's requirements aren't that hard to fulfill, using -profile:v high might be another option to consider. Personally I would rather wait it out if YouTube really takes a while to encode.
    – slhck
    Oct 4, 2012 at 9:49
  • Thank you. I reduced fps to 1, video size and conversion time (on youtube) become 30% less. If to reduce fps more, however put it much less then 1, it does not give more effect. Can you explain this?
    – WHITECOLOR
    Oct 4, 2012 at 11:02
  • Maybe YouTube converts it back to 1 fps? Maybe there's a lower boundary on how long it takes to encode a video depending on a certain frame rate. I'm not sure if there are any constraints but it would make sense from a compatibility standpoint. I know MPEG-2 restricts frame rates to certain values, MPEG-4 Part 10 (h.264) doesn't IIRC.
    – slhck
    Oct 4, 2012 at 11:11
10

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/

3
  • The options specified in the link you provided are slightly different now than what you have here.
    – Baodad
    Apr 14, 2017 at 13:16
  • True, for some reason I had to use -bf 1, instead of -bf 2 or the video would get transcoded by YouTube. Maybe nowadays it doesn't matter, try it with a short sample video. The -crf parameter is just for quality of encode, I simply could tolerate a lower quality encode to lower file size.
    – Moshev
    Apr 18, 2017 at 13:27
  • My experience with this is that YouTube currently transcodes everything regardless and that what these settings are really good for is to speed up that process -- and they do work well for that (regardless of bf setting). Thus, the crf setting can't save you from transcoding so you might as well set it for as high a quality as you need in case YouTube decides to do a better transcode from your original someday (which does happen as codecs improve).
    – juanitogan
    May 22, 2018 at 20:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .