Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Java wrapper around the FFmpeg command line tool

License

NotificationsYou must be signed in to change notification settings

bramp/ffmpeg-cli-wrapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

by Andrew Brampton (bramp.net) (c) 2013-2024

"Buy Me A Coffee"

A fluent interface for running FFmpeg from Java.

JavaBuild StatusCoverage StatusMavenLibraries.io

GitHub |API docs

Install

We currently support Java 8 and above. Use Maven to install the dependency.

<dependency>  <groupId>net.bramp.ffmpeg</groupId>  <artifactId>ffmpeg</artifactId>  <version>0.8.0</version></dependency>

Usage

Video Encoding

Code:

FFmpegffmpeg =newFFmpeg("/path/to/ffmpeg");FFprobeffprobe =newFFprobe("/path/to/ffprobe");FFmpegBuilderbuilder =newFFmpegBuilder()  .setInput("input.mp4")// Filename, or a FFmpegProbeResult  .done()  .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();FFmpegExecutorexecutor =newFFmpegExecutor(ffmpeg,ffprobe);// Run a one-pass encodeexecutor.createJob(builder).run();// Or run a two-pass encode (which is better quality at the cost of being slower)executor.createTwoPassJob(builder).run();

Get Media Information

Code:

FFprobeffprobe =newFFprobe("/path/to/ffprobe");FFmpegProbeResultprobeResult =ffprobe.probe("input.mp4");FFmpegFormatformat =probeResult.getFormat();System.out.format("%nFile: '%s' ; Format: '%s' ; Duration: %.3fs",format.filename,format.format_long_name,format.duration);FFmpegStreamstream =probeResult.getStreams().get(0);System.out.format("%nCodec: '%s' ; Width: %dpx ; Height: %dpx",stream.codec_long_name,stream.width,stream.height);

Get progress while encoding

FFmpegExecutorexecutor =newFFmpegExecutor(ffmpeg,ffprobe);FFmpegProbeResultin =ffprobe.probe("input.flv");FFmpegBuilderbuilder =newFFmpegBuilder() .setInput(in)// Or filename .done() .addOutput("output.mp4") .done();FFmpegJobjob =executor.createJob(builder,newProgressListener() {// Using the FFmpegProbeResult determine the duration of the inputfinaldoubleduration_ns =in.getFormat().duration *TimeUnit.SECONDS.toNanos(1);@Overridepublicvoidprogress(Progressprogress) {doublepercentage =progress.out_time_ns /duration_ns;// Print out interesting information about the progressSystem.out.println(String.format("[%.0f%%] status:%s frame:%d time:%s ms fps:%.0f speed:%.2fx",percentage *100,progress.status,progress.frame,FFmpegUtils.toTimecode(progress.out_time_ns,TimeUnit.NANOSECONDS),progress.fps.doubleValue(),progress.speed  )); }});job.run();

Building & Releasing

If you wish to make changes, then building and releasing is simple:

# To buildmvn# To testmvntest# To release (pushing jar to maven central)# (don't forget to set up your ~/.m2/settings.xml)mvn release:preparemvn release:perform# To publish javadocgit checkout ffmpeg-0.xmvn clean javadoc:aggregate scm-publish:publish-scm

Bumpings Deps

# Update Maven Pluginsmvn versions:display-plugin-updates# Library Dependenciesmvn versions:display-dependency-updates

Install FFmpeg on Ubuntu

We only the support the original FFmpeg, not the libav version. Before Ubuntu 12.04, and in 15.04and later the original FFmpeg is shipped. If you have to run on a version with libav, you can installFFmpeg from a PPA, or using the static build. More informationhere

Get involved

We welcome contributions. Please check theissue tracker.If you see something you wish to work on, please either comment on the issue, or just send a pullrequest. Want to work on something else, then just open a issue, and we can discuss! We appreciatedocumentation improvements, code cleanup, or new features. Please be mindful that all work is doneon a volunteer basis, thus we can be slow to reply.

Licence (Simplified BSD License)

Copyright (c) 2013-2024, Andrew BramptonAll rights reserved.Redistribution and use in source and binary forms, with or withoutmodification, are permitted provided that the following conditions are met:* Redistributions of source code must retain the above copyright notice, this  list of conditions and the following disclaimer.* Redistributions in binary form must reproduce the above copyright notice,  this list of conditions and the following disclaimer in the documentation  and/or other materials provided with the distribution.THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THEIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AREDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLEFOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIALDAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS ORSERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVERCAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USEOF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

About

Java wrapper around the FFmpeg command line tool

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

  •  

Packages

No packages published

Contributors28


[8]ページ先頭

©2009-2025 Movatter.jp