1

I'm trying to split a video (50-100Mo) into several small clips of a few seconds each. I don't need re-encoding, hence my use of codec copy.

However some of the resulting clips don't have any video.

Fast but no video in some files

ffmpeg \
  -y \
  -i ./data/partie-1:-Apprendre-300-mots-du-quotidien-en-LSF.jauvert-laura.hd.mkv \
  -ss 0:00:07.00 \
  -codec copy \
  -loglevel error \
  -to 0:00:10.36 \
  'raw/0:00:07.00.au revoir.mkv'

I also tried -map 0 -c copy, -acodec copy -map 0:a -vcodec copy -map 0:v or no option related to codec.

Slow but complete

No argument related to audio/video encoding, it's working but pretty slow.

ffmpeg -y \
  -i "$SOURCE_VIDEO_FILE" \
  -ss 0:05:37.69 \
  -to 0:05:40.64 \
  -loglevel error
  'raw/0:05:37.69.pas la peine.mkv'

Question

How do I split a video into small chunk ~2-4s when I have no need for re-encoding?

1

General speaking, you can not split already encoded video into some chunks with arbitrary length without re-encoding.

The simplest way to make a cut is to get content between IDR frames. You could split your video sequence into segments that contain arbitrary number of GOPs (sequence of frames starting with IDR frame with length to next IDR) each. In this case, you could just copy the content without re-encoding.

So, you goal is to find out appropriate IDR frames, that satisfy you clip duration, and make a cut with copy. You lucky ffmpeg use -noaccurate_seek for copy. You could point start position by -ss and duration with -to near IDR.

You could face some challenges here:

  1. original video sequence has a variable GOP length - clip duration won't be the same;
  2. original video sequence has an infinite GOP length (only first frame is IDR) - impossible to split it without re-encoding;

In your example you should move -ss and -to options before -i, because you want to seek start position in the input video.

  • Moving -ss and -to options before -i throws an error: ffmpeg -y -ss 0:00:16.10 -to 0:00:19.11 -i ./file.mkv -acodec copy -vcodec copy -loglevel error 'raw/output.mkv': Option to (record or transcode stop time) cannot be applied to input url ./file.mkv -- you are trying to apply an input option to an output file or vice versa. Move this option before the file it belongs to. – Édouard Lopez Dec 7 '18 at 9:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.