Can you splice a 1 min clip out of a larger file, without transcoding it?

user15063 picture user15063 · Oct 29, 2009 · Viewed 9.4k times · Source

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

Answer

Art Clarke picture Art Clarke · Nov 6, 2009

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.