Coder Social home page Coder Social logo

ffmpeg-cli-wrapper's Introduction

FFmpeg CLI Wrapper for Java

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

"Buy Me A Coffee"

A fluent interface for running FFmpeg from Java.

Java Build Status Coverage Status Maven Libraries.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:

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 better quality at the cost of being slower)
executor.createTwoPassJob(builder).run();

Get Media Information

Code:

FFprobe ffprobe = new FFprobe("/path/to/ffprobe");
FFmpegProbeResult probeResult = ffprobe.probe("input.mp4");

FFmpegFormat format = probeResult.getFormat();
System.out.format("%nFile: '%s' ; Format: '%s' ; Duration: %.3fs", 
 format.filename,
 format.format_long_name,
 format.duration
);

FFmpegStream stream = 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

FFmpegExecutor executor = new FFmpegExecutor(ffmpeg, ffprobe);

FFmpegProbeResult in = ffprobe.probe("input.flv");

FFmpegBuilder builder = new FFmpegBuilder()
 .setInput(in) // Or filename
 .addOutput("output.mp4")
 .done();

FFmpegJob job = executor.createJob(builder, new ProgressListener() {

 // Using the FFmpegProbeResult determine the duration of the input
 final double duration_ns = in.getFormat().duration * TimeUnit.SECONDS.toNanos(1);

 @Override
 public void progress(Progress progress) {
  double percentage = progress.out_time_ns / duration_ns;

  // Print out interesting information about the progress
  System.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 build
mvn

# To test
mvn test

# To release (pushing jar to maven central)
# (don't forget to set up your ~/.m2/settings.xml)
mvn release:prepare
mvn release:perform

# To publish javadoc
git checkout ffmpeg-0.x
mvn clean javadoc:aggregate scm-publish:publish-scm

Bumpings Deps

# Update Maven Plugins
mvn versions:display-plugin-updates

# Library Dependencies
mvn 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.04 and later the original FFmpeg is shipped. If you have to run on a version with libav, you can install FFmpeg from a PPA, or using the static build. More information here

Get involved

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

Licence (Simplified BSD License)

Copyright (c) 2013-2024, Andrew Brampton
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, 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, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

ffmpeg-cli-wrapper's People

Contributors

blakehawkins avatar borismcfishtank avatar bramp avatar dama-de avatar davinkevin avatar dazito avatar dependabot[bot] avatar easyg0ing1 avatar euklios avatar handokochen avatar igracia avatar jinukix avatar luca992 avatar mandrakey avatar nsilberman avatar orthlus avatar psiniemi avatar reutsharabani avatar st-h avatar stonio avatar sverkera avatar van1164 avatar waisbrot avatar xmg333 avatar yermak avatar zeeshanasghar avatar ziodave avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ffmpeg-cli-wrapper's Issues

Change -v to be configurable

Hi! You in library in the class FFmpegBuilder, have such line:

args.add (" - v", "error");//TODO make configurable

Here take and transfer it a line, and better generally delete because in ffmpeg there is no such option! And because of this error it isn't written stry to the file because ffmpeg tries to understand that for an option such. When manually I take request which collected your class and I insert into the linux console and I clean parameter - v error, everything works.

Examples good quality ogv and webm?

I'm taking a very large mp4/mov file and I want to transcode it into three different formats for cross browser compatibility. I also watermark the video. First I create a smaller watermarked mp4 with h264, and it looks great;

FFmpegBuilder builder = new FFmpegBuilder()

    .setInput(inVideo)     // Filename, or a FFmpegProbeResult
    .addInput(sampleWatermarkImg)
    .overrideOutputFiles(true) // Override the output if it exists
    .addOutput(destFile)   // Filename for the destination
    .setFormat("mp4")        // Format is inferred from filename, or can be set
    .setVideoCodec("libx264")     // Video using x264
    .setVideoFrameRate(24, 1)     // at 24 frames per second
    .setVideoResolution( iwidth , newHeight) // at 640x480 resolution
    .setComplexVideoFilter("\"overlay=main_w-overlay_w-10:main_h-overlay_h-10\"")
    .setStrict(FFmpegBuilder.Strict.EXPERIMENTAL) // Allow FFmpeg to use experimental specs
    .done();

When creating ogv with libtheora and webm with libvpx it looks terrible. Can you please give a hint as to how to set the quality? For ogv I want to set something like -qscale:v 7.

release the project as jar file

Hi,
it's be very nice if you can release your project as jar lib, cause i use not maven. Sorry i'm old school.

Best regards,
Paul

How add a transparent watermark?

I see some code,but it does't working!

FFmpegBuilder builder = new FFmpegBuilder() .setInput(in) // Or filename .addInput(waterMarkingImgPath) .overrideOutputFiles(true) .addOutput("e:\\output.mp4") .setAudioBitRate(1_000_000) .setAudioSampleRate(4_4100) .setFormat("FLV") .done();

has any way to add a transparent png as watermark in video?thank!

Ability to skip defining inputs and do it manually via extra args

Right now it's required to provide at least one input. I've got situation when:

  1. input definition is complex: -f lavfi -i aevalsrc=0
  2. it has to be before extra_args because they refer to it (-map, -shortest)

There was no way to do it besides extending FFmpegBuilder and just copying this method commenting out inputs check - and this way it worked well just with all args defined through addExtraArgs.

Maybe I'm missing something in ffmpeg usage - I've tried several args order in command line and it complained about -i going after other args.

Support setting input arguments (such as format and bitrate)

Format and AudioSampleRate needed in FFmpegBuilder.

ffmpeg -f s16le -ar 16000 -i input.pcm output.wav

It wont work with
ffmpeg -i input.pcm -f s16le -ar 16000 output.wav

I added format and AudioSampleRate to get it to work but I don't think this is exactly how you have envisioned FFmpegBuilder and FFmpegOutputBuilder working. I don't mind fixing it and providing a pull request but just wanted to get an understanding of your vision.

Specify default FFMPEG and FFPROBE constants

Please specify default constants for FFMPEG and FFPROBE to use instead of String, for example:

public class FFmpegConstants {

// File Extensions
public static final String AVI = "avi";
public static final String MP4 = "mp4";
public static final String OGG = "ogg";
public static final String MOV = "mov";
public static final String _3GP = "3gp";

//  Formats
public static final String MP4_FORMAT = "mp4";

// Audio
public static final String AAC_CODEC = "aac";

// Video
public static final String H264_CODEC = "libx264";

// Presets
public static final String ULTRAFAST_PRESET = "ultrafast";

}

Document supported FFmpeg versions

Can you add in this project homepage useful information for newcomers to start:

  • Java version supported
  • FFmpeg version supported
  • Operating systems supported

setComplexVideoFilter with unexpected results with filtergraph

I'm using the setComplexVideoFilter to add an adelay/amix filter, to merge audio and video tracks that have different lengths, into a single file. I have ffmpeg 3.2 installed in OS X.

The actual command that works is
ffmpeg -y -v error -i video.trk -i audio.trk -filter_complex "[1:0]adelay=10000|10000[t1];[t1]amix=inputs=1" -c:v copy out.webm. To have the library generating the same command, I had to add escaped quotes to the string, producing the following line outputBuilder.setComplexVideoFilter("\"[1:0]adelay=10000|10000[t1];[t1]amix=inputs=1\"");. This yields the following result.

/usr/local/bin/ffmpeg -y -v error -i video.trk -i audio.trk -filter_complex "[1:0]adelay=10000|10000[t1];[t1]amix=inputs=1" -c:v copy out.webm
Truncating packet of size 21863284 to 2742585
Truncating packet of size 21863284 to 181769
[AVFilterGraph @ 0x7faa89416fe0] No such filter: '"'
Error initializing complex filters.
Invalid argument

Issuing the following line outputBuilder.setComplexVideoFilter("[1:0]adelay=10000|10000[t1];[t1]amix=inputs=1"); produces an expected error, as the complex filter should go between quotes

/usr/local/bin/ffmpeg -y -v error -i video.trk -i audio.trk -filter_complex [1:0]adelay=10000|10000[t1];[t1]amix=inputs=1 -c:v copy out.webm
Truncating packet of size 21863284 to 2742585
Truncating packet of size 21863284 to 181769
Filter amix has an unconnected output

which is expected, as it is the same output that you get when running from command line.

Not sure if there's anything we can do here, and is a problem from the ProcessBuilder itself. Any ideas?

ffpobe bitrate overflow int

hi ,
i'm getting json parsing error after running FFprobe.probe on some image,
turns out that ffprobe's output is :
Input #0, image2, from 'C:\temp\templates\c41b4f90-3dc2-42c8-8efa-7dee15e19d01(Footage)\Assets\back.jpg':
Duration: 00:00:00.04, start: 0.000000, bitrate: 2510838 kb/s
Stream #0:0: Video: mjpeg, yuvj444p(pc, bt470bg/unknown/unknown), 5760x3840 [SAR 300:300 DAR 3:2], 25 tbr, 25 tbn, 25 tbc

notice that the bitrate exceeds int ,
FFmpegFormat field bitrate should be changed to long

FFMPEG Command witn -vsync vfr

I was not able to model following command in FFMPEG CLI.

ffmpeg -i input.mp4 -vf "select=gt(scene,0.5)" -frames:v 5 -vsync vfr out%02d.png

It kept throwing error for the "-vsync vfr" options. I tried adding that in video filter as well as addExtraArgs.

-movflags option

Hi
there's no implementation fo the -movflags option in order, for example, to move the moov atom at the beginning of the encoded file (with faststart)

Add support for input and output streams

For example:
ffmpeg -re -y -i '/file.mp4' -c:v libx264 -f flv 'rtmp://server.com:80/live/...'

setInput() and setOutput() accept Strings right now. Add a File and URL version of the arguments, which would then allow for using URLs as input/output.

Not being able to find a class definition for FFmpeg.

While trying to test the library I've got this error...

Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/base/MoreObjects
at net.bramp.ffmpeg.FFmpeg.(FFmpeg.java:34)
at test_mixer.OggEncoder.oggEncoder(OggEncoder.java:28)
at test_mixer.Main.recordAudio(Main.java:96)
at test_mixer.Main.main(Main.java:29)
Caused by: java.lang.ClassNotFoundException: com.google.common.base.MoreObjects
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 4 more

The paths that I have are the following ones...
String ffmpegPath = "C:\\Users\\Test\\EclipseWorkspace\\test_mixer\\ffmpeg\\bin\\ffmpeg.exe";
String ffprobePath = "C:\\Users\\Test\\EclipseWorkspace\\test_mixer\\ffmpeg\\bin\\ffprobe.exe";

Error is thrown while trying to instantiate the FFmpeg class. (I suposse the same will happen with the FFprobe class).
FFmpeg ffmpeg = new FFmpeg(ffmpegPath);

FFmpegUtils.parseBitrate throws IllegalArgument when bitrate is 'N/A'

When using a ProgressListener, the first message contains "N/A" for the bitrate. This causes the TcpProgressParserRunnable to exit:

Exception in thread "TcpProgressParser(tcp://127.0.0.1:58092)" java.lang.IllegalArgumentException: Invalid bitrate 'N/A'
	at net.bramp.ffmpeg.FFmpegUtils.parseBitrate(FFmpegUtils.java:64)
	at net.bramp.ffmpeg.progress.Progress.parseLine(Progress.java:76)
	at net.bramp.ffmpeg.progress.StreamProgressParser.processReader(StreamProgressParser.java:41)
	at net.bramp.ffmpeg.progress.StreamProgressParser.processStream(StreamProgressParser.java:32)
	at net.bramp.ffmpeg.progress.TcpProgressParserRunnable.run(TcpProgressParserRunnable.java:35)
	at java.lang.Thread.run(Thread.java:745)

Codec type is null and HZ values are missing from streams

Codectype , hz and stereo/Mono identifier are missing

I am expecting below values via FFProbe

Example:
Metadata:
artist : Girl Talk (RoyalJatt.Com)
album : All Day (www.RoyalJatt.Com)
genre : RoyalJatt.Com
date : 2010
Duration: 00:06:02.06, start: 0.000000, bitrate: 326 kb/s
Stream #0:0: Audio: mp3, 44100 Hz, stereo, s16p, 320 kb/s
Stream #0:1: Video: gif, bgra, 90k tbr, 90k tbn, 90k tbc
Metadata:
title : cover
comment : Cover (front)

How to set -pix_fmt?

I need to set -pix_fmt yuv420p using your APIs. How do I do it?

I am completely dependent on this. Please help me out if at there is an option. I am not able to set it.

Allow extra arguments to FFprobe

It would be useful to support arbitrary extra arguments to FFprobe. Specifically I'm trying to set the expected input format, or a format/protocol whitelist. Currently this means I must reimplement probe(), since it does not support extraArgs like FFMpeg does.

Actual command string

Is there a way to get the actual string being executed? Would be extremely useful for debugging.

Stopping ffmpeg / wrapper remotely

Hi,

I use this library as an RTSP client to record IP camera streams. I can start the streams but I could not figure out how to stop recoding remotely, since ffmpeg waits for q button to stop and terminate.

What can be the proper way of stopping ffmpeg / wrapper, without killing the sub-process ?

codec_time_base can be 1/0 which causes Gson deserialization to error when decoding as a Fraction.

I receive this error:

Exception in thread "main" java.lang.ArithmeticException: The denominator must not be zero
    at org.apache.commons.lang3.math.Fraction.getFraction(Fraction.java:143)
    at org.apache.commons.lang3.math.Fraction.getFraction(Fraction.java:348)
    at net.bramp.commons.lang3.math.gson.FractionAdapter.read(FractionAdapter.java:37)
    at net.bramp.commons.lang3.math.gson.FractionAdapter.read(FractionAdapter.java:17)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:116)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:216)
    at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:40)
    at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:82)
    at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:61)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:116)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:216)
    at com.google.gson.Gson.fromJson(Gson.java:879)
    at com.google.gson.Gson.fromJson(Gson.java:817)
    at net.bramp.ffmpeg.FFprobe.probe(FFprobe.java:101)

