使用FFmpeg demo常见错误

编译SDK

编译之后,运行make install后,在C:/MSYS/local会生成bin、include、lib等文件夹。这样ffmpeg的编译环境就帮我生成了一个SDK,这个SDK在linux上用C来开发是没有问题的,我们需要使这个SDK在MS Visual Studio 开发环境中能用,编译的时候会碰到一大堆问题。我的环境是VS2008。

建立工程:

我们用ffplay验证我们的SDK,如果发现SDK问题,就可以得到及时的解决。建立一个ffplay的空工程,把ffplay.c,cmdutils.c,cmdutils.h,config.h导入这个空工程中,然后在VS2008中配置头文件目录和lib库目录(注意:ffplay需要用sdl,把sdl也加进入)

编译并排错

下面是在VS2008中,编译ffplay出现的错误,有些错误时ffplay中出现的,有些事sdk的问题。

fatal error C1083: 无法打开包括文件:“inttypes.h”: No such file or directory

在vs2008下没有这个文件,实际上这个文件无非也就是一些整形定义而已,可以直接注释掉这个包含,自己创建这个文件,放到inclue/libavutil下,include改为#include"libavutil/inttypes.h"

fatal error C1083: 无法打开包括文件:“stdint.h”: No such file or directory

copy C:/MSYS/include下的stdint.h到libavutil中。修改#include<stdint.h>#include“stdint.h”

fatal error C1083: 无法打开包括文件:“libavdevice/avdevice.h”: No such file or directory

用不着,直接注释

ffplay.cpp中报错

fatal error C1083: 无法打开包括文件:“libavcodec/audioconvert.h”: No such file or directory

fatal error C1083: 无法打开包括文件:“libavcodec/colorspace.h”: No such file or directory

make install安装的头文件不全,从libavcodec中copy这两个头文件

fatal error C1083: 无法打开包括文件:“unistd.h”: No such file or directory

许多在Linux下开发的C程序都需要头文件unistd.h,但VC中没有个头文件,

所以用VC编译总是报错。把下面的内容保存为unistd.h,可以解决这个问题。

/** This file is part of the Mingw32 package.

*  unistd.h maps     (roughly) to io.h

*/

#ifndef _UNISTD_H

#define _UNISTD_H

#include <io.h>

#include <process.h>

#endif /* _UNISTD_H */

提示

static int wanted_stream[AVMEDIA_TYPE_NB]={

    [AVMEDIA_TYPE_AUDIO]=-1,

    [AVMEDIA_TYPE_VIDEO]=-1,

    [AVMEDIA_TYPE_SUBTITLE]=-1,

};语法错误

VC的标准C++不支持这个赋值方式,我们改为

static int wanted_stream[AVMEDIA_TYPE_NB]=

{

     -1,

     -1,

     0,

     -1,

     0

};

error C3861: “rint”: 找不到标识符

rint函数是个四舍五入的方法,我们自己实现

inline long rint(double x)
{
if(x >= 0.)

return (long)(x + 0.5);
else
return (long)(x - 0.5);
}

指示FFTSample data[2][2*nb_freq];表达式错误

我们知道标准C++不支持动态数组。修改为

FFTSample *data[2];

data[1] = malloc(sizeof(FFTSample) * 2*nb_freq);

data[0] = malloc(sizeof(FFTSample) * 2*nb_freq);

最后释放

free(data[0]);

free(data[1]);

error C3861: “usleep”: 找不到标识符

VC中没有usleep,usleep是微妙级别的,所以需要把代码改为

usleep(is->audio_st &&is->show_audio ?rdftspeed*1000 : 5000);

to

Sleep (is->audio_st &&is->show_audio ?rdftspeed*1 : 5);

指出    ap->time_base= (AVRational){1, 25};语法错误。

还是标准C++不支持这种语法,修改为

ap->time_base.num = 1;

ap->time_base.den = 25;

error C2054: 在“inline”之后应输入“(”

这是因为c不支持inline,我们把cmdutils.c改为cmdutils.cpp,把ffplay.c改为ffplay.cpp。

链接错误:

现在编译可以通过,但是现实一大堆库没有链接(好像有77个链接错误),把

avcodec-52.lib

avformat-52.lib

avutil-50.lib

swscale-0.lib

加进去还是没用,发现是我们用了ffplay.cpp,需要在ffmpeg所有头文件中加。

#ifdef  __cplusplus

extern "C" {

#endif

#ifdef  __cplusplus

}

#endif

这样就可以正确链接了。

最后可以正确编译出ffplay.exe。我们把include、lib和ffmpeg编译出来的dll打包,就可以发布了。

//新问题:

1:pollfd 结构重定义;

    os_support.h 和 winsock2.h 结构重定义,将os_support.h文件中的pollfd结构改为,如下:

#if !HAVE_WINSOCK2_H
struct pollfd {
    int fd;
    short events;  /* events to look for */
    short revents; /* events that occurred */
};
#endif

2:

出现 'class' : missing tag name

将void show_help_children(const AVClass *class, int flags);

改成void show_help_children(const AVClass *avclass, int flags);

3:

INT64_MAX 未定义;

在 stdint.h 头文件中将条件编译取消;

4:

error C3861: “snprintf”: 找不到标识符

添加:#define snprintf _snprintf

5:

error C2146: 语法错误 : 缺少“)”(在标识符“PRIx64”的前面)

