1 /***************************************************************************
2                           \fn x265Encoder
3                           \brief Internal handling of video encoders
4                              -------------------
5 
6     copyright            : (C) 2002/2014 by mean/gruntster
7     email                : fixounet@free.fr
8  ***************************************************************************/
9 
10 /***************************************************************************
11  *                                                                         *
12  *   This program is free software; you can redistribute it and/or modify  *
13  *   it under the terms of the GNU General Public License as published by  *
14  *   the Free Software Foundation; either version 2 of the License, or     *
15  *   (at your option) any later version.                                   *
16  *                                                                         *
17  ***************************************************************************/
18 #ifndef ADM_x265_H
19 #define ADM_x265_H
20 #include "ADM_coreVideoEncoder.h"
21 #include "ADM_encoderConf.h"
22 #include "x265_settings.h"
23 extern "C"
24 {
25 #include "x265.h"
26 };
27 
28 #define X265_DEFAULT_CONF \
29 { \
30    true, /* bool UseAdvancedConfiguration */ \
31    { /* General */ \
32     { \
33     COMPRESS_AQ, /* COMPRESSION_MODE  mode */ \
34     20,              /* uint32_t          qz           /// Quantizer */ \
35     1500,           /* uint32_t          bitrate      /// In kb/s */ \
36     700,            /* uint32_t          finalsize    /// In ? */ \
37     1500,           /* uint32_t          avg_bitrate  /// avg_bitrate is in kb/s!! */ \
38         ADM_ENC_CAP_CBR+ \
39         ADM_ENC_CAP_CQ+ \
40         ADM_ENC_CAP_AQ+ \
41         ADM_ENC_CAP_2PASS+ \
42         ADM_ENC_CAP_2PASS_BR+ \
43         ADM_ENC_CAP_GLOBAL+ \
44         0*ADM_ENC_CAP_SAME \
45     }, \
46     99, /* Pool Threads : auto */ \
47     99, /* Frame Threads : auto */ \
48     std::string(""), /* Preset */ \
49     std::string(""), /* Tuning */ \
50     std::string(""), /* Profile */ \
51     }, \
52     -1, /* Level */ \
53     {1,1}, /* Sar width/height */ \
54     3, /* uint32_t MaxRefFrames */ \
55     25, /* uint32_t MinIdr */ \
56     250, /* uint32_t MaxIdr */ \
57     40, /* uint32_t i_scenecut_threshold */ \
58     3, /* uint32_t MaxBFrame */ \
59     1, /* uint32_t i_bframe_adaptative */ \
60     0, /* uint32_t i_bframe_bias */ \
61     2, /* uint32_t i_bframe_pyramid */ \
62     1, /* bool b_deblocking_filter */ \
63     0, /* uint32_t interlaced_mode */ \
64     false, /* bool constrained_intra */ \
65     40,	/* uint32_t lookahead; */ \
66     2, /*    uint32_t weighted_pred */ \
67     1, /*    bool weighted_bipred */ \
68     0, /*    uint32_t cb_chroma_offset */ \
69     0, /*    uint32_t cr_chroma_offset */ \
70     3, /*    uint32_t me_method */ \
71     16, /*   uint32_t me_range */ \
72     5, /*    uint32_t subpel_refine */ \
73     1, /*    uint32_t trellis */ \
74     1.0, /*     float psy_rd */ \
75     true, /*    bool fast_pskip */ \
76     true, /*    bool dct_decimate */ \
77     0, /*    uint32_t noise_reduction */ \
78     0, /*    uint32_t noise_reduction_intra */ \
79     0, /*    uint32_t noise_reduction_inter */ \
80     true, /*    bool strong_intra_smoothing */ \
81 	{ /* Rate Control */ \
82 	0,	/* uint32_t rc_method; */ \
83 	0,	/* uint32_t qp_constant; */ \
84 	4,	/* uint32_t qp_step; */ \
85 	0,	/* uint32_t bitrate; */ \
86 	1.0,	/* float rate_tolerance; */ \
87 	0,	/* uint32_t vbv_max_bitrate; */ \
88 	0,	/* uint32_t vbv_buffer_size; */ \
89 	1,	/* uint32_t vbv_buffer_init; */ \
90 	1.4,	/* float ip_factor; */ \
91 	1.3,	/* float pb_factor; */ \
92 	2,	/* uint32_t aq_mode; */ \
93 	1.0,	/* float aq_strength; */ \
94 	true, 	/* bool cu_tree; */ \
95         false   /* bool strict_cbr; */ \
96 	} \
97 }
98 
99 /**
100         \class x265Encoder
101         \brief x265 HEVC encoder
102 
103 */
104 class x265Encoder : public ADM_coreVideoEncoder
105 {
106 protected:
107                x265_param      param;
108                x265_encoder    *handle;
109                x265_picture    pic;
110                int             plane;
111                bool            globalHeader;
112                bool            preAmble (ADMImage * in);
113                bool            postAmble (ADMBitstream * out,uint32_t nbNals,x265_nal *nal,x265_picture *picout);
114                bool            createHeader(void);
115                int             encodeNals(uint8_t *buf, int size, x265_nal *nals, int nalCount, bool skipSei,bool &idrHint);
116                uint32_t        extraDataLen;
117                uint8_t         *extraData;
118                uint32_t        seiUserDataLen;
119                uint8_t         *seiUserData ;
120                bool            firstIdr;
121                uint32_t        passNumber;
122                char            *logFile;
123 
124 
125 public:
126 
127                            x265Encoder(ADM_coreVideoFilter *src,bool globalHeader);
128 virtual                    ~x265Encoder();
129 virtual        bool        setup(void);
130 virtual        bool        encode (ADMBitstream * out);
getFourcc(void)131 virtual const  char        *getFourcc(void) {return "HEVC";}
getExtraData(uint32_t * l,uint8_t ** d)132 virtual        bool         getExtraData(uint32_t *l,uint8_t **d) {*l=extraDataLen;*d=extraData;return true;}
133 virtual        bool         isDualPass(void) ;
134 
135 virtual        bool         setPassAndLogFile(int pass,const char *name);
136 
137 
138 };
139 
140 #endif
141