When I try to probe an mpegts file. For reference, here is the FFProbe output as JSON:

{
    "streams": [
        {
            "index": 0,
            "codec_name": "h264",
            "codec_long_name": "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10",
            "profile": "High",
            "codec_type": "video",
            "codec_time_base": "1/26",
            "codec_tag_string": "[27][0][0][0]",
            "codec_tag": "0x001b",
            "width": 1920,
            "height": 1080,
            "coded_width": 1920,
            "coded_height": 1088,
            "has_b_frames": 0,
            "sample_aspect_ratio": "1:1",
            "display_aspect_ratio": "16:9",
            "pix_fmt": "yuv420p",
            "level": 41,
            "color_range": "tv",
            "color_space": "bt709",
            "color_transfer": "bt709",
            "color_primaries": "bt709",
            "chroma_location": "left",
            "refs": 1,
            "is_avc": "0",
            "nal_length_size": "0",
            "id": "0x100",
            "r_frame_rate": "167/12",
            "avg_frame_rate": "13/1",
            "time_base": "1/90000",
            "start_pts": 5477657,
            "start_time": "60.862856",
            "duration_ts": 378588,
            "duration": "4.206533",
            "bits_per_raw_sample": "8",
            "disposition": {
                "default": 0,
                "dub": 0,
                "original": 0,
                "comment": 0,
                "lyrics": 0,
                "karaoke": 0,
                "forced": 0,
                "hearing_impaired": 0,
                "visual_impaired": 0,
                "clean_effects": 0,
                "attached_pic": 0
            }
        },
        {
            "index": 1,
            "codec_name": "aac",
            "codec_long_name": "AAC (Advanced Audio Coding)",
            "codec_type": "audio",
            "codec_time_base": "1/0",
            "codec_tag_string": "[15][0][0][0]",
            "codec_tag": "0x000f",
            "sample_fmt": "fltp",
            "sample_rate": "0",
            "channels": 0,
            "bits_per_sample": 0,
            "id": "0x101",
            "r_frame_rate": "0/0",
            "avg_frame_rate": "0/0",
            "time_base": "1/90000",
            "start_pts": 5477657,
            "start_time": "60.862856",
            "duration_ts": 378588,
            "duration": "4.206533",
            "disposition": {
                "default": 0,
                "dub": 0,
                "original": 0,
                "comment": 0,
                "lyrics": 0,
                "karaoke": 0,
                "forced": 0,
                "hearing_impaired": 0,
                "visual_impaired": 0,
                "clean_effects": 0,
                "attached_pic": 0
            }
        }
    ],
    "format": {
        "filename": "1.ts",
        "nb_streams": 2,
        "nb_programs": 1,
        "format_name": "mpegts",
        "format_long_name": "MPEG-TS (MPEG-2 Transport Stream)",
        "start_time": "60.862856",
        "duration": "4.206533",
        "size": "574528",
        "bit_rate": "1092639",
        "probe_score": 100
    }
}

