如何使用ffmpeg与MSVC ++解码视频? [英] how to use ffmpeg with MSVC++ to decode a video?

查看:244
本文介绍了如何使用ffmpeg与MSVC ++解码视频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做的是使用msvc ++编写一个示例应用程序,它将输入视频文件并对其进行解码。我想要使​​用我的应用程序中使用的ffmpeg函数完成所有的解码。我阅读了dranger的教程,但无法实现,任何帮助将非常感激。

解决方案

您有两个选项:


  1. 您可以自行构建源代码。

  2. 您可以使用dll下载已经构建的版本。

如果我是你,我会选择第二个选项。这是当我开始用ffmpeg体验时所做的。如果您从未构建源代码,建筑可能会是一种痛苦。



您可以从这里(您应该下载dev版本)。



将此文件放在 VisualStudio20xx / Projects / yourProjectName / yourProjectName /



下载后,您应该显示MSVC的标头和.lib文件。
转到
项目 - >属性 - >配置属性 - > C / C ++ - >一般
然后将附加包含目录设置为ffmpeg / include



应该设置ffmpeg的包含文件。



对于.lib文件:



项目 - >属性 - >配置属性 - >链接器 - >常规
将附加库目录设置为ffmpeg / lib



这应该设置.lib文件。



现在应该可以通过

 包含ffmpeg库externC
{
#include }

*(!)如果您收到数以千计的LNK2001链接器错误在这些步骤之后,您应该为您的包含添加一些pragma注释。我不是%100肯定这些评论做什么,你可以搜索它。但是,这是MSVC要了解的东西。



例如,

  #pragma comment(lib,avcodec.lib)

这个pragma评论也应该在externC范围内。



*(!)如果您收到此编译错误:'UINT64_C':未找到标识符 >

您可以使用此宏作为解决方法:

  #ifndef __STDC_CONSTANT_MACROS 
#define __STDC_CONSTANT_MACROS
#endif

现在关于编码/解码的东西,你可以检查我的这个的这个的问题


  1. 将文件解码为数据包

  2. 将数据包解码为帧

  3. 将帧编码成包

  4. 将数据包复制到文件中。

我学习从硬的方式,但代码是很好的评论,因此我想你可以理解什么/如何完成它来克服这个过程。


What i want to do is to make a sample application using msvc++ which will take input as a video file and decode it. I want all the decoding to be done using ffmpeg functions used in my application.I read dranger's tutorial but could not implement it, any help would be really appreciated.

解决方案

You have two options:

  1. you can build the source code yourself.
  2. you can download an "already builded version" with dlls.

If I were you, I would have chosen the second option. It was what I have had done when I started to experiencing with ffmpeg. Building can be a pain if you have never built a source code.

You can find latest ffmpeg builds from here (You should download the "dev" version).

Put this file inside VisualStudio20xx/Projects/yourProjectName/yourProjectName/

After downloading you should show MSVC the destination of headers & the .lib files. Go to Project -> Properties -> Configuration Properties -> C/C++ -> General then set the "Additional Include Directories" to ffmpeg/include

This should set the include files for ffmpeg.

For .lib files:

Project -> Properties -> Configuration Properties -> Linker -> General set "Additional Library Directories" to ffmpeg/lib

This should set the .lib files.

Now should be able to include ffmpeg libraries by

extern "C" 
{
     #include <libavcodec/avcodec.h>
}

*(!) If you get a thousands of LNK2001 linker errors after these steps, you should add some pragma comments for your includes. I am not %100 sure what do these comments do, you can search it. But it is something for MSVC to understand stuff.

For example,

#pragma comment (lib,"avcodec.lib")

this pragma comment too, should be in extern "C" scope.

*(!)If you get this compile error : 'UINT64_C': identifier not found

You can use this macro as a workaround:

#ifndef __STDC_CONSTANT_MACROS
#define __STDC_CONSTANT_MACROS
#endif 

Now about the encode/decode stuff, you can check this question of mine which contains a code that

  1. demuxes the file into packets
  2. decodes the packets into frames
  3. encodes the frames into packages
  4. muxes packets into a file.

I learnt from hard way but the code is well-commented therefore I think you can understand what/how exactly it does to overcome the process.

这篇关于如何使用ffmpeg与MSVC ++解码视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