---
title: "ffmpeg 视频转码例子集合"
author: "不念书的小子"
date: "2014-01-28T14:29:30Z"
tags: []
categories: ["开源软件"]
slug: "ffmpeg"
draft: false
lastmod: "2014-01-28T14:30:14Z"
id: 2010401
url: "https://tompig.iteye.com/blog/2010401"
---

http://rodrigopolo.com/ffmpeg/cheats.php

 

vfilter 加水印

ffmpeg -i d:/l.mpg -vf "movie=720576.png \[watermark]; \[in]\[watermark] overlay=10:10 \[out]"  -b 3500k  -vcodec mpeg2video  -acodec copy   d:/output2.mpg

 

-muxrate 复用码率，设置之后整体码率模式才是CBR

 

-c:v mpeg2video MPEG2视频编码

 

-flags ildct+ilme 隔行扫描

 

 

-top 隔行扫描前场/后场优先模式 ，1是前场（顶场），0是后场（底场）

 

-streamid 设置视频、音频PID，0视频，1音频

 

-f mpegts 输出封装格式mpeg2ts

 

-c:a mp2 MPEG音频编码

 

#####High quality 2 Pass

ffmpeg -y -i INPUT -r 30000/1001 -b 2M -bt 4M -vcodec libx264 -pass 1 -vpre fastfirstpass -an output.mp4

 

ffmpeg -y -i INPUT -r 30000/1001 -b 2M -bt 4M -vcodec libx264 -pass 2 -vpre hq -acodec libfaac -ac 2 -ar 48000 -ab 192k output.mp4

 

#####iPod-iPhone 320 width

ffmpeg -i INPUT -s 320x240 -r 30000/1001 -b 200k -bt 240k -vcodec libx264 -vpre ipod320 -acodec libfaac -ac 2 -ar 48000 -ab 192k output.mp4

 

 

#####iPod-iPhone 640 width

ffmpeg -i INPUT -s 640x480 -r 30000/1001 -b 200k -bt 240k -vcodec libx264 -vpre ipod640 -acodec libfaac -ac 2 -ar 48000 -ab 192k output.mp4

 

 

#####Hight quality, 2 pass without presset

ffmpeg -y -i input -r 24000/1001 -b 6144k -bt 8192k -vcodec libx264 -pass 1 -flags +loop -me\_method dia -g 250 -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -bf 16 -b\_strategy 1 -i\_qfactor 0.71 -cmp +chroma -subq 1 -me\_range 16 -coder 1 -sc\_threshold 40 -flags2 -bpyramid-wpred-mixed\_refs-dct8x8+fastpskip -keyint\_min 25 -refs 1 -trellis 0 -directpred 1 -partitions -parti8x8-parti4x4-partp8x8-partp4x4-partb8x8-an output.mp4

ffmpeg -y -i input -r 24000/1001 -b 6144k -bt 8192k -vcodec libx264 -pass 2 -flags +loop -me\_method umh -g 250 -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -bf 16 -b\_strategy 1 -i\_qfactor 0.71 -cmp +chroma -subq 8 -me\_range 16 -coder 1 -sc\_threshold 40 -flags2 +bpyramid+wpred+mixed\_refs+dct8x8+fastpskip -keyint\_min 25 -refs 4 -trellis 1 -directpred 3 -partitions +parti8x8+parti4x4+partp8x8+partb8x8-acodec libfaac -ac 2 -ar 44100 -ab 128k output.mp4

 

 

#####iPod-iPhone 320 width, without presset

ffmpeg -i INPUT -s 320x240 -r 30000/1001 -b 200k -bt 240k -vcodec libx264 -coder 0 -bf 0 -flags2 -wpred-dct8x8 -level 13 -maxrate 768k -bufsize 3M-acodec libfaac -ac 2 -ar 48000 -ab 192k output.mp4

 

 

#####iPod-iPhone 640 width, without presset

ffmpeg -i INPUT -s 320x240 -r 30000/1001 -b 200k -bt 240k -vcodec libx264 coder 0 -bf 0 -refs 1 -flags2 -wpred-dct8x8 -level 30 -maxrate 10M -bufsize 10M-acodec libfaac -ac 2 -ar 48000 -ab 192k output.mp4

 

 

#####iPod-iPhone, 2 pass custom

ffmpeg -y -i input -r 30000/1001 -s 480x272 -aspect 480:272 -vcodec libx264 -b 512k -bt 1024k -maxrate 4M -flags +loop -cmp +chroma -me\_range 16 -g 300 -keyint\_min 25 -sc\_threshold 40 -i\_qfactor 0.71 -rc\_eq "blurCplx^(1-qComp)" -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -coder 0 -refs 1 -bufsize 4M -level 21 -partitions parti4x4+partp8x8+partb8x8 -subq 5 -f mp4 -pass 1 -an -title "Title" output.mp4

ffmpeg -y -i input -r 30000/1001 -s 480x272 -aspect 480:272 -vcodec libx264 -b 512k -bt 1024k -maxrate 4M -flags +loop -cmp +chroma -me\_range 16 -g 300 keyint\_min 25 -sc\_threshold 40 -i\_qfactor 0.71 -rc\_eq "blurCplx^(1-qComp)" -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -coder 0 -refs 1 -bufsize 4M -level 21 -partitions parti4x4+partp8x8+partb8x8 -subq 5 -f mp4 -pass 2 -acodec libfaac -ac 2 -ar 44100 -ab 128k -title "Title" output.mp4 

 

#####To DV

