radikoについてあれこれ

プロトコルrtmpなので、どうにかサーバ経由で、
Androidで聞けないかなあということであれこれ試してみる。

flvstreamerでファイルに保存

synapticで検索窓にrtmpと入力して検索すると、flvstreamerなるものがヒットする。
RTMP client と書いてあるのでとりあえずいれてコマンドを叩く。

$ flvstreamer 
FLVStreamer v1.8e
(c) 2009 Andrej Stepanchuk, The Flvstreamer Team, license: GPL
ERROR: You must specify a hostname (--host) or url (-r "rtmp://host[:port]/playpath") containing a hostname

どうやら

rtmp://host[:port]/playpath

というのがわかればきけるのか?
で、flvstreamerを使ったradiko保存方法をみると、以下でflvファイルに保存が簡単にでける。

flvstreamer -r "rtmp://radiko.smartstream.ne.jp:1935" -a "TBS/_defInst_" -y "simul-stream" -v -o TBS.flv

cronを使った定時録音の方法もありました。
flvに保存する一番簡単な方法。

rtmpdumpでコマンドラインでライブ視聴

シンプルにいける。

$ ./rtmpdump --rtmp "rtmp://radiko.smartstream.ne.jp:1935" --playpath "simul-stream" --app "TBS/_defInst_" --live | mplayer -

さらにシンプルに

$ ./rtmpdump -vr rtmp://radiko.smartstream.ne.jp/TBS/_defInst_/simul-stream | mplayer -

ローカルPCでrtmpgwで視聴

radikoをフラッシュ無しで再生を参考に,

rtmpgw起動、

$ ./rtmpgw --rtmp "rtmp://radiko.smartstream.ne.jp:1935" --playpath "simul-stream" --swfUrl "http://radiko.jp/player/player_0.0.9.swf" --pageUrl "http://radiko.jp/player/player.html#QRR" --app "QRR/_defInst_" --flashVer "LNX 10,0,45,2" --live --device 127.0.0.1 --sport 8088
HTTP-RTMP Stream Gateway v2.2
(c) 2010 Andrej Stepanchuk, Howard Chu; license: GPL

Streaming on http://127.0.0.1:8088
Connecting ... port: 1935, app: QRR/_defInst_
ERROR: rtmp server sent error
Metadata:
  audiodatarate         48.00
611.949 KB / 100.35 sec

mplayerで聴く。

$ mplayer http://127.0.0.1:8088
MPlayer SVN-r29237-4.4.1 (C) 2000-2009 MPlayer Team
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.

