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?
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.