AForge.NET

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

Record H264

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

Re: Record H264

Postby cesarsouza » Wed Jan 02, 2013 3:19 am

andrew.kirillov wrote:No. This what I though to try as well. Also may need to try latest version of FFMPEG. Will give at a go somewhere next year ;)


Take your time, Andrew - and particulary take a time to enjoy the beginning of a new year ;) hope your new year's eve has been great.

In the meantime, I've discovered another oddity of the H624 codec. When using it, the VideoFileWriter may not save all encoded frames to disk upon calling the Close function. I am not sure this happens with other codecs, but I verified it doesn't with MPEG4, for example.

I noticed there are no other code sections in VideoFileWriter.cpp retrieving frames from the video buffer and flushing then to disk (particularly, this does not seems to be done in the Close function). But it does not seems to be necessary, since MPEG4 does just fine even without it. But with H624, sometimes I lose about 10 seconds of frames when I close the stream. I solved this issue by adding a Flush function and calling it in the beginning of the Close method. I am updating the patch.

Cheers,
Cesar
Attachments
flush.zip
(2.96 KiB) Downloaded 544 times
cesarsouza
 
Posts: 63
Joined: Fri Apr 10, 2009 3:41 pm

Re: Record H264

Postby cesarsouza » Wed Jan 16, 2013 11:37 pm

andrew.kirillov wrote:But, this is FFMPEG – free, but brutal.


Today I attempted to update ffmpeg to its latest version, using the builds from http://ffmpeg.zeranoe.com/builds/.

The entire API changed. Not very encouraging...
cesarsouza
 
Posts: 63
Joined: Fri Apr 10, 2009 3:41 pm

Re: Record H264

Postby andrew.kirillov » Thu Jan 17, 2013 8:19 am

cesarsouza wrote:The entire API changed. Not very encouraging...

If it is really so, then I am not sure what these guys think about ... Do they expect everyone will change their software? Previously I saw they were keeping old API for a while, but marking it "deprecated".
With best regards,
Andrew


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

Re: Record H264

Postby cesarsouza » Thu Jan 17, 2013 1:23 pm

Yes, some parts were deprecated, some others I could not find... But this could be perhaps because I missed the inclusion of some new headers. What I noticed, for example, was the renaming of almost all constants such as Codec_ID and PixelFormats to have a different prefix, and some other structural changes. However, at this point, I wasn't sure if when writing AForge.FFmpeg you had to make any changes in the ffmpeg code directly, which in this case I had lost when I updated the headers.

Could you perhaps give some info if you had to change anything manually to work with VS, C++/CLI or something else?

I will give it another try later.
cesarsouza
 
Posts: 63
Joined: Fri Apr 10, 2009 3:41 pm

Re: Record H264

Postby andrew.kirillov » Thu Jan 17, 2013 1:28 pm

I did zero changes to the headers/sources of the FFmpeg library.

Some time ago I did update to newer version of FFmpeg and it was simple - got new release of FFmpeg and rebuilt AForge.Video.FFMPEG.
With best regards,
Andrew


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

Re: Record H264

Postby cesarsouza » Fri Jan 18, 2013 5:28 am

It seems that, in the meantime, FFmpeg was forked into libav, and the two projects continued to exist simultaneously. At this point I am not sure anymore the Zeranoe builds are based on FFmpeg or libav. That would explain the lots of AV prefixes and renaming of constants throughout the sources. The story given in the aforementioned page concerning the reasons for the fork is quite funny, as it seemed something almost... childish. Too bad users are the ones who may end up suffering from this.
cesarsouza
 
Posts: 63
Joined: Fri Apr 10, 2009 3:41 pm

Re: Record H264

Postby andrew.kirillov » Thu Jan 31, 2013 9:05 pm

Hello,

I did update update of the FFMPEG library. Of course I did not use any of the recent builds, since they brake backward compatibility. The last working build was from from January 27, 2011. Since new builds don't have old API (in any of the headers), I don't have much interest to upgrade to the new version in the near future.

Anyway, I am not sure which version you've used and how you did tests, but even with a bit newer version, the H264 produces miserable results (I was saving video from a USB camera). A dozen of pretty meaningless configuration values do not make it easier to debug.
With best regards,
Andrew


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

Re: Record H264

Postby cesarsouza » Sun Feb 03, 2013 5:51 pm

Hi Andrew,

