search
HomeDatabaseMysql TutorialOPENCV2.3 + FFMPEG + Visual Studio 2008 的坑爹之旅

使用opencv分析视频,虽然是要做研究单还要保证程序的工程性(不是只读一下特定AVI式就完了)于是乎选择了支持ffmpeg的opencv2.3 一开始没有问题,程序写的很爽,但是当我想回放一下视频片段的时候,问题一下就出来了:无法使用VideoCapture来准确的定位到视

使用opencv分析视频,虽然是要做研究单还要保证程序的工程性(不是只读一下特定AVI格式就完了)于是乎选择了支持ffmpeg的opencv2.3 

一开始没有问题,程序写的很爽,但是当我想回放一下视频片段的时候,问题一下就出来了:无法使用VideoCapture来准确的定位到视频中的某一特定时间


要解决问题:

 opencv无法正常回放视频(原因是VideoCapture::set 函数里只有一种关键帧模式,详情参见《OpenCV 2.3.1 中关于cvCaptureProperty()定位不准的问题》)


解决方案:

上面给出的链接文章已经给出了这一问题的解决方案,但是过于笼统(我怀疑他们应该是使用的linux系统),在windows下这一编译过程可以用坑爹来形容。好吧,让我们来回顾一下这一坑爹之旅。

1 要修改的代码部分请参见OpenCV 2.3.1 中关于cvCaptureProperty()定位不准的问题 这里不再重复

2 关键的问题来了:我在windows下使用cmake安装opencv的时候,根本就没有WITH_FFMPEG这个选项,而在网上查到的解决方案都是通过修改cmake而直接搞定的,简直可谓是轻松愉快加嗨皮OPENCV2.3 + FFMPEG + Visual Studio 2008 的坑爹之旅 ,下面给出windows下需要修改的一些内容。

2.1 先说ffmpeg的下载安装。由于一开始不是很清楚,就去ffmpeg的网站上下了最新版本编译好的程序,结果死活有函数找不到。后来google后发现,原来是因为opencv使用的是0.7x版本的ffmpeg,下载的时候大家注意一下。http://ffmpeg.zeranoe.com/builds/在这里下载,我是懒人,我下的编译完的版本。下载完,你怎么配置环境变量我就不管了,反正最后重新编译opencv时你能想起来就行。

2.2 然后我们可以打开opencv文件夹下面 CMakeLists.txt 这个文件发现

[html] view plaincopy

  1. if(UNIX)  
  2.     set(WITH_FFMPEG ON CACHE BOOL "Include FFMPEG support")  
  3.     if(NOT APPLE)  
  4.         set(WITH_UNICAP OFF CACHE BOOL "Include Unicap support (GPL)")  
  5.         set(WITH_GTK ON CACHE BOOL "Include GTK support")  
  6.         set(WITH_GSTREAMER ON CACHE BOOL "Include Gstreamer support")  
  7.         set(WITH_V4L ON CACHE BOOL "Include Video 4 Linux support")  
  8.         set(WITH_XINE OFF CACHE BOOL "Include Xine support (GPL)")  
  9.     endif()  
  10.     set(WITH_PVAPI ON CACHE BOOL "Include Prosilica GigE support")  
  11.     set(WITH_1394 ON CACHE BOOL "Include IEEE1394 support")  
  12. endif()  
通过上面代码可以看出来,只有在UNIX环境下才会有WITH_FFMPEG这个选项,好吧,往下的牛人可以直接修改这个txt了,来构造自己的cmakelist文件,可惜我对cmake不是很熟,不是很敢修改这些代码,于是乎我就采用了一个笨一些的方法,手动去修改cmake生成的项目配置文件

找到opencv_highgui这个项目,打开cap_ffmpeg.cpp文件,你会发现这么一段预编译代码

[html] view plaincopy

  1. #ifdef HAVE_FFMPEG  
  2. #include "cap_ffmpeg_impl.hpp"  
  3. #else  
  4. #include "cap_ffmpeg_api.hpp"  
  5. #endif  
由于windows下的CMAKE没有预定义HAVE_FFMPEG 所以说我们需要在预编译指令里面加上HAVE_FFMPEG,位置在项目->属性-> c++ ->预处理器定义

2.3 下一步是将你的ffmpeg库的include文件夹加到highgui项目中去,不想细说了,还有就是ffmpeg中的静态链接库。这些没有什么难度。然后编译一下,ok,满屏的错误。

转到cap_ffmpeg_impl.hpp文件,大部分的错误是从这里来的

