热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Ubuntu安装FFmpeg编码出MP4文件的方法

http:wiki.ubuntu.org.cnUbuntuSkillsUbuntu安装FFmpeg编码出MP4文件的方法2011-09-0616:42佚名linux公社字号

http://wiki.ubuntu.org.cn/UbuntuSkills

Ubuntu安装FFmpeg编码出MP4文件的方法
2011-09-06 16:42 佚名 linux公社 字号:T | T
一键收藏,随时查看,分享好友!

FFmpeg是Ubuntu下强大的视频、音频编解码工具。 x264可以编码出高质量的h.264视频,iPad必须要h.264编码或mpeg-4编码的视频才能正常播放。Ubuntu官方源默认是不提供h.264编码的,这就需要我们手工编译安装FFmpeg的h.264支持,使之能够编码出MP4文件。

AD:2013云计算架构师峰会课程资料下载

 

FFmpegUbuntu下强大的视频、音频编解码工具。 x264可以编码出高质量的h.264视频,iPad必须要h.264编码或mpeg-4编码的视频才能正常播放。

由于版权方面尚未确定,虽然全国很多网站都在使用h.264编码,但将来很有可能会被版权问题所困扰,所以Ubuntu官方源默认是不提供h.264编码的,这就需要我们手工编译安装FFmpeg的h.264支持,使之能够编码出MP4文件。

Ubuntu下安装、使用和升级FFmpeg的方法如下

1、安装支持包

  1. #libMP3lame  
  2.  
  3. sudo apt-get remove libMP3lame-dev  
  4.  
  5. sudo apt-get install nasm  
  6.  
  7. wget  
  8.  
  9. tar xzvf lame-3.98.4.tar.gz  
  10.  
  11. cd lame-3.98.4  
  12.  
  13. ./configure --enable-nasm --disable-shared  
  14.  
  15. make  
  16.  
  17. sudo checkinstall --pkgname=lame-ffmpeg --pkgversion="3.98.4" --backup=no --default --deldoc=yes 

#卸载现有的 x264、libx264-dev、FFmpeg

  1. sudo apt-get remove ffmpeg x264 libx264-dev 

#安装所有的 FFmpeg 和 x264 支持包

  1. sudo apt-get update  
  2.  
  3. sudo apt-get install build-essential subversion git-core checkinstall yasm texi2html libfaac-dev libMP3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libsdl1.2-dev libtheora-dev libvorbis-dev libvpx-dev libx11-dev libxfixes-dev libxvidcore-dev zlib1g-dev 

2、安装x264

  1. cd  
  2.  
  3. git clone git://git.videolan.org/x264.git  
  4.  
  5. cd x264  
  6.  
  7. #./configure  
  8.  ./configure --enable-static --enabled-shared
  9. make  
  10.  
  11. sudo checkinstall --pkgname=x264 --pkgversion "2:0.`grep X264_BUILD x264.h -m1 | cut -d' ' -f3`.`git rev-list HEAD | wc -l`+git`git rev-list HEAD -n 1 | head -c 7`" --backup=no --deldoc=yes --fstrans=no --default 

3、安装FFmpeg

  1. cd  
  2.  
  3. svn checkout svn://svn.ffmpeg.org/ffmpeg/trunk ffmpeg  
  4.  
  5. cd ffmpeg  
  6.  
  7. ./configure --enable-gpl --enable-version3 --enable-nonfree --enable-postproc --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxvid 
  8. #--enable-x11grab  
  9.  
  10. gcc使用正确的版本http://forums.debian.net/viewtopic.php?f=10&t=103908
  11. http://www.linuxquestions.org/questions/linux-software-2/managed-environment-ffmpeg-install-4175461262/
  12. make  
  13.  
  14. sudo checkinstall --pkgname=ffmpeg --pkgversion "4:SVN-r`LANG=C svn info | grep Revision | awk '{ print $NF }'`" --backup=no --deldoc=yes --fstrans=no --default  
  15.  
  16. hash x264 ffmpeg ffplay 

4、安装qt-faststart(可选)

这是个重要的x264再编码工具, 它的作用是使得视频不必等待下载完成即可开始播放。

