2012-09-14 17:51:26 +02:00
|
|
|
/*
|
2012-12-28 11:41:30 +01:00
|
|
|
* muxing using libavformat
|
2017-06-13 20:22:15 +02:00
|
|
|
*
|
2012-09-14 17:51:26 +02:00
|
|
|
* Copyright (C) 2011 Rudolf Polzer <divVerent@xonotic.org>
|
|
|
|
*
|
2012-12-28 11:41:30 +01:00
|
|
|
* This file is part of mpv.
|
|
|
|
*
|
2017-06-13 20:22:15 +02:00
|
|
|
* mpv is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2012-09-14 17:51:26 +02:00
|
|
|
*
|
2015-04-13 09:36:54 +02:00
|
|
|
* mpv is distributed in the hope that it will be useful,
|
2012-09-14 17:51:26 +02:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2017-06-13 20:22:15 +02:00
|
|
|
* GNU Lesser General Public License for more details.
|
2012-09-14 17:51:26 +02:00
|
|
|
*
|
2017-06-13 20:22:15 +02:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
|
2012-09-14 17:51:26 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef MPLAYER_ENCODE_LAVC_H
|
|
|
|
#define MPLAYER_ENCODE_LAVC_H
|
|
|
|
|
2014-03-08 23:38:53 +01:00
|
|
|
#include <pthread.h>
|
|
|
|
|
2012-09-14 17:51:26 +02:00
|
|
|
#include <libavcodec/avcodec.h>
|
|
|
|
#include <libavformat/avformat.h>
|
|
|
|
#include <libavutil/avstring.h>
|
|
|
|
#include <libavutil/pixfmt.h>
|
|
|
|
#include <libavutil/opt.h>
|
|
|
|
#include <libavutil/mathematics.h>
|
|
|
|
|
|
|
|
#include "encode.h"
|
2012-11-09 01:06:43 +01:00
|
|
|
#include "video/csputils.h"
|
2012-09-14 17:51:26 +02:00
|
|
|
|
|
|
|
struct encode_lavc_context {
|
2013-12-21 20:11:04 +01:00
|
|
|
struct mpv_global *global;
|
2014-06-11 02:04:02 +02:00
|
|
|
struct encode_opts *options;
|
2013-12-21 20:11:04 +01:00
|
|
|
struct mp_log *log;
|
2014-03-30 19:05:59 +02:00
|
|
|
struct mp_tags *metadata;
|
2012-09-14 17:51:26 +02:00
|
|
|
|
2014-03-08 23:38:53 +01:00
|
|
|
// All entry points must be guarded with the lock. Functions called by
|
|
|
|
// the playback core lock this automatically, but ao_lavc.c and vo_lavc.c
|
|
|
|
// must lock manually before accessing state.
|
|
|
|
pthread_mutex_t lock;
|
|
|
|
|
2013-03-04 22:21:57 +01:00
|
|
|
float vo_fps;
|
|
|
|
|
2016-04-11 20:24:48 +02:00
|
|
|
// FFmpeg contexts.
|
2012-09-14 17:51:26 +02:00
|
|
|
AVFormatContext *avc;
|
2016-04-11 20:24:48 +02:00
|
|
|
AVStream *vst;
|
|
|
|
AVStream *ast;
|
|
|
|
AVCodecContext *vcc;
|
|
|
|
AVCodecContext *acc;
|
|
|
|
|
|
|
|
// these are processed from the options
|
2012-09-14 17:51:26 +02:00
|
|
|
AVRational timebase;
|
|
|
|
AVCodec *vc;
|
|
|
|
AVCodec *ac;
|
|
|
|
AVDictionary *foptions;
|
|
|
|
AVDictionary *aoptions;
|
|
|
|
AVDictionary *voptions;
|
|
|
|
|
|
|
|
// values created during encoding
|
|
|
|
int header_written; // -1 means currently writing
|
|
|
|
|
|
|
|
// sync to audio mode
|
|
|
|
double audio_pts_offset;
|
|
|
|
double last_video_in_pts;
|
|
|
|
|
2014-03-07 15:23:03 +01:00
|
|
|
double last_audio_in_pts;
|
|
|
|
int64_t samples_since_last_pts;
|
|
|
|
|
2012-09-14 17:51:26 +02:00
|
|
|
// anti discontinuity mode
|
|
|
|
double next_in_pts;
|
|
|
|
double discontinuity_pts_offset;
|
|
|
|
|
|
|
|
long long abytes;
|
|
|
|
long long vbytes;
|
|
|
|
struct stream *twopass_bytebuffer_a;
|
|
|
|
struct stream *twopass_bytebuffer_v;
|
2013-05-25 18:31:06 +02:00
|
|
|
double t0;
|
2012-09-14 17:51:26 +02:00
|
|
|
unsigned int frames;
|
2013-06-20 11:16:51 +02:00
|
|
|
double audioseconds;
|
2012-09-29 15:04:40 +02:00
|
|
|
|
2012-09-14 17:51:26 +02:00
|
|
|
bool expect_video;
|
|
|
|
bool expect_audio;
|
2012-09-29 15:04:40 +02:00
|
|
|
bool video_first;
|
|
|
|
bool audio_first;
|
2012-09-14 17:51:26 +02:00
|
|
|
|
|
|
|
// has encoding failed?
|
|
|
|
bool failed;
|
|
|
|
bool finished;
|
|
|
|
};
|
|
|
|
|
|
|
|
// interface for vo/ao drivers
|
2016-04-11 20:24:48 +02:00
|
|
|
int encode_lavc_alloc_stream(struct encode_lavc_context *ctx,
|
|
|
|
enum AVMediaType mt, AVStream **stream_out,
|
|
|
|
AVCodecContext **codec_out);
|
|
|
|
void encode_lavc_write_stats(struct encode_lavc_context *ctx,
|
|
|
|
AVCodecContext *stream);
|
|
|
|
int encode_lavc_write_frame(struct encode_lavc_context *ctx, AVStream *stream,
|
|
|
|
AVPacket *packet);
|
2013-11-29 17:39:57 +01:00
|
|
|
int encode_lavc_supports_pixfmt(struct encode_lavc_context *ctx, enum AVPixelFormat format);
|
2016-04-11 20:24:48 +02:00
|
|
|
int encode_lavc_open_codec(struct encode_lavc_context *ctx,
|
|
|
|
AVCodecContext *codec);
|
2012-09-14 17:51:26 +02:00
|
|
|
int encode_lavc_available(struct encode_lavc_context *ctx);
|
|
|
|
int encode_lavc_timesyncfailed(struct encode_lavc_context *ctx);
|
|
|
|
int encode_lavc_start(struct encode_lavc_context *ctx); // returns 1 on success
|
|
|
|
int encode_lavc_oformat_flags(struct encode_lavc_context *ctx);
|
2016-04-11 20:24:48 +02:00
|
|
|
double encode_lavc_getoffset(struct encode_lavc_context *ctx,
|
|
|
|
AVCodecContext *codec);
|
2012-09-14 17:51:26 +02:00
|
|
|
void encode_lavc_fail(struct encode_lavc_context *ctx, const char *format, ...); // report failure of encoding
|
|
|
|
|
|
|
|
bool encode_lavc_set_csp(struct encode_lavc_context *ctx,
|
2016-04-11 20:24:48 +02:00
|
|
|
AVCodecContext *codec, enum mp_csp csp);
|
2012-09-14 17:51:26 +02:00
|
|
|
bool encode_lavc_set_csp_levels(struct encode_lavc_context *ctx,
|
2016-04-11 20:24:48 +02:00
|
|
|
AVCodecContext *codec, enum mp_csp_levels lev);
|
2012-09-14 17:51:26 +02:00
|
|
|
enum mp_csp encode_lavc_get_csp(struct encode_lavc_context *ctx,
|
2016-04-11 20:24:48 +02:00
|
|
|
AVCodecContext *codec);
|
2012-09-14 17:51:26 +02:00
|
|
|
enum mp_csp_levels encode_lavc_get_csp_levels(struct encode_lavc_context *ctx,
|
2016-04-11 20:24:48 +02:00
|
|
|
AVCodecContext *codec);
|
2012-09-14 17:51:26 +02:00
|
|
|
|
|
|
|
#endif
|