AForge.NET

  :: AForge.NET Framework :: Articles :: Forums ::

Video FFMPEG encode

Forum to discuss AForge.NET Framework, its features, API, how-tos, etc.

Video FFMPEG encode

Postby hmess » Thu Nov 24, 2011 7:01 am

Hello.
I want to thanks you first for you good job.

I use the library video.ffmepg to save image, from a Sony camera in live stream, in to an avi file.
I write some texte on the image before encoded it and save it in this avi file.
The frame rate is egal at 25fps and the size is 720x576.

My trouble is that the resulting video miss a lot of frame and the quality is really bad.

how can i make a better quality and 25fps it is too fast ?

Sorry for my english.
Thanks for your answer.
Best regards,
MH.
hmess
 
Posts: 4
Joined: Thu Nov 24, 2011 6:49 am

Re: Video FFMPEG encode

Postby andrew.kirillov » Thu Nov 24, 2011 9:33 am

Hello,

Frame rate can be set using VideoFileWriter.Open() method.

With quality it is a bit more difficult. For quality control there is bit rate, which is hardcoded value in current version 2.2.2. However in the next version it will be possible to set bit rate in the Open() method. If you want it now, then you may get latest sources out of SVN and build them manually - there bit rate is already configurable.
With best regards,
Andrew


Interested in supporting AForge.NET Framework?
User avatar
andrew.kirillov
Site Admin, AForge.NET Developer
 
Posts: 2567
Joined: Fri Jan 23, 2009 9:12 am
Location: UK

Re: Video FFMPEG encode

Postby hmess » Thu Nov 24, 2011 5:26 pm

Hello, thank you andrew for your answer.
Ok i see for the bite rate, i will build e new vdeo.ffmpeg with visual studio express c++.

I know for the frame rate, and it's what i use.
but the time of the avi created don't correspond of the time betwen the open file and close file (some frame is missing at 25fps)
That's why this make me think that the function "WriteVideoFrame( image )" with an avi file encode limit the frame rate.
Because i use it with a timer.interval = 40 (25fps), i draw text on a bmp and i use WriteVideoFrame( image ) for write it in the avi.
Perhaps it because image encoded need a lot of ressource and speed and my computer is not speed enough ?
hmess
 
Posts: 4
Joined: Thu Nov 24, 2011 6:49 am

Re: Video FFMPEG encode

Postby csjerry » Sun Nov 27, 2011 3:39 am

I meet the same problem.
I draw a line on the video picturebox and record the video.when playing the avi I can't see the process of drawing line. It shows the whole line directly.
I reduced the famerate in Open method . The problem still exists.
csjerry
 
Posts: 22
Joined: Mon Oct 31, 2011 1:22 am

Re: Video FFMPEG encode

Postby andrew.kirillov » Sun Nov 27, 2011 4:31 pm

csjerry wrote:It shows the whole line directly.

Unlucky you ;)

Here is the code which works fine for me:
Code: Select all
VideoFileWriter writer = new VideoFileWriter( );

try
{
    writer.Open( fileName, 320, 240, 25, VideoCodec.Default );

    Bitmap image = new Bitmap( 320, 240, PixelFormat.Format24bppRgb );

    for ( int i = 0; i < 300; i++ )
    {
        image.SetPixel( i % 320, i % 240, Color.Green );
        image.SetPixel( ( i + 1 ) % 320, i % 240, Color.Red );
        image.SetPixel( ( i + 2 ) % 320, i % 240, Color.Blue );

        writer.WriteVideoFrame( image );
    }

    image.Dispose( );

    writer.Close( );
}
catch (Exception ex )
{

}
With best regards,
Andrew


Interested in supporting AForge.NET Framework?
User avatar
andrew.kirillov
Site Admin, AForge.NET Developer
 
Posts: 2567
Joined: Fri Jan 23, 2009 9:12 am
Location: UK

Re: Video FFMPEG encode

Postby csjerry » Tue Nov 29, 2011 1:00 pm

Hi andrew,
I guess I haven't descripted clearly .So I show the details and look forward to your solution .

develpment: VS2010+.NET Framework 3.5 +C#

Step 1: I used AForge.Video.DirectShow to connect a camera and show the video in picturebox(change the Picturebox.Image) . the code just like AForge sample .
Step 2: I made a draw tool by GDI+ to draw simple shapes on the picturebox . I think you can understand what I say .
Step 3: I used AForge.Video.FFMPEG to write avi file . the frame is the bitmap cloned from picturebox.Image .

OK, that's the details.now the question is what I said at above.
by the way . If I remove the Step1 ,yeah ,the effect is good ,the same as your code . But why after adding step 1 the problem occured ? perhaps this question is not about the AForge Framework ,but I hope you can help me find the reason.
Thank you .
csjerry
 
Posts: 22
Joined: Mon Oct 31, 2011 1:22 am

Re: Video FFMPEG encode

Postby hmess » Wed Nov 30, 2011 6:38 pm

Hi Andrew.
i try to modify the Aforge.video.ffmpeg, to use other encoder like FFH264 ( more perfomrer) or MJPEG to see if that reduce the CPU time to keep up the 25 frames per second.
But When i use the new dll my program bug, and say that it don't now the codec. Does it because the external FFMPEG don't contain it or i have to add on my system this encoder ?
Thank you for you answer.
best regards,
HM.
hmess
 
Posts: 4
Joined: Thu Nov 24, 2011 6:49 am

Re: Video FFMPEG encode

Postby andrew.kirillov » Wed Nov 30, 2011 8:25 pm

@hmess

Not sure what goes wrong with your system. If you feel comfortable changing sources, then you should be prepared to debug and resolve issues.
With best regards,
Andrew


Interested in supporting AForge.NET Framework?
User avatar
andrew.kirillov
Site Admin, AForge.NET Developer
 
Posts: 2567
Joined: Fri Jan 23, 2009 9:12 am
Location: UK

Re: Video FFMPEG encode

Postby hmess » Sat Dec 03, 2011 11:54 am

Thank you andrew for your answer.

I upload in attachment my new video.FFMPEG DLL and the source. In this one there is the new function with the bit rate in input for C#. And some change in the codec avaible. But for me the new codec i have change, don't work.
I have an exception : "codec not find".
can someone test it and tell me if it work for him ?
Thank by advance.
Attachments
Video.FFMPEG.zip
Video.FFMPEG
(30.48 KiB) Downloaded 159 times
hmess
 
Posts: 4
Joined: Thu Nov 24, 2011 6:49 am




Return to AForge.NET Framework