【问题标题】:MP4 Video Compressor in java [closed]java中的MP4视频压缩器[关闭]
【发布时间】:2018-04-26 12:01:35
【问题描述】:

谁能推荐我一个好的压缩器或第三方库来从服务器端压缩 MP4 视频(我正在使用 Spring MVC)。

我了解了 FFMPEG 和 Xuggler,除此之外还有任何维护的用于在 java 中使用的压缩器。请给我一些建议或链接。

【问题讨论】:

  • 选择 FFMPEG,它的开源并且有据可查,它还具有 h264 和 h265 视频编码器,因此您也可以选择适合您要求的编码器。了解更多信息 (ffmpeg.org/ffmpeg-all.html)
  • 感谢您的回复。我会通过你建议的链接。
  • 不客气建议你使用 FFMPEG,因为它很容易使用,其余取决于你的选择
  • 您有任何示例链接吗?如果你有请在这里发帖。

标签: java compression mp4 video-compression


【解决方案1】:

使用 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

【讨论】:

    【解决方案2】:

    看看jcodec

    https://github.com/jcodec/jcodec

    它具有 H.264 主要配置文件解码器和 H.264 基线配置文件编码器,并支持 MP4 复用器/解复用器。

    另外,您可以考虑使用基于 OSS C 的解决方案并尝试使用 C->Java 转换器。这可能是一项艰巨的任务,但会有很多好的库。

    【讨论】:

    • 正如您在项目的 GitHub 页面上看到的,最新提交是在 2018 年 3 月 15 日完成的。所以,是的,它似乎并没有死。
    • FFMPEG 的最后一次提交是在 2018 年 4 月 26 日
    • @MikhailKholodkov 没有压缩的例子,我也用谷歌搜索过。你能把例子的链接发给我吗(jcodec)。
    • 您需要使用 SequenceEncoder 类。我没有关于这个主题的示例,但现在在 Stackoverflow 上搜索 SequenceEncoder。
    猜你喜欢
    • 1970-01-01
    • 2012-08-09
    • 1970-01-01
    • 1970-01-01
    • 2017-11-29
    • 1970-01-01
    • 2015-04-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多