1

In my app I would like to split a selected video from the gallery into smaller pieces of the same length. For example, if I want to split a 25 second video into pieces of up to 10 seconds, I would get 3 videos (10 sec, 10 sec, 5 sec).

So far I found this answer on Stack Overflow that allows me to just choose the beginning and end of a video.

How can I use MediaCodec to achieve my goal?

GTR - Vitor
  • 123
  • 1
  • 1
  • 6

1 Answers1

0

To produce segments of exact duration you would need to re-encode the video and possibly the audio track using pairs of decoders and encoders (instances of MediaCodec) along with a MediaExtractor and a separate MediaMuxer for each output segment.

Each time you reach the end of a segment (looking at the presentation time of the frame) you would send an end-of-stream signal to the encoder and then restart it.

For audio you would also need to split some of the decoded buffers at the segment boundaries.

dev.bmax
  • 8,998
  • 3
  • 30
  • 41