ffmpeg + unreal video export

Viewed 45

I am using ffmpeg to create a video from my unreal scene. My popen command is

  std::string command = "ffmpeg -loglevel warning -r "
    + std::to_string(1)
    + " -f rawvideo -pix_fmt rgb24 -s "
    + std::to_string(int(ViewportSize[0])) + "x" + std::to_string(int(ViewportSize[1]))
    + " -i - -threads 0 -preset fast -y -crf 21 "
    + std::string(TCHAR_TO_UTF8(*FString(
            IFileManager::Get().ConvertToAbsolutePathForExternalAppForRead(*FPaths::ProjectDir())))) 
        + "raisimUnrealRecording" + std::to_string(dt.GetTimeOfDay().GetFractionTicks()) + ".mp4";

and I stream the scene as

static int counter = 0;
for (int i = 0; i < ViewportImg.Num(); i++) {
    ViewportImgRGB[3 * i] = 0;
    ViewportImgRGB[3 * i + 1] = 0;
    ViewportImgRGB[3 * i + 2] = 0;

    if (counter % 3 == 0)
        ViewportImgRGB[3 * i] = ViewportImg[i].R;
    else if (counter % 3 == 1)
        ViewportImgRGB[3 * i + 1] = 255;
    else
        ViewportImgRGB[3 * i + 2] = 255;
    }

    counter++;

fwrite(&ViewportImgRGB[0], ViewportSize[0] * ViewportSize[1] * 3 * sizeof(uint8), 1, pPipe);

Here I am sending only the red channel for debugging. The resulting video looks like

enter image description here

It looks like the bytes are shifting, only when I set the image using the scene. If I set the red channel as

ViewportImgRGB[3 * i] = 255;

I see clean frames. I doubt that I am sending the wrong data because that part is quite simple.

Thank you in advance.

0 Answers
Related