File indexing completed on 2025-01-19 04:24:47

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 "TranscodingVorbisFormat.h"
0018 
0019 #include <KLocalizedString>
0020 
0021 using namespace Transcoding;
0022 
0023 VorbisFormat::VorbisFormat()
0024 {
0025     m_encoder = VORBIS;
0026     m_fileExtension = QStringLiteral("ogg");
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>The <b>Vorbis</b> encoder used by Amarok supports "
0030         "a <a href=http://en.wikipedia.org/wiki/Vorbis#Technical_details>variable bitrate "
0031         "(VBR)</a> setting, which means that the bitrate value fluctuates along the track "
0032         "based on the complexity of the audio content. More complex intervals of "
0033         "data are encoded with a higher bitrate than less complex ones; this "
0034         "approach yields overall better quality and a smaller file than having a "
0035         "constant bitrate throughout the track.<br>"
0036         "The Vorbis encoder uses a quality rating \"-q parameter\" between -1 and 10 to define "
0037         "a certain expected audio quality level. The bitrate measure in this slider is "
0038         "just a rough estimate (provided by Vorbis) of the average bitrate of the encoded "
0039         "track given a q value. In fact, with newer and more efficient Vorbis versions the "
0040         "actual bitrate is even lower.<br>"
0041         "<b>-q5</b> is a good choice for music listening on a portable player.<br/>"
0042         "Anything below <b>-q3</b> might be unsatisfactory for music and anything above "
0043         "<b>-q8</b> is probably overkill.");
0044     QStringList valueLabels;
0045     const QByteArray vbr = "-q%1 ~%2kb/s";
0046     valueLabels
0047         << i18n( vbr, -1, 45 )
0048         << i18n( vbr, 0, 64 )
0049         << i18n( vbr, 1, 80 )
0050         << i18n( vbr, 2, 96 )
0051         << i18n( vbr, 3, 112 )
0052         << i18n( vbr, 4, 128 )
0053         << i18n( vbr, 5, 160 )
0054         << i18n( vbr, 6, 192 )
0055         << i18n( vbr, 7, 224 )
0056         << i18n( vbr, 8, 256 )
0057         << i18n( vbr, 9, 320 )
0058         << i18n( vbr, 10, 500 );
0059     m_propertyList << Property::Tradeoff( "quality", i18n( "Quality rating for variable bitrate encoding" ), description1,
0060                                           i18n( "Smaller file" ), i18n( "Better sound quality" ),
0061                                           valueLabels, 7 );
0062 }
0063 
0064 QString
0065 VorbisFormat::prettyName() const
0066 {
0067     return i18n( "Ogg Vorbis" );
0068 }
0069 
0070 QString
0071 VorbisFormat::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/Vorbis>Ogg Vorbis</a> is an open "
0076                   "and royalty-free audio codec for lossy audio compression.<br>It produces "
0077                   "smaller files than MP3 at equivalent or higher quality. Ogg Vorbis is an "
0078                   "all-around excellent choice, especially for portable music players that "
0079                   "support it." );
0080 }
0081 
0082 QIcon
0083 VorbisFormat::icon() const
0084 {
0085     return QIcon::fromTheme( QStringLiteral("audio-x-wav") );  //TODO: get a *real* icon!
0086 }
0087 
0088 QStringList
0089 VorbisFormat::ffmpegParameters( const Configuration &configuration ) const
0090 {
0091     QStringList parameters;
0092     parameters << QStringLiteral("-acodec") << QStringLiteral("libvorbis");   //libvorbis is better than FFmpeg's
0093                                               //vorbis implementation in many ways
0094     foreach( const Property &property, m_propertyList )
0095     {
0096         if( !configuration.property( property.name() ).isNull()
0097             && configuration.property( property.name() ).type() == property.variantType() )
0098         {
0099             if( property.name() == "quality" )
0100             {
0101                 int ffmpegQuality = configuration.property( "quality" ).toInt() - 1;
0102                 parameters << QStringLiteral("-aq") << QString::number( ffmpegQuality );
0103             }
0104         }
0105     }
0106     parameters << QStringLiteral("-vn"); // no video stream or album art, some devices can't handle that
0107     return parameters;
0108 }
0109 
0110 bool
0111 VorbisFormat::verifyAvailability( const QString &ffmpegOutput ) const
0112 {
0113     return ffmpegOutput.contains( QRegExp( QStringLiteral("^ .EA... vorbis +.*libvorbis") ) );
0114 }