我正在开发一个使用 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/