File indexing completed on 2024-06-16 07:42:07

0001 /*
0002     SPDX-FileCopyrightText: 1998-2007 Sebastian Trueg <trueg@k3b.org>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #ifndef _K3B_VIDEODVD_TITLE_TRANSCODING_JOB_H_
0007 #define _K3B_VIDEODVD_TITLE_TRANSCODING_JOB_H_
0008 
0009 #include "k3b_export.h"
0010 #include "k3bjob.h"
0011 #include "k3bvideodvd.h"
0012 #include <QProcess>
0013 
0014 namespace K3b {
0015     class ExternalBin;
0016 
0017 
0018     /**
0019      * The VideoDVDTitleTranscodingJob rips a Video DVD title directly
0020      * from the medium and transcodes it on-the-fly to, for example, an XviD video
0021      *
0022      * For now only one audio stream is supported.
0023      */
0024     class LIBK3B_EXPORT VideoDVDTitleTranscodingJob : public Job
0025     {
0026         Q_OBJECT
0027 
0028     public:
0029         VideoDVDTitleTranscodingJob( JobHandler* hdl, QObject* parent );
0030         ~VideoDVDTitleTranscodingJob() override;
0031 
0032         /**
0033          * The video codecs supported by this job.
0034          */
0035         enum VideoCodec {
0036             VIDEO_CODEC_XVID,
0037             VIDEO_CODEC_FFMPEG_MPEG4,
0038             VIDEO_CODEC_NUM_ENTRIES /**< Do not use this as a codec. */
0039         };
0040 
0041         /**
0042          * The audio codecs supported by this job.
0043          */
0044         enum AudioCodec {
0045             AUDIO_CODEC_MP3,
0046             /*    AUDIO_CODEC_OGG_VORBIS,*/
0047             AUDIO_CODEC_AC3_STEREO,
0048             AUDIO_CODEC_AC3_PASSTHROUGH,
0049             AUDIO_CODEC_NUM_ENTRIES /**< Do not use this as a codec. */
0050         };
0051 
0052         const VideoDVD::VideoDVD& videoDVD() const { return m_dvd; }
0053         int title() const { return m_titleNumber; }
0054         int audioStream() const { return m_audioStreamIndex; }
0055         int clippingTop() const { return m_clippingTop; }
0056         int clippingLeft() const { return m_clippingLeft; }
0057         int clippingBottom() const { return m_clippingBottom; }
0058         int clippingRight() const { return m_clippingRight; }
0059         int height() const { return m_height; }
0060         int width() const { return m_width; }
0061         const QString& filename() { return m_filename; }
0062         VideoCodec videoCodec() const { return m_videoCodec; }
0063         int videoBitrate() const { return m_videoBitrate; }
0064         bool twoPassEncoding() const { return m_twoPassEncoding; }
0065         AudioCodec audioCodec() const { return m_audioCodec; }
0066         int audioBitrate() const { return m_audioBitrate; }
0067         bool audioVBR() const { return m_audioVBR; }
0068         bool resampleAudioTo44100() const { return m_resampleAudio; }
0069         bool lowPriority() const { return m_lowPriority; }
0070 
0071         /**
0072          * \param bin If 0 the default binary from Core will be used
0073          */
0074         static bool transcodeBinaryHasSupportFor( VideoCodec codec, const ExternalBin* bin = 0 );
0075 
0076         /**
0077          * \param bin If 0 the default binary from Core will be used
0078          */
0079         static bool transcodeBinaryHasSupportFor( AudioCodec codec, const ExternalBin* bin = 0 );
0080 
0081         static QString videoCodecString( VideoCodec );
0082         static QString audioCodecString( AudioCodec );
0083 
0084         static QString videoCodecDescription( VideoCodec );
0085         static QString audioCodecDescription( AudioCodec );
0086 
0087     public Q_SLOTS:
0088         void start() override;
0089         void cancel() override;
0090 
0091         /**
0092          * The device containing the Video DVD
0093          */
0094         void setVideoDVD( const K3b::VideoDVD::VideoDVD& dvd ) { m_dvd = dvd; }
0095 
0096         /**
0097          * Set the title number to be transcoded
0098          *
0099          * The default value is 1, denoting the first title.
0100          */
0101         void setTitle( int t ) { m_titleNumber = t; }
0102 
0103         /**
0104          * Set the audio stream to use.
0105          *
0106          * For now K3b does not support encoding multiple audio streams
0107          * in one video file.
0108          *
0109          * The default value is 0, meaning that the first audio stream will
0110          * be encoded.
0111          */
0112         void setAudioStream( int i ) { m_audioStreamIndex = i; }
0113 
0114         /**
0115          * Set the clipping values for the Video title.
0116          * The clipping will be applied before the transcoding.
0117          *
0118          * For now it is not possible to use different clipping values for left
0119          * and right as transcode cannot handle this. Thus, the job uses the
0120          * smaller value for both the left and right clipping.
0121          *
0122          * The default is to not clip the video.
0123          */
0124         void setClipping( int top, int left, int bottom, int right );
0125 
0126         /**
0127          * The size of the resulting transcoded video.
0128          *
0129          * The default is to automatically adjust the size (width=height=0), which
0130          * essentially means that anamorph encoded source material will be resized
0131          * according to its aspect ratio.
0132          *
0133          * It is also possible to set just the width or just the height and leave
0134          * the other value to 0 which will then be determined automatically.
0135          *
0136          * The clipping values will be taken into account if at least one value
0137          * is determined automatically.
0138          *
0139          * The width and height values have to be a multiple of 16. If it is not,
0140          * they will be changed accordingly.
0141          *
0142          * FIXME: GET MessageInfoRMATION: why a multiple of 16 and not 8 or 32?
0143          */
0144         void setSize( int width, int height );
0145 
0146         /**
0147          * The filename to write the resulting video to.
0148          *
0149          * The default is some automatically generated filename
0150          * in the default K3b temp directory.
0151          */
0152         void setFilename( const QString& name ) { m_filename = name; }
0153 
0154         /**
0155          * Set the video codec used to encode the video title.
0156          *
0157          * The default is VIDEO_CODEC_FFMPEG_MPEG4
0158          */
0159         void setVideoCodec( VideoCodec codec ) { m_videoCodec = codec; }
0160 
0161         /**
0162          * Set the bitrate used to encode the video.
0163          *
0164          * The default is 1800
0165          */
0166         void setVideoBitrate( int bitrate ) { m_videoBitrate = bitrate; }
0167 
0168         /**
0169          * Set if the job should use two-pass encoding to improve
0170          * the quality of the resulting video.
0171          *
0172          * The default is false.
0173          */
0174         void setTwoPassEncoding( bool b ) { m_twoPassEncoding = b; }
0175 
0176         /**
0177          * Set the audio codec used to encode the audio stream
0178          * in the video title.
0179          *
0180          * The default is AUDIO_CODEC_MP3
0181          */
0182         void setAudioCodec( AudioCodec codec ) { m_audioCodec = codec; }
0183 
0184         /**
0185          * Set the bitrate used to encode the audio stream.
0186          *
0187          * The default is 128
0188          *
0189          * In case of the AC3 codec the bitrate can be some value between 32 and 640.
0190          *
0191          * For the AC3 passthrough mode the bitrate is ignored.
0192          */
0193         void setAudioBitrate( int bitrate ) { m_audioBitrate = bitrate; }
0194 
0195         /**
0196          * Set if the audio stream should be encoded with a variable bitrate.
0197          *
0198          * The default is false.
0199          *
0200          * For the AC3 passthrough mode the bitrate is ignored.
0201          */
0202         void setAudioVBR( bool vbr ) { m_audioVBR = vbr; }
0203 
0204         /**
0205          * Set if the audio data should be resampled to 44100 Hz/s
0206          *
0207          * The default is false.
0208          *
0209          * For the AC3 passthrough mode this is ignored.
0210          */
0211         void setResampleAudioTo44100( bool b ) { m_resampleAudio = b; }
0212 
0213         /**
0214          * If true the transcode processes will be run with a very low scheduling
0215          * priority.
0216          *
0217          * The default is true.
0218          */
0219         void setLowPriority( bool b ) { m_lowPriority = b; }
0220 
0221     private Q_SLOTS:
0222         void slotTranscodeStderr( const QString& );
0223         void slotTranscodeExited( int, QProcess::ExitStatus );
0224 
0225     private:
0226         /**
0227          * \param 0 - single pass encoding
0228          *        1 - two pass encoding/first pass
0229          *        2 - two pass encoding/second pass
0230          */
0231         void startTranscode( int pass );
0232 
0233         void cleanup( bool success );
0234 
0235         VideoDVD::VideoDVD m_dvd;
0236 
0237         QString m_filename;
0238 
0239         int m_clippingTop;
0240         int m_clippingBottom;
0241         int m_clippingLeft;
0242         int m_clippingRight;
0243 
0244         int m_width;
0245         int m_height;
0246 
0247         int m_titleNumber;
0248         int m_audioStreamIndex;
0249 
0250         VideoCodec m_videoCodec;
0251         AudioCodec m_audioCodec;
0252 
0253         int m_videoBitrate;
0254         int m_audioBitrate;
0255         bool m_audioVBR;
0256 
0257         bool m_resampleAudio;
0258         bool m_twoPassEncoding;
0259 
0260         bool m_lowPriority;
0261 
0262         class Private;
0263         Private* d;
0264     };
0265 }
0266 
0267 #endif