磊玲2015的gravatar头像
磊玲2015 2016-08-22 13:59:26

java如何实现对上传的视频进行拆分和提取前5分钟视频?

java实现对上传的视频进行处理。例如:我现在上传一个时间为20分钟的一个视频,现在要求将此视频拆分为两个,一个保留原来视频,另一个是提取此视频的前5分钟 该怎么做

所有回答列表(1)
最代码官方的gravatar头像
最代码官方  LV167 2016年8月22日

之前在调研视频课堂的转码技术时在github上发现了一个java封装ffmpeg实现的开源视频处理框架

bramp/ffmpeg-cli-wrapper

你可以参考下是否满足你的需求。

FFmpeg ffmpeg = new FFmpeg("/path/to/ffmpeg");
FFprobe ffprobe = new FFprobe("/path/to/ffprobe");

FFmpegBuilder builder = new FFmpegBuilder()

  .setInput("input.mp4")     // Filename, or a FFmpegProbeResult
  .overrideOutputFiles(true) // Override the output if it exists

  .addOutput("output.mp4")   // 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
    .setAudioCodec("aac")        // using the aac codec
    .setAudioSampleRate(48_000)  // at 48KHz
    .setAudioBitRate(32768)      // at 32 kbit/s

    .setVideoCodec("libx264")     // Video using x264
    .setVideoFrameRate(24, 1)     // at 24 frames per second
    .setVideoResolution(640, 480) // at 640x480 resolution

    .setStrict(FFmpegBuilder.Strict.EXPERIMENTAL) // Allow FFmpeg to use experimental specs
    .done();

FFmpegExecutor executor = new FFmpegExecutor(ffmpeg, ffprobe);

// Run a one-pass encode
executor.createJob(builder).run();

// Or run a two-pass encode (which is slower at the cost of better quality)
executor.createTwoPassJob(builder).run();

ffmpeg是可以实现视频提取的

//从00:00:00截取00:01:00的视频,视频和音频格式保持
ffmpeg -ss 00:00:00 -i 2843238156110848.wmv -acodec copy -vcodec copy -t 00:01:00 2843238156110848_clip.wmv

如果该框架不支持,你可以根据源码自行实现该方法。

顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友