video record and playback at same time using DirectShow

筅森魡賤 提交于 2019-12-08 11:42:49

问题


I should develop an application that records and plays recorded video while recording continues (without stopping graph). I know how to use and develop using DirectShow but I need architecture of my graph. What filters should I use?

I did it with raw video using DirectShow and SampleGrabber but I should compress video and I have no idea how to do it in compressed video file (which is not closed, because recording continues).

I think MPEG-2 recording is the best for my application but please guide me about filters I should use.

Thanks


回答1:


Have you tried the StreamBufferEngine?

Recording a file and watching it at the same time is a little bit problematic, because the Demuxer needs to reparse the written file, to know about the new parts. I have never seen an demuxer doing this.

The other big problem is the file-locking! The DirectShow filewriter and most other similar filters lock the file for the writing. So no other process can open the file for reading.

You are searching for a TimeShift system. There are some thirt-party SDK for this. But it can also be implemented with own DirectShow Filters, but you will need a lot of time and knowledge for this. I know it's possible because I have done it in the videoplayer from my company (utilius fairplay 5).




回答2:


I worked on that issue for weeks, SBE does not work well in H264 mux in transport I came up with a solution , let me share

First , the encoder need to have small GOP , like 15 , not 150, otherwise the sync will take time and it will seen as a big hang.

The idea is to create directshow filter , start from Live source filter (https://www.codeproject.com/Articles/158053/DirectShow-Filters-Development-Part-2-Live-Source)

Modified the filter , not to enter the frame from external program.

add winsock2 , for UDP binding , or multicast group. Start receive the data from live source and sample it out to the output pin.

Suggest always to use Elecard SDk for setup. On the sender you can use nw renderer but there you cannot change the encoder GOP so open graph edit and build the sender graph desktop capture->encoder->mux->nwrenderer.

Your new filter should know to receive the data and display it on screen

once you have that working you can than continue add the timeshift capabilities into your filter.

Allocate a very big buffer , 200 mega to 1 giga , up to you( on ram ofcourse) the same data that you send to the output pin , copy it into that buffer, make it circular with rd and wr indexes.

You need to add interface to your filter, functions like 1. GoLive 2.SetSeekPoint

The way i did it is the following I created a callback from the filter into the host ( c# ) that send the time and the wr pointer every 1 second or more( depends on the accurate i need) In the host i created a list of those two information. Now in c# i have the list of the wr pointer and its time. easy to search and set the RD pointer back to the filter.

The filter have two modes than: 1. in live it send the current received data 2. in seek it send the data from the big buffer , following the rd pointer.

Hope it understood.



来源:https://stackoverflow.com/questions/17423574/video-record-and-playback-at-same-time-using-directshow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!