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 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
|
/*****************************************************************
* gmerlin-encoders - encoder plugins for gmerlin
*
* Copyright (c) 2001 - 2011 Members of the Gmerlin project
* gmerlin-general@lists.sourceforge.net
* http://gmerlin.sourceforge.net
*
* 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.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* *****************************************************************/
#include <config.h>
#include AVFORMAT_HEADER
#include <gmerlin/plugin.h>
#include <gmerlin/pluginfuncs.h>
#define FLAG_CONSTANT_FRAMERATE (1<<9)
#ifdef HAVE_LIBAVCORE_AVCORE_H
#include <libavcore/avcore.h>
#endif
#if (LIBAVCORE_VERSION_INT >= ((0<<16)|(10<<8)|0)) || (LIBAVUTIL_VERSION_INT >= ((50<<16)|(38<<8)|0))
#define SampleFormat AVSampleFormat
#define SAMPLE_FMT_U8 AV_SAMPLE_FMT_U8
#define SAMPLE_FMT_S16 AV_SAMPLE_FMT_S16
#define SAMPLE_FMT_S32 AV_SAMPLE_FMT_S32
#define SAMPLE_FMT_FLT AV_SAMPLE_FMT_FLT
#define SAMPLE_FMT_DBL AV_SAMPLE_FMT_DBL
#define SAMPLE_FMT_NONE AV_SAMPLE_FMT_NONE
#endif
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(54,1,0)
#define ENCODE_VIDEO2 1
#else
#define ENCODE_VIDEO 1
#endif
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(53,34,0)
#define ENCODE_AUDIO2 1
#else
#define ENCODE_AUDIO 1
#endif
typedef struct
{
char * name;
char * long_name;
enum AVCodecID id;
const bg_parameter_info_t * parameters;
/* Terminated with PIX_FMT_NB */
enum PixelFormat * pixelformats;
} ffmpeg_codec_info_t;
typedef struct
{
char * name;
char * short_name;
char * extension;
int max_audio_streams;
int max_video_streams;
const enum AVCodecID * audio_codecs;
const enum AVCodecID * video_codecs;
int flags;
const bg_encoder_framerate_t * framerates;
} ffmpeg_format_info_t;
/* codecs.c */
bg_parameter_info_t *
bg_ffmpeg_create_audio_parameters(const ffmpeg_format_info_t * format_info);
bg_parameter_info_t *
bg_ffmpeg_create_video_parameters(const ffmpeg_format_info_t * format_info);
bg_parameter_info_t *
bg_ffmpeg_create_parameters(const ffmpeg_format_info_t * format_info);
void
bg_ffmpeg_set_codec_parameter(AVCodecContext * ctx,
#if LIBAVCODEC_VERSION_MAJOR >= 54
AVDictionary ** options,
#endif
const char * name,
const bg_parameter_value_t * val);
enum AVCodecID
bg_ffmpeg_find_audio_encoder(const ffmpeg_format_info_t * format, const char * name);
enum AVCodecID
bg_ffmpeg_find_video_encoder(const ffmpeg_format_info_t * format, const char * name);
typedef struct
{
AVStream * stream;
gavl_audio_format_t format;
uint8_t * buffer;
int buffer_alloc;
gavl_audio_frame_t * frame;
int initialized;
#if LIBAVCODEC_VERSION_MAJOR >= 54
AVDictionary * options;
#endif
#if ENCODE_AUDIO2
int64_t samples_written;
#endif
const gavl_compression_info_t * ci;
int64_t pts_offset;
} ffmpeg_audio_stream_t;
typedef struct
{
AVStream * stream;
gavl_video_format_t format;
uint8_t * buffer;
int buffer_alloc;
AVFrame * frame;
int initialized;
/* Multipass stuff */
char * stats_filename;
int pass;
int total_passes;
FILE * stats_file;
bg_encoder_framerate_t fr;
int64_t frames_written;
#if LIBAVCODEC_VERSION_MAJOR >= 54
AVDictionary * options;
#endif
const gavl_compression_info_t * ci;
int64_t dts;
int64_t pts_offset;
} ffmpeg_video_stream_t;
typedef struct
{
AVStream * stream;
int64_t pts_offset;
} ffmpeg_text_stream_t;
typedef struct
{
int num_audio_streams;
int num_video_streams;
int num_text_streams;
ffmpeg_audio_stream_t * audio_streams;
ffmpeg_video_stream_t * video_streams;
ffmpeg_text_stream_t * text_streams;
AVFormatContext * ctx;
bg_parameter_info_t * audio_parameters;
bg_parameter_info_t * video_parameters;
bg_parameter_info_t * parameters;
const ffmpeg_format_info_t * formats;
const ffmpeg_format_info_t * format;
int initialized;
int got_error;
// Needed when we write compressed video packets with B-frames
int need_pts_offset;
bg_encoder_callbacks_t * cb;
} ffmpeg_priv_t;
extern const bg_encoder_framerate_t
bg_ffmpeg_mpeg_framerates[];
void * bg_ffmpeg_create(const ffmpeg_format_info_t * formats);
void bg_ffmpeg_destroy(void*);
void bg_ffmpeg_set_callbacks(void * data,
bg_encoder_callbacks_t * cb);
const bg_parameter_info_t * bg_ffmpeg_get_parameters(void * data);
void bg_ffmpeg_set_parameter(void * data, const char * name,
const bg_parameter_value_t * v);
int bg_ffmpeg_open(void * data, const char * filename,
const gavl_metadata_t * metadata,
const bg_chapter_list_t * chapter_list);
const bg_parameter_info_t * bg_ffmpeg_get_audio_parameters(void * data);
const bg_parameter_info_t * bg_ffmpeg_get_video_parameters(void * data);
int bg_ffmpeg_add_audio_stream(void * data,
const gavl_metadata_t * metadata,
const gavl_audio_format_t * format);
int bg_ffmpeg_add_video_stream(void * data,
const gavl_metadata_t * metadata,
const gavl_video_format_t * format);
int bg_ffmpeg_add_text_stream(void * data,
const gavl_metadata_t * metadata,
int * timescale);
void bg_ffmpeg_set_audio_parameter(void * data, int stream, const char * name,
const bg_parameter_value_t * v);
void bg_ffmpeg_set_video_parameter(void * data, int stream, const char * name,
const bg_parameter_value_t * v);
enum PixelFormat * bg_ffmpeg_get_pixelformats(enum AVCodecID id);
int bg_ffmpeg_set_video_pass(void * data, int stream, int pass,
int total_passes,
const char * stats_file);
int bg_ffmpeg_start(void * data);
void bg_ffmpeg_get_audio_format(void * data, int stream,
gavl_audio_format_t*ret);
void bg_ffmpeg_get_video_format(void * data, int stream,
gavl_video_format_t*ret);
int bg_ffmpeg_write_audio_frame(void * data,
gavl_audio_frame_t * frame, int stream);
int bg_ffmpeg_write_video_frame(void * data,
gavl_video_frame_t * frame, int stream);
int bg_ffmpeg_write_subtitle_text(void * data,const char * text,
int64_t start,
int64_t duration, int stream);
int bg_ffmpeg_close(void * data, int do_delete);
gavl_pixelformat_t bg_pixelformat_ffmpeg_2_gavl(enum PixelFormat p);
enum PixelFormat bg_pixelformat_gavl_2_ffmpeg(gavl_pixelformat_t p);
gavl_sample_format_t bg_sample_format_ffmpeg_2_gavl(enum SampleFormat p);
enum AVCodecID bg_codec_id_gavl_2_ffmpeg(gavl_codec_id_t gavl);
/* Compressed stream support */
int bg_ffmpeg_writes_compressed_audio(void * priv,
const gavl_audio_format_t * format,
const gavl_compression_info_t * info);
int bg_ffmpeg_writes_compressed_video(void * priv,
const gavl_video_format_t * format,
const gavl_compression_info_t * info);
int bg_ffmpeg_add_audio_stream_compressed(void * priv,
const gavl_metadata_t * metadata,
const gavl_audio_format_t * format,
const gavl_compression_info_t * info);
int bg_ffmpeg_add_video_stream_compressed(void * priv,
const gavl_metadata_t * metadata,
const gavl_video_format_t * format,
const gavl_compression_info_t * info);
int bg_ffmpeg_write_audio_packet(void * data, gavl_packet_t * packet, int stream);
int bg_ffmpeg_write_video_packet(void * data, gavl_packet_t * packet, int stream);
|