Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The filter complex does not put te quotation marks and null problem #53

Closed
tarikkilic opened this issue Aug 26, 2019 · 7 comments
Closed

Comments

@tarikkilic
Copy link

tarikkilic commented Aug 26, 2019

I try to trim videos and concat them. Doesn't put quatation marks and null=concat instead of only using concat. And [0:v]trim=start=0.0:end=2.0:setpts:PTS-STARTPTS[0]; after could be setpts=PTS-STARTPTS but couldn't. I want to create the following command like that
./ffmpeg -i ../Desktop/ramb.mp4 -filter_complex "[0:v]trim=start=0:end=5,setpts=PTS-STARTPTS[0]; [0:v]trim=start=10 : end=15,setpts=PTS-STARTPTS[1]; [0][1]concat[2]; [0:v]trim=start=25,setpts=PTS-STARTPTS[3]; [2][3]concat [out1]" -map [out1] ../Desktop/cut_ramb2.mp4

but command constructed like this:
ffmpeg -i /var/www/contents/rawVideo/30_Rambo.mp4 -y -filter_complex [0:v]trim=start=0.0:end=2.0:setpts:PTS-STARTPTS[0]; [0:v]trim=start=5.0:end=15.0:setpts:PTS-STARTPTS[1]; [0][1]null=concat[2]; [0:v]trim=start=40.0:end=45.0:setpts:PTS-STARTPTS[3]; [2][3]null=concat[4] -map [4] /var/www/contents/trimmedVideo/trimmed_30_Rambo.mp4

and I am using Jaffre-wrapper in Java Code like this:

FilterChain filterChain = new FilterChain();

            filterChain.addFilter(
                    Filter.fromInputLink(StreamSpecifier.withInputIndexAndType(0,StreamType.VIDEO)).
                            setName("trim").
                            addArgument("start",start.toString()).
                            addArgument("end",end.toString()).
                            addArgument("setpts").
                            addArgument("PTS-STARTPTS").
                            addOutputLink(String.valueOf(outIndex++))
            );
            filterChainList.add(filterChain);

            if(i != 0){
                FilterChain filterChain1 = new FilterChain();
                filterChain1.addFilter(
                        Filter.fromInputLink(String.valueOf(outIndex-2)).
                                addInputLink(String.valueOf(outIndex-1)).
                                addArgument("concat").
                                addOutputLink(String.valueOf(outIndex++))
                );
                filterChainList.add(filterChain1);
            }`

return FilterGraph.of().addFilterChains(filterChainList);

FilterGraph filterGraph = createFilterChain();

    FFmpegResult result = FFmpeg.atPath(ffmpegBin)
            .addInput(UrlInput.fromPath(input))
            .setOverwriteOutput(true)
            .setFilter(filterGraph.getValue())
            .addArgument("-map")
            .addArgument("[" + out + "]")
            .addOutput(UrlOutput.toPath(output))
            .execute();`

Thanks for this project. This project helped me a lot.

@kokorin
Copy link
Owner

kokorin commented Aug 26, 2019 via email

@kokorin
Copy link
Owner

kokorin commented Aug 27, 2019

@tarikkilic when constructing filter you have to specify filter name, but you specify concat as argument.
Try to use setName method:

Filter.fromInputLink(String.valueOf(outIndex-2)).
                   addInputLink(String.valueOf(outIndex-1)).
                   setName("concat").
                   addOutputLink(String.valueOf(outIndex++))

Also note the difference bnetween FilterChain and Filter:
[0:v]trim=start=0:end=5,setpts=PTS-STARTPTS[0]; is a filter chain which contains 2 filters: trim and setpts. So you have to do something like the following:

filterChain
           .addFilter(
                    Filter.fromInputLink(StreamSpecifier.withInputIndexAndType(0,StreamType.VIDEO)).
                            setName("trim").
                            addArgument("start",start.toString()).
                            addArgument("end",end.toString())
           )
           .addFilter(
                    Filter.withName("setpts").
                            addArgument("PTS-STARTPTS").
                            addOutputLink(String.valueOf(outIndex++))
          );