inttypes.h的内容改为如下:

// ISO C9x  compliant inttypes.h for Microsoft Visual Studio
// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124
//
//  Copyright (c) 2006 Alexander Chemeris
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
//   1. Redistributions of source code must retain the above copyright notice,
//      this list of conditions and the following disclaimer.
//
//   2. Redistributions in binary form must reproduce the above copyright
//      notice, this list of conditions and the following disclaimer in the
//      documentation and/or other materials provided with the distribution.
//
//   3. The name of the author may be used to endorse or promote products
//      derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
///

#ifndef _MSC_VER // [
#error "Use this header only with Microsoft Visual C++ compilers!"
#endif // _MSC_VER ]

#ifndef _MSC_INTTYPES_H_ // [
#define _MSC_INTTYPES_H_

#if _MSC_VER > 1000
#pragma once
#endif

#include "stdint.h"

// 7.8 Format conversion of integer types

typedef struct {
   intmax_t quot;
   intmax_t rem;
} imaxdiv_t;

// 7.8.1 Macros for format specifiers

//#if !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS) // [   See footnote 185 at page 198
#if defined(__cplusplus) || defined(__STDC_FORMAT_MACROS) // [   See footnote 185 at page 198 //yao;
// The fprintf macros for signed integers are:
#define PRId8       "d"
#define PRIi8       "i"
#define PRIdLEAST8  "d"
#define PRIiLEAST8  "i"
#define PRIdFAST8   "d"
#define PRIiFAST8   "i"

#define PRId16       "hd"
#define PRIi16       "hi"
#define PRIdLEAST16  "hd"
#define PRIiLEAST16  "hi"
#define PRIdFAST16   "hd"
#define PRIiFAST16   "hi"

#define PRId32       "I32d"
#define PRIi32       "I32i"
#define PRIdLEAST32  "I32d"
#define PRIiLEAST32  "I32i"
#define PRIdFAST32   "I32d"
#define PRIiFAST32   "I32i"

#define PRId64       "I64d"
#define PRIi64       "I64i"
#define PRIdLEAST64  "I64d"
#define PRIiLEAST64  "I64i"
#define PRIdFAST64   "I64d"
#define PRIiFAST64   "I64i"

#define PRIdMAX     "I64d"
#define PRIiMAX     "I64i"

#define PRIdPTR     "Id"
#define PRIiPTR     "Ii"

// The fprintf macros for unsigned integers are:
#define PRIo8       "o"
#define PRIu8       "u"
#define PRIx8       "x"
#define PRIX8       "X"
#define PRIoLEAST8  "o"
#define PRIuLEAST8  "u"
#define PRIxLEAST8  "x"
#define PRIXLEAST8  "X"
#define PRIoFAST8   "o"
#define PRIuFAST8   "u"
#define PRIxFAST8   "x"
#define PRIXFAST8   "X"

#define PRIo16       "ho"
#define PRIu16       "hu"
#define PRIx16       "hx"
#define PRIX16       "hX"
#define PRIoLEAST16  "ho"
#define PRIuLEAST16  "hu"
#define PRIxLEAST16  "hx"
#define PRIXLEAST16  "hX"
#define PRIoFAST16   "ho"
#define PRIuFAST16   "hu"
#define PRIxFAST16   "hx"
#define PRIXFAST16   "hX"

#define PRIo32       "I32o"
#define PRIu32       "I32u"
#define PRIx32       "I32x"
#define PRIX32       "I32X"
#define PRIoLEAST32  "I32o"
#define PRIuLEAST32  "I32u"
#define PRIxLEAST32  "I32x"
#define PRIXLEAST32  "I32X"
#define PRIoFAST32   "I32o"
#define PRIuFAST32   "I32u"
#define PRIxFAST32   "I32x"
#define PRIXFAST32   "I32X"

#define PRIo64       "I64o"
#define PRIu64       "I64u"
#define PRIx64       "I64x"
#define PRIX64       "I64X"
#define PRIoLEAST64  "I64o"
#define PRIuLEAST64  "I64u"
#define PRIxLEAST64  "I64x"
#define PRIXLEAST64  "I64X"
#define PRIoFAST64   "I64o"
#define PRIuFAST64   "I64u"
#define PRIxFAST64   "I64x"
#define PRIXFAST64   "I64X"

#define PRIoMAX     "I64o"
#define PRIuMAX     "I64u"
#define PRIxMAX     "I64x"
#define PRIXMAX     "I64X"

#define PRIoPTR     "Io"
#define PRIuPTR     "Iu"
#define PRIxPTR     "Ix"
#define PRIXPTR     "IX"

// The fscanf macros for signed integers are:
#define SCNd8       "d"
#define SCNi8       "i"
#define SCNdLEAST8  "d"
#define SCNiLEAST8  "i"
#define SCNdFAST8   "d"
#define SCNiFAST8   "i"