Notice the codec_time_base is 1/0?

Two-Pass encoding needs mandatory parameters

Your library offers 2 methods to encode videos createJob(FFmpegBuilder builder) and createTwoPassJob(FFmpegBuilder builder) .

However, two-Pass encoding does not work if some parameters are not set such as format and videoBitRate. Single-pass encoding works without these arguments though.

So could you ensure mandatory parameters are set when using createTwoPassJob(FFmpegBuilder builder)?

Examples

One-Pass MP4 encoding with minimum parameters on Windows:

ffmpeg.exe -i input.mp4 output.mp4

Two-Pass MP4 encoding with minimum parameters on Windows:

ffmpeg.exe -y -i input.mp4 -b:v 128k -pass 1 -f mp4 NUL
ffmpeg.exe -i input.mp4 -b:v 128k -pass 2  output.mp4

java.lang.ClassNotFoundException: com.google.common.base.MoreObjects

Using v0.5 I get the following stack trace

24-Oct-2016 15:31:20.778 SEVERE [http-apr-8082-exec-2] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [jerseyspring] in context with path [] threw exception [java.lang.NoClassDefFoundError: com/google/common/base/MoreObjects] with root cause
java.lang.ClassNotFoundException: com.google.common.base.MoreObjects
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1332)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1166)
at net.bramp.ffmpeg.FFmpeg.(FFmpeg.java:37)
at com.foo.service.VideoServiceFFmpegCli.init(VideoServiceFFmpegCli.java:73)
at com.foo.rest.UploadResource2.upload(UploadResource2.java:333)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:205)
at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)
at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1542)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1473)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:558)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:733)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:154)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:50)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.foo.filter.TokenFilter.doFilter(TokenFilter.java:98)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.foo.filter.CorsFilter2.doFilter(CorsFilter2.java:34)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:85)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2503)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2492)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)

