1 /////////////////////////////////////////////////////////////////////////////
2 // Name:        mediatrc_ffmpeg.h
3 // Purpose:     FFMPEG Media Transcoder
4 // Author:      Alex Thuering
5 // Created:     26.04.2008
6 // RCS-ID:      $Id: mediatrc_ffmpeg.h,v 1.43 2016/06/04 22:04:07 ntalex Exp $
7 // Copyright:   (c) Alex Thuering
8 // Licence:     GPL
9 /////////////////////////////////////////////////////////////////////////////
10 
11 #ifndef WX_FFMPEG_MEDIA_TRANSCODER_H
12 #define WX_FFMPEG_MEDIA_TRANSCODER_H
13 
14 #include "mediaenc.h"
15 #include <wxSVG/mediadec_ffmpeg.h>
16 #include "wx/dynarray.h"
17 #include <stdint.h>
18 #include <math.h>
19 #include <map>
20 #include <vector>
21 
22 using namespace std;
23 
24 class wxFfmpegMediaTranscoder {
25 public:
26 	wxFfmpegMediaTranscoder();
27 	~wxFfmpegMediaTranscoder();
28 
29 	/** Initializes transcoder command */
30 	void Init();
31 
32 	/** Adds input file. */
33 	bool AddInputFile(const wxString& fileName, const wxString& format = wxT(""), long tsOffset = 0);
34 
35 	/** Sets output file and video/audio/subtitle formats. */
36 	bool SetOutputFile(const wxString& fileName, VideoFormat videoFormat, bool ntscFilm, AspectRatio aspectRatio,
37 			AudioFormat audioFormat, SubtitleFormat subtitleFormat, int videoBitrate = 6000, bool vbr = false,
38 			int audioBitrate = 224, int mapFileIdx = -1, int mapStreamIdx = -1, StreamType mapStreamType = stUNKNOWN);
39 	/** Sets output file and video/audio/subtitle formats. */
40 	bool SetOutputFile(const wxString& fileName, VideoFormat videoFormat, bool ntscFilm, AspectRatio aspectRatio,
41 			wxArrayInt audioFormats, wxArrayInt subtitleFormats, int videoBitrate = 6000, bool vbr = false,
42 			int audioBitrate = 224, int mapFileIdx = -1, int mapStreamIdx = -1, StreamType mapStreamType = stUNKNOWN);
43 	/** Sets output format (optional). Call it before SetOutputFile() */
SetOutputFormat(wxString outputFormat)44 	void SetOutputFormat(wxString outputFormat) { m_outputFormat = outputFormat; }
45 	/** Sets interlaced encoding flag */
46 	void SetInterlaced(bool value);
47 	/** Sets first field flag (Auto, TFF, BFF) */
48 	void SetFirstField(FirstField firstField);
49 	/** Sets start time (in sec) */
50 	void SetStartTime(double startTime);
51 	/** Sets recording time (in sec) */
52 	void SetRecordingTime(double recordingTime);
53 	/** Sets list of chapters to force key frames */
SetChapterList(const wxString & chapterList)54 	void SetChapterList(const wxString& chapterList) { m_chapterList = chapterList; }
55 	/** Sets video filters */
SetVideoFilters(const wxString & videoFilters)56 	void SetVideoFilters(const wxString& videoFilters) { m_videoFilters = videoFilters; }
57 	/** Sets audio filters */
SetAudioFilters(int streamIndex,const wxString & audioFilters)58 	void SetAudioFilters(int streamIndex, const wxString& audioFilters) { m_audioFilters[streamIndex] = audioFilters; }
59 	/** Returns audio filters */
GetAudioFilters()60 	map<int, wxString>& GetAudioFilters() { return m_audioFilters; }
61 	/** Set filter to concat video segments (with reencoding) */
62 	void ConcatVideo(const wxString& resultFile, int videoBitrate = 6000, bool copyAudio = true, bool copySubtitle = false);
63 	/** Set filter to concat audio segments */
64 	void ConcatAudio(const wxString& resultFile, int segments);
65 	/** Set filter and output to calculate replay gain values */
66 	void ReplayGain(int audioStreamIdx);
67 	/** Set filter and output to calculate volume peak value */
68 	void VolumeDetect(int audioStreamIdx);
69 
70 	/** Returns transcoding command */
71 	wxString GetCmd(bool forceInternalEncoder = false) const;
72 
73 private:
74 	unsigned int m_inputFileCount;
75 	wxString m_cmd;
76 	wxString m_outputFormat;
77 	wxString m_chapterList; // list of chapters to force key frames
78 	wxString m_videoFilters;
79     map<int, wxString> m_audioFilters; // stream index -> audio filters
80     void AddOption(const wxString& name, const wxString& value);
81     void AddAudioOption(const wxString& name, int streamIdx, const wxString& value);
82     void AddVideoOption(const wxString& name, int streamIdx, const wxString& value);
83     void AddSubtitleOption(const wxString& name, int streamIdx, const wxString& value);
84 };
85 
86 #endif // WX_FFMPEG_MEDIA_TRANSCODER_H
87