#define SCNd16       "hd"
#define SCNi16       "hi"
#define SCNdLEAST16  "hd"
#define SCNiLEAST16  "hi"
#define SCNdFAST16   "hd"
#define SCNiFAST16   "hi"

#define SCNd32       "ld"
#define SCNi32       "li"
#define SCNdLEAST32  "ld"
#define SCNiLEAST32  "li"
#define SCNdFAST32   "ld"
#define SCNiFAST32   "li"

#define SCNd64       "I64d"
#define SCNi64       "I64i"
#define SCNdLEAST64  "I64d"
#define SCNiLEAST64  "I64i"
#define SCNdFAST64   "I64d"
#define SCNiFAST64   "I64i"

#define SCNdMAX     "I64d"
#define SCNiMAX     "I64i"

#ifdef _WIN64 // [
#  define SCNdPTR     "I64d"
#  define SCNiPTR     "I64i"
#else  // _WIN64 ][
#  define SCNdPTR     "ld"
#  define SCNiPTR     "li"
#endif  // _WIN64 ]

// The fscanf macros for unsigned integers are:
#define SCNo8       "o"
#define SCNu8       "u"
#define SCNx8       "x"
#define SCNX8       "X"
#define SCNoLEAST8  "o"
#define SCNuLEAST8  "u"
#define SCNxLEAST8  "x"
#define SCNXLEAST8  "X"
#define SCNoFAST8   "o"
#define SCNuFAST8   "u"
#define SCNxFAST8   "x"
#define SCNXFAST8   "X"

#define SCNo16       "ho"
#define SCNu16       "hu"
#define SCNx16       "hx"
#define SCNX16       "hX"
#define SCNoLEAST16  "ho"
#define SCNuLEAST16  "hu"
#define SCNxLEAST16  "hx"
#define SCNXLEAST16  "hX"
#define SCNoFAST16   "ho"
#define SCNuFAST16   "hu"
#define SCNxFAST16   "hx"
#define SCNXFAST16   "hX"

#define SCNo32       "lo"
#define SCNu32       "lu"
#define SCNx32       "lx"
#define SCNX32       "lX"
#define SCNoLEAST32  "lo"
#define SCNuLEAST32  "lu"
#define SCNxLEAST32  "lx"
#define SCNXLEAST32  "lX"
#define SCNoFAST32   "lo"
#define SCNuFAST32   "lu"
#define SCNxFAST32   "lx"
#define SCNXFAST32   "lX"

#define SCNo64       "I64o"
#define SCNu64       "I64u"
#define SCNx64       "I64x"
#define SCNX64       "I64X"
#define SCNoLEAST64  "I64o"
#define SCNuLEAST64  "I64u"
#define SCNxLEAST64  "I64x"
#define SCNXLEAST64  "I64X"
#define SCNoFAST64   "I64o"
#define SCNuFAST64   "I64u"
#define SCNxFAST64   "I64x"
#define SCNXFAST64   "I64X"

#define SCNoMAX     "I64o"
#define SCNuMAX     "I64u"
#define SCNxMAX     "I64x"
#define SCNXMAX     "I64X"

#ifdef _WIN64 // [
#  define SCNoPTR     "I64o"
#  define SCNuPTR     "I64u"
#  define SCNxPTR     "I64x"
#  define SCNXPTR     "I64X"
#else  // _WIN64 ][
#  define SCNoPTR     "lo"
#  define SCNuPTR     "lu"
#  define SCNxPTR     "lx"
#  define SCNXPTR     "lX"
#endif  // _WIN64 ]

#endif // __STDC_FORMAT_MACROS ]

// 7.8.2 Functions for greatest-width integer types

// 7.8.2.1 The imaxabs function
#define imaxabs _abs64

// 7.8.2.2 The imaxdiv function

// This is modified version of div() function from Microsoft's div.c found
// in %MSVC.NET%\crt\src\div.c
#ifdef STATIC_IMAXDIV // [
static
#else // STATIC_IMAXDIV ][
_inline
#endif // STATIC_IMAXDIV ]
imaxdiv_t __cdecl imaxdiv(intmax_t numer, intmax_t denom)
{
   imaxdiv_t result;

   result.quot = numer / denom;
   result.rem = numer % denom;

   if (numer < 0 && result.rem > 0) {
      // did division wrong; must fix up
      ++result.quot;
      result.rem -= denom;
   }

   return result;
}

// 7.8.2.3 The strtoimax and strtoumax functions
#define strtoimax _strtoi64
#define strtoumax _strtoui64

// 7.8.2.4 The wcstoimax and wcstoumax functions
#define wcstoimax _wcstoi64
#define wcstoumax _wcstoui64


#endif // _MSC_INTTYPES_H_ ]

6:

    AVRational tb = ist->framerate.num ? (AVRational){ist->framerate.den,
                                                      ist->framerate.num} :
                                         ist->st->time_base;

改为:

AVRational tb = ist->framerate.num ? ist->framerate : ist->st->time_base;

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值