使用方法:

  1. qt-faststart input.foo output.foo 

安装方法:

  1. cd ~/ffmpeg  
  2.  
  3. make tools/qt-faststart  
  4.  
  5. sudo checkinstall --pkgname=qt-faststart --pkgversion "4:SVN-r`LANG=C svn info | grep Revision | awk '{ print $NF }'`" --backup=no --deldoc=yes --fstrans=no --default install -D -m755 tools/qt-faststart /usr/local/bin/qt-faststart 

5、基本安装完成,你可以保留 ~/x264、~/ffmpeg目录以便将来升级时使用。

6、升级 FFmpeg 和 x264

  1. sudo apt-get remove ffmpeg x264 libx264-dev libvpx  
  2.  
  3. cd ~/x264  
  4.  
  5. make distclean  
  6.  
  7. git pull  
  8.  
  9. cd ~/ffmpeg  
  10.  
  11. make distclean  
  12.  
  13. svn update  
  14.  
  15. ./configure --enable-gpl --enable-version3 --enable-nonfree --enable-postproc --enable-libfaac --enable-libMP3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxvid --enable-x11grab  
  16.  
  17. make  
  18.  
  19. sudo checkinstall --pkgname=ffmpeg --pkgversion "4:SVN-r`LANG=C svn info | grep Revision | awk '{ print $NF }'`" --backup=no --deldoc=yes --fstrans=no --default  
  20.  
  21. hash x264 ffmpeg ffplay 

7、使用 FFmpeg and x264

容易的输出高质量视频的方法是使用FFmpeg中libx264的预设模式。你可以手工调整一些选项 (例如窗口大小: -s 640×480) 。 另外你可以参考 libx264 预设模式在线列表或再 /usr/local/share/ffmpeg 目录中查找帮助。

One-pass CRF (Constant Rate Factor) 使用预设模式:slow. One-pass CRF是经常使用的常规编码方式. 调整 -crf 可以改变输出质量. 数字越小输出质量越高同时输出尺寸越大. 可使用的数字范围是:18 ~ 28。

  1. ffmpeg -i input.avi -acodec libfaac -ab 128k -ac 2 -vcodec libx264 -vpre slow -crf 22 -threads 0 output.MP4 

Two-Pass encode 使用预设模式: fast. 想要精确设置目标编码率、文件大小的时候会使用到这个编码模式。

  1. ffmpeg -i input.avi -pass 1 -vcodec libx264 -vpre fast_firstpass -b 512k -bt 512k -threads 0 -f rawvideo -an -y /dev/null && ffmpeg -i input.avi -pass 2 -acodec libfaac -ab 128k -ac 2 -vcodec libx264 -vpre fast -b 512k -bt 512k -threads 0 output.MP4 

iPod/iPad 640×480,使用预设值: slow 和 ipod640:

  1. ffmpeg -i input.avi -acodec libfaac -aq 100 -ac 2 -vcodec libx264 -vpre slow -vpre ipod640 -crf 26 -map_meta_data 0:0 -vf scale=640:-1 -threads 0 output.MP4 

总结:

欲知更多有关Ubuntu安装FFmpeg编码出MP4文件的方法,请点击Ubuntu如何转换mp4与x264和h.264。

 

 

https://trac.ffmpeg.org/wiki/UbuntuCompilationGuide

 

Compile FFmpeg on Ubuntu, Debian, or Mint

 

Contents

  1. Get the Dependencies
  2. Compilation & Installation
  3. Finish
  4. Updating FFmpeg
  5. Reverting Changes Made by This Guide
  6. If You Need Help
  7. Also See

 

This guide for supported releases of UbuntuDebian, and Linux Mint will provide a local install of the latest FFmpeg tools and libraries including several external encoding and decoding libraries (codecs). This will not provide a system installation and therefore will not interfere with anything such as repository packages. Recent static builds are also available for lazy people or those who are unable to compile.


Get the Dependencies

Copy and paste the whole code box for each step.

