2 * Copyright (C) <2009> Edward Hervey <bilboed@bilboed.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
20 #ifndef __GST_FFMPEG_UTILS_H__
21 #define __GST_FFMPEG_UTILS_H__
27 #include <libavcodec/avcodec.h>
28 #include <libavutil/mathematics.h>
32 /* Introduced since ffmpeg version 4.3
34 * Note: Not all ffmpeg encoders seem to be reusable after flushing/draining.
35 * So if ffmpeg encoder doesn't support it, we should reopen encoding session.
37 * Before ffmpeg 4.3, avcodec_flush_buffers() was implemented in
38 * libavcodec/decodec.c but it was moved to libavcodec/utils.c and it would be
39 * accepted if encoder supports AV_CODEC_CAP_ENCODER_FLUSH flag.
40 * That implies that avcodec_flush_buffers() wasn't intended to be working
41 * properly for encoders.
43 #ifndef AV_CODEC_CAP_ENCODER_FLUSH
45 * This encoder can be flushed using avcodec_flush_buffers(). If this flag is
46 * not set, the encoder must be closed and reopened to ensure that no frames
49 #define AV_CODEC_CAP_ENCODER_FLUSH (1 << 21)
53 *Get the size of an picture
56 gst_ffmpeg_avpicture_get_size (int pix_fmt, int width, int height);
59 * Fill in pointers in an AVFrame, aligned by 4 (required by X).
63 gst_ffmpeg_avpicture_fill (AVFrame * picture,
65 enum AVPixelFormat pix_fmt,
70 * Convert from/to a GStreamer <-> FFMpeg timestamp.
73 gst_ffmpeg_time_ff_to_gst (gint64 pts, AVRational base)
77 if (pts == AV_NOPTS_VALUE){
78 out = GST_CLOCK_TIME_NONE;
80 AVRational bq = { 1, GST_SECOND };
81 out = av_rescale_q (pts, base, bq);
88 gst_ffmpeg_time_gst_to_ff (guint64 time, AVRational base)
92 if (!GST_CLOCK_TIME_IS_VALID (time) || base.num == 0) {
95 AVRational bq = { 1, GST_SECOND };
96 out = av_rescale_q (time, bq, base);
103 gst_ffmpeg_init_pix_fmt_info(void);
106 gst_ffmpeg_auto_max_threads(void);
109 gst_ffmpeg_get_codecid_longname (enum AVCodecID codec_id);
112 av_smp_format_depth(enum AVSampleFormat smp_fmt);
115 new_aligned_buffer (gint size);
119 GST_AV_CODEC_COMPLIANCE_AUTO = G_MAXINT,
120 GST_AV_CODEC_COMPLIANCE_VERY_STRICT = FF_COMPLIANCE_VERY_STRICT,
121 GST_AV_CODEC_COMPLIANCE_STRICT = FF_COMPLIANCE_STRICT,
122 GST_AV_CODEC_COMPLIANCE_NORMAL = FF_COMPLIANCE_NORMAL,
123 GST_AV_CODEC_COMPLIANCE_UNOFFICIAL = FF_COMPLIANCE_UNOFFICIAL,
124 GST_AV_CODEC_COMPLIANCE_EXPERIMENTAL = FF_COMPLIANCE_EXPERIMENTAL,
125 } GstAvCodecCompliance;
127 #define GST_TYPE_AV_CODEC_COMPLIANCE (gst_av_codec_compliance_get_type())
128 GType gst_av_codec_compliance_get_type (void);
131 #endif /* __GST_FFMPEG_UTILS_H__ */