Explicitly adding guava resolves the issue.

com.google.guava guava 19.0

Callback for ffmpeg job completion

It would be nice if the there is callback after the ffmpeg transcoding is complete, since from java we have to have limit the number of ffmpeg processes running on the system using Executorservice. I have created a pull request , i can also send a patch if required.

Edge case with start_pts

I've found an issue with certain encoders that when the stream they are sending out will overflow an int for the start_pts. The json parser threw a number format exception as the value was 3883260966 in the case I initially found.

I forked this and changed start_pts in FFmpegStream.java to a double for my purposes,

    // Edge case found on encoder, changed from int to double
    public double start_pts;
    public double start_time;

not sure if you want me to submit a pull request or if you want to change it yourself if you feel it is an issue that may strike other users.

Wrong argument order

Hi,

I use the lib on os x and the produced command line seems to be wrong, if I change the order (put the input file directly before the output filename) it works on the command line.

FFmpegBuilder API is not intuitive

It seems that after addOutput("filename") another builder is returned - FFmpegOutputBuilder.

In my opinion the FFmpegOutputBuilder should be self contained builder, and FFmpegBuilder should have a method public FFmpegBuilder addOutputBuilder(FFmpegOutputBuilder outputBuilder).

This will be much clearer, builder which returns itself and not another builder. Since once another builder is returned, there is no going back to the FFmpegBuilder.

