Thursday, March 3, 2011

encode avi with given output file size

I have an avi file which i want to re-encode to fit on a cd of 650 mb how can i encode it, so that the file size does not succeed the given size, what program to use?

From stackoverflow
  • AutoGK can do this very effectively. Primarily designed for DVD **cough** backup purposes, but it will also accept AVI as source. It's more of a collection of opensource programs with a co-ordinating GUI, so don't worry when the installer installs several items.

  • I assume you want to do this programmatically:

    For Windows:

    You can use directshow to transcode your video by building a filter graph.

    Get (if you don't already have) the platform SDK for windows. Then browse here to check out some of the directshow examples which construct filter graphs for transcoding.

    To build you will need the base classes. You can build them here:

    C:\Program Files\Microsoft SDKs\Windows\v6.1\Samples\Multimedia\DirectShow\BaseClasses
    

    Then check out the examples here:

    C:\Program Files\Microsoft SDKs\Windows\v6.1\Samples\Multimedia\DirectShow
    

    You can also manually create filter graphs to get a hang for how they are used and see how these things make sense (such as the enumeration of the encoders you will learn about in the examples):

    C:\Program Files\Microsoft SDKs\Windows\v6.1\Bin\graphedt.exe
    

    Once you have gone this far and understand how directshow works you can use some math to figure out how to transcode your video to fit in the size you want. To do this you may want to look at how many frames/sec your input video is and how big each frame is.

    Different encoders work in different ways:

    Lets assume you are transcoding avi file to a smaller or lesser quality avi file. Look at your input frame sizes and fps to determine the whole file size, then use some algebra to figure how to either reduce frame size or reduce # of frames per second (or a combination of both) to achieve the desired size (which can be your input variable).

    As for other encoders you may want to see how they work. Lossy encoders such as mp4 perform estimations to find out what video has changed from frame to frame- and that information is stored in the file to reconstruct frames. You will have to read about how they work - or check to see how to use your particular encoder for more details.

    For Linux (and also windows):

    You can use ffmpeg which is an all-in-one for transcoding and other things to video. You can even find prebuilt exe of the command line application, although the main page does not host it (just the source). This application uses open source video libraries to do a lot of the video transcoding as well as many other things. If you can locate a good dependable exe file you should probably check this out if you want something that is easy to use for your application. Check out their homepage here.

    I hope this gets you started.

  • To make it fit a specific size, you must use an appropriate bit-rate.

    For fixed bit-rate video, to get the target bit-rate you would take the target size, in bits, and the length of the source in seconds.

    target bit-rate = size / seconds
    

    For example:

    seconds = (90mins * 60) = 5400
    size = ((650MB * 1024) * 8) = 5324800
    target bit-rate = ~986 kilobytes per second
    

    With variable bit-rate, things are rather more complicated. Not quite sure if there's a way to accurately make the output file a set size. The easiest way is to calculate the maximum bit-rate using the above method,

  • Calculate the number of seconds the AVI is. Then, take the file size and divide by the length. Convert to kilobits per second, and use that as your bitrate median. (Use Google to do the math and conversion easily.)

    You can weigh the video and audio bitrates as you desire. Usually 96 kbps is good enough with AAC, but you may want more or less. Experiment.

0 comments:

Post a Comment