2012-04-07 08:36:04 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2012-11-04 00:22:16 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2012-04-07 08:36:04 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <string.h>
|
|
|
|
/* for stats file handling */
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <glib/gstdio.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <libavcodec/avcodec.h>
|
2017-03-16 04:23:01 +00:00
|
|
|
#include <libavutil/stereo3d.h>
|
2012-04-07 08:36:04 +00:00
|
|
|
|
|
|
|
#include <gst/gst.h>
|
2012-06-14 14:29:05 +00:00
|
|
|
#include <gst/video/gstvideometa.h>
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2012-09-10 15:53:54 +00:00
|
|
|
#include "gstav.h"
|
|
|
|
#include "gstavcodecmap.h"
|
|
|
|
#include "gstavutils.h"
|
|
|
|
#include "gstavvidenc.h"
|
|
|
|
#include "gstavcfg.h"
|
2012-04-07 08:36:04 +00:00
|
|
|
|
|
|
|
#define DEFAULT_VIDEO_BITRATE 300000 /* in bps */
|
|
|
|
#define DEFAULT_VIDEO_GOP_SIZE 15
|
|
|
|
|
|
|
|
#define DEFAULT_WIDTH 352
|
|
|
|
#define DEFAULT_HEIGHT 288
|
|
|
|
|
|
|
|
|
|
|
|
#define VIDEO_BUFFER_SIZE (1024*1024)
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2012-11-19 16:08:23 +00:00
|
|
|
PROP_0,
|
|
|
|
PROP_BIT_RATE,
|
|
|
|
PROP_GOP_SIZE,
|
|
|
|
PROP_ME_METHOD,
|
|
|
|
PROP_BUFSIZE,
|
|
|
|
PROP_RTP_PAYLOAD_SIZE,
|
2014-03-18 05:26:52 +00:00
|
|
|
PROP_MAX_THREADS,
|
2013-10-14 20:50:57 +00:00
|
|
|
PROP_COMPLIANCE,
|
2014-02-23 10:40:14 +00:00
|
|
|
PROP_CFG_BASE,
|
2012-04-07 08:36:04 +00:00
|
|
|
};
|
|
|
|
|
2012-04-07 09:14:45 +00:00
|
|
|
#define GST_TYPE_ME_METHOD (gst_ffmpegvidenc_me_method_get_type())
|
2012-04-07 08:36:04 +00:00
|
|
|
static GType
|
2012-04-07 09:14:45 +00:00
|
|
|
gst_ffmpegvidenc_me_method_get_type (void)
|
2012-04-07 08:36:04 +00:00
|
|
|
{
|
|
|
|
static GType ffmpegenc_me_method_type = 0;
|
|
|
|
static GEnumValue ffmpegenc_me_methods[] = {
|
|
|
|
{ME_ZERO, "None (Very low quality)", "zero"},
|
|
|
|
{ME_FULL, "Full (Slow, unmaintained)", "full"},
|
|
|
|
{ME_LOG, "Logarithmic (Low quality, unmaintained)", "logarithmic"},
|
|
|
|
{ME_PHODS, "phods (Low quality, unmaintained)", "phods"},
|
|
|
|
{ME_EPZS, "EPZS (Best quality, Fast)", "epzs"},
|
|
|
|
{ME_X1, "X1 (Experimental)", "x1"},
|
|
|
|
{0, NULL, NULL},
|
|
|
|
};
|
|
|
|
if (!ffmpegenc_me_method_type) {
|
|
|
|
ffmpegenc_me_method_type =
|
2012-06-15 10:28:54 +00:00
|
|
|
g_enum_register_static ("GstLibAVVidEncMeMethod", ffmpegenc_me_methods);
|
2012-04-07 08:36:04 +00:00
|
|
|
}
|
|
|
|
return ffmpegenc_me_method_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* A number of function prototypes are given so we can refer to them later. */
|
2012-04-07 09:14:45 +00:00
|
|
|
static void gst_ffmpegvidenc_class_init (GstFFMpegVidEncClass * klass);
|
|
|
|
static void gst_ffmpegvidenc_base_init (GstFFMpegVidEncClass * klass);
|
|
|
|
static void gst_ffmpegvidenc_init (GstFFMpegVidEnc * ffmpegenc);
|
|
|
|
static void gst_ffmpegvidenc_finalize (GObject * object);
|
|
|
|
|
2013-08-29 14:53:28 +00:00
|
|
|
static gboolean gst_ffmpegvidenc_start (GstVideoEncoder * encoder);
|
2012-04-24 09:31:27 +00:00
|
|
|
static gboolean gst_ffmpegvidenc_stop (GstVideoEncoder * encoder);
|
|
|
|
static GstFlowReturn gst_ffmpegvidenc_finish (GstVideoEncoder * encoder);
|
|
|
|
static gboolean gst_ffmpegvidenc_set_format (GstVideoEncoder * encoder,
|
|
|
|
GstVideoCodecState * state);
|
2012-06-14 14:29:05 +00:00
|
|
|
static gboolean gst_ffmpegvidenc_propose_allocation (GstVideoEncoder * encoder,
|
|
|
|
GstQuery * query);
|
2013-08-15 13:51:52 +00:00
|
|
|
static gboolean gst_ffmpegvidenc_flush (GstVideoEncoder * encoder);
|
2012-04-24 09:31:27 +00:00
|
|
|
|
|
|
|
static GstFlowReturn gst_ffmpegvidenc_handle_frame (GstVideoEncoder * encoder,
|
|
|
|
GstVideoCodecFrame * frame);
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2012-04-07 09:14:45 +00:00
|
|
|
static void gst_ffmpegvidenc_set_property (GObject * object,
|
2012-04-07 08:36:04 +00:00
|
|
|
guint prop_id, const GValue * value, GParamSpec * pspec);
|
2012-04-07 09:14:45 +00:00
|
|
|
static void gst_ffmpegvidenc_get_property (GObject * object,
|
2012-04-07 08:36:04 +00:00
|
|
|
guint prop_id, GValue * value, GParamSpec * pspec);
|
|
|
|
|
2012-06-14 14:29:05 +00:00
|
|
|
#define GST_FFENC_PARAMS_QDATA g_quark_from_static_string("avenc-params")
|
2012-04-07 08:36:04 +00:00
|
|
|
|
|
|
|
static GstElementClass *parent_class = NULL;
|
|
|
|
|
2012-04-07 09:14:45 +00:00
|
|
|
/*static guint gst_ffmpegvidenc_signals[LAST_SIGNAL] = { 0 }; */
|
2012-04-07 08:36:04 +00:00
|
|
|
|
|
|
|
static void
|
2012-04-07 09:14:45 +00:00
|
|
|
gst_ffmpegvidenc_base_init (GstFFMpegVidEncClass * klass)
|
2012-04-07 08:36:04 +00:00
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
|
|
|
AVCodec *in_plugin;
|
|
|
|
GstPadTemplate *srctempl = NULL, *sinktempl = NULL;
|
|
|
|
GstCaps *srccaps = NULL, *sinkcaps = NULL;
|
2012-04-07 09:14:45 +00:00
|
|
|
gchar *longname, *description;
|
2017-03-22 07:25:40 +00:00
|
|
|
const gchar *classification;
|
2012-04-07 08:36:04 +00:00
|
|
|
|
|
|
|
in_plugin =
|
|
|
|
(AVCodec *) g_type_get_qdata (G_OBJECT_CLASS_TYPE (klass),
|
|
|
|
GST_FFENC_PARAMS_QDATA);
|
|
|
|
g_assert (in_plugin != NULL);
|
|
|
|
|
|
|
|
/* construct the element details struct */
|
2012-06-14 14:29:05 +00:00
|
|
|
longname = g_strdup_printf ("libav %s encoder", in_plugin->long_name);
|
|
|
|
description = g_strdup_printf ("libav %s encoder", in_plugin->name);
|
2017-03-22 07:25:40 +00:00
|
|
|
classification =
|
2017-03-20 16:49:47 +00:00
|
|
|
gst_ffmpeg_codecid_is_image (in_plugin->id) ? "Codec/Encoder/Image" :
|
|
|
|
"Codec/Encoder/Video";
|
2012-06-14 14:29:05 +00:00
|
|
|
gst_element_class_set_metadata (element_class, longname,
|
2017-03-22 07:25:40 +00:00
|
|
|
classification, description,
|
2012-04-07 08:36:04 +00:00
|
|
|
"Wim Taymans <wim.taymans@gmail.com>, "
|
|
|
|
"Ronald Bultje <rbultje@ronald.bitfreak.net>");
|
|
|
|
g_free (longname);
|
|
|
|
g_free (description);
|
|
|
|
|
|
|
|
if (!(srccaps = gst_ffmpeg_codecid_to_caps (in_plugin->id, NULL, TRUE))) {
|
|
|
|
GST_DEBUG ("Couldn't get source caps for encoder '%s'", in_plugin->name);
|
2012-06-14 14:29:05 +00:00
|
|
|
srccaps = gst_caps_new_empty_simple ("unknown/unknown");
|
2012-04-07 08:36:04 +00:00
|
|
|
}
|
|
|
|
|
2012-12-11 18:48:34 +00:00
|
|
|
sinkcaps = gst_ffmpeg_codectype_to_video_caps (NULL,
|
|
|
|
in_plugin->id, TRUE, in_plugin);
|
|
|
|
if (!sinkcaps) {
|
|
|
|
GST_DEBUG ("Couldn't get sink caps for encoder '%s'", in_plugin->name);
|
|
|
|
sinkcaps = gst_caps_new_empty_simple ("unknown/unknown");
|
|
|
|
}
|
2012-04-07 08:36:04 +00:00
|
|
|
|
|
|
|
/* pad templates */
|
|
|
|
sinktempl = gst_pad_template_new ("sink", GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS, sinkcaps);
|
|
|
|
srctempl = gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS, srccaps);
|
|
|
|
|
|
|
|
gst_element_class_add_pad_template (element_class, srctempl);
|
|
|
|
gst_element_class_add_pad_template (element_class, sinktempl);
|
|
|
|
|
2017-01-02 03:36:09 +00:00
|
|
|
gst_caps_unref (sinkcaps);
|
|
|
|
gst_caps_unref (srccaps);
|
|
|
|
|
2012-04-07 08:36:04 +00:00
|
|
|
klass->in_plugin = in_plugin;
|
|
|
|
klass->srctempl = srctempl;
|
|
|
|
klass->sinktempl = sinktempl;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-04-07 09:14:45 +00:00
|
|
|
gst_ffmpegvidenc_class_init (GstFFMpegVidEncClass * klass)
|
2012-04-07 08:36:04 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
2012-04-24 09:31:27 +00:00
|
|
|
GstVideoEncoderClass *venc_class;
|
2014-03-18 05:26:52 +00:00
|
|
|
int caps;
|
2012-04-07 08:36:04 +00:00
|
|
|
|
|
|
|
gobject_class = (GObjectClass *) klass;
|
2012-04-24 09:31:27 +00:00
|
|
|
venc_class = (GstVideoEncoderClass *) klass;
|
2012-04-07 08:36:04 +00:00
|
|
|
|
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
|
|
|
|
2012-04-07 09:14:45 +00:00
|
|
|
gobject_class->set_property = gst_ffmpegvidenc_set_property;
|
|
|
|
gobject_class->get_property = gst_ffmpegvidenc_get_property;
|
|
|
|
|
2012-06-14 14:29:05 +00:00
|
|
|
/* FIXME: could use -1 for a sensible per-codec default based on
|
|
|
|
* e.g. input resolution and framerate */
|
2012-11-19 16:08:23 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_BIT_RATE,
|
2012-06-14 14:29:05 +00:00
|
|
|
g_param_spec_int ("bitrate", "Bit Rate",
|
|
|
|
"Target Video Bitrate", 0, G_MAXINT, DEFAULT_VIDEO_BITRATE,
|
2012-04-07 09:14:45 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2012-11-19 16:08:23 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_GOP_SIZE,
|
2012-04-07 09:14:45 +00:00
|
|
|
g_param_spec_int ("gop-size", "GOP Size",
|
|
|
|
"Number of frames within one GOP", 0, G_MAXINT,
|
|
|
|
DEFAULT_VIDEO_GOP_SIZE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2012-11-19 16:08:23 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_ME_METHOD,
|
2012-04-07 09:14:45 +00:00
|
|
|
g_param_spec_enum ("me-method", "ME Method", "Motion Estimation Method",
|
|
|
|
GST_TYPE_ME_METHOD, ME_EPZS,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2012-11-19 16:08:23 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_BUFSIZE,
|
2012-06-14 14:29:05 +00:00
|
|
|
g_param_spec_int ("buffer-size", "Buffer Size",
|
|
|
|
"Size of the video buffers", 0, G_MAXINT, 0,
|
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
2012-04-07 09:14:45 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass),
|
2012-11-19 16:08:23 +00:00
|
|
|
PROP_RTP_PAYLOAD_SIZE, g_param_spec_int ("rtp-payload-size",
|
2012-06-14 14:29:05 +00:00
|
|
|
"RTP Payload Size", "Target GOB length", 0, G_MAXINT, 0,
|
2012-04-07 09:14:45 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2014-03-18 05:26:52 +00:00
|
|
|
caps = klass->in_plugin->capabilities;
|
|
|
|
if (caps & (CODEC_CAP_FRAME_THREADS | CODEC_CAP_SLICE_THREADS)) {
|
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_MAX_THREADS,
|
|
|
|
g_param_spec_int ("max-threads", "Maximum encode threads",
|
|
|
|
"Maximum number of worker threads to spawn. (0 = auto)",
|
|
|
|
0, G_MAXINT, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
}
|
|
|
|
|
2013-10-14 20:50:57 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_COMPLIANCE,
|
|
|
|
g_param_spec_enum ("compliance", "Compliance",
|
|
|
|
"Adherence of the encoder to the specifications",
|
|
|
|
GST_TYPE_FFMPEG_COMPLIANCE, FFMPEG_DEFAULT_COMPLIANCE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2012-04-07 09:14:45 +00:00
|
|
|
/* register additional properties, possibly dependent on the exact CODEC */
|
2014-02-23 10:40:14 +00:00
|
|
|
gst_ffmpeg_cfg_install_property (klass, PROP_CFG_BASE);
|
2012-04-07 09:14:45 +00:00
|
|
|
|
2013-08-29 14:53:28 +00:00
|
|
|
venc_class->start = gst_ffmpegvidenc_start;
|
2012-04-24 09:31:27 +00:00
|
|
|
venc_class->stop = gst_ffmpegvidenc_stop;
|
|
|
|
venc_class->finish = gst_ffmpegvidenc_finish;
|
|
|
|
venc_class->handle_frame = gst_ffmpegvidenc_handle_frame;
|
|
|
|
venc_class->set_format = gst_ffmpegvidenc_set_format;
|
2012-06-14 14:29:05 +00:00
|
|
|
venc_class->propose_allocation = gst_ffmpegvidenc_propose_allocation;
|
2013-08-15 13:51:52 +00:00
|
|
|
venc_class->flush = gst_ffmpegvidenc_flush;
|
2012-04-07 09:14:45 +00:00
|
|
|
|
|
|
|
gobject_class->finalize = gst_ffmpegvidenc_finalize;
|
2012-04-07 08:36:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-04-07 09:14:45 +00:00
|
|
|
gst_ffmpegvidenc_init (GstFFMpegVidEnc * ffmpegenc)
|
2012-04-07 08:36:04 +00:00
|
|
|
{
|
2012-12-05 18:25:37 +00:00
|
|
|
GstFFMpegVidEncClass *klass =
|
|
|
|
(GstFFMpegVidEncClass *) G_OBJECT_GET_CLASS (ffmpegenc);
|
|
|
|
|
2015-08-17 07:36:39 +00:00
|
|
|
GST_PAD_SET_ACCEPT_TEMPLATE (GST_VIDEO_ENCODER_SINK_PAD (ffmpegenc));
|
|
|
|
|
2012-04-07 08:36:04 +00:00
|
|
|
/* ffmpeg objects */
|
2012-12-05 18:25:37 +00:00
|
|
|
ffmpegenc->context = avcodec_alloc_context3 (klass->in_plugin);
|
2015-06-28 13:37:23 +00:00
|
|
|
ffmpegenc->picture = av_frame_alloc ();
|
2012-04-07 08:36:04 +00:00
|
|
|
ffmpegenc->opened = FALSE;
|
|
|
|
|
|
|
|
ffmpegenc->file = NULL;
|
|
|
|
|
2012-04-07 09:14:45 +00:00
|
|
|
ffmpegenc->bitrate = DEFAULT_VIDEO_BITRATE;
|
|
|
|
ffmpegenc->me_method = ME_EPZS;
|
|
|
|
ffmpegenc->buffer_size = 512 * 1024;
|
|
|
|
ffmpegenc->gop_size = DEFAULT_VIDEO_GOP_SIZE;
|
|
|
|
ffmpegenc->rtp_payload_size = 0;
|
2013-10-14 20:50:57 +00:00
|
|
|
ffmpegenc->compliance = FFMPEG_DEFAULT_COMPLIANCE;
|
2014-03-18 05:26:52 +00:00
|
|
|
ffmpegenc->max_threads = 0;
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2012-04-07 09:14:45 +00:00
|
|
|
ffmpegenc->lmin = 2;
|
|
|
|
ffmpegenc->lmax = 31;
|
|
|
|
ffmpegenc->max_key_interval = 0;
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2012-12-04 17:28:11 +00:00
|
|
|
gst_ffmpeg_cfg_set_defaults (ffmpegenc);
|
2012-04-07 08:36:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-04-07 09:14:45 +00:00
|
|
|
gst_ffmpegvidenc_finalize (GObject * object)
|
2012-04-07 08:36:04 +00:00
|
|
|
{
|
2012-04-07 09:14:45 +00:00
|
|
|
GstFFMpegVidEnc *ffmpegenc = (GstFFMpegVidEnc *) object;
|
2012-04-07 08:36:04 +00:00
|
|
|
|
|
|
|
gst_ffmpeg_cfg_finalize (ffmpegenc);
|
|
|
|
|
|
|
|
/* clean up remaining allocated data */
|
2015-06-28 13:37:23 +00:00
|
|
|
av_frame_free (&ffmpegenc->picture);
|
2014-01-15 09:02:33 +00:00
|
|
|
gst_ffmpeg_avcodec_close (ffmpegenc->context);
|
2012-04-07 08:36:04 +00:00
|
|
|
av_free (ffmpegenc->context);
|
|
|
|
|
|
|
|
g_free (ffmpegenc->filename);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-04-24 09:31:27 +00:00
|
|
|
gst_ffmpegvidenc_set_format (GstVideoEncoder * encoder,
|
|
|
|
GstVideoCodecState * state)
|
2012-04-07 08:36:04 +00:00
|
|
|
{
|
|
|
|
GstCaps *other_caps;
|
|
|
|
GstCaps *allowed_caps;
|
|
|
|
GstCaps *icaps;
|
2012-04-24 09:31:27 +00:00
|
|
|
GstVideoCodecState *output_format;
|
2015-11-04 20:18:56 +00:00
|
|
|
enum AVPixelFormat pix_fmt;
|
2012-04-24 09:31:27 +00:00
|
|
|
GstFFMpegVidEnc *ffmpegenc = (GstFFMpegVidEnc *) encoder;
|
2012-04-07 09:14:45 +00:00
|
|
|
GstFFMpegVidEncClass *oclass =
|
|
|
|
(GstFFMpegVidEncClass *) G_OBJECT_GET_CLASS (ffmpegenc);
|
2012-04-07 08:36:04 +00:00
|
|
|
|
|
|
|
/* close old session */
|
|
|
|
if (ffmpegenc->opened) {
|
|
|
|
gst_ffmpeg_avcodec_close (ffmpegenc->context);
|
|
|
|
ffmpegenc->opened = FALSE;
|
2013-08-29 14:53:28 +00:00
|
|
|
if (avcodec_get_context_defaults3 (ffmpegenc->context,
|
|
|
|
oclass->in_plugin) < 0) {
|
|
|
|
GST_DEBUG_OBJECT (ffmpegenc, "Failed to set context defaults");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2012-04-07 08:36:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* if we set it in _getcaps we should set it also in _link */
|
2013-10-14 20:50:57 +00:00
|
|
|
ffmpegenc->context->strict_std_compliance = ffmpegenc->compliance;
|
2012-04-07 08:36:04 +00:00
|
|
|
|
|
|
|
/* user defined properties */
|
|
|
|
ffmpegenc->context->bit_rate = ffmpegenc->bitrate;
|
|
|
|
ffmpegenc->context->bit_rate_tolerance = ffmpegenc->bitrate;
|
|
|
|
ffmpegenc->context->gop_size = ffmpegenc->gop_size;
|
|
|
|
ffmpegenc->context->me_method = ffmpegenc->me_method;
|
2012-07-02 17:39:02 +00:00
|
|
|
GST_DEBUG_OBJECT (ffmpegenc, "Setting avcontext to bitrate %d, gop_size %d",
|
2012-04-07 08:36:04 +00:00
|
|
|
ffmpegenc->bitrate, ffmpegenc->gop_size);
|
|
|
|
|
2014-03-18 05:26:52 +00:00
|
|
|
if (ffmpegenc->max_threads == 0) {
|
|
|
|
if (!(oclass->in_plugin->capabilities & CODEC_CAP_AUTO_THREADS))
|
|
|
|
ffmpegenc->context->thread_count = gst_ffmpeg_auto_max_threads ();
|
|
|
|
else
|
|
|
|
ffmpegenc->context->thread_count = 0;
|
|
|
|
} else
|
|
|
|
ffmpegenc->context->thread_count = ffmpegenc->max_threads;
|
|
|
|
|
2012-04-07 08:36:04 +00:00
|
|
|
/* RTP payload used for GOB production (for Asterisk) */
|
|
|
|
if (ffmpegenc->rtp_payload_size) {
|
|
|
|
ffmpegenc->context->rtp_payload_size = ffmpegenc->rtp_payload_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* additional avcodec settings */
|
|
|
|
/* first fill in the majority by copying over */
|
|
|
|
gst_ffmpeg_cfg_fill_context (ffmpegenc, ffmpegenc->context);
|
|
|
|
|
|
|
|
/* then handle some special cases */
|
|
|
|
ffmpegenc->context->lmin = (ffmpegenc->lmin * FF_QP2LAMBDA + 0.5);
|
|
|
|
ffmpegenc->context->lmax = (ffmpegenc->lmax * FF_QP2LAMBDA + 0.5);
|
|
|
|
|
|
|
|
if (ffmpegenc->interlaced) {
|
|
|
|
ffmpegenc->context->flags |=
|
|
|
|
CODEC_FLAG_INTERLACED_DCT | CODEC_FLAG_INTERLACED_ME;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* some other defaults */
|
|
|
|
ffmpegenc->context->rc_strategy = 2;
|
|
|
|
ffmpegenc->context->b_frame_strategy = 0;
|
|
|
|
ffmpegenc->context->coder_type = 0;
|
|
|
|
ffmpegenc->context->context_model = 0;
|
|
|
|
ffmpegenc->context->scenechange_threshold = 0;
|
|
|
|
|
|
|
|
/* and last but not least the pass; CBR, 2-pass, etc */
|
|
|
|
ffmpegenc->context->flags |= ffmpegenc->pass;
|
|
|
|
switch (ffmpegenc->pass) {
|
|
|
|
/* some additional action depends on type of pass */
|
|
|
|
case CODEC_FLAG_QSCALE:
|
|
|
|
ffmpegenc->context->global_quality
|
|
|
|
= ffmpegenc->picture->quality = FF_QP2LAMBDA * ffmpegenc->quantizer;
|
|
|
|
break;
|
|
|
|
case CODEC_FLAG_PASS1: /* need to prepare a stats file */
|
|
|
|
/* we don't close when changing caps, fingers crossed */
|
|
|
|
if (!ffmpegenc->file)
|
|
|
|
ffmpegenc->file = g_fopen (ffmpegenc->filename, "w");
|
2012-04-24 09:31:27 +00:00
|
|
|
if (!ffmpegenc->file)
|
|
|
|
goto open_file_err;
|
2012-04-07 08:36:04 +00:00
|
|
|
break;
|
|
|
|
case CODEC_FLAG_PASS2:
|
|
|
|
{ /* need to read the whole stats file ! */
|
|
|
|
gsize size;
|
|
|
|
|
|
|
|
if (!g_file_get_contents (ffmpegenc->filename,
|
2012-04-24 09:31:27 +00:00
|
|
|
&ffmpegenc->context->stats_in, &size, NULL))
|
|
|
|
goto file_read_err;
|
2012-04-07 08:36:04 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-04-24 09:31:27 +00:00
|
|
|
GST_DEBUG_OBJECT (ffmpegenc, "Extracting common video information");
|
|
|
|
/* fetch pix_fmt, fps, par, width, height... */
|
|
|
|
gst_ffmpeg_videoinfo_to_context (&state->info, ffmpegenc->context);
|
|
|
|
|
2014-04-30 14:59:04 +00:00
|
|
|
/* sanitize time base */
|
|
|
|
if (ffmpegenc->context->time_base.num <= 0
|
|
|
|
|| ffmpegenc->context->time_base.den <= 0)
|
|
|
|
goto insane_timebase;
|
|
|
|
|
2013-05-06 22:56:22 +00:00
|
|
|
if ((oclass->in_plugin->id == AV_CODEC_ID_MPEG4)
|
2012-04-07 08:36:04 +00:00
|
|
|
&& (ffmpegenc->context->time_base.den > 65535)) {
|
|
|
|
/* MPEG4 Standards do not support time_base denominator greater than
|
|
|
|
* (1<<16) - 1 . We therefore scale them down.
|
|
|
|
* Agreed, it will not be the exact framerate... but the difference
|
|
|
|
* shouldn't be that noticeable */
|
|
|
|
ffmpegenc->context->time_base.num =
|
|
|
|
(gint) gst_util_uint64_scale_int (ffmpegenc->context->time_base.num,
|
|
|
|
65535, ffmpegenc->context->time_base.den);
|
|
|
|
ffmpegenc->context->time_base.den = 65535;
|
|
|
|
GST_LOG_OBJECT (ffmpegenc, "MPEG4 : scaled down framerate to %d / %d",
|
|
|
|
ffmpegenc->context->time_base.den, ffmpegenc->context->time_base.num);
|
|
|
|
}
|
|
|
|
|
|
|
|
pix_fmt = ffmpegenc->context->pix_fmt;
|
|
|
|
|
|
|
|
/* max-key-interval may need the framerate set above */
|
|
|
|
if (ffmpegenc->max_key_interval) {
|
|
|
|
AVCodecContext *ctx;
|
|
|
|
|
|
|
|
/* override gop-size */
|
|
|
|
ctx = ffmpegenc->context;
|
|
|
|
ctx->gop_size = (ffmpegenc->max_key_interval < 0) ?
|
|
|
|
(-ffmpegenc->max_key_interval
|
|
|
|
* (ctx->time_base.den * ctx->ticks_per_frame / ctx->time_base.num))
|
|
|
|
: ffmpegenc->max_key_interval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* some codecs support more than one format, first auto-choose one */
|
|
|
|
GST_DEBUG_OBJECT (ffmpegenc, "picking an output format ...");
|
2012-04-24 09:31:27 +00:00
|
|
|
allowed_caps = gst_pad_get_allowed_caps (GST_VIDEO_ENCODER_SRC_PAD (encoder));
|
2012-04-07 08:36:04 +00:00
|
|
|
if (!allowed_caps) {
|
|
|
|
GST_DEBUG_OBJECT (ffmpegenc, "... but no peer, using template caps");
|
|
|
|
/* we need to copy because get_allowed_caps returns a ref, and
|
|
|
|
* get_pad_template_caps doesn't */
|
|
|
|
allowed_caps =
|
2012-06-14 14:29:05 +00:00
|
|
|
gst_pad_get_pad_template_caps (GST_VIDEO_ENCODER_SRC_PAD (encoder));
|
2012-04-07 08:36:04 +00:00
|
|
|
}
|
|
|
|
GST_DEBUG_OBJECT (ffmpegenc, "chose caps %" GST_PTR_FORMAT, allowed_caps);
|
|
|
|
gst_ffmpeg_caps_with_codecid (oclass->in_plugin->id,
|
|
|
|
oclass->in_plugin->type, allowed_caps, ffmpegenc->context);
|
|
|
|
|
2016-07-05 17:15:28 +00:00
|
|
|
/* open codec */
|
|
|
|
if (gst_ffmpeg_avcodec_open (ffmpegenc->context, oclass->in_plugin) < 0) {
|
|
|
|
gst_caps_unref (allowed_caps);
|
|
|
|
goto open_codec_fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* is the colourspace correct? */
|
|
|
|
if (pix_fmt != ffmpegenc->context->pix_fmt) {
|
|
|
|
gst_caps_unref (allowed_caps);
|
|
|
|
goto pix_fmt_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we may have failed mapping caps to a pixfmt,
|
|
|
|
* and quite some codecs do not make up their own mind about that
|
|
|
|
* in any case, _NONE can never work out later on */
|
|
|
|
if (pix_fmt == AV_PIX_FMT_NONE) {
|
|
|
|
gst_caps_unref (allowed_caps);
|
|
|
|
goto bad_input_fmt;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* second pass stats buffer no longer needed */
|
|
|
|
g_free (ffmpegenc->context->stats_in);
|
|
|
|
|
2012-04-07 08:36:04 +00:00
|
|
|
/* try to set this caps on the other side */
|
|
|
|
other_caps = gst_ffmpeg_codecid_to_caps (oclass->in_plugin->id,
|
|
|
|
ffmpegenc->context, TRUE);
|
|
|
|
|
2012-06-14 14:29:05 +00:00
|
|
|
if (!other_caps) {
|
|
|
|
gst_caps_unref (allowed_caps);
|
2012-04-24 09:31:27 +00:00
|
|
|
goto unsupported_codec;
|
2012-06-14 14:29:05 +00:00
|
|
|
}
|
2012-04-07 08:36:04 +00:00
|
|
|
|
|
|
|
icaps = gst_caps_intersect (allowed_caps, other_caps);
|
|
|
|
gst_caps_unref (allowed_caps);
|
|
|
|
gst_caps_unref (other_caps);
|
|
|
|
if (gst_caps_is_empty (icaps)) {
|
|
|
|
gst_caps_unref (icaps);
|
2014-05-29 16:16:42 +00:00
|
|
|
goto unsupported_codec;
|
2012-04-07 08:36:04 +00:00
|
|
|
}
|
2014-06-21 16:29:32 +00:00
|
|
|
icaps = gst_caps_fixate (icaps);
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2014-05-29 16:16:42 +00:00
|
|
|
GST_DEBUG_OBJECT (ffmpegenc, "codec flags 0x%08x", ffmpegenc->context->flags);
|
|
|
|
|
2012-04-24 09:31:27 +00:00
|
|
|
/* Store input state and set output state */
|
|
|
|
if (ffmpegenc->input_state)
|
|
|
|
gst_video_codec_state_unref (ffmpegenc->input_state);
|
|
|
|
ffmpegenc->input_state = gst_video_codec_state_ref (state);
|
|
|
|
|
|
|
|
output_format = gst_video_encoder_set_output_state (encoder, icaps, state);
|
|
|
|
gst_video_codec_state_unref (output_format);
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2015-07-29 15:24:54 +00:00
|
|
|
/* Store some tags */
|
|
|
|
{
|
|
|
|
GstTagList *tags = gst_tag_list_new_empty ();
|
|
|
|
const gchar *codec;
|
|
|
|
|
|
|
|
gst_tag_list_add (tags, GST_TAG_MERGE_REPLACE, GST_TAG_NOMINAL_BITRATE,
|
2016-09-14 09:20:48 +00:00
|
|
|
(guint) ffmpegenc->context->bit_rate, NULL);
|
2015-07-29 15:24:54 +00:00
|
|
|
|
|
|
|
if ((codec =
|
|
|
|
gst_ffmpeg_get_codecid_longname (ffmpegenc->context->codec_id)))
|
|
|
|
gst_tag_list_add (tags, GST_TAG_MERGE_REPLACE, GST_TAG_VIDEO_CODEC, codec,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
gst_video_encoder_merge_tags (encoder, tags, GST_TAG_MERGE_REPLACE);
|
|
|
|
gst_tag_list_unref (tags);
|
|
|
|
}
|
|
|
|
|
2012-04-07 08:36:04 +00:00
|
|
|
/* success! */
|
|
|
|
ffmpegenc->opened = TRUE;
|
|
|
|
|
|
|
|
return TRUE;
|
2012-04-24 09:31:27 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
open_file_err:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (ffmpegenc, RESOURCE, OPEN_WRITE,
|
|
|
|
(("Could not open file \"%s\" for writing."), ffmpegenc->filename),
|
|
|
|
GST_ERROR_SYSTEM);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
file_read_err:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (ffmpegenc, RESOURCE, READ,
|
|
|
|
(("Could not get contents of file \"%s\"."), ffmpegenc->filename),
|
|
|
|
GST_ERROR_SYSTEM);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-05-29 16:16:42 +00:00
|
|
|
insane_timebase:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (ffmpegenc, "Rejecting time base %d/%d",
|
|
|
|
ffmpegenc->context->time_base.den, ffmpegenc->context->time_base.num);
|
|
|
|
goto cleanup_stats_in;
|
|
|
|
}
|
|
|
|
unsupported_codec:
|
|
|
|
{
|
|
|
|
GST_DEBUG ("Unsupported codec - no caps found");
|
|
|
|
goto cleanup_stats_in;
|
|
|
|
}
|
2012-04-24 09:31:27 +00:00
|
|
|
open_codec_fail:
|
|
|
|
{
|
2012-06-14 14:29:05 +00:00
|
|
|
GST_DEBUG_OBJECT (ffmpegenc, "avenc_%s: Failed to open libav codec",
|
2012-04-24 09:31:27 +00:00
|
|
|
oclass->in_plugin->name);
|
2014-05-29 16:16:42 +00:00
|
|
|
goto close_codec;
|
2012-04-24 09:31:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pix_fmt_err:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (ffmpegenc,
|
2012-06-14 14:29:05 +00:00
|
|
|
"avenc_%s: AV wants different colourspace (%d given, %d wanted)",
|
2012-04-24 09:31:27 +00:00
|
|
|
oclass->in_plugin->name, pix_fmt, ffmpegenc->context->pix_fmt);
|
2014-05-29 16:16:42 +00:00
|
|
|
goto close_codec;
|
2012-04-24 09:31:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bad_input_fmt:
|
|
|
|
{
|
2012-06-14 14:29:05 +00:00
|
|
|
GST_DEBUG_OBJECT (ffmpegenc, "avenc_%s: Failed to determine input format",
|
2012-04-24 09:31:27 +00:00
|
|
|
oclass->in_plugin->name);
|
2014-05-29 16:16:42 +00:00
|
|
|
goto close_codec;
|
2012-04-24 09:31:27 +00:00
|
|
|
}
|
2014-06-02 07:27:17 +00:00
|
|
|
close_codec:
|
2012-04-24 09:31:27 +00:00
|
|
|
{
|
|
|
|
gst_ffmpeg_avcodec_close (ffmpegenc->context);
|
2013-08-29 14:53:28 +00:00
|
|
|
if (avcodec_get_context_defaults3 (ffmpegenc->context,
|
|
|
|
oclass->in_plugin) < 0)
|
|
|
|
GST_DEBUG_OBJECT (ffmpegenc, "Failed to set context defaults");
|
2014-06-02 07:27:17 +00:00
|
|
|
goto cleanup_stats_in;
|
|
|
|
}
|
|
|
|
cleanup_stats_in:
|
|
|
|
{
|
2015-11-20 18:48:47 +00:00
|
|
|
g_free (ffmpegenc->context->stats_in);
|
2014-04-30 14:59:04 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2012-04-07 08:36:04 +00:00
|
|
|
}
|
|
|
|
|
2012-06-14 14:29:05 +00:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_ffmpegvidenc_propose_allocation (GstVideoEncoder * encoder,
|
|
|
|
GstQuery * query)
|
|
|
|
{
|
2012-07-06 09:50:57 +00:00
|
|
|
gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL);
|
2012-06-14 14:29:05 +00:00
|
|
|
|
|
|
|
return GST_VIDEO_ENCODER_CLASS (parent_class)->propose_allocation (encoder,
|
|
|
|
query);
|
|
|
|
}
|
|
|
|
|
2014-03-21 09:10:14 +00:00
|
|
|
static void
|
|
|
|
gst_ffmpegvidenc_free_avpacket (gpointer pkt)
|
|
|
|
{
|
2014-03-18 05:26:52 +00:00
|
|
|
av_packet_unref ((AVPacket *) pkt);
|
2014-03-21 09:10:14 +00:00
|
|
|
g_slice_free (AVPacket, pkt);
|
|
|
|
}
|
|
|
|
|
2015-06-28 14:27:52 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GstBuffer *buffer;
|
|
|
|
GstVideoFrame vframe;
|
|
|
|
} BufferInfo;
|
|
|
|
|
|
|
|
static void
|
|
|
|
buffer_info_free (void *opaque, guint8 * data)
|
|
|
|
{
|
|
|
|
BufferInfo *info = opaque;
|
|
|
|
|
|
|
|
gst_video_frame_unmap (&info->vframe);
|
|
|
|
gst_buffer_unref (info->buffer);
|
|
|
|
g_slice_free (BufferInfo, info);
|
|
|
|
}
|
|
|
|
|
2017-03-16 04:23:01 +00:00
|
|
|
static enum AVStereo3DType
|
|
|
|
stereo_gst_to_av (GstVideoMultiviewMode mview_mode)
|
|
|
|
{
|
|
|
|
switch (mview_mode) {
|
|
|
|
case GST_VIDEO_MULTIVIEW_MODE_SIDE_BY_SIDE:
|
|
|
|
return AV_STEREO3D_SIDEBYSIDE;
|
|
|
|
case GST_VIDEO_MULTIVIEW_MODE_TOP_BOTTOM:
|
|
|
|
return AV_STEREO3D_TOPBOTTOM;
|
|
|
|
case GST_VIDEO_MULTIVIEW_MODE_FRAME_BY_FRAME:
|
|
|
|
return AV_STEREO3D_FRAMESEQUENCE;
|
|
|
|
case GST_VIDEO_MULTIVIEW_MODE_CHECKERBOARD:
|
|
|
|
return AV_STEREO3D_CHECKERBOARD;
|
|
|
|
case GST_VIDEO_MULTIVIEW_MODE_SIDE_BY_SIDE_QUINCUNX:
|
|
|
|
return AV_STEREO3D_SIDEBYSIDE_QUINCUNX;
|
|
|
|
case GST_VIDEO_MULTIVIEW_MODE_ROW_INTERLEAVED:
|
|
|
|
return AV_STEREO3D_LINES;
|
|
|
|
case GST_VIDEO_MULTIVIEW_MODE_COLUMN_INTERLEAVED:
|
|
|
|
return AV_STEREO3D_COLUMNS;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
GST_WARNING ("Unsupported multiview mode - no mapping in libav");
|
|
|
|
return AV_STEREO3D_2D;
|
|
|
|
}
|
|
|
|
|
2012-04-07 08:36:04 +00:00
|
|
|
static GstFlowReturn
|
2012-04-24 09:31:27 +00:00
|
|
|
gst_ffmpegvidenc_handle_frame (GstVideoEncoder * encoder,
|
|
|
|
GstVideoCodecFrame * frame)
|
2012-04-07 08:36:04 +00:00
|
|
|
{
|
2012-04-24 09:31:27 +00:00
|
|
|
GstFFMpegVidEnc *ffmpegenc = (GstFFMpegVidEnc *) encoder;
|
2012-04-07 08:36:04 +00:00
|
|
|
GstBuffer *outbuf;
|
2014-01-03 15:24:28 +00:00
|
|
|
gint ret = 0, c;
|
2012-04-24 09:31:27 +00:00
|
|
|
GstVideoInfo *info = &ffmpegenc->input_state->info;
|
2014-03-18 05:26:52 +00:00
|
|
|
AVPacket *pkt;
|
2014-01-03 15:24:28 +00:00
|
|
|
int have_data = 0;
|
2015-06-28 14:27:52 +00:00
|
|
|
BufferInfo *buffer_info;
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2015-06-28 14:35:46 +00:00
|
|
|
if (ffmpegenc->interlaced) {
|
|
|
|
ffmpegenc->picture->interlaced_frame = TRUE;
|
|
|
|
/* if this is not the case, a filter element should be used to swap fields */
|
|
|
|
ffmpegenc->picture->top_field_first =
|
|
|
|
GST_BUFFER_FLAG_IS_SET (frame->input_buffer, GST_VIDEO_BUFFER_FLAG_TFF);
|
|
|
|
}
|
|
|
|
|
2017-03-16 04:23:01 +00:00
|
|
|
if (GST_VIDEO_INFO_MULTIVIEW_MODE (info) != GST_VIDEO_MULTIVIEW_MODE_NONE) {
|
|
|
|
AVStereo3D *stereo = av_stereo3d_create_side_data (ffmpegenc->picture);
|
|
|
|
stereo->type = stereo_gst_to_av (GST_VIDEO_INFO_MULTIVIEW_MODE (info));
|
|
|
|
|
|
|
|
if (GST_VIDEO_INFO_MULTIVIEW_FLAGS (info) &
|
|
|
|
GST_VIDEO_MULTIVIEW_FLAGS_RIGHT_VIEW_FIRST) {
|
|
|
|
stereo->flags = AV_STEREO3D_FLAG_INVERT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-24 09:31:27 +00:00
|
|
|
if (GST_VIDEO_CODEC_FRAME_IS_FORCE_KEYFRAME (frame))
|
2012-09-12 13:30:05 +00:00
|
|
|
ffmpegenc->picture->pict_type = AV_PICTURE_TYPE_I;
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2015-06-28 14:27:52 +00:00
|
|
|
buffer_info = g_slice_new0 (BufferInfo);
|
|
|
|
buffer_info->buffer = gst_buffer_ref (frame->input_buffer);
|
|
|
|
|
|
|
|
if (!gst_video_frame_map (&buffer_info->vframe, info, frame->input_buffer,
|
|
|
|
GST_MAP_READ)) {
|
2012-06-14 14:29:05 +00:00
|
|
|
GST_ERROR_OBJECT (encoder, "Failed to map input buffer");
|
2015-06-28 14:27:52 +00:00
|
|
|
gst_buffer_unref (buffer_info->buffer);
|
|
|
|
g_slice_free (BufferInfo, buffer_info);
|
2015-11-02 01:00:55 +00:00
|
|
|
gst_video_codec_frame_unref (frame);
|
2012-06-14 14:29:05 +00:00
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
|
2012-04-24 09:31:27 +00:00
|
|
|
/* Fill avpicture */
|
2015-06-28 14:27:52 +00:00
|
|
|
ffmpegenc->picture->buf[0] =
|
|
|
|
av_buffer_create (NULL, 0, buffer_info_free, buffer_info, 0);
|
2012-04-24 09:31:27 +00:00
|
|
|
for (c = 0; c < AV_NUM_DATA_POINTERS; c++) {
|
|
|
|
if (c < GST_VIDEO_INFO_N_COMPONENTS (info)) {
|
2015-06-28 14:27:52 +00:00
|
|
|
ffmpegenc->picture->data[c] =
|
|
|
|
GST_VIDEO_FRAME_PLANE_DATA (&buffer_info->vframe, c);
|
2012-06-14 14:29:05 +00:00
|
|
|
ffmpegenc->picture->linesize[c] =
|
2015-06-28 14:27:52 +00:00
|
|
|
GST_VIDEO_FRAME_COMP_STRIDE (&buffer_info->vframe, c);
|
2012-04-24 09:31:27 +00:00
|
|
|
} else {
|
|
|
|
ffmpegenc->picture->data[c] = NULL;
|
|
|
|
ffmpegenc->picture->linesize[c] = 0;
|
|
|
|
}
|
|
|
|
}
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2016-02-16 07:11:08 +00:00
|
|
|
ffmpegenc->picture->format = ffmpegenc->context->pix_fmt;
|
|
|
|
ffmpegenc->picture->width = GST_VIDEO_FRAME_WIDTH (&buffer_info->vframe);
|
|
|
|
ffmpegenc->picture->height = GST_VIDEO_FRAME_HEIGHT (&buffer_info->vframe);
|
|
|
|
|
2012-04-07 08:36:04 +00:00
|
|
|
ffmpegenc->picture->pts =
|
2012-04-24 09:31:27 +00:00
|
|
|
gst_ffmpeg_time_gst_to_ff (frame->pts /
|
2012-04-07 08:36:04 +00:00
|
|
|
ffmpegenc->context->ticks_per_frame, ffmpegenc->context->time_base);
|
|
|
|
|
2014-01-03 15:24:28 +00:00
|
|
|
have_data = 0;
|
2014-03-21 09:10:14 +00:00
|
|
|
pkt = g_slice_new0 (AVPacket);
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2014-01-03 15:24:28 +00:00
|
|
|
ret =
|
2014-03-21 09:10:14 +00:00
|
|
|
avcodec_encode_video2 (ffmpegenc->context, pkt, ffmpegenc->picture,
|
2014-01-03 15:24:28 +00:00
|
|
|
&have_data);
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2015-06-28 14:27:52 +00:00
|
|
|
av_frame_unref (ffmpegenc->picture);
|
2012-06-14 14:29:05 +00:00
|
|
|
|
2014-03-21 09:10:14 +00:00
|
|
|
if (ret < 0 || !have_data)
|
|
|
|
g_slice_free (AVPacket, pkt);
|
|
|
|
|
2014-01-03 15:24:28 +00:00
|
|
|
if (ret < 0)
|
2012-04-24 09:31:27 +00:00
|
|
|
goto encode_fail;
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2012-04-24 09:31:27 +00:00
|
|
|
/* Encoder needs more data */
|
2015-11-20 18:48:47 +00:00
|
|
|
if (!have_data) {
|
2015-11-02 01:00:55 +00:00
|
|
|
gst_video_codec_frame_unref (frame);
|
2012-04-07 08:36:04 +00:00
|
|
|
return GST_FLOW_OK;
|
2015-11-02 01:00:55 +00:00
|
|
|
}
|
2012-04-07 08:36:04 +00:00
|
|
|
|
|
|
|
/* save stats info if there is some as well as a stats file */
|
|
|
|
if (ffmpegenc->file && ffmpegenc->context->stats_out)
|
|
|
|
if (fprintf (ffmpegenc->file, "%s", ffmpegenc->context->stats_out) < 0)
|
|
|
|
GST_ELEMENT_ERROR (ffmpegenc, RESOURCE, WRITE,
|
|
|
|
(("Could not write to file \"%s\"."), ffmpegenc->filename),
|
|
|
|
GST_ERROR_SYSTEM);
|
|
|
|
|
2012-06-26 10:36:56 +00:00
|
|
|
gst_video_codec_frame_unref (frame);
|
|
|
|
|
2012-04-24 09:31:27 +00:00
|
|
|
/* Get oldest frame */
|
|
|
|
frame = gst_video_encoder_get_oldest_frame (encoder);
|
|
|
|
|
2014-01-03 15:24:28 +00:00
|
|
|
outbuf =
|
2015-06-28 14:32:02 +00:00
|
|
|
gst_buffer_new_wrapped_full (GST_MEMORY_FLAG_READONLY, pkt->data,
|
|
|
|
pkt->size, 0, pkt->size, pkt, gst_ffmpegvidenc_free_avpacket);
|
2014-01-03 15:24:28 +00:00
|
|
|
frame->output_buffer = outbuf;
|
2012-04-24 09:31:27 +00:00
|
|
|
|
2016-01-19 07:36:01 +00:00
|
|
|
if (pkt->flags & AV_PKT_FLAG_KEY)
|
|
|
|
GST_VIDEO_CODEC_FRAME_SET_SYNC_POINT (frame);
|
|
|
|
else
|
|
|
|
GST_VIDEO_CODEC_FRAME_UNSET_SYNC_POINT (frame);
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2012-04-24 09:31:27 +00:00
|
|
|
return gst_video_encoder_finish_frame (encoder, frame);
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2012-04-24 09:31:27 +00:00
|
|
|
/* ERRORS */
|
|
|
|
encode_fail:
|
|
|
|
{
|
|
|
|
#ifndef GST_DISABLE_GST_DEBUG
|
|
|
|
GstFFMpegVidEncClass *oclass =
|
|
|
|
(GstFFMpegVidEncClass *) (G_OBJECT_GET_CLASS (ffmpegenc));
|
|
|
|
GST_ERROR_OBJECT (ffmpegenc,
|
2012-06-14 14:29:05 +00:00
|
|
|
"avenc_%s: failed to encode buffer", oclass->in_plugin->name);
|
2012-04-24 09:31:27 +00:00
|
|
|
#endif /* GST_DISABLE_GST_DEBUG */
|
2014-03-22 16:10:24 +00:00
|
|
|
/* avoid frame (and ts etc) piling up */
|
|
|
|
return gst_video_encoder_finish_frame (encoder, frame);
|
2012-04-24 09:31:27 +00:00
|
|
|
}
|
2012-04-07 08:36:04 +00:00
|
|
|
}
|
|
|
|
|
2013-08-21 12:40:03 +00:00
|
|
|
static GstFlowReturn
|
2012-04-07 09:14:45 +00:00
|
|
|
gst_ffmpegvidenc_flush_buffers (GstFFMpegVidEnc * ffmpegenc, gboolean send)
|
2012-04-07 08:36:04 +00:00
|
|
|
{
|
2012-04-24 09:31:27 +00:00
|
|
|
GstVideoCodecFrame *frame;
|
2013-08-21 12:40:03 +00:00
|
|
|
GstFlowReturn flow_ret = GST_FLOW_OK;
|
2012-04-24 09:31:27 +00:00
|
|
|
GstBuffer *outbuf;
|
2014-01-03 15:24:28 +00:00
|
|
|
gint ret;
|
2015-06-28 14:30:54 +00:00
|
|
|
AVPacket *pkt;
|
2014-01-03 15:24:28 +00:00
|
|
|
int have_data = 0;
|
2012-04-07 08:36:04 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (ffmpegenc, "flushing buffers with sending %d", send);
|
|
|
|
|
|
|
|
/* no need to empty codec if there is none */
|
|
|
|
if (!ffmpegenc->opened)
|
2013-08-21 12:40:03 +00:00
|
|
|
goto done;
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2012-04-24 09:31:27 +00:00
|
|
|
while ((frame =
|
|
|
|
gst_video_encoder_get_oldest_frame (GST_VIDEO_ENCODER (ffmpegenc)))) {
|
2015-06-28 14:30:54 +00:00
|
|
|
pkt = g_slice_new0 (AVPacket);
|
2014-01-03 15:24:28 +00:00
|
|
|
have_data = 0;
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2015-06-28 14:30:54 +00:00
|
|
|
ret = avcodec_encode_video2 (ffmpegenc->context, pkt, NULL, &have_data);
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2014-01-03 15:24:28 +00:00
|
|
|
if (ret < 0) { /* there should be something, notify and give up */
|
2012-04-07 08:36:04 +00:00
|
|
|
#ifndef GST_DISABLE_GST_DEBUG
|
2012-04-07 09:14:45 +00:00
|
|
|
GstFFMpegVidEncClass *oclass =
|
|
|
|
(GstFFMpegVidEncClass *) (G_OBJECT_GET_CLASS (ffmpegenc));
|
2012-04-07 08:36:04 +00:00
|
|
|
GST_WARNING_OBJECT (ffmpegenc,
|
2012-06-14 14:29:05 +00:00
|
|
|
"avenc_%s: failed to flush buffer", oclass->in_plugin->name);
|
2012-04-07 08:36:04 +00:00
|
|
|
#endif /* GST_DISABLE_GST_DEBUG */
|
2015-06-28 14:54:35 +00:00
|
|
|
g_slice_free (AVPacket, pkt);
|
2012-07-23 08:40:14 +00:00
|
|
|
gst_video_codec_frame_unref (frame);
|
2012-04-07 08:36:04 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* save stats info if there is some as well as a stats file */
|
|
|
|
if (ffmpegenc->file && ffmpegenc->context->stats_out)
|
|
|
|
if (fprintf (ffmpegenc->file, "%s", ffmpegenc->context->stats_out) < 0)
|
|
|
|
GST_ELEMENT_ERROR (ffmpegenc, RESOURCE, WRITE,
|
|
|
|
(("Could not write to file \"%s\"."), ffmpegenc->filename),
|
|
|
|
GST_ERROR_SYSTEM);
|
|
|
|
|
2014-01-03 15:24:28 +00:00
|
|
|
if (send && have_data) {
|
2015-06-28 14:30:54 +00:00
|
|
|
outbuf =
|
2015-06-28 14:32:02 +00:00
|
|
|
gst_buffer_new_wrapped_full (GST_MEMORY_FLAG_READONLY, pkt->data,
|
2015-10-03 17:14:05 +00:00
|
|
|
pkt->size, 0, pkt->size, pkt, gst_ffmpegvidenc_free_avpacket);
|
2014-01-03 15:24:28 +00:00
|
|
|
frame->output_buffer = outbuf;
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2016-01-19 07:36:01 +00:00
|
|
|
if (pkt->flags & AV_PKT_FLAG_KEY)
|
2012-11-20 10:53:52 +00:00
|
|
|
GST_VIDEO_CODEC_FRAME_SET_SYNC_POINT (frame);
|
2016-01-19 07:36:01 +00:00
|
|
|
else
|
|
|
|
GST_VIDEO_CODEC_FRAME_UNSET_SYNC_POINT (frame);
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2013-08-21 12:40:03 +00:00
|
|
|
flow_ret =
|
|
|
|
gst_video_encoder_finish_frame (GST_VIDEO_ENCODER (ffmpegenc), frame);
|
2012-11-20 10:53:52 +00:00
|
|
|
} else {
|
2014-02-01 13:40:24 +00:00
|
|
|
/* no frame attached, so will be skipped and removed from frame list */
|
|
|
|
gst_video_encoder_finish_frame (GST_VIDEO_ENCODER (ffmpegenc), frame);
|
2012-11-20 10:53:52 +00:00
|
|
|
}
|
2012-04-07 08:36:04 +00:00
|
|
|
}
|
2013-08-21 12:40:03 +00:00
|
|
|
|
|
|
|
done:
|
|
|
|
|
|
|
|
return flow_ret;
|
2012-04-07 08:36:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2012-04-07 09:14:45 +00:00
|
|
|
gst_ffmpegvidenc_set_property (GObject * object,
|
2012-04-07 08:36:04 +00:00
|
|
|
guint prop_id, const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2012-04-07 09:14:45 +00:00
|
|
|
GstFFMpegVidEnc *ffmpegenc;
|
2012-04-07 08:36:04 +00:00
|
|
|
|
|
|
|
/* Get a pointer of the right type. */
|
2012-04-07 09:14:45 +00:00
|
|
|
ffmpegenc = (GstFFMpegVidEnc *) (object);
|
2012-04-07 08:36:04 +00:00
|
|
|
|
|
|
|
if (ffmpegenc->opened) {
|
|
|
|
GST_WARNING_OBJECT (ffmpegenc,
|
|
|
|
"Can't change properties once decoder is setup !");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check the argument id to see which argument we're setting. */
|
|
|
|
switch (prop_id) {
|
2012-11-19 16:08:23 +00:00
|
|
|
case PROP_BIT_RATE:
|
2012-06-14 14:29:05 +00:00
|
|
|
ffmpegenc->bitrate = g_value_get_int (value);
|
2012-04-07 08:36:04 +00:00
|
|
|
break;
|
2012-11-19 16:08:23 +00:00
|
|
|
case PROP_GOP_SIZE:
|
2012-04-07 08:36:04 +00:00
|
|
|
ffmpegenc->gop_size = g_value_get_int (value);
|
|
|
|
break;
|
2012-11-19 16:08:23 +00:00
|
|
|
case PROP_ME_METHOD:
|
2012-04-07 08:36:04 +00:00
|
|
|
ffmpegenc->me_method = g_value_get_enum (value);
|
|
|
|
break;
|
2012-11-19 16:08:23 +00:00
|
|
|
case PROP_BUFSIZE:
|
2012-04-07 08:36:04 +00:00
|
|
|
break;
|
2012-11-19 16:08:23 +00:00
|
|
|
case PROP_RTP_PAYLOAD_SIZE:
|
2012-06-14 14:29:05 +00:00
|
|
|
ffmpegenc->rtp_payload_size = g_value_get_int (value);
|
2012-04-07 08:36:04 +00:00
|
|
|
break;
|
2013-10-14 20:50:57 +00:00
|
|
|
case PROP_COMPLIANCE:
|
|
|
|
ffmpegenc->compliance = g_value_get_enum (value);
|
|
|
|
break;
|
2014-03-18 05:26:52 +00:00
|
|
|
case PROP_MAX_THREADS:
|
|
|
|
ffmpegenc->max_threads = g_value_get_int (value);
|
|
|
|
break;
|
2012-04-07 08:36:04 +00:00
|
|
|
default:
|
|
|
|
if (!gst_ffmpeg_cfg_set_property (object, value, pspec))
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The set function is simply the inverse of the get fuction. */
|
|
|
|
static void
|
2012-04-07 09:14:45 +00:00
|
|
|
gst_ffmpegvidenc_get_property (GObject * object,
|
2012-04-07 08:36:04 +00:00
|
|
|
guint prop_id, GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2012-04-07 09:14:45 +00:00
|
|
|
GstFFMpegVidEnc *ffmpegenc;
|
2012-04-07 08:36:04 +00:00
|
|
|
|
|
|
|
/* It's not null if we got it, but it might not be ours */
|
2012-04-07 09:14:45 +00:00
|
|
|
ffmpegenc = (GstFFMpegVidEnc *) (object);
|
2012-04-07 08:36:04 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
2012-11-19 16:08:23 +00:00
|
|
|
case PROP_BIT_RATE:
|
2012-06-14 14:29:05 +00:00
|
|
|
g_value_set_int (value, ffmpegenc->bitrate);
|
2012-04-07 08:36:04 +00:00
|
|
|
break;
|
2012-11-19 16:08:23 +00:00
|
|
|
case PROP_GOP_SIZE:
|
2012-04-07 08:36:04 +00:00
|
|
|
g_value_set_int (value, ffmpegenc->gop_size);
|
|
|
|
break;
|
2012-11-19 16:08:23 +00:00
|
|
|
case PROP_ME_METHOD:
|
2012-04-07 08:36:04 +00:00
|
|
|
g_value_set_enum (value, ffmpegenc->me_method);
|
|
|
|
break;
|
2012-11-19 16:08:23 +00:00
|
|
|
case PROP_BUFSIZE:
|
2012-06-14 14:29:05 +00:00
|
|
|
g_value_set_int (value, ffmpegenc->buffer_size);
|
2012-04-07 08:36:04 +00:00
|
|
|
break;
|
2012-11-19 16:08:23 +00:00
|
|
|
case PROP_RTP_PAYLOAD_SIZE:
|
2012-06-14 14:29:05 +00:00
|
|
|
g_value_set_int (value, ffmpegenc->rtp_payload_size);
|
2012-04-07 08:36:04 +00:00
|
|
|
break;
|
2013-10-14 20:50:57 +00:00
|
|
|
case PROP_COMPLIANCE:
|
|
|
|
g_value_set_enum (value, ffmpegenc->compliance);
|
|
|
|
break;
|
2014-03-18 05:26:52 +00:00
|
|
|
case PROP_MAX_THREADS:
|
|
|
|
g_value_set_int (value, ffmpegenc->max_threads);
|
|
|
|
break;
|
2012-04-07 08:36:04 +00:00
|
|
|
default:
|
|
|
|
if (!gst_ffmpeg_cfg_get_property (object, value, pspec))
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-20 10:56:57 +00:00
|
|
|
static gboolean
|
2013-08-15 13:51:52 +00:00
|
|
|
gst_ffmpegvidenc_flush (GstVideoEncoder * encoder)
|
2012-11-20 10:56:57 +00:00
|
|
|
{
|
|
|
|
GstFFMpegVidEnc *ffmpegenc = (GstFFMpegVidEnc *) encoder;
|
|
|
|
|
2013-08-15 13:51:52 +00:00
|
|
|
if (ffmpegenc->opened)
|
2012-11-20 10:56:57 +00:00
|
|
|
avcodec_flush_buffers (ffmpegenc->context);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-08-29 14:53:28 +00:00
|
|
|
static gboolean
|
|
|
|
gst_ffmpegvidenc_start (GstVideoEncoder * encoder)
|
|
|
|
{
|
|
|
|
GstFFMpegVidEnc *ffmpegenc = (GstFFMpegVidEnc *) encoder;
|
|
|
|
GstFFMpegVidEncClass *oclass =
|
|
|
|
(GstFFMpegVidEncClass *) G_OBJECT_GET_CLASS (ffmpegenc);
|
|
|
|
|
|
|
|
/* close old session */
|
2014-01-15 09:02:33 +00:00
|
|
|
gst_ffmpeg_avcodec_close (ffmpegenc->context);
|
2013-08-29 14:53:28 +00:00
|
|
|
if (avcodec_get_context_defaults3 (ffmpegenc->context, oclass->in_plugin) < 0) {
|
|
|
|
GST_DEBUG_OBJECT (ffmpegenc, "Failed to set context defaults");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-04-24 09:31:27 +00:00
|
|
|
static gboolean
|
|
|
|
gst_ffmpegvidenc_stop (GstVideoEncoder * encoder)
|
2012-04-07 08:36:04 +00:00
|
|
|
{
|
2012-04-24 09:31:27 +00:00
|
|
|
GstFFMpegVidEnc *ffmpegenc = (GstFFMpegVidEnc *) encoder;
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2012-04-24 09:31:27 +00:00
|
|
|
gst_ffmpegvidenc_flush_buffers (ffmpegenc, FALSE);
|
2012-12-17 15:35:36 +00:00
|
|
|
gst_ffmpeg_avcodec_close (ffmpegenc->context);
|
|
|
|
ffmpegenc->opened = FALSE;
|
|
|
|
|
2012-04-24 09:31:27 +00:00
|
|
|
if (ffmpegenc->file) {
|
|
|
|
fclose (ffmpegenc->file);
|
|
|
|
ffmpegenc->file = NULL;
|
|
|
|
}
|
2013-12-07 11:10:13 +00:00
|
|
|
if (ffmpegenc->input_state) {
|
|
|
|
gst_video_codec_state_unref (ffmpegenc->input_state);
|
|
|
|
ffmpegenc->input_state = NULL;
|
|
|
|
}
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2012-04-24 09:31:27 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_ffmpegvidenc_finish (GstVideoEncoder * encoder)
|
|
|
|
{
|
|
|
|
GstFFMpegVidEnc *ffmpegenc = (GstFFMpegVidEnc *) encoder;
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2013-08-21 12:40:03 +00:00
|
|
|
return gst_ffmpegvidenc_flush_buffers (ffmpegenc, TRUE);
|
2012-04-07 08:36:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2012-04-07 09:14:45 +00:00
|
|
|
gst_ffmpegvidenc_register (GstPlugin * plugin)
|
2012-04-07 08:36:04 +00:00
|
|
|
{
|
|
|
|
GTypeInfo typeinfo = {
|
2012-04-07 09:14:45 +00:00
|
|
|
sizeof (GstFFMpegVidEncClass),
|
|
|
|
(GBaseInitFunc) gst_ffmpegvidenc_base_init,
|
2012-04-07 08:36:04 +00:00
|
|
|
NULL,
|
2012-04-07 09:14:45 +00:00
|
|
|
(GClassInitFunc) gst_ffmpegvidenc_class_init,
|
2012-04-07 08:36:04 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2012-04-07 09:14:45 +00:00
|
|
|
sizeof (GstFFMpegVidEnc),
|
2012-04-07 08:36:04 +00:00
|
|
|
0,
|
2012-04-07 09:14:45 +00:00
|
|
|
(GInstanceInitFunc) gst_ffmpegvidenc_init,
|
2012-04-07 08:36:04 +00:00
|
|
|
};
|
|
|
|
GType type;
|
|
|
|
AVCodec *in_plugin;
|
|
|
|
|
|
|
|
|
|
|
|
GST_LOG ("Registering encoders");
|
|
|
|
|
|
|
|
/* build global ffmpeg param/property info */
|
|
|
|
gst_ffmpeg_cfg_init ();
|
|
|
|
|
|
|
|
in_plugin = av_codec_next (NULL);
|
|
|
|
while (in_plugin) {
|
|
|
|
gchar *type_name;
|
|
|
|
|
|
|
|
/* Skip non-AV codecs */
|
2012-04-07 09:14:45 +00:00
|
|
|
if (in_plugin->type != AVMEDIA_TYPE_VIDEO)
|
2012-04-07 08:36:04 +00:00
|
|
|
goto next;
|
|
|
|
|
|
|
|
/* no quasi codecs, please */
|
2013-05-06 22:56:22 +00:00
|
|
|
if (in_plugin->id == AV_CODEC_ID_RAWVIDEO ||
|
|
|
|
in_plugin->id == AV_CODEC_ID_V210 ||
|
|
|
|
in_plugin->id == AV_CODEC_ID_V210X ||
|
2016-07-22 11:54:21 +00:00
|
|
|
in_plugin->id == AV_CODEC_ID_V308 ||
|
|
|
|
in_plugin->id == AV_CODEC_ID_V408 ||
|
|
|
|
in_plugin->id == AV_CODEC_ID_V410 ||
|
2013-05-06 22:56:22 +00:00
|
|
|
in_plugin->id == AV_CODEC_ID_R210
|
2016-07-22 11:54:21 +00:00
|
|
|
|| in_plugin->id == AV_CODEC_ID_AYUV
|
|
|
|
|| in_plugin->id == AV_CODEC_ID_Y41P
|
|
|
|
|| in_plugin->id == AV_CODEC_ID_012V
|
|
|
|
|| in_plugin->id == AV_CODEC_ID_YUV4
|
2016-09-02 15:55:46 +00:00
|
|
|
#if AV_VERSION_INT (LIBAVCODEC_VERSION_MAJOR, LIBAVCODEC_VERSION_MINOR, LIBAVCODEC_VERSION_MICRO) >= \
|
|
|
|
AV_VERSION_INT (57,4,0)
|
|
|
|
|| in_plugin->id == AV_CODEC_ID_WRAPPED_AVFRAME
|
|
|
|
#endif
|
|
|
|
|| in_plugin->id == AV_CODEC_ID_ZLIB) {
|
2012-04-07 08:36:04 +00:00
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No encoders depending on external libraries (we don't build them, but
|
|
|
|
* people who build against an external ffmpeg might have them.
|
|
|
|
* We have native gstreamer plugins for all of those libraries anyway. */
|
|
|
|
if (!strncmp (in_plugin->name, "lib", 3)) {
|
|
|
|
GST_DEBUG
|
|
|
|
("Not using external library encoder %s. Use the gstreamer-native ones instead.",
|
|
|
|
in_plugin->name);
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
|
2016-07-22 11:42:59 +00:00
|
|
|
if (strstr (in_plugin->name, "vaapi")) {
|
|
|
|
GST_DEBUG
|
|
|
|
("Ignoring VAAPI encoder %s. We can't handle this outside of ffmpeg",
|
|
|
|
in_plugin->name);
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
|
2016-11-11 16:03:00 +00:00
|
|
|
if (strstr (in_plugin->name, "nvenc")) {
|
2016-07-22 11:42:59 +00:00
|
|
|
GST_DEBUG
|
|
|
|
("Ignoring nvenc encoder %s. We can't handle this outside of ffmpeg",
|
|
|
|
in_plugin->name);
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
|
2016-11-11 16:03:00 +00:00
|
|
|
if (g_str_has_suffix (in_plugin->name, "_qsv")) {
|
|
|
|
GST_DEBUG
|
|
|
|
("Ignoring qsv encoder %s. We can't handle this outside of ffmpeg",
|
|
|
|
in_plugin->name);
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
|
2012-09-30 15:25:29 +00:00
|
|
|
/* only video encoders */
|
2012-12-05 09:52:34 +00:00
|
|
|
if (!av_codec_is_encoder (in_plugin)
|
|
|
|
|| in_plugin->type != AVMEDIA_TYPE_VIDEO)
|
2012-04-07 08:36:04 +00:00
|
|
|
goto next;
|
|
|
|
|
|
|
|
/* FIXME : We should have a method to know cheaply whether we have a mapping
|
|
|
|
* for the given plugin or not */
|
|
|
|
|
|
|
|
GST_DEBUG ("Trying plugin %s [%s]", in_plugin->name, in_plugin->long_name);
|
|
|
|
|
|
|
|
/* no codecs for which we're GUARANTEED to have better alternatives */
|
2012-04-24 09:31:27 +00:00
|
|
|
if (!strcmp (in_plugin->name, "gif")) {
|
2012-04-07 08:36:04 +00:00
|
|
|
GST_LOG ("Ignoring encoder %s", in_plugin->name);
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* construct the type */
|
2012-06-14 14:29:05 +00:00
|
|
|
type_name = g_strdup_printf ("avenc_%s", in_plugin->name);
|
2012-04-07 08:36:04 +00:00
|
|
|
|
|
|
|
type = g_type_from_name (type_name);
|
|
|
|
|
|
|
|
if (!type) {
|
|
|
|
|
|
|
|
/* create the glib type now */
|
2012-04-24 09:31:27 +00:00
|
|
|
type =
|
|
|
|
g_type_register_static (GST_TYPE_VIDEO_ENCODER, type_name, &typeinfo,
|
|
|
|
0);
|
2012-04-07 08:36:04 +00:00
|
|
|
g_type_set_qdata (type, GST_FFENC_PARAMS_QDATA, (gpointer) in_plugin);
|
|
|
|
|
|
|
|
{
|
|
|
|
static const GInterfaceInfo preset_info = {
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
g_type_add_interface_static (type, GST_TYPE_PRESET, &preset_info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gst_element_register (plugin, type_name, GST_RANK_SECONDARY, type)) {
|
|
|
|
g_free (type_name);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (type_name);
|
|
|
|
|
|
|
|
next:
|
|
|
|
in_plugin = av_codec_next (in_plugin);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_LOG ("Finished registering encoders");
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|