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

10,280

Solution 1

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.

Solution 2

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

Solution 3

As Evan notes, the approach in the accepted answer can result in loss of A/V sync. However his solution is not correct because -sameq was removed.

As stated at https://trac.ffmpeg.org/wiki/Seeking the -ss option should come before -i not after. This fixed the issue for me.

Share:
10,280
Admin
Author by

Admin

Updated on June 09, 2022

Comments

  • Admin
    Admin about 2 years

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

  • Adam Spiers
    Adam Spiers over 9 years
    -sameq was removed - see my answer.
  • Adam Spiers
    Adam Spiers over 9 years
    This can result in A/V sync issues - see my answer.
  • Sridhar Sarnobat
    Sridhar Sarnobat almost 5 years
    ...not to be confused with ffplay -fs (which means play a video in full screen)!