sudo apt-get update
sudo apt-get -y install autoconf automake build-essential git libass-dev libgpac-dev \libsdl1.2-dev libtheora-dev libtool libva-dev libvdpau-dev libvorbis-dev libx11-dev \libxext-dev libxfixes-dev pkg-config texi2html zlib1g-dev
mkdir ~/ffmpeg_sources

  • Server users can omit the ffplay and x11 dependencies: libsdl1.2-dev libva-dev libvdpau-dev libx11-dev libxext-dev libxfixes-dev.
  • Ubuntu 10.04 Lucid users will need to install the git-core package instead of the git package. Lucid lacks the package libva-dev. This can be ignored.

Compilation & Installation

One advantage to compiling is that you can build ffmpeg to your liking. If you do not require certain encoders you may skip the relevant section and then remove the appropriate ./configure option in FFmpeg. For example, if libopus is not needed, then skip that section and then remove --enable-libopus from the Install FFmpeg section.

Yasm

Yasm is an assembler used by x264 and FFmpeg.

Ubuntu 13.10, Ubuntu 13.04, and Mint 15 users can alternatively install the yasm package from the repository instead of compiling.

cd ~/ffmpeg_sources
wget http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz
tar xzvf yasm-1.2.0.tar.gz
cd yasm-1.2.0
./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin"
make
make install
make distclean
. ~/.profile

x264

H.264 video encoder. See the x264 Encoding Guide for more information and examples.

cd ~/ffmpeg_sources
git clone --depth 1 git://git.videolan.org/x264.git
cd x264
./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --enable-static
make
make install
make distclean

Note: You can download the nightly  x264 source snapshot as an alternative to using git.

fdk-aac

AAC audio encoder. See the AAC Encoding Guide for more information and examples.

cd ~/ffmpeg_sources
git clone --depth 1 git://git.code.sf.net/p/opencore-amr/fdk-aac
cd fdk-aac
autoreconf -fiv
./configure --prefix="$HOME/ffmpeg_build" --disable-shared
make
make install
make distclean

Note: You can download a  fdk-aac source snapshot as an alternative to using git.

libmp3lame

MP3 audio encoder.

Most users can install the repository package:

sudo apt-get install libmp3lame-dev

Ubuntu 10.04 and Debian Squeeze users must compile:

sudo apt-get install nasm
cd ~/ffmpeg_sources
wget http://downloads.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz
tar xzvf lame-3.99.5.tar.gz
cd lame-3.99.5
./configure --prefix="$HOME/ffmpeg_build" --enable-nasm --disable-shared
make
make install
make distclean

libopus

Opus audio decoder and encoder.

Ubuntu 13.10, Ubuntu 13.04, and Mint 15 users can alternatively install the libopus-dev package from the repository instead of compiling.

cd ~/ffmpeg_sources
wget http://downloads.xiph.org/releases/opus/opus-1.0.3.tar.gz
tar xzvf opus-1.0.3.tar.gz
cd opus-1.0.3
./configure --prefix="$HOME/ffmpeg_build" --disable-shared
make
make install
make distclean

libvpx

VP8/VP9 video encoder and decoder. See the vpx (WebM) Encoding Guide for more information and examples.

Ubuntu 13.10, Ubuntu 13.04, and Mint 15 users can alternatively install the libvpx-dev package from the repository instead of compiling.

cd ~/ffmpeg_sources
git clone --depth 1 http://git.chromium.org/webm/libvpx.git
cd libvpx
./configure --prefix="$HOME/ffmpeg_build" --disable-examples
make
make install
make clean

Note: You can download a  libvpx source snapshot as an alternative to using git.

ffmpeg

Note: Server users should remove --enable-x11grab from the following command:

cd ~/ffmpeg_sources
git clone --depth 1 git://source.ffmpeg.org/ffmpeg
cd ffmpeg
PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig"
export PKG_CONFIG_PATH
./configure --prefix="$HOME/ffmpeg_build" \--extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" \--bindir="$HOME/bin" --extra-libs="-ldl" --enable-gpl --enable-libass --enable-libfdk-aac \--enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx \--enable-libx264 --enable-nonfree --enable-x11grab
make
make install
make distclean
hash -r

Note: You can download the nightly FFmpeg source snapshot as an alternative to using git.


