0

I am trying to add three filters to a png file using ffmpeg in Android (I am using the writing mind lib).

So far I managed to pull together the cmd:

-i /storage/emulated/0/videoApp/temp/firstFrameOfMergedVideo.png 

-i /storage/emulated/0/videoApp/temp/logo.png

-filter_complex

FIRST FILTER

[1:v]scale=h=-1:w=100[overlay_scaled],[0:v][overlay_scaled]overlay=eval=init:x=W-100-W*0.1:y=W*0.1, 

SECOND FILTER

drawtext=fontfile=/system/fonts/Roboto-Regular.ttf:text='xbsg':fontcolor=white:fontsize=60:box=1:boxcolor=0x7FFFD4@0.5:boxborderw=20:x=20:y=h-(text_h*2)-(h*0.1):enable='between(t,0,2)',

THIRD FILTER

drawtext=fontfile=/system/fonts/Roboto-Regular.ttf:text='cbeh':fontcolor=white:fontsize=30:box=1:boxcolor=0x7FFFD4@0.5:boxborderw=20:x=20:y=h-text_h-(h*0.1)+25:enable='between(t,0,2)',

FOURTH FILTER

eq=contrast=1:brightness=0.26180276:saturation=1:gamma=1:gamma_r=1:gamma_g=1:gamma_b=1:gamma_weight=1 
-c:a
copy
/storage/emulated/0/videoApp/temp/frameWithFilters.png

Right now I am trying to separate the filters using , but I also tried ;

It throws me back:

Input #0, png_pipe, from '/storage/emulated/0/videoApp/temp/firstFrameOfMergedVideo.png':
  Duration: N/A, bitrate: N/A
    Stream #0:0: Video: png, rgb24(pc), 1080x1920, 25 tbr, 25 tbn, 25 tbc

Input #1, png_pipe, from '/storage/emulated/0/videoApp/temp/logo.png':
  Duration: N/A, bitrate: N/A
    Stream #1:0: Video: png, rgba(pc), 528x582, 25 tbr, 25 tbn, 25 tbc

[NULL @ 0xf265d800] Unable to find a suitable output format for ','
,: Invalid argument

If I apply them individual they work.

I am new to ffmpeg so any help would be appreciated.

llogan
  • 121,796
  • 28
  • 232
  • 243
A.Butakidis
  • 355
  • 1
  • 6
  • 16
  • Your command should work (using the commas to link your [simple filters](https://ffmpeg.org/ffmpeg.html#Simple-filtergraphs)) unscripted in a command-line environment, so it's not a problem with ffmpeg. Probably the typical quoting issue experienced by Android users trying to use ffmpeg. Unrelated to the issue, but you don't need `-c:a copy` since your inputs are PNG. – llogan Oct 03 '18 at 18:05
  • 1
    I verify it was a format issue, the command also itself was not correct as I had to make some stream vars, so the correct stream got the brightness change and the overlays remained unchanged. – A.Butakidis Oct 04 '18 at 11:14

1 Answers1

0

I finally figured it out.

The filters must pass in the String array as one string For example filterArray[2] = "-filter_complex" filterArray[3] ="rest of filter".

If anyone is curious the following piece of code applies up to three filters, if present to a video. These filters can be a change of brightness ( needs to be applied first so other filters can be applied on top ), an overlay of a logo image placed at the top right corner and scaled down to a specific size and two text overlays placed one below the other at the bottom left corner.

public void applyFiltersToImage(String srcPath, String outPath, String logoPath, String name, String function, float brightness, ProgressListener progressListener) {

    List<String> cmdList = new ArrayList<>();
    cmdList.add("-i");
    cmdList.add(srcPath);
    if (logoPath != null) {
        cmdList.add("-i");
        cmdList.add(logoPath);
    }

    cmdList.add("-filter_complex");

    StringBuilder filterBuilder = new StringBuilder();

    if (brightness != 0) {
        filterBuilder
                .append("eq=contrast=1:brightness=")
                .append(brightness)
                .append(":saturation=1:gamma=1:gamma_r=1:gamma_g=1:gamma_b=1:gamma_weight=1[v]");
        if (logoPath != null || name != null || function != null)
            filterBuilder.append(";");
    }


    if (logoPath != null) {

        filterBuilder
                .append("[1:v]scale=h=-1:w=")
                .append("100")
                .append("[overlay_scaled],")
                .append(brightness != 0 ? "[v]" : "[0:v]")
                .append("[overlay_scaled]overlay=eval=init:x=W-")
                .append("100")
                .append("-W*0.1:y=W*0.1[v]");

        if (name != null || function != null)
            filterBuilder.append(";[v]");
    }

    if (name != null || function != null) {
        if(brightness != 0 && logoPath == null)
            filterBuilder.append("[v]");

        filterBuilder
                .append("drawtext=fontfile=")
                .append("/system/fonts/Roboto-Regular.ttf")
                .append(":text='")
                .append(name)
                .append("':fontcolor=white:fontsize=")
                .append("60")
                .append(":box=1:boxcolor=0x7FFFD4@0.5:boxborderw=20:x=20:y=h-(text_h*2)-(h*0.1):enable=\'between(t,0,2)\'")
                .append(",drawtext=fontfile=")
                .append("/system/fonts/Roboto-Regular.ttf")
                .append(":text='")
                .append(function)
                .append("':fontcolor=white:fontsize=")
                .append("30")
                .append(":box=1:boxcolor=0x7FFFD4@0.5:boxborderw=20:x=20:y=h-text_h-(h*0.1)+25:enable=\'between(t,0,2)\'[v]");
    }

    cmdList.add(filterBuilder.toString());
    cmdList.add("-map");
    cmdList.add("[v]");
    cmdList.add(outPath);

    String[] cmd = new String[cmdList.size()];

    for (int i = 0; i < cmdList.size(); i++) {
        cmd[i] = cmdList.get(i);
    }

    executeCmd(cmd, progressListener, outPath);
}
A.Butakidis
  • 355
  • 1
  • 6
  • 16