2.3.1 找不到msinttypes.h文件 上这里下载 http://code.google.com/p/msinttypes/ 然后塞进项目去就行了。

2.3.2 INT64_C, UINT64_C 没定义, 自己定义一下就可以了。在文件中加入

[html] view plaincopy

  1. #define INT64_C  
  2. #define UINT64_C  
2.3.3 如果提示av_open_input_file 找不到,恭喜你,你没好好看前面的内容,你下错ffmpeg啦~~ 要0.7x版本~~

2.3.4 如果报错 snprintf 这个函数找不到,我不知道这个函数在那个头文件里,我加上了结果没找到,如果你知道的话就加上对应头文件就好了。或者你可以像我似的,使用一个把这个函数改成sprintf版本

[html] view plaincopy

  1. //snprintf(oc->filename, sizeof(oc->filename), "%s", filename);  
  2.     sprintf(oc->filename, filename, "%s");  
2.3.5 我就遇到了4个要修改的地方,如果你又遇到别的错误,那只好自己慢慢修改了。

2.3.6 重新编译highgui项目,替换原有的lib,dll文件。

2.3.7 PS, 貌似还需要删除opencv_ffmpeg.dll文件,这样才能调用正确的帧跳转方法,但是删除opencv_ffmpeg后,程序就无法读取非avi类型媒体文件。 目前原因不明,有时间在慢慢鼓捣吧。

OK,整个坑爹之旅到此结束。


http://blog.csdn.net/sxy0082002/article/details/7450623

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
MySQL's Place: Databases and ProgrammingMySQL's Place: Databases and ProgrammingApr 13, 2025 am 12:18 AM

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

MySQL: From Small Businesses to Large EnterprisesMySQL: From Small Businesses to Large EnterprisesApr 13, 2025 am 12:17 AM

MySQL is suitable for small and large enterprises. 1) Small businesses can use MySQL for basic data management, such as storing customer information. 2) Large enterprises can use MySQL to process massive data and complex business logic to optimize query performance and transaction processing.

What are phantom reads and how does InnoDB prevent them (Next-Key Locking)?What are phantom reads and how does InnoDB prevent them (Next-Key Locking)?Apr 13, 2025 am 12:16 AM

InnoDB effectively prevents phantom reading through Next-KeyLocking mechanism. 1) Next-KeyLocking combines row lock and gap lock to lock records and their gaps to prevent new records from being inserted. 2) In practical applications, by optimizing query and adjusting isolation levels, lock competition can be reduced and concurrency performance can be improved.

MySQL: Not a Programming Language, But...MySQL: Not a Programming Language, But...Apr 13, 2025 am 12:03 AM

MySQL is not a programming language, but its query language SQL has the characteristics of a programming language: 1. SQL supports conditional judgment, loops and variable operations; 2. Through stored procedures, triggers and functions, users can perform complex logical operations in the database.

MySQL: An Introduction to the World's Most Popular DatabaseMySQL: An Introduction to the World's Most Popular DatabaseApr 12, 2025 am 12:18 AM

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

The Importance of MySQL: Data Storage and ManagementThe Importance of MySQL: Data Storage and ManagementApr 12, 2025 am 12:18 AM

MySQL is an open source relational database management system suitable for data storage, management, query and security. 1. It supports a variety of operating systems and is widely used in Web applications and other fields. 2. Through the client-server architecture and different storage engines, MySQL processes data efficiently. 3. Basic usage includes creating databases and tables, inserting, querying and updating data. 4. Advanced usage involves complex queries and stored procedures. 5. Common errors can be debugged through the EXPLAIN statement. 6. Performance optimization includes the rational use of indexes and optimized query statements.

Why Use MySQL? Benefits and AdvantagesWhy Use MySQL? Benefits and AdvantagesApr 12, 2025 am 12:17 AM

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

Describe InnoDB locking mechanisms (shared locks, exclusive locks, intention locks, record locks, gap locks, next-key locks).Describe InnoDB locking mechanisms (shared locks, exclusive locks, intention locks, record locks, gap locks, next-key locks).Apr 12, 2025 am 12:16 AM

InnoDB's lock mechanisms include shared locks, exclusive locks, intention locks, record locks, gap locks and next key locks. 1. Shared lock allows transactions to read data without preventing other transactions from reading. 2. Exclusive lock prevents other transactions from reading and modifying data. 3. Intention lock optimizes lock efficiency. 4. Record lock lock index record. 5. Gap lock locks index recording gap. 6. The next key lock is a combination of record lock and gap lock to ensure data consistency.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),