c++ - 如何在ffmpeg 2.6.3中调用avformat_alloc_output_context2?

标签 c++ qt ffmpeg

我正在开发一个使用 ffmpeg 播放音频/视频的 C/C++ 应用程序。现在我想增强该应用程序以允许用户从视频中提取音频并保存它。我关注了这个https://ffmpeg.org/doxygen/trunk/muxing_8c-source.html对于保存部分,但现在问题出在 avformat_alloc_output_context2() 上。我收到错误:“未定义对‘avformat_alloc_output_context2’的引用 ”。有谁知道在 ffmpeg 版本 2.6.3 中调用 'avformat_alloc_output_context2' 的正确方法

最佳答案

记得包含

extern "C"
{
     #include "libavformat/avformat.h"
}

之后你就可以调用

 * @param *ctx is set to the created format context, or to NULL in
 * case of failure
 * @param oformat format to use for allocating the context, if NULL
 * format_name and filename are used instead
 * @param format_name the name of output format to use for allocating the
 * context, if NULL filename is used instead
 * @param filename the name of the filename to use for allocating the
 * context, may be NULL
 * @return >= 0 in case of success, a negative AVERROR code in case of
 * failure
 */
 int avformat_alloc_output_context2(AVFormatContext **ctx, AVOutputFormat *oformat, const char *format_name, const char *filename);

例如:

static const char* output_formats[] = { NULL, "mp3", "ogg", "wav" };

AVFormatContext* formatCtx = NULL;

QString outputFileName = "insert here your output file name";

avformat_alloc_output_context2(&formatCtx, NULL, output_formats[1], outputFileName.toStdString().c_str());
if(formatCtx == NULL)
{
    //allocation have failed
}

关于c++ - 如何在ffmpeg 2.6.3中调用avformat_alloc_output_context2?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30784796/

相关文章:

c++ - 如何迭代枚举?

c++ - 使用 GCC 和 C++11 实现类型 "long double"

linux - 相同的 QFont 配置导致嵌入式 Linux 和 Linux Ubuntu 之间的字体不同

c++ - 我在C++中创建可除数为30的数字的函数

c++ - 我的程序崩溃了,我找不到原因

c++ - 如何使用Xcode编译qt .uic文件?

c++ - 如何将 QDateTime 转换为 GMT Unix Stamp

python - FFMPEG 和 Pythons 子进程

video - libavcodec 获取视频时长和帧率

objective-c - 如何在 Objective-C 中使用 FFmpeg 在 macOS 中录制屏幕?