FFmpeg - radijo stoties live video kanalas (pravers Tvheadend vartotojams)

Įrašo turinys

Daug nesiplėtosiu.

Tiesiog kartais mėgstu pasileisti radijo stotį per TV prie kurio prijungtos kolonėles.

Kaip keista, bet yra ką klausyti Lietuvoje 😆

Ko reikės?

Kalbėsiu tik apie Tvheadend reikalus, bet galima prisitaikyti ir kitom programom.

Reikės FFmpeg.

Web serverio su PHP nes paimsim pavadinimą (kas šiuo metu eteryje) iš radijo stoties ir pateiksim taip:

m1 dance ffmpeg

M1plius 1024x.

Goldfm 1024x.

Opus3 1024x.

Ehr 1024x.

Laluna 1024x.

Rc 1024x.

Zip 1024x.

Dar reikės jog veiktų crontab.

Komandos

Pradžiai imame pavadinimus iš stočių.

Reikės .php failo kuriame toks turinys (skirta M-1 Plius):

<?phpheader("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");header('Content-Type: text/plain; charset=utf-8');$url = "https://www.pliusas.fm/status.json";$getfile = file_get_contents($url);$array = json_decode($getfile, true);echo $array['author'];echo "\n";echo $array['track'];

Atsidarius .php naršyklėje gauname tiesiog kas dabar eteryje:

Image.

Tada reikia jog pastoviai būtų atsiunčiamas .txt failiukas su tai kas groja, tam pasitelksim crontab, kadangi crontab negali kas kelias sekundes startuoti, tai tenka taip daryti:

 * * * * for i in {1..6}; do wget -N https://adresas_iki_php_failo/pliusas.php -O /kelias_iki_txt_failo/pliusas.txt & sleep 5; done 

Aišku galima su bash pasirašyti ir dėti į crontab.

Kuriame naują kanalą Tvheadend'e:

pipe:///usr/bin/ffmpeg -loop 1 -y -i http://adresas_iki_pagrindinio_paveikslelio/pliusas.jpg -i https://radio.m-1.fm/m1plius/aacp64 -vcodec h264 -acodec copy -vframes 14490 -vf "drawtext=:x=20:y=650:fontsize=30:fontcolor=black:textfile=/kelias_iki_txt_failo/pliusas.txt:reload=1" -tune zerolatency -f mpegts pipe:1

Pateiksiu taip pat variantą su vaapi (mažiau kankiname cpu):

pipe:///usr/bin/ffmpeg -vaapi_device /dev/dri/renderD128 -loop 1 -y -i http://adresas_iki_pagrindinio_paveikslelio/pliusas.jpg -i https://lrt-live.lrt.lt/audio/ndvr/hls/lrt_opus/index.m3u8 -vframes 14490 -vf "drawtext=:x=20:y=650:fontsize=30:fontcolor=white:textfile=/kelias_iki_txt_failo/pliusas.txt:reload=1,format=nv12,hwupload" -c:v h264_vaapi -acodec copy -tune zerolatency -f mpegts pipe:1

Ir galop leidžiame kanalą ir gauname paveikslėlio vaizdą ir pavadinimą kas groja.

PHP kuriuos pakūriau

M-1 Plius pateiktas pavyzdyje.

M-1 Dance

<?phpheader("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");header('Content-Type: text/plain; charset=utf-8');$url2 = "https://m-1dance.fm/broadcast.json";$getfile2 = file_get_contents($url2);$array2 = json_decode($getfile2, true);$url = "https://m-1dance.fm/playing.json";$getfile = file_get_contents($url);$array = json_decode($getfile, true);echo 'Laidos pavadinimas: ';echo $array2['broadcasts']['title'];echo "\n";echo $array2['broadcasts']['time'];echo ' ';echo $array2['broadcasts']['time2'];echo "\n";echo "\n";echo $array['artist'];echo "\n";echo $array['title'];echo "\n";

Rock FM

<?phpheader("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");header('Content-Type: text/plain; charset=utf-8');$url = "https://rockfm.lt/onair.txt?v=";$getfile = file_get_contents($url);$array = json_decode($getfile, true);echo $array['now']['artist'];echo "\n";echo $array['now']['title'];

Opus3

<?phpheader("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");header('Content-Type: text/plain; charset=utf-8');$url = "https://www.lrt.lt/api/json/rds?station=opus";$getfile = file_get_contents($url);$array = json_decode($getfile, true);echo $array['rds'][0]['song'];

RC

<?phpheader("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");header('Content-Type: text/plain; charset=utf-8');$url = "https://rc.lt/onair.txt";$getfile = file_get_contents($url);$array = json_decode($getfile, true);echo $array['now']['artist'];echo "\n";echo $array['now']['title'];

Zip FM

<?phpheader("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");header('Content-Type: text/plain; charset=utf-8');$url = "https://zipfm.lt/onair.txt?v=";$getfile = file_get_contents($url);$array = json_decode($getfile, true);echo $array['now']['artist'];echo "\n";echo $array['now']['title'];

European Hit Radio

<?phpheader("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");header('Content-Type: text/plain; charset=utf-8');$url = "https://www.europeanhitradio.lt/load-songs.php?action=load_songs";$getfile = file_get_contents($url);$array = json_decode($getfile, true);echo $array['Current']['Artist'];echo "\n";echo $array['Current']['Title'];echo "\n";echo "\n";echo 'Kita daina:';echo "\n";echo $array['Next1']['Artist'];echo "\n";echo $array['Next1']['Title'];

Laluna

https://www.laluna.lt/xml/onair.txt

Gold FM

https://goldfm.lt/wp-content/themes/radio-gold-fm/radio/php/radio-get.php

Keli pastebėjimai

Bent mano atveju teko mažint paveikslėlių kokybę iki >100KB ir 720p nes kažkodėl mano android grotuvas nesugebėjo rodyti vaizdo nors VLC be problemų leido.

Reiktų dar ant Vaapi paleisti, nes dabar CPU kankina labiau.

Bei reiktų pakoreguoti info atnaujinimo laiką.

Toggle darkmode