-
-
Save Bioblaze/4e12d2c1056559420280ea50896787c8 to your computer and use it in GitHub Desktop.
FunkyWayFM: The shell script used to merge the video feed and AzuraCast-powered radio feed into a single YouTube stream.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
VBR="1500k" | |
FPS="30" | |
QUAL="veryfast" | |
YOUTUBE_URL="rtmp://a.rtmp.youtube.com/live2" | |
KEY="" | |
VIDEO_SOURCE="/home/ubuntu/video3.mp4" | |
AUDIO_SOURCE="http://localhost:8000/stream/;stream.mp3" | |
NP_SOURCE="/home/ubuntu/nowplaying.txt" | |
ffmpeg \ | |
-re -f lavfi -i "movie=filename=$VIDEO_SOURCE:loop=0, setpts=N/(FRAME_RATE*TB)" \ | |
-thread_queue_size 512 -i "$AUDIO_SOURCE" \ | |
-map 0:v:0 -map 1:a:0 \ | |
-map_metadata:g 1:g \ | |
-vf drawtext="fontfile=/home/ubuntu/unifont.ttf: fontsize=55: \ | |
box=0: [email protected]: boxborderw=20: \ | |
textfile=$NP_SOURCE: reload=1: [email protected]: x=315: y=960" \ | |
-vcodec libx264 -pix_fmt yuv420p -preset $QUAL -r $FPS -g $(($FPS * 2)) -b:v $VBR \ | |
-acodec libmp3lame -ar 44100 -threads 6 -qscale:v 3 -b:a 320000 -bufsize 512k \ | |
-f flv "$YOUTUBE_URL/$KEY" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Now playing script. | |
$start_time = time(); | |
while(time() < ($start_time + 59)) { | |
$np_raw = file_get_contents('http://localhost:8000/stats'); | |
$np = xml_to_array($np_raw); | |
$np_text = $np['SHOUTCASTSERVER']['SONGTITLE']; | |
$np_text = wordwrap($np_text, 80); | |
if (empty($np_text)) { | |
$np_text = 'Funky Way FM'; | |
} | |
atomic_put_contents('nowplaying.txt', $np_text); | |
sleep(10); | |
} | |
function atomic_put_contents($filename, $data) | |
{ | |
file_put_contents($filename.'.new', $data); | |
rename($filename.'.new', $filename); | |
} | |
function xml_to_array($xml) | |
{ | |
$values = $index = $array = []; | |
$parser = xml_parser_create(); | |
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); | |
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); | |
xml_parse_into_struct($parser, $xml, $values, $index); | |
xml_parser_free($parser); | |
$i = 0; | |
$name = $values[$i]['tag']; | |
$array[$name] = isset($values[$i]['attributes']) ? $values[$i]['attributes'] : ''; | |
$array[$name] = _struct_to_array($values, $i); | |
return $array; | |
} | |
function _struct_to_array($values, &$i) | |
{ | |
$child = []; | |
if (isset($values[$i]['value'])) { | |
array_push($child, $values[$i]['value']); | |
} | |
while ($i++ < count($values)) { | |
switch ($values[$i]['type']) { | |
case 'cdata': | |
array_push($child, $values[$i]['value']); | |
break; | |
case 'complete': | |
$name = $values[$i]['tag']; | |
if (!empty($name)) { | |
$child[$name] = ($values[$i]['value']) ? ($values[$i]['value']) : ''; | |
if (isset($values[$i]['attributes'])) { | |
$child[$name] = $values[$i]['attributes']; | |
} | |
} | |
break; | |
case 'open': | |
$name = $values[$i]['tag']; | |
$size = isset($child[$name]) ? sizeof($child[$name]) : 0; | |
$child[$name][$size] = _struct_to_array($values, $i); | |
break; | |
case 'close': | |
return $child; | |
break; | |
} | |
} | |
return $child; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment