Qt and DirectShow (Not Quicktime)
- From: Todd Dobmeyer <ToddDobmeyer@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 15 Jun 2006 05:52:02 -0700
I am working on developing a video player that can skip any amount of frames
requested by the user. Thus being why I am showing the video using
DirectShow. I am using Qt by Trolltech to handle my GUI such as all the
buttons and the frame to display the video in. I have all the buttons
implemented and the video playing. One thing I need to be able to do is click
on a point on the video and draw a red dot to show where I clicked. Then if I
click on another spot in the video on the same frame the original red dot
disappears and a new red dot appears based on the newly clicked location. I
am using a windowless control to show my video. This is what I had planned to
do for drawing the point:
/*
* Event handler for the any widget using the installEventFilter function
*/
bool VideoViewerWindow::eventFilter( QObject *obj, QEvent *event )
{
if( event->type() == QEvent::Paint || event->type( ) == QEvent::Move )
{
if( pMediaSeeking != NULL )
{
QPainter* painter;
//painter = new QPainter( mpVideoPlayer );
painter = new QPainter( mpFrame );
painter->setPen( QPen( Qt::red, 3 ) );
// mpOverlay is now transparent
painter->drawPixmap( 0, 0, 561, 351, *mpOverlay );
// Creating a 2nd painter to paint on the overlay...doesn't appear
to help though
QPainter* painter2;
painter2 = new QPainter( mpOverlay );
painter2->setPen( QPen( Qt::red, 3 ) );
// Creating a painter to act as an eraser by using the transparent
color for the pen
QPainter* eraser;
eraser = new QPainter( mpOverlay );
eraser->setPen( QPen( Qt::transparent, 3 ) );
for( int i = 0 ; i < azElPoints.size( ) ; i++ )
{
if( azElPoints[i].frameNumber == getCurrentFrame( ) )
{
if( erasePoint == true )
{
eraser->drawPoint( tempX, tempY );
erasePoint = false;
}
painter->drawPoint( azElPoints[i].xPos, azElPoints[i].yPos );
}
}
delete painter;
delete painter2;
repaintWindow( );
return true;
}
}
return QObject::eventFilter( obj, event );
}
repaintWindow( ) looks like this:
/*
*
* repaintWindow( )
*
* This function repaints the video in its video frame so that the video
will be
* upon loading and flipping back and forth between open windows.
*
*/
void VideoViewerWindow::repaintWindow( )
{
long lWidth, lHeight;
HRESULT hr = pWindowlessControl->GetNativeVideoSize( &lWidth, &lHeight,
NULL, NULL );
RECT rcSrc, rcDest;
// Set the source rectangle.
SetRect( &rcSrc, 0, 0, lWidth, lHeight );
// Get the window client area.
GetClientRect( (HWND) mpVideoPlayer->winId( ), &rcDest );
// Set the destination rectangle.
SetRect(&rcDest, 1, 1, 558, 349);
// Set the video position.
hr = pWindowlessControl->SetVideoPosition( &rcSrc, &rcDest );
PAINTSTRUCT ps;
HDC hdc;
RECT rcClient;
GetClientRect( (HWND) mpVideoPlayer->winId( ), &rcClient );
hdc = BeginPaint( (HWND) mpVideoPlayer->winId( ), &ps );
if( pWindowlessControl != NULL )
{
// Find the region where the application can paint by subtracting
// the video destination rectangle from the client area.
// (Assume that g_rcDest was calculated previously.)
HRGN rgnClient = CreateRectRgnIndirect( &rcClient );
HRGN rgnVideo = CreateRectRgnIndirect( &rcDest );
CombineRgn( rgnClient, rgnClient, rgnVideo, RGN_DIFF );
// Paint on window.
HBRUSH hbr = GetSysColorBrush( COLOR_BTNFACE );
FillRgn( hdc, rgnClient, hbr );
// Clean up.
DeleteObject( hbr );
DeleteObject( rgnClient );
DeleteObject( rgnVideo );
// Request the VMR to paint the video.
HRESULT hr = pWindowlessControl->RepaintVideo( (HWND)
mpVideoPlayer->winId( ), hdc );
}
}
What I am getting is a red dot to display on the frame and everytime a
repaint occurs the video displays for a brief second and then the video
disappears and the blank frame reappears with the red dot being drawn where
it should be drawn. What I am having problems getting to work is I need to
display the red dot on top of the video, not the way it is currently working.
Thanks for any help you may have for getting this to work. If you need more
information, please let me know!
.
- Follow-Ups:
- Re: Qt and DirectShow (Not Quicktime)
- From: The March Hare [MVP]
- Re: Qt and DirectShow (Not Quicktime)
- Prev by Date: RenderDvdVideoVolume Revisited
- Next by Date: mixer
- Previous by thread: RenderDvdVideoVolume Revisited
- Next by thread: Re: Qt and DirectShow (Not Quicktime)
- Index(es):
Loading