步骤如下:

1. 下载

官网永远是王道,呵呵:http://ffmpeg.org/download.html

或者 svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg

2. 编译

    • 运行./configure
      很不幸,运行configure后出现了错误提示:
      yasm not found, use –disable-yasm for a crippled build

      解决方案:sudo apt-getinstall yasm
      重新./configure,搞定

    • make

    • make install
      权限不够需要前面加上sudo

    • 编译源码:一定注意加载库的顺序.

    • 参考代码:
    • #include <SDL/SDL.h>
      
      #include <libavcodec/avcodec.h>
      #include <libavformat/avformat.h>
      #include <stdio.h>
      #include <libswscale/swscale.h> int main(int argc, char *argv[]) {
      AVFormatContext *pFormatCtx;
      int i, videoStream;
      AVCodecContext *pCodecCtx;
      AVCodec *pCodec;
      AVFrame *pFrame;
      AVFrame *pFrameYUV;
      AVPacket packet;
      int frameFinished;
      int numBytes; // Register all formats and codecs
      av_register_all();
      // Open video file
      if (av_open_input_file(&pFormatCtx, "/home/user/workspace/panda/media/video/4f5a9c384d94eb21e5273ec263457535.mp4", NULL, , NULL )
      != ) {
      printf("=== cannot open file\n===");
      return -; // Couldn't open file
      }
      // Retrieve stream information
      if (av_find_stream_info(pFormatCtx) < )
      return -; // Couldn't find stream information
      // Dump information about file onto standard error
      // dump_format(pFormatCtx, 0, argv[1], false);
      // Find the first video stream
      videoStream = -;
      for (i = ; i < pFormatCtx->nb_streams; i++)
      if (pFormatCtx->streams[i]->codec->codec_type == CODEC_TYPE_VIDEO) ////////
      {
      videoStream = i;
      break;
      }
      if (videoStream == -)
      return -; // Didn't find a video stream
      // Get a pointer to the codec context for the video stream
      pCodecCtx = pFormatCtx->streams[videoStream]->codec; //////////
      ///////// SDL initialization
      SDL_Surface *screen = SDL_SetVideoMode(pCodecCtx->width, pCodecCtx->height, , SDL_HWSURFACE);
      SDL_Overlay *overlay = SDL_CreateYUVOverlay(pCodecCtx->width, pCodecCtx->height, SDL_YV12_OVERLAY, screen);
      static SDL_Rect rect;
      rect.x = ;
      rect.y = ;
      rect.w = pCodecCtx->width;
      rect.h = pCodecCtx->height;
      //////////
      // Find the decoder for the video stream
      pCodec = avcodec_find_decoder(pCodecCtx->codec_id);
      if (pCodec == NULL )
      return -; // Codec not found
      // Open codec
      if (avcodec_open(pCodecCtx, pCodec) < )
      return -; // Could not open codec // Allocate video frame
      pFrame = avcodec_alloc_frame();
      // Allocate an AVFrame structure
      pFrameYUV = avcodec_alloc_frame();
      if (pFrameYUV == NULL )
      return -; static struct SwsContext *img_convert_ctx; img_convert_ctx = sws_getContext(pCodecCtx->width, pCodecCtx->height, pCodecCtx->pix_fmt, pCodecCtx->width, pCodecCtx->height,
      // PIX_FMT_RGB24,
      PIX_FMT_YUV420P, SWS_BICUBIC, NULL, NULL, NULL ); // Set SDL events
      SDL_EventState(SDL_ACTIVEEVENT, SDL_IGNORE);
      SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
      SDL_ShowCursor(SDL_DISABLE); // Read frames
      while ((av_read_frame(pFormatCtx, &packet) >= ) && (SDL_PollEvent(NULL ) == )) {
      // Is this a packet from the video stream?
      if (packet.stream_index == videoStream) {
      // Decode video frame
      avcodec_decode_video(pCodecCtx, pFrame, &frameFinished, packet.data, packet.size);
      // Did we get a video frame?
      if (frameFinished) {
      // Convert the image from its native format to YUV, and display SDL_LockYUVOverlay(overlay);
      pFrameYUV->data[] = overlay->pixels[];
      pFrameYUV->data[] = overlay->pixels[];
      pFrameYUV->data[] = overlay->pixels[]; pFrameYUV->linesize[] = overlay->pitches[];
      pFrameYUV->linesize[] = overlay->pitches[];
      pFrameYUV->linesize[] = overlay->pitches[]; // img_convert((AVPicture *) pFrameYUV, PIX_FMT_YUV420P, (AVPicture *) pFrame, pCodecCtx->pix_fmt, pCodecCtx->width,
      // pCodecCtx->height); // other codes
      // Convert the image from its native format to RGB sws_scale(img_convert_ctx, (const uint8_t* const *) pFrame->data, pFrame->linesize, , pCodecCtx->height, pFrameYUV->data,
      pFrameYUV->linesize); SDL_UnlockYUVOverlay(overlay);
      SDL_DisplayYUVOverlay(overlay, &rect);
      ///
      SDL_Delay();
      }
      }
      // Free the packet that was allocated by av_read_frame
      av_free_packet(&packet);
      }
      // Free the RGB image
      av_free(pFrameYUV);
      // Free the YUV frame
      av_free(pFrame);
      // Close the codec
      avcodec_close(pCodecCtx);
      // Close the video file
      av_close_input_file(pFormatCtx);
      //
      SDL_FreeYUVOverlay(overlay);
      return ;
      }
    • 放大播放:
    • #include <SDL/SDL.h>
      
      #include <libavcodec/avcodec.h>
      #include <libavformat/avformat.h>
      #include <stdio.h>
      #include <libswscale/swscale.h> int avcodec_main(int argc, char *argv[]) {
      AVFormatContext *pFormatCtx;
      int i, videoStream;
      AVCodecContext *pCodecCtx;
      AVCodec *pCodec;
      AVFrame *pFrame;
      AVFrame *pFrameYUV;
      AVPacket packet;
      int frameFinished;
      int numBytes; // Register all formats and codecs
      av_register_all();
      // Open video file
      if (av_open_input_file(&pFormatCtx, "/home/user/workspace/panda/media/video/4f5a9c384d94eb21e5273ec263457535.mp4", NULL, 0, NULL )
      != 0) {
      printf("=== cannot open file\n===");
      return -1; // Couldn't open file
      }
      // Retrieve stream information
      if (av_find_stream_info(pFormatCtx) < 0)
      return -1; // Couldn't find stream information
      // Dump information about file onto standard error
      // dump_format(pFormatCtx, 0, argv[1], false);
      // Find the first video stream
      videoStream = -1;
      for (i = 0; i < pFormatCtx->nb_streams; i++)
      if (pFormatCtx->streams[i]->codec->codec_type == CODEC_TYPE_VIDEO) ////////
      {
      videoStream = i;
      break;
      }
      if (videoStream == -1)
      return -1; // Didn't find a video stream
      // Get a pointer to the codec context for the video stream
      pCodecCtx = pFormatCtx->streams[videoStream]->codec; ////////// ///////// SDL initialization
      int w = 1920, h = 1080; SDL_Surface *screen = SDL_SetVideoMode(w, h, 0, SDL_HWSURFACE);
      SDL_Overlay *overlay = SDL_CreateYUVOverlay(w, h, SDL_YV12_OVERLAY, screen);
      static SDL_Rect rect;
      rect.x = 0;
      rect.y = 0;
      rect.w = w;
      rect.h = h;
      //////////
      // Find the decoder for the video stream
      pCodec = avcodec_find_decoder(pCodecCtx->codec_id);
      if (pCodec == NULL )
      return -1; // Codec not found
      // Open codec
      if (avcodec_open(pCodecCtx, pCodec) < 0)
      return -1; // Could not open codec // Allocate video frame
      pFrame = avcodec_alloc_frame();
      // Allocate an AVFrame structure
      pFrameYUV = avcodec_alloc_frame();
      if (pFrameYUV == NULL )
      return -1; static struct SwsContext *img_convert_ctx; img_convert_ctx = sws_getContext(pCodecCtx->width, pCodecCtx->height, pCodecCtx->pix_fmt, w, h,
      // PIX_FMT_RGB24,
      PIX_FMT_YUV420P, SWS_BICUBIC, NULL, NULL, NULL ); // Set SDL events
      SDL_EventState(SDL_ACTIVEEVENT, SDL_IGNORE);
      SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
      SDL_ShowCursor(SDL_DISABLE); // Read frames
      while ((av_read_frame(pFormatCtx, &packet) >= 0) && (SDL_PollEvent(NULL ) == 0)) {
      // Is this a packet from the video stream?
      if (packet.stream_index == videoStream) {
      // Decode video frame
      avcodec_decode_video(pCodecCtx, pFrame, &frameFinished, packet.data, packet.size);
      // Did we get a video frame?
      if (frameFinished) {
      // Convert the image from its native format to YUV, and display SDL_LockYUVOverlay(overlay);
      pFrameYUV->data[0] = overlay->pixels[0];
      pFrameYUV->data[1] = overlay->pixels[2];
      pFrameYUV->data[2] = overlay->pixels[1]; pFrameYUV->linesize[0] = overlay->pitches[0];
      pFrameYUV->linesize[1] = overlay->pitches[2];
      pFrameYUV->linesize[2] = overlay->pitches[1]; // img_convert((AVPicture *) pFrameYUV, PIX_FMT_YUV420P, (AVPicture *) pFrame, pCodecCtx->pix_fmt, pCodecCtx->width,
      // pCodecCtx->height); // other codes
      // Convert the image from its native format to RGB sws_scale(img_convert_ctx, (const uint8_t* const *) pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pFrameYUV->data,
      pFrameYUV->linesize); SDL_UnlockYUVOverlay(overlay);
      SDL_DisplayYUVOverlay(overlay, &rect);
      ///
      SDL_Delay(30);
      }
      }
      // Free the packet that was allocated by av_read_frame
      av_free_packet(&packet);
      }
      // Free the RGB image
      av_free(pFrameYUV);
      // Free the YUV frame
      av_free(pFrame);
      // Close the codec
      avcodec_close(pCodecCtx);
      // Close the video file
      av_close_input_file(pFormatCtx);
      //
      SDL_FreeYUVOverlay(overlay);
      return 0;
      }

        

    • 参考http://hi.baidu.com/xiaomeng008/archive/tag/ffmpeg

    • ffmpeg: http://blog.csdn.net/byxdaz/article/details/7316304

      ffmpeg编译和使用大全     http://lvzun.iteye.com/blog/706121

    • 重点推荐:http://dranger.com/ffmpeg/ An ffmpeg and SDL Tutorial
    • http://www.libsdl.org/release/SDL-1.2.15/test/  SDL官方示例。 overlay有rgb转换到YUV.

