[C++] 181 FFmpegコマンド作成 : 動画に複数のぼかしを入れる

[M1 Mac, Big Sur 11.6.8, clang 13.0.0]

動画に複数のぼかしを入れるFFmpegコマンド作成プログラムを書きました。

これで四角形のモザイクを何ヶ所でも入れることができます。

#include <cppstd.h>
#include <Split.h> // 自製文字列分割クラス

class Split spt; 

int main()
{   
    vector<string> crops;
    vector<string> overs;
    string comp;
    string input = "input.mp4";
    string output = "output.mp4";
    string filters = "227:168:411:117,319:177:650:117,416:80:121:657";

    vector<string> list_filter = spt.splits(filters,",");
    int num = list_filter.size();
    
    for (int i=0;i < num;i++){
        string crop = "[0:v]crop=" + list_filter[i] + ",boxblur=4[b" + to_string(i) + "]";
        crops.push_back(crop);
    }

    for (string ele:crops){
        cout << ele << endl;
    }

    for (int i=0;i < num;i++){
        vector<string> values = spt.splits(list_filter[i],":");
        if (i==0){
            string over = "[0:v][b0]overlay=" + values[2] + ":" + values[3] + "[ovr0]";
            overs.push_back(over);
        } else {
            string over = "[ovr" + to_string(i-1) + "][b" + to_string(i) + "]overlay=" + values[2] + ":" + values[3] + "[ovr" + to_string(i) + "]";
            overs.push_back(over);
        }
    }

    for (string ele:overs){
        cout << ele << endl;
    }

    crops.insert(crops.end(), overs.begin(), overs.end());

   int num2 = crops.size();
    for (int i = 0;i < num2;i++){
        if (i != num2 - 1){
            comp += crops[i] + ";\\" + "\n";
        } else {
            comp += crops[i];
        }
    }

    cout << "comp: " << comp << endl;

    string cmd =  "ffmpeg -i " + input + " -filter_complex \\\n\"" + comp + "\"\\\n -map \"[ovr" + to_string(num-1) + "]\" " + output;

    cout << "cmd: " << cmd << endl;
}
--------------------------------------------------
作成されたコマンド
--------------------------------------------------
ffmpeg -i input.mp4 -filter_complex \
"[0:v]crop=227:168:411:117,boxblur=4[b0];\
[0:v]crop=319:177:650:117,boxblur=4[b1];\
[0:v]crop=416:80:121:657,boxblur=4[b2];\
[0:v][b0]overlay=411:117[ovr0];\
[ovr0][b1]overlay=650:117[ovr1];\
[ovr1][b2]overlay=121:657[ovr2]"\
 -map "[ovr2]" output.mp4