1

I use Accord.Video.FFMPEG to create a video of 200 images with the H264 codec. For some reason, the video is very poor quality. Its size is less than 1MB. When choosing VideoCodec.Raw, the quality is high, but I am not happy with the huge size.

I do something like this

using (var vFWriter = new VideoFileWriter())
{
    vFWriter.Open(video_name, 1920, 1080, 24, VideoCodec.H264);
    for (int i = 0; i < 200; ++i)
    {
        var img_name_src = ...
        using (Bitmap src_jpg = new Bitmap(img_name_src))
        {
            vFWriter.WriteVideoFrame(src_jpg);
        }
    }
    vFWriter.Close();
}

When I run the program, messages appear:

[swscaler @ 06c36d20] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 06e837a0] deprecated pixel format used, make sure you did set range correctly
[avi @ 06c43980] Using AVStream.codec.time_base as a timebase hint to the muxer is deprecated. Set AVStream.time_base instead.
[avi @ 06c43980] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.

I don’t know if they affect something.

It looks like 1 frame:

enter image description here

This is the frame from the video:

enter image description here

How to fix it?

Is there any other way in C# to create a video from individual frames?

  • 1
    I don't use Accord.net. My way is to just run FFmpeg.exe from C# as an external `Process` and feed it (pipe) the bitmap data . See also https://stackoverflow.com/a/13777166/2057709 for example FFmpeg parameters. – VC.One Oct 17 '19 at 06:40
  • 1
    PS: I meant look at [this article](https://mathewsachin.github.io/blog/2017/07/28/ffmpeg-pipe-csharp.html) for examples of piping. Then also use my above comment's shown FFmpeg paameters. Anyways when I got such bad quality video, I had to set output **twice** in FFmpeg parameters. It somehow worked, but I don't now about Accord. – VC.One Oct 17 '19 at 14:30
  • 1
    @VC.One, thanks, you helped me! It works! – Кирилл Малышев Oct 18 '19 at 00:17

1 Answers1

3

Usually, video quality is down to the bitrate which can be changed with this overload:

writer.Open(fileName, width, height, frameRate, VideoCodec, BitRate);

In the millions, the video still has artifacts on high detail frames but is mostly fine. In the billions however, artifacts disappear entirely but file size sky rockets and playback speed is affected by retrieval times from the disk.

Try experimenting with different VideoCodecs, bitrates and file types (mp4, avi, webm etc) to find a suitable balance for your project.