summaryrefslogtreecommitdiffstats
path: root/libk3b/jobs/k3bvideodvdtitletranscodingjob.h
blob: 963a81be3a6a409d0645077c177dc72f67723ea0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
/* 
 *
 * $Id: sourceheader 511311 2006-02-19 14:51:05Z trueg $
 * Copyright (C) 2006 Sebastian Trueg <trueg@k3b.org>
 *
 * This file is part of the K3b project.
 * Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * See the file "COPYING" for the exact licensing terms.
 */

#ifndef _K3B_VIDEODVD_TITLE_TRANSCODING_JOB_H_
#define _K3B_VIDEODVD_TITLE_TRANSCODING_JOB_H_

#include <k3b_export.h>
#include <k3bjob.h>
#include <k3bvideodvd.h>

class KProcess;
class K3bExternalBin;


/**
 * The K3bVideoDVDTitleTranscodingJob rips a Video DVD title directly
 * from the medium and transcodes it on-the-fly to, for example, an XviD video
 *
 * For now only one audio stream is supported.
 */
class LIBK3B_EXPORT K3bVideoDVDTitleTranscodingJob : public K3bJob
{
  Q_OBJECT
  TQ_OBJECT

 public:
  K3bVideoDVDTitleTranscodingJob( K3bJobHandler* hdl, TQObject* parent );
  ~K3bVideoDVDTitleTranscodingJob();

  /**
   * The video codecs supported by this job.
   */
  enum VideoCodec {
    VIDEO_CODEC_XVID,
    VIDEO_CODEC_FFMPEG_MPEG4,
    VIDEO_CODEC_NUM_ENTRIES /**< Do not use this as a codec. */
  };

  /**
   * The audio codecs supported by this job.
   */
  enum AudioCodec {
    AUDIO_CODEC_MP3,
    /*    AUDIO_CODEC_OGG_VORBIS,*/
    AUDIO_CODEC_AC3_STEREO,
    AUDIO_CODEC_AC3_PASSTHROUGH,
    AUDIO_CODEC_NUM_ENTRIES /**< Do not use this as a codec. */
  };

  const K3bVideoDVD::VideoDVD& videoDVD() const { return m_dvd; }
  int title() const { return m_titleNumber; }
  int audioStream() const { return m_audioStreamIndex; }
  int clippingTop() const { return m_clippingTop; }
  int clippingLeft() const { return m_clippingLeft; }
  int clippingBottom() const { return m_clippingBottom; }
  int clippingRight() const { return m_clippingRight; }
  int height() const { return m_height; }
  int width() const { return m_width; }
  const TQString& filename() { return m_filename; }
  VideoCodec videoCodec() const { return m_videoCodec; }
  int videoBitrate() const { return m_videoBitrate; }
  bool twoPassEncoding() const { return m_twoPassEncoding; }
  AudioCodec audioCodec() const { return m_audioCodec; }
  int audioBitrate() const { return m_audioBitrate; }
  bool audioVBR() const { return m_audioVBR; }
  bool resampleAudioTo44100() const { return m_resampleAudio; }
  bool lowPriority() const { return m_lowPriority; }

  /**
   * \param bin If 0 the default binary from K3bCore will be used
   */
  static bool transcodeBinaryHasSupportFor( VideoCodec codec, const K3bExternalBin* bin = 0 );

  /**
   * \param bin If 0 the default binary from K3bCore will be used
   */
  static bool transcodeBinaryHasSupportFor( AudioCodec codec, const K3bExternalBin* bin = 0 );

  static TQString videoCodecString( VideoCodec );
  static TQString audioCodecString( AudioCodec );

  static TQString videoCodecDescription( VideoCodec );
  static TQString audioCodecDescription( AudioCodec );

 public slots:
  void start();
  void cancel();

  /**
   * The device containing the Video DVD
   */
  void setVideoDVD( const K3bVideoDVD::VideoDVD& dvd ) { m_dvd = dvd; }

  /**
   * Set the title number to be transcoded
   *
   * The default value is 1, denoting the first title.
   */
  void setTitle( int t ) { m_titleNumber = t; }

