radiko 予約録音&aac, mp3 変換
前のエントリ コンソールで radiko 再生,予約録音 - matoken’s meme -hatena- の続きです.
実際にcrontab に登録して予約録音,録音したflv を音声ファイルのaac/mp3 への変換まで成功したのでメモしておきます.
先ずは,crontab への登録.
59 1 * * 2 /opt/local/bin/rtmpdump --rtmp "rtmp://radiko.smartstream.ne.jp:1935" --playpath "simul-stream" --app "TBS/_defInst_" --live -B 7320 --flv ~/radio/baka-`date +%Y%m%d`.flv
これで,毎週火曜01:59~ 7320秒(02:00~04:00の番組で前後1分マージン取ってます.)録音されるはず.
しかし以下のエラーで失敗していました.
Subject: Cron
/opt/local/bin/rtmpdump --rtmp "rtmp://radiko.smartstream.ne.jp:1935" --playpath "simul-stream" --app "TBS/_defInst_" --live -B 7320 --flv ~/radio/baka-`date +
Content-Type: text/plain; charset=ANSI_X3.4-1968
X-Cron-Env:
X-Cron-Env:
X-Cron-Env:
X-Cron-Env:
Message-Id:
Date: Tue, 23 Mar 2010 01:59:01 +0900
Status: O/bin/sh: Syntax error: EOF in backquote substitution
これはcrontab では行末か% 迄をコマンドとして解釈するそうで% を使いたい場合は\ でエスケープする必要がある様です.
以下man 5 crontab より.
The ``sixth'' field (the rest of the line) specifies the command to be run. The entire command portion of the line, up to a newline or % character, will be executed by /bin/sh or
by the shell specified in the SHELL variable of the crontab file. Percent-signs (%) in the command, unless escaped with backslash (\), will be changed into newline characters,
and all data after the first % will be sent to the command as standard input. There is no way to split a single command line onto multiple lines, like the shell's trailing "\".
ということで,以下の様に書き直します.
59 1 * * 2 /opt/local/bin/rtmpdump --rtmp "rtmp://radiko.smartstream.ne.jp:1935" --playpath "simul-stream" --app "TBS/_defInst_" --live -B 7320 --flv ~/radio/baka-`date +\%Y\%m\%d`.flv
この形式で試すとうまく録音出来ました.
後は,STDOUT/STDERROR がメールに出力され無い様/dev/null にリダイレクトしておきます.これでメールにログが溜まらなくなります.
59 1 * * 2 /opt/local/bin/rtmpdump --rtmp "rtmp://radiko.smartstream.ne.jp:1935" --playpath "simul-stream" --app "TBS/_defInst_" --live -B 7320 --flv ~/radio/baka-`date +\%Y\%m\%d`.flv > /dev/null 2>&1
これでflv 形式のファイルが溜まっていくようになりました.
このままPC で聞くならこれでもいいのですが,mp3 player などに入れて持ち歩きたいので変換します.
前回は
ffmpeg -i infile.flv -acodec copy outfile.mp3
と書きましたが,確認するとradiko のflv はmp3 でなくaac でした.なので,
で,aac に吐き出せます.
mp3 はこんな感じで.
ffmpeg -i infile.flv -acodec libmp3lame outfile.mp3
flv とaac はほぼ同じサイズですが,mp3 は一寸増えたので少し音質落とすとかしてもいいかもしれません.
ここまで出来たら後はiPod なりなんなりの音楽プレイヤーに放り込んで外でも聴けます♪
変換まで自動化してもいいですね.
あ,前もって時計合わせはしておかないと悲しいことになりかねないので注意しましょう.