Question

How do you encode video from Webcam into H.264 in C#?

What do I need

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

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

Was it helpful?

Solution

You will need to look into DirectShow SDK.

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

DirectShow is audio/video processing framework, and you can use graph edit tool to put your devices on the graph and test it. And you have to write similar code to build graph, graph is chain of devices/objects that interact with each other to produce final output.

DirectShow can be used in .NET, you can use GraphEditPlus tool to create a graph and use it in .NET, however I doubt .NET is better way because it may lead to unknown errors as DirectShow is closely bound to COM. If you create ActiveX control, in native C++ and use DirectShow to do entire recording and you use ActiveX in WPF, that will be more stable however difficult to program.

Typically you will need graph as following,

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

x264 is free open source and has a good MP4Muxer but not legal, you must have patent licenses acquired for using H264 in your code.

Alternatives are you can go with lots of commercial controls, Intel's IPP is the best implementation of H264 so far, but its little tricky to put it in directshow.

OTHER TIPS

Below are 2 samples from CodeProject for Video Capturing in .NET.

They do not include H.264 specifically. For that you might want to post-process the video after capturing, with 3rd party components E.g: http://www.elecard.com/products/products-pc/sdk/codec-.net-sdk/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top