ffmpeg -i input -target ntsc-dv -aspect 4:3 -y output.dv

#####From DV To Microsoft AVI DV

ffmpeg -i input.dv -vcodec copy -vtag dvsd -acodec pcm\_s16le -f avi -aspect 4:3 -y output.avi

#####AAC Stereo HQ 

-acodec libfaac -ac 2 -ar 48000 -ab 192k

 

#####AAC Stereo SQ 

-acodec libfaac -ac 2 -ar 44100 -ab 128k

#####AAC 5.1 HQ 

-acodec libfaac -ac 6 -ar 48000 -ab 448k

#####AAC 5.1 LQ 

-acodec libfaac -ac 6 -ar 44100 -ab 224k

 

#####AC3 5.1 Channel Mapping Fix

eac3to from\_true\_hd.ac3 fixed\_mapping.ac3 -blu-ray -448

#####AAC to AC3 

1.From AAC to WAV with faad2: 

faad2 -o temp\_audio.wav input.aac

2.From WAV to AC3 with eac3to 

eac3to temp\_audio.wav output.ac3 -448

#####AC3 to AAC 

1.From AC3 to a remapped AC3 with eac3to: 

eac3to input.ac3 temp\_remaped.ac3 -448 -resampleTo48000 -2,1,0,3,4,52.

From remapped AC3 to AAC with FFmpeg 

ffmpeg -y -i temp\_remaped.ac3 -vn -acodec libfaac -ac 6 -ar 48000 -ab 384k output.m4a

\#####

 

 

FFmpeg Information Sources

IRC

Server: irc.freenode.net

Channel: #ffmpeg

 

Download

The bests binaries on the web, Easy installation without compiling, just runing an install file:

FFmpeg for Windows

FFmpeg for Macintosh OS X (Intel)

FFmpeg for Linux

 

You can also use this extremely easy guide to install FFmpeg on your Windows, GNU Linux or Macintosh machine:

http://rodrigopolo.com/about/wp-stream-video/ffmpeg-binary-installers-for-win-mac-and-linux 

 

Win32 Binary Builds

http://ffmpeg.arrozcru.com/autobuilds

http://sourceforge.net/project/showfiles.php?group\_id=205275&package\_id=248632

 

FFmpeg x264 encoding guide by Robert Swain

http://rob.opendot.cl/index.php/useful-stuff/ffmpeg-x264-encoding-guide

 

 

H.264 Profiles and Levels

8x8dct high 

cabac+bframes main 

-level # 

 

Special Thanks To: 

•Jason Garrett-Glaser, a.k.a., Dark Shikari for all the knowledge and information shared

Diary Of An x264 Developer

http://en.wikipedia.org/wiki/User:Dark\_Shikari

•Creators of VS4P (Video Scripts for Portables) for sharing one of the most functional building guide for FFmpeg on Ubuntu

http://code.google.com/p/vs4p/wiki/BackEndApps

•Gianluigi Tiesi a.k.a, Sherpya for making one of the best Win32 FFmpeg binaries

http://oss.netfarm.it/mplayer-win32.php

•Fabrice Bellard a.k.a, Gerard Lantau for giving the best video/audio encoder to the world of open source

http://www.ffmpeg.org 

http://en.wikipedia.org/wiki/Fabrice\_Bellard

•Howard Pritchett for his FFmpeg Guide (maping channels)

http://howto-pages.org/ffmpeg 

•Olivier Amato for a comprehensive guide about framerates and FFmpeg

http://www.itbroadcastanddigitalcinema.com/ffmpeg\_howto.html#Encoding\_H.264\_Long\_GOP

•The comunity and people who write Wikipedia for all the information you share for free

http://en.wikipedia.org/wiki/H.264 

http://en.wikipedia.org/wiki/Advanced\_Audio\_Coding

http://en.wikipedia.org/wiki/AVCHD

 

 

 

 ————————————————————————————————————————

 

 

ffmpeg转3gp   移动wap平台可以用

 

 

 

-y      如果存在重复文件名则覆盖

 

-i       输入文件名

 

-bitexact    使用位精确算法

 

-ac    声道数1或2,amr编码只支持单声道

 

-acodec    音频编码器 aac/amr\_nb/amr\_wb  转3gp用amr\_nb多一些,windows下要用libfaac/libamr\_nb/amr\_wb

 

-ar    声音采样率单位Hz

 

-ab   音频比特率单位Kbps

 

-s      分辨率176x144

 

-vcodec     h263/mpeg4 使用h.263编码,h.263支持QCIF和CIF外，还支持SQCIF、4CIF和16CIF这5中分辨率，不支持320\*240

 

-b      码率

 

-r       帧率

 

-f       强制使用格式

 

-qscale  6或4         使用动态码率来设置

 

 

 

具体命令如下：

 

 

 

ffmpeg -y -i test.wmv  -ac 1 -acodec amr\_nb -ar 8000 -ab 6.7k -s 176x144 -vcodec h263 -b 50k -r 6 -f 3gp output.3gp

 

 

 

ffmpeg -y -i test.wmv  -ac 1 -acodec libamr\_nb -ar 8000 -ab 6.7k -s 128x96 -vcodec h263 -b 50k -r 6 -f 3gp output.3gp

 

 

 

高质量-qscale  6 

 

 ffmpeg -y -i test.wmv  -ac 1 -acodec libamr\_nb -ar 8000 -ab 6.7k -s 176x144 -vcodec h263 -b 50k -r 6 –qscale 6 -f 3gp output.3gp