How to encode video from a webcam to H.264 in C #?

How do you encode webcam video in H.264 in C #?

What I need

  • MSDN if there is any help with this.
  • Open Source Libs / wrappers for encoding / decoding.
  • Tutorials and blog articles on how to do this.

Some examples of how to encode in 3GP or FLV or something else with a low file size will be more than appreciated.

+4
source share
2 answers

You will need to look in the DirectShow SDK.

H.264 coding directly is not possible, however there are commercial activex controls that can help you. But you need to understand a few things

DirectShow is an audio / video processing system, and you can use the graph editing tool to place your devices on a graph and test it. And you should write a similar code to build a graph, a graph is a chain of devices / objects that interact with each other to get the final result.

DirectShow can be used in .NET, you can use the GraphEditPlus tool to create a graph and use it in .NET. However, I doubt that .NET is better because it can lead to unknown errors, since DirectShow is closely related to COM. If you create an ActiveX control in native C ++ and use DirectShow for full recording, and you use ActiveX in WPF, it will be more stable, although it is difficult to program.

You will usually need a graph as follows:

Video Source => Demux -> Audio Stream + Video Stream -> MP4Muxer 

x264 is free open source and has good MP4Muxer, but not legal, you must have patent licenses purchased to use H264 in your code.

Alternatives - you can go with a lot of commercial controls, Intel IPP is the best implementation of H264 so far, but it is a bit difficult to do live.

+2
source

Below are 2 samples from CodeProject for video capture in .NET.

They do not include H.264 specifically. To do this, you may want to post-process the video after capture using third-party components. For example: http://www.elecard.com/products/products-pc/sdk/codec-.net-sdk/

+1
source

All Articles