@tarikkilic
Copy link
Author

Thank you very much. This problem solved. And last question : Jaffre constructed command like this:
image
but throw exception:
image

I copied command from first screenshoot and paste terminal, ffmpeg works but throw exception in java program. I didn't understand.

@kokorin
Copy link
Owner

kokorin commented Aug 27, 2019

To get detailed message you need to enable trace logs for Jaffree. Paste logs here if you need more help.

@tarikkilic
Copy link
Author

tarikkilic commented Aug 27, 2019

Is that what you meant? and my ffmpeg code:

FFmpegResult result = FFmpeg.atPath(ffmpegBin) .addInput(UrlInput.fromPath(input)) .setOverwriteOutput(true) .addArgument("-filter_complex") .addArgument("\'") .addArgument(command) .addArgument("\'") .addArgument("-map") .addArgument("[" + out + "]") .addOutput(UrlOutput.toPath(output)) .execute();

2019-08-27 17:56:51,402 INFO com.github.kokorin.jaffree.process.ProcessHandler [Thread-4] Command constructed:
/root/bin/ffmpeg -i /var/www/contents/rawVideo/30_Rambo.mp4 -y -filter_complex ' [0:v]trim=start=0.0:end=45.0,setpts=PTS-STARTPTS[0];[0:v]trim=start=55.0:end=15.0,setpts=PTS-STARTPTS[1];[0][1]concat[2];[0:v]trim=start=40.0:end=2.0,setpts=PTS-STARTPTS[3];[2][3]concat[4] ' -map [4] /var/www/contents/trimmedVideo/trimmed_30_Rambo.mp4
2019-08-27 17:56:51,402 INFO com.github.kokorin.jaffree.process.ProcessHandler [Thread-4] Starting process: /root/bin/ffmpeg
2019-08-27 17:56:51,403 DEBUG com.github.kokorin.jaffree.process.ProcessHandler [Thread-4] Waiting for Process output
2019-08-27 17:56:51,403 TRACE com.github.kokorin.jaffree.process.ProcessHandler [Thread-4] Process has no output yet, will sleep
2019-08-27 17:56:51,504 DEBUG com.github.kokorin.jaffree.process.ProcessHandler [Thread-4] Starting IO interaction with process
2019-08-27 17:56:51,504 INFO com.github.kokorin.jaffree.process.ProcessHandler [Thread-4] Waiting for process to finish
2019-08-27 17:56:51,505 DEBUG com.github.kokorin.jaffree.process.ProcessHandler [Thread-4] Waiting for Executor to stop
2019-08-27 17:56:51,505 TRACE com.github.kokorin.jaffree.process.ProcessHandler [Thread-4] Executor hasn't yet stopped, will sleep
2019-08-27 17:56:51,505 DEBUG com.github.kokorin.jaffree.process.Executor [StdErr] StdErr thread has started
2019-08-27 17:56:51,505 DEBUG com.github.kokorin.jaffree.process.Executor [StdOut] StdOut thread has started
2019-08-27 17:56:51,505 DEBUG com.github.kokorin.jaffree.process.Executor [StdOut] StdOut thread has finished
2019-08-27 17:56:51,505 DEBUG com.github.kokorin.jaffree.ffmpeg.FFmpegResultReader [StdErr] ffmpeg version N-94303-g7cb4f8c Copyright (c) 2000-2019 the FFmpeg developers
2019-08-27 17:56:51,506 DEBUG com.github.kokorin.jaffree.ffmpeg.FFmpegResultReader [StdErr] built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-36)
2019-08-27 17:56:51,506 DEBUG com.github.kokorin.jaffree.ffmpeg.FFmpegResultReader [StdErr] configuration: --prefix=/root/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/root/ffmpeg_build/include --extra-ldflags=-L/root/ffmpeg_build/lib --extra-libs=-lpthread --extra-libs=-lm --bindir=/root/bin --enable-libvmaf --enable-version3 --enable-gpl --enable-libfdk_aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree
2019-08-27 17:56:51,506 DEBUG com.github.kokorin.jaffree.ffmpeg.FFmpegResultReader [StdErr] libavutil 56. 30.100 / 56. 30.100
2019-08-27 17:56:51,506 DEBUG com.github.kokorin.jaffree.ffmpeg.FFmpegResultReader [StdErr] libavcodec 58. 53.101 / 58. 53.101
2019-08-27 17:56:51,507 DEBUG com.github.kokorin.jaffree.ffmpeg.FFmpegResultReader [StdErr] libavformat 58. 28.102 / 58. 28.102
2019-08-27 17:56:51,507 DEBUG com.github.kokorin.jaffree.ffmpeg.FFmpegResultReader [StdErr] libavdevice 58. 7.100 / 58. 7.100
2019-08-27 17:56:51,507 DEBUG com.github.kokorin.jaffree.ffmpeg.FFmpegResultReader [StdErr] libavfilter 7. 56.101 / 7. 56.101
2019-08-27 17:56:51,507 DEBUG com.github.kokorin.jaffree.ffmpeg.FFmpegResultReader [StdErr] libswscale 5. 4.101 / 5. 4.101
2019-08-27 17:56:51,507 DEBUG com.github.kokorin.jaffree.ffmpeg.FFmpegResultReader [StdErr] libswresample 3. 4.100 / 3. 4.100
2019-08-27 17:56:51,508 DEBUG com.github.kokorin.jaffree.ffmpeg.FFmpegResultReader [StdErr] libpostproc 55. 4.100 / 55. 4.100
2019-08-27 17:56:51,508 DEBUG com.github.kokorin.jaffree.ffmpeg.FFmpegResultReader [StdErr] Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/var/www/contents/rawVideo/30_Rambo.mp4':
2019-08-27 17:56:51,508 DEBUG com.github.kokorin.jaffree.ffmpeg.FFmpegResultReader [StdErr] Metadata:
2019-08-27 17:56:51,508 DEBUG com.github.kokorin.jaffree.ffmpeg.FFmpegResultReader [StdErr] major_brand : isom
2019-08-27 17:56:51,508 DEBUG com.github.kokorin.jaffree.ffmpeg.FFmpegResultReader [StdErr] minor_version : 512
2019-08-27 17:56:51,508 DEBUG com.github.kokorin.jaffree.ffmpeg.FFmpegResultReader [StdErr] compatible_brands: isomiso2avc1mp41
2019-08-27 17:56:51,508 DEBUG com.github.kokorin.jaffree.ffmpeg.FFmpegResultReader [StdErr] title : Rambo: Last Blood - Theatrical Trailer
2019-08-27 17:56:51,508 DEBUG com.github.kokorin.jaffree.ffmpeg.FFmpegResultReader [StdErr] artist : Lionsgate
2019-08-27 17:56:51,509 DEBUG com.github.kokorin.jaffree.ffmpeg.FFmpegResultReader [StdErr] date : 2019
2019-08-27 17:56:51,509 DEBUG com.github.kokorin.jaffree.ffmpeg.FFmpegResultReader [StdErr] encoder : Lavf58.28.102
2019-08-27 17:56:51,509 DEBUG com.github.kokorin.jaffree.ffmpeg.FFmpegResultReader [StdErr] genre : Trailer
2019-08-27 17:56:51,509 DEBUG com.github.kokorin.jaffree.ffmpeg.FFmpegResultReader [StdErr] Duration: 00:00:30.03, start: 0.000000, bitrate: 12767 kb/s
2019-08-27 17:56:51,509 DEBUG com.github.kokorin.jaffree.ffmpeg.FFmpegResultReader [StdErr] Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x802 [SAR 1:1 DAR 960:401], 12633 kb/s, 23.98 fps, 23.98 tbr, 24k tbn, 47.95 tbc (default)
2019-08-27 17:56:51,509 DEBUG com.github.kokorin.jaffree.ffmpeg.FFmpegResultReader [StdErr] Metadata:
2019-08-27 17:56:51,509 DEBUG com.github.kokorin.jaffree.ffmpeg.FFmpegResultReader [StdErr] handler_name : VideoHandler
2019-08-27 17:56:51,509 DEBUG com.github.kokorin.jaffree.ffmpeg.FFmpegResultReader [StdErr] Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
2019-08-27 17:56:51,509 DEBUG com.github.kokorin.jaffree.ffmpeg.FFmpegResultReader [StdErr] Metadata:
2019-08-27 17:56:51,509 DEBUG com.github.kokorin.jaffree.ffmpeg.FFmpegResultReader [StdErr] handler_name : SoundHandler
2019-08-27 17:56:51,510 DEBUG com.github.kokorin.jaffree.ffmpeg.FFmpegResultReader [StdErr] [AVFilterGraph @ 0x3e6da00] No such filter: ''
2019-08-27 17:56:51,510 DEBUG com.github.kokorin.jaffree.ffmpeg.FFmpegResultReader [StdErr] Error initializing complex filters.
2019-08-27 17:56:51,510 DEBUG com.github.kokorin.jaffree.ffmpeg.FFmpegResultReader [StdErr] Invalid argument
2019-08-27 17:56:51,516 DEBUG com.github.kokorin.jaffree.process.Executor [StdErr] Exception: StdErr, collecting for later report
java.lang.RuntimeException: Invalid argument
at com.github.kokorin.jaffree.ffmpeg.FFmpegResultReader.read(FFmpegResultReader.java:91)
at com.github.kokorin.jaffree.ffmpeg.FFmpegResultReader.read(FFmpegResultReader.java:32)
at com.github.kokorin.jaffree.process.ProcessHandler$2.run(ProcessHandler.java:171)
at com.github.kokorin.jaffree.process.Executor$1.run(Executor.java:66)
at java.lang.Thread.run(Thread.java:748)
2019-08-27 17:56:51,516 DEBUG com.github.kokorin.jaffree.process.Executor [StdErr] StdErr thread has finished
2019-08-27 17:56:51,517 WARN com.github.kokorin.jaffree.process.ProcessHandler [Thread-4] Waiting for process has been interrupted
java.lang.InterruptedException: sleep interrupted
at java.lang.Thread.sleep(Native Method)
at com.github.kokorin.jaffree.process.ProcessHandler.waitForExecutorToStop(ProcessHandler.java:281)
at com.github.kokorin.jaffree.process.ProcessHandler.interactWithProcess(ProcessHandler.java:114)
at com.github.kokorin.jaffree.process.ProcessHandler.execute(ProcessHandler.java:85)
at com.github.kokorin.jaffree.ffmpeg.FFmpeg.execute(FFmpeg.java:161)
at com.atlas.videolab.ffmpeg.FfmpegFilter.trimVideo(FfmpegFilter.java:100)
at com.atlas.videolab.flowprocess.Orchestration.lambda$flowProcess$0(Orchestration.java:99)
at java.lang.Thread.run(Thread.java:748)
2019-08-27 17:56:51,517 DEBUG com.github.kokorin.jaffree.process.Executor [Thread-4] Stopping execution
2019-08-27 17:56:51,517 WARN com.github.kokorin.jaffree.process.Executor [Thread-4] Interrupting ALIVE thread: StdErr
2019-08-27 17:56:51,517 WARN com.github.kokorin.jaffree.process.Executor [Thread-4] Interrupting ALIVE thread: StdOut

@kokorin
Copy link
Owner

kokorin commented Aug 27, 2019

Yes, the error message is the following:

[AVFilterGraph @ 0x3e6da00] No such filter: ''
Error initializing complex filters.
Invalid argument

With Java process executor you don't need to escape or quot arguments. Probably you can't escape or quot. So just remove .addArgument("\'")

@tarikkilic
Copy link
Author

Problem Solved! Thanks a lot. But If I write ffmpeg in command-line, I must put quotationmarks to filter. But with Java process executor, I don't put quotation marks and works ffmpeg. I'm confused. Issue can be closed. Again thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants