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

It seems that filters cannot be used at the same time #149

Open
AGPEIM opened this issue May 5, 2021 · 6 comments
Open

It seems that filters cannot be used at the same time #149

AGPEIM opened this issue May 5, 2021 · 6 comments

Comments

@AGPEIM
Copy link

AGPEIM commented May 5, 2021

i need to add 2 filters and i tried this:

videoAttributes.addFilter(scaleFilter);
videoAttributes.addFilter(subtitleFilter);

but only the below one works,
Log says

[Thread-9] INFO ws.schild.jave.ConversionOutputAnalyzer - Unhandled message in step: 1 Line: 15 message: <Only '-vf ass='/Users/lius/Desktop/t_sub.ass'' read, ignoring remaining -vf options: Use ',' to separate filters>
[Thread-9] INFO ws.schild.jave.ConversionOutputAnalyzer - Unhandled message in step: 1 Line: 16 message: <Only '-af (null)' read, ignoring remaining -af options: Use ',' to separate filters>

I don’t know if the method I’m using is incorrect or it’s a bug

@a-schild
Copy link
Owner

a-schild commented May 5, 2021

Could you please provide me with a full example?
Perhpas swapping the filter order changes behaviour?

@AGPEIM
Copy link
Author

AGPEIM commented May 5, 2021

here's the full example

public void encodeVideo(){
        File subtitle=new File("/Users/lius/Desktop/1.ass");
        File video=new File("/Users/lius/Desktop/1.flv");
        File target=new File("/Users/lius/Desktop/1.mp4");

        Encoder encoder=new Encoder();
        EncodingAttributes attributes=new EncodingAttributes();
        AudioAttributes audioAttributes=new AudioAttributes();
        VideoAttributes videoAttributes=new VideoAttributes();
        audioAttributes.setCodec(AudioAttributes.DIRECT_STREAM_COPY);

        AssSubtitlesFilter filter=new AssSubtitlesFilter(subtitle);
        videoAttributes.addFilter(filter);

        VideoSize size=new VideoSize(1080,720);
        ScaleFilter scaleFilter=new ScaleFilter(size);
        videoAttributes.addFilter(scaleFilter);

        attributes.setAudioAttributes(audioAttributes);
        attributes.setVideoAttributes(videoAttributes);
        try {
            encoder.encode(new MultimediaObject(video),target,attributes);
        } catch (EncoderException e) {
            e.printStackTrace();
        }
    }

i have tried swapping the filter order,only the below one works,for example,If the scaleFilter is added after, the video will only scaled without adding subtitles. If the SubtitleFilter is added later, the video will only add subtitles but not scaled.

@a-schild
Copy link
Owner

a-schild commented May 5, 2021

Thanks for testing this.
Yep, it seems that we need to build another argument list, when multiple filters need to be applied in one pass.

https://stackoverflow.com/questions/6195872/applying-multiple-filters-at-once-with-ffmpeg

Something like this is required
-vf "[in] scale=iw/2:ih/2, pad=iw+40:ih+40:10:10 [top]; movie=yourLogoOrVideo.pngOraviEtc, scale=iw/2:ih/2 , fade=out:400:40:alpha=1 [bottom]; [top][bottom] overlay=PaddingFromTop:PaddingFromLeft [out]"

At the moment each filter added ads an -vf .... to the command line, need to contact them together (and make sure the escaping of special chars still works)

@a-schild
Copy link
Owner

a-schild commented May 6, 2021

@mressler Hello Michael,
have you time to look into this one? (I have not enough stream experience to do the modification)

In Encoder.java on lines 391+ we have this stream processing

          new SimpleArgument(ArgType.OUTFILE,
              ea -> ea.getVideoAttributes()
                      .map(VideoAttributes::getVideoFilters)
                      .map(Collection::stream)
                      .map(s -> s.flatMap(vf -> Stream.of("-vf", vf.getExpression())))
                      .orElseGet(Stream::empty)),

When two video filters are passed to the Encoder, then it generates this command arguments:

-vf filterExpression2 -vf FilterExpression2

But for ffmpeg, we need only one -vf argument, and then contact the expressions with "; " so it should generate

-vf filterExpression2; FilterExpression2

@a-schild
Copy link
Owner

Should be fixed in the 3.2.0-SNAPSHOT release.
Could you please test it?

@mressler
Copy link
Collaborator

Sorry, I missed the @mention. You likely want to set a complex filtergraph. That's what FFMPEG calls it in the documentation, and that's what I added early in 3.0.

But that's a good change to support multiple filters.

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

No branches or pull requests

3 participants