Playing http://127.0.0.1:8088.
Resolving 127.0.0.1 for AF_INET6...
Couldn't resolve name for AF_INET6: 127.0.0.1
Connecting to server 127.0.0.1[127.0.0.1]: 8088...
Cache size set to 320 KBytes
Cache fill: 17.50% (57344 bytes)   
libavformat file format detected.
[lavf] Video stream found, -vid 0
[lavf] Audio stream found, -aid 1
VIDEO:  []  0x0  0bpp  1000.000 fps    0.0 kbps ( 0.0 kbyte/s)
open: No such file or directory
[MGA] Couldn't open: /dev/mga_vid
open: No such file or directory
[MGA] Couldn't open: /dev/mga_vid
[VO_TDFXFB] Can't open /dev/fb0: Permission denied.
[VO_3DFX] Unable to open /dev/3dfx.
==========================================================================
Opening video decoder: [raw] RAW Uncompressed Video
RAW: depth 0 not supported
VDecoder init failed :(
Opening video decoder: [raw] RAW Uncompressed Video
RAW: depth 0 not supported
VDecoder init failed :(
Opening video decoder: [raw] RAW Uncompressed Video
RAW: depth 0 not supported
VDecoder init failed :(
Opening video decoder: [raw] RAW Uncompressed Video
RAW: depth 0 not supported
VDecoder init failed :(
Opening video decoder: [raw] RAW Uncompressed Video
RAW: depth 0 not supported
VDecoder init failed :(
Opening video decoder: [raw] RAW Uncompressed Video
RAW: depth 0 not supported
VDecoder init failed :(
Opening video decoder: [raw] RAW Uncompressed Video
RAW: depth 0 not supported
VDecoder init failed :(
Opening video decoder: [raw] RAW Uncompressed Video
RAW: depth 0 not supported
VDecoder init failed :(
Opening video decoder: [raw] RAW Uncompressed Video
RAW: depth 0 not supported
VDecoder init failed :(
Opening video decoder: [raw] RAW Uncompressed Video
RAW: depth 0 not supported
VDecoder init failed :(
Opening video decoder: [raw] RAW Uncompressed Video
RAW: depth 0 not supported
VDecoder init failed :(
Opening video decoder: [raw] RAW Uncompressed Video
RAW: depth 0 not supported
VDecoder init failed :(
Opening video decoder: [raw] RAW Uncompressed Video
RAW: depth 0 not supported
VDecoder init failed :(
Opening video decoder: [raw] RAW Uncompressed Video
RAW: depth 0 not supported
VDecoder init failed :(
Opening video decoder: [raw] RAW Uncompressed Video
VDecoder init failed :(
Opening video decoder: [raw] RAW Uncompressed Video
VDecoder init failed :(
Opening video decoder: [raw] RAW Uncompressed Video
VDecoder init failed :(
Opening video decoder: [raw] RAW Uncompressed Video
VDecoder init failed :(
Opening video decoder: [raw] RAW Uncompressed Video
VDecoder init failed :(
Opening video decoder: [raw] RAW Uncompressed Video
VDecoder init failed :(
Opening video decoder: [hmblck] Hauppauge Macroblock/NV12/NV21 Decoder
VDecoder init failed :(
Opening video decoder: [hmblck] Hauppauge Macroblock/NV12/NV21 Decoder
VDecoder init failed :(
Opening video decoder: [hmblck] Hauppauge Macroblock/NV12/NV21 Decoder
VDecoder init failed :(
Opening video decoder: [raw] RAW Uncompressed Video
VDecoder init failed :(
Opening video decoder: [raw] RAW Uncompressed Video
VDecoder init failed :(
Opening video decoder: [raw] RAW Uncompressed Video
RAW: depth 0 not supported
VDecoder init failed :(
Cannot find codec matching selected -vo and video format 0x0.
Read DOCS/HTML/en/codecs.html!
==========================================================================
==========================================================================
Opening audio decoder: [faad] AAC (MPEG2/4 Advanced Audio Coding)
FAAD: compressed input bitrate missing, assuming 128kbit/s!
AUDIO: 48000 Hz, 2 ch, s16le, 128.0 kbit/8.33% (ratio: 16000->192000)
Selected audio codec: [faad] afm: faad (FAAD AAC (MPEG-2/MPEG-4 Audio))
==========================================================================
[pulse] working around probably broken pause functionality,
        see http://www.pulseaudio.org/ticket/440
AO: [pulse] 48000Hz 2ch s16le (2 bytes per sample)
Video: no video
Starting playback...
A:  95.1 (01:35.0) of 0.0 (unknown) 13.3% 1% 
MPlayer interrupted by signal 2 in module: play_audio
MPlayer interrupted by signal 2 in module: enable_cache
A:  95.1 (01:35.1) of 0.0 (unknown) 13.3% 1%

と、なんかいろいろ吐くけど、まあ聴ける。
GNOME系のプレーヤでもアクセス先を合わせれば聴ける。

外部サーバ上でrtmpgwを動かして、ネット経由でアクセス

残念!!

ERROR: rtmp server requested close
DEBUG: RTMP_ClientPacket, received: invoke 125 bytes
DEBUG: (object begin)
DEBUG: Property: <Name:                  no-name., STRING:	_error>
DEBUG: Property: <Name:                  no-name., NUMBER:	1.00>
DEBUG: Property: NULL
DEBUG: Property: <Name:                  no-name., OBJECT>
DEBUG: (object begin)
DEBUG: Property: <Name:                     level, STRING:	error>
DEBUG: Property: <Name:                      code, STRING:	NetConnection.Connect.Rejected>
DEBUG: Property: <Name:               description, STRING:	Connection failed.>
DEBUG: Property: NULL
DEBUG: (object end)


どうやらサーバのIPが視聴可能でない。

視聴可能IPを持つサーバでrtmpgwにアクセスして視聴

AndroidポッドキャストアプリListenでアクセス。
サーバはなんらかのレスポンスを受信してるっぽいが、
画面がプログレスのぐるぐるのまま。

Connecting ... port: 1935, app: QRR/_defInst_
ERROR: rtmp server sent error
Metadata:
  audiodatarate         48.00
ERROR: processTCPrequest, sending failed, error: 32
Closing connection... done!

中継ワンライナーがありました。

http://gist.github.com/332851

$ rtmpdump -vr rtmp://radiko.smartstream.ne.jp/TBS/_defInst_/simul-stream -o - | ffmpeg -y -i - -vn -acodec libmp3lame -f mpegts - | mediastreamsegmenter --audio-only -b http://hoge/radiko -f ~/Sites/radiko -t 5 -s 5 -D

flvからmp3に変換

ffmpeg -i infile.flv -acodec copy outfile.mp3