ffmpeg 在ubuntu上编译环境搭建和开发的更多相关文章

  1. ubuntu上lamp环境搭建

    首先,介绍个彻底删除linux已经安装的软件的方法. sudo apt-get purge mysql-server mysql-client mysql-common mysql-server-5. ...

  2. Ubuntu下qemu环境搭建vexpress开发平台

    在查找资料过程中,发现自己搭建虚拟的arm环境的话,有一个比较好的软件就是qemu了,当然还有其他的,大家各投所好就好. 接下来说一下qemu环境搭建过程. 其实搭建很简单,作为小白,我还是捣鼓了两三 ...

  3. RabbitMQ系列(一)RabbitMQ在Ubuntu上的环境搭建

    环境配置 Ubuntu Server 18.04 RabbitMQ 3.6.10 安装之前 我们使用apt-get进行RabbitMQ安装,在安装之前,强烈建议您把apt源换位国内,大大增加下载安装的 ...

  4. Ubuntu上CUDA环境搭建

    1.下载CUDA:https://developer.nvidia.com/cuda-toolkit-archive (如果已经安装了N卡驱动,最好用.deb,如果没有安装,可以用.run) 2.根据 ...

  5. RabbitMQ在Ubuntu上的环境搭建

    1.修改/etc/apt/sources.list文件 A:命令:vi /etc/apt/sources.list B:在最后一行加上:deb http://www.rabbitmq.com/debi ...

  6. Ubuntu Desktop开发生产环境搭建

    Ubuntu Desktop开发生产环境搭建 1   开发生产环境搭建 在本节内容开始前,先定义一下使用场合,没有哪种系统或者设备是万能的,都有它的优点和缺点,能够在具体的使用场景,根据自身的需求来取 ...

  7. ubuntu12.04下安卓编译环境搭建总结

    前言:      因为工作需要,经常要编译安卓下的动态库,公司有已经搭建好环境的服务器,但是第一自己想自己搭建一下了解一个整个过程,另外,公司的服务器也经常出现问 题,导致编译不了,所以就想自己搭建环 ...

  8. Tiny4412 开发板 编译环境搭建【转】

    本文转载自:http://blog.csdn.net/beijiwei/article/details/51055369 版权声明:本文为博主原创文章,未经博主允许不得转载. /*********** ...

  9. u-boot 移植(一)编译环境搭建

    u-boot 移植(一)编译环境搭建 soc:s3c2440 board:jz2440 uboot:u-boot-2016.11 toolchain:gcc-linaro-7.4.1-2019.02- ...