Finish

  • Installation is now complete and ffmpeg is now ready for use. See the x264 Encoding Guide for examples.
  • If you do not see FFmpeg developers in your ffmpeg console output then something went wrong and you're probably using the  fake "ffmpeg" from the repository.
  • HTML formatted documentation is available in ~/ffmpeg_build/share/doc/ffmpeg.
  • You can keep the ffmpeg_sources directory if you plan on updating later. See Updating FFmpeg below for more details followed by instructions for reverting all changes made by this guide.

Updating FFmpeg

Development of FFmpeg is active and an occasional update can give you new features and bug fixes. First, remove (or move) the old files and then update the dependencies:

rm -rf ~/ffmpeg_build ~/bin/{ffmpeg,ffprobe,ffserver,vsyasm,x264,yasm,ytasm}
sudo apt-get update
sudo apt-get -y install autoconf automake build-essential git libass-dev libgpac-dev \libsdl1.2-dev libtheora-dev libtool libva-dev libvdpau-dev libvorbis-dev libx11-dev \libxext-dev libxfixes-dev pkg-config texi2html zlib1g-dev

Server users can omit: libsdl1.2-dev libva-dev libvdpau-dev libx11-dev libxext-dev libxfixes-dev.

x264

cd ~/ffmpeg_sources/x264
make distclean
git pull

Now run ./configuremake, and make install as shown in the Install x264 section.

fdk-aac

cd ~/ffmpeg_sources/fdk-aac
make distclean
git pull

Now run ./configuremake, and make install as shown in the Install fdk-aac section.

libvpx

cd ~/ffmpeg_sources/libvpx
make clean
git pull

Now run ./configuremake, and make install as shown in the Install libvpx section.

ffmpeg

cd ~/ffmpeg_sources/ffmpeg
make distclean
git pull

Now run ./configuremake, and make install as shown in the Install FFmpeg section.


Reverting Changes Made by This Guide

To remove ffmpeg, x264, and dependencies installed for this guide:

rm -rf ~/ffmpeg_build ~/ffmpeg_sources ~/bin/{ffmpeg,ffprobe,ffserver,vsyasm,x264,yasm,ytasm}
sudo apt-get autoremove autoconf automake build-essential git libass-dev libgpac-dev \libmp3lame-dev libopus-dev libsdl1.2-dev libtheora-dev libtool libva-dev libvdpau-dev \libvorbis-dev libvpx-dev libx11-dev libxext-dev libxfixes-dev texi2html zlib1g-dev
hash -r


If You Need Help

Feel free to ask questions at the #ffmpeg IRC channel or the ffmpeg-user mailing list.


Also See

  • x264 Encoding Guide
  • AAC Encoding Guide
  •  Howto: Compile the development version of VLC under the latest Ubuntu release
  •  Howto: Build the svn MPlayer under the latest release version of Ubuntu



