当初、
本連載ではNHKのインターネットラジオ
これを受け、
「らじる☆らじる」
それから2年経った今年の9月、
RTMPからHLSへの移行
前節でも触れたように、
RTMPは独自プロトコルを利用しているため、
FlashPlayerには、
加えて、
そのような環境変化を踏まえ、
一方、
HLSの場合、
実のところ、
HLSについて
さて、
「複数の動画ファイルを指定した順に連続して再生する」
M3U形式を採用することで、
少し先回りになりますが、
$ wget https://nhkradioakfm-i.akamaihd.net/hls/live/512290/1-fm/1-fm-01.m3u8 --2017-09-27 08:21:09-- https://nhkradioakfm-i.akamaihd.net/hls/live/512290/1-fm/1-fm-01.m3u8 Resolving nhkradioakfm-i.akamaihd.net... 61.213.189.240, 61.213.189.250 Connecting to nhkradioakfm-i.akamaihd.net|61.213.189.240|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 965 [application/x-mpegURL] Saving to: ‘1-fm-01.m3u8’ 1-fm-01.m3u8 100%[================================>] 965 --.-KB/s in 0s 2017-09-27 08:21:09 (138 MB/s) - ‘1-fm-01.m3u8’ saved [965/965]
このファイルの中身は以下の通り、
$ cat 1-fm-01.m3u8 #EXTM3U #EXT-X-VERSION:2 #EXT-X-TARGETDURATION:11 #EXT-X-MEDIA-SEQUENCE:222425 #EXTINF:10, 1-fm-20170831T143716-01-111/425.ts #EXTINF:10, 1-fm-20170831T143716-01-111/426.ts #EXTINF:10, 1-fm-20170831T143716-01-111/427.ts #EXTINF:10, 1-fm-20170831T143716-01-111/428.ts ....
ここで指定されている "425.
$ wget https://nhkradioakfm-i.akamaihd.net/hls/live/512290/1-fm/1-fm-20170831T143716-01-111/439.ts --2017-09-27 08:26:42-- https://nhkradioakfm-i.akamaihd.net/hls/live/512290/1-fm/1-fm-20170831T143716-01-111/439.ts Resolving nhkradioakfm-i.akamaihd.net... 61.213.189.240, 61.213.189.250 Connecting to nhkradioakfm-i.akamaihd.net|61.213.189.240|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 87232 (85K) [video/MP2T] Saving to: ‘439.ts’ 439.ts 100%[================================>] 85.19K --.-KB/s in 0.007s 2017-09-27 08:26:42 (12.4 MB/s) - ‘439.ts’ saved [87232/87232]
このファイルは、
$ ls -lh 439.ts -rw-r--r--+ 1 kojima users 86K 9月 27日 08:26 439.ts $ file 439.ts 439.ts: MPEG transport stream data
このファイルのみをsmplayerで再生することも可能で、

一方、
$ smplayer https://nhkradioakfm-i.akamaihd.net/hls/live/512290/1-fm/1-fm-01.m3u8 QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-kojima' QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-kojima' Debug: global_init ... Debug: BaseGui::open: 'https://nhkradioakfm-i.akamaihd.net/hls/live/512290/1-fm/1-fm-01.m3u8' Debug: Core::open: 'https://nhkradioakfm-i.akamaihd.net/hls/live/512290/1-fm/1-fm-01.m3u8' ... Debug: Core::startMplayer: checking if stream is a playlist Debug: Core::startMplayer: url path: '/hls/live/512290/1-fm/1-fm-01.m3u8' Debug: Core::startMplayer: url_is_playlist: 1 Debug: Core::startMplayer: URL extension: "m3u8" Debug: InfoReader::setPlayerBin: mplayerbin: "/usr/bin/mpv" ...

radiru_rec.pyスクリプトの修正
さて、
まず、
まずはffmpegの入力元
$ ffmpeg -i https://nhkradioakfm-i.akamaihd.net/hls/live/512290/1-fm/1-fm-01.m3u8 -t 30 -movflags faststart -c copy -bsf:a aac_adtstoasc test.m4a ffmpeg version 3.3.2 Copyright (c) 2000-2017 the FFmpeg developers built with gcc 7.1.0 (GCC) configuration: --prefix=/usr --enable-gpl --enable-version3 --enable-nonfree --disable-static --enable-shared --disable-debug --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-openssl ... [hls,applehttp @ 0x670340] Opening 'https://nhkradioakfm-i.akamaihd.net/hls/live/512290/1-fm/1-fm-20170831T143716-01-111/1946.ts' for reading Input #0, hls,applehttp, from 'https://nhkradioakfm-i.akamaihd.net/hls/live/512290/1-fm/1-fm-01.m3u8': Duration: N/A, start: 13154.032222, bitrate: N/A Program 0 Metadata: variant_bitrate : 0 Stream #0:0: Audio: aac (HE-AAC) ([15][0][0][0] / 0x000F), 48000 Hz, stereo, fltp ... Press [q] to stop, [?] for help [hls,applehttp @ 0x670340] Opening 'https://nhkradioakfm-i.akamaihd.net/hls/live/512290/1-fm/1-fm-20170831T143716-01-111/1947.ts' for reading [hls,applehttp @ 0x670340] Opening 'https://nhkradioakfm-i.akamaihd.net/hls/live/512290/1-fm/1-fm-20170831T143716-01-111/1948.ts' for reading [ipod @ 0x6c47e0] Starting second pass: moving the moov atom to the beginning of the file size= 180kB time=00:00:29.99 bitrate= 49.0kbits/s speed= 192x video:0kB audio:176kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.971487%
上記コマンドラインのオプションとして指定している -t 30 は30秒間録音する指示、
$ ls -lh test.m4a -rw-r--r--+ 1 kojima users 180K 9月 27日 12:38 test.m4a $ file test.m4a test.m4a: ISO Media, Apple iTunes ALAC/AAC-LC (.M4A) Audio
ffmpegでデータを正しく受信できたので、
<radiru_config><!-- お知らせ -->
<info>/radio/include/oshirase.txt</info>
<!-- 各地域のストリームURL -->
<stream_url>
<data>
<areajp>札幌</areajp>
<area>sapporo</area>
<apikey>700</apikey>
<areakey>010</areakey>
<r1hls>
https://nhkradioikr1-i.akamaihd.net/hls/live/512098/1-r1/1-r1-01.m3u8
</r1hls>
<r2hls>
https://nhkradioakr2-i.akamaihd.net/hls/live/511929/1-r2/1-r2-01.m3u8
</r2hls>
<fmhls>
https://nhkradioikfm-i.akamaihd.net/hls/live/512100/1-fm/1-fm-01.m3u8
</fmhls>
</data>
<data>
<areajp>仙台</areajp>
...
<r1hls>
https://nhkradiohkr1-i.akamaihd.net/hls/live/512075/1-r1/1-r1-01.m3u8
</r1hls>
<r2hls>
https://nhkradioakr2-i.akamaihd.net/hls/live/511929/1-r2/1-r2-01.m3u8
</r2hls>
...
これらの情報が揃えば、
206 if channel == 'r1':
207 url = 'https://nhkradioakr1-i.akamaihd.net/hls/live/511633/1-r1/1-r1-01.m3u8'
208 elif channel == 'r2':
209 url = 'https://nhkradioakr2-i.akamaihd.net/hls/live/511929/1-r2/1-r2-01.m3u8'
210 elif channel == 'fm':
211 url = 'https://nhkradioakfm-i.akamaihd.net/hls/live/512290/1-fm/1-fm-01.m3u8'
212 elif channel == 'r1_kansai':
213 url = 'https://nhkradiobkr1-i.akamaihd.net/hls/live/512291/1-r1/1-r1-01.m3u8'
214 else:
215 print("channel set error:{0}".format(channel))
216 usage()
217 sys.exit(1)
実際に音声データをダウンロードする部分は、
229 lines.append('#!/bin/sh')
230 lines.append('m4afile={0}/{1}.m4a'.format(musicdir, title))
231 lines.append('( ffmpeg -i {0} -t {1} -movflags faststart -c copy -bsf:a aac_adtstoasc $m4afile ) &'.format(url, sduration))
232 lines.append('sleep 1m')
rtmpdumpを使っていた旧バージョンでは、
こうして修正したHLSに対応したradiru_
RTMPからHLSに変ってまず気づくことは、
また、