Search code examples
c++variablesquotation-marks

Getting variables into "quotation marks"


I'm currently struggling with getting variables within "quoatation marks"
My code looks like this:

const char* cmd = "ffmpeg -r 25 -f rawvideo -pix_fmt rgba -s 1280x720 -i - "
"-threads 0 -preset fast -y -pix_fmt yuv420p -crf 21 -vf vflip output.mp4";

Now I got two int variables named "previewWidth" and "previewHeight" and I want them to replace the "1280x720". But I can't figure out how to do that

Thanks,
Marco


Solution

  • int previewWidth, previewHeight;
    // ...
    char cmd[1024];
    sprintf (cmd, "ffmpeg -r 25 -f rawvideo -pix_fmt rgba -s %dx%d -i - "
        "-threads 0 -preset fast -y -pix_fmt yuv420p -crf 21 -vf vflip output.mp4",
        previewWidth, previewHeight);
    

    Since this is C++, you'd be better off using std::string.