Add text to video

I am trying to add text to a video. I used the Accord framework , and this is what I have now:

using (var vFReader = new VideoFileReader())
{
    vFReader.Open(@"\video.mp4");

    using (var vFWriter = new VideoFileWriter())
    {
        vFWriter.Open(@"\video2.mp4", vFReader.Width, vFReader.Height, vFReader.FrameRate, VideoCodec.MPEG4, vFReader.BitRate);

        for (var i = 0; i < vFReader.FrameCount; i++)
        {
            var image = vFReader.ReadVideoFrame();

            var graphics = Graphics.FromImage(image);

            graphics.SmoothingMode = SmoothingMode.HighQuality;
            graphics.DrawString("Custom text", font, Brushes.White, new Point(vFReader.Width / 2, 25), format);

            graphics.Flush();

            vFWriter.WriteVideoFrame(image, (uint)i);
        }
        vFWriter.Flush();
    }
}

This technically works, but the resulting video is very poor compared to the original. What am I doing wrong?

Here is the difference in quality.

Original video:

Original video

Edited Video:

enter image description here

+4
source share

Source: https://habr.com/ru/post/1696047/


All Articles