| 1 | #pragma once
|
|---|
| 2 |
|
|---|
| 3 | /**
|
|---|
| 4 | * @author Tophead, Jan Drabner
|
|---|
| 5 | */
|
|---|
| 6 |
|
|---|
| 7 | #ifdef FFMPEG_DLL_EXPORTS
|
|---|
| 8 | #define FFMPEG_DLL_API __declspec(dllexport)
|
|---|
| 9 | #else
|
|---|
| 10 | #define FFMPEG_DLL_API __declspec(dllimport)
|
|---|
| 11 | #endif
|
|---|
| 12 |
|
|---|
| 13 | //#include "libavcodec/avcodec.h"
|
|---|
| 14 | //#include "C:/ffmpeg/include/stdint.h"
|
|---|
| 15 | //#include "C:/ffmpeg/include/inttypes.h"
|
|---|
| 16 |
|
|---|
| 17 | #ifndef M_PI
|
|---|
| 18 | #define M_PI 3.14159265358979323846
|
|---|
| 19 | #endif
|
|---|
| 20 |
|
|---|
| 21 | #define inline _inline
|
|---|
| 22 | #define snprintf _snprintf
|
|---|
| 23 |
|
|---|
| 24 | extern "C" {
|
|---|
| 25 | #include "libavformat/avformat.h"
|
|---|
| 26 | #include "libswscale/swscale.h"
|
|---|
| 27 | }
|
|---|
| 28 | #include <memory.h>
|
|---|
| 29 | #include <windows.h>
|
|---|
| 30 | #include <queue>
|
|---|
| 31 | #include "FramesCollection.h"
|
|---|
| 32 |
|
|---|
| 33 | struct Picture
|
|---|
| 34 | {
|
|---|
| 35 | int frame;
|
|---|
| 36 | void *pic;
|
|---|
| 37 | int pic_size;
|
|---|
| 38 | int vStart;
|
|---|
| 39 | int soundOffset;
|
|---|
| 40 | int lStart;
|
|---|
| 41 | int lEnd;
|
|---|
| 42 | int vEnd;
|
|---|
| 43 | bool bFree;
|
|---|
| 44 |
|
|---|
| 45 | };
|
|---|
| 46 |
|
|---|
| 47 | static void log_callback(void *ptr, int level, const char *fmt, va_list vargs);
|
|---|
| 48 |
|
|---|
| 49 | // Diese Klasse wird aus ffmpeg_dll.dll exportiert.
|
|---|
| 50 | class FFMPEG_DLL_API Cffmpeg_dll {
|
|---|
| 51 | public:
|
|---|
| 52 | // constructor
|
|---|
| 53 | Cffmpeg_dll(void);
|
|---|
| 54 | // destructor
|
|---|
| 55 | ~Cffmpeg_dll(void);
|
|---|
| 56 | // here comes the data
|
|---|
| 57 |
|
|---|
| 58 | /* encoder thread */
|
|---|
| 59 | int QueuePicture( Picture& pic );
|
|---|
| 60 | HANDLE thread;
|
|---|
| 61 | CRITICAL_SECTION queueLock;
|
|---|
| 62 | std::queue< Picture >* pictureQueue;
|
|---|
| 63 |
|
|---|
| 64 | /**************************************************************/
|
|---|
| 65 | /* audio data */
|
|---|
| 66 |
|
|---|
| 67 | bool skippedFirst; // Skip the first frame because of audio noise
|
|---|
| 68 |
|
|---|
| 69 | float t, tincr, tincr2;
|
|---|
| 70 | int16_t *samples;
|
|---|
| 71 | uint8_t *audio_outbuf;
|
|---|
| 72 | int audio_outbuf_size;
|
|---|
| 73 | int audio_input_frame_size;
|
|---|
| 74 | char soundInputPath[1024];
|
|---|
| 75 | FILE *fp_sound_input;
|
|---|
| 76 |
|
|---|
| 77 | enum AVSampleFormat sample_fmt;
|
|---|
| 78 | int audio_bit_rate;
|
|---|
| 79 | int sample_rate;
|
|---|
| 80 | int channels;
|
|---|
| 81 |
|
|---|
| 82 | /**************************************************************/
|
|---|
| 83 | /* video data */
|
|---|
| 84 |
|
|---|
| 85 | AVFrame *picture, *tmp_picture;
|
|---|
| 86 | uint8_t *video_outbuf;
|
|---|
| 87 | int frame_count, video_outbuf_size;
|
|---|
| 88 | int srcWidth, srcHeight;
|
|---|
| 89 | int dstWidth, dstHeight;
|
|---|
| 90 | struct SwsContext *img_convert_ctx;
|
|---|
| 91 | AVOutputFormat *fmt;
|
|---|
| 92 | AVFormatContext *oc;
|
|---|
| 93 | AVStream *audio_st, *video_st;
|
|---|
| 94 | char videoOutputPath[1024];
|
|---|
| 95 | double audio_pts, video_pts;
|
|---|
| 96 | int video_bit_rate;
|
|---|
| 97 |
|
|---|
| 98 | // h264 specific parameters
|
|---|
| 99 | int qmin, qmax;
|
|---|
| 100 | int me_method;
|
|---|
| 101 | int me_subpel_quality;
|
|---|
| 102 | float i_quant_factor;
|
|---|
| 103 | float qcompress;
|
|---|
| 104 | int max_qdiff;
|
|---|
| 105 |
|
|---|
| 106 | int fps;
|
|---|
| 107 | char audioCodec[512];
|
|---|
| 108 | CodecID audio_codec_id;
|
|---|
| 109 | void * audio_codec_ptr;
|
|---|
| 110 | char videoCodec[512];
|
|---|
| 111 | CodecID video_codec_id;
|
|---|
| 112 | bool video_finished;
|
|---|
| 113 |
|
|---|
| 114 | int threads;
|
|---|
| 115 |
|
|---|
| 116 |
|
|---|
| 117 | /**************************************************************/
|
|---|
| 118 | /* intro and outro data */
|
|---|
| 119 | FramesCollection* introVideo;
|
|---|
| 120 | FramesCollection* outroVideo;
|
|---|
| 121 | };
|
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 | extern "C"
|
|---|
| 125 | {
|
|---|
| 126 | FFMPEG_DLL_API Cffmpeg_dll * Create_Cffmpeg_dll();
|
|---|
| 127 |
|
|---|
| 128 | FFMPEG_DLL_API int InitVideo_ffmpeg_dll(Cffmpeg_dll * ptr,
|
|---|
| 129 | const char * filename,
|
|---|
| 130 | const char * soundname,
|
|---|
| 131 | const char * logfilePath);
|
|---|
| 132 |
|
|---|
| 133 | FFMPEG_DLL_API int EncodePicture_ffmpeg_dll(Cffmpeg_dll * ptr,
|
|---|
| 134 | int frame,
|
|---|
| 135 | void * pic, int pic_size,
|
|---|
| 136 | int vStart = 0,
|
|---|
| 137 | int soundOffset = 0,
|
|---|
| 138 | int lStart = 0, int lEnd = 0,
|
|---|
| 139 | int vEnd = 0 );
|
|---|
| 140 |
|
|---|
| 141 | FFMPEG_DLL_API int CloseVideo_ffmpeg_dll(Cffmpeg_dll * ptr);
|
|---|
| 142 |
|
|---|
| 143 | FFMPEG_DLL_API int Delete_Cffmpeg_dll(Cffmpeg_dll * ptr);
|
|---|
| 144 | }
|
|---|
| 145 |
|
|---|