Advertisement
Guest User

Converter.h

a guest
Jul 22nd, 2015
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.49 KB | None | 0 0
  1. #ifndef CONVERTER_H_
  2. #define CONVERTER_H_
  3.  
  4. #include <QString>
  5. #include <QObject>
  6. #include <QQueue>
  7. #include <FileFormats.h>
  8.  
  9. extern "C" {
  10. #include <libavcodec/avcodec.h>
  11. #include <libavformat/avformat.h>
  12. #include <libswscale/swscale.h>
  13. #include <libavresample/avresample.h>
  14. #include <libavutil/opt.h>
  15. }
  16.  
  17. class InternetVideo;
  18. class Converter : public QObject
  19. {
  20.     Q_OBJECT
  21.  
  22. public:
  23.  
  24.     Converter();
  25.     void AddToQueue(InternetVideo* v);
  26.     void StartConverting();
  27.  
  28.     void SetFormatSettings(FileFormat format, int audioQuality, int videoQuality);
  29.     void SetTargetPath(QString target) { m_TargetPath = target; }
  30.  
  31. protected slots:
  32.     void onConvertingFinished(InternetVideo *v);
  33.  
  34. signals:
  35.     void QueueFinished();
  36.     void ConvertingFinished(InternetVideo *v);
  37.  
  38. private:
  39.  
  40.     bool OpenInput(const char* path);
  41.     bool OpenOutput(QString targetFilename);
  42.  
  43.     void Convert(InternetVideo *v);
  44.     AVStream * add_audio_stream(AVFormatContext * m_OutputFormatCtx, AVCodec ** m_AudioCodec, enum AVCodecID audio_codec);
  45.     AVStream * add_video_stream(AVFormatContext * m_OutputFormatCtx, AVCodec ** m_AudioCodec, enum AVCodecID audio_codec);
  46.     int open_audio(AVFormatContext * m_OutputFormatCtx, AVCodec * m_AudioCodec, AVStream * audio_st);
  47.     int open_video(AVFormatContext * m_OutputFormatCtx, AVCodec * m_VideoCodec, AVStream * video_st);
  48.     int decode_frame(AVPacket* packet, AVFrame* outputFrame);
  49.     int decode_packet(AVPacket* packet, AVFrame* outputFrame);
  50.     void write_audio_frame(AVFrame *frame, uint8_t** audio_dst_data, int audio_dst_bufsize);
  51.     void write_delayed_frames(AVFormatContext * m_OutputFormatCtx, AVStream * audio_st);
  52.     QQueue<InternetVideo*> m_Queue;
  53.  
  54.     bool m_Converting;
  55.     bool m_audioOnly;
  56.  
  57.     QString m_TargetPath;
  58.  
  59.     FileFormat m_Format;
  60.     AudioQuality m_AudioQuality;
  61.     VideoQuality m_VideoQuality;
  62.     QString m_FileEnding;
  63.  
  64.     //libav stuff
  65.     AVFormatContext *m_FormatCtx;
  66.     AVFormatContext *m_OutputFormatCtx;
  67.     AVCodecContext *m_VideoCodecCtx;
  68.     AVCodecContext *m_AudioCodecCtx;
  69.     AVCodec *m_VideoCodec;
  70.     AVCodec *m_AudioCodec;
  71.     AVCodec *m_OutputAudioCodec;
  72.     AVCodec *m_OutputVideoCodec;
  73.     AVAudioResampleContext *m_avresampleCtx;
  74.     int m_VideoStreamIndex;
  75.     int m_AudioStreamIndex;
  76.     int m_Audio_channels;
  77.     int audio_input_frame_size;
  78.     int got_frame;
  79.     int audiobufsize = 0;
  80.     AVFrame* m_DecodedAudioFrame;
  81.     AVFrame* m_DecodedVideoFrame;
  82.     uint8_t** audio_dst_data;
  83.     uint8_t*  video_dst_data;
  84.     AVStream * audio_st;
  85.     AVStream * video_st;
  86.     int audio_dst_linesize;
  87.     int audio_dst_bufsize;
  88. };
  89.  
  90. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement