Help, converting with FFMPEG

Hi to all.

I am not tottally illiterate for video files, I do know that mp4, flv, avi and other formats are containers and that h264, mpeg2 etc are encodings. Well, that is about it.
What I do not know is when to use which, etc, but this is out of the scope.

I have a camera with which I make my videos, and I need 2 converts, one for safekeeping and making DVD sometimes, and other to post to Youtube.

So, lets go:

INPUT: (from camera)

Video: mpeg2video, yuv420p, 720x576 [PAR 64:45 DAR 16:9], 9100 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc
Audio: ac3, 48000 Hz, stereo, s16, 256 kb/s

Now… I found that bitrate 4096k is good for safekeeping and 2048k for youtube.

I use:
***ffmpeg -i INPUTFILE.MPG -b 4096k -f mp4 -ar 44100 -ac 2 -acodec aac OUTPUT.mpg

(for youtube, I just change bitrate to 2048k)

example: in this case, when input file size is ~370 MB, bitrate 4096k gives me 177 MB output, and bitrate 2048k gives 90 MB.

I tried adding -vcodec libx264 -vpre=hp but besides MUCH longer worktime, nothing much is gained.

So, my question is:
Is there some better way to convert video, using some other codecs, bitrates or other parameters where (in both cases I need good quality/size ratio):

  1. for safekeeping I need quality to be DVD-TV watchible and less size possible for maintaining that quality

  2. less size possible, but not to be fuzzy… lets say… youtube quality… lol


I’m not in to using the command line with detailed ffmpeg where a GUI is easier. (having typed that, I do use ffmpeg where a GUI based program does not easily do what I want).

I note your format is close to the DVD pal resolution. Did you check to see if the application “tovid” (packaged by Packman) would provide what you wanted? A tovid command:

tovid -dvd -pal -normalize -quality 9 -in INPUT.MPG -out OUTPUT

and tovid will output a DVD compliant MPEG.

Or you could try WinFF (packaged by packman). The beauty of WinFF is it has many preset configurations you can select from a drop down menu, and it also gives you the exact ffmpeg command it is going to use, so that you can instead take that command and send it from a command line.

But if your desired output format does NOT have to be MPEG, then its hard to beat microchip’s scripts h264enc, xvidenc, and divxenc. h264enc will likely give the best quality/size ratio, but it will be the slowest to encode. I have used xvidenc for many of my videos.

You can get those from microchips respository. For example for 11.2:

Add his repository, install the scripts, and remove the repository.

For example, to use xvidenc:

xvidenc -2p -p uhq

and after specifying “file” and the input and output video in the 1st three steps (and one MUST be exact here) then simply choose default settings (press <enter> ) for most of the rest.

My camera is PAL, and most DVD stuff I watch in both PAL and NTSC. I use DeVeDe for making DVDs, so it is no big deal.

WinFF was bad, but that was 6 months ago when I tried.
will try with xvidenc

anyways, what are best params for youtube?

WinFF works great now. Take a look at this thread from post #49 and onward: *(

The videos I upload for youtube typically come straight from kdelive (mp4 or m2t) with at 1280x720 resolution with 8M bit rate.

Note this page: Optimizing your video uploads : Getting Started - YouTube Help

Example video:

Here is an example of a video where the intermediary output came from tovid (before editing with kdenlive):*


But, I’ve seen that page for youtube. Tells me nothing. By them bitrate of 9100k is the same as 2048… difference is just 1-10 GB in size.

It tells you nothing? I can not understand that.

It tells me a LOT. It tells me:

  • use these containers: FLV, MPEG-2, and MPEG-4 . It then goes on to say these codecs: H.264 or MPEG-2 preferred.
  • I tells me "The frame rate of the original video should be maintained without re-sampling. In particular pulldown and other frame rate re-sampling techniques are strongly discouraged.
    " which means do not re-encode a zillion times.
  • For resolution it recommends: 1920x1080 (1080p) or 1280 x 720.
  • It provides similar guidance for audio

If that tells you NOTHING then unfortunately there is also nothing I can pass to you. >:(

For me it says everything. :\

Oh sorry, yes, id does tell codec and audio, container and max size for HD…

and nothing for LD… low grade, resolution, bitrate recommended etc. That is why I asked for optimal settings based on expirience.

I do not know what you mean there.

It gives this recommendation for bit rate:

Because bit-rate is highly dependent on codec there is no recommended or minimum value. Videos should be optimized for resolution, aspect ratio and frame rate rather than bit rate.
I’ve uploaded videos with bitrates as high as 8Mb/sec.

Oh yes, it can be done, I did with 9.1 Mb/s, but file takes too long to upload as it is immense.

My original question. to be more clear is:

Based on expirience, what is the best codec/container/bitrate/video_size to get good quality and less file size.

I see no difference, after upload, of PAL size and 640x360, no difference between 4Mb/s and 9Mb/s.
I found that one can get good quality with sizes 640x360 and bitrate 2048k.

Now… what would be better? MP4 or MP2? Which Bitrate? AAC or MP3? XVID,DVD or H264?
(all based on expirience).

My FFMPEG settings for Youtube are now:

ffmpeg -i INPUTFILE.MPG -s 640x360 -b 2048k -f mp4 -ar 44100 -ac 2 -acodec libmp3lame -ar 128k OUTPUT.mpg

(I am not fond of using WinFF, xvidconv)

What are (based on your expirience) optimal for youtube? (question is for all who read this)

Did you try downloading your 9.1M b/s file from youtube (after they have converted it) and see what bitrate they produce after their re-encoding ?

That might give you a better idea as to what you should upload.

Hmmm that is the idea… I never thought of that!

Well, here it is. Script that converts video to exactly how youtube resamples it, so you dont have to upload more megs than necessary

#Youtube optimized
VIDEO_OPTIONS="-b 512k -f mp4 -s 480x270 -vcodec libx264 -vpre hq";
AUDIO_OPTIONS="-ar 44100 -ac 2 -ab 93k -acodec aac";


For who doesn’t know shell…
save it as youlike , let’s say “”
execute: chmod +x

usage: ./youtubeconv IN_FILE.whatever OUT_FILE.mp4

Notice size: 480x270… that is if original is pal/ntsc, if you have another aspect ratio, lets say 1024x768, your new size will be

480 * X = 1024 * 768
X = (480*768)/1024
X = 360

so your video size (-s parameter) should be 480x360.

Calculate for any aspect, but 480 Width should be fixed.

Glad to read it works for you.

I downloaded my video referenced above from youtube, where youtube had converted the video. Here are some of the specs on the youtube converted video (ie after youtube conversion):

Video Codec ID: avc1
Video format: H264
Video Resolution: 1280x720
Video Bit rate: 1994 Kpbs
Video Max bit rate: 6282 kbps
Audio Codec: AAC
Audio bit rate: 125 Kbps
Max Audio bit rate; 145 kbps

Hence I think the quality of the youtube video download varies according to the quality of the upload.

I agree, but if you do not want HD, whatever you upload will be in standard container, as I see with width 480 as bigger or 360 as smaller container.
Difference, as it opens here, is on fullscreen mode.

Maybe youtubes conversion depends on an input, as you say, but I tried uploading PAL resolution, with 9100 kbps and audio AAC 256bit, and still, it converted it to settings above…

Who knows what’s in the mind of conversion AI? :slight_smile:

Can’t help much with the youtube movies, but for encoding to dvd you could try -target option. So if you would want to encode to pal-dvd, you would enter:

ffmpeg -i INPUT -target pal-dvd OUTPUT

ffmpeg will use all the settings that are ideal for creating dvd movies. You can change the standard options just by adding them to the command.

You can also set the size of the video file for hd with the size option.

ffmpeg -i INPUT -s hd480 OUTPUT

You can use hd480, hd720 and hd1080

Oh, that is useful!
thank you!

A good site to get the basics of ffmpeg is ffmpeg audio/video manipulation.

Also found this command on FFmpeg made easy | TuxRadar Linux

$ ffmpeg -i INPUT -ar 22050 -acodec libmp3lame -ab 32K -r 25 -s 320x240 -vcodec flv OUTPUT

Don’t know if it’s any use to you, but hope it helps.

Definately helps. Big thanks!