java - java中的MP4视频压缩器
问题描述
谁能建议我一个好的压缩器或第三方库来从服务器端压缩 MP4 视频(我正在使用 Spring MVC)。
我了解了 FFMPEG 和 Xuggler,除此之外,任何维护的压缩器都可以在 java 中使用。请给我建议或链接。
解决方案
使用 FFMPEG 包装器来压缩视频。这是下载链接:https ://www.ffmpeg.org/download.html
github:https ://github.com/bramp/ffmpeg-cli-wrapper
这里的代码:
ffmpeg = new FFmpeg("D:/ffmpeg-20180429-cae6f80-win32-static/ffmpeg-20180429-cae6f80-win32-static/bin/ffmpeg");
ffprobe = new FFprobe("D:/ffmpeg-20180429-cae6f80-win32-static/ffmpeg-20180429-cae6f80-win32-static/bin/ffprobe");
FFmpegBuilder builder = new FFmpegBuilder()
.setInput(input) // Filename, or a FFmpegProbeResult
.overrideOutputFiles(true) // Override the output if it exists
.addOutput(output) // Filename for the destination
.setFormat("mp4") // Format is inferred from filename, or can be set
// .setTargetSize(250_000) // Aim for a 250KB file
.disableSubtitle() // No subtiles
.setAudioChannels(1) // Mono audio
// .setAudioChannels(2)
.setAudioCodec("aac") // using the aac codec
.setAudioSampleRate(48_000) // at 48KHz
.setAudioBitRate(32768) // at 32 kbit/s
// .setAudioBitRate(126000)
.setVideoCodec("libx264") // Video using x264
.setVideoFrameRate(24, 1) // at 24 frames per second
.setVideoResolution(1280, 720) // at 640x480 resolution
// .setVideoResolution(1024, 768)
// .setVideoResolution(640, 480)
.setVideoBitRate(762800)
.setStrict(FFmpegBuilder.Strict.EXPERIMENTAL) // Allow FFmpeg to use experimental specs
.done();
FFmpegExecutor executor = new FFmpegExecutor(ffmpeg, ffprobe);
executor.createJob(builder).run(); // Run a one-pass encode
推荐阅读
- reactjs - 如何在nextjs中第一次显示reactour?
- sql - 授予 SQL 用户查询和修改数据库能力的最低权限
- css - 完成所有集成过程后,Tailwindcss 在 Vue.js 中不起作用?
- python - 安装程序仅在并行运行时运行一次
- java - 仅在值之间使用分隔符打印
- flutter - Flutter Run 不工作,在 iPhone 上启动应用程序时出错
- git - 与 Unix 组共享 git-annex 存储库
- python - 如何将for循环更改为while循环
- unity3d - 当旋转由统一 3D 中的鼠标位置确定时,如何在更新中 Mathf.Clamp 一个轴 y
- angular - 使用 moment.js 将日期转换为可以发送到数据库的良好格式