This will also simplify multiple output creations on the consumer side, if there are repetitions with slight variations of the output, e.g. video format.

FFProbe constructor discrepancy

The FFProbe example on the main readme contains the following initialization:
FFprobe ffprobe = new FFprobe("/path/to/ffprobe");

Unfortunately, that constructor (which only takes a path) was removed in version 0.6
Chen

Set input duration

FFmpegBuilder has an option for input start offset, but not for input duration ("-t")

order of ExtraArgs

Hi there,
I'am working on a project where I have to decode, encode and join several raw audio files.

For example:

file1.pcma
file2.pcma

with a command like this:

ffmpeg.exe  -filter_complex "[1:a]adelay=4000[a1];[0:a][a1]amix=inputs=2:duration=longest" -f alaw -ar 8000 -ac 1 -i file1.pcma -f alaw -ar 8000 -ac 1 -i file2.pcma -ar 8000 -ac 1 out.wav

For this it's important to have args in the right order.

I tried to get something like this with ffmpeg-cli-wrapper, because it's a nice peace of software and covers all the event and threading stuff. I tried it with the following command:

FFmpeg ffmpeg = new FFmpeg("./src/main/resources/ffmpeg/ffmpeg.exe");
FFmpegBuilder builder = new FFmpegBuilder()
	.addExtraArgs("-filter_complex \"[1:a]adelay=4000[a1];[0:a][a1]amix=inputs=2:duration=longest\"")
	.setInput("./file1.pcma").setFormat("alaw").addExtraArgs("-ar 8000 -ac 1")
	.addInput("./file2.pcma").setFormat("alaw").addExtraArgs("-ar 8000 -ac 1")
	.addOutput("./output.wav").addExtraArgs("-ar 8000 -ac 1").done();

what it has produced was:

./src/main/resources/ffmpeg/ffmpeg.exe -y -v error -f alaw -filter_complex "[1:a]adelay=4000[a1];[0:a][a1]amix=inputs=2:duration=longest" -ar 8000 -ac 1 -ar 8000 -ac 1 -i ./file1.pcma -i ./file2.pcma -ar 8000 -ac 1 ./output.wav

As you can see the order is not right. The format argument has only appliend once and the other two extraargs doesn't belong to the right input because of the order.

Get single frames from video source

Use ffmpeg to get frames e.g. as BufferedImage. Set decoding options to runtime, e.g. nextFrame(), seek(int timestamp), ...

This possibilities are highly needed to perform imageprocessing tools to videos.

Is there a way to add such things?

Thanks for the nice work so far.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.