Many thanks for the effort. I felt your pain when I tried updating it myself weeks ago too, and couldn't believe how much effort it would take. I initially thought I was missing something on the way you built/updated through FFmpeg versions, and that is why I asked you at first. But now I see they have indeed broken backward compatibility for sure, and upgrading would be a major effort. Thanks for bringing the latest possible version though - it will surely be highly appreciated.

Anyways Andrew, I found I could only achieve a sane quality by using a giant bit-rate (on the order of 10k or so). It was the same with the OGG/OGM codecs. I suppose this could be happening because those codecs often expect to be used with a virtual/dynamic bit-rate setting. I couldn't find exactly what to tune, though.

I am leaving all modifications I used in Screencast Capture in a patch in the repository for anyone willing to try messing with the H624/OGG settings in AForge.
cesarsouza
 
Posts: 63
Joined: Fri Apr 10, 2009 3:41 pm

Re: Record H264

Postby yooooooooooo0 » Sun Mar 17, 2013 10:39 am

hello,I want add h264 in VideoCodec,but i get a error:"Cannot open video codec."

VideoCodec.h:
Code: Select all
public enum class VideoCodec
   {
      /// <summary>
      /// Default video codec, which FFmpeg library selects for the specified file format.
      /// </summary>
      Default = -1,
      /// <summary>
      /// MPEG-4 part 2.
      /// </summary>
      MPEG4 = 0,
      /// <summary>
      /// Windows Media Video 7.
      /// </summary>
      WMV1,
      /// <summary>
      /// Windows Media Video 8.
      /// </summary>
      WMV2,
      /// <summary>
      /// MPEG-4 part 2 Microsoft variant version 2.
      /// </summary>
      MSMPEG4v2,
      /// <summary>
      /// MPEG-4 part 2 Microsoft variant version 3.
      /// </summary>
      MSMPEG4v3,
      /// <summary>
      /// H.263+ / H.263-1998 / H.263 version 2.
      /// </summary>
      H263P,
      /// <summary>
      /// Flash Video (FLV) / Sorenson Spark / Sorenson H.263.
      /// </summary>
      FLV1,
      /// <summary>
      /// MPEG-2 part 2.
      /// </summary>
      MPEG2,
      /// <summary>
      /// Raw (uncompressed) video.
      /// </summary>
      Raw,
      H264


VideoCodec.cpp:
Code: Select all
int video_codecs[] =
{
   libffmpeg::CODEC_ID_MPEG4,
   libffmpeg::CODEC_ID_WMV1,
   libffmpeg::CODEC_ID_WMV2,
   libffmpeg::CODEC_ID_MSMPEG4V2,
   libffmpeg::CODEC_ID_MSMPEG4V3,
   libffmpeg::CODEC_ID_H263P,
   libffmpeg::CODEC_ID_FLV1,
   libffmpeg::CODEC_ID_MPEG2VIDEO,
   libffmpeg::CODEC_ID_RAWVIDEO,
   libffmpeg::CODEC_ID_H264,
};

int pixel_formats[] =
{
   libffmpeg::PIX_FMT_YUV420P,
   libffmpeg::PIX_FMT_YUV420P,
   libffmpeg::PIX_FMT_YUV420P,
   libffmpeg::PIX_FMT_YUV420P,
   libffmpeg::PIX_FMT_YUV420P,
   libffmpeg::PIX_FMT_YUV420P,
   libffmpeg::PIX_FMT_YUV420P,
   libffmpeg::PIX_FMT_YUV420P,
   libffmpeg::PIX_FMT_BGR24,
   libffmpeg::PIX_FMT_YUV420P,
};


my app:
Code: Select all
static void Main(string[] args)
        {
            using (VideoFileWriter fw = new VideoFileWriter())
            {
                fw.Open("test.mp4", 320, 240, 25, VideoCodec.H264);
                for (int i = 0; i < 5; i++)
                {
                    fw.WriteVideoFrame(new Bitmap((i + 1) + ".jpg"));
                }
            }
        }


please help me!Thanks!
yooooooooooo0
 
Posts: 2
Joined: Sun Mar 17, 2013 9:36 am

Re: Record H264

Postby yooooooooooo0 » Wed Apr 17, 2013 8:12 am

I use sport_coder's patch and set VideoCodec.H264 ,but mp4 file can not play in chrome tag:<video>
yooooooooooo0
 
Posts: 2
Joined: Sun Mar 17, 2013 9:36 am



Previous

Return to AForge.NET Framework