Click here to Skip to main content
15,907,687 members
Please Sign up or sign in to vote.
4.95/5 (10 votes)
I am creating the video player which is having the basic controls and i want to add the reverse play control. IVideoFrameStep interface is containing the method for step forward, i couldn't find any interface for step backward. So for that am using IMediaSeeking which is containing GetCurrentPosition and SetPosition methods.
Below is my code for Step Backward:
C++
LONGLONG pos;
pSeek->GetCurrentPosition(&pos);
pos-=FrameValue;
hr = pSeek->SetPositions(&pos,AM_SEEKING_AbsolutePositioning,NULL,
                         AM_SEEKING_NoPositioning);
pControl->Pause();


I can play the video backward if i use this in a loop, but i cant pause or stop the video until it completes.

1)Is there any other way to play the video backward in DirectShow!?

And am using VMR9 as a renderer filter for playing more than one video at a time. The video was step forward smoothly but if i use the above mentioned code for step backward am getting issues. Even though i am rendering two same videos the frame was differs when step backward or else the screen get black randomly in one video region.

2)What i have to do to step frame back the two videos without any issues which i was mentioned when the step back control was invoked!?

Thanking you in advance,
Posted
Updated 25-Apr-13 23:37pm
v11
Comments
Matthew Faithfull 15-Mar-13 11:19am    
Because many video formats have key frames and delta frames playing backwards is not as simple as reversing the order of the frames unless you first convert to a format that doesn't. I don't know if any or all of the DirectShow filters you're using support reverse playback you'd need to check them individually. If you have a choice of format try MJPEG for reverse play, it's simple and each frame is separate so forward or backwards becomes just a matter of frame order.
J.Surjith Kumar 16-Mar-13 8:04am    
Thanks for your comment. Can you give me any reference!?
Matthew Faithfull 16-Mar-13 8:37am    
I'm afraid I can't. I worked with guys who did the video playback and I've writen a motion JPEG decoder from scratch but I never worked on the playback engine, I just learned a few things from talking to the guys who did. So I really don't have details or links. If it's MPEG4 you're dealing with though there are loads of online documents, specs and sources.
You might want to look at GStreamer or ask on a GStreamer forum, any code won't be directly applicable but the MPEG related issues and conceptual solutions may be useful.
Sergey Alexandrovich Kryukov 15-Mar-13 13:40pm    
Interesting question anyway, my 5.
—SA
SoMad 16-Mar-13 2:39am    
As Matthew said, you might be seeing the problems due to difference frames when stepping backwards. I am pretty sure this is also happening when you play it backwards in a loop, but you get a key frame often enough to "repair" the display without noticing the partial updates.
BTW, I also like your question.

Soren Madsen

Repeatedly calling IMediaSeeking::SetPositions to framestep backwards one frame at a time will give you reverse playback. It will be very unlikely to be smooth, but I think it's going to be the best you can achieve without writing multiple custom filters.

Using a codec without any temporal compression like mjpeg or jpeg2000 would help a lot with this technique. For regular modern codecs lowering the resolution and bitrate would help.

I'm not sure that the stock AVI demux will support negative rates for any format, even if the format does not use temporal compression. And certainly most other demux filters will not support negative rate. So you will probably need a custom demux filter to do this. If you do this, make sure you use a container format with an index (mp4 for example).

If you use a format without temporal compression (motion jpeg, i-frames only mpeg-2 etc), you will pay a considerable price in frame compression in order to be able to play in reverse. If you want to do this really well, consider the approach taken by some DVD implementations. Some of them play in reverse by playing only the i-frame, so you have 1 or 2 fps. But the top-end implementation will decode a whole GOP (approx 15 frames) and will then render these frames in reverse order while decoding the previous GOP. This is expensive in development terms and in system resources, but gets a good end result.

(Adapted from http://stackoverflow.com/q/1725534/1758762[^])
 
Share this answer
 
v4
Our new DirectShow source filter supports reverse playback for all kinds of files, including those with temporal compression (H.264, MPEG-2, etc.).

We were able to achieve this by implementing reading, file splitting and decoding in a single component, thus avoiding DirectShow complexities, that become especially problematic for reverse playback of files with temporal compression.
 
Share this answer
 
Comments
[no name] 14-Jan-14 4:54am    
If you supply the source code for free then this may be an answer otherwise not.
to play a video backward by using rewind option.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900