  /**
   * Set the audio stream to use.
   *
   * For now K3b does not support encoding multiple audio streams
   * in one video file.
   *
   * The default value is 0, meaning that the first audio stream will
   * be encoded.
   */
  void setAudioStream( int i ) { m_audioStreamIndex = i; }

  /**
   * Set the clipping values for the Video title.
   * The clipping will be applied before the transcoding.
   *
   * For now it is not possible to use different clipping values for left
   * and right as transcode cannot handle this. Thus, the job uses the
   * smaller value for both the left and right clipping.
   *
   * The default is to not clip the video.
   */
  void setClipping( int top, int left, int bottom, int right );

  /**
   * The size of the resulting transcoded video.
   *
   * The default is to automatically adjust the size (width=height=0), which
   * essentially means that anamorph encoded source material will be resized
   * according to its aspect ratio.
   *
   * It is also possible to set just the width or just the height and leave 
   * the other value to 0 which will then be determined automatically.
   *
   * The clipping values will be taken into account if at least one value
   * is determined automatically.
   *
   * The width and height values have to be a multiple of 16. If it is not, 
   * they will be changed accordingly.
   *
   * FIXME: GET INFORMATION: why a multiple of 16 and not 8 or 32?
   */
  void setSize( int width, int height );

  /**
   * The filename to write the resulting video to.
   *
   * The default is some automatically generated filename
   * in the default K3b temp directory.
   */
  void setFilename( const TQString& name ) { m_filename = name; }

  /**
   * Set the video codec used to encode the video title.
   *
   * The default is VIDEO_CODEC_FFMPEG_MPEG4
   */
  void setVideoCodec( VideoCodec codec ) { m_videoCodec = codec; }

  /**
   * Set the bitrate used to encode the video.
   *
   * The default is 1800
   */
  void setVideoBitrate( int bitrate ) { m_videoBitrate = bitrate; }

  /**
   * Set if the job should use two-pass encoding to improve
   * the quality of the resulting video.
   *
   * The default is false.
   */
  void setTwoPassEncoding( bool b ) { m_twoPassEncoding = b; }

  /**
   * Set the audio codec used to encode the audio stream
   * in the video title.
   *
   * The default is AUDIO_CODEC_MP3
   */
  void setAudioCodec( AudioCodec codec ) { m_audioCodec = codec; }

  /**
   * Set the bitrate used to encode the audio stream.
   *
   * The default is 128
   *
   * In case of the AC3 codec the bitrate can be some value between 32 and 640.
   *
   * For the AC3 passthrough mode the bitrate is ignored.
   */
  void setAudioBitrate( int bitrate ) { m_audioBitrate = bitrate; }

  /**
   * Set if the audio stream should be encoded with a variable bitrate.
   *
   * The default is false.
   *
   * For the AC3 passthrough mode the bitrate is ignored.
   */
  void setAudioVBR( bool vbr ) { m_audioVBR = vbr; }

  /**
   * Set if the audio data should be resampled to 44100 Hz/s
   *
   * The default is false.
   *
   * For the AC3 passthrough mode this is ignored.
   */
  void setResampleAudioTo44100( bool b ) { m_resampleAudio = b; }

  /**
   * If true the transcode processes will be run with a very low scheduling 
   * priority.
   *
   * The default is true.
   */
  void setLowPriority( bool b ) { m_lowPriority = b; }

 private slots:
  void slotTranscodeStderr( const TQString& );
  void slotTranscodeExited( KProcess* );

 private:
  /**
   * \param 0 - single pass encoding
   *        1 - two pass encoding/first pass
   *        2 - two pass encoding/second pass
   */
  void startTranscode( int pass );

  void cleanup( bool success );

  K3bVideoDVD::VideoDVD m_dvd;

  TQString m_filename;

  int m_clippingTop;
  int m_clippingBottom;
  int m_clippingLeft;
  int m_clippingRight;

  int m_width;
  int m_height;

  int m_titleNumber;
  int m_audioStreamIndex;  

  VideoCodec m_videoCodec;
  AudioCodec m_audioCodec;

  int m_videoBitrate;
  int m_audioBitrate;
  bool m_audioVBR;

  bool m_resampleAudio;
  bool m_twoPassEncoding;

  bool m_lowPriority;

  class Private;
  Private* d;
};

#endif