Take the 2-minute tour ×

I have a site that allows people to upload large video files in various formats (avi, mp4, mkv and flv). I need to generate a 1 minute "sample" from the larger file that has been uploaded, and the sample needs to be in the same format, have the same frame dimensions and bit-rate as the original file. Is there a way to simply cut out a section of the file into a new file? Preferably in ffmpeg (or any other tool if ffmpeg is impossible).

share|improve this question
It all depends on where the keyframes are. –  John Gietzen Oct 29 '09 at 1:37
Not sure what you mean... –  user15063 Oct 29 '09 at 3:58

2 Answers 2

up vote 9 down vote accepted

First you'll want to understand how video files actually work. Here's a set of tutorials explaining that: Overly Simplistic Guide to Internet Video.

Then, you can try a variety of tools that may help with slicing out a sample. One is flvtool (if your input is FLV) or FFmpeg. With FFmpeg you can specify a start time and stop time, and it will attempt to cut out just what you ask for (but it will have to find the nearest key-frame to begin slicing at).

Here's the FFmpeg command to read a file called input.flv, start 15 seconds into the video, and then cut out the next 60 seconds, but otherwise keep the same parameters for the audio code and video codec, and write it to an output file:

ffmpeg -i input.flv -ss 15 -t 60 -acodec copy -vcodec copy output.flv

Finally if you want you can write computer code in C or C++ (using FFmpeg's libav libraries) or Java (using Xuggler) to programatically do this, but that's pretty advanced for your use case.

share|improve this answer
great answer, thanks –  Profane Sep 12 '11 at 13:04

If you are having problems keeping auto and video synced up as I was, the following may help (found on another website):

ffmpeg -sameq -i file.flv -ss 00:01:00 -t 00:00:30 -ac 2 -r 25 -copyts output.flv
share|improve this answer

Your Answer

