Mencoder 文档学习日记2

视频处理技术的专业性很强,有不少的专业知识没有接触过,加上英语水平有限,第7、8章并没有译文,所以第7章的“用 Mencoder 编码”和第8章的FAQ只是浏览了一下,以后有需要的时候再深入学习。
http://www.mplayerhq.hu/DOCS/HTML/en/encoding-guide.html
Chapter 7. Encoding with MEncoder
http://www.mplayerhq.hu/DOCS/HTML/en/faq.html
Chapter 8. Frequently Asked Questions

2011年03月08日 星期二
http://www.mplayerhq.hu/DOCS/HTML/en/encoding-guide.html
Chapter 7. Encoding with MEncoder

http://www.mplayerhq.hu/DOCS/HTML/en/menc-feat-dvd-mpeg4.html
从此到后面视频和音频处理专业方面的东西太多了,又没有人把它翻译出来,好多都看不懂,只能过一遍,懂多少是多少。

7.1. Making a high quality MPEG-4 ("DivX") rip of a DVD movie
把 DVD 转码成 mpeg4 视频可以用来减小文件体积。
有许多不错的图形化前端可以用来转码:http://www.mplayerhq.hu/design7/projects.html#mencoder_frontends

7.1.1. Preparing to encode: Identifying source material and framerate
要先识别是 NTSC 还是 PAL 制式的 DVD;NTSC 更难转码

7.1.1.2. Identifying source material
介绍不同的 pulldown (拆装?)及识别方法

7.1.2. Constant quantizer vs. multipass
介绍3种不同的转码方法:constant bitrate (CBR), constant quantizer, and multipass (ABR, or average bitrate),所采取的方法将影响对每个 macroblocks (In each of these modes, the video codec (such as libavcodec) breaks the video frame into 16x16 pixel macroblocks and then applies a quantizer to each macroblock. )采用的 quantizer 数值(数值越小,质量越高,体积越大),从而影响到最终文件的大小、视频质量、编码时间。

问题:在 CBR 模式下,比特率是怎样影响视频的质量的?
答:,编码器会丢掉图像细节以使其不超过给定比特率。具体是用作用在 macroblocks 上的 quantizer 来实现的。所以在帧率、分辨率一定的情况下,改变视频编码的比特率就会影响视频的大小和质量。例如:虽然都是 176x144 分辨率的 1 帧,高比特率的情况下会使每个像素点的数据更接近原始视频。

7.1.3. Constraints for efficient encoding
问题:内容看得不是很明白。

此节结论是裁剪掉视频的黑边有助于提高转换效率。

2011年03月10日 星期四

7.1.4. Cropping and Scaling

问题:chroma 和 luma 这一部分不懂,关于图像信息存储的方式不懂。

mplayer -vf cropdetect test.avi
[CROP] Crop area: X: 0..639 Y: 34..352 (-vf crop=640:304:0:42).0

mplayer -vf rectangle=640:304:0:42 test.avi

发现使用 cropdetect 视频滤镜的值会把顶部和底部有内容的部分截掉(分别实验10秒和60秒的视频),所以自动探测截取操作并不可靠。

问题:libavcodec 选项中 autoaspect 在 mencoder 转换视频中的用法?

下面是 winmenc 中的一个转换手机视频命令,但是在 Ubuntu 10.10 下默认没有编译入 libfaac (MPlayer was compiled without libfaac. See README or DOCS.),所以暂时无法使用。

mencoder test10s.avi -of lavf -lavfopts format=mp4 -sws 9 -af volnorm -srate 22050 -vf-add scale=176:-2,harddup -ofps 13 -oac faac -faacopts br=32:mpeg=4:object=2:raw -ovc lavc -ffourcc DIVX -lavcopts vcodec=mpeg4:vbitrate=128:threads=2:aglobal=1:vglobal=1 -o test10s.DivX.mp4

2011年03月14日 星期一
7.1.5. Choosing resolution and bitrate
"constant quantizer"用不着指定视频编码率。
视频编码率不与分辨率的平方成正比。如:320x240 file at 200 kbit/sec will not be the same quality as the same movie at 640x480 and 800 kbit/sec. A better estimate seems to be that bitrates scale proportional to the square root of resolution, so that 320x240 and 400 kbit/sec would be comparable to 640x480 at 800 kbit/sec.

7.1.5.1. Computing the resolution
ARc = (Wc x (ARa / PRdvd )) / Hc
ResY = INT(SQRT( 1000*Bitrate/25/ARc/CQ )/16) * 16 and ResX = INT( ResY * ARc / 16) * 16

问题:目标文件的分辨率是一定的,怎么得到合适的视频比特率?
答:因为DVD的分辨率是一定的,所以可以从上面的 ResY 反推,Bitrate = ResY^2*CQ*ARc*25/1000 ,CQ 的选择可以根据视频的类型(如动作多的,平静的)和编码类型从 0.1~0.3 之间选择。低的分辨率需要相对高的 CQ 值。

2011年03月15日 星期二
7.1.6. Filtering

视频滤镜的效果是按顺序执行的;
一些视频滤镜需要在前面载入;
crop是必要的,但是避免scale;
不要调整gamma, contrast, brightness,这是播放器做的;

问题:-vf hqdn3d=2:1:2 减噪视频滤镜的用法?

