gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-31 02:22:02 24 4
gpt4 key购买 nike

我正在开发一个使用 ffmpeg 播放音频/视频的 c/c++ 应用程序。现在我想增强应用程序以允许用户从视频中提取音频并保存。我跟着这个https://ffmpeg.org/doxygen/trunk/muxing_8c-source.html对于保存部分,但现在问题出在 avformat_alloc_output_context2() 上。我收到一个错误:“对 `avformat_alloc_output_context2' 的 undefined reference “。有谁知道在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com