自动压缩相机拍的视频

[lang_zh]
我喜欢DC的视频拍摄功能,但是大部分DC拍出来的视频都特别大(没压缩过)。特别是之前的理光CX200,拍出来的几分钟的视频居然要占几百兆的空间,劳民伤财。

用flash video encoder、Blend带的encoder压缩是一个方法,几百兆的avi瞬间变身10几兆,但是要鼠标点来点去,也劳民伤财。

于是花20分钟写了个powershell小脚本,自动来。
把以下的脚本存在你的照片库根目录下,只要每次有新照片后跑一次就好了。

使用了一个免费的h.264的压缩程序,需要安装powershell(win7自带)。


$x264 = "C:Program FilesH.264 Encoderx264.exe" # get the x264.exe from the below address,and modify this line
if (-not (test-path $x264)) {
	write-host "You don't have x264.exe implace, go get it here: 'http://www.x264.nl/'."
	exit;
}
# this x264.exe doesn't handle every video file (one example is my casio-ex-m2)
# so we remember these files and ignore them
$exceptions = @{};
$EXCEPTION_FILE = ".encode_exceptions";

gc $EXCEPTION_FILE 2>$null |% {
	$exceptions[$_] = 1;
}

dir -r |? { $_ -match ".avi$" } |% {
	$out = $_.FullName -replace ".w+$", ".mp4";
	if((-not (test-path $out) -or -not (dir $out).Length) -and -not $exceptions[$_.FullName]){
		write-host "Found new video file: $($_.FullName)"
		write-host "Encoding... "
		&$x264 --crf 24 -o $out $_.FullName
		if(-not (test-path $out) -or -not (dir $out).Length){
			write-host "There is error converting this file, add it into exception list.";
			$exceptions[$_.FullName] = 1;
			del $out -force;
		}else{
			write-host "Done";
			# del $_.FullName # delete the origin file?
		}
	}
}
"" | out-file $EXCEPTION_FILE -encoding "UTF8" -force
$exceptions.Keys |? {$_} | out-file $EXCEPTION_FILE -encoding "UTF8" -append

做的过程中还发现了Windows Live Photo Gallery的一个sb bug……我的MP4文件建出来就删不掉了,哪怕它是一个0kb的空文件……原因呢,就是一个叫“Windows Live Quicktime Control Host”的进程一看到新的媒体文件就上去咬住不放……详情这里:http://discussions.apple.com/thread.jspa?threadID=2302943&tstart=0

 

[/lang_zh]

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>