Transcoding to different codecs depending on bitrate?

Need help? Post your questions here.

Moderator: moderators

Transcoding to different codecs depending on bitrate?

Postby kingmos » Sun Jan 08, 2012 8:30 am

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
kingmos
 
Posts: 13
Joined: Thu Oct 14, 2010 2:51 pm

Re: Transcoding to different codecs depending on bitrate?

Postby wraithdu » Mon Jan 09, 2012 3:28 pm

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.
wraithdu
 
Posts: 50
Joined: Thu Apr 01, 2010 10:34 pm

Re: Transcoding to different codecs depending on bitrate?

Postby kingmos » Tue Jan 10, 2012 6:26 pm

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
kingmos
 
Posts: 13
Joined: Thu Oct 14, 2010 2:51 pm

Re: Transcoding to different codecs depending on bitrate?

Postby bushman4 » Tue Jan 10, 2012 6:31 pm

Put quotes around the proper variables in the transcode settings and those quotes should be passed on...

HTH,

Glenn
Glenn Sullivan
Subsonic 6.1.6 (Unraid Docker)
90 regular Subsonic Users

Library as of 2024-10-28:
4,527 artists
19,996 albums
282,151 songs
10201.40 GB
41,583 hours
User avatar
bushman4
 
Posts: 875
Joined: Thu Dec 02, 2010 1:47 pm
Location: Massachusetts, USA

Re: Transcoding to different codecs depending on bitrate?

Postby wraithdu » Wed Jan 11, 2012 12:19 am

As mentioned above. Odd though, Subsonic WAR / Tomcat version calls my BAT files with quotes where appropriate.
wraithdu
 
Posts: 50
Joined: Thu Apr 01, 2010 10:34 pm

Re: Transcoding to different codecs depending on bitrate?

Postby kingmos » Wed Jan 11, 2012 6:54 am

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""]
kingmos
 
Posts: 13
Joined: Thu Oct 14, 2010 2:51 pm

Re: Transcoding to different codecs depending on bitrate?

Postby kingmos » Wed Jan 11, 2012 1:33 pm

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
kingmos
 
Posts: 13
Joined: Thu Oct 14, 2010 2:51 pm

Re: Transcoding to different codecs depending on bitrate?

Postby wraithdu » Wed Jan 11, 2012 4:01 pm

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.
wraithdu
 
Posts: 50
Joined: Thu Apr 01, 2010 10:34 pm

Re: Transcoding to different codecs depending on bitrate?

Postby wraithdu » Wed Jan 11, 2012 4:49 pm

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.
wraithdu
 
Posts: 50
Joined: Thu Apr 01, 2010 10:34 pm

Re: Transcoding to different codecs depending on bitrate?

Postby dhl » Fri Mar 30, 2012 8:48 pm

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?
dhl
 
Posts: 2
Joined: Fri Mar 30, 2012 8:37 pm

Re: Transcoding to different codecs depending on bitrate?

Postby kingmos » Fri May 25, 2012 10:04 am

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
kingmos
 
Posts: 13
Joined: Thu Oct 14, 2010 2:51 pm

Re: Transcoding to different codecs depending on bitrate?

Postby kingmos » Fri May 25, 2012 12:18 pm

So I did a small tutorial:
viewtopic.php?f=6&t=9587
kingmos
 
Posts: 13
Joined: Thu Oct 14, 2010 2:51 pm

Re: Transcoding to different codecs depending on bitrate?

Postby dhl » Sat May 26, 2012 2:17 am

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?
dhl
 
Posts: 2
Joined: Fri Mar 30, 2012 8:37 pm

Re: Transcoding to different codecs depending on bitrate?

Postby kingmos » Wed May 30, 2012 3:58 pm

... 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.
kingmos
 
Posts: 13
Joined: Thu Oct 14, 2010 2:51 pm


Return to Help

Who is online

Users browsing this forum: No registered users and 36 guests