How to encode Video from Web-Camera into H.264 in C#? [closed]
Closed 9 years ago.
- Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
- Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done s开发者_运维百科o far to solve it.
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.
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.
Below are 2 samples from CodeProject for Video Capturing in .NET.
- http://www.codeproject.com/KB/directx/DirXVidStrm.aspx
- http://www.codeproject.com/KB/cs/WebCamService.aspx
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/
精彩评论