【发布时间】:2023-03-03 04:55:22
【问题描述】:
我已经在 Ubuntu 上成功构建了 FFmpeg,make examples 可以工作。我已经测试了示例“encode_video.c”,它生成了几个文件,如“encode_video”、“encode_video.d”、“encode_video.o”、“encode_video_g”和“encode_video”。 “encode_video”文件运行良好。
但是,当我想在其他地方手动构建此示例而不是命令make examples 时。编译就可以完成了。但是当我运行“encoding”文件时,它总是会显示“Codec xxx not found”。
我使用命令gcc -o encoding encode_video.c -lavcodec -lavutil。
这是“encode_video.c”的部分行。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libavcodec/avcodec.h>
#include <libavutil/opt.h>
#include <libavutil/imgutils.h>
int main(int argc, char **argv)
{
const char *filename, *codec_name;
const AVCodec *codec;
AVCodecContext *c= NULL;
int i, ret, x, y;
FILE *f;
AVFrame *frame;
AVPacket *pkt;
uint8_t endcode[] = { 0, 0, 1, 0xb7 };
if (argc <= 2) {
fprintf(stderr, "Usage: %s <output file> <codec name>\n", argv[0]);
exit(0);
}
filename = argv[1];
codec_name = argv[2];
/* find the mpeg1video encoder */
codec = avcodec_find_encoder_by_name(codec_name);
if (!codec) {
fprintf(stderr, "Codec '%s' not found\n", codec_name);
exit(1);
}
c = avcodec_alloc_context3(codec);
if (!c) {
fprintf(stderr, "Could not allocate video codec context\n");
exit(1);
}
pkt = av_packet_alloc();
if (!pkt)
exit(1);
}
【问题讨论】: