avmux: Fix crash when muxer doesn't get codecid

gst_ffmpeg_formatid_get_codecids from gst_ffmpegmux_base_init to gst_ffmpegmux_base_init

FFmpeg 7.0 included new muxer rcwt for Raw Captions with Time
(RCWT). Commit [1].  GStreamer couldn't get sink caps for muxer it.

Calling gst_ffmpeg_formatid_get_codecids in gst_ffmpegmux_register to
avoid create muxer without pad templates.

[1] https://github.com/FFmpeg/FFmpeg/commit/3525544e48

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/7168>
This commit is contained in:
Ruben Gonzalez 2024-07-12 17:09:15 +02:00 committed by GStreamer Marge Bot
parent 13034cc63f
commit 3e4c8f1b16
3 changed files with 12 additions and 5 deletions

View file

@ -3884,7 +3884,7 @@ gst_ffmpeg_formatid_to_caps (const gchar * format_name)
gboolean gboolean
gst_ffmpeg_formatid_get_codecids (const gchar * format_name, gst_ffmpeg_formatid_get_codecids (const gchar * format_name,
enum AVCodecID **video_codec_list, enum AVCodecID **audio_codec_list, enum AVCodecID **video_codec_list, enum AVCodecID **audio_codec_list,
AVOutputFormat * plugin) const AVOutputFormat * plugin)
{ {
static enum AVCodecID tmp_vlist[] = { static enum AVCodecID tmp_vlist[] = {
AV_CODEC_ID_NONE, AV_CODEC_ID_NONE,

View file

@ -123,7 +123,7 @@ gboolean
gst_ffmpeg_formatid_get_codecids (const gchar *format_name, gst_ffmpeg_formatid_get_codecids (const gchar *format_name,
enum AVCodecID ** video_codec_list, enum AVCodecID ** video_codec_list,
enum AVCodecID ** audio_codec_list, enum AVCodecID ** audio_codec_list,
AVOutputFormat * plugin); const AVOutputFormat * plugin);
#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(57, 28, 100) #if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(57, 28, 100)
gboolean gboolean

View file

@ -69,7 +69,7 @@ struct _GstFFMpegMuxClass
{ {
GstElementClass parent_class; GstElementClass parent_class;
AVOutputFormat *in_plugin; const AVOutputFormat *in_plugin;
}; };
#define GST_TYPE_FFMPEGMUX \ #define GST_TYPE_FFMPEGMUX \
@ -192,7 +192,7 @@ gst_ffmpegmux_base_init (gpointer g_class)
GstFFMpegMuxClass *klass = (GstFFMpegMuxClass *) g_class; GstFFMpegMuxClass *klass = (GstFFMpegMuxClass *) g_class;
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
GstPadTemplate *videosinktempl, *audiosinktempl, *srctempl; GstPadTemplate *videosinktempl, *audiosinktempl, *srctempl;
AVOutputFormat *in_plugin; const AVOutputFormat *in_plugin;
GstCaps *srccaps, *audiosinkcaps, *videosinkcaps; GstCaps *srccaps, *audiosinkcaps, *videosinkcaps;
enum AVCodecID *video_ids = NULL, *audio_ids = NULL; enum AVCodecID *video_ids = NULL, *audio_ids = NULL;
gchar *longname, *description, *name; gchar *longname, *description, *name;
@ -332,7 +332,7 @@ gst_ffmpegmux_init (GstFFMpegMux * ffmpegmux, GstFFMpegMuxClass * g_class)
(GstCollectPadsFunction) gst_ffmpegmux_collected, ffmpegmux); (GstCollectPadsFunction) gst_ffmpegmux_collected, ffmpegmux);
ffmpegmux->context = avformat_alloc_context (); ffmpegmux->context = avformat_alloc_context ();
ffmpegmux->context->oformat = oclass->in_plugin; ffmpegmux->context->oformat = (struct AVOutputFormat *) oclass->in_plugin;
ffmpegmux->context->nb_streams = 0; ffmpegmux->context->nb_streams = 0;
ffmpegmux->opened = FALSE; ffmpegmux->opened = FALSE;
@ -872,6 +872,7 @@ gst_ffmpegmux_register (GstPlugin * plugin)
GType type; GType type;
const AVOutputFormat *in_plugin; const AVOutputFormat *in_plugin;
void *i = 0; void *i = 0;
enum AVCodecID *video_ids = NULL, *audio_ids = NULL;
GST_LOG ("Registering muxers"); GST_LOG ("Registering muxers");
@ -925,6 +926,12 @@ gst_ffmpegmux_register (GstPlugin * plugin)
} }
} }
if (!gst_ffmpeg_formatid_get_codecids (in_plugin->name, &video_ids,
&audio_ids, in_plugin)) {
GST_LOG ("Ignoring muxer %s because no sink caps", in_plugin->name);
continue;
}
if (gst_ffmpegmux_get_replacement (in_plugin->name)) if (gst_ffmpegmux_get_replacement (in_plugin->name))
rank = GST_RANK_NONE; rank = GST_RANK_NONE;