x264和FFMPEG 编译后遇到的一些问题:UINT64_C,

原:http://blog.csdn.net/bg2bkk/article/details/9048465

吭吃坑吃的编译安装完ffmpeg 0.75,在centos5.9上后,遇到了一些问题,都是十分常见的问题,希望对大家有用。

问题一

/usr/local/include/libavutil/common.h: In function ‘int32_t av_clipl_int32_c(int64_t)’:
/usr/local/include/libavutil/common.h:170: error: ‘UINT64_C’ was not declared in this scope

这个问题可以这么解决

编辑文件  gedit /usr/local/include/libavutil/common.h

添加如下代码可以解决。

//add by bg2bkk
#ifndef UINT64_C
#define UINT64_C(value) __CONCAT(value, ULL)
#endif
//add by bg2bkk

问题二

./ffmpeg_test: error while loading shared libraries: libavcodec.so.52: cannot open shared object file: No such file or directory

这个问题的原因在于没有把ffmpeg的lib放到ld.conf里,参考链接:http://forum.ivorde.ro/ffmpeg-error-while-loading-shared-libraries-libavdevice-so-52-cannot-open-shared-object-file-no-t129.html

这个thread不错,有很多有用的命令:

ldd `which ffmpeg` 查看ffmpeg的库是否可以找到

这时一般会打印为:

linux-gate.so.1 =>  (0x00f90000)
libavdevice.so.52 => not found
libavfilter.so.1 => not found
libavformat.so.52 => not found
libavcodec.so.52 => not found
libpostproc.so.51 => not found
libswscale.so.0 => not found
libavutil.so.50 => not found
libpthread.so.0 => /lib/libpthread.so.0 (0x00821000)
libm.so.6 => /lib/libm.so.6 (0x007da000)
libc.so.6 => /lib/libc.so.6 (0x0067b000)
/lib/ld-linux.so.2 (0x0065c000)

而命令find /usr/local/lib/ | grep -E "libavdevice.so.52|libavfilter.so.1|libavcodec.so.52|libavcore.so.0"

通常会打印输出

/usr/local/lib/libavdevice.so.52.5.0
/usr/local/lib/libavfilter.so.1
/usr/local/lib/libavdevice.so.52
/usr/local/lib/libavfilter.so.1.80.0
/usr/local/lib/libavcodec.so.52.123.0
/usr/local/lib/libavcodec.so.52

说明你有这些库,只是没有识别。当然,路径/usr/local/lib 和/usr/local/include主要是因为ffmpeg的安装前缀是/usr/lcoal,好像用户安装linux的软件默认都是这里。

修改文件sudo vim /etc/ld.so.conf

在文件里添加

/usr/local/lib

这句

然后保存退出。

sudo ldconfig

这样就可以找到这些库了。

问题三

./ffmpeg_test: error while loading shared libraries: /usr/local/lib/libswscale.so.0: cannot restore segment prot after reloc: Permission denied

这个问题属于

动态链接库加载出错:cannot restore segment prot after reloc: Permission denied

关闭selinux即可
sudo  /usr/sbin/setenforce 0


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是一个简单的使用FFmpeg解码并播放视频的demo代码: ```c #include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <string.h> #include <libavformat/avformat.h> #include <libavutil/imgutils.h> #include <libavutil/samplefmt.h> #include <libswscale/swscale.h> int main(int argc, char *argv[]) { AVFormatContext *fmt_ctx = NULL; AVCodecContext *codec_ctx = NULL; AVCodec *codec = NULL; AVFrame *frame = NULL; AVPacket pkt; int stream_index, ret; struct SwsContext *sws_ctx = NULL; const char *src_filename; const char *dst_filename; FILE *dst_file; if (argc < 3) { fprintf(stderr, "Usage: %s <input_file> <output_file>\n", argv[0]); exit(1); } src_filename = argv[1]; dst_filename = argv[2]; // 打开输入文件 if (avformat_open_input(&fmt_ctx, src_filename, NULL, NULL) < 0) { fprintf(stderr, "Error opening input file.\n"); exit(1); } // 获取流信息 if (avformat_find_stream_info(fmt_ctx, NULL) < 0) { fprintf(stderr, "Error finding stream information.\n"); exit(1); } // 打印流信息 av_dump_format(fmt_ctx, 0, src_filename, 0); // 找到视频流 stream_index = av_find_best_stream(fmt_ctx, AVMEDIA_TYPE_VIDEO, -1, -1, &codec, 0); if (stream_index < 0) { fprintf(stderr, "Error finding video stream.\n"); exit(1); } // 分配解码器上下文 codec_ctx = avcodec_alloc_context3(codec); if (!codec_ctx) { fprintf(stderr, "Error allocating codec context.\n"); exit(1); } // 复制解码器参数 if (avcodec_parameters_to_context(codec_ctx, fmt_ctx->streams[stream_index]->codecpar) < 0) { fprintf(stderr, "Error copying codec parameters.\n"); exit(1); } // 打开解码器 if (avcodec_open2(codec_ctx, codec, NULL) < 0) { fprintf(stderr, "Error opening codec.\n"); exit(1); } // 分配帧 frame = av_frame_alloc(); if (!frame) { fprintf(stderr, "Error allocating frame.\n"); exit(1); } // 打开输出文件 dst_file = fopen(dst_filename, "wb"); if (!dst_file) { fprintf(stderr, "Error opening output file.\n"); exit(1); } // 初始化SWS上下文 sws_ctx = sws_getContext(codec_ctx->width, codec_ctx->height, codec_ctx->pix_fmt, codec_ctx->width, codec_ctx->height, AV_PIX_FMT_RGB24, SWS_BILINEAR, NULL, NULL, NULL); // 读取数据包并解码 while (av_read_frame(fmt_ctx, &pkt) >= 0) { if (pkt.stream_index == stream_index) { ret = avcodec_send_packet(codec_ctx, &pkt); if (ret < 0) { fprintf(stderr, "Error sending a packet for decoding.\n"); exit(1); } while (ret >= 0) { ret = avcodec_receive_frame(codec_ctx, frame); if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) break; else if (ret < 0) { fprintf(stderr, "Error during decoding.\n"); exit(1); } // 转换像素格式 sws_scale(sws_ctx, (const uint8_t *const *)frame->data, frame->linesize, 0, frame->height, frame->data, frame->linesize); // 写入文件 fwrite(frame->data[0], 1, codec_ctx->width * codec_ctx->height * 3, dst_file); } } av_packet_unref(&pkt); } // 关闭输出文件 fclose(dst_file); // 释放资源 av_frame_free(&frame); avcodec_free_context(&codec_ctx); avformat_close_input(&fmt_ctx); sws_freeContext(sws_ctx); return 0; } ``` 这个程序可以读取一个视频文件并将其解码到RGB24格式,然后写入一个二进制文件中。如果您需要显示视频,可以使用相应的库将RGB24格式转换为您需要的格式,例如OpenGL或SDL等库。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值