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_caps_new_simple (mimetype, "channel-mask", GST_TYPE_BITMASK,
657 "channels", G_TYPE_INT, nbits_set, NULL);
659 gst_caps_append (caps, tmp);
665 if (maxchannels == 1)
666 caps = gst_caps_new_simple (mimetype,
667 "channels", G_TYPE_INT, maxchannels, NULL);
669 caps = gst_caps_new_simple (mimetype,
670 "channels", GST_TYPE_INT_RANGE, 1, maxchannels, NULL);
674 GValue list = { 0, };
676 g_value_init (&list, GST_TYPE_LIST);
677 for (i = 0; i < n_rates; i++) {
680 g_value_init (&v, G_TYPE_INT);
681 g_value_set_int (&v, rates[i]);
682 gst_value_list_append_value (&list, &v);
685 gst_caps_set_value (caps, "rate", &list);
686 g_value_unset (&list);
687 } else if (codec && codec->supported_samplerates
688 && codec->supported_samplerates[0]) {
692 if (!codec->supported_samplerates[1]) {
693 gst_caps_set_simple (caps, "rate", G_TYPE_INT,
694 codec->supported_samplerates[0], NULL);
696 const int *rates = codec->supported_samplerates;
698 g_value_init (&va, GST_TYPE_LIST);
699 g_value_init (&v, G_TYPE_INT);
702 g_value_set_int (&v, *rates);
703 gst_value_list_append_value (&va, &v);
706 gst_caps_set_value (caps, "rate", &va);
711 gst_caps_set_simple (caps, "rate", GST_TYPE_INT_RANGE, 4000, 96000, NULL);
714 caps = gst_caps_new_empty_simple (mimetype);
717 va_start (var_args, fieldname);
718 gst_caps_set_simple_valist (caps, fieldname, var_args);
724 /* Convert a FFMPEG codec ID and optional AVCodecContext
725 * to a GstCaps. If the context is ommitted, no fixed values
726 * for video/audio size will be included in the GstCaps
728 * CodecID is primarily meant for compressed data GstCaps!
730 * encode is a special parameter. gstffmpegdec will say
731 * FALSE, gstffmpegenc will say TRUE. The output caps
732 * depends on this, in such a way that it will be very
733 * specific, defined, fixed and correct caps for encoders,
734 * yet very wide, "forgiving" caps for decoders. Example
735 * for mp3: decode: audio/mpeg,mpegversion=1,layer=[1-3]
736 * but encode: audio/mpeg,mpegversion=1,layer=3,bitrate=x,
741 gst_ffmpeg_codecid_to_caps (enum AVCodecID codec_id,
742 AVCodecContext * context, gboolean encode)
744 GstCaps *caps = NULL;
745 gboolean buildcaps = FALSE;
747 GST_LOG ("codec_id:%d, context:%p, encode:%d", codec_id, context, encode);
750 case AV_CODEC_ID_MPEG1VIDEO:
752 caps = gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
753 "mpegversion", G_TYPE_INT, 1,
754 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
757 case AV_CODEC_ID_MPEG2VIDEO:
761 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
762 "mpegversion", G_TYPE_INT, 2, "systemstream", G_TYPE_BOOLEAN, FALSE,
765 /* decode both MPEG-1 and MPEG-2; width/height/fps are all in
766 * the MPEG video stream headers, so may be omitted from caps. */
767 caps = gst_caps_new_simple ("video/mpeg",
768 "mpegversion", GST_TYPE_INT_RANGE, 1, 2,
769 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
773 case AV_CODEC_ID_H263:
776 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
777 "video/x-h263", "variant", G_TYPE_STRING, "itu", "h263version",
778 G_TYPE_STRING, "h263", NULL);
780 /* don't pass codec_id, we can decode other variants with the H263
781 * decoder that don't have specific size requirements
784 gst_ff_vid_caps_new (context, NULL, AV_CODEC_ID_NONE, encode,
785 "video/x-h263", "variant", G_TYPE_STRING, "itu", NULL);
789 case AV_CODEC_ID_H263P:
791 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h263",
792 "variant", G_TYPE_STRING, "itu", "h263version", G_TYPE_STRING,
794 if (encode && context) {
796 gst_caps_set_simple (caps,
797 "annex-f", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_4MV,
798 "annex-j", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_LOOP_FILTER,
799 "annex-i", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_AC_PRED,
800 "annex-t", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_AC_PRED,
805 case AV_CODEC_ID_H263I:
807 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
808 "video/x-intel-h263", "variant", G_TYPE_STRING, "intel", NULL);
811 case AV_CODEC_ID_H261:
813 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h261",
817 case AV_CODEC_ID_RV10:
818 case AV_CODEC_ID_RV20:
819 case AV_CODEC_ID_RV30:
820 case AV_CODEC_ID_RV40:
825 case AV_CODEC_ID_RV40:
828 case AV_CODEC_ID_RV30:
831 case AV_CODEC_ID_RV20:
840 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
841 "video/x-pn-realvideo", "rmversion", G_TYPE_INT, version, NULL);
843 if (context->extradata_size >= 8) {
844 gst_caps_set_simple (caps,
845 "subformat", G_TYPE_INT, GST_READ_UINT32_BE (context->extradata),
852 case AV_CODEC_ID_MP1:
854 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
855 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 1, NULL);
858 case AV_CODEC_ID_MP2:
860 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
861 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 2, NULL);
864 case AV_CODEC_ID_MP3:
868 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
869 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 3, NULL);
871 /* Decodes MPEG-1 layer 1/2/3. Samplerate, channels et al are
872 * in the MPEG audio header, so may be omitted from caps. */
873 caps = gst_caps_new_simple ("audio/mpeg",
874 "mpegversion", G_TYPE_INT, 1,
875 "layer", GST_TYPE_INT_RANGE, 1, 3, NULL);
879 case AV_CODEC_ID_MUSEPACK7:
881 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
882 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 7,
886 case AV_CODEC_ID_MUSEPACK8:
888 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
889 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 8,
893 case AV_CODEC_ID_AC3:
896 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-ac3",
900 case AV_CODEC_ID_EAC3:
903 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-eac3",
907 case AV_CODEC_ID_TRUEHD:
909 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
910 "audio/x-true-hd", NULL);
913 case AV_CODEC_ID_ATRAC1:
915 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
916 "audio/x-vnd.sony.atrac1", NULL);
919 case AV_CODEC_ID_ATRAC3:
921 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
922 "audio/x-vnd.sony.atrac3", NULL);
925 case AV_CODEC_ID_DTS:
927 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dts",
931 case AV_CODEC_ID_APE:
933 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
934 "audio/x-ffmpeg-parsed-ape", NULL);
936 gst_caps_set_simple (caps,
937 "depth", G_TYPE_INT, context->bits_per_coded_sample, NULL);
941 case AV_CODEC_ID_MLP:
943 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mlp",
947 case AV_CODEC_ID_IMC:
949 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-imc",
953 /* MJPEG is normal JPEG, Motion-JPEG and Quicktime MJPEG-A. MJPEGB
954 * is Quicktime's MJPEG-B. LJPEG is lossless JPEG. I don't know what
955 * sp5x is, but it's apparently something JPEG... We don't separate
956 * between those in GStreamer. Should we (at least between MJPEG,
957 * MJPEG-B and sp5x decoding...)? */
958 case AV_CODEC_ID_MJPEG:
959 case AV_CODEC_ID_LJPEG:
961 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/jpeg",
962 "parsed", G_TYPE_BOOLEAN, TRUE, NULL);
965 case AV_CODEC_ID_JPEG2000:
967 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-j2c",
970 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
971 encode, "image/x-jpc", NULL));
972 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
973 encode, "image/jp2", NULL));
977 case AV_CODEC_ID_SP5X:
979 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/sp5x",
983 case AV_CODEC_ID_MJPEGB:
985 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
986 "video/x-mjpeg-b", NULL);
989 case AV_CODEC_ID_MPEG4:
990 if (encode && context != NULL) {
991 /* I'm not exactly sure what ffmpeg outputs... ffmpeg itself uses
992 * the AVI fourcc 'DIVX', but 'mp4v' for Quicktime... */
993 switch (context->codec_tag) {
994 case GST_MAKE_FOURCC ('D', 'I', 'V', 'X'):
996 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
997 "video/x-divx", "divxversion", G_TYPE_INT, 5, NULL);
999 case GST_MAKE_FOURCC ('m', 'p', '4', 'v'):
1001 /* FIXME: bitrate. libav doesn't expose the used profile and level */
1003 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1004 "video/mpeg", "systemstream", G_TYPE_BOOLEAN, FALSE,
1005 "mpegversion", G_TYPE_INT, 4, NULL);
1009 /* The trick here is to separate xvid, divx, mpeg4, 3ivx et al */
1011 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
1012 "mpegversion", G_TYPE_INT, 4, "systemstream", G_TYPE_BOOLEAN, FALSE,
1016 GValue arr = { 0, };
1017 GValue item = { 0, };
1019 g_value_init (&arr, GST_TYPE_LIST);
1020 g_value_init (&item, G_TYPE_STRING);
1021 g_value_set_string (&item, "simple");
1022 gst_value_list_append_value (&arr, &item);
1023 g_value_set_string (&item, "advanced-simple");
1024 gst_value_list_append_value (&arr, &item);
1025 g_value_unset (&item);
1027 gst_caps_set_value (caps, "profile", &arr);
1028 g_value_unset (&arr);
1030 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
1031 encode, "video/x-divx", "divxversion", G_TYPE_INT, 5, NULL));
1033 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
1034 encode, "video/x-divx", "divxversion", GST_TYPE_INT_RANGE, 4,
1040 case AV_CODEC_ID_RAWVIDEO:
1042 gst_ffmpeg_codectype_to_video_caps (context, codec_id, encode, NULL);
1045 case AV_CODEC_ID_MSMPEG4V1:
1046 case AV_CODEC_ID_MSMPEG4V2:
1047 case AV_CODEC_ID_MSMPEG4V3:
1049 gint version = 41 + codec_id - AV_CODEC_ID_MSMPEG4V1;
1051 /* encode-FIXME: bitrate */
1053 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1054 "video/x-msmpeg", "msmpegversion", G_TYPE_INT, version, NULL);
1055 if (!encode && codec_id == AV_CODEC_ID_MSMPEG4V3) {
1056 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
1057 encode, "video/x-divx", "divxversion", G_TYPE_INT, 3, NULL));
1062 case AV_CODEC_ID_WMV1:
1063 case AV_CODEC_ID_WMV2:
1065 gint version = (codec_id == AV_CODEC_ID_WMV1) ? 1 : 2;
1068 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1069 "wmvversion", G_TYPE_INT, version, NULL);
1073 case AV_CODEC_ID_FLV1:
1075 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1076 "video/x-flash-video", "flvversion", G_TYPE_INT, 1, NULL);
1079 case AV_CODEC_ID_SVQ1:
1081 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-svq",
1082 "svqversion", G_TYPE_INT, 1, NULL);
1085 case AV_CODEC_ID_SVQ3:
1087 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-svq",
1088 "svqversion", G_TYPE_INT, 3, NULL);
1091 case AV_CODEC_ID_DVAUDIO:
1093 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dv",
1097 case AV_CODEC_ID_DVVIDEO:
1099 if (encode && context) {
1100 const gchar *format;
1102 switch (context->pix_fmt) {
1103 case AV_PIX_FMT_YUYV422:
1106 case AV_PIX_FMT_YUV420P:
1109 case AV_PIX_FMT_YUVA420P:
1112 case AV_PIX_FMT_YUV411P:
1115 case AV_PIX_FMT_YUV422P:
1118 case AV_PIX_FMT_YUV410P:
1123 ("Couldnt' find format for pixfmt %d, defaulting to I420",
1129 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dv",
1130 "systemstream", G_TYPE_BOOLEAN, FALSE, "format", G_TYPE_STRING,
1134 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dv",
1135 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
1140 case AV_CODEC_ID_WMAV1:
1141 case AV_CODEC_ID_WMAV2:
1143 gint version = (codec_id == AV_CODEC_ID_WMAV1) ? 1 : 2;
1147 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1148 "wmaversion", G_TYPE_INT, version, "block_align", G_TYPE_INT,
1149 context->block_align, "bitrate", G_TYPE_INT, context->bit_rate,
1153 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1154 "wmaversion", G_TYPE_INT, version, "block_align",
1155 GST_TYPE_INT_RANGE, 0, G_MAXINT, "bitrate", GST_TYPE_INT_RANGE, 0,
1160 case AV_CODEC_ID_WMAPRO:
1163 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1164 "wmaversion", G_TYPE_INT, 3, NULL);
1167 case AV_CODEC_ID_WMALOSSLESS:
1169 /* libav only supports a depth of 16 at the moment */
1171 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1172 "wmaversion", G_TYPE_INT, 4, "depth", G_TYPE_INT, 16, NULL);
1175 case AV_CODEC_ID_WMAVOICE:
1178 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wms",
1183 case AV_CODEC_ID_MACE3:
1184 case AV_CODEC_ID_MACE6:
1186 gint version = (codec_id == AV_CODEC_ID_MACE3) ? 3 : 6;
1189 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mace",
1190 "maceversion", G_TYPE_INT, version, NULL);
1194 case AV_CODEC_ID_HUFFYUV:
1196 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1197 "video/x-huffyuv", NULL);
1199 gst_caps_set_simple (caps,
1200 "bpp", G_TYPE_INT, context->bits_per_coded_sample, NULL);
1204 case AV_CODEC_ID_CYUV:
1206 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1207 "video/x-compressed-yuv", NULL);
1210 case AV_CODEC_ID_H264:
1212 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h264",
1213 "alignment", G_TYPE_STRING, "au", NULL);
1215 GValue arr = { 0, };
1216 GValue item = { 0, };
1217 g_value_init (&arr, GST_TYPE_LIST);
1218 g_value_init (&item, G_TYPE_STRING);
1219 g_value_set_string (&item, "avc");
1220 gst_value_list_append_value (&arr, &item);
1221 g_value_set_string (&item, "byte-stream");
1222 gst_value_list_append_value (&arr, &item);
1223 g_value_unset (&item);
1224 gst_caps_set_value (caps, "stream-format", &arr);
1225 g_value_unset (&arr);
1229 case AV_CODEC_ID_HEVC:
1231 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h265",
1232 "alignment", G_TYPE_STRING, "au", NULL);
1234 GValue arr = { 0, };
1235 GValue item = { 0, };
1236 g_value_init (&arr, GST_TYPE_LIST);
1237 g_value_init (&item, G_TYPE_STRING);
1238 g_value_set_string (&item, "hvc1");
1239 gst_value_list_append_value (&arr, &item);
1240 g_value_set_string (&item, "hev1");
1241 gst_value_list_append_value (&arr, &item);
1242 g_value_set_string (&item, "byte-stream");
1243 gst_value_list_append_value (&arr, &item);
1244 g_value_unset (&item);
1245 gst_caps_set_value (caps, "stream-format", &arr);
1246 g_value_unset (&arr);
1250 case AV_CODEC_ID_INDEO5:
1252 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1253 "indeoversion", G_TYPE_INT, 5, NULL);
1256 case AV_CODEC_ID_INDEO4:
1258 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1259 "indeoversion", G_TYPE_INT, 4, NULL);
1262 case AV_CODEC_ID_INDEO3:
1264 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1265 "indeoversion", G_TYPE_INT, 3, NULL);
1268 case AV_CODEC_ID_INDEO2:
1270 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1271 "indeoversion", G_TYPE_INT, 2, NULL);
1274 case AV_CODEC_ID_FLASHSV:
1276 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1277 "video/x-flash-screen", NULL);
1280 case AV_CODEC_ID_VP3:
1282 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp3",
1286 case AV_CODEC_ID_VP5:
1288 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp5",
1292 case AV_CODEC_ID_VP6:
1294 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp6",
1298 case AV_CODEC_ID_VP6F:
1300 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1301 "video/x-vp6-flash", NULL);
1304 case AV_CODEC_ID_VP6A:
1306 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1307 "video/x-vp6-alpha", NULL);
1310 case AV_CODEC_ID_VP8:
1312 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp8",
1316 case AV_CODEC_ID_VP9:
1318 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp9",
1322 case AV_CODEC_ID_THEORA:
1324 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1325 "video/x-theora", NULL);
1328 case AV_CODEC_ID_AAC:
1331 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
1335 GValue arr = { 0, };
1336 GValue item = { 0, };
1338 g_value_init (&arr, GST_TYPE_LIST);
1339 g_value_init (&item, G_TYPE_INT);
1340 g_value_set_int (&item, 2);
1341 gst_value_list_append_value (&arr, &item);
1342 g_value_set_int (&item, 4);
1343 gst_value_list_append_value (&arr, &item);
1344 g_value_unset (&item);
1346 gst_caps_set_value (caps, "mpegversion", &arr);
1347 g_value_unset (&arr);
1349 g_value_init (&arr, GST_TYPE_LIST);
1350 g_value_init (&item, G_TYPE_STRING);
1351 g_value_set_string (&item, "raw");
1352 gst_value_list_append_value (&arr, &item);
1353 g_value_set_string (&item, "adts");
1354 gst_value_list_append_value (&arr, &item);
1355 g_value_set_string (&item, "adif");
1356 gst_value_list_append_value (&arr, &item);
1357 g_value_unset (&item);
1359 gst_caps_set_value (caps, "stream-format", &arr);
1360 g_value_unset (&arr);
1362 gst_caps_set_simple (caps, "mpegversion", G_TYPE_INT, 4,
1363 "stream-format", G_TYPE_STRING, "raw",
1364 "base-profile", G_TYPE_STRING, "lc", NULL);
1366 if (context && context->extradata_size > 0)
1367 gst_codec_utils_aac_caps_set_level_and_profile (caps,
1368 context->extradata, context->extradata_size);
1373 case AV_CODEC_ID_AAC_LATM: /* LATM/LOAS AAC syntax */
1374 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
1375 "mpegversion", G_TYPE_INT, 4, "stream-format", G_TYPE_STRING, "loas",
1379 case AV_CODEC_ID_ASV1:
1381 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-asus",
1382 "asusversion", G_TYPE_INT, 1, NULL);
1384 case AV_CODEC_ID_ASV2:
1386 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-asus",
1387 "asusversion", G_TYPE_INT, 2, NULL);
1390 case AV_CODEC_ID_FFV1:
1392 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-ffv",
1393 "ffvversion", G_TYPE_INT, 1, NULL);
1396 case AV_CODEC_ID_4XM:
1398 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-4xm",
1402 case AV_CODEC_ID_XAN_WC3:
1403 case AV_CODEC_ID_XAN_WC4:
1405 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-xan",
1406 "wcversion", G_TYPE_INT, 3 - AV_CODEC_ID_XAN_WC3 + codec_id, NULL);
1409 case AV_CODEC_ID_CLJR:
1411 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1412 "video/x-cirrus-logic-accupak", NULL);
1415 case AV_CODEC_ID_FRAPS:
1417 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-fraps",
1421 case AV_CODEC_ID_MDEC:
1422 case AV_CODEC_ID_ROQ:
1423 case AV_CODEC_ID_INTERPLAY_VIDEO:
1427 case AV_CODEC_ID_VCR1:
1429 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1430 "video/x-ati-vcr", "vcrversion", G_TYPE_INT, 1, NULL);
1433 case AV_CODEC_ID_RPZA:
1435 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1436 "video/x-apple-video", NULL);
1439 case AV_CODEC_ID_CINEPAK:
1441 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1442 "video/x-cinepak", NULL);
1445 /* WS_VQA belogns here (order) */
1447 case AV_CODEC_ID_MSRLE:
1449 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-rle",
1450 "layout", G_TYPE_STRING, "microsoft", NULL);
1452 gst_caps_set_simple (caps,
1453 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1455 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1459 case AV_CODEC_ID_QTRLE:
1461 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-rle",
1462 "layout", G_TYPE_STRING, "quicktime", NULL);
1464 gst_caps_set_simple (caps,
1465 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1467 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1471 case AV_CODEC_ID_MSVIDEO1:
1473 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1474 "video/x-msvideocodec", "msvideoversion", G_TYPE_INT, 1, NULL);
1477 case AV_CODEC_ID_MSS1:
1479 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1480 "wmvversion", G_TYPE_INT, 1, "format", G_TYPE_STRING, "MSS1", NULL);
1483 case AV_CODEC_ID_MSS2:
1485 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1486 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "MSS2", NULL);
1489 case AV_CODEC_ID_WMV3:
1491 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1492 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "WMV3", NULL);
1494 case AV_CODEC_ID_VC1:
1496 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1497 "wmvversion", G_TYPE_INT, 3, NULL);
1498 if (!context && !encode) {
1499 GValue arr = { 0, };
1500 GValue item = { 0, };
1502 g_value_init (&arr, GST_TYPE_LIST);
1503 g_value_init (&item, G_TYPE_STRING);
1504 g_value_set_string (&item, "WVC1");
1505 gst_value_list_append_value (&arr, &item);
1506 g_value_set_string (&item, "WMVA");
1507 gst_value_list_append_and_take_value (&arr, &item);
1508 gst_caps_set_value (caps, "format", &arr);
1509 g_value_unset (&arr);
1511 gst_caps_set_simple (caps, "format", G_TYPE_STRING, "WVC1", NULL);
1514 case AV_CODEC_ID_QDM2:
1516 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-qdm2",
1520 case AV_CODEC_ID_MSZH:
1522 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-mszh",
1526 case AV_CODEC_ID_ZLIB:
1528 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-zlib",
1532 case AV_CODEC_ID_TRUEMOTION1:
1534 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1535 "video/x-truemotion", "trueversion", G_TYPE_INT, 1, NULL);
1537 case AV_CODEC_ID_TRUEMOTION2:
1539 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1540 "video/x-truemotion", "trueversion", G_TYPE_INT, 2, NULL);
1543 case AV_CODEC_ID_ULTI:
1545 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1546 "video/x-ultimotion", NULL);
1549 case AV_CODEC_ID_TSCC:
1551 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1552 "video/x-camtasia", NULL);
1554 gst_caps_set_simple (caps,
1555 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1557 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1561 case AV_CODEC_ID_TSCC2:
1563 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1564 "video/x-tscc", "tsccversion", G_TYPE_INT, 2, NULL);
1567 case AV_CODEC_ID_KMVC:
1569 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-kmvc",
1573 case AV_CODEC_ID_NUV:
1575 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-nuv",
1579 case AV_CODEC_ID_GIF:
1581 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/gif",
1585 case AV_CODEC_ID_PNG:
1587 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/png",
1591 case AV_CODEC_ID_PPM:
1593 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/ppm",
1597 case AV_CODEC_ID_PBM:
1599 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/pbm",
1603 case AV_CODEC_ID_PAM:
1605 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1606 "image/x-portable-anymap", NULL);
1609 case AV_CODEC_ID_PGM:
1611 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1612 "image/x-portable-graymap", NULL);
1615 case AV_CODEC_ID_PCX:
1617 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-pcx",
1621 case AV_CODEC_ID_SGI:
1623 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-sgi",
1627 case AV_CODEC_ID_TARGA:
1629 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-tga",
1633 case AV_CODEC_ID_TIFF:
1635 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/tiff",
1639 case AV_CODEC_ID_SUNRAST:
1641 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1642 "image/x-sun-raster", NULL);
1645 case AV_CODEC_ID_SMC:
1647 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-smc",
1651 case AV_CODEC_ID_QDRAW:
1653 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-qdrw",
1657 case AV_CODEC_ID_DNXHD:
1659 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dnxhd",
1663 case AV_CODEC_ID_PRORES:
1665 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1666 "video/x-prores", NULL);
1669 case AV_CODEC_ID_MIMIC:
1671 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-mimic",
1675 case AV_CODEC_ID_VMNC:
1677 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vmnc",
1681 case AV_CODEC_ID_TRUESPEECH:
1683 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1684 "audio/x-truespeech", NULL);
1687 case AV_CODEC_ID_QCELP:
1689 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/qcelp",
1693 case AV_CODEC_ID_AMV:
1695 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-amv",
1699 case AV_CODEC_ID_AASC:
1701 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-aasc",
1705 case AV_CODEC_ID_LOCO:
1707 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-loco",
1711 case AV_CODEC_ID_ZMBV:
1713 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-zmbv",
1717 case AV_CODEC_ID_LAGARITH:
1719 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1720 "video/x-lagarith", NULL);
1723 case AV_CODEC_ID_CSCD:
1725 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1726 "video/x-camstudio", NULL);
1728 gst_caps_set_simple (caps,
1729 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1731 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1735 case AV_CODEC_ID_AIC:
1737 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1738 "video/x-apple-intermediate-codec", NULL);
1741 case AV_CODEC_ID_CAVS:
1743 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1744 "video/x-cavs", NULL);
1747 case AV_CODEC_ID_WS_VQA:
1748 case AV_CODEC_ID_IDCIN:
1749 case AV_CODEC_ID_8BPS:
1750 case AV_CODEC_ID_FLIC:
1751 case AV_CODEC_ID_VMDVIDEO:
1752 case AV_CODEC_ID_VMDAUDIO:
1753 case AV_CODEC_ID_VIXL:
1754 case AV_CODEC_ID_QPEG:
1755 case AV_CODEC_ID_PGMYUV:
1756 case AV_CODEC_ID_FFVHUFF:
1757 case AV_CODEC_ID_WNV1:
1758 case AV_CODEC_ID_MP3ADU:
1759 case AV_CODEC_ID_MP3ON4:
1760 case AV_CODEC_ID_WESTWOOD_SND1:
1761 case AV_CODEC_ID_MMVIDEO:
1762 case AV_CODEC_ID_AVS:
1766 /* weird quasi-codecs for the demuxers only */
1767 case AV_CODEC_ID_PCM_S16LE:
1768 case AV_CODEC_ID_PCM_S16BE:
1769 case AV_CODEC_ID_PCM_U16LE:
1770 case AV_CODEC_ID_PCM_U16BE:
1771 case AV_CODEC_ID_PCM_S8:
1772 case AV_CODEC_ID_PCM_U8:
1774 GstAudioFormat format;
1777 case AV_CODEC_ID_PCM_S16LE:
1778 format = GST_AUDIO_FORMAT_S16LE;
1780 case AV_CODEC_ID_PCM_S16BE:
1781 format = GST_AUDIO_FORMAT_S16BE;
1783 case AV_CODEC_ID_PCM_U16LE:
1784 format = GST_AUDIO_FORMAT_U16LE;
1786 case AV_CODEC_ID_PCM_U16BE:
1787 format = GST_AUDIO_FORMAT_U16BE;
1789 case AV_CODEC_ID_PCM_S8:
1790 format = GST_AUDIO_FORMAT_S8;
1792 case AV_CODEC_ID_PCM_U8:
1793 format = GST_AUDIO_FORMAT_U8;
1797 g_assert (0); /* don't worry, we never get here */
1802 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-raw",
1803 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
1804 "layout", G_TYPE_STRING, "interleaved", NULL);
1808 case AV_CODEC_ID_PCM_MULAW:
1810 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mulaw",
1814 case AV_CODEC_ID_PCM_ALAW:
1816 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-alaw",
1820 case AV_CODEC_ID_ADPCM_G722:
1822 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/G722",
1825 gst_caps_set_simple (caps,
1826 "block_align", G_TYPE_INT, context->block_align,
1827 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1830 case AV_CODEC_ID_ADPCM_G726:
1832 /* the G726 decoder can also handle G721 */
1834 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-adpcm",
1835 "layout", G_TYPE_STRING, "g726", NULL);
1837 gst_caps_set_simple (caps,
1838 "block_align", G_TYPE_INT, context->block_align,
1839 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1842 gst_caps_append (caps, gst_caps_new_simple ("audio/x-adpcm",
1843 "layout", G_TYPE_STRING, "g721",
1844 "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, 8000, NULL));
1848 case AV_CODEC_ID_ADPCM_IMA_QT:
1849 case AV_CODEC_ID_ADPCM_IMA_WAV:
1850 case AV_CODEC_ID_ADPCM_IMA_DK3:
1851 case AV_CODEC_ID_ADPCM_IMA_DK4:
1852 case AV_CODEC_ID_ADPCM_IMA_WS:
1853 case AV_CODEC_ID_ADPCM_IMA_SMJPEG:
1854 case AV_CODEC_ID_ADPCM_IMA_AMV:
1855 case AV_CODEC_ID_ADPCM_IMA_ISS:
1856 case AV_CODEC_ID_ADPCM_IMA_EA_EACS:
1857 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
1858 case AV_CODEC_ID_ADPCM_MS:
1859 case AV_CODEC_ID_ADPCM_4XM:
1860 case AV_CODEC_ID_ADPCM_XA:
1861 case AV_CODEC_ID_ADPCM_ADX:
1862 case AV_CODEC_ID_ADPCM_EA:
1863 case AV_CODEC_ID_ADPCM_CT:
1864 case AV_CODEC_ID_ADPCM_SWF:
1865 case AV_CODEC_ID_ADPCM_YAMAHA:
1866 case AV_CODEC_ID_ADPCM_SBPRO_2:
1867 case AV_CODEC_ID_ADPCM_SBPRO_3:
1868 case AV_CODEC_ID_ADPCM_SBPRO_4:
1869 case AV_CODEC_ID_ADPCM_EA_R1:
1870 case AV_CODEC_ID_ADPCM_EA_R2:
1871 case AV_CODEC_ID_ADPCM_EA_R3:
1872 case AV_CODEC_ID_ADPCM_EA_MAXIS_XA:
1873 case AV_CODEC_ID_ADPCM_EA_XAS:
1874 case AV_CODEC_ID_ADPCM_THP:
1876 const gchar *layout = NULL;
1879 case AV_CODEC_ID_ADPCM_IMA_QT:
1880 layout = "quicktime";
1882 case AV_CODEC_ID_ADPCM_IMA_WAV:
1885 case AV_CODEC_ID_ADPCM_IMA_DK3:
1888 case AV_CODEC_ID_ADPCM_IMA_DK4:
1891 case AV_CODEC_ID_ADPCM_IMA_WS:
1892 layout = "westwood";
1894 case AV_CODEC_ID_ADPCM_IMA_SMJPEG:
1897 case AV_CODEC_ID_ADPCM_IMA_AMV:
1900 case AV_CODEC_ID_ADPCM_IMA_ISS:
1903 case AV_CODEC_ID_ADPCM_IMA_EA_EACS:
1906 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
1909 case AV_CODEC_ID_ADPCM_MS:
1910 layout = "microsoft";
1912 case AV_CODEC_ID_ADPCM_4XM:
1915 case AV_CODEC_ID_ADPCM_XA:
1918 case AV_CODEC_ID_ADPCM_ADX:
1921 case AV_CODEC_ID_ADPCM_EA:
1924 case AV_CODEC_ID_ADPCM_CT:
1927 case AV_CODEC_ID_ADPCM_SWF:
1930 case AV_CODEC_ID_ADPCM_YAMAHA:
1933 case AV_CODEC_ID_ADPCM_SBPRO_2:
1936 case AV_CODEC_ID_ADPCM_SBPRO_3:
1939 case AV_CODEC_ID_ADPCM_SBPRO_4:
1942 case AV_CODEC_ID_ADPCM_EA_R1:
1945 case AV_CODEC_ID_ADPCM_EA_R2:
1948 case AV_CODEC_ID_ADPCM_EA_R3:
1951 case AV_CODEC_ID_ADPCM_EA_MAXIS_XA:
1952 layout = "ea-maxis-xa";
1954 case AV_CODEC_ID_ADPCM_EA_XAS:
1957 case AV_CODEC_ID_ADPCM_THP:
1961 g_assert (0); /* don't worry, we never get here */
1965 /* FIXME: someone please check whether we need additional properties
1966 * in this caps definition. */
1968 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-adpcm",
1969 "layout", G_TYPE_STRING, layout, NULL);
1971 gst_caps_set_simple (caps,
1972 "block_align", G_TYPE_INT, context->block_align,
1973 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1977 case AV_CODEC_ID_AMR_NB:
1979 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/AMR",
1983 case AV_CODEC_ID_AMR_WB:
1985 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/AMR-WB",
1989 case AV_CODEC_ID_GSM:
1991 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-gsm",
1995 case AV_CODEC_ID_GSM_MS:
1997 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/ms-gsm",
2001 case AV_CODEC_ID_NELLYMOSER:
2003 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
2004 "audio/x-nellymoser", NULL);
2007 case AV_CODEC_ID_SIPR:
2010 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-sipro",
2013 gst_caps_set_simple (caps,
2014 "leaf_size", G_TYPE_INT, context->block_align,
2015 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
2020 case AV_CODEC_ID_RA_144:
2021 case AV_CODEC_ID_RA_288:
2022 case AV_CODEC_ID_COOK:
2027 case AV_CODEC_ID_RA_144:
2030 case AV_CODEC_ID_RA_288:
2033 case AV_CODEC_ID_COOK:
2040 /* FIXME: properties? */
2042 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
2043 "audio/x-pn-realaudio", "raversion", G_TYPE_INT, version, NULL);
2045 gst_caps_set_simple (caps,
2046 "leaf_size", G_TYPE_INT, context->block_align,
2047 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
2052 case AV_CODEC_ID_ROQ_DPCM:
2053 case AV_CODEC_ID_INTERPLAY_DPCM:
2054 case AV_CODEC_ID_XAN_DPCM:
2055 case AV_CODEC_ID_SOL_DPCM:
2057 const gchar *layout = NULL;
2060 case AV_CODEC_ID_ROQ_DPCM:
2063 case AV_CODEC_ID_INTERPLAY_DPCM:
2064 layout = "interplay";
2066 case AV_CODEC_ID_XAN_DPCM:
2069 case AV_CODEC_ID_SOL_DPCM:
2073 g_assert (0); /* don't worry, we never get here */
2077 /* FIXME: someone please check whether we need additional properties
2078 * in this caps definition. */
2080 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dpcm",
2081 "layout", G_TYPE_STRING, layout, NULL);
2083 gst_caps_set_simple (caps,
2084 "block_align", G_TYPE_INT, context->block_align,
2085 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
2089 case AV_CODEC_ID_SHORTEN:
2090 caps = gst_caps_new_empty_simple ("audio/x-shorten");
2093 case AV_CODEC_ID_ALAC:
2095 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-alac",
2098 gst_caps_set_simple (caps,
2099 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
2103 case AV_CODEC_ID_FLAC:
2104 /* Note that ffmpeg has no encoder yet, but just for safety. In the
2105 * encoder case, we want to add things like samplerate, channels... */
2107 caps = gst_caps_new_empty_simple ("audio/x-flac");
2111 case AV_CODEC_ID_S302M:
2112 caps = gst_caps_new_empty_simple ("audio/x-smpte-302m");
2115 case AV_CODEC_ID_DVD_SUBTITLE:
2116 case AV_CODEC_ID_DVB_SUBTITLE:
2119 case AV_CODEC_ID_BMP:
2120 caps = gst_caps_new_empty_simple ("image/bmp");
2122 case AV_CODEC_ID_TTA:
2124 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-tta",
2127 gst_caps_set_simple (caps,
2128 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
2131 case AV_CODEC_ID_TWINVQ:
2133 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
2134 "audio/x-twin-vq", NULL);
2136 case AV_CODEC_ID_G729:
2138 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/G729",
2142 GST_DEBUG ("Unknown codec ID %d, please add mapping here", codec_id);
2149 if ((codec = avcodec_find_decoder (codec_id)) ||
2150 (codec = avcodec_find_encoder (codec_id))) {
2153 GST_LOG ("Could not create stream format caps for %s", codec->name);
2155 switch (codec->type) {
2156 case AVMEDIA_TYPE_VIDEO:
2157 mime = g_strdup_printf ("video/x-gst-av-%s", codec->name);
2159 gst_ff_vid_caps_new (context, NULL, codec_id, encode, mime, NULL);
2162 case AVMEDIA_TYPE_AUDIO:
2163 mime = g_strdup_printf ("audio/x-gst-av-%s", codec->name);
2165 gst_ff_aud_caps_new (context, NULL, codec_id, encode, mime, NULL);
2167 gst_caps_set_simple (caps,
2168 "block_align", G_TYPE_INT, context->block_align,
2169 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
2180 /* set private data */
2181 if (context && context->extradata_size > 0) {
2182 GstBuffer *data = gst_buffer_new_and_alloc (context->extradata_size);
2184 gst_buffer_fill (data, 0, context->extradata, context->extradata_size);
2185 gst_caps_set_simple (caps, "codec_data", GST_TYPE_BUFFER, data, NULL);
2186 gst_buffer_unref (data);
2189 GST_LOG ("caps for codec_id=%d: %" GST_PTR_FORMAT, codec_id, caps);
2192 GST_LOG ("No caps found for codec_id=%d", codec_id);
2198 /* Convert a FFMPEG Pixel Format and optional AVCodecContext
2199 * to a GstCaps. If the context is ommitted, no fixed values
2200 * for video/audio size will be included in the GstCaps
2202 * See below for usefullness
2206 gst_ffmpeg_pixfmt_to_caps (enum AVPixelFormat pix_fmt, AVCodecContext * context,
2207 enum AVCodecID codec_id)
2209 GstCaps *caps = NULL;
2210 GstVideoFormat format;
2212 format = gst_ffmpeg_pixfmt_to_videoformat (pix_fmt);
2214 if (format != GST_VIDEO_FORMAT_UNKNOWN) {
2215 caps = gst_ff_vid_caps_new (context, NULL, codec_id, TRUE, "video/x-raw",
2216 "format", G_TYPE_STRING, gst_video_format_to_string (format), NULL);
2220 GST_DEBUG ("caps for pix_fmt=%d: %" GST_PTR_FORMAT, pix_fmt, caps);
2222 GST_LOG ("No caps found for pix_fmt=%d", pix_fmt);
2229 gst_ffmpeg_smpfmt_to_audioformat (enum AVSampleFormat sample_fmt)
2231 switch (sample_fmt) {
2232 case AV_SAMPLE_FMT_U8:
2233 case AV_SAMPLE_FMT_U8P:
2234 return GST_AUDIO_FORMAT_U8;
2236 case AV_SAMPLE_FMT_S16:
2237 case AV_SAMPLE_FMT_S16P:
2238 return GST_AUDIO_FORMAT_S16;
2240 case AV_SAMPLE_FMT_S32:
2241 case AV_SAMPLE_FMT_S32P:
2242 return GST_AUDIO_FORMAT_S32;
2244 case AV_SAMPLE_FMT_FLT:
2245 case AV_SAMPLE_FMT_FLTP:
2246 return GST_AUDIO_FORMAT_F32;
2248 case AV_SAMPLE_FMT_DBL:
2249 case AV_SAMPLE_FMT_DBLP:
2250 return GST_AUDIO_FORMAT_F64;
2254 return GST_AUDIO_FORMAT_UNKNOWN;
2259 /* Convert a FFMPEG Sample Format and optional AVCodecContext
2260 * to a GstCaps. If the context is ommitted, no fixed values
2261 * for video/audio size will be included in the GstCaps
2263 * See below for usefullness
2267 gst_ffmpeg_smpfmt_to_caps (enum AVSampleFormat sample_fmt,
2268 AVCodecContext * context, AVCodec * codec, enum AVCodecID codec_id)
2270 GstCaps *caps = NULL;
2271 GstAudioFormat format;
2273 format = gst_ffmpeg_smpfmt_to_audioformat (sample_fmt);
2275 if (format != GST_AUDIO_FORMAT_UNKNOWN) {
2276 caps = gst_ff_aud_caps_new (context, codec, codec_id, TRUE, "audio/x-raw",
2277 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
2278 "layout", G_TYPE_STRING, "interleaved", NULL);
2279 GST_LOG ("caps for sample_fmt=%d: %" GST_PTR_FORMAT, sample_fmt, caps);
2281 GST_LOG ("No caps found for sample_fmt=%d", sample_fmt);
2288 caps_has_field (GstCaps * caps, const gchar * field)
2292 n = gst_caps_get_size (caps);
2293 for (i = 0; i < n; i++) {
2294 GstStructure *s = gst_caps_get_structure (caps, i);
2296 if (gst_structure_has_field (s, field))
2304 gst_ffmpeg_codectype_to_audio_caps (AVCodecContext * context,
2305 enum AVCodecID codec_id, gboolean encode, AVCodec * codec)
2307 GstCaps *caps = NULL;
2309 GST_DEBUG ("context:%p, codec_id:%d, encode:%d, codec:%p",
2310 context, codec_id, encode, codec);
2312 GST_DEBUG ("sample_fmts:%p, samplerates:%p",
2313 codec->sample_fmts, codec->supported_samplerates);
2316 /* Specific codec context */
2318 gst_ffmpeg_smpfmt_to_caps (context->sample_fmt, context, codec,
2321 caps = gst_ff_aud_caps_new (context, codec, codec_id, encode, "audio/x-raw",
2322 "layout", G_TYPE_STRING, "interleaved", NULL);
2323 if (!caps_has_field (caps, "format"))
2324 gst_ffmpeg_audio_set_sample_fmts (caps,
2325 codec ? codec->sample_fmts : NULL);
2332 gst_ffmpeg_codectype_to_video_caps (AVCodecContext * context,
2333 enum AVCodecID codec_id, gboolean encode, AVCodec * codec)
2337 GST_LOG ("context:%p, codec_id:%d, encode:%d, codec:%p",
2338 context, codec_id, encode, codec);
2341 caps = gst_ffmpeg_pixfmt_to_caps (context->pix_fmt, context, codec_id);
2344 gst_ff_vid_caps_new (context, codec, codec_id, encode, "video/x-raw",
2346 if (!caps_has_field (caps, "format"))
2347 gst_ffmpeg_video_set_pix_fmts (caps, codec ? codec->pix_fmts : NULL);
2352 /* Convert a GstCaps (audio/raw) to a FFMPEG SampleFmt
2353 * and other audio properties in a AVCodecContext.
2355 * For usefullness, see below
2359 gst_ffmpeg_caps_to_smpfmt (const GstCaps * caps,
2360 AVCodecContext * context, gboolean raw)
2362 GstStructure *structure;
2364 GstAudioFormat format = GST_AUDIO_FORMAT_UNKNOWN;
2367 g_return_if_fail (gst_caps_get_size (caps) == 1);
2369 structure = gst_caps_get_structure (caps, 0);
2371 gst_structure_get_int (structure, "channels", &context->channels);
2372 gst_structure_get_int (structure, "rate", &context->sample_rate);
2373 gst_structure_get_int (structure, "block_align", &context->block_align);
2374 if (gst_structure_get_int (structure, "bitrate", &bitrate))
2375 context->bit_rate = bitrate;
2380 if (gst_structure_has_name (structure, "audio/x-raw")) {
2381 if ((fmt = gst_structure_get_string (structure, "format"))) {
2382 format = gst_audio_format_from_string (fmt);
2387 case GST_AUDIO_FORMAT_F32:
2388 context->sample_fmt = AV_SAMPLE_FMT_FLT;
2390 case GST_AUDIO_FORMAT_F64:
2391 context->sample_fmt = AV_SAMPLE_FMT_DBL;
2393 case GST_AUDIO_FORMAT_S32:
2394 context->sample_fmt = AV_SAMPLE_FMT_S32;
2396 case GST_AUDIO_FORMAT_S16:
2397 context->sample_fmt = AV_SAMPLE_FMT_S16;
2404 /* Convert a GstCaps (video/raw) to a FFMPEG PixFmt
2405 * and other video properties in a AVCodecContext.
2407 * For usefullness, see below
2411 gst_ffmpeg_caps_to_pixfmt (const GstCaps * caps,
2412 AVCodecContext * context, gboolean raw)
2414 GstStructure *structure;
2416 const GValue *par = NULL;
2418 GstVideoFormat format = GST_VIDEO_FORMAT_UNKNOWN;
2420 GST_DEBUG ("converting caps %" GST_PTR_FORMAT, caps);
2421 g_return_if_fail (gst_caps_get_size (caps) == 1);
2422 structure = gst_caps_get_structure (caps, 0);
2424 gst_structure_get_int (structure, "width", &context->width);
2425 gst_structure_get_int (structure, "height", &context->height);
2426 gst_structure_get_int (structure, "bpp", &context->bits_per_coded_sample);
2428 fps = gst_structure_get_value (structure, "framerate");
2429 if (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps)) {
2431 int num = gst_value_get_fraction_numerator (fps);
2432 int den = gst_value_get_fraction_denominator (fps);
2434 if (num > 0 && den > 0) {
2435 /* somehow these seem mixed up.. */
2436 /* they're fine, this is because it does period=1/frequency */
2437 context->time_base.den = gst_value_get_fraction_numerator (fps);
2438 context->time_base.num = gst_value_get_fraction_denominator (fps);
2439 context->ticks_per_frame = 1;
2441 GST_DEBUG ("setting framerate %d/%d = %lf",
2442 context->time_base.den, context->time_base.num,
2443 1. * context->time_base.den / context->time_base.num);
2445 GST_INFO ("ignoring framerate %d/%d (probably variable framerate)",
2446 context->time_base.num, context->time_base.den);
2450 par = gst_structure_get_value (structure, "pixel-aspect-ratio");
2451 if (par && GST_VALUE_HOLDS_FRACTION (par)) {
2453 int num = gst_value_get_fraction_numerator (par);
2454 int den = gst_value_get_fraction_denominator (par);
2456 if (num > 0 && den > 0) {
2457 context->sample_aspect_ratio.num = num;
2458 context->sample_aspect_ratio.den = den;
2460 GST_DEBUG ("setting pixel-aspect-ratio %d/%d = %lf",
2461 context->sample_aspect_ratio.num, context->sample_aspect_ratio.den,
2462 1. * context->sample_aspect_ratio.num /
2463 context->sample_aspect_ratio.den);
2465 GST_WARNING ("ignoring insane pixel-aspect-ratio %d/%d",
2466 context->sample_aspect_ratio.num, context->sample_aspect_ratio.den);
2473 g_return_if_fail (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps));
2475 if (gst_structure_has_name (structure, "video/x-raw")) {
2476 if ((fmt = gst_structure_get_string (structure, "format"))) {
2477 format = gst_video_format_from_string (fmt);
2482 case GST_VIDEO_FORMAT_YUY2:
2483 context->pix_fmt = AV_PIX_FMT_YUYV422;
2485 case GST_VIDEO_FORMAT_I420:
2486 context->pix_fmt = AV_PIX_FMT_YUV420P;
2488 case GST_VIDEO_FORMAT_A420:
2489 context->pix_fmt = AV_PIX_FMT_YUVA420P;
2491 case GST_VIDEO_FORMAT_Y41B:
2492 context->pix_fmt = AV_PIX_FMT_YUV411P;
2494 case GST_VIDEO_FORMAT_Y42B:
2495 context->pix_fmt = AV_PIX_FMT_YUV422P;
2497 case GST_VIDEO_FORMAT_YUV9:
2498 context->pix_fmt = AV_PIX_FMT_YUV410P;
2500 case GST_VIDEO_FORMAT_Y444:
2501 context->pix_fmt = AV_PIX_FMT_YUV444P;
2503 case GST_VIDEO_FORMAT_GRAY8:
2504 context->pix_fmt = AV_PIX_FMT_GRAY8;
2506 case GST_VIDEO_FORMAT_xRGB:
2507 #if (G_BYTE_ORDER == G_BIG_ENDIAN)
2508 context->pix_fmt = AV_PIX_FMT_RGB32;
2511 case GST_VIDEO_FORMAT_BGRx:
2512 #if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
2513 context->pix_fmt = AV_PIX_FMT_RGB32;
2516 case GST_VIDEO_FORMAT_RGB:
2517 context->pix_fmt = AV_PIX_FMT_RGB24;
2519 case GST_VIDEO_FORMAT_BGR:
2520 context->pix_fmt = AV_PIX_FMT_BGR24;
2522 case GST_VIDEO_FORMAT_RGB16:
2523 context->pix_fmt = AV_PIX_FMT_RGB565;
2525 case GST_VIDEO_FORMAT_RGB15:
2526 context->pix_fmt = AV_PIX_FMT_RGB555;
2528 case GST_VIDEO_FORMAT_RGB8P:
2529 context->pix_fmt = AV_PIX_FMT_PAL8;
2538 GstVideoFormat format;
2539 enum AVPixelFormat pixfmt;
2542 /* FIXME : FILLME */
2543 static const PixToFmt pixtofmttable[] = {
2544 /* GST_VIDEO_FORMAT_I420, */
2545 {GST_VIDEO_FORMAT_I420, AV_PIX_FMT_YUV420P},
2546 /* Note : this should use a different chroma placement */
2547 {GST_VIDEO_FORMAT_I420, AV_PIX_FMT_YUVJ420P},
2549 /* GST_VIDEO_FORMAT_YV12, */
2550 /* GST_VIDEO_FORMAT_YUY2, */
2551 {GST_VIDEO_FORMAT_YUY2, AV_PIX_FMT_YUYV422},
2552 /* GST_VIDEO_FORMAT_UYVY, */
2553 {GST_VIDEO_FORMAT_UYVY, AV_PIX_FMT_UYVY422},
2554 /* GST_VIDEO_FORMAT_AYUV, */
2555 /* GST_VIDEO_FORMAT_RGBx, */
2556 /* GST_VIDEO_FORMAT_BGRx, */
2557 /* GST_VIDEO_FORMAT_xRGB, */
2558 /* GST_VIDEO_FORMAT_xBGR, */
2559 /* GST_VIDEO_FORMAT_RGBA, */
2560 {GST_VIDEO_FORMAT_RGBA, AV_PIX_FMT_RGBA},
2561 /* GST_VIDEO_FORMAT_BGRA, */
2562 {GST_VIDEO_FORMAT_BGRA, AV_PIX_FMT_BGRA},
2563 /* GST_VIDEO_FORMAT_ARGB, */
2564 {GST_VIDEO_FORMAT_ARGB, AV_PIX_FMT_ARGB},
2565 /* GST_VIDEO_FORMAT_ABGR, */
2566 {GST_VIDEO_FORMAT_ABGR, AV_PIX_FMT_ABGR},
2567 /* GST_VIDEO_FORMAT_RGB, */
2568 {GST_VIDEO_FORMAT_RGB, AV_PIX_FMT_RGB24},
2569 /* GST_VIDEO_FORMAT_BGR, */
2570 {GST_VIDEO_FORMAT_BGR, AV_PIX_FMT_BGR24},
2571 /* GST_VIDEO_FORMAT_Y41B, */
2572 {GST_VIDEO_FORMAT_Y41B, AV_PIX_FMT_YUV411P},
2573 /* GST_VIDEO_FORMAT_Y42B, */
2574 {GST_VIDEO_FORMAT_Y42B, AV_PIX_FMT_YUV422P},
2575 {GST_VIDEO_FORMAT_Y42B, AV_PIX_FMT_YUVJ422P},
2576 /* GST_VIDEO_FORMAT_YVYU, */
2577 /* GST_VIDEO_FORMAT_Y444, */
2578 {GST_VIDEO_FORMAT_Y444, AV_PIX_FMT_YUV444P},
2579 {GST_VIDEO_FORMAT_Y444, AV_PIX_FMT_YUVJ444P},
2580 /* GST_VIDEO_FORMAT_v210, */
2581 /* GST_VIDEO_FORMAT_v216, */
2582 /* GST_VIDEO_FORMAT_NV12, */
2583 {GST_VIDEO_FORMAT_NV12, AV_PIX_FMT_NV12},
2584 /* GST_VIDEO_FORMAT_NV21, */
2585 {GST_VIDEO_FORMAT_NV21, AV_PIX_FMT_NV21},
2586 /* GST_VIDEO_FORMAT_GRAY8, */
2587 {GST_VIDEO_FORMAT_GRAY8, AV_PIX_FMT_GRAY8},
2588 /* GST_VIDEO_FORMAT_GRAY16_BE, */
2589 {GST_VIDEO_FORMAT_GRAY16_BE, AV_PIX_FMT_GRAY16BE},
2590 /* GST_VIDEO_FORMAT_GRAY16_LE, */
2591 {GST_VIDEO_FORMAT_GRAY16_LE, AV_PIX_FMT_GRAY16LE},
2592 /* GST_VIDEO_FORMAT_v308, */
2593 /* GST_VIDEO_FORMAT_Y800, */
2594 /* GST_VIDEO_FORMAT_Y16, */
2595 /* GST_VIDEO_FORMAT_RGB16, */
2596 {GST_VIDEO_FORMAT_RGB16, AV_PIX_FMT_RGB565},
2597 /* GST_VIDEO_FORMAT_BGR16, */
2598 /* GST_VIDEO_FORMAT_RGB15, */
2599 {GST_VIDEO_FORMAT_RGB15, AV_PIX_FMT_RGB555},
2600 /* GST_VIDEO_FORMAT_BGR15, */
2601 /* GST_VIDEO_FORMAT_UYVP, */
2602 /* GST_VIDEO_FORMAT_A420, */
2603 {GST_VIDEO_FORMAT_A420, AV_PIX_FMT_YUVA420P},
2604 /* GST_VIDEO_FORMAT_RGB8_PALETTED, */
2605 {GST_VIDEO_FORMAT_RGB8P, AV_PIX_FMT_PAL8},
2606 /* GST_VIDEO_FORMAT_YUV9, */
2607 {GST_VIDEO_FORMAT_YUV9, AV_PIX_FMT_YUV410P},
2608 /* GST_VIDEO_FORMAT_YVU9, */
2609 /* GST_VIDEO_FORMAT_IYU1, */
2610 /* GST_VIDEO_FORMAT_ARGB64, */
2611 /* GST_VIDEO_FORMAT_AYUV64, */
2612 /* GST_VIDEO_FORMAT_r210, */
2613 {GST_VIDEO_FORMAT_I420_10LE, AV_PIX_FMT_YUV420P10LE},
2614 {GST_VIDEO_FORMAT_I420_10BE, AV_PIX_FMT_YUV420P10BE},
2615 {GST_VIDEO_FORMAT_I422_10LE, AV_PIX_FMT_YUV422P10LE},
2616 {GST_VIDEO_FORMAT_I422_10BE, AV_PIX_FMT_YUV422P10BE},
2617 {GST_VIDEO_FORMAT_Y444_10LE, AV_PIX_FMT_YUV444P10LE},
2618 {GST_VIDEO_FORMAT_Y444_10BE, AV_PIX_FMT_YUV444P10BE},
2619 {GST_VIDEO_FORMAT_GBR, AV_PIX_FMT_GBRP},
2620 {GST_VIDEO_FORMAT_GBR_10LE, AV_PIX_FMT_GBRP10LE},
2621 {GST_VIDEO_FORMAT_GBR_10BE, AV_PIX_FMT_GBRP10BE},
2622 {GST_VIDEO_FORMAT_A420_10LE, AV_PIX_FMT_YUVA420P10LE},
2623 {GST_VIDEO_FORMAT_A420_10BE, AV_PIX_FMT_YUVA420P10BE},
2624 {GST_VIDEO_FORMAT_A422_10LE, AV_PIX_FMT_YUVA422P10LE},
2625 {GST_VIDEO_FORMAT_A422_10BE, AV_PIX_FMT_YUVA422P10BE},
2626 {GST_VIDEO_FORMAT_A444_10LE, AV_PIX_FMT_YUVA444P10LE},
2627 {GST_VIDEO_FORMAT_A444_10BE, AV_PIX_FMT_YUVA444P10BE},
2631 gst_ffmpeg_pixfmt_to_videoformat (enum AVPixelFormat pixfmt)
2635 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2636 if (pixtofmttable[i].pixfmt == pixfmt)
2637 return pixtofmttable[i].format;
2639 GST_DEBUG ("Unknown pixel format %d", pixfmt);
2640 return GST_VIDEO_FORMAT_UNKNOWN;
2643 static enum AVPixelFormat
2644 gst_ffmpeg_videoformat_to_pixfmt_for_codec (GstVideoFormat format,
2645 const AVCodec * codec)
2649 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++) {
2650 if (pixtofmttable[i].format == format) {
2653 if (codec && codec->pix_fmts) {
2654 for (j = 0; codec->pix_fmts[j] != -1; j++) {
2655 if (pixtofmttable[i].pixfmt == codec->pix_fmts[j])
2656 return pixtofmttable[i].pixfmt;
2659 return pixtofmttable[i].pixfmt;
2664 return AV_PIX_FMT_NONE;
2668 gst_ffmpeg_videoformat_to_pixfmt (GstVideoFormat format)
2670 return gst_ffmpeg_videoformat_to_pixfmt_for_codec (format, NULL);
2674 gst_ffmpeg_videoinfo_to_context (GstVideoInfo * info, AVCodecContext * context)
2678 context->width = GST_VIDEO_INFO_WIDTH (info);
2679 context->height = GST_VIDEO_INFO_HEIGHT (info);
2680 for (i = 0; i < GST_VIDEO_INFO_N_COMPONENTS (info); i++)
2681 bpp += GST_VIDEO_INFO_COMP_DEPTH (info, i);
2682 context->bits_per_coded_sample = bpp;
2684 context->ticks_per_frame = 1;
2685 if (GST_VIDEO_INFO_FPS_N (info) == 0) {
2686 GST_DEBUG ("Using 25/1 framerate");
2687 context->time_base.den = 25;
2688 context->time_base.num = 1;
2690 context->time_base.den = GST_VIDEO_INFO_FPS_N (info);
2691 context->time_base.num = GST_VIDEO_INFO_FPS_D (info);
2694 context->sample_aspect_ratio.num = GST_VIDEO_INFO_PAR_N (info);
2695 context->sample_aspect_ratio.den = GST_VIDEO_INFO_PAR_D (info);
2698 gst_ffmpeg_videoformat_to_pixfmt_for_codec (GST_VIDEO_INFO_FORMAT (info),
2703 gst_ffmpeg_audioinfo_to_context (GstAudioInfo * info, AVCodecContext * context)
2705 const AVCodec *codec;
2706 const enum AVSampleFormat *smpl_fmts;
2707 enum AVSampleFormat smpl_fmt = -1;
2709 context->channels = info->channels;
2710 context->sample_rate = info->rate;
2711 context->channel_layout =
2712 gst_ffmpeg_channel_positions_to_layout (info->position, info->channels);
2714 codec = context->codec;
2716 smpl_fmts = codec->sample_fmts;
2718 switch (info->finfo->format) {
2719 case GST_AUDIO_FORMAT_F32:
2721 while (*smpl_fmts != -1) {
2722 if (*smpl_fmts == AV_SAMPLE_FMT_FLT) {
2723 smpl_fmt = *smpl_fmts;
2725 } else if (*smpl_fmts == AV_SAMPLE_FMT_FLTP) {
2726 smpl_fmt = *smpl_fmts;
2732 smpl_fmt = AV_SAMPLE_FMT_FLT;
2735 case GST_AUDIO_FORMAT_F64:
2737 while (*smpl_fmts != -1) {
2738 if (*smpl_fmts == AV_SAMPLE_FMT_DBL) {
2739 smpl_fmt = *smpl_fmts;
2741 } else if (*smpl_fmts == AV_SAMPLE_FMT_DBLP) {
2742 smpl_fmt = *smpl_fmts;
2748 smpl_fmt = AV_SAMPLE_FMT_DBL;
2751 case GST_AUDIO_FORMAT_S32:
2753 while (*smpl_fmts != -1) {
2754 if (*smpl_fmts == AV_SAMPLE_FMT_S32) {
2755 smpl_fmt = *smpl_fmts;
2757 } else if (*smpl_fmts == AV_SAMPLE_FMT_S32P) {
2758 smpl_fmt = *smpl_fmts;
2764 smpl_fmt = AV_SAMPLE_FMT_S32;
2767 case GST_AUDIO_FORMAT_S16:
2769 while (*smpl_fmts != -1) {
2770 if (*smpl_fmts == AV_SAMPLE_FMT_S16) {
2771 smpl_fmt = *smpl_fmts;
2773 } else if (*smpl_fmts == AV_SAMPLE_FMT_S16P) {
2774 smpl_fmt = *smpl_fmts;
2780 smpl_fmt = AV_SAMPLE_FMT_S16;
2783 case GST_AUDIO_FORMAT_U8:
2785 while (*smpl_fmts != -1) {
2786 if (*smpl_fmts == AV_SAMPLE_FMT_U8) {
2787 smpl_fmt = *smpl_fmts;
2789 } else if (*smpl_fmts == AV_SAMPLE_FMT_U8P) {
2790 smpl_fmt = *smpl_fmts;
2796 smpl_fmt = AV_SAMPLE_FMT_U8;
2803 g_assert (smpl_fmt != -1);
2805 context->sample_fmt = smpl_fmt;
2808 /* Convert a GstCaps and a FFMPEG codec Type to a
2809 * AVCodecContext. If the context is ommitted, no fixed values
2810 * for video/audio size will be included in the context
2812 * AVMediaType is primarily meant for uncompressed data GstCaps!
2816 gst_ffmpeg_caps_with_codectype (enum AVMediaType type,
2817 const GstCaps * caps, AVCodecContext * context)
2819 if (context == NULL)
2823 case AVMEDIA_TYPE_VIDEO:
2824 gst_ffmpeg_caps_to_pixfmt (caps, context, TRUE);
2827 case AVMEDIA_TYPE_AUDIO:
2828 gst_ffmpeg_caps_to_smpfmt (caps, context, TRUE);
2839 nal_escape (guint8 * dst, guint8 * src, guint size, guint * destsize)
2843 guint8 *end = src + size;
2846 while (srcp < end) {
2847 if (count == 2 && *srcp <= 0x03) {
2848 GST_DEBUG ("added escape code");
2857 GST_DEBUG ("copy %02x, count %d", *srcp, count);
2860 *destsize = dstp - dst;
2863 /* copy the config, escaping NAL units as we iterate them, if something fails we
2864 * copy everything and hope for the best. */
2866 copy_config (guint8 * dst, guint8 * src, guint size, guint * destsize)
2871 guint nalsize, esize;
2881 cnt = *(srcp + 5) & 0x1f; /* Number of sps */
2883 GST_DEBUG ("num SPS %d", cnt);
2885 memcpy (dstp, srcp, 6);
2889 for (i = 0; i < cnt; i++) {
2890 GST_DEBUG ("copy SPS %d", i);
2891 nalsize = (srcp[0] << 8) | srcp[1];
2892 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2893 dstp[0] = esize >> 8;
2894 dstp[1] = esize & 0xff;
2896 srcp += nalsize + 2;
2899 cnt = *(dstp++) = *(srcp++); /* Number of pps */
2901 GST_DEBUG ("num PPS %d", cnt);
2903 for (i = 0; i < cnt; i++) {
2904 GST_DEBUG ("copy PPS %d", i);
2905 nalsize = (srcp[0] << 8) | srcp[1];
2906 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2907 dstp[0] = esize >> 8;
2908 dstp[1] = esize & 0xff;
2910 srcp += nalsize + 2;
2912 *destsize = dstp - dst;
2918 GST_DEBUG ("something unexpected, doing full copy");
2919 memcpy (dst, src, size);
2927 * caps_with_codecid () transforms a GstCaps for a known codec
2928 * ID into a filled-in context.
2929 * codec_data from caps will override possible extradata already in the context
2933 gst_ffmpeg_caps_with_codecid (enum AVCodecID codec_id,
2934 enum AVMediaType codec_type, const GstCaps * caps, AVCodecContext * context)
2937 const GValue *value;
2940 GST_LOG ("codec_id:%d, codec_type:%d, caps:%" GST_PTR_FORMAT " context:%p",
2941 codec_id, codec_type, caps, context);
2943 if (!context || !gst_caps_get_size (caps))
2946 str = gst_caps_get_structure (caps, 0);
2948 /* extradata parsing (esds [mpeg4], wma/wmv, msmpeg4v1/2/3, etc.) */
2949 if ((value = gst_structure_get_value (str, "codec_data"))) {
2952 buf = gst_value_get_buffer (value);
2953 gst_buffer_map (buf, &map, GST_MAP_READ);
2955 /* free the old one if it is there */
2956 if (context->extradata)
2957 av_free (context->extradata);
2960 if (codec_id == AV_CODEC_ID_H264) {
2963 GST_DEBUG ("copy, escaping codec_data %d", size);
2964 /* ffmpeg h264 expects the codec_data to be escaped, there is no real
2965 * reason for this but let's just escape it for now. Start by allocating
2966 * enough space, x2 is more than enough.
2968 * FIXME, we disabled escaping because some file already contain escaped
2969 * codec_data and then we escape twice and fail. It's better to leave it
2970 * as is, as that is what most players do. */
2971 context->extradata =
2972 av_mallocz (GST_ROUND_UP_16 (size * 2 +
2973 FF_INPUT_BUFFER_PADDING_SIZE));
2974 copy_config (context->extradata, data, size, &extrasize);
2975 GST_DEBUG ("escaped size: %d", extrasize);
2976 context->extradata_size = extrasize;
2980 /* allocate with enough padding */
2981 GST_DEBUG ("copy codec_data");
2982 context->extradata =
2983 av_mallocz (GST_ROUND_UP_16 (map.size +
2984 FF_INPUT_BUFFER_PADDING_SIZE));
2985 memcpy (context->extradata, map.data, map.size);
2986 context->extradata_size = map.size;
2989 /* Hack for VC1. Sometimes the first (length) byte is 0 for some files */
2990 if (codec_id == AV_CODEC_ID_VC1 && map.size > 0 && map.data[0] == 0) {
2991 context->extradata[0] = (guint8) map.size;
2994 GST_DEBUG ("have codec data of size %" G_GSIZE_FORMAT, map.size);
2996 gst_buffer_unmap (buf, &map);
2998 context->extradata = NULL;
2999 context->extradata_size = 0;
3000 GST_DEBUG ("no codec data");
3004 case AV_CODEC_ID_MPEG4:
3006 const gchar *mime = gst_structure_get_name (str);
3008 context->flags |= CODEC_FLAG_4MV;
3010 if (!strcmp (mime, "video/x-divx"))
3011 context->codec_tag = GST_MAKE_FOURCC ('D', 'I', 'V', 'X');
3012 else if (!strcmp (mime, "video/mpeg")) {
3013 const gchar *profile;
3015 context->codec_tag = GST_MAKE_FOURCC ('m', 'p', '4', 'v');
3017 profile = gst_structure_get_string (str, "profile");
3019 if (g_strcmp0 (profile, "advanced-simple") == 0)
3020 context->flags |= CODEC_FLAG_GMC | CODEC_FLAG_QPEL;
3026 case AV_CODEC_ID_SVQ3:
3027 /* FIXME: this is a workaround for older gst-plugins releases
3028 * (<= 0.8.9). This should be removed at some point, because
3029 * it causes wrong decoded frame order. */
3030 if (!context->extradata) {
3031 gint halfpel_flag, thirdpel_flag, low_delay, unknown_svq3_flag;
3034 if (gst_structure_get_int (str, "halfpel_flag", &halfpel_flag) &&
3035 gst_structure_get_int (str, "thirdpel_flag", &thirdpel_flag) &&
3036 gst_structure_get_int (str, "low_delay", &low_delay) &&
3037 gst_structure_get_int (str, "unknown_svq3_flag",
3038 &unknown_svq3_flag)) {
3039 context->extradata = (guint8 *) av_mallocz (0x64);
3040 g_stpcpy ((gchar *) context->extradata, "SVQ3");
3044 flags |= unknown_svq3_flag;
3046 flags |= halfpel_flag;
3048 flags |= thirdpel_flag;
3051 flags = GUINT16_FROM_LE (flags);
3053 memcpy ((gchar *) context->extradata + 0x62, &flags, 2);
3054 context->extradata_size = 0x64;
3059 case AV_CODEC_ID_MSRLE:
3060 case AV_CODEC_ID_QTRLE:
3061 case AV_CODEC_ID_TSCC:
3062 case AV_CODEC_ID_CSCD:
3063 case AV_CODEC_ID_APE:
3067 if (gst_structure_get_int (str, "depth", &depth)) {
3068 context->bits_per_coded_sample = depth;
3070 GST_WARNING ("No depth field in caps %" GST_PTR_FORMAT, caps);
3076 case AV_CODEC_ID_COOK:
3077 case AV_CODEC_ID_RA_288:
3078 case AV_CODEC_ID_RA_144:
3079 case AV_CODEC_ID_SIPR:
3084 if (gst_structure_get_int (str, "leaf_size", &leaf_size))
3085 context->block_align = leaf_size;
3086 if (gst_structure_get_int (str, "bitrate", &bitrate))
3087 context->bit_rate = bitrate;
3090 case AV_CODEC_ID_ALAC:
3091 gst_structure_get_int (str, "samplesize",
3092 &context->bits_per_coded_sample);
3095 case AV_CODEC_ID_DVVIDEO:
3097 const gchar *format;
3099 if ((format = gst_structure_get_string (str, "format"))) {
3101 if (g_str_equal (format, "YUY2"))
3102 context->pix_fmt = AV_PIX_FMT_YUYV422;
3103 else if (g_str_equal (format, "I420"))
3104 context->pix_fmt = AV_PIX_FMT_YUV420P;
3105 else if (g_str_equal (format, "A420"))
3106 context->pix_fmt = AV_PIX_FMT_YUVA420P;
3107 else if (g_str_equal (format, "Y41B"))
3108 context->pix_fmt = AV_PIX_FMT_YUV411P;
3109 else if (g_str_equal (format, "Y42B"))
3110 context->pix_fmt = AV_PIX_FMT_YUV422P;
3111 else if (g_str_equal (format, "YUV9"))
3112 context->pix_fmt = AV_PIX_FMT_YUV410P;
3114 GST_WARNING ("couldn't convert format %s" " to a pixel format",
3118 GST_WARNING ("No specified format");
3121 case AV_CODEC_ID_H263P:
3125 if (!gst_structure_get_boolean (str, "annex-f", &val) || val)
3126 context->flags |= CODEC_FLAG_4MV;
3128 context->flags &= ~CODEC_FLAG_4MV;
3129 if ((!gst_structure_get_boolean (str, "annex-i", &val) || val) &&
3130 (!gst_structure_get_boolean (str, "annex-t", &val) || val))
3131 context->flags |= CODEC_FLAG_AC_PRED;
3133 context->flags &= ~CODEC_FLAG_AC_PRED;
3134 if (!gst_structure_get_boolean (str, "annex-j", &val) || val)
3135 context->flags |= CODEC_FLAG_LOOP_FILTER;
3137 context->flags &= ~CODEC_FLAG_LOOP_FILTER;
3140 case AV_CODEC_ID_ADPCM_G726:
3142 const gchar *layout;
3144 if ((layout = gst_structure_get_string (str, "layout"))) {
3145 if (!strcmp (layout, "g721")) {
3146 context->sample_rate = 8000;
3147 context->channels = 1;
3148 context->bit_rate = 32000;
3157 if (!gst_caps_is_fixed (caps))
3160 /* common properties (width, height, fps) */
3161 switch (codec_type) {
3162 case AVMEDIA_TYPE_VIDEO:
3163 gst_ffmpeg_caps_to_pixfmt (caps, context,
3164 codec_id == AV_CODEC_ID_RAWVIDEO);
3166 case AVMEDIA_TYPE_AUDIO:
3167 gst_ffmpeg_caps_to_smpfmt (caps, context, FALSE);
3173 /* fixup of default settings */
3175 case AV_CODEC_ID_QCELP:
3176 /* QCELP is always mono, no matter what the caps say */
3177 context->channels = 1;
3179 case AV_CODEC_ID_ADPCM_G726:
3180 if (context->sample_rate && context->bit_rate)
3181 context->bits_per_coded_sample =
3182 context->bit_rate / context->sample_rate;
3189 /* _formatid_to_caps () is meant for muxers/demuxers, it
3190 * transforms a name (ffmpeg way of ID'ing these, why don't
3191 * they have unique numerical IDs?) to the corresponding
3192 * caps belonging to that mux-format
3194 * Note: we don't need any additional info because the caps
3195 * isn't supposed to contain any useful info besides the
3200 gst_ffmpeg_formatid_to_caps (const gchar * format_name)
3202 GstCaps *caps = NULL;
3204 if (!strcmp (format_name, "mpeg")) {
3205 caps = gst_caps_new_simple ("video/mpeg",
3206 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3207 } else if (!strcmp (format_name, "mpegts")) {
3208 caps = gst_caps_new_simple ("video/mpegts",
3209 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3210 } else if (!strcmp (format_name, "rm")) {
3211 caps = gst_caps_new_simple ("application/x-pn-realmedia",
3212 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3213 } else if (!strcmp (format_name, "asf")) {
3214 caps = gst_caps_new_empty_simple ("video/x-ms-asf");
3215 } else if (!strcmp (format_name, "avi")) {
3216 caps = gst_caps_new_empty_simple ("video/x-msvideo");
3217 } else if (!strcmp (format_name, "wav")) {
3218 caps = gst_caps_new_empty_simple ("audio/x-wav");
3219 } else if (!strcmp (format_name, "ape")) {
3220 caps = gst_caps_new_empty_simple ("application/x-ape");
3221 } else if (!strcmp (format_name, "swf")) {
3222 caps = gst_caps_new_empty_simple ("application/x-shockwave-flash");
3223 } else if (!strcmp (format_name, "au")) {
3224 caps = gst_caps_new_empty_simple ("audio/x-au");
3225 } else if (!strcmp (format_name, "dv")) {
3226 caps = gst_caps_new_simple ("video/x-dv",
3227 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3228 } else if (!strcmp (format_name, "4xm")) {
3229 caps = gst_caps_new_empty_simple ("video/x-4xm");
3230 } else if (!strcmp (format_name, "matroska")) {
3231 caps = gst_caps_new_empty_simple ("video/x-matroska");
3232 } else if (!strcmp (format_name, "mp3")) {
3233 caps = gst_caps_new_empty_simple ("application/x-id3");
3234 } else if (!strcmp (format_name, "flic")) {
3235 caps = gst_caps_new_empty_simple ("video/x-fli");
3236 } else if (!strcmp (format_name, "flv")) {
3237 caps = gst_caps_new_empty_simple ("video/x-flv");
3238 } else if (!strcmp (format_name, "tta")) {
3239 caps = gst_caps_new_empty_simple ("audio/x-ttafile");
3240 } else if (!strcmp (format_name, "aiff")) {
3241 caps = gst_caps_new_empty_simple ("audio/x-aiff");
3242 } else if (!strcmp (format_name, "mov_mp4_m4a_3gp_3g2")) {
3244 gst_caps_from_string
3245 ("application/x-3gp; video/quicktime; audio/x-m4a");
3246 } else if (!strcmp (format_name, "mov")) {
3247 caps = gst_caps_from_string ("video/quicktime,variant=(string)apple");
3248 } else if (!strcmp (format_name, "mp4")) {
3249 caps = gst_caps_from_string ("video/quicktime,variant=(string)iso");
3250 } else if (!strcmp (format_name, "3gp")) {
3251 caps = gst_caps_from_string ("video/quicktime,variant=(string)3gpp");
3252 } else if (!strcmp (format_name, "3g2")) {
3253 caps = gst_caps_from_string ("video/quicktime,variant=(string)3g2");
3254 } else if (!strcmp (format_name, "psp")) {
3255 caps = gst_caps_from_string ("video/quicktime,variant=(string)psp");
3256 } else if (!strcmp (format_name, "ipod")) {
3257 caps = gst_caps_from_string ("video/quicktime,variant=(string)ipod");
3258 } else if (!strcmp (format_name, "aac")) {
3259 caps = gst_caps_new_simple ("audio/mpeg",
3260 "mpegversion", G_TYPE_INT, 4, NULL);
3261 } else if (!strcmp (format_name, "gif")) {
3262 caps = gst_caps_from_string ("image/gif");
3263 } else if (!strcmp (format_name, "ogg")) {
3264 caps = gst_caps_from_string ("application/ogg");
3265 } else if (!strcmp (format_name, "mxf") || !strcmp (format_name, "mxf_d10")) {
3266 caps = gst_caps_from_string ("application/mxf");
3267 } else if (!strcmp (format_name, "gxf")) {
3268 caps = gst_caps_from_string ("application/gxf");
3269 } else if (!strcmp (format_name, "yuv4mpegpipe")) {
3270 caps = gst_caps_new_simple ("application/x-yuv4mpeg",
3271 "y4mversion", G_TYPE_INT, 2, NULL);
3272 } else if (!strcmp (format_name, "mpc")) {
3273 caps = gst_caps_from_string ("audio/x-musepack, streamversion = (int) 7");
3274 } else if (!strcmp (format_name, "mpc8")) {
3275 caps = gst_caps_from_string ("audio/x-musepack, streamversion = (int) 8");
3276 } else if (!strcmp (format_name, "vqf")) {
3277 caps = gst_caps_from_string ("audio/x-vqf");
3278 } else if (!strcmp (format_name, "nsv")) {
3279 caps = gst_caps_from_string ("video/x-nsv");
3280 } else if (!strcmp (format_name, "amr")) {
3281 caps = gst_caps_from_string ("audio/x-amr-nb-sh");
3282 } else if (!strcmp (format_name, "webm")) {
3283 caps = gst_caps_from_string ("video/webm");
3284 } else if (!strcmp (format_name, "voc")) {
3285 caps = gst_caps_from_string ("audio/x-voc");
3286 } else if (!strcmp (format_name, "pva")) {
3287 caps = gst_caps_from_string ("video/x-pva");
3291 GST_LOG ("Could not create stream format caps for %s", format_name);
3292 name = g_strdup_printf ("application/x-gst-av-%s", format_name);
3293 caps = gst_caps_new_empty_simple (name);
3301 gst_ffmpeg_formatid_get_codecids (const gchar * format_name,
3302 enum AVCodecID ** video_codec_list, enum AVCodecID ** audio_codec_list,
3303 AVOutputFormat * plugin)
3305 static enum AVCodecID tmp_vlist[] = {
3309 static enum AVCodecID tmp_alist[] = {
3314 GST_LOG ("format_name : %s", format_name);
3316 if (!strcmp (format_name, "mp4")) {
3317 static enum AVCodecID mp4_video_list[] = {
3318 AV_CODEC_ID_MPEG4, AV_CODEC_ID_H264,
3322 static enum AVCodecID mp4_audio_list[] = {
3323 AV_CODEC_ID_AAC, AV_CODEC_ID_MP3,
3327 *video_codec_list = mp4_video_list;
3328 *audio_codec_list = mp4_audio_list;
3329 } else if (!strcmp (format_name, "mpeg")) {
3330 static enum AVCodecID mpeg_video_list[] = { AV_CODEC_ID_MPEG1VIDEO,
3331 AV_CODEC_ID_MPEG2VIDEO,
3335 static enum AVCodecID mpeg_audio_list[] = { AV_CODEC_ID_MP1,
3341 *video_codec_list = mpeg_video_list;
3342 *audio_codec_list = mpeg_audio_list;
3343 } else if (!strcmp (format_name, "dvd")) {
3344 static enum AVCodecID mpeg_video_list[] = { AV_CODEC_ID_MPEG2VIDEO,
3347 static enum AVCodecID mpeg_audio_list[] = { AV_CODEC_ID_MP2,
3350 AV_CODEC_ID_PCM_S16BE,
3354 *video_codec_list = mpeg_video_list;
3355 *audio_codec_list = mpeg_audio_list;
3356 } else if (!strcmp (format_name, "mpegts")) {
3357 static enum AVCodecID mpegts_video_list[] = { AV_CODEC_ID_MPEG1VIDEO,
3358 AV_CODEC_ID_MPEG2VIDEO,
3362 static enum AVCodecID mpegts_audio_list[] = { AV_CODEC_ID_MP2,
3370 *video_codec_list = mpegts_video_list;
3371 *audio_codec_list = mpegts_audio_list;
3372 } else if (!strcmp (format_name, "vob")) {
3373 static enum AVCodecID vob_video_list[] =
3374 { AV_CODEC_ID_MPEG2VIDEO, AV_CODEC_ID_NONE };
3375 static enum AVCodecID vob_audio_list[] = { AV_CODEC_ID_MP2, AV_CODEC_ID_AC3,
3376 AV_CODEC_ID_DTS, AV_CODEC_ID_NONE
3379 *video_codec_list = vob_video_list;
3380 *audio_codec_list = vob_audio_list;
3381 } else if (!strcmp (format_name, "flv")) {
3382 static enum AVCodecID flv_video_list[] =
3383 { AV_CODEC_ID_FLV1, AV_CODEC_ID_NONE };
3384 static enum AVCodecID flv_audio_list[] =
3385 { AV_CODEC_ID_MP3, AV_CODEC_ID_NONE };
3387 *video_codec_list = flv_video_list;
3388 *audio_codec_list = flv_audio_list;
3389 } else if (!strcmp (format_name, "asf")) {
3390 static enum AVCodecID asf_video_list[] =
3391 { AV_CODEC_ID_WMV1, AV_CODEC_ID_WMV2, AV_CODEC_ID_MSMPEG4V3,
3394 static enum AVCodecID asf_audio_list[] =
3395 { AV_CODEC_ID_WMAV1, AV_CODEC_ID_WMAV2, AV_CODEC_ID_MP3,
3399 *video_codec_list = asf_video_list;
3400 *audio_codec_list = asf_audio_list;
3401 } else if (!strcmp (format_name, "dv")) {
3402 static enum AVCodecID dv_video_list[] =
3403 { AV_CODEC_ID_DVVIDEO, AV_CODEC_ID_NONE };
3404 static enum AVCodecID dv_audio_list[] =
3405 { AV_CODEC_ID_PCM_S16LE, AV_CODEC_ID_NONE };
3407 *video_codec_list = dv_video_list;
3408 *audio_codec_list = dv_audio_list;
3409 } else if (!strcmp (format_name, "mov")) {
3410 static enum AVCodecID mov_video_list[] = {
3411 AV_CODEC_ID_SVQ1, AV_CODEC_ID_SVQ3, AV_CODEC_ID_MPEG4,
3412 AV_CODEC_ID_H263, AV_CODEC_ID_H263P,
3413 AV_CODEC_ID_H264, AV_CODEC_ID_DVVIDEO,
3417 static enum AVCodecID mov_audio_list[] = {
3418 AV_CODEC_ID_PCM_MULAW, AV_CODEC_ID_PCM_ALAW, AV_CODEC_ID_ADPCM_IMA_QT,
3419 AV_CODEC_ID_MACE3, AV_CODEC_ID_MACE6, AV_CODEC_ID_AAC,
3420 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3421 AV_CODEC_ID_PCM_S16BE, AV_CODEC_ID_PCM_S16LE,
3422 AV_CODEC_ID_MP3, AV_CODEC_ID_NONE
3425 *video_codec_list = mov_video_list;
3426 *audio_codec_list = mov_audio_list;
3427 } else if ((!strcmp (format_name, "3gp") || !strcmp (format_name, "3g2"))) {
3428 static enum AVCodecID tgp_video_list[] = {
3429 AV_CODEC_ID_MPEG4, AV_CODEC_ID_H263, AV_CODEC_ID_H263P, AV_CODEC_ID_H264,
3432 static enum AVCodecID tgp_audio_list[] = {
3433 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3438 *video_codec_list = tgp_video_list;
3439 *audio_codec_list = tgp_audio_list;
3440 } else if (!strcmp (format_name, "mmf")) {
3441 static enum AVCodecID mmf_audio_list[] = {
3442 AV_CODEC_ID_ADPCM_YAMAHA, AV_CODEC_ID_NONE
3444 *video_codec_list = NULL;
3445 *audio_codec_list = mmf_audio_list;
3446 } else if (!strcmp (format_name, "amr")) {
3447 static enum AVCodecID amr_audio_list[] = {
3448 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3451 *video_codec_list = NULL;
3452 *audio_codec_list = amr_audio_list;
3453 } else if (!strcmp (format_name, "gif")) {
3454 static enum AVCodecID gif_image_list[] = {
3455 AV_CODEC_ID_RAWVIDEO, AV_CODEC_ID_NONE
3457 *video_codec_list = gif_image_list;
3458 *audio_codec_list = NULL;
3459 } else if ((plugin->audio_codec != AV_CODEC_ID_NONE) ||
3460 (plugin->video_codec != AV_CODEC_ID_NONE)) {
3461 tmp_vlist[0] = plugin->video_codec;
3462 tmp_alist[0] = plugin->audio_codec;
3464 *video_codec_list = tmp_vlist;
3465 *audio_codec_list = tmp_alist;
3466 } else if ((!strcmp (format_name, "pva"))) {
3467 static enum AVCodecID tgp_video_list[] = {
3468 AV_CODEC_ID_MPEG2VIDEO,
3471 static enum AVCodecID tgp_audio_list[] = {
3476 *video_codec_list = tgp_video_list;
3477 *audio_codec_list = tgp_audio_list;
3479 GST_LOG ("Format %s not found", format_name);
3486 /* Convert a GstCaps to a FFMPEG codec ID. Size et all
3487 * are omitted, that can be queried by the user itself,
3488 * we're not eating the GstCaps or anything
3489 * A pointer to an allocated context is also needed for
3490 * optional extra info
3494 gst_ffmpeg_caps_to_codecid (const GstCaps * caps, AVCodecContext * context)
3496 enum AVCodecID id = AV_CODEC_ID_NONE;
3497 const gchar *mimetype;
3498 const GstStructure *structure;
3499 gboolean video = FALSE, audio = FALSE; /* we want to be sure! */
3501 g_return_val_if_fail (caps != NULL, AV_CODEC_ID_NONE);
3502 g_return_val_if_fail (gst_caps_get_size (caps) == 1, AV_CODEC_ID_NONE);
3503 structure = gst_caps_get_structure (caps, 0);
3505 mimetype = gst_structure_get_name (structure);
3507 if (!strcmp (mimetype, "video/x-raw")) {
3508 id = AV_CODEC_ID_RAWVIDEO;
3510 } else if (!strcmp (mimetype, "audio/x-raw")) {
3513 if (gst_audio_info_from_caps (&info, caps)) {
3514 switch (GST_AUDIO_INFO_FORMAT (&info)) {
3515 case GST_AUDIO_FORMAT_S8:
3516 id = AV_CODEC_ID_PCM_S8;
3518 case GST_AUDIO_FORMAT_U8:
3519 id = AV_CODEC_ID_PCM_U8;
3521 case GST_AUDIO_FORMAT_S16LE:
3522 id = AV_CODEC_ID_PCM_S16LE;
3524 case GST_AUDIO_FORMAT_S16BE:
3525 id = AV_CODEC_ID_PCM_S16BE;
3527 case GST_AUDIO_FORMAT_U16LE:
3528 id = AV_CODEC_ID_PCM_U16LE;
3530 case GST_AUDIO_FORMAT_U16BE:
3531 id = AV_CODEC_ID_PCM_U16BE;
3536 if (id != AV_CODEC_ID_NONE)
3539 } else if (!strcmp (mimetype, "audio/x-mulaw")) {
3540 id = AV_CODEC_ID_PCM_MULAW;
3542 } else if (!strcmp (mimetype, "audio/x-alaw")) {
3543 id = AV_CODEC_ID_PCM_ALAW;
3545 } else if (!strcmp (mimetype, "video/x-dv")) {
3548 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3550 id = AV_CODEC_ID_DVVIDEO;
3553 } else if (!strcmp (mimetype, "audio/x-dv")) { /* ??? */
3554 id = AV_CODEC_ID_DVAUDIO;
3556 } else if (!strcmp (mimetype, "video/x-h263")) {
3557 const gchar *h263version =
3558 gst_structure_get_string (structure, "h263version");
3559 if (h263version && !strcmp (h263version, "h263p"))
3560 id = AV_CODEC_ID_H263P;
3562 id = AV_CODEC_ID_H263;
3564 } else if (!strcmp (mimetype, "video/x-intel-h263")) {
3565 id = AV_CODEC_ID_H263I;
3567 } else if (!strcmp (mimetype, "video/x-h261")) {
3568 id = AV_CODEC_ID_H261;
3570 } else if (!strcmp (mimetype, "video/mpeg")) {
3574 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3575 gst_structure_get_int (structure, "mpegversion", &mpegversion) &&
3577 switch (mpegversion) {
3579 id = AV_CODEC_ID_MPEG1VIDEO;
3582 id = AV_CODEC_ID_MPEG2VIDEO;
3585 id = AV_CODEC_ID_MPEG4;
3589 if (id != AV_CODEC_ID_NONE)
3591 } else if (!strcmp (mimetype, "image/jpeg")) {
3592 id = AV_CODEC_ID_MJPEG; /* A... B... */
3594 } else if (!strcmp (mimetype, "video/x-jpeg-b")) {
3595 id = AV_CODEC_ID_MJPEGB;
3597 } else if (!strcmp (mimetype, "video/x-wmv")) {
3598 gint wmvversion = 0;
3600 if (gst_structure_get_int (structure, "wmvversion", &wmvversion)) {
3601 switch (wmvversion) {
3603 id = AV_CODEC_ID_WMV1;
3606 id = AV_CODEC_ID_WMV2;
3610 const gchar *format;
3612 /* WMV3 unless the fourcc exists and says otherwise */
3613 id = AV_CODEC_ID_WMV3;
3615 if ((format = gst_structure_get_string (structure, "format")) &&
3616 (g_str_equal (format, "WVC1") || g_str_equal (format, "WMVA")))
3617 id = AV_CODEC_ID_VC1;
3623 if (id != AV_CODEC_ID_NONE)
3625 } else if (!strcmp (mimetype, "audio/x-vorbis")) {
3626 id = AV_CODEC_ID_VORBIS;
3628 } else if (!strcmp (mimetype, "audio/x-qdm2")) {
3629 id = AV_CODEC_ID_QDM2;
3631 } else if (!strcmp (mimetype, "audio/mpeg")) {
3633 gint mpegversion = 0;
3635 if (gst_structure_get_int (structure, "mpegversion", &mpegversion)) {
3636 switch (mpegversion) {
3637 case 2: /* ffmpeg uses faad for both... */
3639 id = AV_CODEC_ID_AAC;
3642 if (gst_structure_get_int (structure, "layer", &layer)) {
3645 id = AV_CODEC_ID_MP1;
3648 id = AV_CODEC_ID_MP2;
3651 id = AV_CODEC_ID_MP3;
3657 if (id != AV_CODEC_ID_NONE)
3659 } else if (!strcmp (mimetype, "audio/x-musepack")) {
3660 gint streamversion = -1;
3662 if (gst_structure_get_int (structure, "streamversion", &streamversion)) {
3663 if (streamversion == 7)
3664 id = AV_CODEC_ID_MUSEPACK7;
3666 id = AV_CODEC_ID_MUSEPACK7;
3668 } else if (!strcmp (mimetype, "audio/x-wma")) {
3669 gint wmaversion = 0;
3671 if (gst_structure_get_int (structure, "wmaversion", &wmaversion)) {
3672 switch (wmaversion) {
3674 id = AV_CODEC_ID_WMAV1;
3677 id = AV_CODEC_ID_WMAV2;
3680 id = AV_CODEC_ID_WMAPRO;
3684 if (id != AV_CODEC_ID_NONE)
3686 } else if (!strcmp (mimetype, "audio/x-wms")) {
3687 id = AV_CODEC_ID_WMAVOICE;
3689 } else if (!strcmp (mimetype, "audio/x-ac3")) {
3690 id = AV_CODEC_ID_AC3;
3692 } else if (!strcmp (mimetype, "audio/x-eac3")) {
3693 id = AV_CODEC_ID_EAC3;
3695 } else if (!strcmp (mimetype, "audio/x-vnd.sony.atrac3") ||
3696 !strcmp (mimetype, "audio/atrac3")) {
3697 id = AV_CODEC_ID_ATRAC3;
3699 } else if (!strcmp (mimetype, "audio/x-dts")) {
3700 id = AV_CODEC_ID_DTS;
3702 } else if (!strcmp (mimetype, "application/x-ape")) {
3703 id = AV_CODEC_ID_APE;
3705 } else if (!strcmp (mimetype, "video/x-msmpeg")) {
3706 gint msmpegversion = 0;
3708 if (gst_structure_get_int (structure, "msmpegversion", &msmpegversion)) {
3709 switch (msmpegversion) {
3711 id = AV_CODEC_ID_MSMPEG4V1;
3714 id = AV_CODEC_ID_MSMPEG4V2;
3717 id = AV_CODEC_ID_MSMPEG4V3;
3721 if (id != AV_CODEC_ID_NONE)
3723 } else if (!strcmp (mimetype, "video/x-svq")) {
3724 gint svqversion = 0;
3726 if (gst_structure_get_int (structure, "svqversion", &svqversion)) {
3727 switch (svqversion) {
3729 id = AV_CODEC_ID_SVQ1;
3732 id = AV_CODEC_ID_SVQ3;
3736 if (id != AV_CODEC_ID_NONE)
3738 } else if (!strcmp (mimetype, "video/x-huffyuv")) {
3739 id = AV_CODEC_ID_HUFFYUV;
3741 } else if (!strcmp (mimetype, "audio/x-mace")) {
3742 gint maceversion = 0;
3744 if (gst_structure_get_int (structure, "maceversion", &maceversion)) {
3745 switch (maceversion) {
3747 id = AV_CODEC_ID_MACE3;
3750 id = AV_CODEC_ID_MACE6;
3754 if (id != AV_CODEC_ID_NONE)
3756 } else if (!strcmp (mimetype, "video/x-theora")) {
3757 id = AV_CODEC_ID_THEORA;
3759 } else if (!strcmp (mimetype, "video/x-vp3")) {
3760 id = AV_CODEC_ID_VP3;
3762 } else if (!strcmp (mimetype, "video/x-vp5")) {
3763 id = AV_CODEC_ID_VP5;
3765 } else if (!strcmp (mimetype, "video/x-vp6")) {
3766 id = AV_CODEC_ID_VP6;
3768 } else if (!strcmp (mimetype, "video/x-vp6-flash")) {
3769 id = AV_CODEC_ID_VP6F;
3771 } else if (!strcmp (mimetype, "video/x-vp6-alpha")) {
3772 id = AV_CODEC_ID_VP6A;
3774 } else if (!strcmp (mimetype, "video/x-vp8")) {
3775 id = AV_CODEC_ID_VP8;
3777 } else if (!strcmp (mimetype, "video/x-vp9")) {
3778 id = AV_CODEC_ID_VP9;
3780 } else if (!strcmp (mimetype, "video/x-flash-screen")) {
3781 id = AV_CODEC_ID_FLASHSV;
3783 } else if (!strcmp (mimetype, "video/x-indeo")) {
3784 gint indeoversion = 0;
3786 if (gst_structure_get_int (structure, "indeoversion", &indeoversion)) {
3787 switch (indeoversion) {
3789 id = AV_CODEC_ID_INDEO5;
3792 id = AV_CODEC_ID_INDEO4;
3795 id = AV_CODEC_ID_INDEO3;
3798 id = AV_CODEC_ID_INDEO2;
3801 if (id != AV_CODEC_ID_NONE)
3804 } else if (!strcmp (mimetype, "video/x-divx")) {
3805 gint divxversion = 0;
3807 if (gst_structure_get_int (structure, "divxversion", &divxversion)) {
3808 switch (divxversion) {
3810 id = AV_CODEC_ID_MSMPEG4V3;
3814 id = AV_CODEC_ID_MPEG4;
3818 if (id != AV_CODEC_ID_NONE)
3820 } else if (!strcmp (mimetype, "video/x-ffv")) {
3821 gint ffvversion = 0;
3823 if (gst_structure_get_int (structure, "ffvversion", &ffvversion) &&
3825 id = AV_CODEC_ID_FFV1;
3828 } else if (!strcmp (mimetype, "video/x-apple-intermediate-codec")) {
3829 id = AV_CODEC_ID_AIC;
3831 } else if (!strcmp (mimetype, "audio/x-adpcm")) {
3832 const gchar *layout;
3834 layout = gst_structure_get_string (structure, "layout");
3835 if (layout == NULL) {
3837 } else if (!strcmp (layout, "quicktime")) {
3838 id = AV_CODEC_ID_ADPCM_IMA_QT;
3839 } else if (!strcmp (layout, "microsoft")) {
3840 id = AV_CODEC_ID_ADPCM_MS;
3841 } else if (!strcmp (layout, "dvi")) {
3842 id = AV_CODEC_ID_ADPCM_IMA_WAV;
3843 } else if (!strcmp (layout, "4xm")) {
3844 id = AV_CODEC_ID_ADPCM_4XM;
3845 } else if (!strcmp (layout, "smjpeg")) {
3846 id = AV_CODEC_ID_ADPCM_IMA_SMJPEG;
3847 } else if (!strcmp (layout, "dk3")) {
3848 id = AV_CODEC_ID_ADPCM_IMA_DK3;
3849 } else if (!strcmp (layout, "dk4")) {
3850 id = AV_CODEC_ID_ADPCM_IMA_DK4;
3851 } else if (!strcmp (layout, "westwood")) {
3852 id = AV_CODEC_ID_ADPCM_IMA_WS;
3853 } else if (!strcmp (layout, "iss")) {
3854 id = AV_CODEC_ID_ADPCM_IMA_ISS;
3855 } else if (!strcmp (layout, "xa")) {
3856 id = AV_CODEC_ID_ADPCM_XA;
3857 } else if (!strcmp (layout, "adx")) {
3858 id = AV_CODEC_ID_ADPCM_ADX;
3859 } else if (!strcmp (layout, "ea")) {
3860 id = AV_CODEC_ID_ADPCM_EA;
3861 } else if (!strcmp (layout, "g726")) {
3862 id = AV_CODEC_ID_ADPCM_G726;
3863 } else if (!strcmp (layout, "g721")) {
3864 id = AV_CODEC_ID_ADPCM_G726;
3865 } else if (!strcmp (layout, "ct")) {
3866 id = AV_CODEC_ID_ADPCM_CT;
3867 } else if (!strcmp (layout, "swf")) {
3868 id = AV_CODEC_ID_ADPCM_SWF;
3869 } else if (!strcmp (layout, "yamaha")) {
3870 id = AV_CODEC_ID_ADPCM_YAMAHA;
3871 } else if (!strcmp (layout, "sbpro2")) {
3872 id = AV_CODEC_ID_ADPCM_SBPRO_2;
3873 } else if (!strcmp (layout, "sbpro3")) {
3874 id = AV_CODEC_ID_ADPCM_SBPRO_3;
3875 } else if (!strcmp (layout, "sbpro4")) {
3876 id = AV_CODEC_ID_ADPCM_SBPRO_4;
3878 if (id != AV_CODEC_ID_NONE)
3880 } else if (!strcmp (mimetype, "video/x-4xm")) {
3881 id = AV_CODEC_ID_4XM;
3883 } else if (!strcmp (mimetype, "audio/x-dpcm")) {
3884 const gchar *layout;
3886 layout = gst_structure_get_string (structure, "layout");
3889 } else if (!strcmp (layout, "roq")) {
3890 id = AV_CODEC_ID_ROQ_DPCM;
3891 } else if (!strcmp (layout, "interplay")) {
3892 id = AV_CODEC_ID_INTERPLAY_DPCM;
3893 } else if (!strcmp (layout, "xan")) {
3894 id = AV_CODEC_ID_XAN_DPCM;
3895 } else if (!strcmp (layout, "sol")) {
3896 id = AV_CODEC_ID_SOL_DPCM;
3898 if (id != AV_CODEC_ID_NONE)
3900 } else if (!strcmp (mimetype, "audio/x-flac")) {
3901 id = AV_CODEC_ID_FLAC;
3903 } else if (!strcmp (mimetype, "audio/x-shorten")) {
3904 id = AV_CODEC_ID_SHORTEN;
3906 } else if (!strcmp (mimetype, "audio/x-alac")) {
3907 id = AV_CODEC_ID_ALAC;
3909 } else if (!strcmp (mimetype, "video/x-cinepak")) {
3910 id = AV_CODEC_ID_CINEPAK;
3912 } else if (!strcmp (mimetype, "video/x-pn-realvideo")) {
3915 if (gst_structure_get_int (structure, "rmversion", &rmversion)) {
3916 switch (rmversion) {
3918 id = AV_CODEC_ID_RV10;
3921 id = AV_CODEC_ID_RV20;
3924 id = AV_CODEC_ID_RV30;
3927 id = AV_CODEC_ID_RV40;
3931 if (id != AV_CODEC_ID_NONE)
3933 } else if (!strcmp (mimetype, "audio/x-sipro")) {
3934 id = AV_CODEC_ID_SIPR;
3936 } else if (!strcmp (mimetype, "audio/x-pn-realaudio")) {
3939 if (gst_structure_get_int (structure, "raversion", &raversion)) {
3940 switch (raversion) {
3942 id = AV_CODEC_ID_RA_144;
3945 id = AV_CODEC_ID_RA_288;
3948 id = AV_CODEC_ID_COOK;
3952 if (id != AV_CODEC_ID_NONE)
3954 } else if (!strcmp (mimetype, "video/x-rle")) {
3955 const gchar *layout;
3957 if ((layout = gst_structure_get_string (structure, "layout"))) {
3958 if (!strcmp (layout, "microsoft")) {
3959 id = AV_CODEC_ID_MSRLE;
3963 } else if (!strcmp (mimetype, "video/x-xan")) {
3966 if ((gst_structure_get_int (structure, "wcversion", &wcversion))) {
3967 switch (wcversion) {
3969 id = AV_CODEC_ID_XAN_WC3;
3973 id = AV_CODEC_ID_XAN_WC4;
3980 } else if (!strcmp (mimetype, "audio/AMR")) {
3982 id = AV_CODEC_ID_AMR_NB;
3983 } else if (!strcmp (mimetype, "audio/AMR-WB")) {
3984 id = AV_CODEC_ID_AMR_WB;
3986 } else if (!strcmp (mimetype, "audio/qcelp")) {
3987 id = AV_CODEC_ID_QCELP;
3989 } else if (!strcmp (mimetype, "video/x-h264")) {
3990 id = AV_CODEC_ID_H264;
3992 } else if (!strcmp (mimetype, "video/x-h265")) {
3993 id = AV_CODEC_ID_HEVC;
3995 } else if (!strcmp (mimetype, "video/x-flash-video")) {
3996 gint flvversion = 0;
3998 if ((gst_structure_get_int (structure, "flvversion", &flvversion))) {
3999 switch (flvversion) {
4001 id = AV_CODEC_ID_FLV1;
4009 } else if (!strcmp (mimetype, "audio/x-nellymoser")) {
4010 id = AV_CODEC_ID_NELLYMOSER;
4012 } else if (!strncmp (mimetype, "audio/x-gst-av-", 15)) {
4016 if (strlen (mimetype) <= 30 &&
4017 sscanf (mimetype, "audio/x-gst-av-%s", ext) == 1) {
4018 if ((codec = avcodec_find_decoder_by_name (ext)) ||
4019 (codec = avcodec_find_encoder_by_name (ext))) {
4024 } else if (!strncmp (mimetype, "video/x-gst-av-", 15)) {
4028 if (strlen (mimetype) <= 30 &&
4029 sscanf (mimetype, "video/x-gst-av-%s", ext) == 1) {
4030 if ((codec = avcodec_find_decoder_by_name (ext)) ||
4031 (codec = avcodec_find_encoder_by_name (ext))) {
4038 if (context != NULL) {
4039 if (video == TRUE) {
4040 context->codec_type = AVMEDIA_TYPE_VIDEO;
4041 } else if (audio == TRUE) {
4042 context->codec_type = AVMEDIA_TYPE_AUDIO;
4044 context->codec_type = AVMEDIA_TYPE_UNKNOWN;
4046 context->codec_id = id;
4047 gst_ffmpeg_caps_with_codecid (id, context->codec_type, caps, context);
4050 if (id != AV_CODEC_ID_NONE) {
4051 GST_DEBUG ("The id=%d belongs to the caps %" GST_PTR_FORMAT, id, caps);
4053 GST_WARNING ("Couldn't figure out the id for caps %" GST_PTR_FORMAT, caps);