简体   繁体   中英

DirectShow(.net) h264 Encoder/decoder

In my project I have to follow this work flow

  1. I have to take the image captured by a webcam and preview it
  2. in the background encode it using H264
  3. save it on desk
  4. decode the saved file to play it back.

I have used Direct Show .net to implement this and I has successfully implement step 1 but I am now in stuck with points starting from 2

I have made a lot of search as I need something compatible with .net but few results were really useful I get that there is direct show decoder using h264(msdn) but I don't think this is what I am looking for. Also I have found many said talk about window media foundation but I think it works only with native code.

Please help me with your thoughts(I need a start point).

my question how to encode/decode stream from directshow using h264

Since you are using DirectShow, the proper way is to create a two different filtergraphs for the two scenarios (ie for capturing: 1,2,3 and for playback: 4). For encoding/decoding use a H264 Encoder/Decoder filters in your filtergraph. As far as I know, DirectShow doesn't offer built-in H264 coding filters, but you can use third party DShow filters to do the work for you.

Simple search for decoders returned this:

If you are using RGB/A pixel format for your uncompressed captured video stream, then note that some encoder filters may require that your video stream is in Luma-chroma kind of pixel format like YV12 or NV12, in that case you have to use a colorspace convertor filter, which luckily is supported by DShow (as a DMO) in the DMO category.

Your capture graph should look like this: Capture filter -> [Colorspace Convertor] -> H264 Encoder -> [Multiplexor (mp4 for example)] -> Writer filter (File writer or a third party file sink filter)

(the brackets - [] means that it may not be necessary to use those filters.)

The playback graph should be: File Source -> [Splitter] -> H264 Decoder -> Render filter

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM