2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
4 * Copyright (c) 2002-2004 Ronald Bultje <rbultje@ronald.bitfreak.net>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
29 #include <libavcodec/avcodec.h>
30 #include <libavutil/channel_layout.h>
33 #include "gstavcodecmap.h"
35 #include <gst/video/video.h>
36 #include <gst/audio/audio.h>
37 #include <gst/pbutils/codec-utils.h>
39 /* IMPORTANT: Keep this sorted by the ffmpeg channel masks */
43 GstAudioChannelPosition gst;
44 } _ff_to_gst_layout[] = {
46 AV_CH_FRONT_LEFT, GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT}, {
47 AV_CH_FRONT_RIGHT, GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT}, {
48 AV_CH_FRONT_CENTER, GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER}, {
49 AV_CH_LOW_FREQUENCY, GST_AUDIO_CHANNEL_POSITION_LFE1}, {
50 AV_CH_BACK_LEFT, GST_AUDIO_CHANNEL_POSITION_REAR_LEFT}, {
51 AV_CH_BACK_RIGHT, GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT}, {
52 AV_CH_FRONT_LEFT_OF_CENTER, GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER}, {
53 AV_CH_FRONT_RIGHT_OF_CENTER,
54 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER}, {
55 AV_CH_BACK_CENTER, GST_AUDIO_CHANNEL_POSITION_REAR_CENTER}, {
56 AV_CH_SIDE_LEFT, GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT}, {
57 AV_CH_SIDE_RIGHT, GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT}, {
58 AV_CH_TOP_CENTER, GST_AUDIO_CHANNEL_POSITION_TOP_CENTER}, {
59 AV_CH_TOP_FRONT_LEFT, GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_LEFT}, {
60 AV_CH_TOP_FRONT_CENTER, GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_CENTER}, {
61 AV_CH_TOP_FRONT_RIGHT, GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_RIGHT}, {
62 AV_CH_TOP_BACK_LEFT, GST_AUDIO_CHANNEL_POSITION_TOP_REAR_LEFT}, {
63 AV_CH_TOP_BACK_CENTER, GST_AUDIO_CHANNEL_POSITION_TOP_REAR_CENTER}, {
64 AV_CH_TOP_BACK_RIGHT, GST_AUDIO_CHANNEL_POSITION_TOP_REAR_RIGHT}, {
65 AV_CH_STEREO_LEFT, GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT}, {
66 AV_CH_STEREO_RIGHT, GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT}
70 gst_ffmpeg_compliance_get_type (void)
72 static GType ffmpeg_compliance_type = 0;
73 static const GEnumValue compliance_types[] = {
74 {GST_FFMPEG_VERY_STRICT, "Strictly conform to older spec",
76 {GST_FFMPEG_STRICT, "Strictly conform to current spec", "strict"},
77 {GST_FFMPEG_NORMAL, "Normal behavior", "normal"},
78 {GST_FFMPEG_UNOFFICIAL, "Allow unofficial extensions", "unofficial"},
79 {GST_FFMPEG_EXPERIMENTAL, "Allow nonstandardized experimental things",
84 if (!ffmpeg_compliance_type) {
85 ffmpeg_compliance_type =
86 g_enum_register_static ("GstFFMpegCompliance", compliance_types);
88 return ffmpeg_compliance_type;
92 gst_ffmpeg_channel_positions_to_layout (GstAudioChannelPosition * pos,
97 gint channels_found = 0;
102 if (channels == 1 && pos[0] == GST_AUDIO_CHANNEL_POSITION_MONO)
103 return AV_CH_LAYOUT_MONO;
105 for (i = 0; i < channels; i++) {
106 for (j = 0; j < G_N_ELEMENTS (_ff_to_gst_layout); j++) {
107 if (_ff_to_gst_layout[j].gst == pos[i]) {
108 ret |= _ff_to_gst_layout[j].ff;
115 if (channels_found != channels)
121 gst_ffmpeg_channel_layout_to_gst (guint64 channel_layout, gint channels,
122 GstAudioChannelPosition * pos)
125 gboolean none_layout = FALSE;
127 if (channel_layout == 0) {
128 nchannels = channels;
133 /* Special path for mono, as AV_CH_LAYOUT_MONO is the same
134 * as FRONT_CENTER but we distinguish between the two in
137 if (channels == 1 && channel_layout == AV_CH_LAYOUT_MONO) {
138 pos[0] = GST_AUDIO_CHANNEL_POSITION_MONO;
142 for (i = 0; i < 64; i++) {
143 if ((channel_layout & (G_GUINT64_CONSTANT (1) << i)) != 0) {
148 if (nchannels != channels) {
149 GST_ERROR ("Number of channels is different (%u != %u)", channels,
151 nchannels = channels;
155 for (i = 0, j = 0; i < G_N_ELEMENTS (_ff_to_gst_layout); i++) {
156 if ((channel_layout & _ff_to_gst_layout[i].ff) != 0) {
157 pos[j++] = _ff_to_gst_layout[i].gst;
159 if (_ff_to_gst_layout[i].gst == GST_AUDIO_CHANNEL_POSITION_NONE)
164 if (j != nchannels) {
166 ("Unknown channels in channel layout - assuming NONE layout");
173 && !gst_audio_check_valid_channel_positions (pos, nchannels, FALSE)) {
174 GST_ERROR ("Invalid channel layout %" G_GUINT64_FORMAT
175 " - assuming NONE layout", channel_layout);
180 if (nchannels == 1) {
181 pos[0] = GST_AUDIO_CHANNEL_POSITION_MONO;
182 } else if (nchannels == 2) {
183 pos[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT;
184 pos[1] = GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT;
188 for (i = 0; i < nchannels; i++)
189 pos[i] = GST_AUDIO_CHANNEL_POSITION_NONE;
197 _gst_value_list_contains (const GValue * list, const GValue * value)
202 n = gst_value_list_get_size (list);
203 for (i = 0; i < n; i++) {
204 tmp = gst_value_list_get_value (list, i);
205 if (gst_value_compare (value, tmp) == GST_VALUE_EQUAL)
213 gst_ffmpeg_video_set_pix_fmts (GstCaps * caps, const enum AVPixelFormat *fmts)
217 GstVideoFormat format;
219 if (!fmts || fmts[0] == -1) {
222 g_value_init (&va, GST_TYPE_LIST);
223 g_value_init (&v, G_TYPE_STRING);
224 for (i = 0; i <= AV_PIX_FMT_NB; i++) {
225 format = gst_ffmpeg_pixfmt_to_videoformat (i);
226 if (format == GST_VIDEO_FORMAT_UNKNOWN)
228 g_value_set_string (&v, gst_video_format_to_string (format));
229 gst_value_list_append_value (&va, &v);
231 gst_caps_set_value (caps, "format", &va);
237 /* Only a single format */
238 g_value_init (&va, GST_TYPE_LIST);
239 g_value_init (&v, G_TYPE_STRING);
240 while (*fmts != -1) {
241 format = gst_ffmpeg_pixfmt_to_videoformat (*fmts);
242 if (format != GST_VIDEO_FORMAT_UNKNOWN) {
243 g_value_set_string (&v, gst_video_format_to_string (format));
244 /* Only append values we don't have yet */
245 if (!_gst_value_list_contains (&va, &v))
246 gst_value_list_append_value (&va, &v);
250 if (gst_value_list_get_size (&va) == 1) {
251 /* The single value is still in v */
252 gst_caps_set_value (caps, "format", &v);
253 } else if (gst_value_list_get_size (&va) > 1) {
254 gst_caps_set_value (caps, "format", &va);
260 /* this macro makes a caps width fixed or unfixed width/height
261 * properties depending on whether we've got a context.
263 * See below for why we use this.
265 * We should actually do this stuff at the end, like in riff-media.c,
266 * but I'm too lazy today. Maybe later.
269 gst_ff_vid_caps_new (AVCodecContext * context, AVCodec * codec,
270 enum AVCodecID codec_id, gboolean encode, const char *mimetype,
271 const char *fieldname, ...)
273 GstCaps *caps = NULL;
277 GST_LOG ("context:%p, codec_id:%d, mimetype:%s", context, codec_id, mimetype);
279 /* fixed, non probing context */
280 if (context != NULL && context->width != -1) {
283 caps = gst_caps_new_simple (mimetype,
284 "width", G_TYPE_INT, context->width,
285 "height", G_TYPE_INT, context->height, NULL);
287 num = context->time_base.den / context->ticks_per_frame;
288 denom = context->time_base.num;
291 GST_LOG ("invalid framerate: %d/0, -> %d/1", num, num);
294 if (gst_util_fraction_compare (num, denom, 1000, 1) > 0) {
295 GST_LOG ("excessive framerate: %d/%d, -> 0/1", num, denom);
299 GST_LOG ("setting framerate: %d/%d", num, denom);
300 gst_caps_set_simple (caps,
301 "framerate", GST_TYPE_FRACTION, num, denom, NULL);
303 /* so we are after restricted caps in this case */
305 case AV_CODEC_ID_H261:
307 caps = gst_caps_new_simple (mimetype,
308 "width", G_TYPE_INT, 352,
309 "height", G_TYPE_INT, 288,
310 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
311 gst_caps_append (caps, gst_caps_new_simple (mimetype,
312 "width", G_TYPE_INT, 176,
313 "height", G_TYPE_INT, 144,
314 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL));
317 case AV_CODEC_ID_H263:
319 /* 128x96, 176x144, 352x288, 704x576, and 1408x1152. slightly reordered
320 * because we want automatic negotiation to go as close to 320x240 as
322 const static gint widths[] = { 352, 704, 176, 1408, 128 };
323 const static gint heights[] = { 288, 576, 144, 1152, 96 };
325 gint n_sizes = G_N_ELEMENTS (widths);
327 caps = gst_caps_new_empty ();
328 for (i = 0; i < n_sizes; i++) {
329 temp = gst_caps_new_simple (mimetype,
330 "width", G_TYPE_INT, widths[i],
331 "height", G_TYPE_INT, heights[i],
332 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
334 gst_caps_append (caps, temp);
338 case AV_CODEC_ID_DVVIDEO:
345 gint framerate_n, framerate_d;
348 "Y41B", 720, 480, 8, 9, 30000, 1001}, {
349 "Y41B", 720, 480, 32, 27, 30000, 1001}, {
350 "Y42B", 720, 480, 8, 9, 30000, 1001}, {
351 "Y42B", 720, 480, 32, 27, 30000, 1001}, {
352 "I420", 720, 576, 16, 15, 25, 1}, {
353 "I420", 720, 576, 64, 45, 25, 1}, {
354 "Y41B", 720, 576, 16, 15, 25, 1}, {
355 "Y41B", 720, 576, 64, 45, 25, 1}, {
356 "Y42B", 720, 576, 16, 15, 25, 1}, {
357 "Y42B", 720, 576, 64, 45, 25, 1}, {
358 "Y42B", 1280, 1080, 1, 1, 30000, 1001}, {
359 "Y42B", 1280, 1080, 3, 2, 30000, 1001}, {
360 "Y42B", 1440, 1080, 1, 1, 25, 1}, {
361 "Y42B", 1440, 1080, 4, 3, 25, 1}, {
362 "Y42B", 960, 720, 1, 1, 60000, 1001}, {
363 "Y42B", 960, 720, 4, 3, 60000, 1001}, {
364 "Y42B", 960, 720, 1, 1, 50, 1}, {
365 "Y42B", 960, 720, 4, 3, 50, 1},};
367 gint n_sizes = G_N_ELEMENTS (profiles);
369 if (strcmp (mimetype, "video/x-raw") == 0) {
370 caps = gst_caps_new_empty ();
371 for (i = 0; i < n_sizes; i++) {
372 temp = gst_caps_new_simple (mimetype,
373 "format", G_TYPE_STRING, profiles[i].csp,
374 "width", G_TYPE_INT, profiles[i].width,
375 "height", G_TYPE_INT, profiles[i].height,
376 "framerate", GST_TYPE_FRACTION, profiles[i].framerate_n,
377 profiles[i].framerate_d, "pixel-aspect-ratio",
378 GST_TYPE_FRACTION, profiles[i].par_n, profiles[i].par_d, NULL);
380 gst_caps_append (caps, temp);
383 caps = gst_caps_new_empty ();
384 for (i = 0; i < n_sizes; i++) {
385 temp = gst_caps_new_simple (mimetype,
386 "width", G_TYPE_INT, profiles[i].width,
387 "height", G_TYPE_INT, profiles[i].height,
388 "framerate", GST_TYPE_FRACTION, profiles[i].framerate_n,
389 profiles[i].framerate_d, "pixel-aspect-ratio",
390 GST_TYPE_FRACTION, profiles[i].par_n, profiles[i].par_d, NULL);
392 gst_caps_append (caps, temp);
397 case AV_CODEC_ID_DNXHD:
399 caps = gst_caps_new_simple (mimetype,
400 "width", G_TYPE_INT, 1920,
401 "height", G_TYPE_INT, 1080,
402 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
403 gst_caps_append (caps, gst_caps_new_simple (mimetype,
404 "width", G_TYPE_INT, 1280,
405 "height", G_TYPE_INT, 720,
406 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL));
411 if (codec && codec->supported_framerates
412 && codec->supported_framerates[0].num != 0
413 && codec->supported_framerates[0].den != 0) {
416 const AVRational *rates = codec->supported_framerates;
418 if (rates[1].num == 0 && rates[1].den == 0) {
420 gst_caps_new_simple (mimetype, "framerate", GST_TYPE_FRACTION,
421 rates[0].num, rates[0].den, NULL);
423 g_value_init (&va, GST_TYPE_LIST);
424 g_value_init (&v, GST_TYPE_FRACTION);
426 while (rates->num != 0 && rates->den != 0) {
427 gst_value_set_fraction (&v, rates->num, rates->den);
428 gst_value_list_append_value (&va, &v);
432 caps = gst_caps_new_simple (mimetype, NULL, NULL, NULL);
433 gst_caps_set_value (caps, "framerate", &va);
439 caps = gst_caps_new_empty_simple (mimetype);
447 /* no fixed caps or special restrictions applied;
448 * default unfixed setting */
450 GST_DEBUG ("Creating default caps");
451 caps = gst_caps_new_empty_simple (mimetype);
454 va_start (var_args, fieldname);
455 gst_caps_set_simple_valist (caps, fieldname, var_args);
462 get_nbits_set (guint64 n)
467 for (i = 0; i < 64; i++) {
468 if ((n & (G_GUINT64_CONSTANT (1) << i)))
476 gst_ffmpeg_audio_set_sample_fmts (GstCaps * caps,
477 const enum AVSampleFormat *fmts)
481 GstAudioFormat format;
483 if (!fmts || fmts[0] == -1) {
486 g_value_init (&va, GST_TYPE_LIST);
487 g_value_init (&v, G_TYPE_STRING);
488 for (i = 0; i <= AV_SAMPLE_FMT_DBL; i++) {
489 format = gst_ffmpeg_smpfmt_to_audioformat (i);
490 if (format == GST_AUDIO_FORMAT_UNKNOWN)
492 g_value_set_string (&v, gst_audio_format_to_string (format));
493 gst_value_list_append_value (&va, &v);
495 gst_caps_set_value (caps, "format", &va);
501 g_value_init (&va, GST_TYPE_LIST);
502 g_value_init (&v, G_TYPE_STRING);
503 while (*fmts != -1) {
504 format = gst_ffmpeg_smpfmt_to_audioformat (*fmts);
505 if (format != GST_AUDIO_FORMAT_UNKNOWN) {
506 g_value_set_string (&v, gst_audio_format_to_string (format));
507 /* Only append values we don't have yet */
508 if (!_gst_value_list_contains (&va, &v))
509 gst_value_list_append_value (&va, &v);
513 if (gst_value_list_get_size (&va) == 1) {
514 /* The single value is still in v */
515 gst_caps_set_value (caps, "format", &v);
516 } else if (gst_value_list_get_size (&va) > 1) {
517 gst_caps_set_value (caps, "format", &va);
523 /* same for audio - now with channels/sample rate
526 gst_ff_aud_caps_new (AVCodecContext * context, AVCodec * codec,
527 enum AVCodecID codec_id, gboolean encode, const char *mimetype,
528 const char *fieldname, ...)
530 GstCaps *caps = NULL;
534 /* fixed, non-probing context */
535 if (context != NULL && context->channels != -1) {
536 GstAudioChannelPosition pos[64];
539 caps = gst_caps_new_simple (mimetype,
540 "rate", G_TYPE_INT, context->sample_rate,
541 "channels", G_TYPE_INT, context->channels, NULL);
543 if (context->channels > 1 &&
544 gst_ffmpeg_channel_layout_to_gst (context->channel_layout,
545 context->channels, pos) &&
546 gst_audio_channel_positions_to_mask (pos, context->channels, FALSE,
548 gst_caps_set_simple (caps, "channel-mask", GST_TYPE_BITMASK, mask, NULL);
551 gint maxchannels = 2;
552 const gint *rates = NULL;
555 /* so we must be after restricted caps in this case */
557 case AV_CODEC_ID_AAC:
558 case AV_CODEC_ID_AAC_LATM:
559 case AV_CODEC_ID_DTS:
562 case AV_CODEC_ID_MP2:
564 const static gint l_rates[] =
565 { 48000, 44100, 32000, 24000, 22050, 16000 };
566 n_rates = G_N_ELEMENTS (l_rates);
570 case AV_CODEC_ID_EAC3:
571 case AV_CODEC_ID_AC3:
573 const static gint l_rates[] = { 48000, 44100, 32000 };
575 n_rates = G_N_ELEMENTS (l_rates);
579 case AV_CODEC_ID_ADPCM_G722:
581 const static gint l_rates[] = { 16000 };
582 n_rates = G_N_ELEMENTS (l_rates);
587 case AV_CODEC_ID_ADPCM_G726:
589 const static gint l_rates[] = { 8000 };
590 n_rates = G_N_ELEMENTS (l_rates);
595 case AV_CODEC_ID_ADPCM_SWF:
597 const static gint l_rates[] = { 11025, 22050, 44100 };
598 n_rates = G_N_ELEMENTS (l_rates);
602 case AV_CODEC_ID_ROQ_DPCM:
604 const static gint l_rates[] = { 22050 };
605 n_rates = G_N_ELEMENTS (l_rates);
609 case AV_CODEC_ID_AMR_NB:
611 const static gint l_rates[] = { 8000 };
613 n_rates = G_N_ELEMENTS (l_rates);
617 case AV_CODEC_ID_AMR_WB:
619 const static gint l_rates[] = { 16000 };
621 n_rates = G_N_ELEMENTS (l_rates);
629 /* regardless of encode/decode, open up channels if applicable */
630 /* Until decoders/encoders expose the maximum number of channels
631 * they support, we whitelist them here. */
633 case AV_CODEC_ID_WMAPRO:
634 case AV_CODEC_ID_TRUEHD:
641 if (codec && codec->channel_layouts) {
642 const uint64_t *layouts = codec->channel_layouts;
643 GstAudioChannelPosition pos[64];
645 caps = gst_caps_new_empty ();
647 gint nbits_set = get_nbits_set (*layouts);
649 if (gst_ffmpeg_channel_layout_to_gst (*layouts, nbits_set, pos)) {
652 if (gst_audio_channel_positions_to_mask (pos, nbits_set, FALSE,
655 gst_structure_new (mimetype, "channels", G_TYPE_INT, nbits_set,
658 /* No need to require a channel mask for mono or stereo */
659 if (!(nbits_set == 1 && pos[0] == GST_AUDIO_CHANNEL_POSITION_MONO)
661 && pos[0] == GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT
662 && pos[1] == GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT))
663 gst_structure_set (s, "channel-mask", GST_TYPE_BITMASK, mask,
666 gst_caps_append_structure (caps, s);
672 if (maxchannels == 1)
673 caps = gst_caps_new_simple (mimetype,
674 "channels", G_TYPE_INT, maxchannels, NULL);
676 caps = gst_caps_new_simple (mimetype,
677 "channels", GST_TYPE_INT_RANGE, 1, maxchannels, NULL);
681 GValue list = { 0, };
683 g_value_init (&list, GST_TYPE_LIST);
684 for (i = 0; i < n_rates; i++) {
687 g_value_init (&v, G_TYPE_INT);
688 g_value_set_int (&v, rates[i]);
689 gst_value_list_append_value (&list, &v);
692 gst_caps_set_value (caps, "rate", &list);
693 g_value_unset (&list);
694 } else if (codec && codec->supported_samplerates
695 && codec->supported_samplerates[0]) {
699 if (!codec->supported_samplerates[1]) {
700 gst_caps_set_simple (caps, "rate", G_TYPE_INT,
701 codec->supported_samplerates[0], NULL);
703 const int *rates = codec->supported_samplerates;
705 g_value_init (&va, GST_TYPE_LIST);
706 g_value_init (&v, G_TYPE_INT);
709 g_value_set_int (&v, *rates);
710 gst_value_list_append_value (&va, &v);
713 gst_caps_set_value (caps, "rate", &va);
718 gst_caps_set_simple (caps, "rate", GST_TYPE_INT_RANGE, 4000, 96000, NULL);
721 caps = gst_caps_new_empty_simple (mimetype);
724 va_start (var_args, fieldname);
725 gst_caps_set_simple_valist (caps, fieldname, var_args);
731 /* Check if the given codec ID is an image format -- for now this is just
732 * anything whose caps is image/... */
734 gst_ffmpeg_codecid_is_image (enum AVCodecID codec_id)
737 case AV_CODEC_ID_MJPEG:
738 case AV_CODEC_ID_LJPEG:
739 case AV_CODEC_ID_GIF:
740 case AV_CODEC_ID_PPM:
741 case AV_CODEC_ID_PBM:
742 case AV_CODEC_ID_PCX:
743 case AV_CODEC_ID_SGI:
744 case AV_CODEC_ID_TARGA:
745 case AV_CODEC_ID_TIFF:
746 case AV_CODEC_ID_SUNRAST:
747 case AV_CODEC_ID_BMP:
755 /* Convert a FFMPEG codec ID and optional AVCodecContext
756 * to a GstCaps. If the context is ommitted, no fixed values
757 * for video/audio size will be included in the GstCaps
759 * CodecID is primarily meant for compressed data GstCaps!
761 * encode is a special parameter. gstffmpegdec will say
762 * FALSE, gstffmpegenc will say TRUE. The output caps
763 * depends on this, in such a way that it will be very
764 * specific, defined, fixed and correct caps for encoders,
765 * yet very wide, "forgiving" caps for decoders. Example
766 * for mp3: decode: audio/mpeg,mpegversion=1,layer=[1-3]
767 * but encode: audio/mpeg,mpegversion=1,layer=3,bitrate=x,
772 gst_ffmpeg_codecid_to_caps (enum AVCodecID codec_id,
773 AVCodecContext * context, gboolean encode)
775 GstCaps *caps = NULL;
776 gboolean buildcaps = FALSE;
778 GST_LOG ("codec_id:%d, context:%p, encode:%d", codec_id, context, encode);
781 case AV_CODEC_ID_MPEG1VIDEO:
783 caps = gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
784 "mpegversion", G_TYPE_INT, 1,
785 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
788 case AV_CODEC_ID_MPEG2VIDEO:
792 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
793 "mpegversion", G_TYPE_INT, 2, "systemstream", G_TYPE_BOOLEAN, FALSE,
796 /* decode both MPEG-1 and MPEG-2; width/height/fps are all in
797 * the MPEG video stream headers, so may be omitted from caps. */
798 caps = gst_caps_new_simple ("video/mpeg",
799 "mpegversion", GST_TYPE_INT_RANGE, 1, 2,
800 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
804 case AV_CODEC_ID_H263:
807 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
808 "video/x-h263", "variant", G_TYPE_STRING, "itu", "h263version",
809 G_TYPE_STRING, "h263", NULL);
811 /* don't pass codec_id, we can decode other variants with the H263
812 * decoder that don't have specific size requirements
815 gst_ff_vid_caps_new (context, NULL, AV_CODEC_ID_NONE, encode,
816 "video/x-h263", "variant", G_TYPE_STRING, "itu", NULL);
820 case AV_CODEC_ID_H263P:
822 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h263",
823 "variant", G_TYPE_STRING, "itu", "h263version", G_TYPE_STRING,
825 if (encode && context) {
827 gst_caps_set_simple (caps,
828 "annex-f", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_4MV,
829 "annex-j", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_LOOP_FILTER,
830 "annex-i", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_AC_PRED,
831 "annex-t", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_AC_PRED,
836 case AV_CODEC_ID_H263I:
838 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
839 "video/x-intel-h263", "variant", G_TYPE_STRING, "intel", NULL);
842 case AV_CODEC_ID_H261:
844 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h261",
848 case AV_CODEC_ID_RV10:
849 case AV_CODEC_ID_RV20:
850 case AV_CODEC_ID_RV30:
851 case AV_CODEC_ID_RV40:
856 case AV_CODEC_ID_RV40:
859 case AV_CODEC_ID_RV30:
862 case AV_CODEC_ID_RV20:
871 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
872 "video/x-pn-realvideo", "rmversion", G_TYPE_INT, version, NULL);
874 if (context->extradata_size >= 8) {
875 gst_caps_set_simple (caps,
876 "subformat", G_TYPE_INT, GST_READ_UINT32_BE (context->extradata),
883 case AV_CODEC_ID_MP1:
885 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
886 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 1, NULL);
889 case AV_CODEC_ID_MP2:
891 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
892 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 2, NULL);
895 case AV_CODEC_ID_MP3:
899 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
900 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 3, NULL);
902 /* Decodes MPEG-1 layer 1/2/3. Samplerate, channels et al are
903 * in the MPEG audio header, so may be omitted from caps. */
904 caps = gst_caps_new_simple ("audio/mpeg",
905 "mpegversion", G_TYPE_INT, 1,
906 "layer", GST_TYPE_INT_RANGE, 1, 3, NULL);
910 case AV_CODEC_ID_MUSEPACK7:
912 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
913 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 7,
917 case AV_CODEC_ID_MUSEPACK8:
919 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
920 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 8,
924 case AV_CODEC_ID_AC3:
927 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-ac3",
931 case AV_CODEC_ID_EAC3:
934 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-eac3",
938 case AV_CODEC_ID_TRUEHD:
940 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
941 "audio/x-true-hd", NULL);
944 case AV_CODEC_ID_ATRAC1:
946 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
947 "audio/x-vnd.sony.atrac1", NULL);
950 case AV_CODEC_ID_ATRAC3:
952 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
953 "audio/x-vnd.sony.atrac3", NULL);
956 case AV_CODEC_ID_DTS:
958 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dts",
962 case AV_CODEC_ID_APE:
964 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
965 "audio/x-ffmpeg-parsed-ape", NULL);
967 gst_caps_set_simple (caps,
968 "depth", G_TYPE_INT, context->bits_per_coded_sample, NULL);
972 case AV_CODEC_ID_MLP:
974 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mlp",
978 case AV_CODEC_ID_IMC:
980 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-imc",
984 /* MJPEG is normal JPEG, Motion-JPEG and Quicktime MJPEG-A. MJPEGB
985 * is Quicktime's MJPEG-B. LJPEG is lossless JPEG. I don't know what
986 * sp5x is, but it's apparently something JPEG... We don't separate
987 * between those in GStreamer. Should we (at least between MJPEG,
988 * MJPEG-B and sp5x decoding...)? */
989 case AV_CODEC_ID_MJPEG:
990 case AV_CODEC_ID_LJPEG:
992 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/jpeg",
993 "parsed", G_TYPE_BOOLEAN, TRUE, NULL);
996 case AV_CODEC_ID_JPEG2000:
998 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-j2c",
1001 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
1002 encode, "image/x-jpc", NULL));
1003 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
1004 encode, "image/jp2", NULL));
1008 case AV_CODEC_ID_SP5X:
1010 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/sp5x",
1014 case AV_CODEC_ID_MJPEGB:
1016 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1017 "video/x-mjpeg-b", NULL);
1020 case AV_CODEC_ID_MPEG4:
1021 if (encode && context != NULL) {
1022 /* I'm not exactly sure what ffmpeg outputs... ffmpeg itself uses
1023 * the AVI fourcc 'DIVX', but 'mp4v' for Quicktime... */
1024 switch (context->codec_tag) {
1025 case GST_MAKE_FOURCC ('D', 'I', 'V', 'X'):
1027 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1028 "video/x-divx", "divxversion", G_TYPE_INT, 5, NULL);
1030 case GST_MAKE_FOURCC ('m', 'p', '4', 'v'):
1032 /* FIXME: bitrate. libav doesn't expose the used profile and level */
1034 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1035 "video/mpeg", "systemstream", G_TYPE_BOOLEAN, FALSE,
1036 "mpegversion", G_TYPE_INT, 4, NULL);
1040 /* The trick here is to separate xvid, divx, mpeg4, 3ivx et al */
1042 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
1043 "mpegversion", G_TYPE_INT, 4, "systemstream", G_TYPE_BOOLEAN, FALSE,
1047 GValue arr = { 0, };
1048 GValue item = { 0, };
1050 g_value_init (&arr, GST_TYPE_LIST);
1051 g_value_init (&item, G_TYPE_STRING);
1052 g_value_set_string (&item, "simple");
1053 gst_value_list_append_value (&arr, &item);
1054 g_value_set_string (&item, "advanced-simple");
1055 gst_value_list_append_value (&arr, &item);
1056 g_value_unset (&item);
1058 gst_caps_set_value (caps, "profile", &arr);
1059 g_value_unset (&arr);
1061 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
1062 encode, "video/x-divx", "divxversion", G_TYPE_INT, 5, NULL));
1064 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
1065 encode, "video/x-divx", "divxversion", GST_TYPE_INT_RANGE, 4,
1071 case AV_CODEC_ID_RAWVIDEO:
1073 gst_ffmpeg_codectype_to_video_caps (context, codec_id, encode, NULL);
1076 case AV_CODEC_ID_MSMPEG4V1:
1077 case AV_CODEC_ID_MSMPEG4V2:
1078 case AV_CODEC_ID_MSMPEG4V3:
1080 gint version = 41 + codec_id - AV_CODEC_ID_MSMPEG4V1;
1082 /* encode-FIXME: bitrate */
1084 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1085 "video/x-msmpeg", "msmpegversion", G_TYPE_INT, version, NULL);
1086 if (!encode && codec_id == AV_CODEC_ID_MSMPEG4V3) {
1087 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
1088 encode, "video/x-divx", "divxversion", G_TYPE_INT, 3, NULL));
1093 case AV_CODEC_ID_WMV1:
1094 case AV_CODEC_ID_WMV2:
1096 gint version = (codec_id == AV_CODEC_ID_WMV1) ? 1 : 2;
1099 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1100 "wmvversion", G_TYPE_INT, version, NULL);
1104 case AV_CODEC_ID_FLV1:
1106 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1107 "video/x-flash-video", "flvversion", G_TYPE_INT, 1, NULL);
1110 case AV_CODEC_ID_SVQ1:
1112 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-svq",
1113 "svqversion", G_TYPE_INT, 1, NULL);
1116 case AV_CODEC_ID_SVQ3:
1118 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-svq",
1119 "svqversion", G_TYPE_INT, 3, NULL);
1122 case AV_CODEC_ID_DVAUDIO:
1124 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dv",
1128 case AV_CODEC_ID_DVVIDEO:
1130 if (encode && context) {
1131 const gchar *format;
1133 switch (context->pix_fmt) {
1134 case AV_PIX_FMT_YUYV422:
1137 case AV_PIX_FMT_YUV420P:
1140 case AV_PIX_FMT_YUVA420P:
1143 case AV_PIX_FMT_YUV411P:
1146 case AV_PIX_FMT_YUV422P:
1149 case AV_PIX_FMT_YUV410P:
1154 ("Couldnt' find format for pixfmt %d, defaulting to I420",
1160 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dv",
1161 "systemstream", G_TYPE_BOOLEAN, FALSE, "format", G_TYPE_STRING,
1165 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dv",
1166 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
1171 case AV_CODEC_ID_WMAV1:
1172 case AV_CODEC_ID_WMAV2:
1174 gint version = (codec_id == AV_CODEC_ID_WMAV1) ? 1 : 2;
1178 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1179 "wmaversion", G_TYPE_INT, version, "block_align", G_TYPE_INT,
1180 context->block_align, "bitrate", G_TYPE_INT,
1181 (guint) context->bit_rate, NULL);
1184 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1185 "wmaversion", G_TYPE_INT, version, "block_align",
1186 GST_TYPE_INT_RANGE, 0, G_MAXINT, "bitrate", GST_TYPE_INT_RANGE, 0,
1191 case AV_CODEC_ID_WMAPRO:
1194 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1195 "wmaversion", G_TYPE_INT, 3, NULL);
1198 case AV_CODEC_ID_WMALOSSLESS:
1200 /* libav only supports a depth of 16 at the moment */
1202 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1203 "wmaversion", G_TYPE_INT, 4, "depth", G_TYPE_INT, 16, NULL);
1206 case AV_CODEC_ID_WMAVOICE:
1209 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wms",
1214 case AV_CODEC_ID_MACE3:
1215 case AV_CODEC_ID_MACE6:
1217 gint version = (codec_id == AV_CODEC_ID_MACE3) ? 3 : 6;
1220 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mace",
1221 "maceversion", G_TYPE_INT, version, NULL);
1225 case AV_CODEC_ID_HUFFYUV:
1227 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1228 "video/x-huffyuv", NULL);
1230 gst_caps_set_simple (caps,
1231 "bpp", G_TYPE_INT, context->bits_per_coded_sample, NULL);
1235 case AV_CODEC_ID_CYUV:
1237 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1238 "video/x-compressed-yuv", NULL);
1241 case AV_CODEC_ID_H264:
1243 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h264",
1244 "alignment", G_TYPE_STRING, "au", NULL);
1246 GValue arr = { 0, };
1247 GValue item = { 0, };
1248 g_value_init (&arr, GST_TYPE_LIST);
1249 g_value_init (&item, G_TYPE_STRING);
1250 g_value_set_string (&item, "avc");
1251 gst_value_list_append_value (&arr, &item);
1252 g_value_set_string (&item, "byte-stream");
1253 gst_value_list_append_value (&arr, &item);
1254 g_value_unset (&item);
1255 gst_caps_set_value (caps, "stream-format", &arr);
1256 g_value_unset (&arr);
1260 case AV_CODEC_ID_HEVC:
1262 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h265",
1263 "alignment", G_TYPE_STRING, "au", NULL);
1265 GValue arr = { 0, };
1266 GValue item = { 0, };
1267 g_value_init (&arr, GST_TYPE_LIST);
1268 g_value_init (&item, G_TYPE_STRING);
1269 g_value_set_string (&item, "hvc1");
1270 gst_value_list_append_value (&arr, &item);
1271 g_value_set_string (&item, "hev1");
1272 gst_value_list_append_value (&arr, &item);
1273 g_value_set_string (&item, "byte-stream");
1274 gst_value_list_append_value (&arr, &item);
1275 g_value_unset (&item);
1276 gst_caps_set_value (caps, "stream-format", &arr);
1277 g_value_unset (&arr);
1281 case AV_CODEC_ID_INDEO5:
1283 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1284 "indeoversion", G_TYPE_INT, 5, NULL);
1287 case AV_CODEC_ID_INDEO4:
1289 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1290 "indeoversion", G_TYPE_INT, 4, NULL);
1293 case AV_CODEC_ID_INDEO3:
1295 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1296 "indeoversion", G_TYPE_INT, 3, NULL);
1299 case AV_CODEC_ID_INDEO2:
1301 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1302 "indeoversion", G_TYPE_INT, 2, NULL);
1305 case AV_CODEC_ID_FLASHSV:
1307 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1308 "video/x-flash-screen", NULL);
1311 case AV_CODEC_ID_FLASHSV2:
1313 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1314 "video/x-flash-screen2", NULL);
1317 case AV_CODEC_ID_VP3:
1319 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp3",
1323 case AV_CODEC_ID_VP5:
1325 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp5",
1329 case AV_CODEC_ID_VP6:
1331 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp6",
1335 case AV_CODEC_ID_VP6F:
1337 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1338 "video/x-vp6-flash", NULL);
1341 case AV_CODEC_ID_VP6A:
1343 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1344 "video/x-vp6-alpha", NULL);
1347 case AV_CODEC_ID_VP8:
1349 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp8",
1353 case AV_CODEC_ID_VP9:
1355 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp9",
1359 case AV_CODEC_ID_THEORA:
1361 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1362 "video/x-theora", NULL);
1365 case AV_CODEC_ID_CFHD:
1367 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1368 "video/x-cineform", NULL);
1371 case AV_CODEC_ID_AAC:
1374 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
1378 GValue arr = { 0, };
1379 GValue item = { 0, };
1381 g_value_init (&arr, GST_TYPE_LIST);
1382 g_value_init (&item, G_TYPE_INT);
1383 g_value_set_int (&item, 2);
1384 gst_value_list_append_value (&arr, &item);
1385 g_value_set_int (&item, 4);
1386 gst_value_list_append_value (&arr, &item);
1387 g_value_unset (&item);
1389 gst_caps_set_value (caps, "mpegversion", &arr);
1390 g_value_unset (&arr);
1392 g_value_init (&arr, GST_TYPE_LIST);
1393 g_value_init (&item, G_TYPE_STRING);
1394 g_value_set_string (&item, "raw");
1395 gst_value_list_append_value (&arr, &item);
1396 g_value_set_string (&item, "adts");
1397 gst_value_list_append_value (&arr, &item);
1398 g_value_set_string (&item, "adif");
1399 gst_value_list_append_value (&arr, &item);
1400 g_value_unset (&item);
1402 gst_caps_set_value (caps, "stream-format", &arr);
1403 g_value_unset (&arr);
1405 gst_caps_set_simple (caps, "mpegversion", G_TYPE_INT, 4,
1406 "stream-format", G_TYPE_STRING, "raw",
1407 "base-profile", G_TYPE_STRING, "lc", NULL);
1409 if (context && context->extradata_size > 0)
1410 gst_codec_utils_aac_caps_set_level_and_profile (caps,
1411 context->extradata, context->extradata_size);
1416 case AV_CODEC_ID_AAC_LATM: /* LATM/LOAS AAC syntax */
1417 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
1418 "mpegversion", G_TYPE_INT, 4, "stream-format", G_TYPE_STRING, "loas",
1422 case AV_CODEC_ID_ASV1:
1424 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-asus",
1425 "asusversion", G_TYPE_INT, 1, NULL);
1427 case AV_CODEC_ID_ASV2:
1429 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-asus",
1430 "asusversion", G_TYPE_INT, 2, NULL);
1433 case AV_CODEC_ID_FFV1:
1435 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-ffv",
1436 "ffvversion", G_TYPE_INT, 1, NULL);
1439 case AV_CODEC_ID_4XM:
1441 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-4xm",
1445 case AV_CODEC_ID_XAN_WC3:
1446 case AV_CODEC_ID_XAN_WC4:
1448 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-xan",
1449 "wcversion", G_TYPE_INT, 3 - AV_CODEC_ID_XAN_WC3 + codec_id, NULL);
1452 case AV_CODEC_ID_CLJR:
1454 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1455 "video/x-cirrus-logic-accupak", NULL);
1458 case AV_CODEC_ID_FRAPS:
1460 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-fraps",
1464 case AV_CODEC_ID_MDEC:
1465 case AV_CODEC_ID_ROQ:
1466 case AV_CODEC_ID_INTERPLAY_VIDEO:
1470 case AV_CODEC_ID_VCR1:
1472 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1473 "video/x-ati-vcr", "vcrversion", G_TYPE_INT, 1, NULL);
1476 case AV_CODEC_ID_RPZA:
1478 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1479 "video/x-apple-video", NULL);
1482 case AV_CODEC_ID_CINEPAK:
1484 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1485 "video/x-cinepak", NULL);
1488 /* WS_VQA belogns here (order) */
1490 case AV_CODEC_ID_MSRLE:
1492 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-rle",
1493 "layout", G_TYPE_STRING, "microsoft", NULL);
1495 gst_caps_set_simple (caps,
1496 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1498 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1502 case AV_CODEC_ID_QTRLE:
1504 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-rle",
1505 "layout", G_TYPE_STRING, "quicktime", NULL);
1507 gst_caps_set_simple (caps,
1508 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1510 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1514 case AV_CODEC_ID_MSVIDEO1:
1516 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1517 "video/x-msvideocodec", "msvideoversion", G_TYPE_INT, 1, NULL);
1520 case AV_CODEC_ID_MSS1:
1522 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1523 "wmvversion", G_TYPE_INT, 1, "format", G_TYPE_STRING, "MSS1", NULL);
1526 case AV_CODEC_ID_MSS2:
1528 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1529 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "MSS2", NULL);
1532 case AV_CODEC_ID_WMV3:
1534 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1535 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "WMV3", NULL);
1537 case AV_CODEC_ID_VC1:
1539 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1540 "wmvversion", G_TYPE_INT, 3, NULL);
1541 if (!context && !encode) {
1542 GValue arr = { 0, };
1543 GValue item = { 0, };
1545 g_value_init (&arr, GST_TYPE_LIST);
1546 g_value_init (&item, G_TYPE_STRING);
1547 g_value_set_string (&item, "WVC1");
1548 gst_value_list_append_value (&arr, &item);
1549 g_value_set_string (&item, "WMVA");
1550 gst_value_list_append_and_take_value (&arr, &item);
1551 gst_caps_set_value (caps, "format", &arr);
1552 g_value_unset (&arr);
1554 gst_caps_set_simple (caps, "format", G_TYPE_STRING, "WVC1", NULL);
1557 case AV_CODEC_ID_QDM2:
1559 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-qdm2",
1563 case AV_CODEC_ID_MSZH:
1565 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-mszh",
1569 case AV_CODEC_ID_ZLIB:
1571 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-zlib",
1575 case AV_CODEC_ID_TRUEMOTION1:
1577 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1578 "video/x-truemotion", "trueversion", G_TYPE_INT, 1, NULL);
1580 case AV_CODEC_ID_TRUEMOTION2:
1582 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1583 "video/x-truemotion", "trueversion", G_TYPE_INT, 2, NULL);
1586 case AV_CODEC_ID_ULTI:
1588 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1589 "video/x-ultimotion", NULL);
1592 case AV_CODEC_ID_TSCC:
1594 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1595 "video/x-camtasia", NULL);
1597 gst_caps_set_simple (caps,
1598 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1600 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1604 case AV_CODEC_ID_TSCC2:
1606 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1607 "video/x-tscc", "tsccversion", G_TYPE_INT, 2, NULL);
1610 case AV_CODEC_ID_KMVC:
1612 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-kmvc",
1616 case AV_CODEC_ID_NUV:
1618 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-nuv",
1622 case AV_CODEC_ID_GIF:
1624 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1625 "image/gst-libav-gif", "parsed", G_TYPE_BOOLEAN, TRUE, NULL);
1628 case AV_CODEC_ID_PNG:
1630 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/png",
1634 case AV_CODEC_ID_PPM:
1636 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/ppm",
1640 case AV_CODEC_ID_PBM:
1642 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/pbm",
1646 case AV_CODEC_ID_PAM:
1648 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1649 "image/x-portable-anymap", NULL);
1652 case AV_CODEC_ID_PGM:
1654 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1655 "image/x-portable-graymap", NULL);
1658 case AV_CODEC_ID_PCX:
1660 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-pcx",
1664 case AV_CODEC_ID_SGI:
1666 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-sgi",
1670 case AV_CODEC_ID_TARGA:
1672 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-tga",
1676 case AV_CODEC_ID_TIFF:
1678 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/tiff",
1682 case AV_CODEC_ID_SUNRAST:
1684 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1685 "image/x-sun-raster", NULL);
1688 case AV_CODEC_ID_SMC:
1690 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-smc",
1694 case AV_CODEC_ID_QDRAW:
1696 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-qdrw",
1700 case AV_CODEC_ID_DNXHD:
1702 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dnxhd",
1706 case AV_CODEC_ID_PRORES:
1708 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1709 "video/x-prores", NULL);
1711 switch (context->codec_tag) {
1712 case GST_MAKE_FOURCC ('a', 'p', 'c', 'o'):
1713 gst_caps_set_simple (caps, "variant", G_TYPE_STRING, "proxy", NULL);
1715 case GST_MAKE_FOURCC ('a', 'p', 'c', 's'):
1716 gst_caps_set_simple (caps, "variant", G_TYPE_STRING, "lt", NULL);
1719 case GST_MAKE_FOURCC ('a', 'p', 'c', 'n'):
1720 gst_caps_set_simple (caps, "variant", G_TYPE_STRING, "standard",
1723 case GST_MAKE_FOURCC ('a', 'p', 'c', 'h'):
1724 gst_caps_set_simple (caps, "variant", G_TYPE_STRING, "hq", NULL);
1726 case GST_MAKE_FOURCC ('a', 'p', '4', 'h'):
1727 gst_caps_set_simple (caps, "variant", G_TYPE_STRING, "4444", NULL);
1729 case GST_MAKE_FOURCC ('a', 'p', '4', 'x'):
1730 gst_caps_set_simple (caps, "variant", G_TYPE_STRING, "4444xq",
1737 case AV_CODEC_ID_MIMIC:
1739 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-mimic",
1743 case AV_CODEC_ID_VMNC:
1745 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vmnc",
1749 case AV_CODEC_ID_TRUESPEECH:
1751 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1752 "audio/x-truespeech", NULL);
1755 case AV_CODEC_ID_QCELP:
1757 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/qcelp",
1761 case AV_CODEC_ID_AMV:
1763 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-amv",
1767 case AV_CODEC_ID_AASC:
1769 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-aasc",
1773 case AV_CODEC_ID_LOCO:
1775 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-loco",
1779 case AV_CODEC_ID_ZMBV:
1781 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-zmbv",
1785 case AV_CODEC_ID_LAGARITH:
1787 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1788 "video/x-lagarith", NULL);
1791 case AV_CODEC_ID_CSCD:
1793 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1794 "video/x-camstudio", NULL);
1796 gst_caps_set_simple (caps,
1797 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1799 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1803 case AV_CODEC_ID_AIC:
1805 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1806 "video/x-apple-intermediate-codec", NULL);
1809 case AV_CODEC_ID_CAVS:
1811 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1812 "video/x-cavs", NULL);
1815 case AV_CODEC_ID_WS_VQA:
1816 case AV_CODEC_ID_IDCIN:
1817 case AV_CODEC_ID_8BPS:
1818 case AV_CODEC_ID_FLIC:
1819 case AV_CODEC_ID_VMDVIDEO:
1820 case AV_CODEC_ID_VMDAUDIO:
1821 case AV_CODEC_ID_VIXL:
1822 case AV_CODEC_ID_QPEG:
1823 case AV_CODEC_ID_PGMYUV:
1824 case AV_CODEC_ID_FFVHUFF:
1825 case AV_CODEC_ID_WNV1:
1826 case AV_CODEC_ID_MP3ADU:
1827 case AV_CODEC_ID_MP3ON4:
1828 case AV_CODEC_ID_WESTWOOD_SND1:
1829 case AV_CODEC_ID_MMVIDEO:
1830 case AV_CODEC_ID_AVS:
1834 /* weird quasi-codecs for the demuxers only */
1835 case AV_CODEC_ID_PCM_S16LE:
1836 case AV_CODEC_ID_PCM_S16BE:
1837 case AV_CODEC_ID_PCM_U16LE:
1838 case AV_CODEC_ID_PCM_U16BE:
1839 case AV_CODEC_ID_PCM_S8:
1840 case AV_CODEC_ID_PCM_U8:
1842 GstAudioFormat format;
1845 case AV_CODEC_ID_PCM_S16LE:
1846 format = GST_AUDIO_FORMAT_S16LE;
1848 case AV_CODEC_ID_PCM_S16BE:
1849 format = GST_AUDIO_FORMAT_S16BE;
1851 case AV_CODEC_ID_PCM_U16LE:
1852 format = GST_AUDIO_FORMAT_U16LE;
1854 case AV_CODEC_ID_PCM_U16BE:
1855 format = GST_AUDIO_FORMAT_U16BE;
1857 case AV_CODEC_ID_PCM_S8:
1858 format = GST_AUDIO_FORMAT_S8;
1860 case AV_CODEC_ID_PCM_U8:
1861 format = GST_AUDIO_FORMAT_U8;
1865 g_assert (0); /* don't worry, we never get here */
1870 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-raw",
1871 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
1872 "layout", G_TYPE_STRING, "interleaved", NULL);
1876 case AV_CODEC_ID_PCM_MULAW:
1878 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mulaw",
1882 case AV_CODEC_ID_PCM_ALAW:
1884 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-alaw",
1888 case AV_CODEC_ID_ADPCM_G722:
1890 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/G722",
1893 gst_caps_set_simple (caps,
1894 "block_align", G_TYPE_INT, context->block_align,
1895 "bitrate", G_TYPE_INT, (guint) context->bit_rate, NULL);
1898 case AV_CODEC_ID_ADPCM_G726:
1900 /* the G726 decoder can also handle G721 */
1902 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-adpcm",
1903 "layout", G_TYPE_STRING, "g726", NULL);
1905 gst_caps_set_simple (caps,
1906 "block_align", G_TYPE_INT, context->block_align,
1907 "bitrate", G_TYPE_INT, (guint) context->bit_rate, NULL);
1910 gst_caps_append (caps, gst_caps_new_simple ("audio/x-adpcm",
1911 "layout", G_TYPE_STRING, "g721",
1912 "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, 8000, NULL));
1916 case AV_CODEC_ID_ADPCM_IMA_QT:
1917 case AV_CODEC_ID_ADPCM_IMA_WAV:
1918 case AV_CODEC_ID_ADPCM_IMA_DK3:
1919 case AV_CODEC_ID_ADPCM_IMA_DK4:
1920 case AV_CODEC_ID_ADPCM_IMA_WS:
1921 case AV_CODEC_ID_ADPCM_IMA_SMJPEG:
1922 case AV_CODEC_ID_ADPCM_IMA_AMV:
1923 case AV_CODEC_ID_ADPCM_IMA_ISS:
1924 case AV_CODEC_ID_ADPCM_IMA_EA_EACS:
1925 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
1926 case AV_CODEC_ID_ADPCM_MS:
1927 case AV_CODEC_ID_ADPCM_4XM:
1928 case AV_CODEC_ID_ADPCM_XA:
1929 case AV_CODEC_ID_ADPCM_ADX:
1930 case AV_CODEC_ID_ADPCM_EA:
1931 case AV_CODEC_ID_ADPCM_CT:
1932 case AV_CODEC_ID_ADPCM_SWF:
1933 case AV_CODEC_ID_ADPCM_YAMAHA:
1934 case AV_CODEC_ID_ADPCM_SBPRO_2:
1935 case AV_CODEC_ID_ADPCM_SBPRO_3:
1936 case AV_CODEC_ID_ADPCM_SBPRO_4:
1937 case AV_CODEC_ID_ADPCM_EA_R1:
1938 case AV_CODEC_ID_ADPCM_EA_R2:
1939 case AV_CODEC_ID_ADPCM_EA_R3:
1940 case AV_CODEC_ID_ADPCM_EA_MAXIS_XA:
1941 case AV_CODEC_ID_ADPCM_EA_XAS:
1942 case AV_CODEC_ID_ADPCM_THP:
1944 const gchar *layout = NULL;
1947 case AV_CODEC_ID_ADPCM_IMA_QT:
1948 layout = "quicktime";
1950 case AV_CODEC_ID_ADPCM_IMA_WAV:
1953 case AV_CODEC_ID_ADPCM_IMA_DK3:
1956 case AV_CODEC_ID_ADPCM_IMA_DK4:
1959 case AV_CODEC_ID_ADPCM_IMA_WS:
1960 layout = "westwood";
1962 case AV_CODEC_ID_ADPCM_IMA_SMJPEG:
1965 case AV_CODEC_ID_ADPCM_IMA_AMV:
1968 case AV_CODEC_ID_ADPCM_IMA_ISS:
1971 case AV_CODEC_ID_ADPCM_IMA_EA_EACS:
1974 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
1977 case AV_CODEC_ID_ADPCM_MS:
1978 layout = "microsoft";
1980 case AV_CODEC_ID_ADPCM_4XM:
1983 case AV_CODEC_ID_ADPCM_XA:
1986 case AV_CODEC_ID_ADPCM_ADX:
1989 case AV_CODEC_ID_ADPCM_EA:
1992 case AV_CODEC_ID_ADPCM_CT:
1995 case AV_CODEC_ID_ADPCM_SWF:
1998 case AV_CODEC_ID_ADPCM_YAMAHA:
2001 case AV_CODEC_ID_ADPCM_SBPRO_2:
2004 case AV_CODEC_ID_ADPCM_SBPRO_3:
2007 case AV_CODEC_ID_ADPCM_SBPRO_4:
2010 case AV_CODEC_ID_ADPCM_EA_R1:
2013 case AV_CODEC_ID_ADPCM_EA_R2:
2016 case AV_CODEC_ID_ADPCM_EA_R3:
2019 case AV_CODEC_ID_ADPCM_EA_MAXIS_XA:
2020 layout = "ea-maxis-xa";
2022 case AV_CODEC_ID_ADPCM_EA_XAS:
2025 case AV_CODEC_ID_ADPCM_THP:
2029 g_assert (0); /* don't worry, we never get here */
2033 /* FIXME: someone please check whether we need additional properties
2034 * in this caps definition. */
2036 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-adpcm",
2037 "layout", G_TYPE_STRING, layout, NULL);
2039 gst_caps_set_simple (caps,
2040 "block_align", G_TYPE_INT, context->block_align,
2041 "bitrate", G_TYPE_INT, (guint) context->bit_rate, NULL);
2045 case AV_CODEC_ID_AMR_NB:
2047 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/AMR",
2051 case AV_CODEC_ID_AMR_WB:
2053 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/AMR-WB",
2057 case AV_CODEC_ID_GSM:
2059 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-gsm",
2063 case AV_CODEC_ID_GSM_MS:
2065 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/ms-gsm",
2069 case AV_CODEC_ID_NELLYMOSER:
2071 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
2072 "audio/x-nellymoser", NULL);
2075 case AV_CODEC_ID_SIPR:
2078 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-sipro",
2081 gst_caps_set_simple (caps,
2082 "leaf_size", G_TYPE_INT, context->block_align,
2083 "bitrate", G_TYPE_INT, (guint) context->bit_rate, NULL);
2088 case AV_CODEC_ID_RA_144:
2089 case AV_CODEC_ID_RA_288:
2090 case AV_CODEC_ID_COOK:
2095 case AV_CODEC_ID_RA_144:
2098 case AV_CODEC_ID_RA_288:
2101 case AV_CODEC_ID_COOK:
2108 /* FIXME: properties? */
2110 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
2111 "audio/x-pn-realaudio", "raversion", G_TYPE_INT, version, NULL);
2113 gst_caps_set_simple (caps,
2114 "leaf_size", G_TYPE_INT, context->block_align,
2115 "bitrate", G_TYPE_INT, (guint) context->bit_rate, NULL);
2120 case AV_CODEC_ID_ROQ_DPCM:
2121 case AV_CODEC_ID_INTERPLAY_DPCM:
2122 case AV_CODEC_ID_XAN_DPCM:
2123 case AV_CODEC_ID_SOL_DPCM:
2125 const gchar *layout = NULL;
2128 case AV_CODEC_ID_ROQ_DPCM:
2131 case AV_CODEC_ID_INTERPLAY_DPCM:
2132 layout = "interplay";
2134 case AV_CODEC_ID_XAN_DPCM:
2137 case AV_CODEC_ID_SOL_DPCM:
2141 g_assert (0); /* don't worry, we never get here */
2145 /* FIXME: someone please check whether we need additional properties
2146 * in this caps definition. */
2148 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dpcm",
2149 "layout", G_TYPE_STRING, layout, NULL);
2151 gst_caps_set_simple (caps,
2152 "block_align", G_TYPE_INT, context->block_align,
2153 "bitrate", G_TYPE_INT, (guint) context->bit_rate, NULL);
2157 case AV_CODEC_ID_SHORTEN:
2158 caps = gst_caps_new_empty_simple ("audio/x-shorten");
2161 case AV_CODEC_ID_ALAC:
2163 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-alac",
2166 gst_caps_set_simple (caps,
2167 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
2171 case AV_CODEC_ID_FLAC:
2172 /* Note that ffmpeg has no encoder yet, but just for safety. In the
2173 * encoder case, we want to add things like samplerate, channels... */
2175 caps = gst_caps_new_empty_simple ("audio/x-flac");
2179 case AV_CODEC_ID_OPUS:
2180 /* Note that ffmpeg has no encoder yet, but just for safety. In the
2181 * encoder case, we want to add things like samplerate, channels... */
2183 /* FIXME: can ffmpeg handle multichannel Opus? */
2184 caps = gst_caps_new_simple ("audio/x-opus",
2185 "channel-mapping-family", G_TYPE_INT, 0, NULL);
2189 case AV_CODEC_ID_S302M:
2190 caps = gst_caps_new_empty_simple ("audio/x-smpte-302m");
2193 case AV_CODEC_ID_DVD_SUBTITLE:
2194 case AV_CODEC_ID_DVB_SUBTITLE:
2197 case AV_CODEC_ID_BMP:
2198 caps = gst_caps_new_empty_simple ("image/bmp");
2200 case AV_CODEC_ID_TTA:
2202 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-tta",
2205 gst_caps_set_simple (caps,
2206 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
2209 case AV_CODEC_ID_TWINVQ:
2211 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
2212 "audio/x-twin-vq", NULL);
2214 case AV_CODEC_ID_G729:
2216 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/G729",
2219 case AV_CODEC_ID_DSD_LSBF:
2221 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dsd",
2223 gst_caps_set_simple (caps, "lsbf", G_TYPE_BOOLEAN,
2224 TRUE, "planar", G_TYPE_BOOLEAN, FALSE, NULL);
2226 case AV_CODEC_ID_DSD_MSBF:
2228 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dsd",
2230 gst_caps_set_simple (caps, "lsbf", G_TYPE_BOOLEAN,
2231 FALSE, "planar", G_TYPE_BOOLEAN, FALSE, NULL);
2233 case AV_CODEC_ID_DSD_LSBF_PLANAR:
2235 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dsd",
2237 gst_caps_set_simple (caps, "lsbf", G_TYPE_BOOLEAN,
2238 TRUE, "planar", G_TYPE_BOOLEAN, TRUE, NULL);
2240 case AV_CODEC_ID_DSD_MSBF_PLANAR:
2242 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dsd",
2244 gst_caps_set_simple (caps, "lsbf", G_TYPE_BOOLEAN,
2245 FALSE, "planar", G_TYPE_BOOLEAN, TRUE, NULL);
2248 GST_DEBUG ("Unknown codec ID %d, please add mapping here", codec_id);
2255 if ((codec = avcodec_find_decoder (codec_id)) ||
2256 (codec = avcodec_find_encoder (codec_id))) {
2259 GST_LOG ("Could not create stream format caps for %s", codec->name);
2261 switch (codec->type) {
2262 case AVMEDIA_TYPE_VIDEO:
2263 mime = g_strdup_printf ("video/x-gst-av-%s", codec->name);
2265 gst_ff_vid_caps_new (context, NULL, codec_id, encode, mime, NULL);
2268 case AVMEDIA_TYPE_AUDIO:
2269 mime = g_strdup_printf ("audio/x-gst-av-%s", codec->name);
2271 gst_ff_aud_caps_new (context, NULL, codec_id, encode, mime, NULL);
2273 gst_caps_set_simple (caps,
2274 "block_align", G_TYPE_INT, context->block_align,
2275 "bitrate", G_TYPE_INT, (guint) context->bit_rate, NULL);
2286 /* set private data */
2287 if (context && context->extradata_size > 0) {
2288 GstBuffer *data = gst_buffer_new_and_alloc (context->extradata_size);
2290 gst_buffer_fill (data, 0, context->extradata, context->extradata_size);
2291 gst_caps_set_simple (caps, "codec_data", GST_TYPE_BUFFER, data, NULL);
2292 gst_buffer_unref (data);
2295 GST_LOG ("caps for codec_id=%d: %" GST_PTR_FORMAT, codec_id, caps);
2298 GST_LOG ("No caps found for codec_id=%d", codec_id);
2304 /* Convert a FFMPEG Pixel Format and optional AVCodecContext
2305 * to a GstCaps. If the context is ommitted, no fixed values
2306 * for video/audio size will be included in the GstCaps
2308 * See below for usefullness
2312 gst_ffmpeg_pixfmt_to_caps (enum AVPixelFormat pix_fmt, AVCodecContext * context,
2313 enum AVCodecID codec_id)
2315 GstCaps *caps = NULL;
2316 GstVideoFormat format;
2318 format = gst_ffmpeg_pixfmt_to_videoformat (pix_fmt);
2320 if (format != GST_VIDEO_FORMAT_UNKNOWN) {
2321 caps = gst_ff_vid_caps_new (context, NULL, codec_id, TRUE, "video/x-raw",
2322 "format", G_TYPE_STRING, gst_video_format_to_string (format), NULL);
2326 GST_DEBUG ("caps for pix_fmt=%d: %" GST_PTR_FORMAT, pix_fmt, caps);
2328 GST_LOG ("No caps found for pix_fmt=%d", pix_fmt);
2335 gst_ffmpeg_smpfmt_to_audioformat (enum AVSampleFormat sample_fmt)
2337 switch (sample_fmt) {
2338 case AV_SAMPLE_FMT_U8:
2339 case AV_SAMPLE_FMT_U8P:
2340 return GST_AUDIO_FORMAT_U8;
2342 case AV_SAMPLE_FMT_S16:
2343 case AV_SAMPLE_FMT_S16P:
2344 return GST_AUDIO_FORMAT_S16;
2346 case AV_SAMPLE_FMT_S32:
2347 case AV_SAMPLE_FMT_S32P:
2348 return GST_AUDIO_FORMAT_S32;
2350 case AV_SAMPLE_FMT_FLT:
2351 case AV_SAMPLE_FMT_FLTP:
2352 return GST_AUDIO_FORMAT_F32;
2354 case AV_SAMPLE_FMT_DBL:
2355 case AV_SAMPLE_FMT_DBLP:
2356 return GST_AUDIO_FORMAT_F64;
2360 return GST_AUDIO_FORMAT_UNKNOWN;
2365 /* Convert a FFMPEG Sample Format and optional AVCodecContext
2366 * to a GstCaps. If the context is ommitted, no fixed values
2367 * for video/audio size will be included in the GstCaps
2369 * See below for usefullness
2373 gst_ffmpeg_smpfmt_to_caps (enum AVSampleFormat sample_fmt,
2374 AVCodecContext * context, AVCodec * codec, enum AVCodecID codec_id)
2376 GstCaps *caps = NULL;
2377 GstAudioFormat format;
2379 format = gst_ffmpeg_smpfmt_to_audioformat (sample_fmt);
2381 if (format != GST_AUDIO_FORMAT_UNKNOWN) {
2382 caps = gst_ff_aud_caps_new (context, codec, codec_id, TRUE, "audio/x-raw",
2383 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
2384 "layout", G_TYPE_STRING, "interleaved", NULL);
2385 GST_LOG ("caps for sample_fmt=%d: %" GST_PTR_FORMAT, sample_fmt, caps);
2387 GST_LOG ("No caps found for sample_fmt=%d", sample_fmt);
2394 caps_has_field (GstCaps * caps, const gchar * field)
2398 n = gst_caps_get_size (caps);
2399 for (i = 0; i < n; i++) {
2400 GstStructure *s = gst_caps_get_structure (caps, i);
2402 if (gst_structure_has_field (s, field))
2410 gst_ffmpeg_codectype_to_audio_caps (AVCodecContext * context,
2411 enum AVCodecID codec_id, gboolean encode, AVCodec * codec)
2413 GstCaps *caps = NULL;
2415 GST_DEBUG ("context:%p, codec_id:%d, encode:%d, codec:%p",
2416 context, codec_id, encode, codec);
2418 GST_DEBUG ("sample_fmts:%p, samplerates:%p",
2419 codec->sample_fmts, codec->supported_samplerates);
2422 /* Specific codec context */
2424 gst_ffmpeg_smpfmt_to_caps (context->sample_fmt, context, codec,
2427 caps = gst_ff_aud_caps_new (context, codec, codec_id, encode, "audio/x-raw",
2428 "layout", G_TYPE_STRING, "interleaved", NULL);
2429 if (!caps_has_field (caps, "format"))
2430 gst_ffmpeg_audio_set_sample_fmts (caps,
2431 codec ? codec->sample_fmts : NULL);
2438 gst_ffmpeg_codectype_to_video_caps (AVCodecContext * context,
2439 enum AVCodecID codec_id, gboolean encode, AVCodec * codec)
2443 GST_LOG ("context:%p, codec_id:%d, encode:%d, codec:%p",
2444 context, codec_id, encode, codec);
2447 caps = gst_ffmpeg_pixfmt_to_caps (context->pix_fmt, context, codec_id);
2450 gst_ff_vid_caps_new (context, codec, codec_id, encode, "video/x-raw",
2452 if (!caps_has_field (caps, "format"))
2453 gst_ffmpeg_video_set_pix_fmts (caps, codec ? codec->pix_fmts : NULL);
2458 /* Convert a GstCaps (audio/raw) to a FFMPEG SampleFmt
2459 * and other audio properties in a AVCodecContext.
2461 * For usefullness, see below
2465 gst_ffmpeg_caps_to_smpfmt (const GstCaps * caps,
2466 AVCodecContext * context, gboolean raw)
2468 GstStructure *structure;
2470 GstAudioFormat format = GST_AUDIO_FORMAT_UNKNOWN;
2473 g_return_if_fail (gst_caps_get_size (caps) == 1);
2475 structure = gst_caps_get_structure (caps, 0);
2477 gst_structure_get_int (structure, "channels", &context->channels);
2478 gst_structure_get_int (structure, "rate", &context->sample_rate);
2479 gst_structure_get_int (structure, "block_align", &context->block_align);
2480 if (gst_structure_get_int (structure, "bitrate", &bitrate))
2481 context->bit_rate = bitrate;
2486 if (gst_structure_has_name (structure, "audio/x-raw")) {
2487 if ((fmt = gst_structure_get_string (structure, "format"))) {
2488 format = gst_audio_format_from_string (fmt);
2493 case GST_AUDIO_FORMAT_F32:
2494 context->sample_fmt = AV_SAMPLE_FMT_FLT;
2496 case GST_AUDIO_FORMAT_F64:
2497 context->sample_fmt = AV_SAMPLE_FMT_DBL;
2499 case GST_AUDIO_FORMAT_S32:
2500 context->sample_fmt = AV_SAMPLE_FMT_S32;
2502 case GST_AUDIO_FORMAT_S16:
2503 context->sample_fmt = AV_SAMPLE_FMT_S16;
2510 /* Convert a GstCaps (video/raw) to a FFMPEG PixFmt
2511 * and other video properties in a AVCodecContext.
2513 * For usefullness, see below
2517 gst_ffmpeg_caps_to_pixfmt (const GstCaps * caps,
2518 AVCodecContext * context, gboolean raw)
2520 GstStructure *structure;
2522 const GValue *par = NULL;
2524 GstVideoFormat format = GST_VIDEO_FORMAT_UNKNOWN;
2527 GST_DEBUG ("converting caps %" GST_PTR_FORMAT, caps);
2528 g_return_if_fail (gst_caps_get_size (caps) == 1);
2529 structure = gst_caps_get_structure (caps, 0);
2531 gst_structure_get_int (structure, "width", &context->width);
2532 gst_structure_get_int (structure, "height", &context->height);
2533 gst_structure_get_int (structure, "bpp", &context->bits_per_coded_sample);
2535 fps = gst_structure_get_value (structure, "framerate");
2536 if (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps)) {
2538 int num = gst_value_get_fraction_numerator (fps);
2539 int den = gst_value_get_fraction_denominator (fps);
2541 if (num > 0 && den > 0) {
2542 /* somehow these seem mixed up.. */
2543 /* they're fine, this is because it does period=1/frequency */
2544 context->time_base.den = gst_value_get_fraction_numerator (fps);
2545 context->time_base.num = gst_value_get_fraction_denominator (fps);
2546 context->ticks_per_frame = 1;
2548 GST_DEBUG ("setting framerate %d/%d = %lf",
2549 context->time_base.den, context->time_base.num,
2550 1. * context->time_base.den / context->time_base.num);
2552 GST_INFO ("ignoring framerate %d/%d (probably variable framerate)",
2553 context->time_base.num, context->time_base.den);
2557 par = gst_structure_get_value (structure, "pixel-aspect-ratio");
2558 if (par && GST_VALUE_HOLDS_FRACTION (par)) {
2560 int num = gst_value_get_fraction_numerator (par);
2561 int den = gst_value_get_fraction_denominator (par);
2563 if (num > 0 && den > 0) {
2564 context->sample_aspect_ratio.num = num;
2565 context->sample_aspect_ratio.den = den;
2567 GST_DEBUG ("setting pixel-aspect-ratio %d/%d = %lf",
2568 context->sample_aspect_ratio.num, context->sample_aspect_ratio.den,
2569 1. * context->sample_aspect_ratio.num /
2570 context->sample_aspect_ratio.den);
2572 GST_WARNING ("ignoring insane pixel-aspect-ratio %d/%d",
2573 context->sample_aspect_ratio.num, context->sample_aspect_ratio.den);
2580 g_return_if_fail (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps));
2582 if (gst_structure_has_name (structure, "video/x-raw")) {
2583 if ((fmt = gst_structure_get_string (structure, "format"))) {
2584 format = gst_video_format_from_string (fmt);
2589 case GST_VIDEO_FORMAT_YUY2:
2590 context->pix_fmt = AV_PIX_FMT_YUYV422;
2592 case GST_VIDEO_FORMAT_I420:
2593 context->pix_fmt = AV_PIX_FMT_YUV420P;
2595 case GST_VIDEO_FORMAT_A420:
2596 context->pix_fmt = AV_PIX_FMT_YUVA420P;
2598 case GST_VIDEO_FORMAT_Y41B:
2599 context->pix_fmt = AV_PIX_FMT_YUV411P;
2601 case GST_VIDEO_FORMAT_Y42B:
2602 context->pix_fmt = AV_PIX_FMT_YUV422P;
2604 case GST_VIDEO_FORMAT_YUV9:
2605 context->pix_fmt = AV_PIX_FMT_YUV410P;
2607 case GST_VIDEO_FORMAT_Y444:
2608 context->pix_fmt = AV_PIX_FMT_YUV444P;
2610 case GST_VIDEO_FORMAT_GRAY8:
2611 context->pix_fmt = AV_PIX_FMT_GRAY8;
2613 case GST_VIDEO_FORMAT_xRGB:
2614 #if (G_BYTE_ORDER == G_BIG_ENDIAN)
2615 context->pix_fmt = AV_PIX_FMT_RGB32;
2618 case GST_VIDEO_FORMAT_BGRx:
2619 #if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
2620 context->pix_fmt = AV_PIX_FMT_RGB32;
2623 case GST_VIDEO_FORMAT_RGB:
2624 context->pix_fmt = AV_PIX_FMT_RGB24;
2626 case GST_VIDEO_FORMAT_BGR:
2627 context->pix_fmt = AV_PIX_FMT_BGR24;
2629 case GST_VIDEO_FORMAT_RGB16:
2630 context->pix_fmt = AV_PIX_FMT_RGB565;
2632 case GST_VIDEO_FORMAT_RGB15:
2633 context->pix_fmt = AV_PIX_FMT_RGB555;
2635 case GST_VIDEO_FORMAT_RGB8P:
2636 context->pix_fmt = AV_PIX_FMT_PAL8;
2642 s = gst_structure_get_string (structure, "interlace-mode");
2644 if (strcmp (s, "progressive") == 0) {
2645 context->field_order = AV_FIELD_PROGRESSIVE;
2646 } else if (strcmp (s, "interleaved") == 0) {
2647 s = gst_structure_get_string (structure, "field-order");
2649 if (strcmp (s, "top-field-first") == 0) {
2650 context->field_order = AV_FIELD_TT;
2651 } else if (strcmp (s, "bottom-field-first") == 0) {
2652 context->field_order = AV_FIELD_TB;
2661 GstVideoFormat format;
2662 enum AVPixelFormat pixfmt;
2665 /* FIXME : FILLME */
2666 static const PixToFmt pixtofmttable[] = {
2667 /* GST_VIDEO_FORMAT_I420, */
2668 {GST_VIDEO_FORMAT_I420, AV_PIX_FMT_YUV420P},
2669 /* Note : this should use a different chroma placement */
2670 {GST_VIDEO_FORMAT_I420, AV_PIX_FMT_YUVJ420P},
2672 /* GST_VIDEO_FORMAT_YV12, */
2673 /* GST_VIDEO_FORMAT_YUY2, */
2674 {GST_VIDEO_FORMAT_YUY2, AV_PIX_FMT_YUYV422},
2675 /* GST_VIDEO_FORMAT_UYVY, */
2676 {GST_VIDEO_FORMAT_UYVY, AV_PIX_FMT_UYVY422},
2677 /* GST_VIDEO_FORMAT_AYUV, */
2678 /* GST_VIDEO_FORMAT_RGBx, */
2679 {GST_VIDEO_FORMAT_RGBx, AV_PIX_FMT_RGB0},
2680 /* GST_VIDEO_FORMAT_BGRx, */
2681 {GST_VIDEO_FORMAT_BGRx, AV_PIX_FMT_BGR0},
2682 /* GST_VIDEO_FORMAT_xRGB, */
2683 {GST_VIDEO_FORMAT_xRGB, AV_PIX_FMT_0RGB},
2684 /* GST_VIDEO_FORMAT_xBGR, */
2685 {GST_VIDEO_FORMAT_xBGR, AV_PIX_FMT_0BGR},
2686 /* GST_VIDEO_FORMAT_RGBA, */
2687 {GST_VIDEO_FORMAT_RGBA, AV_PIX_FMT_RGBA},
2688 /* GST_VIDEO_FORMAT_BGRA, */
2689 {GST_VIDEO_FORMAT_BGRA, AV_PIX_FMT_BGRA},
2690 /* GST_VIDEO_FORMAT_ARGB, */
2691 {GST_VIDEO_FORMAT_ARGB, AV_PIX_FMT_ARGB},
2692 /* GST_VIDEO_FORMAT_ABGR, */
2693 {GST_VIDEO_FORMAT_ABGR, AV_PIX_FMT_ABGR},
2694 /* GST_VIDEO_FORMAT_RGB, */
2695 {GST_VIDEO_FORMAT_RGB, AV_PIX_FMT_RGB24},
2696 /* GST_VIDEO_FORMAT_BGR, */
2697 {GST_VIDEO_FORMAT_BGR, AV_PIX_FMT_BGR24},
2698 /* GST_VIDEO_FORMAT_Y41B, */
2699 {GST_VIDEO_FORMAT_Y41B, AV_PIX_FMT_YUV411P},
2700 /* GST_VIDEO_FORMAT_Y42B, */
2701 {GST_VIDEO_FORMAT_Y42B, AV_PIX_FMT_YUV422P},
2702 {GST_VIDEO_FORMAT_Y42B, AV_PIX_FMT_YUVJ422P},
2703 /* GST_VIDEO_FORMAT_YVYU, */
2704 /* GST_VIDEO_FORMAT_Y444, */
2705 {GST_VIDEO_FORMAT_Y444, AV_PIX_FMT_YUV444P},
2706 {GST_VIDEO_FORMAT_Y444, AV_PIX_FMT_YUVJ444P},
2707 /* GST_VIDEO_FORMAT_v210, */
2708 /* GST_VIDEO_FORMAT_v216, */
2709 /* GST_VIDEO_FORMAT_NV12, */
2710 {GST_VIDEO_FORMAT_NV12, AV_PIX_FMT_NV12},
2711 /* GST_VIDEO_FORMAT_NV21, */
2712 {GST_VIDEO_FORMAT_NV21, AV_PIX_FMT_NV21},
2713 /* GST_VIDEO_FORMAT_GRAY8, */
2714 {GST_VIDEO_FORMAT_GRAY8, AV_PIX_FMT_GRAY8},
2715 /* GST_VIDEO_FORMAT_GRAY16_BE, */
2716 {GST_VIDEO_FORMAT_GRAY16_BE, AV_PIX_FMT_GRAY16BE},
2717 /* GST_VIDEO_FORMAT_GRAY16_LE, */
2718 {GST_VIDEO_FORMAT_GRAY16_LE, AV_PIX_FMT_GRAY16LE},
2719 /* GST_VIDEO_FORMAT_v308, */
2720 /* GST_VIDEO_FORMAT_Y800, */
2721 /* GST_VIDEO_FORMAT_Y16, */
2722 /* GST_VIDEO_FORMAT_RGB16, */
2723 {GST_VIDEO_FORMAT_RGB16, AV_PIX_FMT_RGB565},
2724 /* GST_VIDEO_FORMAT_BGR16, */
2725 /* GST_VIDEO_FORMAT_RGB15, */
2726 {GST_VIDEO_FORMAT_RGB15, AV_PIX_FMT_RGB555},
2727 /* GST_VIDEO_FORMAT_BGR15, */
2728 /* GST_VIDEO_FORMAT_UYVP, */
2729 /* GST_VIDEO_FORMAT_A420, */
2730 {GST_VIDEO_FORMAT_A420, AV_PIX_FMT_YUVA420P},
2731 /* GST_VIDEO_FORMAT_RGB8_PALETTED, */
2732 {GST_VIDEO_FORMAT_RGB8P, AV_PIX_FMT_PAL8},
2733 /* GST_VIDEO_FORMAT_YUV9, */
2734 {GST_VIDEO_FORMAT_YUV9, AV_PIX_FMT_YUV410P},
2735 /* GST_VIDEO_FORMAT_YVU9, */
2736 /* GST_VIDEO_FORMAT_IYU1, */
2737 /* GST_VIDEO_FORMAT_ARGB64, */
2738 /* GST_VIDEO_FORMAT_AYUV64, */
2739 /* GST_VIDEO_FORMAT_r210, */
2740 {GST_VIDEO_FORMAT_I420_10LE, AV_PIX_FMT_YUV420P10LE},
2741 {GST_VIDEO_FORMAT_I420_10BE, AV_PIX_FMT_YUV420P10BE},
2742 {GST_VIDEO_FORMAT_I422_10LE, AV_PIX_FMT_YUV422P10LE},
2743 {GST_VIDEO_FORMAT_I422_10BE, AV_PIX_FMT_YUV422P10BE},
2744 {GST_VIDEO_FORMAT_Y444_10LE, AV_PIX_FMT_YUV444P10LE},
2745 {GST_VIDEO_FORMAT_Y444_10BE, AV_PIX_FMT_YUV444P10BE},
2746 {GST_VIDEO_FORMAT_GBR, AV_PIX_FMT_GBRP},
2747 {GST_VIDEO_FORMAT_GBRA, AV_PIX_FMT_GBRAP},
2748 {GST_VIDEO_FORMAT_GBR_10LE, AV_PIX_FMT_GBRP10LE},
2749 {GST_VIDEO_FORMAT_GBR_10BE, AV_PIX_FMT_GBRP10BE},
2750 {GST_VIDEO_FORMAT_GBR_12LE, AV_PIX_FMT_GBRP12LE},
2751 {GST_VIDEO_FORMAT_GBR_12BE, AV_PIX_FMT_GBRP12BE},
2752 {GST_VIDEO_FORMAT_GBRA_12LE, AV_PIX_FMT_GBRAP12LE},
2753 {GST_VIDEO_FORMAT_GBRA_12BE, AV_PIX_FMT_GBRAP12BE},
2754 {GST_VIDEO_FORMAT_A420_10LE, AV_PIX_FMT_YUVA420P10LE},
2755 {GST_VIDEO_FORMAT_A420_10BE, AV_PIX_FMT_YUVA420P10BE},
2756 {GST_VIDEO_FORMAT_A422_10LE, AV_PIX_FMT_YUVA422P10LE},
2757 {GST_VIDEO_FORMAT_A422_10BE, AV_PIX_FMT_YUVA422P10BE},
2758 {GST_VIDEO_FORMAT_A444_10LE, AV_PIX_FMT_YUVA444P10LE},
2759 {GST_VIDEO_FORMAT_A444_10BE, AV_PIX_FMT_YUVA444P10BE},
2760 {GST_VIDEO_FORMAT_I420_12LE, AV_PIX_FMT_YUV420P12LE},
2761 {GST_VIDEO_FORMAT_I420_12BE, AV_PIX_FMT_YUV420P12BE},
2762 {GST_VIDEO_FORMAT_I422_12LE, AV_PIX_FMT_YUV422P12LE},
2763 {GST_VIDEO_FORMAT_I422_12BE, AV_PIX_FMT_YUV422P12BE},
2764 {GST_VIDEO_FORMAT_Y444_12LE, AV_PIX_FMT_YUV444P12LE},
2765 {GST_VIDEO_FORMAT_Y444_12BE, AV_PIX_FMT_YUV444P12BE},
2769 gst_ffmpeg_pixfmt_to_videoformat (enum AVPixelFormat pixfmt)
2773 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2774 if (pixtofmttable[i].pixfmt == pixfmt)
2775 return pixtofmttable[i].format;
2777 GST_DEBUG ("Unknown pixel format %d", pixfmt);
2778 return GST_VIDEO_FORMAT_UNKNOWN;
2781 static enum AVPixelFormat
2782 gst_ffmpeg_videoformat_to_pixfmt_for_codec (GstVideoFormat format,
2783 const AVCodec * codec)
2787 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++) {
2788 if (pixtofmttable[i].format == format) {
2791 if (codec && codec->pix_fmts) {
2792 for (j = 0; codec->pix_fmts[j] != -1; j++) {
2793 if (pixtofmttable[i].pixfmt == codec->pix_fmts[j])
2794 return pixtofmttable[i].pixfmt;
2797 return pixtofmttable[i].pixfmt;
2802 return AV_PIX_FMT_NONE;
2806 gst_ffmpeg_videoformat_to_pixfmt (GstVideoFormat format)
2808 return gst_ffmpeg_videoformat_to_pixfmt_for_codec (format, NULL);
2812 gst_ffmpeg_videoinfo_to_context (GstVideoInfo * info, AVCodecContext * context)
2816 context->width = GST_VIDEO_INFO_WIDTH (info);
2817 context->height = GST_VIDEO_INFO_HEIGHT (info);
2818 for (i = 0; i < GST_VIDEO_INFO_N_COMPONENTS (info); i++)
2819 bpp += GST_VIDEO_INFO_COMP_DEPTH (info, i);
2820 context->bits_per_coded_sample = bpp;
2822 context->ticks_per_frame = 1;
2823 if (GST_VIDEO_INFO_FPS_N (info) == 0) {
2824 GST_DEBUG ("Using 25/1 framerate");
2825 context->time_base.den = 25;
2826 context->time_base.num = 1;
2828 context->time_base.den = GST_VIDEO_INFO_FPS_N (info);
2829 context->time_base.num = GST_VIDEO_INFO_FPS_D (info);
2832 context->sample_aspect_ratio.num = GST_VIDEO_INFO_PAR_N (info);
2833 context->sample_aspect_ratio.den = GST_VIDEO_INFO_PAR_D (info);
2836 gst_ffmpeg_videoformat_to_pixfmt_for_codec (GST_VIDEO_INFO_FORMAT (info),
2839 switch (info->chroma_site) {
2840 case GST_VIDEO_CHROMA_SITE_MPEG2:
2841 context->chroma_sample_location = AVCHROMA_LOC_LEFT;
2843 case GST_VIDEO_CHROMA_SITE_JPEG:
2844 context->chroma_sample_location = AVCHROMA_LOC_CENTER;
2846 case GST_VIDEO_CHROMA_SITE_DV:
2847 context->chroma_sample_location = AVCHROMA_LOC_TOPLEFT;
2849 case GST_VIDEO_CHROMA_SITE_V_COSITED:
2850 context->chroma_sample_location = AVCHROMA_LOC_TOP;
2856 switch (info->colorimetry.primaries) {
2857 case GST_VIDEO_COLOR_PRIMARIES_BT709:
2858 context->color_primaries = AVCOL_PRI_BT709;
2860 case GST_VIDEO_COLOR_PRIMARIES_BT470M:
2861 context->color_primaries = AVCOL_PRI_BT470M;
2863 case GST_VIDEO_COLOR_PRIMARIES_BT470BG:
2864 context->color_primaries = AVCOL_PRI_BT470BG;
2866 case GST_VIDEO_COLOR_PRIMARIES_SMPTE170M:
2867 context->color_primaries = AVCOL_PRI_SMPTE170M;
2869 case GST_VIDEO_COLOR_PRIMARIES_SMPTE240M:
2870 context->color_primaries = AVCOL_PRI_SMPTE240M;
2872 case GST_VIDEO_COLOR_PRIMARIES_FILM:
2873 context->color_primaries = AVCOL_PRI_FILM;
2875 case GST_VIDEO_COLOR_PRIMARIES_BT2020:
2876 context->color_primaries = AVCOL_PRI_BT2020;
2882 switch (info->colorimetry.transfer) {
2883 case GST_VIDEO_TRANSFER_BT709:
2884 context->color_trc = AVCOL_TRC_BT709;
2886 case GST_VIDEO_TRANSFER_GAMMA22:
2887 context->color_trc = AVCOL_TRC_GAMMA22;
2889 case GST_VIDEO_TRANSFER_GAMMA28:
2890 context->color_trc = AVCOL_TRC_GAMMA28;
2892 case GST_VIDEO_TRANSFER_SMPTE240M:
2893 context->color_trc = AVCOL_TRC_SMPTE240M;
2895 case GST_VIDEO_TRANSFER_GAMMA10:
2896 context->color_trc = AVCOL_TRC_LINEAR;
2898 case GST_VIDEO_TRANSFER_LOG100:
2899 context->color_trc = AVCOL_TRC_LOG;
2901 case GST_VIDEO_TRANSFER_LOG316:
2902 context->color_trc = AVCOL_TRC_LOG_SQRT;
2904 case GST_VIDEO_TRANSFER_BT2020_12:
2905 context->color_trc = AVCOL_TRC_BT2020_12;
2911 switch (info->colorimetry.matrix) {
2912 case GST_VIDEO_COLOR_MATRIX_RGB:
2913 context->colorspace = AVCOL_SPC_RGB;
2915 case GST_VIDEO_COLOR_MATRIX_BT709:
2916 context->colorspace = AVCOL_SPC_BT709;
2918 case GST_VIDEO_COLOR_MATRIX_FCC:
2919 context->colorspace = AVCOL_SPC_FCC;
2921 case GST_VIDEO_COLOR_MATRIX_BT601:
2922 context->colorspace = AVCOL_SPC_BT470BG;
2924 case GST_VIDEO_COLOR_MATRIX_SMPTE240M:
2925 context->colorspace = AVCOL_SPC_SMPTE240M;
2927 case GST_VIDEO_COLOR_MATRIX_BT2020:
2928 context->colorspace = AVCOL_SPC_BT2020_NCL;
2934 if (info->colorimetry.range == GST_VIDEO_COLOR_RANGE_0_255) {
2935 context->color_range = AVCOL_RANGE_JPEG;
2937 context->color_range = AVCOL_RANGE_MPEG;
2942 gst_ffmpeg_audioinfo_to_context (GstAudioInfo * info, AVCodecContext * context)
2944 const AVCodec *codec;
2945 const enum AVSampleFormat *smpl_fmts;
2946 enum AVSampleFormat smpl_fmt = -1;
2948 context->channels = info->channels;
2949 context->sample_rate = info->rate;
2950 context->channel_layout =
2951 gst_ffmpeg_channel_positions_to_layout (info->position, info->channels);
2953 codec = context->codec;
2955 smpl_fmts = codec->sample_fmts;
2957 switch (info->finfo->format) {
2958 case GST_AUDIO_FORMAT_F32:
2960 while (*smpl_fmts != -1) {
2961 if (*smpl_fmts == AV_SAMPLE_FMT_FLT) {
2962 smpl_fmt = *smpl_fmts;
2964 } else if (*smpl_fmts == AV_SAMPLE_FMT_FLTP) {
2965 smpl_fmt = *smpl_fmts;
2971 smpl_fmt = AV_SAMPLE_FMT_FLT;
2974 case GST_AUDIO_FORMAT_F64:
2976 while (*smpl_fmts != -1) {
2977 if (*smpl_fmts == AV_SAMPLE_FMT_DBL) {
2978 smpl_fmt = *smpl_fmts;
2980 } else if (*smpl_fmts == AV_SAMPLE_FMT_DBLP) {
2981 smpl_fmt = *smpl_fmts;
2987 smpl_fmt = AV_SAMPLE_FMT_DBL;
2990 case GST_AUDIO_FORMAT_S32:
2992 while (*smpl_fmts != -1) {
2993 if (*smpl_fmts == AV_SAMPLE_FMT_S32) {
2994 smpl_fmt = *smpl_fmts;
2996 } else if (*smpl_fmts == AV_SAMPLE_FMT_S32P) {
2997 smpl_fmt = *smpl_fmts;
3003 smpl_fmt = AV_SAMPLE_FMT_S32;
3006 case GST_AUDIO_FORMAT_S16:
3008 while (*smpl_fmts != -1) {
3009 if (*smpl_fmts == AV_SAMPLE_FMT_S16) {
3010 smpl_fmt = *smpl_fmts;
3012 } else if (*smpl_fmts == AV_SAMPLE_FMT_S16P) {
3013 smpl_fmt = *smpl_fmts;
3019 smpl_fmt = AV_SAMPLE_FMT_S16;
3022 case GST_AUDIO_FORMAT_U8:
3024 while (*smpl_fmts != -1) {
3025 if (*smpl_fmts == AV_SAMPLE_FMT_U8) {
3026 smpl_fmt = *smpl_fmts;
3028 } else if (*smpl_fmts == AV_SAMPLE_FMT_U8P) {
3029 smpl_fmt = *smpl_fmts;
3035 smpl_fmt = AV_SAMPLE_FMT_U8;
3042 g_assert (smpl_fmt != -1);
3044 context->sample_fmt = smpl_fmt;
3047 /* Convert a GstCaps and a FFMPEG codec Type to a
3048 * AVCodecContext. If the context is ommitted, no fixed values
3049 * for video/audio size will be included in the context
3051 * AVMediaType is primarily meant for uncompressed data GstCaps!
3055 gst_ffmpeg_caps_with_codectype (enum AVMediaType type,
3056 const GstCaps * caps, AVCodecContext * context)
3058 if (context == NULL)
3062 case AVMEDIA_TYPE_VIDEO:
3063 gst_ffmpeg_caps_to_pixfmt (caps, context, TRUE);
3066 case AVMEDIA_TYPE_AUDIO:
3067 gst_ffmpeg_caps_to_smpfmt (caps, context, TRUE);
3078 nal_escape (guint8 * dst, guint8 * src, guint size, guint * destsize)
3082 guint8 *end = src + size;
3085 while (srcp < end) {
3086 if (count == 2 && *srcp <= 0x03) {
3087 GST_DEBUG ("added escape code");
3096 GST_DEBUG ("copy %02x, count %d", *srcp, count);
3099 *destsize = dstp - dst;
3102 /* copy the config, escaping NAL units as we iterate them, if something fails we
3103 * copy everything and hope for the best. */
3105 copy_config (guint8 * dst, guint8 * src, guint size, guint * destsize)
3110 guint nalsize, esize;
3120 cnt = *(srcp + 5) & 0x1f; /* Number of sps */
3122 GST_DEBUG ("num SPS %d", cnt);
3124 memcpy (dstp, srcp, 6);
3128 for (i = 0; i < cnt; i++) {
3129 GST_DEBUG ("copy SPS %d", i);
3130 nalsize = (srcp[0] << 8) | srcp[1];
3131 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
3132 dstp[0] = esize >> 8;
3133 dstp[1] = esize & 0xff;
3135 srcp += nalsize + 2;
3138 cnt = *(dstp++) = *(srcp++); /* Number of pps */
3140 GST_DEBUG ("num PPS %d", cnt);
3142 for (i = 0; i < cnt; i++) {
3143 GST_DEBUG ("copy PPS %d", i);
3144 nalsize = (srcp[0] << 8) | srcp[1];
3145 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
3146 dstp[0] = esize >> 8;
3147 dstp[1] = esize & 0xff;
3149 srcp += nalsize + 2;
3151 *destsize = dstp - dst;
3157 GST_DEBUG ("something unexpected, doing full copy");
3158 memcpy (dst, src, size);
3166 * caps_with_codecid () transforms a GstCaps for a known codec
3167 * ID into a filled-in context.
3168 * codec_data from caps will override possible extradata already in the context
3172 gst_ffmpeg_caps_with_codecid (enum AVCodecID codec_id,
3173 enum AVMediaType codec_type, const GstCaps * caps, AVCodecContext * context)
3176 const GValue *value;
3179 GST_LOG ("codec_id:%d, codec_type:%d, caps:%" GST_PTR_FORMAT " context:%p",
3180 codec_id, codec_type, caps, context);
3182 if (!context || !gst_caps_get_size (caps))
3185 str = gst_caps_get_structure (caps, 0);
3187 /* extradata parsing (esds [mpeg4], wma/wmv, msmpeg4v1/2/3, etc.) */
3188 if ((value = gst_structure_get_value (str, "codec_data"))) {
3191 buf = gst_value_get_buffer (value);
3192 gst_buffer_map (buf, &map, GST_MAP_READ);
3194 /* free the old one if it is there */
3195 if (context->extradata)
3196 av_free (context->extradata);
3199 if (codec_id == AV_CODEC_ID_H264) {
3202 GST_DEBUG ("copy, escaping codec_data %d", size);
3203 /* ffmpeg h264 expects the codec_data to be escaped, there is no real
3204 * reason for this but let's just escape it for now. Start by allocating
3205 * enough space, x2 is more than enough.
3207 * FIXME, we disabled escaping because some file already contain escaped
3208 * codec_data and then we escape twice and fail. It's better to leave it
3209 * as is, as that is what most players do. */
3210 context->extradata =
3211 av_mallocz (GST_ROUND_UP_16 (size * 2 +
3212 AV_INPUT_BUFFER_PADDING_SIZE));
3213 copy_config (context->extradata, data, size, &extrasize);
3214 GST_DEBUG ("escaped size: %d", extrasize);
3215 context->extradata_size = extrasize;
3219 /* allocate with enough padding */
3220 GST_DEBUG ("copy codec_data");
3221 context->extradata =
3222 av_mallocz (GST_ROUND_UP_16 (map.size +
3223 AV_INPUT_BUFFER_PADDING_SIZE));
3224 memcpy (context->extradata, map.data, map.size);
3225 context->extradata_size = map.size;
3228 /* Hack for VC1. Sometimes the first (length) byte is 0 for some files */
3229 if (codec_id == AV_CODEC_ID_VC1 && map.size > 0 && map.data[0] == 0) {
3230 context->extradata[0] = (guint8) map.size;
3233 GST_DEBUG ("have codec data of size %" G_GSIZE_FORMAT, map.size);
3235 gst_buffer_unmap (buf, &map);
3237 context->extradata = NULL;
3238 context->extradata_size = 0;
3239 GST_DEBUG ("no codec data");
3243 case AV_CODEC_ID_MPEG4:
3245 const gchar *mime = gst_structure_get_name (str);
3247 context->flags |= CODEC_FLAG_4MV;
3249 if (!strcmp (mime, "video/x-divx"))
3250 context->codec_tag = GST_MAKE_FOURCC ('D', 'I', 'V', 'X');
3251 else if (!strcmp (mime, "video/mpeg")) {
3252 const gchar *profile;
3254 context->codec_tag = GST_MAKE_FOURCC ('m', 'p', '4', 'v');
3256 profile = gst_structure_get_string (str, "profile");
3258 if (g_strcmp0 (profile, "advanced-simple") == 0)
3259 context->flags |= CODEC_FLAG_GMC | CODEC_FLAG_QPEL;
3265 case AV_CODEC_ID_SVQ3:
3266 /* FIXME: this is a workaround for older gst-plugins releases
3267 * (<= 0.8.9). This should be removed at some point, because
3268 * it causes wrong decoded frame order. */
3269 if (!context->extradata) {
3270 gint halfpel_flag, thirdpel_flag, low_delay, unknown_svq3_flag;
3273 if (gst_structure_get_int (str, "halfpel_flag", &halfpel_flag) &&
3274 gst_structure_get_int (str, "thirdpel_flag", &thirdpel_flag) &&
3275 gst_structure_get_int (str, "low_delay", &low_delay) &&
3276 gst_structure_get_int (str, "unknown_svq3_flag",
3277 &unknown_svq3_flag)) {
3278 context->extradata = (guint8 *) av_mallocz (0x64);
3279 g_stpcpy ((gchar *) context->extradata, "SVQ3");
3283 flags |= unknown_svq3_flag;
3285 flags |= halfpel_flag;
3287 flags |= thirdpel_flag;
3290 flags = GUINT16_FROM_LE (flags);
3292 memcpy ((gchar *) context->extradata + 0x62, &flags, 2);
3293 context->extradata_size = 0x64;
3298 case AV_CODEC_ID_MSRLE:
3299 case AV_CODEC_ID_QTRLE:
3300 case AV_CODEC_ID_TSCC:
3301 case AV_CODEC_ID_CSCD:
3302 case AV_CODEC_ID_APE:
3306 if (gst_structure_get_int (str, "depth", &depth)) {
3307 context->bits_per_coded_sample = depth;
3309 GST_WARNING ("No depth field in caps %" GST_PTR_FORMAT, caps);
3315 case AV_CODEC_ID_COOK:
3316 case AV_CODEC_ID_RA_288:
3317 case AV_CODEC_ID_RA_144:
3318 case AV_CODEC_ID_SIPR:
3323 if (gst_structure_get_int (str, "leaf_size", &leaf_size))
3324 context->block_align = leaf_size;
3325 if (gst_structure_get_int (str, "bitrate", &bitrate))
3326 context->bit_rate = bitrate;
3329 case AV_CODEC_ID_ALAC:
3330 gst_structure_get_int (str, "samplesize",
3331 &context->bits_per_coded_sample);
3334 case AV_CODEC_ID_DVVIDEO:
3336 const gchar *format;
3338 if ((format = gst_structure_get_string (str, "format"))) {
3340 if (g_str_equal (format, "YUY2"))
3341 context->pix_fmt = AV_PIX_FMT_YUYV422;
3342 else if (g_str_equal (format, "I420"))
3343 context->pix_fmt = AV_PIX_FMT_YUV420P;
3344 else if (g_str_equal (format, "A420"))
3345 context->pix_fmt = AV_PIX_FMT_YUVA420P;
3346 else if (g_str_equal (format, "Y41B"))
3347 context->pix_fmt = AV_PIX_FMT_YUV411P;
3348 else if (g_str_equal (format, "Y42B"))
3349 context->pix_fmt = AV_PIX_FMT_YUV422P;
3350 else if (g_str_equal (format, "YUV9"))
3351 context->pix_fmt = AV_PIX_FMT_YUV410P;
3353 GST_WARNING ("couldn't convert format %s" " to a pixel format",
3357 GST_WARNING ("No specified format");
3360 case AV_CODEC_ID_H263P:
3364 if (!gst_structure_get_boolean (str, "annex-f", &val) || val)
3365 context->flags |= CODEC_FLAG_4MV;
3367 context->flags &= ~CODEC_FLAG_4MV;
3368 if ((!gst_structure_get_boolean (str, "annex-i", &val) || val) &&
3369 (!gst_structure_get_boolean (str, "annex-t", &val) || val))
3370 context->flags |= CODEC_FLAG_AC_PRED;
3372 context->flags &= ~CODEC_FLAG_AC_PRED;
3373 if (!gst_structure_get_boolean (str, "annex-j", &val) || val)
3374 context->flags |= CODEC_FLAG_LOOP_FILTER;
3376 context->flags &= ~CODEC_FLAG_LOOP_FILTER;
3379 case AV_CODEC_ID_ADPCM_G726:
3381 const gchar *layout;
3383 if ((layout = gst_structure_get_string (str, "layout"))) {
3384 if (!strcmp (layout, "g721")) {
3385 context->sample_rate = 8000;
3386 context->channels = 1;
3387 context->bit_rate = 32000;
3396 if (!gst_caps_is_fixed (caps))
3399 /* common properties (width, height, fps) */
3400 switch (codec_type) {
3401 case AVMEDIA_TYPE_VIDEO:
3402 gst_ffmpeg_caps_to_pixfmt (caps, context,
3403 codec_id == AV_CODEC_ID_RAWVIDEO);
3405 case AVMEDIA_TYPE_AUDIO:
3406 gst_ffmpeg_caps_to_smpfmt (caps, context, FALSE);
3412 /* fixup of default settings */
3414 case AV_CODEC_ID_QCELP:
3415 /* QCELP is always mono, no matter what the caps say */
3416 context->channels = 1;
3418 case AV_CODEC_ID_ADPCM_G726:
3419 if (context->sample_rate && context->bit_rate)
3420 context->bits_per_coded_sample =
3421 context->bit_rate / context->sample_rate;
3428 /* _formatid_to_caps () is meant for muxers/demuxers, it
3429 * transforms a name (ffmpeg way of ID'ing these, why don't
3430 * they have unique numerical IDs?) to the corresponding
3431 * caps belonging to that mux-format
3433 * Note: we don't need any additional info because the caps
3434 * isn't supposed to contain any useful info besides the
3439 gst_ffmpeg_formatid_to_caps (const gchar * format_name)
3441 GstCaps *caps = NULL;
3443 if (!strcmp (format_name, "mpeg")) {
3444 caps = gst_caps_new_simple ("video/mpeg",
3445 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3446 } else if (!strcmp (format_name, "mpegts")) {
3447 caps = gst_caps_new_simple ("video/mpegts",
3448 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3449 } else if (!strcmp (format_name, "rm")) {
3450 caps = gst_caps_new_simple ("application/x-pn-realmedia",
3451 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3452 } else if (!strcmp (format_name, "asf")) {
3453 caps = gst_caps_new_empty_simple ("video/x-ms-asf");
3454 } else if (!strcmp (format_name, "avi")) {
3455 caps = gst_caps_new_empty_simple ("video/x-msvideo");
3456 } else if (!strcmp (format_name, "wav")) {
3457 caps = gst_caps_new_empty_simple ("audio/x-wav");
3458 } else if (!strcmp (format_name, "ape")) {
3459 caps = gst_caps_new_empty_simple ("application/x-ape");
3460 } else if (!strcmp (format_name, "swf")) {
3461 caps = gst_caps_new_empty_simple ("application/x-shockwave-flash");
3462 } else if (!strcmp (format_name, "au")) {
3463 caps = gst_caps_new_empty_simple ("audio/x-au");
3464 } else if (!strcmp (format_name, "dv")) {
3465 caps = gst_caps_new_simple ("video/x-dv",
3466 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3467 } else if (!strcmp (format_name, "4xm")) {
3468 caps = gst_caps_new_empty_simple ("video/x-4xm");
3469 } else if (!strcmp (format_name, "matroska")) {
3470 caps = gst_caps_new_empty_simple ("video/x-matroska");
3471 } else if (!strcmp (format_name, "ivf")) {
3472 caps = gst_caps_new_empty_simple ("video/x-ivf");
3473 } else if (!strcmp (format_name, "mp3")) {
3474 caps = gst_caps_new_empty_simple ("application/x-id3");
3475 } else if (!strcmp (format_name, "flic")) {
3476 caps = gst_caps_new_empty_simple ("video/x-fli");
3477 } else if (!strcmp (format_name, "flv")) {
3478 caps = gst_caps_new_empty_simple ("video/x-flv");
3479 } else if (!strcmp (format_name, "tta")) {
3480 caps = gst_caps_new_empty_simple ("audio/x-ttafile");
3481 } else if (!strcmp (format_name, "aiff")) {
3482 caps = gst_caps_new_empty_simple ("audio/x-aiff");
3483 } else if (!strcmp (format_name, "mov_mp4_m4a_3gp_3g2")) {
3485 gst_caps_from_string
3486 ("application/x-3gp; video/quicktime; audio/x-m4a");
3487 } else if (!strcmp (format_name, "mov")) {
3488 caps = gst_caps_from_string ("video/quicktime,variant=(string)apple");
3489 } else if (!strcmp (format_name, "mp4")) {
3490 caps = gst_caps_from_string ("video/quicktime,variant=(string)iso");
3491 } else if (!strcmp (format_name, "3gp")) {
3492 caps = gst_caps_from_string ("video/quicktime,variant=(string)3gpp");
3493 } else if (!strcmp (format_name, "3g2")) {
3494 caps = gst_caps_from_string ("video/quicktime,variant=(string)3g2");
3495 } else if (!strcmp (format_name, "psp")) {
3496 caps = gst_caps_from_string ("video/quicktime,variant=(string)psp");
3497 } else if (!strcmp (format_name, "ipod")) {
3498 caps = gst_caps_from_string ("video/quicktime,variant=(string)ipod");
3499 } else if (!strcmp (format_name, "aac")) {
3500 caps = gst_caps_new_simple ("audio/mpeg",
3501 "mpegversion", G_TYPE_INT, 4, NULL);
3502 } else if (!strcmp (format_name, "gif")) {
3503 caps = gst_caps_from_string ("image/gif");
3504 } else if (!strcmp (format_name, "ogg")) {
3505 caps = gst_caps_from_string ("application/ogg");
3506 } else if (!strcmp (format_name, "mxf") || !strcmp (format_name, "mxf_d10")) {
3507 caps = gst_caps_from_string ("application/mxf");
3508 } else if (!strcmp (format_name, "gxf")) {
3509 caps = gst_caps_from_string ("application/gxf");
3510 } else if (!strcmp (format_name, "yuv4mpegpipe")) {
3511 caps = gst_caps_new_simple ("application/x-yuv4mpeg",
3512 "y4mversion", G_TYPE_INT, 2, NULL);
3513 } else if (!strcmp (format_name, "mpc")) {
3514 caps = gst_caps_from_string ("audio/x-musepack, streamversion = (int) 7");
3515 } else if (!strcmp (format_name, "mpc8")) {
3516 caps = gst_caps_from_string ("audio/x-musepack, streamversion = (int) 8");
3517 } else if (!strcmp (format_name, "vqf")) {
3518 caps = gst_caps_from_string ("audio/x-vqf");
3519 } else if (!strcmp (format_name, "nsv")) {
3520 caps = gst_caps_from_string ("video/x-nsv");
3521 } else if (!strcmp (format_name, "amr")) {
3522 caps = gst_caps_from_string ("audio/x-amr-nb-sh");
3523 } else if (!strcmp (format_name, "webm")) {
3524 caps = gst_caps_from_string ("video/webm");
3525 } else if (!strcmp (format_name, "voc")) {
3526 caps = gst_caps_from_string ("audio/x-voc");
3527 } else if (!strcmp (format_name, "pva")) {
3528 caps = gst_caps_from_string ("video/x-pva");
3529 } else if (!strcmp (format_name, "brstm")) {
3530 caps = gst_caps_from_string ("audio/x-brstm");
3531 } else if (!strcmp (format_name, "bfstm")) {
3532 caps = gst_caps_from_string ("audio/x-bfstm");
3536 GST_LOG ("Could not create stream format caps for %s", format_name);
3537 name = g_strdup_printf ("application/x-gst-av-%s", format_name);
3538 caps = gst_caps_new_empty_simple (name);
3546 gst_ffmpeg_formatid_get_codecids (const gchar * format_name,
3547 enum AVCodecID ** video_codec_list, enum AVCodecID ** audio_codec_list,
3548 AVOutputFormat * plugin)
3550 static enum AVCodecID tmp_vlist[] = {
3554 static enum AVCodecID tmp_alist[] = {
3559 GST_LOG ("format_name : %s", format_name);
3561 if (!strcmp (format_name, "mp4")) {
3562 static enum AVCodecID mp4_video_list[] = {
3563 AV_CODEC_ID_MPEG4, AV_CODEC_ID_H264,
3567 static enum AVCodecID mp4_audio_list[] = {
3568 AV_CODEC_ID_AAC, AV_CODEC_ID_MP3,
3572 *video_codec_list = mp4_video_list;
3573 *audio_codec_list = mp4_audio_list;
3574 } else if (!strcmp (format_name, "mpeg")) {
3575 static enum AVCodecID mpeg_video_list[] = { AV_CODEC_ID_MPEG1VIDEO,
3576 AV_CODEC_ID_MPEG2VIDEO,
3580 static enum AVCodecID mpeg_audio_list[] = { AV_CODEC_ID_MP1,
3586 *video_codec_list = mpeg_video_list;
3587 *audio_codec_list = mpeg_audio_list;
3588 } else if (!strcmp (format_name, "dvd")) {
3589 static enum AVCodecID mpeg_video_list[] = { AV_CODEC_ID_MPEG2VIDEO,
3592 static enum AVCodecID mpeg_audio_list[] = { AV_CODEC_ID_MP2,
3595 AV_CODEC_ID_PCM_S16BE,
3599 *video_codec_list = mpeg_video_list;
3600 *audio_codec_list = mpeg_audio_list;
3601 } else if (!strcmp (format_name, "mpegts")) {
3602 static enum AVCodecID mpegts_video_list[] = { AV_CODEC_ID_MPEG1VIDEO,
3603 AV_CODEC_ID_MPEG2VIDEO,
3607 static enum AVCodecID mpegts_audio_list[] = { AV_CODEC_ID_MP2,
3615 *video_codec_list = mpegts_video_list;
3616 *audio_codec_list = mpegts_audio_list;
3617 } else if (!strcmp (format_name, "vob")) {
3618 static enum AVCodecID vob_video_list[] =
3619 { AV_CODEC_ID_MPEG2VIDEO, AV_CODEC_ID_NONE };
3620 static enum AVCodecID vob_audio_list[] = { AV_CODEC_ID_MP2, AV_CODEC_ID_AC3,
3621 AV_CODEC_ID_DTS, AV_CODEC_ID_NONE
3624 *video_codec_list = vob_video_list;
3625 *audio_codec_list = vob_audio_list;
3626 } else if (!strcmp (format_name, "flv")) {
3627 static enum AVCodecID flv_video_list[] =
3628 { AV_CODEC_ID_FLV1, AV_CODEC_ID_NONE };
3629 static enum AVCodecID flv_audio_list[] =
3630 { AV_CODEC_ID_MP3, AV_CODEC_ID_NONE };
3632 *video_codec_list = flv_video_list;
3633 *audio_codec_list = flv_audio_list;
3634 } else if (!strcmp (format_name, "asf")) {
3635 static enum AVCodecID asf_video_list[] =
3636 { AV_CODEC_ID_WMV1, AV_CODEC_ID_WMV2, AV_CODEC_ID_MSMPEG4V3,
3639 static enum AVCodecID asf_audio_list[] =
3640 { AV_CODEC_ID_WMAV1, AV_CODEC_ID_WMAV2, AV_CODEC_ID_MP3,
3644 *video_codec_list = asf_video_list;
3645 *audio_codec_list = asf_audio_list;
3646 } else if (!strcmp (format_name, "dv")) {
3647 static enum AVCodecID dv_video_list[] =
3648 { AV_CODEC_ID_DVVIDEO, AV_CODEC_ID_NONE };
3649 static enum AVCodecID dv_audio_list[] =
3650 { AV_CODEC_ID_PCM_S16LE, AV_CODEC_ID_NONE };
3652 *video_codec_list = dv_video_list;
3653 *audio_codec_list = dv_audio_list;
3654 } else if (!strcmp (format_name, "mov")) {
3655 static enum AVCodecID mov_video_list[] = {
3656 AV_CODEC_ID_SVQ1, AV_CODEC_ID_SVQ3, AV_CODEC_ID_MPEG4,
3657 AV_CODEC_ID_H263, AV_CODEC_ID_H263P,
3658 AV_CODEC_ID_H264, AV_CODEC_ID_DVVIDEO,
3662 static enum AVCodecID mov_audio_list[] = {
3663 AV_CODEC_ID_PCM_MULAW, AV_CODEC_ID_PCM_ALAW, AV_CODEC_ID_ADPCM_IMA_QT,
3664 AV_CODEC_ID_MACE3, AV_CODEC_ID_MACE6, AV_CODEC_ID_AAC,
3665 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3666 AV_CODEC_ID_PCM_S16BE, AV_CODEC_ID_PCM_S16LE,
3667 AV_CODEC_ID_MP3, AV_CODEC_ID_NONE
3670 *video_codec_list = mov_video_list;
3671 *audio_codec_list = mov_audio_list;
3672 } else if ((!strcmp (format_name, "3gp") || !strcmp (format_name, "3g2"))) {
3673 static enum AVCodecID tgp_video_list[] = {
3674 AV_CODEC_ID_MPEG4, AV_CODEC_ID_H263, AV_CODEC_ID_H263P, AV_CODEC_ID_H264,
3677 static enum AVCodecID tgp_audio_list[] = {
3678 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3683 *video_codec_list = tgp_video_list;
3684 *audio_codec_list = tgp_audio_list;
3685 } else if (!strcmp (format_name, "mmf")) {
3686 static enum AVCodecID mmf_audio_list[] = {
3687 AV_CODEC_ID_ADPCM_YAMAHA, AV_CODEC_ID_NONE
3689 *video_codec_list = NULL;
3690 *audio_codec_list = mmf_audio_list;
3691 } else if (!strcmp (format_name, "amr")) {
3692 static enum AVCodecID amr_audio_list[] = {
3693 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3696 *video_codec_list = NULL;
3697 *audio_codec_list = amr_audio_list;
3698 } else if (!strcmp (format_name, "gif")) {
3699 static enum AVCodecID gif_image_list[] = {
3700 AV_CODEC_ID_RAWVIDEO, AV_CODEC_ID_NONE
3702 *video_codec_list = gif_image_list;
3703 *audio_codec_list = NULL;
3704 } else if ((plugin->audio_codec != AV_CODEC_ID_NONE) ||
3705 (plugin->video_codec != AV_CODEC_ID_NONE)) {
3706 tmp_vlist[0] = plugin->video_codec;
3707 tmp_alist[0] = plugin->audio_codec;
3709 *video_codec_list = tmp_vlist;
3710 *audio_codec_list = tmp_alist;
3711 } else if ((!strcmp (format_name, "pva"))) {
3712 static enum AVCodecID tgp_video_list[] = {
3713 AV_CODEC_ID_MPEG2VIDEO,
3716 static enum AVCodecID tgp_audio_list[] = {
3721 *video_codec_list = tgp_video_list;
3722 *audio_codec_list = tgp_audio_list;
3724 GST_LOG ("Format %s not found", format_name);
3731 /* Convert a GstCaps to a FFMPEG codec ID. Size et all
3732 * are omitted, that can be queried by the user itself,
3733 * we're not eating the GstCaps or anything
3734 * A pointer to an allocated context is also needed for
3735 * optional extra info
3739 gst_ffmpeg_caps_to_codecid (const GstCaps * caps, AVCodecContext * context)
3741 enum AVCodecID id = AV_CODEC_ID_NONE;
3742 const gchar *mimetype;
3743 const GstStructure *structure;
3744 gboolean video = FALSE, audio = FALSE; /* we want to be sure! */
3746 g_return_val_if_fail (caps != NULL, AV_CODEC_ID_NONE);
3747 g_return_val_if_fail (gst_caps_get_size (caps) == 1, AV_CODEC_ID_NONE);
3748 structure = gst_caps_get_structure (caps, 0);
3750 mimetype = gst_structure_get_name (structure);
3752 if (!strcmp (mimetype, "video/x-raw")) {
3753 id = AV_CODEC_ID_RAWVIDEO;
3755 } else if (!strcmp (mimetype, "audio/x-raw")) {
3758 if (gst_audio_info_from_caps (&info, caps)) {
3759 switch (GST_AUDIO_INFO_FORMAT (&info)) {
3760 case GST_AUDIO_FORMAT_S8:
3761 id = AV_CODEC_ID_PCM_S8;
3763 case GST_AUDIO_FORMAT_U8:
3764 id = AV_CODEC_ID_PCM_U8;
3766 case GST_AUDIO_FORMAT_S16LE:
3767 id = AV_CODEC_ID_PCM_S16LE;
3769 case GST_AUDIO_FORMAT_S16BE:
3770 id = AV_CODEC_ID_PCM_S16BE;
3772 case GST_AUDIO_FORMAT_U16LE:
3773 id = AV_CODEC_ID_PCM_U16LE;
3775 case GST_AUDIO_FORMAT_U16BE:
3776 id = AV_CODEC_ID_PCM_U16BE;
3781 if (id != AV_CODEC_ID_NONE)
3784 } else if (!strcmp (mimetype, "audio/x-mulaw")) {
3785 id = AV_CODEC_ID_PCM_MULAW;
3787 } else if (!strcmp (mimetype, "audio/x-alaw")) {
3788 id = AV_CODEC_ID_PCM_ALAW;
3790 } else if (!strcmp (mimetype, "video/x-dv")) {
3793 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3795 id = AV_CODEC_ID_DVVIDEO;
3798 } else if (!strcmp (mimetype, "audio/x-dv")) { /* ??? */
3799 id = AV_CODEC_ID_DVAUDIO;
3801 } else if (!strcmp (mimetype, "video/x-h263")) {
3802 const gchar *h263version =
3803 gst_structure_get_string (structure, "h263version");
3804 if (h263version && !strcmp (h263version, "h263p"))
3805 id = AV_CODEC_ID_H263P;
3807 id = AV_CODEC_ID_H263;
3809 } else if (!strcmp (mimetype, "video/x-intel-h263")) {
3810 id = AV_CODEC_ID_H263I;
3812 } else if (!strcmp (mimetype, "video/x-h261")) {
3813 id = AV_CODEC_ID_H261;
3815 } else if (!strcmp (mimetype, "video/mpeg")) {
3819 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3820 gst_structure_get_int (structure, "mpegversion", &mpegversion) &&
3822 switch (mpegversion) {
3824 id = AV_CODEC_ID_MPEG1VIDEO;
3827 id = AV_CODEC_ID_MPEG2VIDEO;
3830 id = AV_CODEC_ID_MPEG4;
3834 if (id != AV_CODEC_ID_NONE)
3836 } else if (!strcmp (mimetype, "image/jpeg")) {
3837 id = AV_CODEC_ID_MJPEG; /* A... B... */
3839 } else if (!strcmp (mimetype, "video/x-jpeg-b")) {
3840 id = AV_CODEC_ID_MJPEGB;
3842 } else if (!strcmp (mimetype, "video/x-wmv")) {
3843 gint wmvversion = 0;
3845 if (gst_structure_get_int (structure, "wmvversion", &wmvversion)) {
3846 switch (wmvversion) {
3848 id = AV_CODEC_ID_WMV1;
3851 id = AV_CODEC_ID_WMV2;
3855 const gchar *format;
3857 /* WMV3 unless the fourcc exists and says otherwise */
3858 id = AV_CODEC_ID_WMV3;
3860 if ((format = gst_structure_get_string (structure, "format")) &&
3861 (g_str_equal (format, "WVC1") || g_str_equal (format, "WMVA")))
3862 id = AV_CODEC_ID_VC1;
3868 if (id != AV_CODEC_ID_NONE)
3870 } else if (!strcmp (mimetype, "audio/x-vorbis")) {
3871 id = AV_CODEC_ID_VORBIS;
3873 } else if (!strcmp (mimetype, "audio/x-qdm2")) {
3874 id = AV_CODEC_ID_QDM2;
3876 } else if (!strcmp (mimetype, "audio/mpeg")) {
3878 gint mpegversion = 0;
3880 if (gst_structure_get_int (structure, "mpegversion", &mpegversion)) {
3881 switch (mpegversion) {
3882 case 2: /* ffmpeg uses faad for both... */
3884 id = AV_CODEC_ID_AAC;
3887 if (gst_structure_get_int (structure, "layer", &layer)) {
3890 id = AV_CODEC_ID_MP1;
3893 id = AV_CODEC_ID_MP2;
3896 id = AV_CODEC_ID_MP3;
3902 if (id != AV_CODEC_ID_NONE)
3904 } else if (!strcmp (mimetype, "audio/x-musepack")) {
3905 gint streamversion = -1;
3907 if (gst_structure_get_int (structure, "streamversion", &streamversion)) {
3908 if (streamversion == 7)
3909 id = AV_CODEC_ID_MUSEPACK7;
3911 id = AV_CODEC_ID_MUSEPACK7;
3913 } else if (!strcmp (mimetype, "audio/x-wma")) {
3914 gint wmaversion = 0;
3916 if (gst_structure_get_int (structure, "wmaversion", &wmaversion)) {
3917 switch (wmaversion) {
3919 id = AV_CODEC_ID_WMAV1;
3922 id = AV_CODEC_ID_WMAV2;
3925 id = AV_CODEC_ID_WMAPRO;
3929 if (id != AV_CODEC_ID_NONE)
3931 } else if (!strcmp (mimetype, "audio/x-wms")) {
3932 id = AV_CODEC_ID_WMAVOICE;
3934 } else if (!strcmp (mimetype, "audio/x-ac3")) {
3935 id = AV_CODEC_ID_AC3;
3937 } else if (!strcmp (mimetype, "audio/x-eac3")) {
3938 id = AV_CODEC_ID_EAC3;
3940 } else if (!strcmp (mimetype, "audio/x-vnd.sony.atrac3") ||
3941 !strcmp (mimetype, "audio/atrac3")) {
3942 id = AV_CODEC_ID_ATRAC3;
3944 } else if (!strcmp (mimetype, "audio/x-dts")) {
3945 id = AV_CODEC_ID_DTS;
3947 } else if (!strcmp (mimetype, "application/x-ape")) {
3948 id = AV_CODEC_ID_APE;
3950 } else if (!strcmp (mimetype, "video/x-msmpeg")) {
3951 gint msmpegversion = 0;
3953 if (gst_structure_get_int (structure, "msmpegversion", &msmpegversion)) {
3954 switch (msmpegversion) {
3956 id = AV_CODEC_ID_MSMPEG4V1;
3959 id = AV_CODEC_ID_MSMPEG4V2;
3962 id = AV_CODEC_ID_MSMPEG4V3;
3966 if (id != AV_CODEC_ID_NONE)
3968 } else if (!strcmp (mimetype, "video/x-svq")) {
3969 gint svqversion = 0;
3971 if (gst_structure_get_int (structure, "svqversion", &svqversion)) {
3972 switch (svqversion) {
3974 id = AV_CODEC_ID_SVQ1;
3977 id = AV_CODEC_ID_SVQ3;
3981 if (id != AV_CODEC_ID_NONE)
3983 } else if (!strcmp (mimetype, "video/x-huffyuv")) {
3984 id = AV_CODEC_ID_HUFFYUV;
3986 } else if (!strcmp (mimetype, "audio/x-mace")) {
3987 gint maceversion = 0;
3989 if (gst_structure_get_int (structure, "maceversion", &maceversion)) {
3990 switch (maceversion) {
3992 id = AV_CODEC_ID_MACE3;
3995 id = AV_CODEC_ID_MACE6;
3999 if (id != AV_CODEC_ID_NONE)
4001 } else if (!strcmp (mimetype, "video/x-theora")) {
4002 id = AV_CODEC_ID_THEORA;
4004 } else if (!strcmp (mimetype, "video/x-vp3")) {
4005 id = AV_CODEC_ID_VP3;
4007 } else if (!strcmp (mimetype, "video/x-vp5")) {
4008 id = AV_CODEC_ID_VP5;
4010 } else if (!strcmp (mimetype, "video/x-vp6")) {
4011 id = AV_CODEC_ID_VP6;
4013 } else if (!strcmp (mimetype, "video/x-vp6-flash")) {
4014 id = AV_CODEC_ID_VP6F;
4016 } else if (!strcmp (mimetype, "video/x-vp6-alpha")) {
4017 id = AV_CODEC_ID_VP6A;
4019 } else if (!strcmp (mimetype, "video/x-vp8")) {
4020 id = AV_CODEC_ID_VP8;
4022 } else if (!strcmp (mimetype, "video/x-vp9")) {
4023 id = AV_CODEC_ID_VP9;
4025 } else if (!strcmp (mimetype, "video/x-flash-screen")) {
4026 id = AV_CODEC_ID_FLASHSV;
4028 } else if (!strcmp (mimetype, "video/x-flash-screen2")) {
4029 id = AV_CODEC_ID_FLASHSV2;
4031 } else if (!strcmp (mimetype, "video/x-cineform")) {
4032 id = AV_CODEC_ID_CFHD;
4034 } else if (!strcmp (mimetype, "video/x-indeo")) {
4035 gint indeoversion = 0;
4037 if (gst_structure_get_int (structure, "indeoversion", &indeoversion)) {
4038 switch (indeoversion) {
4040 id = AV_CODEC_ID_INDEO5;
4043 id = AV_CODEC_ID_INDEO4;
4046 id = AV_CODEC_ID_INDEO3;
4049 id = AV_CODEC_ID_INDEO2;
4052 if (id != AV_CODEC_ID_NONE)
4055 } else if (!strcmp (mimetype, "video/x-divx")) {
4056 gint divxversion = 0;
4058 if (gst_structure_get_int (structure, "divxversion", &divxversion)) {
4059 switch (divxversion) {
4061 id = AV_CODEC_ID_MSMPEG4V3;
4065 id = AV_CODEC_ID_MPEG4;
4069 if (id != AV_CODEC_ID_NONE)
4071 } else if (!strcmp (mimetype, "video/x-ffv")) {
4072 gint ffvversion = 0;
4074 if (gst_structure_get_int (structure, "ffvversion", &ffvversion) &&
4076 id = AV_CODEC_ID_FFV1;
4079 } else if (!strcmp (mimetype, "video/x-apple-intermediate-codec")) {
4080 id = AV_CODEC_ID_AIC;
4082 } else if (!strcmp (mimetype, "audio/x-adpcm")) {
4083 const gchar *layout;
4085 layout = gst_structure_get_string (structure, "layout");
4086 if (layout == NULL) {
4088 } else if (!strcmp (layout, "quicktime")) {
4089 id = AV_CODEC_ID_ADPCM_IMA_QT;
4090 } else if (!strcmp (layout, "microsoft")) {
4091 id = AV_CODEC_ID_ADPCM_MS;
4092 } else if (!strcmp (layout, "dvi")) {
4093 id = AV_CODEC_ID_ADPCM_IMA_WAV;
4094 } else if (!strcmp (layout, "4xm")) {
4095 id = AV_CODEC_ID_ADPCM_4XM;
4096 } else if (!strcmp (layout, "smjpeg")) {
4097 id = AV_CODEC_ID_ADPCM_IMA_SMJPEG;
4098 } else if (!strcmp (layout, "dk3")) {
4099 id = AV_CODEC_ID_ADPCM_IMA_DK3;
4100 } else if (!strcmp (layout, "dk4")) {
4101 id = AV_CODEC_ID_ADPCM_IMA_DK4;
4102 } else if (!strcmp (layout, "westwood")) {
4103 id = AV_CODEC_ID_ADPCM_IMA_WS;
4104 } else if (!strcmp (layout, "iss")) {
4105 id = AV_CODEC_ID_ADPCM_IMA_ISS;
4106 } else if (!strcmp (layout, "xa")) {
4107 id = AV_CODEC_ID_ADPCM_XA;
4108 } else if (!strcmp (layout, "adx")) {
4109 id = AV_CODEC_ID_ADPCM_ADX;
4110 } else if (!strcmp (layout, "ea")) {
4111 id = AV_CODEC_ID_ADPCM_EA;
4112 } else if (!strcmp (layout, "g726")) {
4113 id = AV_CODEC_ID_ADPCM_G726;
4114 } else if (!strcmp (layout, "g721")) {
4115 id = AV_CODEC_ID_ADPCM_G726;
4116 } else if (!strcmp (layout, "ct")) {
4117 id = AV_CODEC_ID_ADPCM_CT;
4118 } else if (!strcmp (layout, "swf")) {
4119 id = AV_CODEC_ID_ADPCM_SWF;
4120 } else if (!strcmp (layout, "yamaha")) {
4121 id = AV_CODEC_ID_ADPCM_YAMAHA;
4122 } else if (!strcmp (layout, "sbpro2")) {
4123 id = AV_CODEC_ID_ADPCM_SBPRO_2;
4124 } else if (!strcmp (layout, "sbpro3")) {
4125 id = AV_CODEC_ID_ADPCM_SBPRO_3;
4126 } else if (!strcmp (layout, "sbpro4")) {
4127 id = AV_CODEC_ID_ADPCM_SBPRO_4;
4129 if (id != AV_CODEC_ID_NONE)
4131 } else if (!strcmp (mimetype, "video/x-4xm")) {
4132 id = AV_CODEC_ID_4XM;
4134 } else if (!strcmp (mimetype, "audio/x-dpcm")) {
4135 const gchar *layout;
4137 layout = gst_structure_get_string (structure, "layout");
4140 } else if (!strcmp (layout, "roq")) {
4141 id = AV_CODEC_ID_ROQ_DPCM;
4142 } else if (!strcmp (layout, "interplay")) {
4143 id = AV_CODEC_ID_INTERPLAY_DPCM;
4144 } else if (!strcmp (layout, "xan")) {
4145 id = AV_CODEC_ID_XAN_DPCM;
4146 } else if (!strcmp (layout, "sol")) {
4147 id = AV_CODEC_ID_SOL_DPCM;
4149 if (id != AV_CODEC_ID_NONE)
4151 } else if (!strcmp (mimetype, "audio/x-flac")) {
4152 id = AV_CODEC_ID_FLAC;
4154 } else if (!strcmp (mimetype, "audio/x-shorten")) {
4155 id = AV_CODEC_ID_SHORTEN;
4157 } else if (!strcmp (mimetype, "audio/x-alac")) {
4158 id = AV_CODEC_ID_ALAC;
4160 } else if (!strcmp (mimetype, "video/x-cinepak")) {
4161 id = AV_CODEC_ID_CINEPAK;
4163 } else if (!strcmp (mimetype, "video/x-pn-realvideo")) {
4166 if (gst_structure_get_int (structure, "rmversion", &rmversion)) {
4167 switch (rmversion) {
4169 id = AV_CODEC_ID_RV10;
4172 id = AV_CODEC_ID_RV20;
4175 id = AV_CODEC_ID_RV30;
4178 id = AV_CODEC_ID_RV40;
4182 if (id != AV_CODEC_ID_NONE)
4184 } else if (!strcmp (mimetype, "audio/x-sipro")) {
4185 id = AV_CODEC_ID_SIPR;
4187 } else if (!strcmp (mimetype, "audio/x-pn-realaudio")) {
4190 if (gst_structure_get_int (structure, "raversion", &raversion)) {
4191 switch (raversion) {
4193 id = AV_CODEC_ID_RA_144;
4196 id = AV_CODEC_ID_RA_288;
4199 id = AV_CODEC_ID_COOK;
4203 if (id != AV_CODEC_ID_NONE)
4205 } else if (!strcmp (mimetype, "video/x-rle")) {
4206 const gchar *layout;
4208 if ((layout = gst_structure_get_string (structure, "layout"))) {
4209 if (!strcmp (layout, "microsoft")) {
4210 id = AV_CODEC_ID_MSRLE;
4214 } else if (!strcmp (mimetype, "video/x-xan")) {
4217 if ((gst_structure_get_int (structure, "wcversion", &wcversion))) {
4218 switch (wcversion) {
4220 id = AV_CODEC_ID_XAN_WC3;
4224 id = AV_CODEC_ID_XAN_WC4;
4231 } else if (!strcmp (mimetype, "audio/AMR")) {
4233 id = AV_CODEC_ID_AMR_NB;
4234 } else if (!strcmp (mimetype, "audio/AMR-WB")) {
4235 id = AV_CODEC_ID_AMR_WB;
4237 } else if (!strcmp (mimetype, "audio/qcelp")) {
4238 id = AV_CODEC_ID_QCELP;
4240 } else if (!strcmp (mimetype, "video/x-h264")) {
4241 id = AV_CODEC_ID_H264;
4243 } else if (!strcmp (mimetype, "video/x-h265")) {
4244 id = AV_CODEC_ID_HEVC;
4246 } else if (!strcmp (mimetype, "video/x-flash-video")) {
4247 gint flvversion = 0;
4249 if ((gst_structure_get_int (structure, "flvversion", &flvversion))) {
4250 switch (flvversion) {
4252 id = AV_CODEC_ID_FLV1;
4260 } else if (!strcmp (mimetype, "audio/x-nellymoser")) {
4261 id = AV_CODEC_ID_NELLYMOSER;
4263 } else if (!strncmp (mimetype, "audio/x-gst-av-", 15)) {
4267 if (strlen (mimetype) <= 30 &&
4268 sscanf (mimetype, "audio/x-gst-av-%s", ext) == 1) {
4269 if ((codec = avcodec_find_decoder_by_name (ext)) ||
4270 (codec = avcodec_find_encoder_by_name (ext))) {
4275 } else if (!strncmp (mimetype, "video/x-gst-av-", 15)) {
4279 if (strlen (mimetype) <= 30 &&
4280 sscanf (mimetype, "video/x-gst-av-%s", ext) == 1) {
4281 if ((codec = avcodec_find_decoder_by_name (ext)) ||
4282 (codec = avcodec_find_encoder_by_name (ext))) {
4289 if (context != NULL) {
4290 if (video == TRUE) {
4291 context->codec_type = AVMEDIA_TYPE_VIDEO;
4292 } else if (audio == TRUE) {
4293 context->codec_type = AVMEDIA_TYPE_AUDIO;
4295 context->codec_type = AVMEDIA_TYPE_UNKNOWN;
4297 context->codec_id = id;
4298 gst_ffmpeg_caps_with_codecid (id, context->codec_type, caps, context);
4301 if (id != AV_CODEC_ID_NONE) {
4302 GST_DEBUG ("The id=%d belongs to the caps %" GST_PTR_FORMAT, id, caps);
4304 GST_WARNING ("Couldn't figure out the id for caps %" GST_PTR_FORMAT, caps);