1. 功能
从原始视频中均匀抽取一部分帧,合成新的视频文件。
2. 优点
降低原始视频的存储量大小,精简保存。
3. 缺点
丢帧太多的话,会导致视频播放过程中花屏,甚至视频无法播放。
4. 代码
(基于mp4parser的代码来做的)
import org.mp4parser.Container;
import org.mp4parser.IsoFile;
import org.mp4parser.muxer.Movie;
import org.mp4parser.muxer.Track;
import org.mp4parser.muxer.builder.DefaultMp4Builder;
import org.mp4parser.muxer.container.mp4.MovieCreator;
import org.mp4parser.muxer.tracks.AppendTrack;
import org.mp4parser.muxer.tracks.ClippedTrack;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
/**
* Removes some samples in the middle
* Suppose newFrameRate == m, and frameRate == n
* If m < n, then we take m frames of one second on average to create the new video.
*/
public class DecreaseFPS {
public static void main(String[] args) throws IOException {
//String audioEnglish = RemoveSomeSamplesExample.class.getProtectionDomain().getCodeSource().getLocation().getFile() + "/count-english-audio.mp4";
String srcVideoPath = "test.mp4";
String dstVideoPath = "removeSampleOutput.mp4";
removeFrames(srcVideoPath, dstVideoPath);
}
public static void removeFrames(String srcVideoPath, String dstVideoPath) throws IOException {
double videoDuration = getDuration(srcVideoPath);
Movie originalMovie = MovieCr

本文介绍了如何利用mp4parser库从视频中抽帧并降低帧率,以此减小视频存储量。虽然可能导致播放质量问题,但提供了具体的实现代码。在操作过程中遇到内存溢出和帧拼接问题,并给出了临时解决方案。
1万+

被折叠的 条评论
为什么被折叠?



