Directshow / Stream Buffer Engine / Mediaseeking

Posted on 2003-03-24
Medium Priority
Last Modified: 2013-12-03

I've got a strange problem, and maybe there is someone out there that can
help me out. I'm using the Stream Buffer Engine in WinXPsp1  (SBE for short)
to build my own PVR (personal video recorder). I've got allmost everything
working now (including timeshifting) but I've a problem creating permanent
recordings using the SBE (file extention DVR-MS)

What I do:
- create a capture graph and use the Streamsink to write to disk (create a
recorderobject, set to permanent writing, enter filename blah blah blah);
- start the actual recording to the permanent file

Now while recording I can open the file using any player (after the TV
performance update Q810243) and watch the file while it is being recorder. While
recording media player shows the correct mediaduration (time)

- when i'm done recording i call pRecordControl->stop(0). This stops the
recording and trims the created file to the length actually used. I free the
Recorderobject (_Release) . Now when I try playing the newly recorded file ,
mediaplayer (or any other program for that matter) shows a mediaduration
that is absolutely nonsense (sometime 4 hrs for a 10 second recording,
sometimes for example 22094993939393 hrs 3434783278789mins for a 2 minute
recording). Getting the current position from the IMediaSeeking interface is no
problem and works correctly.

What do I do wrong ? Do I have to set the mediaduration myself just before
stopping the recorder object (if so how ?)... Any suggestions are



Question by:Bombadil
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2

Expert Comment

ID: 8200849
Are you confirming that the recording has stopped before you release the recording object?

You might try spinning on GetRecordingStatus() [*after* calling Stop()] and waiting for it to return bStopped as TRUE.

Something like this, only less off-the-cuff:

BOOL bStopped;

} while (bStopped == FALSE);
LVL 49

Expert Comment

ID: 8201004
Your question made me read up on this subject and it is way cool.   Obviously, one cannot rule out bugs in this fledgling technology.

The only thing that jumps out at me is that you did not specify the type you are using in the CreateRecorder call.  Do you get similar problems with both RECORDING_TYPE_REFERENCE and RECORDING_TYPE_CONTENT ?  Also do you get the same problem when you *don't* open the stream for playing while it is currently recording?

-- Dan

Author Comment

ID: 8201272
TascoDLX. Yes before releasing the recording object I make sure it has stopped.

Dan, it sure is cool ! I started writing my own filters but found out 'by accident' that Windows XP sp1 had these filters standard. I could understand there are some bugs, but Windows MCE also uses the same technology. I would guess MS would have fixed it by now. I get the problem for both content and reference recordings. I also get the problem when i don't open the stream while it is still being recorded to.

Rgds. Tom
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks


Accepted Solution

TascoDLX earned 435 total points
ID: 8201591
The only other thing I can think of is if you use the RecordingAttribute interface to manually set the duration after you've stopped recording.

I'd imagine you've probably already tried this, but just in case, the call is (I believe):

pRecordingAttribute->SetAttribute(0, L"Duration", STREAMBUFFER_TYPE_QWORD, &qwDuration, sizeof(QWORD));

If that doesn't work, I'd say open up the newly created vidfile and manually write the duration into the header.
Can't say I know the DVR-MS format off hand though.

Author Comment

ID: 8203600

Had not tried that before (cool feature b.t.w. to add additional information to the recording itself; date, program, genre ,etc).

I found out that writing Attributes after the recording has started is not possible. Any attributes you want to set you would heve to set before the recording starts (so it seems). Also setting attributes just before or just after stopping the recording doesn't seem to work.

What I did find is, that the correct duration is actually present in the file header. I haven't figured out the header format, but I noticed that the incorrect duration (8 bytes) is allways followed by the correct duration (also 8 bytes). Depending on the additional attributes you set the position of these bytes tends to shift so before I can actually do something with this info, I'll have to figure out the header format. Manually hacking the header and shifting these 8 bytes results in a file that has a correct duration though.


LVL 49

Expert Comment

ID: 8203953
>>when I try playing the newly recorded file, mediaplayer ... shows a mediaduration that is absolutely nonsense

Is this only a 'cosmetic' problem?  That is, does media player correctly play only 10 seconds of a 10-second recording?  Maybe the fault is that the media player is misinterpretting the the data.  For instance, it may be doing 32-bit math with 64-bit values.  Or perhaps it assumes that the upper 32 bit have been cleared, etc.  

If you try to seek eleven seconds into a ten-second file, does the API indicate the error correctly?  If you use the correct procedure to obtain the duration data (whatever procedure that is), do you get correct values?

-- Dan

Author Comment

ID: 8204994

It is not just a cosmetic problem. All methods for obtaining the media duration give the same wrong result. Zoomplayer for example simply crashes if you seek beyond the actual end of the file.

Currenty I've found a workaround. It's dirty, but it works (dirty because there has to be a clean method).

After the recording is finished I open the file and just hack the header, replacing the incorrect duration data with the correct duration data. For now I'm happy.



Author Comment

ID: 8205015
It's not the "clean" answer I was looking for, but I go for the "write the duration myself" part of your answer.
(for now that seems to work).



Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question