Android(java方法)上实现mp4的分割和拼接 (二).pdf
本节讲述如何在android上实现对mp4文件的高效剪切。业务需求示例:将一个2分钟的mp4文件从00:42到01:16剪成视频,需要足够短的执行时间和尽可能少的错误。
分析:mp4Parser 只能在关键帧处剪切。例如,如果在 00:40 和 00:45 有一个可剪切的关键帧,那么剪切视频的头部和尾部应该被剪短。然后有错误的视频很短。如果误差大于0.5S,则使用FFmpeg逐帧对文件进行编码和解码。这样一来,mp4文件最多会有三段,你可以将这三段mp4重新拼接起来。
下面直接列出关键代码。这些代码也可以通过在PC上新建一个java项目来实现。
(This section describes how to cut MP4 files efficiently on Android.
Business requirement example: cutting a 2-minute MP4 file from 00:42 to 01:16 into video requires short enough execution time and as few errors as possible.
Analysis: mp4parser can only cut at keyframes. For example, if there is a cutable key frame at 00:40 and 00:45, the head and tail of the cut video should be cut short. Then the video with errors is very short. If the error is greater than 0.5s, ffmpeg is used to encode and decode the file frame by frame. In this way, the MP4 file can have up to three segments, and you can splice these three segments together again.
Key codes are listed directly below. These codes can also be implemented by creating a new Java project on the PC.)
页:
[1]