views:

205

answers:

1

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).

+1  A: 

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.

Xuggle