View previous topic :: View next topic |
Author |
Message |
Anonymous Guest
|
Posted: Fri Jun 22, 2007 12:49 pm Post subject: Perl script to reencode live OGG to AAC+ |
|
|
Hi, this is my script that i use to stream AAC+ to my Icecast (relay).
Code: |
#!/usr/bin/perl
use HTTP::Daemon;
use HTTP::Status;
my $d = HTTP::Daemon->new( LocalPort => 1212, LocalAddr => 'my.ip', Reuse => 1, Timeout => 180 ) || die "Cannot create socket: $!\n";
while (my $c = $d->accept) {
while (my $r = $c->get_request) {
if ($r->method eq 'GET' and $r->url->path eq "/stream") {
# remember, this is *not* recommened practice :-)
$c->send_basic_header('200 OK
Content-Type: audio/aacp
icy-br:32
icy-genre: Various
icy-name:Radio low rate aac+
icy-notice1:<BR>This stream requires <a href="http://www.winamp.com/">Winamp</a><BR>
icy-notice2:Perl aac plus Server/Linux v0.0.1<BR>
icy-pub:1
icy-url:http://radio.com
Server: PerlStreamer 0.0.1'."\r\n\r\n");
open(FILEHANDLE, "/usr/bin/ogg123 -q -b 256 -d wav -f /home/tipok/newaac/in.wav http://server.ip:port/stream|") or die "cannot open source";
sleep 10; #buffering
open(FILEHANDLE1, "/home/me/newaac/aacplusenc /home/me/newaac/in.wav /home/me/newaac/out.aac 32000 s|") or die "cannot open encoder";
$c->send_file("cat /home/me/newaac/out.aac |");
close(FILEHANDLE);
close(FILEHANDLE1);
} else {
$c->send_error(RC_FORBIDDEN)
}
}
$c->close;
undef($c); |
U need to create 2 pipes "in.wav" and "out.aac"
Code: |
root@radio:~/newaac# mkfifo in.wav
root@radio:~/newaac# mkfifo out.aac
root@radio:~/newaac# chmod 777 in.wav
root@radio:~/newaac# chmod 777 out.aac
|
Don't forget to install 3gpp's aacplusenc to ~/newaac
Afret this u can configure your Icecast Server like this
Code: |
....
<relay>
<server>my.ip</server>
<port>1212</port>
<mount>/stream</mount>
<local-mount>/radio.aacp</local-mount>
<relay-shoutcast-metadata>0</relay-shoutcast-metadata>
<on-demand>0</on-demand>
</relay>
...
|
And connect winamp to /radio.aacp wait about 10 secs... |
|
Back to top |
|
|
jduffas
Joined: 26 Feb 2008 Posts: 3
|
Posted: Thu Dec 18, 2008 9:01 pm Post subject: |
|
|
hi !
I'm very interested in streaming in aac+
but I don't understand how does the scrpit work.
has it to be lauhcned on the server, or as client to send the stream to the server ?
when I try to launch it, I got an error :
Missing right curly or square bracket at aac+ line 36, at end of line
syntax error at aac+ line 36, at EOF
Execution of aac+ aborted due to compilation errors.
any idea ?
jean |
|
Back to top |
|
|
gerrit
Joined: 25 Apr 2009 Posts: 17
|
Posted: Sat Apr 25, 2009 3:33 pm Post subject: Re: Perl script to reencode live OGG to AAC+ |
|
|
Something similar but with php and apache
ogg2aac_stream.php:
Code: |
<?php
$aac_bitrate = "64";
$ogg_stream = "http://localhost:8000/mystream.ogg"
$curl = "/usr/bin/curl -A aacpstream -s --retry 5 $ogg_stream";
$sox = "/usr/bin/sox -V1 -togg - -twav -c 2 -";
$aacplusenc = "/usr/bin/aacplusenc - - $aac_bitrate 2> /dev/null";
header("Content-Type: audio/aacp");
header("icy-notice1:this requires winamp<BR>");
header("icy-notice2:Your Radio AAC+ Server<BR>");
header("icy-name:"."Your Radio Station");
header("icy-description:"."Your Radio Station Description");
header("icy-genre:"."various");
header("icy-pub:"."1");
header("icy-br:"."$aac_bitrate");
header("icy-url:"."http://www.yourwebsite.com");
passthru("$curl|$sox|$aacplusenc");
?>
|
or stream from your soundcard.
Code: |
<?php
$aac_bitrate = "64";
# oss
#$sox = "/usr/bin/sox -q -r 44100 -c2 -2 -t ossdsp -s /dev/dsp0 -t wav -";
# alsa
$sox = "/usr/bin/sox -q -r 44100 -c2 -2 -t alsa plughw:0 -t wav -";
$sox_effect = "";
# compander
#$sox_effect = "compand 0.01,1 -90,-90,-70,-70,-60,-20,0,0 -5";
$aacplusenc = "/usr/bin/aacplusenc - - $aac_bitrate 2> /dev/null";
header("Content-Type: audio/aacp");
header("icy-notice1:this requires winamp<BR>");
header("icy-notice2:YouSeeRadio AAC+ Server<BR>");
header("icy-name:"."Your Radio Station");
header("icy-description:"."Your Radio Station Description");
header("icy-genre:"."various");
header("icy-pub:"."1");
header("icy-br:"."$aac_bitrate");
header("icy-url:"."http://www.yourwebsite.com");
passthru("$sox $sox_effect|$aacplusenc");
?>
|
icecast config
Code: |
---------
<relay>
<server>localhost</server>
<port>80</port>
<mount>/ogg2aac_stream.php</mount>
<local-mount>/mystream.aac</local-mount>
<on-demand>0</on-demand>
<relay-shoutcast-metadata>1</relay-shoutcast-metadata>
</relay>
----------
|
You have to adjust everything to your system and liking
One problem is that the converting keeps active even if you stop listening with your server, you have to kill curl or sox to stop it. |
|
Back to top |
|
|
davidh
Joined: 06 Nov 2014 Posts: 3
|
Posted: Sat Nov 08, 2014 3:53 am Post subject: |
|
|
Hello,
I find this topic really interesting and helpful. I would like to transcode MP3 to AACP using PHP.
This is the code I have:
Code: |
<?php
$aac_bitrate = "64";
$ogg_stream = "http://www.yourwebsite.com:8000/web.mp3";
$curl = "/usr/bin/curl -A aacpstream -s --retry 5 ".$ogg_stream;
$sox = "/usr/local/bin/sox -V1 -tmp3 - -twav -c 2 -";
$aacplusenc = "/usr/local/bin/aacplusenc - - ".$aac_bitrate." 2> /dev/null";
header("Content-Type: audio/aacp");
header("icy-notice1:this requires winamp<BR>");
header("icy-notice2:Your Radio AAC+ Server<BR>");
header("icy-name:"."Your Radio Station");
header("icy-description:"."Your Radio Station Description");
header("icy-genre:"."various");
header("icy-pub:"."1");
header("icy-br:"."$aac_bitrate");
header("icy-url:"."http://www.yourwebsite.com");
passthru("$curl|$sox|$aacplusenc");
?> |
The error message:
/usr/local/bin/sox FAIL sox: `-' error writing output file: Broken pipe
Im not used to sox, I dont know the command line params and the documentation does not seem to help.
Im doing something wrong here:
"/usr/local/bin/sox -V1 -tmp3 - -twav -c 2 -"
Can anyone spot the issue?
Thank you to everyone on the icecast community, you have helped me so much and I think I will go as far as saying "I love you all"!
Thanks,
David |
|
Back to top |
|
|
gerrit
Joined: 25 Apr 2009 Posts: 17
|
Posted: Sat Nov 08, 2014 2:14 pm Post subject: |
|
|
Im doing something wrong here:
"/usr/local/bin/sox -V1 -tmp3 - -twav -c 2 -"
Best try it step by step on the command line
curl -A aacpstream -s --retry 5 http://yourstream.mp3 > stream.mp3
curl -A aacpstream -s --retry 5 http://yourstream.mp3 |sox -V1 -tmp3 - -twav -c 2 - > steam.wav
curl -A aacpstream -s --retry 5 http://yourstream.mp3 |sox -V1 -tmp3 - -twav -c 2 - |aacplusenc - - 64000 s > stream.aac
Depending on your version of aacplusenc the command line can vary
like
Usage: aacplusenc <source.wav> <destination.aac> <bitrate>
or
Usage: aacplusenc <wav_file> <bitstream_file> <bitrate> <(m)ono/(s)tereo>
Gerrit |
|
Back to top |
|
|
|