"Fossies" - the Fresh Open Source Software Archive

Member "amarok-2.9.0/src/core/transcoding/formats/TranscodingVorbisFormat.cpp" (28 Feb 2018, 5378 Bytes) of package /linux/misc/amarok-2.9.0.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "TranscodingVorbisFormat.cpp" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes reports: 2.8.90_vs_2.9.0 or 2.8.0_vs_2.9.0.

    1 /****************************************************************************************
    2  * Copyright (c) 2010 Téo Mrnjavac <teo@kde.org>                                        *
    3  *                                                                                      *
    4  * This program is free software; you can redistribute it and/or modify it under        *
    5  * the terms of the GNU General Public License as published by the Free Software        *
    6  * Foundation; either version 2 of the License, or (at your option) any later           *
    7  * version.                                                                             *
    8  *                                                                                      *
    9  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
   10  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
   11  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
   12  *                                                                                      *
   13  * You should have received a copy of the GNU General Public License along with         *
   14  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
   15  ****************************************************************************************/
   16 
   17 #include "TranscodingVorbisFormat.h"
   18 
   19 #include <KLocale>
   20 
   21 using namespace Transcoding;
   22 
   23 VorbisFormat::VorbisFormat()
   24 {
   25     m_encoder = VORBIS;
   26     m_fileExtension = "ogg";
   27     QString description1 =
   28         i18n( "The bitrate is a measure of the quantity of data used to represent a "
   29         "second of the audio track.<br>The <b>Vorbis</b> encoder used by Amarok supports "
   30         "a <a href=http://en.wikipedia.org/wiki/Vorbis#Technical_details>variable bitrate "
   31         "(VBR)</a> setting, which means that the bitrate value fluctuates along the track "
   32         "based on the complexity of the audio content. More complex intervals of "
   33         "data are encoded with a higher bitrate than less complex ones; this "
   34         "approach yields overall better quality and a smaller file than having a "
   35         "constant bitrate throughout the track.<br>"
   36         "The Vorbis encoder uses a quality rating \"-q parameter\" between -1 and 10 to define "
   37         "a certain expected audio quality level. The bitrate measure in this slider is "
   38         "just a rough estimate (provided by Vorbis) of the average bitrate of the encoded "
   39         "track given a q value. In fact, with newer and more efficient Vorbis versions the "
   40         "actual bitrate is even lower.<br>"
   41         "<b>-q5</b> is a good choice for music listening on a portable player.<br/>"
   42         "Anything below <b>-q3</b> might be unsatisfactory for music and anything above "
   43         "<b>-q8</b> is probably overkill.");
   44     QStringList valueLabels;
   45     QByteArray vbr = "-q%1 ~%2kb/s";
   46     valueLabels
   47         << i18n( vbr, -1, 45 )
   48         << i18n( vbr, 0, 64 )
   49         << i18n( vbr, 1, 80 )
   50         << i18n( vbr, 2, 96 )
   51         << i18n( vbr, 3, 112 )
   52         << i18n( vbr, 4, 128 )
   53         << i18n( vbr, 5, 160 )
   54         << i18n( vbr, 6, 192 )
   55         << i18n( vbr, 7, 224 )
   56         << i18n( vbr, 8, 256 )
   57         << i18n( vbr, 9, 320 )
   58         << i18n( vbr, 10, 500 );
   59     m_propertyList << Property::Tradeoff( "quality", i18n( "Quality rating for variable bitrate encoding" ), description1,
   60                                           i18n( "Smaller file" ), i18n( "Better sound quality" ),
   61                                           valueLabels, 7 );
   62 }
   63 
   64 QString
   65 VorbisFormat::prettyName() const
   66 {
   67     return i18n( "Ogg Vorbis" );
   68 }
   69 
   70 QString
   71 VorbisFormat::description() const
   72 {
   73     return i18nc( "Feel free to redirect the english Wikipedia link to a local version, if "
   74                   "it exists.",
   75                   "<a href=http://en.wikipedia.org/wiki/Vorbis>Ogg Vorbis</a> is an open "
   76                   "and royalty-free audio codec for lossy audio compression.<br>It produces "
   77                   "smaller files than MP3 at equivalent or higher quality. Ogg Vorbis is an "
   78                   "all-around excellent choice, especially for portable music players that "
   79                   "support it." );
   80 }
   81 
   82 KIcon
   83 VorbisFormat::icon() const
   84 {
   85     return KIcon( "audio-x-generic" );  //TODO: get a *real* icon!
   86 }
   87 
   88 QStringList
   89 VorbisFormat::ffmpegParameters( const Configuration &configuration ) const
   90 {
   91     QStringList parameters;
   92     parameters << "-acodec" << "libvorbis";   //libvorbis is better than FFmpeg's
   93                                               //vorbis implementation in many ways
   94     foreach( const Property &property, m_propertyList )
   95     {
   96         if( !configuration.property( property.name() ).isNull()
   97             && configuration.property( property.name() ).type() == property.variantType() )
   98         {
   99             if( property.name() == "quality" )
  100             {
  101                 int ffmpegQuality = configuration.property( "quality" ).toInt() - 1;
  102                 parameters << "-aq" << QString::number( ffmpegQuality );
  103             }
  104         }
  105     }
  106     parameters << "-vn"; // no video stream or album art, some devices can't handle that
  107     return parameters;
  108 }
  109 
  110 bool
  111 VorbisFormat::verifyAvailability( const QString &ffmpegOutput ) const
  112 {
  113     return ffmpegOutput.contains( QRegExp( "^ .EA... vorbis +.*libvorbis" ) );
  114 }