推荐阅读
  • 本文介绍了在Android Studio中使用命令行build gradle的方法,并解决了一些常见问题,包括手动配置gradle环境变量和解决External Native Build Issues的方法。同时提供了相关参考文章链接。 ... [详细]
  • 在Docker中,将主机目录挂载到容器中作为volume使用时,常常会遇到文件权限问题。这是因为容器内外的UID不同所导致的。本文介绍了解决这个问题的方法,包括使用gosu和suexec工具以及在Dockerfile中配置volume的权限。通过这些方法,可以避免在使用Docker时出现无写权限的情况。 ... [详细]
  • 安装mysqlclient失败解决办法
    本文介绍了在MAC系统中,使用django使用mysql数据库报错的解决办法。通过源码安装mysqlclient或将mysql_config添加到系统环境变量中,可以解决安装mysqlclient失败的问题。同时,还介绍了查看mysql安装路径和使配置文件生效的方法。 ... [详细]
  • CentOS 6.5安装VMware Tools及共享文件夹显示问题解决方法
    本文介绍了在CentOS 6.5上安装VMware Tools及解决共享文件夹显示问题的方法。包括清空CD/DVD使用的ISO镜像文件、创建挂载目录、改变光驱设备的读写权限等步骤。最后给出了拷贝解压VMware Tools的操作。 ... [详细]
  • 树莓派语音控制的配置方法和步骤
    本文介绍了在树莓派上实现语音控制的配置方法和步骤。首先感谢博主Eoman的帮助,文章参考了他的内容。树莓派的配置需要通过sudo raspi-config进行,然后使用Eoman的控制方法,即安装wiringPi库并编写控制引脚的脚本。具体的安装步骤和脚本编写方法在文章中详细介绍。 ... [详细]
  • 本文介绍了在rhel5.5操作系统下搭建网关+LAMP+postfix+dhcp的步骤和配置方法。通过配置dhcp自动分配ip、实现外网访问公司网站、内网收发邮件、内网上网以及SNAT转换等功能。详细介绍了安装dhcp和配置相关文件的步骤,并提供了相关的命令和配置示例。 ... [详细]
  • Windows下配置PHP5.6的方法及注意事项
    本文介绍了在Windows系统下配置PHP5.6的步骤及注意事项,包括下载PHP5.6、解压并配置IIS、添加模块映射、测试等。同时提供了一些常见问题的解决方法,如下载缺失的msvcr110.dll文件等。通过本文的指导,读者可以轻松地在Windows系统下配置PHP5.6,并解决一些常见的配置问题。 ... [详细]
  • Android Studio Bumblebee | 2021.1.1(大黄蜂版本使用介绍)
    本文介绍了Android Studio Bumblebee | 2021.1.1(大黄蜂版本)的使用方法和相关知识,包括Gradle的介绍、设备管理器的配置、无线调试、新版本问题等内容。同时还提供了更新版本的下载地址和启动页面截图。 ... [详细]
  • eclipse学习(第三章:ssh中的Hibernate)——11.Hibernate的缓存(2级缓存,get和load)
    本文介绍了eclipse学习中的第三章内容,主要讲解了ssh中的Hibernate的缓存,包括2级缓存和get方法、load方法的区别。文章还涉及了项目实践和相关知识点的讲解。 ... [详细]
  • 本文介绍了三种方法来实现在Win7系统中显示桌面的快捷方式,包括使用任务栏快速启动栏、运行命令和自己创建快捷方式的方法。具体操作步骤详细说明,并提供了保存图标的路径,方便以后使用。 ... [详细]
  • 本文介绍了在mac环境下使用nginx配置nodejs代理服务器的步骤,包括安装nginx、创建目录和文件、配置代理的域名和日志记录等。 ... [详细]
  • 本文介绍了如何使用C#制作Java+Mysql+Tomcat环境安装程序,实现一键式安装。通过将JDK、Mysql、Tomcat三者制作成一个安装包,解决了客户在安装软件时的复杂配置和繁琐问题,便于管理软件版本和系统集成。具体步骤包括配置JDK环境变量和安装Mysql服务,其中使用了MySQL Server 5.5社区版和my.ini文件。安装方法为通过命令行将目录转到mysql的bin目录下,执行mysqld --install MySQL5命令。 ... [详细]
  • 本文介绍了在CentOS上安装Python2.7.2的详细步骤,包括下载、解压、编译和安装等操作。同时提供了一些注意事项,以及测试安装是否成功的方法。 ... [详细]
  • python3 nmap函数简介及使用方法
    本文介绍了python3 nmap函数的简介及使用方法,python-nmap是一个使用nmap进行端口扫描的python库,它可以生成nmap扫描报告,并帮助系统管理员进行自动化扫描任务和生成报告。同时,它也支持nmap脚本输出。文章详细介绍了python-nmap的几个py文件的功能和用途,包括__init__.py、nmap.py和test.py。__init__.py主要导入基本信息,nmap.py用于调用nmap的功能进行扫描,test.py用于测试是否可以利用nmap的扫描功能。 ... [详细]
  • 本文介绍了5个基本Linux命令行工具的现代化替代品,包括du、top和ncdu。这些替代品在功能上进行了改进,提高了可用性,并且适用于现代化系统。其中,ncdu是du的替代品,它提供了与du类似的结果,但在一个基于curses的交互式界面中,重点关注占用磁盘空间较多的目录。 ... [详细]
author-avatar
vivi_康冬薇
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有