memo.xight.org

日々のメモ

ffmpeg を利用して ogg からiPhoneの着信音を作成する

Summary

Homebrewのffmpeg を利用して、ogg ファイルを m4a に変換する
IngressのOggファイルをiPhoneの着信音にしたかったので。

ffmpeg を --with-fdk-aac オプションを付けてインストール

$ brew install ffmpeg --with-fdk-aac

ogg から aac に変換する

% ffmpeg -i [input] -c:a libfdk_aac [output]

ffmpeg を起動するperlスクリプト

#!/bin/env perl

use strict;

foreach(@ARGV){
	chomp;
	my $input = $_;
	my $output = $_;
	$output =~ s/\.ogg//;
	$output = $output . ".m4a";
	my $cmd = qq(ffmpeg -i $input -c:a libfdk_aac $output);
	#print qq($cmd\n);
	system($cmd)
}


スクリプト起動

% enc.pl *.ogg

Reference

FFmpeg - Encode - AAC
https://trac.ffmpeg.org/wiki/Encode/AAC

cdrの利用とメンテナンス

Summary

zsh の組み込みコマンド cdr は cd の履歴を保存してくれる。
存在しないディレクトリも履歴に残ったままになってしまうので、自動でメンテナンスをさせたい。

autoload -Uz is-at-least
if is-at-least 4.3.11
then
	# cdr, add-zsh-hook を有効にする
	autoload -Uz chpwd_recent_dirs cdr add-zsh-hook
	add-zsh-hook chpwd chpwd_recent_dirs
	add-zsh-hook chpwd my_compact_chpwd_recent_dirs
	 
	# cdr の設定
	zstyle ':completion:*' recent-dirs-insert both
	zstyle ':chpwd:*' recent-dirs-max 5000
	zstyle ':chpwd:*' recent-dirs-default true
	zstyle ':chpwd:*' recent-dirs-file "$HOME/.cache/shell/chpwd-recent-dirs"
	zstyle ':chpwd:*' recent-dirs-pushd true
	
	function my_compact_chpwd_recent_dirs() {
		emulate -L zsh
		setopt extendedglob
		local -aU reply
		integer history_size
		autoload -Uz chpwd_recent_filehandler
		chpwd_recent_filehandler
		history_size=$#reply
		reply=(${^reply}(N))
		(( $history_size == $#reply )) || chpwd_recent_filehandler $reply
	}
fi

pecoと連携

function peco-cdr () {
	local selected_dir=$(cdr -l | awk '{ print $2 }' | peco)
	if [ -n "$selected_dir" ]; then
		BUFFER="cd ${selected_dir}"
		zle accept-line
	fi
	zle clear-screen
}
zle -N peco-cdr
bindkey '^[xcd' peco-cdr # M-x cdに割り当て

Reference

DevAchive - 2014-09-22 - cdr: 開いたディレクトリの履歴からディレクトリを開く
http://wada811.blogspot.com/2014/09/zsh-cdr.html

@znz blog - 2014-07-25 - zshの機能のみで既に存在しないディレクトリをcdrのリストから削除する
http://blog.n-z.jp/blog/2014-07-25-compact-chpwd-recent-dirs.html