随机推荐

  1. 基于Angular+WebAPI+OData的增删改查

    对于在ASP.NET WebAPI中怎么使用OData,已经在我前面的日志中的说明, 在ASP.NET Web API中使用OData 在这个示例中.我新建了一个Order的实体,在前端使用Angul ...

  2. Xamarin开发的一个简单画图程序分享

    最近Xamarin比较火,于是稍微看了下,感觉接触过MVC的都应该能很快上手,还挺有意思,于是忍不住写了个简单的画图程序,之前看帖子有人说装不上或者无法部署,估计我比较幸运,编译完了一次就安装成功了, ...

  3. GlusterFS分布式存储集群部署记录-相关补充

    接着上一篇Centos7下GlusterFS分布式存储集群环境部署记录文档,继续做一些补充记录,希望能加深对GlusterFS存储操作的理解和熟悉度. ======================== ...

  4. C. Maximum Subrectangle

    链接 [http://codeforces.com/contest/1060/problem/C] 题意 给你两个数列,可以构成一个矩阵C,ci,j=ai⋅bj 1≤x1≤x2≤n , 1≤y1≤y2 ...

  5. 《linux内核设计与分析》内核模块编程

    内核模块编程 一.准备工作 虚拟机:VMware Workstation 12操作系统:ubuntu当前内核版本:linux-headers-4.4.0-22-generic 二.有关于内核模块的知识 ...

  6. Linux内核第二节

    作者:武西垚 深入理解函数调用堆栈 堆栈是C语言程序运行时必须的一个记录调用路径和参数的空间 堆栈的作用 函数调用框架 传递参数 保存返回地址 提供局部变量空间 堆栈相关的寄存器 esp,堆栈指针,指 ...

  7. java_web—JSP+Servlet+JavaBean

    JSP -> Java Server Page  后端 jsp -> JavaScript  前端 JSP语法 1.JSP插入Java代码 三种形式: (1)<%!  %> ( ...

  8. 大三上学期安卓一边学一边开始做一个自己觉得可以的项目 广商小助手App 加油

    这项目构思好多 一个人一步一步来 一边做一边为后面应用铺设 广商小助手APP 设计出的软件登录场景 实现(算是可以) 界面大体出来了 界面点击方面也做了很多特效 上图其实点击各颜色后会出现各种图和反应 ...

  9. 虚拟机Linux(centos)系统能ping通主机,主机无法ping通Linux解决方案

    本文引用:https://blog.csdn.net/clean_water/article/details/53023308 三个步骤: 第一步:虚拟机网络连接方式选择Nat 第二步.关闭liunx ...

  10. Install Kernel 3.10 on CentOS 6.5

    http://bicofino.io/2014/10/25/install-kernel-3-dot-10-on-centos-6-dot-5/ https://gree2.github.io/lin ...