how to get a clips from a video file?

xliu2019 2007-05-19 10:00:45
这是我写的一段code,想实现从视频文件中提取一段出来的功能,
我建立的graph 是
source--->grabber--->writer

可是程序运行的时候,在连接videoout和writein两个pin的时候出错
HRESULT hr;
REFERENCE_TIME rtNow=10000000, rtStop=1000000000;
CoInitialize(NULL);

USES_CONVERSION;
CString m_szInputFile = "E:\\Video\\video\\19.mpg";
TCHAR * tFilename = m_szInputFile.GetBuffer(MAX_PATH);
WCHAR * wFilename = T2W(tFilename);

CComPtr< IGraphBuilder > pGraph;
pGraph.CoCreateInstance(CLSID_FilterGraph);
if(!pGraph)
{
AfxMessageBox(TEXT("Could not create a graph"));
return;
}
// create a CaptureGraphBuilder to help connect filters
CComPtr< ICaptureGraphBuilder > pBuilder;
pBuilder.CoCreateInstance(CLSID_CaptureGraphBuilder);
// tell the capture graph builder what graph we're using
hr = pBuilder->SetFiltergraph(pGraph);
if(FAILED(hr))
{
AfxMessageBox(TEXT("Could not setup capture graph"));
return;
}
// ask directshow to add the appropriate source filter for the given file
CComPtr< IBaseFilter > pSourceBase;
hr = pGraph->AddSourceFilter(wFilename, L"Source", &pSourceBase);
if(!pSourceBase)
{
AfxMessageBox(TEXT("Could not load source filter for file"));
return;
}
CComPtr< IBaseFilter > pVideoFilter;
pVideoFilter.CoCreateInstance(CLSID_SampleGrabber);
hr = pGraph->AddFilter(pVideoFilter, L"VideoGrabber");

CComPtr<IBaseFilter> pFileWriter;
hr = pFileWriter.CoCreateInstance(CLSID_FileWriter);
hr = pGraph->AddFilter(pFileWriter,L"File Writer");
//// Set File name in File Writer filter
CComPtr <IFileSinkFilter> pfsink;
hr = pFileWriter->QueryInterface(IID_IFileSinkFilter,(void**)&pfsink);
hr = pfsink->SetFileName(L"C:\\test.mpg"/*A2COLE(m_avi)*/,NULL);

CComPtr<IPin> pSourcePin = GetOutPin(pSourceBase, 0);
CComPtr<IPin> pVideoIn = GetInPin (pVideoFilter, 0);
CComPtr<IPin> pVideoOut = GetOutPin(pVideoFilter, 0);
CComPtr<IPin> pWriteIn = GetInPin(pFileWriter, 0);

hr = pGraph->Connect(pSourcePin,pVideoIn);
if(FAILED(hr))
{
AfxMessageBox(TEXT("Cannot connect up video chain:1"));
return;
}
hr = pGraph->Connect(pVideoOut,pWriteIn);
if(FAILED(hr))
{
AfxMessageBox(TEXT("Cannot connect up video chain:2"));
return;
}
CComQIPtr< IMediaControl, &IID_IMediaControl > pControl(pGraph);
CComQIPtr< IMediaSeeking, &IID_IMediaSeeking > pSeeking(pGraph);
CComQIPtr< IMediaEvent, &IID_IMediaEvent > pEvent(pGraph);

hr = pSeeking->SetPositions( &rtNow,
AM_SEEKING_AbsolutePositioning,
&rtStop,
AM_SEEKING_AbsolutePositioning );
// Run the graph.
hr = pControl->Run();

// Wait for completion.
long evCode;
hr = pEvent->WaitForCompletion(INFINITE, &evCode);
pControl->Stop();
// Clean up.
CoUninitialize();

请各位指点一下,另外,我的这段代码,能实现提取一段视频的功能吗?
...全文
129 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
systemthink 2007-05-20
  • 打赏
  • 举报
回复
视频是什么格式的呀?
去codeproject上找一哈,有例子的,很不错
Revised for the 2015 update to the CompTIA Linux+/LPIC-1 objectives, this value-packed exam guide covers the leading vendor-neutral credential for Linux and comes with a virtual machine configured for hands-on exercises, video training, and hundreds of practice exam questions. Get complete coverage of all the objectives included on CompTIA Linux+ exams LX0-103 and LX0-104 and LPIC-1 exams 101-400 and 102-400 from this up-to-date resource. Written by a Linux expert and technology trainer, the book provides learning objectives at the beginning of each chapter, exam tips, practice exam questions, and in-depth answer explanations. Designed to help you pass these challenging exams, this definitive volume also serves as an essential on-the-job reference. Covers all exam topics, including how to: Work with the Linux shell Use the vi text editor Manage Linux files and directories Install Linux and manage the boot process Configure the graphical environment Manage software and hardware Manage users, groups, file systems, and processes Administer ownership, permissions, and quotas Write shell scripts Manage network settings and services Secure Linux and use encryption Electronic content includes: 200+ practice exam questions Virtual machine with custom configurations for select chapter exercises 50+ video clips PDF copy of the book Save 10% on CompTIA exam vouchers for any CompTIA certification! See inside the book for details. Table of Contents Chapter 1 An Introduction to Linux Chapter 2 Working with the Linux Shell Chapter 3 Using the vi Text Editor Chapter 4 Managing Linux Files and Directories Chapter 5 Installing Linux Chapter 6 Managing the Linux Boot Process Chapter 7 Managing the Graphical Environment Chapter 8 Managing Linux Software Chapter 9 Managing Linux Users and Groups Chapter 10 Managing Linux File Systems Chapter 11 Managing Ownership, Permissions, and Quotas Chapter 12 Managing Hardware Under Linux Chapter 13 Managing Linux Processes Chapter 14 Writing

19,467

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