File indexing completed on 2025-01-05 04:26:20

0001 /****************************************************************************************
0002  * Copyright (c) 2010 Téo Mrnjavac <teo@kde.org>                                        *
0003  *                                                                                      *
0004  * This program is free software; you can redistribute it and/or modify it under        *
0005  * the terms of the GNU General Public License as published by the Free Software        *
0006  * Foundation; either version 2 of the License, or (at your option) any later           *
0007  * version.                                                                             *
0008  *                                                                                      *
0009  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0010  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0011  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0012  *                                                                                      *
0013  * You should have received a copy of the GNU General Public License along with         *
0014  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0015  ****************************************************************************************/
0016 
0017 #include "TranscodingWmaFormat.h"
0018 
0019 #include <KLocalizedString>
0020 
0021 using namespace Transcoding;
0022 
0023 WmaFormat::WmaFormat()
0024 {
0025     m_encoder = WMA2;
0026     m_fileExtension = QStringLiteral("wma");
0027     const QString description1 =
0028         i18n( "The bitrate is a measure of the quantity of data used to represent a "
0029         "second of the audio track.<br>Due to the limitations of the proprietary <b>WMA</b> "
0030         "format and the difficulty of reverse-engineering a proprietary encoder, the "
0031         "WMA encoder used by Amarok sets a <a href=http://en.wikipedia.org/wiki/"
0032         "Windows_Media_Audio#Windows_Media_Audio>constant bitrate (CBR)</a> setting.<br>"
0033         "For this reason, the bitrate measure in this slider is a pretty accurate estimate "
0034         "of the bitrate of the encoded track.<br>"
0035         "<b>136kb/s</b> is a good choice for music listening on a portable player.<br/>"
0036         "Anything below <b>112kb/s</b> might be unsatisfactory for music and anything above "
0037         "<b>182kb/s</b> is probably overkill.");
0038     QStringList valueLabels;
0039     const QByteArray cbr = "CBR %1kb/s";
0040     valueLabels
0041         << i18n( cbr, 64 )
0042         << i18n( cbr, 80 )
0043         << i18n( cbr, 96 )
0044         << i18n( cbr, 112 )
0045         << i18n( cbr, 136 )
0046         << i18n( cbr, 182 )
0047         << i18n( cbr, 275 )
0048         << i18n( cbr, 550 );
0049     m_validBitrates
0050         << 65
0051         << 75
0052         << 88
0053         << 106
0054         << 133
0055         << 180
0056         << 271
0057         << 545;
0058 
0059     m_propertyList << Property::Tradeoff( "bitrate", i18n( "Bitrate target for constant bitrate encoding" ), description1,
0060                                           i18n( "Smaller file" ), i18n( "Better sound quality" ),
0061                                           valueLabels, 4 );
0062 }
0063 
0064 QString
0065 WmaFormat::prettyName() const
0066 {
0067     return i18n( "Windows Media Audio" );
0068 }
0069 
0070 QString
0071 WmaFormat::description() const
0072 {
0073     return i18nc( "Feel free to redirect the english Wikipedia link to a local version, if "
0074                   "it exists.",
0075                   "<a href=http://en.wikipedia.org/wiki/Windows_Media_Audio>Windows Media "
0076                   "Audio</a> (WMA) is a proprietary codec developed by Microsoft for lossy "
0077                   "audio compression.<br>Recommended only for portable music players that "
0078                   "do not support Ogg Vorbis." );
0079 }
0080 
0081 QIcon
0082 WmaFormat::icon() const
0083 {
0084     return QIcon::fromTheme( "audio-x-generic" );  //TODO: get a *real* icon!
0085 }
0086 
0087 QStringList
0088 WmaFormat::ffmpegParameters( const Configuration &configuration ) const
0089 {
0090     QStringList parameters;
0091     parameters << QStringLiteral("-acodec") << QStringLiteral("wmav2");
0092     foreach( const Property &property, m_propertyList )
0093     {
0094         if( !configuration.property( property.name() ).isNull()
0095             && configuration.property( property.name() ).type() == property.variantType() )
0096         {
0097             if( property.name() == "bitrate" )
0098             {
0099                 int ffmpegBitrate = toFfmpegBitrate( configuration.property( "bitrate" ).toInt() );
0100                 parameters << QStringLiteral("-ab") << QString::number( ffmpegBitrate );
0101             }
0102         }
0103     }
0104     parameters << QStringLiteral("-vn"); // no video stream or album art
0105     return parameters;
0106 }
0107 
0108 int
0109 WmaFormat::toFfmpegBitrate( int setting ) const
0110 {
0111     return m_validBitrates[ setting ] * 1000;
0112 }
0113 
0114 
0115 bool
0116 WmaFormat::verifyAvailability( const QString &ffmpegOutput ) const
0117 {
0118     return ffmpegOutput.contains( QRegExp( QStringLiteral("^ .EA... wmav2 +") ) );
0119 }