[笔记] Ubuntu下编译ffmpeg+openh264+x264

[下载代码]
 
- ffmpeg: git clone git://source.ffmpeg.org/ffmpeg.git
- openh264: git clone  https://github.com/cisco/openh264.git
- x264: git clone http://git.videolan.org/git/x264.git
 
[编译 openh264]
 
make
sudo make install
 
[编译 x264]
 
./configure --enable-shared
make

sudo make install


[编译 ffmpeg]
 

./configure \
--enable-shared \
--enable-libopenh264 \
--enable-libx264 \
--enable-gpl \
--prefix=/usr/local/ffmpeg

make

sudo make install

 

 

 

 

[配置环境]
 
cd /etc/ld.so.conf.d/
创建 ffmpeg.conf,写入 "/usr/local/ffmpeg/lib"
sudo ldconfig
sudo ln -s /usr/local/ffmpeg/bin/ffmpeg /usr/local/bin/
sudo ln -s /usr/local/ffmpeg/bin/ffprobe /usr/local/bin/
sudo ln -s /usr/local/ffmpeg/bin/ffserver /usr/local/bin/
 
[验证 ffmpeg]
 
ffmpeg --help
 
[使用 ffmpeg]
 
使用 openh264 将 avi 视频转为 mp4 视频:
ffmpeg -y -i in.avi -vcodec libopenh264 out.mp4
 

 
[更新于2016-07-15]
 
如果希望编译出静态ffmpeg,且包含libx264,假设x264和ffmpeg是同级相邻目录,需要如下操作:
 
[静态编译libx264]
 
./configure  --prefix=.  --enable-static
make
make install
 
[静态编译ffmpeg]
 
./configure  \
--enable-static \
--disable-shared \
--enable-libx264 \
--enable-gpl \
--enable-ffprobe \
--extra-cflags=-I../x264/include \
--extra-ldflags=-L../x264/lib \
--extra-libs=-ldl
 
make
make install
 
最终得到ffmpeg和ffprobe。

转载于:https://www.cnblogs.com/journeyonmyway/p/4648820.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要使用FFmpeg进行OpenH264解码,你需要按照以下步骤进行操作: 1. 确保你已经安装了OpenH264编解码器库。你可以从OpenH264官方网站下载并安装OpenH264库。 2. 在你的代码中,添加FFmpeg的头文件和链接FFmpeg库。头文件包括`<libavcodec/avcodec.h>`,`<libavformat/avformat.h>`,`<libavutil/avutil.h>`和`<libswscale/swscale.h>`。 3. 创建一个AVFormatContext对象,并使用avformat_open_input函数打开你的输入视频文件。 ```c AVFormatContext *format_ctx = avformat_alloc_context(); if (avformat_open_input(&format_ctx, input_file, NULL, NULL) != 0) { // 处理打开输入文件失败的情况 return -1; } ``` 4. 使用avformat_find_stream_info函数查找视频流的相关信息。 ```c if (avformat_find_stream_info(format_ctx, NULL) < 0) { // 处理查找流信息失败的情况 return -1; } ``` 5. 找到视频流的索引。 ```c int video_stream_index = -1; for (int i = 0; i < format_ctx->nb_streams; i++) { if (format_ctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { video_stream_index = i; break; } } if (video_stream_index == -1) { // 处理找不到视频流的情况 return -1; } ``` 6. 获取视频解码器参数。 ```c AVCodecParameters *codec_params = format_ctx->streams[video_stream_index]->codecpar; ``` 7. 查找OpenH264解码器。 ```c AVCodec *codec = avcodec_find_decoder_by_name("libopenh264"); if (!codec) { // 处理找不到解码器的情况 return -1; } ``` 8. 创建解码器上下文并将解码器参数复制到上下文。 ```c AVCodecContext *codec_ctx = avcodec_alloc_context3(codec); if (!codec_ctx) { // 处理创建解码器上下文失败的情况 return -1; } if (avcodec_parameters_to_context(codec_ctx, codec_params) < 0) { // 处理复制解码器参数到上下文失败的情况 return -1; } ``` 9. 打开解码器。 ```c if (avcodec_open2(codec_ctx, codec, NULL) < 0) { // 处理打开解码器失败的情况 return -1; } ``` 10. 创建AVFrame对象用于存储解码后的帧数据。 ```c AVFrame *frame = av_frame_alloc(); if (!frame) { // 处理创建帧失败的情况 return -1; } ``` 11. 创建AVPacket对象用于存储压缩数据。 ```c AVPacket packet; av_init_packet(&packet); packet.data = NULL; packet.size = 0; ``` 12. 读取并解码每一帧数据。 ```c while (av_read_frame(format_ctx, &packet) >= 0) { if (packet.stream_index == video_stream_index) { // 解码视频帧 if (avcodec_send_packet(codec_ctx, &packet) == 0) { while (avcodec_receive_frame(codec_ctx, frame) == 0) { // 处理解码后的帧数据 // frame->data[0], frame->data[1], frame->data[2]分别为YUV420格式的Y、U、V平面数据 } } } av_packet_unref(&packet); } ``` 13. 清理资源。 ```c av_frame_free(&frame); avcodec_free_context(&codec_ctx); avformat_close_input(&format_ctx); ``` 这些步骤描述了使用FFmpeg进行OpenH264解码的基本流程。你可以根据自己的需求进行进一步的处理和操作。请注意,上述示例代码仅供参考,具体的实现可能需要根据实际情况进行调整和修改。 希望这能对你有所帮助!如有任何问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值