7.1.7. Interlacing and Telecine
从此至后面看起来太专业了,看不大懂,先过一遍,看懂多少是多少。

7.1.7. Interlacing and Telecine
7.1.8. Encoding interlaced video
7.1.9. Notes on Audio/Video synchronization
当心使用 three-pass 声音编码模式可能出现问题。
7.1.10. Choosing the video codec
Compression efficiency, Hardware compatibility, Best quality per encoding time(?), Personal taste
7.1.11. Audio
处理包含声音的视频时不要使用 -nosound 选项

7.1.12. Muxing
7.1.12.1. Improving muxing and A/V sync reliability
使用 harddup 视频滤镜选项提高音画同步的稳定性

7.1.12.2. Limitations of the AVI container
7.1.12.3. Muxing into the Matroska container
Matroska是一种自由、先进的容器格式。

学习知识的深度要与应用层次相匹配,因为我只要求能够把常见视频转换为质量较好的手机视频,所以先浏览了解一下。到应用时再检查具体的参数使用。

http://www.mplayerhq.hu/DOCS/HTML/en/menc-feat-enc-libavcodec.html
7.3. Encoding with the libavcodec codec family
libavcodec 有更多的编码可供选择。如视频的 h263, mpeg4, 音频的 libfaac, libmp3lame等。此章示例转码DVD 至电脑上播放的 avi 文件的过程,着重要考虑:telecine and interlacing within NTSC,crop, scale

http://www.linuxdiyf.com/bbs/thread-156555-1-1.html
mencoder 输入文件 -oac lavc -ovc lavc -lavcopts vcodec=h263:autoaspect:acodec=libfaac -vf scale=176:144 -o 输出文件.3gp

http://forums.freebsd.org/showthread.php?t=18615

#!/bin/sh

if [ "$#" -lt 2 ]
then
	echo "example:"
	echo "$0 saveto.3gp source.mpg -ofps 25";
	exit 1;
fi

mencoder \
	-noconfig all \
	-oac lavc \
	-ovc lavc \
	-lavcopts vcodec=h263p:vbitrate=200:acodec=libamr_nb:abitrate=10200 \
	-of lavf \
	-ofps 15 \
	-srate 8000 \
	-af lavcresample=8000,channels=1,volnorm \
	-o $1 \
	$2 $3 $4

2011年03月25日 星期五
http://www.mplayerhq.hu/DOCS/HTML/en/menc-feat-xvid.html
7.4. Encoding with the Xvid codec
xvid 的默认设置在质量和速度方面是平衡得比较好的,如果没有特殊的要求,不妨可以直接使用默认设置(即不设置特殊的参数?)。

2011年03月28日 星期一
http://www.mplayerhq.hu/DOCS/HTML/en/menc-feat-x264.html
7.5. Encoding with the x264 codec
在两次编码时,首次可以高速低质,二次可以使用高质量的参数,这比两次使用相同的参数获得更佳的质量速度比。

7.6. Encoding with the Video For Windows codec family
http://www.mplayerhq.hu/DOCS/HTML/en/menc-feat-video-for-windows.html
使用 windows 下的二进制编码器进行一些特定格式的视频文件编码

http://www.mplayerhq.hu/DOCS/HTML/en/menc-feat-quicktime-7.html
7.7. Using MEncoder to create QuickTime-compatible files
quicktime 兼容文件可以利用 Mac os 的硬件加速能力;
quicktime 不支持 H.264 的 avi 容器;
Quicktime 7 不支持 MPEG-4 文件里的 SAR (sample aspect ratio) 信息,默认为1。

2011年03月29日 星期二
http://www.mplayerhq.hu/DOCS/HTML/en/menc-feat-vcd-dvd.html
7.8. Using MEncoder to create VCD/SVCD/DVD-compliant files
libavcodec MP2 没有 toolame 或 twolame 质量好?

http://www.mplayerhq.hu/DOCS/HTML/en/faq.html
Chapter 8. Frequently Asked Questions
mencoder 没有直接的方法只提取视频文件中的音频,不过可以用下面的方法:

mkfifo encode
mplayer -ao pcm -aofile encode dvd://1 &
lame your_opts encode music.mp3
rm encode

注:我发现上面的命令在终端执行 mplayer ... & 会报告无法找到命令 mplayer 之类的信息,但在在脚本中执行没有问题,不知怎么一回事?
另外,上面的命令在新版的 mplayer 中不能执行,好像要 -ao pcm:file= 这样的格式。

下面是新版本的 mplayer 从rmvb文件中截取声音片断的可工作代码:

#!/bin/bash

tempfile=`mktemp`
rm $tempfile
mkfifo $tempfile
/usr/bin/mplayer -ss $2 -endpos $3 -vc null -vo null -ao pcm:fast:waveheader:file=$tempfile $1 &
lame $tempfile $4
rm $tempfile

问题:为什么从命令行终端直接执行如:" /usr/bin/mplayer -vc null -vo null yyzs.rmvb & "会报错:
mplayer: could not connect to socket
mplayer: No such file or directory
Failed to open LIRC support. You will not be able to use your remote control.

为什么第三方播放器不能播放用 MEncoder 1.0pre7 以后版本编码的 MPEG-4 电影?
答:http://www.mplayerhq.hu/DOCS/HTML/en/faq.html#id2858903
FourCC 是一个区别编码软件和打算使用的解码软件的 AVI 标签。