Is there a way to split a video into segments of specified length? Ie 60 minute video into 12x5 mins.
It seems the "official" way to do this without reencoding and without losing frames is using the splitmuxsink
element:
For example for a MKV file input:
gst-launch-1.0 filesrc location=input.mkv ! matroskademux ! h264parse ! splitmuxsink location=file%02d.mkv max-size-time=300000000000 muxer=matroskamux
The max-size-time
gives the segment length in nanoseconds (sic), so the above value is 5 minutes. Because it cuts on keyframes, the real segment length will not be exactly 5 min but will vary by a few seconds.
Afaik, you will need to develop your own "segmenter". This is similar to what you need to create HTTP Live streaming files. There might be a simpler solution, but here is what I would do:
You can make a relative small program (in python) using multifilesink next-file=buffer (or next-file marker, if segments can't fit in memory).
You'll need to encode or demux your input stream, and mux the stream back. Cut the muxed stream on key-frame when the desired duration is reached, and push the aggregated buffer (or mark a fake key frame, for example, to force sink to create a new file). Reinitialize the muxer (or append muxer streamheader) to get file with correct header than can be played seperately (depending on the muxer).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With