Page 1 of 1
Transcoding to different codecs depending on bitrate?

Posted:
Sun Jan 08, 2012 8:30 am
by kingmos
Hey there,
first of all: I finally managed to transcode to HE-AAC using a self compiled ffmpeg and iSub on my iPhone. Since it streams in ADTS it doesn't work with the webinterface though.
compiled ffmpeg with
- Code: Select all
./configure --enable-gpl --enable-pthreads --enable-libfaac --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libaacplus --enable-nonfree
transcoding command for iSub is
- Code: Select all
ffmpeg -i %s -f adts -vn -acodec libaacplus -ar 44100 -ab 64k -ac 2 -
If someone only wants to use the webinterface (doesn't work with iSub though)
- Code: Select all
ffmpeg -i %s -f flv -vn -acodec libaacplus -ar 44100 -ab 64k -ac 2 -
What I'd like to do now is transcoding to mp3 or he-aac depending on the bitrate, the player is requesting. If it is greater then 64kbit use mp3, else use he-aac. Afaik this should work with a command like
- Code: Select all
if [ %bk -le 64 ] then ffmpeg -i %s -f adts -vn -acodec libaacplus -ar 44100 -ab 64k -ac 2 - else ffmpeg -i %s -ab %bk -v 0 -f mp3 - fi
Subsonic doesn't do anything at all with that unfortunately. Any Ideas?
Moritz
Re: Transcoding to different codecs depending on bitrate?

Posted:
Mon Jan 09, 2012 3:28 pm
by wraithdu
On Windows use a BAT file, on Linux use a shell script. Make your transcoding command a call to the script (which must be set to execute by default versus opening up for edit, ie when you double click it) with appropriate parameters. Just make sure you don't echo anything extraneous in your script since all stdout data streams through subsonic. You can use whatever branching logic you require this way.
Re: Transcoding to different codecs depending on bitrate?

Posted:
Tue Jan 10, 2012 6:26 pm
by kingmos
I'm on linux and I already tried that. The problem is that I need to parse commandline options and my script gets confused as subsonic calls the filename without any quotes.. If there is a space in the filename my script thinks there are two different commandline options. Any ideas on that?
My script ($S is file):
- Code: Select all
#!/bin/sh
S=$2
BITRATE=$1
if [ $BITRATE -le 96 ]
then /var/subsonic/transcode/ffmpeg_new -i $S -f adts -vn -acodec libaacplus -ar 44100 -ab $BITRATE -ac 2 -
else lame -S -f --resample 44.1 --abr $BITRATE $S -
fi
Re: Transcoding to different codecs depending on bitrate?

Posted:
Tue Jan 10, 2012 6:31 pm
by bushman4
Put quotes around the proper variables in the transcode settings and those quotes should be passed on...
HTH,
Glenn
Re: Transcoding to different codecs depending on bitrate?

Posted:
Wed Jan 11, 2012 12:19 am
by wraithdu
As mentioned above. Odd though, Subsonic WAR / Tomcat version calls my BAT files with quotes where appropriate.
Re: Transcoding to different codecs depending on bitrate?

Posted:
Wed Jan 11, 2012 6:54 am
by kingmos
No Luck.
- Code: Select all
wrapper.sh "%b" "%s"
No quotes are passed.
- Code: Select all
wrapper.sh ""%b"" ""%s""
The even stranger result:
- Code: Select all
Starting transcoder: [/var/subsonic/transcode/wrapper.sh] [] [128""]
Re: Transcoding to different codecs depending on bitrate?

Posted:
Wed Jan 11, 2012 1:33 pm
by kingmos
Ok I got it. If anyone is interested I call the following script with wrapper.sh %b %s
- Code: Select all
#!/bin/sh
NAME=wrapper.sh
IFS=$''
S=$2
BITRATE=$1k
BITRATEAAC=`expr $1 / 2`k
if [ $1 -eq 256 ]
#pipe
then cat $2
elif [ $1 -le 128 ]
#aac
then /var/subsonic/transcode/ffmpeg_new -i $2 -f adts -vn -acodec libaacplus -ar 44100 -ab $BITRATEAAC -ac 2 -
#mp3
else /var/subsonic/transcode/ffmpeg_new -i $2 -ab $BITRATE -v 0 -f mp3 -
fi
Re: Transcoding to different codecs depending on bitrate?

Posted:
Wed Jan 11, 2012 4:01 pm
by wraithdu
That still seems strange to me. The value of IFS should not have anything to do with parameter passing, rather line splitting in loops and from the read command.
Is your error from the shell running the script, or from ffmpeg / lame? Once you assign S=$2, $S is not quoted by default. You should be passing that to ffmpeg as "$S" with quotes. In your last example you're not even using $S, but $2, which may actually be quoted until it is assigned to something else. I'm a little fuzzy on how the shell handles quotes to be honest. But either way, I don't think modifying IFS should matter.
Re: Transcoding to different codecs depending on bitrate?

Posted:
Wed Jan 11, 2012 4:49 pm
by wraithdu
I just did a quick test in cygwin. The shell keeps track of parameters with spaces just fine internally. But when you call an external program there are no quotes around that data. So if you expect the parameter to have spaces, you need to add the quotes.
It seems an alternate solution is to change IFS as you did, but IMO that's not the better solution.
Re: Transcoding to different codecs depending on bitrate?

Posted:
Fri Mar 30, 2012 8:48 pm
by dhl
kingmos wrote:first of all: I finally managed to transcode to HE-AAC using a self compiled ffmpeg and iSub on my iPhone. Since it streams in ADTS it doesn't work with the webinterface though.
@kingmos - would you be willing to share your ffmpeg build? I've been trying to track down an HE-AAC encoder that writes to stdout with zero luck. Want to do exactly what you're doing -- transcode to HE-AAC on a Linux box for playback on iSub. I realize this doesn't solve your immediate problem, but it sounds like you've figured out a big part of the HE-AAC puzzle that folks have been looking for for years. Any help much appreciated! Thanks!
UPDATE-Managed to track down all the libraries and compile my own build. When it works, it sounds fantastic at 64k. But I've run into a problem where songs rarely play all the way thru. After a random amount of time, they always stop. When the play button is pressed, the buffer is empty and the song starts again from the beginning. There are other related problems as well. I've posted about this on the iSub forum.
Is HE-AAC playback working properly for you?
Re: Transcoding to different codecs depending on bitrate?

Posted:
Fri May 25, 2012 10:04 am
by kingmos
Hi,
sorry for the last reply, have been pretty busy.
The problem you describe is on subsonic side and happens only in version 4.6. I downgraded to 4.5 and eyerything works perfectly. I think there is something wrong with the calculation of the lenght of the tracks in the new transcoding engine in 4.6
Regards,
Moritz
Re: Transcoding to different codecs depending on bitrate?

Posted:
Fri May 25, 2012 12:18 pm
by kingmos
So I did a small tutorial:
viewtopic.php?f=6&t=9587
Re: Transcoding to different codecs depending on bitrate?

Posted:
Sat May 26, 2012 2:17 am
by dhl
Hi Kingmos,
Thanks for the tutorial, great stuff!
Just want to let you know that the iSub developer has fixed HE-AAC playback for Subsonic 4.6 in the new 3.8 release of iSub.
Also a question about your wrapper script - curious why you divide the bitrates 64 - 128 in half. Why not just pass them through to
HE-AAC as is?
Re: Transcoding to different codecs depending on bitrate?

Posted:
Wed May 30, 2012 3:58 pm
by kingmos
... are you sure? I mailed with ben about this some time ago and we found out that it worked in subsonic 4.5 so it had to be a problem with version 4.6. Have you tested it? I don't want to up- and downgrade again if it still doesn't work

HE-AAC still sounds reasonable at 32kbit, you can only set isub to 64bkit, hence the division by two. Also HE-AAC only supports up to 64bit afaik. So the rest is transcoded to MP3. As a bonus this then still works in the webinterface.