I'm trying to add text to a video. I've been using the Accord framework so far, and this is what I currently have:
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 is technically working, but the resulting video is in very poor quality compared to the original. What am I doing wrong?
Here is the difference in quality.
Original video:
Edited video: