I have solved a problem that has been bugging me for a long time. My
music collection is mostly flacs (ripped from CDs), but with a
significant number of digital radio or TV broadcasts; these are stream
captures in the broadcast format - i.e. mp2 files. I also have a
(comparatively much smaller) number of mp3 files; mostly these are free
downloads from a variety of websites.
When playing audio on my phone, or using VLC at work, bandwidth is
limited. For these cases I set the client bitrate to 128kbps. When LMS
finds a flac file, it uses the transcoding / conversion procedure that
is defined in convert.conf, decompressing the flac to pcm, and passing
this as input to lame, for encoding at 128kbps. Most other conversions
to mp3 work in a similar way (decompressing to pcm first).
The default definition for mp3 > mp3 encoding (required, for instance,
to reduce my 320kbps mp3s to 128kbps), is this (extracted from
convert.conf):
Code:
--------------------
# special case for smart bitrates on mp3 input
mp3 mp3 transcode *
# IFB:{BITRATE=-B %B}D:{RESAMPLE=--resample %D}
[lame] --silent -q $QUALITY$ -v $BITRATE$ $RESAMPLE$ --mp3input $FILE$ -
--------------------
Note the *--mp3input* parameter. Since mp2 files are also identified by
LMS as being of type mp3 (look in types.conf), this routine is also used
when a 192kbps mp2 is required to be converted to 128kbps. In this case,
lame requires a different parameter: *--mp2input*. Trying to convert an
mp2 file with *--mp3input* fails, and vice versa. In terms of trying to
listen to music under these conditions, the player becomes silent,
possibly resuming after an interval of silence corresponding to the
length of the track.
A few solutions suggest themselves. If mp2 and mp3 files were to be
identified differently, then there could be 2 transcoding definitions,
one for mp2 > mp3, and another for mp3 > mp3. However, we probably
wouldn't want unnecessary mp2 > mp3 conversions and if a player doesn't
report the capability to play back mp2 files, then this conversion could
take place (or mp2 > pcm, which wouldn't be harmful where there is
sufficient bandwidth). So far as I can tell (although I could be wrong),
players aren't reporting mp2 capability. Additionally, I am sure that
there are many places in the LMS code where mp3 files are treated
specially; this might require amendment to allow mp2 files similar
special treatment.
Another solution could be a modified version of the mp3 > mp3
transcoding rule above; one that finds a way of deciding upon the
appropriate *--mp2input* parameter. I struggled to implement this,
spending several days working on a perl script that was to create the
command that would be passed to lame. Unfortunately I fell at the final
hurdle, unable to figure out how to manage file names with embedded
spaces and the like. Almost all of my file names have spaces. Perhaps a
wiser person than I, or someone more familiar with perl, could complete
this code.
However, I consider my eventual successful solution to be the most
appropriate. I have modified TranscodingHelper.pm to permit a new
replacement string in convert.conf and custom-convert.conf. So now my
mp3 > mp3 transcoding defintion reads:
Code:
--------------------
mp3 mp3 transcode *
# IFB:{BITRATE=-B %B}D:{RESAMPLE=--resample %D}
[lame] --silent -q $QUALITY$ -v $BITRATE$ $RESAMPLE$ $LAME_MPTYPE$ $FILE$ -
--------------------
This block is identical to the old block, except that the *--mp3input*
element is replaced with *$LAME_MPTYPE$*.
Then, in TranscodingHelper.pm the following 2 blocks of code allow
determination of the correct value for this parameter:
Code:
--------------------
my $lame_input_type = '';
if ($fullpath =~ m/mp2$/) {
$lame_input_type="--mp2input";
} elsif ($fullpath =~ m/mp3$/) {
$lame_input_type="--mp3input";
}
--------------------
Code:
--------------------
$subs{'LAME_MPTYPE'} = $lame_input_type
--------------------
And, it works.
I spent a lot of time being frustrated by this problem, before looking
for others who had experienced it, and may have solved it. I couldn't
find anything, and yet I would be quite surprised if my experience is
unique. So, I think this is the right place to post this information.
Here's a diff file for my changes to TranscodingHelper.pm. It has a few
extra comments and commented-out lines that I used whilst testing /
debugging. I haven't created a diff for convert.conf or
custom-convert.conf; that simple change is displayed above.
Code:
--------------------
*** Slim/Player/TranscodingHelper.pm.original Tue Jan 8 23:31:55 2013
--- Slim/Player/TranscodingHelper.pm Wed Jan 9 10:44:41 2013
***************
*** 500,505 ****
--- 500,517 ----
}
}
+ # AGM 2013-01-08 added substitution logic for lame --mp2input / --mp3input
parameter
+ my $lame_input_type = '';
+ if ($fullpath =~ m/mp2$/) {
+ $lame_input_type="--mp2input";
+ } elsif ($fullpath =~ m/mp3$/) {
+ $lame_input_type="--mp3input";
+ }
+ # my $agm_logfile="/tmp/transcode-log.log";
+ # system "echo \"filepath: $filepath\" >$agm_logfile";
+ # system "echo \"fullpath: $fullpath\" >>$agm_logfile";
+ # system "echo \"lame input type: $lame_input_type\" >>$agm_logfile";
+
# escape $ and * in file names and URLs.
# Except on Windows where $ and ` shouldn't be escaped and "
# isn't allowed in filenames.
***************
*** 538,543 ****
--- 550,557 ----
$subs{'FILE'} = '"' . $filepath . '"';
$subs{'URL'} = '"' . $fullpath . '"';
$subs{'QUALITY'} = $quality;
+ # AGM 2013-01-08 added '$LAME_MPTYPE$' for lame's --mp[2/3]input parameter
+ $subs{'LAME_MPTYPE'} = $lame_input_type;
foreach (keys %subs) {
$command =~ s/\$$_\$/$subs{$_}/g;
--------------------
------------------------------------------------------------------------
rigsby's Profile: http://forums.slimdevices.com/member.php?userid=58704
View this thread: http://forums.slimdevices.com/showthread.php?t=97794
_______________________________________________
ripping mailing list
[email protected]
http://lists.slimdevices.com/mailman/listinfo/ripping