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);
2137 GST_DEBUG ("Unknown codec ID %d, please add mapping here", codec_id);
2144 if ((codec = avcodec_find_decoder (codec_id)) ||
2145 (codec = avcodec_find_encoder (codec_id))) {
2148 GST_LOG ("Could not create stream format caps for %s", codec->name);
2150 switch (codec->type) {
2151 case AVMEDIA_TYPE_VIDEO:
2152 mime = g_strdup_printf ("video/x-gst-av-%s", codec->name);
2154 gst_ff_vid_caps_new (context, NULL, codec_id, encode, mime, NULL);
2157 case AVMEDIA_TYPE_AUDIO:
2158 mime = g_strdup_printf ("audio/x-gst-av-%s", codec->name);
2160 gst_ff_aud_caps_new (context, NULL, codec_id, encode, mime, NULL);
2162 gst_caps_set_simple (caps,
2163 "block_align", G_TYPE_INT, context->block_align,
2164 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
2175 /* set private data */
2176 if (context && context->extradata_size > 0) {
2177 GstBuffer *data = gst_buffer_new_and_alloc (context->extradata_size);
2179 gst_buffer_fill (data, 0, context->extradata, context->extradata_size);
2180 gst_caps_set_simple (caps, "codec_data", GST_TYPE_BUFFER, data, NULL);
2181 gst_buffer_unref (data);
2184 GST_LOG ("caps for codec_id=%d: %" GST_PTR_FORMAT, codec_id, caps);
2187 GST_LOG ("No caps found for codec_id=%d", codec_id);
2193 /* Convert a FFMPEG Pixel Format and optional AVCodecContext
2194 * to a GstCaps. If the context is ommitted, no fixed values
2195 * for video/audio size will be included in the GstCaps
2197 * See below for usefullness
2201 gst_ffmpeg_pixfmt_to_caps (enum AVPixelFormat pix_fmt, AVCodecContext * context,
2202 enum AVCodecID codec_id)
2204 GstCaps *caps = NULL;
2205 GstVideoFormat format;
2207 format = gst_ffmpeg_pixfmt_to_videoformat (pix_fmt);
2209 if (format != GST_VIDEO_FORMAT_UNKNOWN) {
2210 caps = gst_ff_vid_caps_new (context, NULL, codec_id, TRUE, "video/x-raw",
2211 "format", G_TYPE_STRING, gst_video_format_to_string (format), NULL);
2215 GST_DEBUG ("caps for pix_fmt=%d: %" GST_PTR_FORMAT, pix_fmt, caps);
2217 GST_LOG ("No caps found for pix_fmt=%d", pix_fmt);
2224 gst_ffmpeg_smpfmt_to_audioformat (enum AVSampleFormat sample_fmt)
2226 switch (sample_fmt) {
2227 case AV_SAMPLE_FMT_U8:
2228 case AV_SAMPLE_FMT_U8P:
2229 return GST_AUDIO_FORMAT_U8;
2231 case AV_SAMPLE_FMT_S16:
2232 case AV_SAMPLE_FMT_S16P:
2233 return GST_AUDIO_FORMAT_S16;
2235 case AV_SAMPLE_FMT_S32:
2236 case AV_SAMPLE_FMT_S32P:
2237 return GST_AUDIO_FORMAT_S32;
2239 case AV_SAMPLE_FMT_FLT:
2240 case AV_SAMPLE_FMT_FLTP:
2241 return GST_AUDIO_FORMAT_F32;
2243 case AV_SAMPLE_FMT_DBL:
2244 case AV_SAMPLE_FMT_DBLP:
2245 return GST_AUDIO_FORMAT_F64;
2249 return GST_AUDIO_FORMAT_UNKNOWN;
2254 /* Convert a FFMPEG Sample Format and optional AVCodecContext
2255 * to a GstCaps. If the context is ommitted, no fixed values
2256 * for video/audio size will be included in the GstCaps
2258 * See below for usefullness
2262 gst_ffmpeg_smpfmt_to_caps (enum AVSampleFormat sample_fmt,
2263 AVCodecContext * context, AVCodec * codec, enum AVCodecID codec_id)
2265 GstCaps *caps = NULL;
2266 GstAudioFormat format;
2268 format = gst_ffmpeg_smpfmt_to_audioformat (sample_fmt);
2270 if (format != GST_AUDIO_FORMAT_UNKNOWN) {
2271 caps = gst_ff_aud_caps_new (context, codec, codec_id, TRUE, "audio/x-raw",
2272 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
2273 "layout", G_TYPE_STRING, "interleaved", NULL);
2274 GST_LOG ("caps for sample_fmt=%d: %" GST_PTR_FORMAT, sample_fmt, caps);
2276 GST_LOG ("No caps found for sample_fmt=%d", sample_fmt);
2283 caps_has_field (GstCaps * caps, const gchar * field)
2287 n = gst_caps_get_size (caps);
2288 for (i = 0; i < n; i++) {
2289 GstStructure *s = gst_caps_get_structure (caps, i);
2291 if (gst_structure_has_field (s, field))
2299 gst_ffmpeg_codectype_to_audio_caps (AVCodecContext * context,
2300 enum AVCodecID codec_id, gboolean encode, AVCodec * codec)
2302 GstCaps *caps = NULL;
2304 GST_DEBUG ("context:%p, codec_id:%d, encode:%d, codec:%p",
2305 context, codec_id, encode, codec);
2307 GST_DEBUG ("sample_fmts:%p, samplerates:%p",
2308 codec->sample_fmts, codec->supported_samplerates);
2311 /* Specific codec context */
2313 gst_ffmpeg_smpfmt_to_caps (context->sample_fmt, context, codec,
2316 caps = gst_ff_aud_caps_new (context, codec, codec_id, encode, "audio/x-raw",
2317 "layout", G_TYPE_STRING, "interleaved", NULL);
2318 if (!caps_has_field (caps, "format"))
2319 gst_ffmpeg_audio_set_sample_fmts (caps,
2320 codec ? codec->sample_fmts : NULL);
2327 gst_ffmpeg_codectype_to_video_caps (AVCodecContext * context,
2328 enum AVCodecID codec_id, gboolean encode, AVCodec * codec)
2332 GST_LOG ("context:%p, codec_id:%d, encode:%d, codec:%p",
2333 context, codec_id, encode, codec);
2336 caps = gst_ffmpeg_pixfmt_to_caps (context->pix_fmt, context, codec_id);
2339 gst_ff_vid_caps_new (context, codec, codec_id, encode, "video/x-raw",
2341 if (!caps_has_field (caps, "format"))
2342 gst_ffmpeg_video_set_pix_fmts (caps, codec ? codec->pix_fmts : NULL);
2347 /* Convert a GstCaps (audio/raw) to a FFMPEG SampleFmt
2348 * and other audio properties in a AVCodecContext.
2350 * For usefullness, see below
2354 gst_ffmpeg_caps_to_smpfmt (const GstCaps * caps,
2355 AVCodecContext * context, gboolean raw)
2357 GstStructure *structure;
2359 GstAudioFormat format = GST_AUDIO_FORMAT_UNKNOWN;
2362 g_return_if_fail (gst_caps_get_size (caps) == 1);
2364 structure = gst_caps_get_structure (caps, 0);
2366 gst_structure_get_int (structure, "channels", &context->channels);
2367 gst_structure_get_int (structure, "rate", &context->sample_rate);
2368 gst_structure_get_int (structure, "block_align", &context->block_align);
2369 gst_structure_get_int (structure, "bitrate", &bitrate);
2370 context->bit_rate = bitrate;
2375 if (gst_structure_has_name (structure, "audio/x-raw")) {
2376 if ((fmt = gst_structure_get_string (structure, "format"))) {
2377 format = gst_audio_format_from_string (fmt);
2382 case GST_AUDIO_FORMAT_F32:
2383 context->sample_fmt = AV_SAMPLE_FMT_FLT;
2385 case GST_AUDIO_FORMAT_F64:
2386 context->sample_fmt = AV_SAMPLE_FMT_DBL;
2388 case GST_AUDIO_FORMAT_S32:
2389 context->sample_fmt = AV_SAMPLE_FMT_S32;
2391 case GST_AUDIO_FORMAT_S16:
2392 context->sample_fmt = AV_SAMPLE_FMT_S16;
2399 /* Convert a GstCaps (video/raw) to a FFMPEG PixFmt
2400 * and other video properties in a AVCodecContext.
2402 * For usefullness, see below
2406 gst_ffmpeg_caps_to_pixfmt (const GstCaps * caps,
2407 AVCodecContext * context, gboolean raw)
2409 GstStructure *structure;
2411 const GValue *par = NULL;
2413 GstVideoFormat format = GST_VIDEO_FORMAT_UNKNOWN;
2415 GST_DEBUG ("converting caps %" GST_PTR_FORMAT, caps);
2416 g_return_if_fail (gst_caps_get_size (caps) == 1);
2417 structure = gst_caps_get_structure (caps, 0);
2419 gst_structure_get_int (structure, "width", &context->width);
2420 gst_structure_get_int (structure, "height", &context->height);
2421 gst_structure_get_int (structure, "bpp", &context->bits_per_coded_sample);
2423 fps = gst_structure_get_value (structure, "framerate");
2424 if (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps)) {
2426 int num = gst_value_get_fraction_numerator (fps);
2427 int den = gst_value_get_fraction_denominator (fps);
2429 if (num > 0 && den > 0) {
2430 /* somehow these seem mixed up.. */
2431 /* they're fine, this is because it does period=1/frequency */
2432 context->time_base.den = gst_value_get_fraction_numerator (fps);
2433 context->time_base.num = gst_value_get_fraction_denominator (fps);
2434 context->ticks_per_frame = 1;
2436 GST_DEBUG ("setting framerate %d/%d = %lf",
2437 context->time_base.den, context->time_base.num,
2438 1. * context->time_base.den / context->time_base.num);
2440 GST_WARNING ("ignoring insane framerate %d/%d",
2441 context->time_base.den, context->time_base.num);
2445 par = gst_structure_get_value (structure, "pixel-aspect-ratio");
2446 if (par && GST_VALUE_HOLDS_FRACTION (par)) {
2448 int num = gst_value_get_fraction_numerator (par);
2449 int den = gst_value_get_fraction_denominator (par);
2451 if (num > 0 && den > 0) {
2452 context->sample_aspect_ratio.num = num;
2453 context->sample_aspect_ratio.den = den;
2455 GST_DEBUG ("setting pixel-aspect-ratio %d/%d = %lf",
2456 context->sample_aspect_ratio.num, context->sample_aspect_ratio.den,
2457 1. * context->sample_aspect_ratio.num /
2458 context->sample_aspect_ratio.den);
2460 GST_WARNING ("ignoring insane pixel-aspect-ratio %d/%d",
2461 context->sample_aspect_ratio.num, context->sample_aspect_ratio.den);
2468 g_return_if_fail (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps));
2470 if (gst_structure_has_name (structure, "video/x-raw")) {
2471 if ((fmt = gst_structure_get_string (structure, "format"))) {
2472 format = gst_video_format_from_string (fmt);
2477 case GST_VIDEO_FORMAT_YUY2:
2478 context->pix_fmt = AV_PIX_FMT_YUYV422;
2480 case GST_VIDEO_FORMAT_I420:
2481 context->pix_fmt = AV_PIX_FMT_YUV420P;
2483 case GST_VIDEO_FORMAT_A420:
2484 context->pix_fmt = AV_PIX_FMT_YUVA420P;
2486 case GST_VIDEO_FORMAT_Y41B:
2487 context->pix_fmt = AV_PIX_FMT_YUV411P;
2489 case GST_VIDEO_FORMAT_Y42B:
2490 context->pix_fmt = AV_PIX_FMT_YUV422P;
2492 case GST_VIDEO_FORMAT_YUV9:
2493 context->pix_fmt = AV_PIX_FMT_YUV410P;
2495 case GST_VIDEO_FORMAT_Y444:
2496 context->pix_fmt = AV_PIX_FMT_YUV444P;
2498 case GST_VIDEO_FORMAT_GRAY8:
2499 context->pix_fmt = AV_PIX_FMT_GRAY8;
2501 case GST_VIDEO_FORMAT_xRGB:
2502 #if (G_BYTE_ORDER == G_BIG_ENDIAN)
2503 context->pix_fmt = AV_PIX_FMT_RGB32;
2506 case GST_VIDEO_FORMAT_BGRx:
2507 #if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
2508 context->pix_fmt = AV_PIX_FMT_RGB32;
2511 case GST_VIDEO_FORMAT_RGB:
2512 context->pix_fmt = AV_PIX_FMT_RGB24;
2514 case GST_VIDEO_FORMAT_BGR:
2515 context->pix_fmt = AV_PIX_FMT_BGR24;
2517 case GST_VIDEO_FORMAT_RGB16:
2518 context->pix_fmt = AV_PIX_FMT_RGB565;
2520 case GST_VIDEO_FORMAT_RGB15:
2521 context->pix_fmt = AV_PIX_FMT_RGB555;
2523 case GST_VIDEO_FORMAT_RGB8P:
2524 context->pix_fmt = AV_PIX_FMT_PAL8;
2533 GstVideoFormat format;
2534 enum AVPixelFormat pixfmt;
2537 /* FIXME : FILLME */
2538 static const PixToFmt pixtofmttable[] = {
2539 /* GST_VIDEO_FORMAT_I420, */
2540 {GST_VIDEO_FORMAT_I420, AV_PIX_FMT_YUV420P},
2541 /* Note : this should use a different chroma placement */
2542 {GST_VIDEO_FORMAT_I420, AV_PIX_FMT_YUVJ420P},
2544 /* GST_VIDEO_FORMAT_YV12, */
2545 /* GST_VIDEO_FORMAT_YUY2, */
2546 {GST_VIDEO_FORMAT_YUY2, AV_PIX_FMT_YUYV422},
2547 /* GST_VIDEO_FORMAT_UYVY, */
2548 {GST_VIDEO_FORMAT_UYVY, AV_PIX_FMT_UYVY422},
2549 /* GST_VIDEO_FORMAT_AYUV, */
2550 /* GST_VIDEO_FORMAT_RGBx, */
2551 /* GST_VIDEO_FORMAT_BGRx, */
2552 /* GST_VIDEO_FORMAT_xRGB, */
2553 /* GST_VIDEO_FORMAT_xBGR, */
2554 /* GST_VIDEO_FORMAT_RGBA, */
2555 {GST_VIDEO_FORMAT_RGBA, AV_PIX_FMT_RGBA},
2556 /* GST_VIDEO_FORMAT_BGRA, */
2557 {GST_VIDEO_FORMAT_BGRA, AV_PIX_FMT_BGRA},
2558 /* GST_VIDEO_FORMAT_ARGB, */
2559 {GST_VIDEO_FORMAT_ARGB, AV_PIX_FMT_ARGB},
2560 /* GST_VIDEO_FORMAT_ABGR, */
2561 {GST_VIDEO_FORMAT_ABGR, AV_PIX_FMT_ABGR},
2562 /* GST_VIDEO_FORMAT_RGB, */
2563 {GST_VIDEO_FORMAT_RGB, AV_PIX_FMT_RGB24},
2564 /* GST_VIDEO_FORMAT_BGR, */
2565 {GST_VIDEO_FORMAT_BGR, AV_PIX_FMT_BGR24},
2566 /* GST_VIDEO_FORMAT_Y41B, */
2567 {GST_VIDEO_FORMAT_Y41B, AV_PIX_FMT_YUV411P},
2568 /* GST_VIDEO_FORMAT_Y42B, */
2569 {GST_VIDEO_FORMAT_Y42B, AV_PIX_FMT_YUV422P},
2570 {GST_VIDEO_FORMAT_Y42B, AV_PIX_FMT_YUVJ422P},
2571 /* GST_VIDEO_FORMAT_YVYU, */
2572 /* GST_VIDEO_FORMAT_Y444, */
2573 {GST_VIDEO_FORMAT_Y444, AV_PIX_FMT_YUV444P},
2574 {GST_VIDEO_FORMAT_Y444, AV_PIX_FMT_YUVJ444P},
2575 /* GST_VIDEO_FORMAT_v210, */
2576 /* GST_VIDEO_FORMAT_v216, */
2577 /* GST_VIDEO_FORMAT_NV12, */
2578 {GST_VIDEO_FORMAT_NV12, AV_PIX_FMT_NV12},
2579 /* GST_VIDEO_FORMAT_NV21, */
2580 {GST_VIDEO_FORMAT_NV21, AV_PIX_FMT_NV21},
2581 /* GST_VIDEO_FORMAT_GRAY8, */
2582 {GST_VIDEO_FORMAT_GRAY8, AV_PIX_FMT_GRAY8},
2583 /* GST_VIDEO_FORMAT_GRAY16_BE, */
2584 {GST_VIDEO_FORMAT_GRAY16_BE, AV_PIX_FMT_GRAY16BE},
2585 /* GST_VIDEO_FORMAT_GRAY16_LE, */
2586 {GST_VIDEO_FORMAT_GRAY16_LE, AV_PIX_FMT_GRAY16LE},
2587 /* GST_VIDEO_FORMAT_v308, */
2588 /* GST_VIDEO_FORMAT_Y800, */
2589 /* GST_VIDEO_FORMAT_Y16, */
2590 /* GST_VIDEO_FORMAT_RGB16, */
2591 {GST_VIDEO_FORMAT_RGB16, AV_PIX_FMT_RGB565},
2592 /* GST_VIDEO_FORMAT_BGR16, */
2593 /* GST_VIDEO_FORMAT_RGB15, */
2594 {GST_VIDEO_FORMAT_RGB15, AV_PIX_FMT_RGB555},
2595 /* GST_VIDEO_FORMAT_BGR15, */
2596 /* GST_VIDEO_FORMAT_UYVP, */
2597 /* GST_VIDEO_FORMAT_A420, */
2598 {GST_VIDEO_FORMAT_A420, AV_PIX_FMT_YUVA420P},
2599 /* GST_VIDEO_FORMAT_RGB8_PALETTED, */
2600 {GST_VIDEO_FORMAT_RGB8P, AV_PIX_FMT_PAL8},
2601 /* GST_VIDEO_FORMAT_YUV9, */
2602 {GST_VIDEO_FORMAT_YUV9, AV_PIX_FMT_YUV410P},
2603 /* GST_VIDEO_FORMAT_YVU9, */
2604 /* GST_VIDEO_FORMAT_IYU1, */
2605 /* GST_VIDEO_FORMAT_ARGB64, */
2606 /* GST_VIDEO_FORMAT_AYUV64, */
2607 /* GST_VIDEO_FORMAT_r210, */
2608 {GST_VIDEO_FORMAT_I420_10LE, AV_PIX_FMT_YUV420P10LE},
2609 {GST_VIDEO_FORMAT_I420_10BE, AV_PIX_FMT_YUV420P10BE},
2610 {GST_VIDEO_FORMAT_I422_10LE, AV_PIX_FMT_YUV422P10LE},
2611 {GST_VIDEO_FORMAT_I422_10BE, AV_PIX_FMT_YUV422P10BE},
2612 {GST_VIDEO_FORMAT_Y444_10LE, AV_PIX_FMT_YUV444P10LE},
2613 {GST_VIDEO_FORMAT_Y444_10BE, AV_PIX_FMT_YUV444P10BE},
2614 {GST_VIDEO_FORMAT_GBR, AV_PIX_FMT_GBRP},
2615 {GST_VIDEO_FORMAT_GBR_10LE, AV_PIX_FMT_GBRP10LE},
2616 {GST_VIDEO_FORMAT_GBR_10BE, AV_PIX_FMT_GBRP10BE},
2617 {GST_VIDEO_FORMAT_A420_10LE, AV_PIX_FMT_YUVA420P10LE},
2618 {GST_VIDEO_FORMAT_A420_10BE, AV_PIX_FMT_YUVA420P10BE},
2619 {GST_VIDEO_FORMAT_A422_10LE, AV_PIX_FMT_YUVA422P10LE},
2620 {GST_VIDEO_FORMAT_A422_10BE, AV_PIX_FMT_YUVA422P10BE},
2621 {GST_VIDEO_FORMAT_A444_10LE, AV_PIX_FMT_YUVA444P10LE},
2622 {GST_VIDEO_FORMAT_A444_10BE, AV_PIX_FMT_YUVA444P10BE},
2626 gst_ffmpeg_pixfmt_to_videoformat (enum AVPixelFormat pixfmt)
2630 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2631 if (pixtofmttable[i].pixfmt == pixfmt)
2632 return pixtofmttable[i].format;
2634 GST_DEBUG ("Unknown pixel format %d", pixfmt);
2635 return GST_VIDEO_FORMAT_UNKNOWN;
2638 static enum AVPixelFormat
2639 gst_ffmpeg_videoformat_to_pixfmt_for_codec (GstVideoFormat format,
2640 const AVCodec * codec)
2644 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++) {
2645 if (pixtofmttable[i].format == format) {
2648 if (codec && codec->pix_fmts) {
2649 for (j = 0; codec->pix_fmts[j] != -1; j++) {
2650 if (pixtofmttable[i].pixfmt == codec->pix_fmts[j])
2651 return pixtofmttable[i].pixfmt;
2654 return pixtofmttable[i].pixfmt;
2659 return AV_PIX_FMT_NONE;
2663 gst_ffmpeg_videoformat_to_pixfmt (GstVideoFormat format)
2665 return gst_ffmpeg_videoformat_to_pixfmt_for_codec (format, NULL);
2669 gst_ffmpeg_videoinfo_to_context (GstVideoInfo * info, AVCodecContext * context)
2673 context->width = GST_VIDEO_INFO_WIDTH (info);
2674 context->height = GST_VIDEO_INFO_HEIGHT (info);
2675 for (i = 0; i < GST_VIDEO_INFO_N_COMPONENTS (info); i++)
2676 bpp += GST_VIDEO_INFO_COMP_DEPTH (info, i);
2677 context->bits_per_coded_sample = bpp;
2679 context->ticks_per_frame = 1;
2680 if (GST_VIDEO_INFO_FPS_N (info) == 0) {
2681 GST_DEBUG ("Using 25/1 framerate");
2682 context->time_base.den = 25;
2683 context->time_base.num = 1;
2685 context->time_base.den = GST_VIDEO_INFO_FPS_N (info);
2686 context->time_base.num = GST_VIDEO_INFO_FPS_D (info);
2689 context->sample_aspect_ratio.num = GST_VIDEO_INFO_PAR_N (info);
2690 context->sample_aspect_ratio.den = GST_VIDEO_INFO_PAR_D (info);
2693 gst_ffmpeg_videoformat_to_pixfmt_for_codec (GST_VIDEO_INFO_FORMAT (info),
2698 gst_ffmpeg_audioinfo_to_context (GstAudioInfo * info, AVCodecContext * context)
2700 const AVCodec *codec;
2701 const enum AVSampleFormat *smpl_fmts;
2702 enum AVSampleFormat smpl_fmt = -1;
2704 context->channels = info->channels;
2705 context->sample_rate = info->rate;
2706 context->channel_layout =
2707 gst_ffmpeg_channel_positions_to_layout (info->position, info->channels);
2709 codec = context->codec;
2711 smpl_fmts = codec->sample_fmts;
2713 switch (info->finfo->format) {
2714 case GST_AUDIO_FORMAT_F32:
2716 while (*smpl_fmts != -1) {
2717 if (*smpl_fmts == AV_SAMPLE_FMT_FLT) {
2718 smpl_fmt = *smpl_fmts;
2720 } else if (*smpl_fmts == AV_SAMPLE_FMT_FLTP) {
2721 smpl_fmt = *smpl_fmts;
2727 smpl_fmt = AV_SAMPLE_FMT_FLT;
2730 case GST_AUDIO_FORMAT_F64:
2732 while (*smpl_fmts != -1) {
2733 if (*smpl_fmts == AV_SAMPLE_FMT_DBL) {
2734 smpl_fmt = *smpl_fmts;
2736 } else if (*smpl_fmts == AV_SAMPLE_FMT_DBLP) {
2737 smpl_fmt = *smpl_fmts;
2743 smpl_fmt = AV_SAMPLE_FMT_DBL;
2746 case GST_AUDIO_FORMAT_S32:
2748 while (*smpl_fmts != -1) {
2749 if (*smpl_fmts == AV_SAMPLE_FMT_S32) {
2750 smpl_fmt = *smpl_fmts;
2752 } else if (*smpl_fmts == AV_SAMPLE_FMT_S32P) {
2753 smpl_fmt = *smpl_fmts;
2759 smpl_fmt = AV_SAMPLE_FMT_S32;
2762 case GST_AUDIO_FORMAT_S16:
2764 while (*smpl_fmts != -1) {
2765 if (*smpl_fmts == AV_SAMPLE_FMT_S16) {
2766 smpl_fmt = *smpl_fmts;
2768 } else if (*smpl_fmts == AV_SAMPLE_FMT_S16P) {
2769 smpl_fmt = *smpl_fmts;
2775 smpl_fmt = AV_SAMPLE_FMT_S16;
2778 case GST_AUDIO_FORMAT_U8:
2780 while (*smpl_fmts != -1) {
2781 if (*smpl_fmts == AV_SAMPLE_FMT_U8) {
2782 smpl_fmt = *smpl_fmts;
2784 } else if (*smpl_fmts == AV_SAMPLE_FMT_U8P) {
2785 smpl_fmt = *smpl_fmts;
2791 smpl_fmt = AV_SAMPLE_FMT_U8;
2798 g_assert (smpl_fmt != -1);
2800 context->sample_fmt = smpl_fmt;
2803 /* Convert a GstCaps and a FFMPEG codec Type to a
2804 * AVCodecContext. If the context is ommitted, no fixed values
2805 * for video/audio size will be included in the context
2807 * AVMediaType is primarily meant for uncompressed data GstCaps!
2811 gst_ffmpeg_caps_with_codectype (enum AVMediaType type,
2812 const GstCaps * caps, AVCodecContext * context)
2814 if (context == NULL)
2818 case AVMEDIA_TYPE_VIDEO:
2819 gst_ffmpeg_caps_to_pixfmt (caps, context, TRUE);
2822 case AVMEDIA_TYPE_AUDIO:
2823 gst_ffmpeg_caps_to_smpfmt (caps, context, TRUE);
2834 nal_escape (guint8 * dst, guint8 * src, guint size, guint * destsize)
2838 guint8 *end = src + size;
2841 while (srcp < end) {
2842 if (count == 2 && *srcp <= 0x03) {
2843 GST_DEBUG ("added escape code");
2852 GST_DEBUG ("copy %02x, count %d", *srcp, count);
2855 *destsize = dstp - dst;
2858 /* copy the config, escaping NAL units as we iterate them, if something fails we
2859 * copy everything and hope for the best. */
2861 copy_config (guint8 * dst, guint8 * src, guint size, guint * destsize)
2866 guint nalsize, esize;
2876 cnt = *(srcp + 5) & 0x1f; /* Number of sps */
2878 GST_DEBUG ("num SPS %d", cnt);
2880 memcpy (dstp, srcp, 6);
2884 for (i = 0; i < cnt; i++) {
2885 GST_DEBUG ("copy SPS %d", i);
2886 nalsize = (srcp[0] << 8) | srcp[1];
2887 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2888 dstp[0] = esize >> 8;
2889 dstp[1] = esize & 0xff;
2891 srcp += nalsize + 2;
2894 cnt = *(dstp++) = *(srcp++); /* Number of pps */
2896 GST_DEBUG ("num PPS %d", cnt);
2898 for (i = 0; i < cnt; i++) {
2899 GST_DEBUG ("copy PPS %d", i);
2900 nalsize = (srcp[0] << 8) | srcp[1];
2901 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2902 dstp[0] = esize >> 8;
2903 dstp[1] = esize & 0xff;
2905 srcp += nalsize + 2;
2907 *destsize = dstp - dst;
2913 GST_DEBUG ("something unexpected, doing full copy");
2914 memcpy (dst, src, size);
2922 * caps_with_codecid () transforms a GstCaps for a known codec
2923 * ID into a filled-in context.
2924 * codec_data from caps will override possible extradata already in the context
2928 gst_ffmpeg_caps_with_codecid (enum AVCodecID codec_id,
2929 enum AVMediaType codec_type, const GstCaps * caps, AVCodecContext * context)
2932 const GValue *value;
2935 GST_LOG ("codec_id:%d, codec_type:%d, caps:%" GST_PTR_FORMAT " context:%p",
2936 codec_id, codec_type, caps, context);
2938 if (!context || !gst_caps_get_size (caps))
2941 str = gst_caps_get_structure (caps, 0);
2943 /* extradata parsing (esds [mpeg4], wma/wmv, msmpeg4v1/2/3, etc.) */
2944 if ((value = gst_structure_get_value (str, "codec_data"))) {
2947 buf = gst_value_get_buffer (value);
2948 gst_buffer_map (buf, &map, GST_MAP_READ);
2950 /* free the old one if it is there */
2951 if (context->extradata)
2952 av_free (context->extradata);
2955 if (codec_id == AV_CODEC_ID_H264) {
2958 GST_DEBUG ("copy, escaping codec_data %d", size);
2959 /* ffmpeg h264 expects the codec_data to be escaped, there is no real
2960 * reason for this but let's just escape it for now. Start by allocating
2961 * enough space, x2 is more than enough.
2963 * FIXME, we disabled escaping because some file already contain escaped
2964 * codec_data and then we escape twice and fail. It's better to leave it
2965 * as is, as that is what most players do. */
2966 context->extradata =
2967 av_mallocz (GST_ROUND_UP_16 (size * 2 +
2968 FF_INPUT_BUFFER_PADDING_SIZE));
2969 copy_config (context->extradata, data, size, &extrasize);
2970 GST_DEBUG ("escaped size: %d", extrasize);
2971 context->extradata_size = extrasize;
2975 /* allocate with enough padding */
2976 GST_DEBUG ("copy codec_data");
2977 context->extradata =
2978 av_mallocz (GST_ROUND_UP_16 (map.size +
2979 FF_INPUT_BUFFER_PADDING_SIZE));
2980 memcpy (context->extradata, map.data, map.size);
2981 context->extradata_size = map.size;
2984 /* Hack for VC1. Sometimes the first (length) byte is 0 for some files */
2985 if (codec_id == AV_CODEC_ID_VC1 && map.size > 0 && map.data[0] == 0) {
2986 context->extradata[0] = (guint8) map.size;
2989 GST_DEBUG ("have codec data of size %" G_GSIZE_FORMAT, map.size);
2991 gst_buffer_unmap (buf, &map);
2993 context->extradata = NULL;
2994 context->extradata_size = 0;
2995 GST_DEBUG ("no codec data");
2999 case AV_CODEC_ID_MPEG4:
3001 const gchar *mime = gst_structure_get_name (str);
3003 context->flags |= CODEC_FLAG_4MV;
3005 if (!strcmp (mime, "video/x-divx"))
3006 context->codec_tag = GST_MAKE_FOURCC ('D', 'I', 'V', 'X');
3007 else if (!strcmp (mime, "video/mpeg")) {
3008 const gchar *profile;
3010 context->codec_tag = GST_MAKE_FOURCC ('m', 'p', '4', 'v');
3012 profile = gst_structure_get_string (str, "profile");
3014 if (g_strcmp0 (profile, "advanced-simple") == 0)
3015 context->flags |= CODEC_FLAG_GMC | CODEC_FLAG_QPEL;
3021 case AV_CODEC_ID_SVQ3:
3022 /* FIXME: this is a workaround for older gst-plugins releases
3023 * (<= 0.8.9). This should be removed at some point, because
3024 * it causes wrong decoded frame order. */
3025 if (!context->extradata) {
3026 gint halfpel_flag, thirdpel_flag, low_delay, unknown_svq3_flag;
3029 if (gst_structure_get_int (str, "halfpel_flag", &halfpel_flag) &&
3030 gst_structure_get_int (str, "thirdpel_flag", &thirdpel_flag) &&
3031 gst_structure_get_int (str, "low_delay", &low_delay) &&
3032 gst_structure_get_int (str, "unknown_svq3_flag",
3033 &unknown_svq3_flag)) {
3034 context->extradata = (guint8 *) av_mallocz (0x64);
3035 g_stpcpy ((gchar *) context->extradata, "SVQ3");
3039 flags |= unknown_svq3_flag;
3041 flags |= halfpel_flag;
3043 flags |= thirdpel_flag;
3046 flags = GUINT16_FROM_LE (flags);
3048 memcpy ((gchar *) context->extradata + 0x62, &flags, 2);
3049 context->extradata_size = 0x64;
3054 case AV_CODEC_ID_MSRLE:
3055 case AV_CODEC_ID_QTRLE:
3056 case AV_CODEC_ID_TSCC:
3057 case AV_CODEC_ID_CSCD:
3058 case AV_CODEC_ID_APE:
3062 if (gst_structure_get_int (str, "depth", &depth)) {
3063 context->bits_per_coded_sample = depth;
3065 GST_WARNING ("No depth field in caps %" GST_PTR_FORMAT, caps);
3071 case AV_CODEC_ID_COOK:
3072 case AV_CODEC_ID_RA_288:
3073 case AV_CODEC_ID_RA_144:
3074 case AV_CODEC_ID_SIPR:
3079 if (gst_structure_get_int (str, "leaf_size", &leaf_size))
3080 context->block_align = leaf_size;
3081 if (gst_structure_get_int (str, "bitrate", &bitrate))
3082 context->bit_rate = bitrate;
3085 case AV_CODEC_ID_ALAC:
3086 gst_structure_get_int (str, "samplesize",
3087 &context->bits_per_coded_sample);
3090 case AV_CODEC_ID_DVVIDEO:
3092 const gchar *format;
3094 if ((format = gst_structure_get_string (str, "format"))) {
3096 if (g_str_equal (format, "YUY2"))
3097 context->pix_fmt = AV_PIX_FMT_YUYV422;
3098 else if (g_str_equal (format, "I420"))
3099 context->pix_fmt = AV_PIX_FMT_YUV420P;
3100 else if (g_str_equal (format, "A420"))
3101 context->pix_fmt = AV_PIX_FMT_YUVA420P;
3102 else if (g_str_equal (format, "Y41B"))
3103 context->pix_fmt = AV_PIX_FMT_YUV411P;
3104 else if (g_str_equal (format, "Y42B"))
3105 context->pix_fmt = AV_PIX_FMT_YUV422P;
3106 else if (g_str_equal (format, "YUV9"))
3107 context->pix_fmt = AV_PIX_FMT_YUV410P;
3109 GST_WARNING ("couldn't convert format %s" " to a pixel format",
3113 GST_WARNING ("No specified format");
3116 case AV_CODEC_ID_H263P:
3120 if (!gst_structure_get_boolean (str, "annex-f", &val) || val)
3121 context->flags |= CODEC_FLAG_4MV;
3123 context->flags &= ~CODEC_FLAG_4MV;
3124 if ((!gst_structure_get_boolean (str, "annex-i", &val) || val) &&
3125 (!gst_structure_get_boolean (str, "annex-t", &val) || val))
3126 context->flags |= CODEC_FLAG_AC_PRED;
3128 context->flags &= ~CODEC_FLAG_AC_PRED;
3129 if (!gst_structure_get_boolean (str, "annex-j", &val) || val)
3130 context->flags |= CODEC_FLAG_LOOP_FILTER;
3132 context->flags &= ~CODEC_FLAG_LOOP_FILTER;
3135 case AV_CODEC_ID_ADPCM_G726:
3137 const gchar *layout;
3139 if ((layout = gst_structure_get_string (str, "layout"))) {
3140 if (!strcmp (layout, "g721")) {
3141 context->sample_rate = 8000;
3142 context->channels = 1;
3143 context->bit_rate = 32000;
3152 if (!gst_caps_is_fixed (caps))
3155 /* common properties (width, height, fps) */
3156 switch (codec_type) {
3157 case AVMEDIA_TYPE_VIDEO:
3158 gst_ffmpeg_caps_to_pixfmt (caps, context,
3159 codec_id == AV_CODEC_ID_RAWVIDEO);
3161 case AVMEDIA_TYPE_AUDIO:
3162 gst_ffmpeg_caps_to_smpfmt (caps, context, FALSE);
3168 /* fixup of default settings */
3170 case AV_CODEC_ID_QCELP:
3171 /* QCELP is always mono, no matter what the caps say */
3172 context->channels = 1;
3174 case AV_CODEC_ID_ADPCM_G726:
3175 if (context->sample_rate && context->bit_rate)
3176 context->bits_per_coded_sample =
3177 context->bit_rate / context->sample_rate;
3184 /* _formatid_to_caps () is meant for muxers/demuxers, it
3185 * transforms a name (ffmpeg way of ID'ing these, why don't
3186 * they have unique numerical IDs?) to the corresponding
3187 * caps belonging to that mux-format
3189 * Note: we don't need any additional info because the caps
3190 * isn't supposed to contain any useful info besides the
3195 gst_ffmpeg_formatid_to_caps (const gchar * format_name)
3197 GstCaps *caps = NULL;
3199 if (!strcmp (format_name, "mpeg")) {
3200 caps = gst_caps_new_simple ("video/mpeg",
3201 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3202 } else if (!strcmp (format_name, "mpegts")) {
3203 caps = gst_caps_new_simple ("video/mpegts",
3204 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3205 } else if (!strcmp (format_name, "rm")) {
3206 caps = gst_caps_new_simple ("application/x-pn-realmedia",
3207 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3208 } else if (!strcmp (format_name, "asf")) {
3209 caps = gst_caps_new_empty_simple ("video/x-ms-asf");
3210 } else if (!strcmp (format_name, "avi")) {
3211 caps = gst_caps_new_empty_simple ("video/x-msvideo");
3212 } else if (!strcmp (format_name, "wav")) {
3213 caps = gst_caps_new_empty_simple ("audio/x-wav");
3214 } else if (!strcmp (format_name, "ape")) {
3215 caps = gst_caps_new_empty_simple ("application/x-ape");
3216 } else if (!strcmp (format_name, "swf")) {
3217 caps = gst_caps_new_empty_simple ("application/x-shockwave-flash");
3218 } else if (!strcmp (format_name, "au")) {
3219 caps = gst_caps_new_empty_simple ("audio/x-au");
3220 } else if (!strcmp (format_name, "dv")) {
3221 caps = gst_caps_new_simple ("video/x-dv",
3222 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3223 } else if (!strcmp (format_name, "4xm")) {
3224 caps = gst_caps_new_empty_simple ("video/x-4xm");
3225 } else if (!strcmp (format_name, "matroska")) {
3226 caps = gst_caps_new_empty_simple ("video/x-matroska");
3227 } else if (!strcmp (format_name, "mp3")) {
3228 caps = gst_caps_new_empty_simple ("application/x-id3");
3229 } else if (!strcmp (format_name, "flic")) {
3230 caps = gst_caps_new_empty_simple ("video/x-fli");
3231 } else if (!strcmp (format_name, "flv")) {
3232 caps = gst_caps_new_empty_simple ("video/x-flv");
3233 } else if (!strcmp (format_name, "tta")) {
3234 caps = gst_caps_new_empty_simple ("audio/x-ttafile");
3235 } else if (!strcmp (format_name, "aiff")) {
3236 caps = gst_caps_new_empty_simple ("audio/x-aiff");
3237 } else if (!strcmp (format_name, "mov_mp4_m4a_3gp_3g2")) {
3239 gst_caps_from_string
3240 ("application/x-3gp; video/quicktime; audio/x-m4a");
3241 } else if (!strcmp (format_name, "mov")) {
3242 caps = gst_caps_from_string ("video/quicktime,variant=(string)apple");
3243 } else if (!strcmp (format_name, "mp4")) {
3244 caps = gst_caps_from_string ("video/quicktime,variant=(string)iso");
3245 } else if (!strcmp (format_name, "3gp")) {
3246 caps = gst_caps_from_string ("video/quicktime,variant=(string)3gpp");
3247 } else if (!strcmp (format_name, "3g2")) {
3248 caps = gst_caps_from_string ("video/quicktime,variant=(string)3g2");
3249 } else if (!strcmp (format_name, "psp")) {
3250 caps = gst_caps_from_string ("video/quicktime,variant=(string)psp");
3251 } else if (!strcmp (format_name, "ipod")) {
3252 caps = gst_caps_from_string ("video/quicktime,variant=(string)ipod");
3253 } else if (!strcmp (format_name, "aac")) {
3254 caps = gst_caps_new_simple ("audio/mpeg",
3255 "mpegversion", G_TYPE_INT, 4, NULL);
3256 } else if (!strcmp (format_name, "gif")) {
3257 caps = gst_caps_from_string ("image/gif");
3258 } else if (!strcmp (format_name, "ogg")) {
3259 caps = gst_caps_from_string ("application/ogg");
3260 } else if (!strcmp (format_name, "mxf") || !strcmp (format_name, "mxf_d10")) {
3261 caps = gst_caps_from_string ("application/mxf");
3262 } else if (!strcmp (format_name, "gxf")) {
3263 caps = gst_caps_from_string ("application/gxf");
3264 } else if (!strcmp (format_name, "yuv4mpegpipe")) {
3265 caps = gst_caps_new_simple ("application/x-yuv4mpeg",
3266 "y4mversion", G_TYPE_INT, 2, NULL);
3267 } else if (!strcmp (format_name, "mpc")) {
3268 caps = gst_caps_from_string ("audio/x-musepack, streamversion = (int) 7");
3269 } else if (!strcmp (format_name, "mpc8")) {
3270 caps = gst_caps_from_string ("audio/x-musepack, streamversion = (int) 8");
3271 } else if (!strcmp (format_name, "vqf")) {
3272 caps = gst_caps_from_string ("audio/x-vqf");
3273 } else if (!strcmp (format_name, "nsv")) {
3274 caps = gst_caps_from_string ("video/x-nsv");
3275 } else if (!strcmp (format_name, "amr")) {
3276 caps = gst_caps_from_string ("audio/x-amr-nb-sh");
3277 } else if (!strcmp (format_name, "webm")) {
3278 caps = gst_caps_from_string ("video/webm");
3279 } else if (!strcmp (format_name, "voc")) {
3280 caps = gst_caps_from_string ("audio/x-voc");
3281 } else if (!strcmp (format_name, "pva")) {
3282 caps = gst_caps_from_string ("video/x-pva");
3286 GST_LOG ("Could not create stream format caps for %s", format_name);
3287 name = g_strdup_printf ("application/x-gst-av-%s", format_name);
3288 caps = gst_caps_new_empty_simple (name);
3296 gst_ffmpeg_formatid_get_codecids (const gchar * format_name,
3297 enum AVCodecID ** video_codec_list, enum AVCodecID ** audio_codec_list,
3298 AVOutputFormat * plugin)
3300 static enum AVCodecID tmp_vlist[] = {
3304 static enum AVCodecID tmp_alist[] = {
3309 GST_LOG ("format_name : %s", format_name);
3311 if (!strcmp (format_name, "mp4")) {
3312 static enum AVCodecID mp4_video_list[] = {
3313 AV_CODEC_ID_MPEG4, AV_CODEC_ID_H264,
3317 static enum AVCodecID mp4_audio_list[] = {
3318 AV_CODEC_ID_AAC, AV_CODEC_ID_MP3,
3322 *video_codec_list = mp4_video_list;
3323 *audio_codec_list = mp4_audio_list;
3324 } else if (!strcmp (format_name, "mpeg")) {
3325 static enum AVCodecID mpeg_video_list[] = { AV_CODEC_ID_MPEG1VIDEO,
3326 AV_CODEC_ID_MPEG2VIDEO,
3330 static enum AVCodecID mpeg_audio_list[] = { AV_CODEC_ID_MP1,
3336 *video_codec_list = mpeg_video_list;
3337 *audio_codec_list = mpeg_audio_list;
3338 } else if (!strcmp (format_name, "dvd")) {
3339 static enum AVCodecID mpeg_video_list[] = { AV_CODEC_ID_MPEG2VIDEO,
3342 static enum AVCodecID mpeg_audio_list[] = { AV_CODEC_ID_MP2,
3345 AV_CODEC_ID_PCM_S16BE,
3349 *video_codec_list = mpeg_video_list;
3350 *audio_codec_list = mpeg_audio_list;
3351 } else if (!strcmp (format_name, "mpegts")) {
3352 static enum AVCodecID mpegts_video_list[] = { AV_CODEC_ID_MPEG1VIDEO,
3353 AV_CODEC_ID_MPEG2VIDEO,
3357 static enum AVCodecID mpegts_audio_list[] = { AV_CODEC_ID_MP2,
3365 *video_codec_list = mpegts_video_list;
3366 *audio_codec_list = mpegts_audio_list;
3367 } else if (!strcmp (format_name, "vob")) {
3368 static enum AVCodecID vob_video_list[] =
3369 { AV_CODEC_ID_MPEG2VIDEO, AV_CODEC_ID_NONE };
3370 static enum AVCodecID vob_audio_list[] = { AV_CODEC_ID_MP2, AV_CODEC_ID_AC3,
3371 AV_CODEC_ID_DTS, AV_CODEC_ID_NONE
3374 *video_codec_list = vob_video_list;
3375 *audio_codec_list = vob_audio_list;
3376 } else if (!strcmp (format_name, "flv")) {
3377 static enum AVCodecID flv_video_list[] =
3378 { AV_CODEC_ID_FLV1, AV_CODEC_ID_NONE };
3379 static enum AVCodecID flv_audio_list[] =
3380 { AV_CODEC_ID_MP3, AV_CODEC_ID_NONE };
3382 *video_codec_list = flv_video_list;
3383 *audio_codec_list = flv_audio_list;
3384 } else if (!strcmp (format_name, "asf")) {
3385 static enum AVCodecID asf_video_list[] =
3386 { AV_CODEC_ID_WMV1, AV_CODEC_ID_WMV2, AV_CODEC_ID_MSMPEG4V3,
3389 static enum AVCodecID asf_audio_list[] =
3390 { AV_CODEC_ID_WMAV1, AV_CODEC_ID_WMAV2, AV_CODEC_ID_MP3,
3394 *video_codec_list = asf_video_list;
3395 *audio_codec_list = asf_audio_list;
3396 } else if (!strcmp (format_name, "dv")) {
3397 static enum AVCodecID dv_video_list[] =
3398 { AV_CODEC_ID_DVVIDEO, AV_CODEC_ID_NONE };
3399 static enum AVCodecID dv_audio_list[] =
3400 { AV_CODEC_ID_PCM_S16LE, AV_CODEC_ID_NONE };
3402 *video_codec_list = dv_video_list;
3403 *audio_codec_list = dv_audio_list;
3404 } else if (!strcmp (format_name, "mov")) {
3405 static enum AVCodecID mov_video_list[] = {
3406 AV_CODEC_ID_SVQ1, AV_CODEC_ID_SVQ3, AV_CODEC_ID_MPEG4,
3407 AV_CODEC_ID_H263, AV_CODEC_ID_H263P,
3408 AV_CODEC_ID_H264, AV_CODEC_ID_DVVIDEO,
3412 static enum AVCodecID mov_audio_list[] = {
3413 AV_CODEC_ID_PCM_MULAW, AV_CODEC_ID_PCM_ALAW, AV_CODEC_ID_ADPCM_IMA_QT,
3414 AV_CODEC_ID_MACE3, AV_CODEC_ID_MACE6, AV_CODEC_ID_AAC,
3415 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3416 AV_CODEC_ID_PCM_S16BE, AV_CODEC_ID_PCM_S16LE,
3417 AV_CODEC_ID_MP3, AV_CODEC_ID_NONE
3420 *video_codec_list = mov_video_list;
3421 *audio_codec_list = mov_audio_list;
3422 } else if ((!strcmp (format_name, "3gp") || !strcmp (format_name, "3g2"))) {
3423 static enum AVCodecID tgp_video_list[] = {
3424 AV_CODEC_ID_MPEG4, AV_CODEC_ID_H263, AV_CODEC_ID_H263P, AV_CODEC_ID_H264,
3427 static enum AVCodecID tgp_audio_list[] = {
3428 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3433 *video_codec_list = tgp_video_list;
3434 *audio_codec_list = tgp_audio_list;
3435 } else if (!strcmp (format_name, "mmf")) {
3436 static enum AVCodecID mmf_audio_list[] = {
3437 AV_CODEC_ID_ADPCM_YAMAHA, AV_CODEC_ID_NONE
3439 *video_codec_list = NULL;
3440 *audio_codec_list = mmf_audio_list;
3441 } else if (!strcmp (format_name, "amr")) {
3442 static enum AVCodecID amr_audio_list[] = {
3443 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3446 *video_codec_list = NULL;
3447 *audio_codec_list = amr_audio_list;
3448 } else if (!strcmp (format_name, "gif")) {
3449 static enum AVCodecID gif_image_list[] = {
3450 AV_CODEC_ID_RAWVIDEO, AV_CODEC_ID_NONE
3452 *video_codec_list = gif_image_list;
3453 *audio_codec_list = NULL;
3454 } else if ((plugin->audio_codec != AV_CODEC_ID_NONE) ||
3455 (plugin->video_codec != AV_CODEC_ID_NONE)) {
3456 tmp_vlist[0] = plugin->video_codec;
3457 tmp_alist[0] = plugin->audio_codec;
3459 *video_codec_list = tmp_vlist;
3460 *audio_codec_list = tmp_alist;
3461 } else if ((!strcmp (format_name, "pva"))) {
3462 static enum AVCodecID tgp_video_list[] = {
3463 AV_CODEC_ID_MPEG2VIDEO,
3466 static enum AVCodecID tgp_audio_list[] = {
3471 *video_codec_list = tgp_video_list;
3472 *audio_codec_list = tgp_audio_list;
3474 GST_LOG ("Format %s not found", format_name);
3481 /* Convert a GstCaps to a FFMPEG codec ID. Size et all
3482 * are omitted, that can be queried by the user itself,
3483 * we're not eating the GstCaps or anything
3484 * A pointer to an allocated context is also needed for
3485 * optional extra info
3489 gst_ffmpeg_caps_to_codecid (const GstCaps * caps, AVCodecContext * context)
3491 enum AVCodecID id = AV_CODEC_ID_NONE;
3492 const gchar *mimetype;
3493 const GstStructure *structure;
3494 gboolean video = FALSE, audio = FALSE; /* we want to be sure! */
3496 g_return_val_if_fail (caps != NULL, AV_CODEC_ID_NONE);
3497 g_return_val_if_fail (gst_caps_get_size (caps) == 1, AV_CODEC_ID_NONE);
3498 structure = gst_caps_get_structure (caps, 0);
3500 mimetype = gst_structure_get_name (structure);
3502 if (!strcmp (mimetype, "video/x-raw")) {
3503 id = AV_CODEC_ID_RAWVIDEO;
3505 } else if (!strcmp (mimetype, "audio/x-raw")) {
3508 if (gst_audio_info_from_caps (&info, caps)) {
3509 switch (GST_AUDIO_INFO_FORMAT (&info)) {
3510 case GST_AUDIO_FORMAT_S8:
3511 id = AV_CODEC_ID_PCM_S8;
3513 case GST_AUDIO_FORMAT_U8:
3514 id = AV_CODEC_ID_PCM_U8;
3516 case GST_AUDIO_FORMAT_S16LE:
3517 id = AV_CODEC_ID_PCM_S16LE;
3519 case GST_AUDIO_FORMAT_S16BE:
3520 id = AV_CODEC_ID_PCM_S16BE;
3522 case GST_AUDIO_FORMAT_U16LE:
3523 id = AV_CODEC_ID_PCM_U16LE;
3525 case GST_AUDIO_FORMAT_U16BE:
3526 id = AV_CODEC_ID_PCM_U16BE;
3531 if (id != AV_CODEC_ID_NONE)
3534 } else if (!strcmp (mimetype, "audio/x-mulaw")) {
3535 id = AV_CODEC_ID_PCM_MULAW;
3537 } else if (!strcmp (mimetype, "audio/x-alaw")) {
3538 id = AV_CODEC_ID_PCM_ALAW;
3540 } else if (!strcmp (mimetype, "video/x-dv")) {
3543 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3545 id = AV_CODEC_ID_DVVIDEO;
3548 } else if (!strcmp (mimetype, "audio/x-dv")) { /* ??? */
3549 id = AV_CODEC_ID_DVAUDIO;
3551 } else if (!strcmp (mimetype, "video/x-h263")) {
3552 const gchar *h263version =
3553 gst_structure_get_string (structure, "h263version");
3554 if (h263version && !strcmp (h263version, "h263p"))
3555 id = AV_CODEC_ID_H263P;
3557 id = AV_CODEC_ID_H263;
3559 } else if (!strcmp (mimetype, "video/x-intel-h263")) {
3560 id = AV_CODEC_ID_H263I;
3562 } else if (!strcmp (mimetype, "video/x-h261")) {
3563 id = AV_CODEC_ID_H261;
3565 } else if (!strcmp (mimetype, "video/mpeg")) {
3569 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3570 gst_structure_get_int (structure, "mpegversion", &mpegversion) &&
3572 switch (mpegversion) {
3574 id = AV_CODEC_ID_MPEG1VIDEO;
3577 id = AV_CODEC_ID_MPEG2VIDEO;
3580 id = AV_CODEC_ID_MPEG4;
3584 if (id != AV_CODEC_ID_NONE)
3586 } else if (!strcmp (mimetype, "image/jpeg")) {
3587 id = AV_CODEC_ID_MJPEG; /* A... B... */
3589 } else if (!strcmp (mimetype, "video/x-jpeg-b")) {
3590 id = AV_CODEC_ID_MJPEGB;
3592 } else if (!strcmp (mimetype, "video/x-wmv")) {
3593 gint wmvversion = 0;
3595 if (gst_structure_get_int (structure, "wmvversion", &wmvversion)) {
3596 switch (wmvversion) {
3598 id = AV_CODEC_ID_WMV1;
3601 id = AV_CODEC_ID_WMV2;
3605 const gchar *format;
3607 /* WMV3 unless the fourcc exists and says otherwise */
3608 id = AV_CODEC_ID_WMV3;
3610 if ((format = gst_structure_get_string (structure, "format")) &&
3611 (g_str_equal (format, "WVC1") || g_str_equal (format, "WMVA")))
3612 id = AV_CODEC_ID_VC1;
3618 if (id != AV_CODEC_ID_NONE)
3620 } else if (!strcmp (mimetype, "audio/x-vorbis")) {
3621 id = AV_CODEC_ID_VORBIS;
3623 } else if (!strcmp (mimetype, "audio/x-qdm2")) {
3624 id = AV_CODEC_ID_QDM2;
3626 } else if (!strcmp (mimetype, "audio/mpeg")) {
3628 gint mpegversion = 0;
3630 if (gst_structure_get_int (structure, "mpegversion", &mpegversion)) {
3631 switch (mpegversion) {
3632 case 2: /* ffmpeg uses faad for both... */
3634 id = AV_CODEC_ID_AAC;
3637 if (gst_structure_get_int (structure, "layer", &layer)) {
3640 id = AV_CODEC_ID_MP1;
3643 id = AV_CODEC_ID_MP2;
3646 id = AV_CODEC_ID_MP3;
3652 if (id != AV_CODEC_ID_NONE)
3654 } else if (!strcmp (mimetype, "audio/x-musepack")) {
3655 gint streamversion = -1;
3657 if (gst_structure_get_int (structure, "streamversion", &streamversion)) {
3658 if (streamversion == 7)
3659 id = AV_CODEC_ID_MUSEPACK7;
3661 id = AV_CODEC_ID_MUSEPACK7;
3663 } else if (!strcmp (mimetype, "audio/x-wma")) {
3664 gint wmaversion = 0;
3666 if (gst_structure_get_int (structure, "wmaversion", &wmaversion)) {
3667 switch (wmaversion) {
3669 id = AV_CODEC_ID_WMAV1;
3672 id = AV_CODEC_ID_WMAV2;
3675 id = AV_CODEC_ID_WMAPRO;
3679 if (id != AV_CODEC_ID_NONE)
3681 } else if (!strcmp (mimetype, "audio/x-wms")) {
3682 id = AV_CODEC_ID_WMAVOICE;
3684 } else if (!strcmp (mimetype, "audio/x-ac3")) {
3685 id = AV_CODEC_ID_AC3;
3687 } else if (!strcmp (mimetype, "audio/x-eac3")) {
3688 id = AV_CODEC_ID_EAC3;
3690 } else if (!strcmp (mimetype, "audio/x-vnd.sony.atrac3") ||
3691 !strcmp (mimetype, "audio/atrac3")) {
3692 id = AV_CODEC_ID_ATRAC3;
3694 } else if (!strcmp (mimetype, "audio/x-dts")) {
3695 id = AV_CODEC_ID_DTS;
3697 } else if (!strcmp (mimetype, "application/x-ape")) {
3698 id = AV_CODEC_ID_APE;
3700 } else if (!strcmp (mimetype, "video/x-msmpeg")) {
3701 gint msmpegversion = 0;
3703 if (gst_structure_get_int (structure, "msmpegversion", &msmpegversion)) {
3704 switch (msmpegversion) {
3706 id = AV_CODEC_ID_MSMPEG4V1;
3709 id = AV_CODEC_ID_MSMPEG4V2;
3712 id = AV_CODEC_ID_MSMPEG4V3;
3716 if (id != AV_CODEC_ID_NONE)
3718 } else if (!strcmp (mimetype, "video/x-svq")) {
3719 gint svqversion = 0;
3721 if (gst_structure_get_int (structure, "svqversion", &svqversion)) {
3722 switch (svqversion) {
3724 id = AV_CODEC_ID_SVQ1;
3727 id = AV_CODEC_ID_SVQ3;
3731 if (id != AV_CODEC_ID_NONE)
3733 } else if (!strcmp (mimetype, "video/x-huffyuv")) {
3734 id = AV_CODEC_ID_HUFFYUV;
3736 } else if (!strcmp (mimetype, "audio/x-mace")) {
3737 gint maceversion = 0;
3739 if (gst_structure_get_int (structure, "maceversion", &maceversion)) {
3740 switch (maceversion) {
3742 id = AV_CODEC_ID_MACE3;
3745 id = AV_CODEC_ID_MACE6;
3749 if (id != AV_CODEC_ID_NONE)
3751 } else if (!strcmp (mimetype, "video/x-theora")) {
3752 id = AV_CODEC_ID_THEORA;
3754 } else if (!strcmp (mimetype, "video/x-vp3")) {
3755 id = AV_CODEC_ID_VP3;
3757 } else if (!strcmp (mimetype, "video/x-vp5")) {
3758 id = AV_CODEC_ID_VP5;
3760 } else if (!strcmp (mimetype, "video/x-vp6")) {
3761 id = AV_CODEC_ID_VP6;
3763 } else if (!strcmp (mimetype, "video/x-vp6-flash")) {
3764 id = AV_CODEC_ID_VP6F;
3766 } else if (!strcmp (mimetype, "video/x-vp6-alpha")) {
3767 id = AV_CODEC_ID_VP6A;
3769 } else if (!strcmp (mimetype, "video/x-vp8")) {
3770 id = AV_CODEC_ID_VP8;
3772 } else if (!strcmp (mimetype, "video/x-vp9")) {
3773 id = AV_CODEC_ID_VP9;
3775 } else if (!strcmp (mimetype, "video/x-flash-screen")) {
3776 id = AV_CODEC_ID_FLASHSV;
3778 } else if (!strcmp (mimetype, "video/x-indeo")) {
3779 gint indeoversion = 0;
3781 if (gst_structure_get_int (structure, "indeoversion", &indeoversion)) {
3782 switch (indeoversion) {
3784 id = AV_CODEC_ID_INDEO5;
3787 id = AV_CODEC_ID_INDEO4;
3790 id = AV_CODEC_ID_INDEO3;
3793 id = AV_CODEC_ID_INDEO2;
3796 if (id != AV_CODEC_ID_NONE)
3799 } else if (!strcmp (mimetype, "video/x-divx")) {
3800 gint divxversion = 0;
3802 if (gst_structure_get_int (structure, "divxversion", &divxversion)) {
3803 switch (divxversion) {
3805 id = AV_CODEC_ID_MSMPEG4V3;
3809 id = AV_CODEC_ID_MPEG4;
3813 if (id != AV_CODEC_ID_NONE)
3815 } else if (!strcmp (mimetype, "video/x-ffv")) {
3816 gint ffvversion = 0;
3818 if (gst_structure_get_int (structure, "ffvversion", &ffvversion) &&
3820 id = AV_CODEC_ID_FFV1;
3823 } else if (!strcmp (mimetype, "video/x-apple-intermediate-codec")) {
3824 id = AV_CODEC_ID_AIC;
3826 } else if (!strcmp (mimetype, "audio/x-adpcm")) {
3827 const gchar *layout;
3829 layout = gst_structure_get_string (structure, "layout");
3830 if (layout == NULL) {
3832 } else if (!strcmp (layout, "quicktime")) {
3833 id = AV_CODEC_ID_ADPCM_IMA_QT;
3834 } else if (!strcmp (layout, "microsoft")) {
3835 id = AV_CODEC_ID_ADPCM_MS;
3836 } else if (!strcmp (layout, "dvi")) {
3837 id = AV_CODEC_ID_ADPCM_IMA_WAV;
3838 } else if (!strcmp (layout, "4xm")) {
3839 id = AV_CODEC_ID_ADPCM_4XM;
3840 } else if (!strcmp (layout, "smjpeg")) {
3841 id = AV_CODEC_ID_ADPCM_IMA_SMJPEG;
3842 } else if (!strcmp (layout, "dk3")) {
3843 id = AV_CODEC_ID_ADPCM_IMA_DK3;
3844 } else if (!strcmp (layout, "dk4")) {
3845 id = AV_CODEC_ID_ADPCM_IMA_DK4;
3846 } else if (!strcmp (layout, "westwood")) {
3847 id = AV_CODEC_ID_ADPCM_IMA_WS;
3848 } else if (!strcmp (layout, "iss")) {
3849 id = AV_CODEC_ID_ADPCM_IMA_ISS;
3850 } else if (!strcmp (layout, "xa")) {
3851 id = AV_CODEC_ID_ADPCM_XA;
3852 } else if (!strcmp (layout, "adx")) {
3853 id = AV_CODEC_ID_ADPCM_ADX;
3854 } else if (!strcmp (layout, "ea")) {
3855 id = AV_CODEC_ID_ADPCM_EA;
3856 } else if (!strcmp (layout, "g726")) {
3857 id = AV_CODEC_ID_ADPCM_G726;
3858 } else if (!strcmp (layout, "g721")) {
3859 id = AV_CODEC_ID_ADPCM_G726;
3860 } else if (!strcmp (layout, "ct")) {
3861 id = AV_CODEC_ID_ADPCM_CT;
3862 } else if (!strcmp (layout, "swf")) {
3863 id = AV_CODEC_ID_ADPCM_SWF;
3864 } else if (!strcmp (layout, "yamaha")) {
3865 id = AV_CODEC_ID_ADPCM_YAMAHA;
3866 } else if (!strcmp (layout, "sbpro2")) {
3867 id = AV_CODEC_ID_ADPCM_SBPRO_2;
3868 } else if (!strcmp (layout, "sbpro3")) {
3869 id = AV_CODEC_ID_ADPCM_SBPRO_3;
3870 } else if (!strcmp (layout, "sbpro4")) {
3871 id = AV_CODEC_ID_ADPCM_SBPRO_4;
3873 if (id != AV_CODEC_ID_NONE)
3875 } else if (!strcmp (mimetype, "video/x-4xm")) {
3876 id = AV_CODEC_ID_4XM;
3878 } else if (!strcmp (mimetype, "audio/x-dpcm")) {
3879 const gchar *layout;
3881 layout = gst_structure_get_string (structure, "layout");
3884 } else if (!strcmp (layout, "roq")) {
3885 id = AV_CODEC_ID_ROQ_DPCM;
3886 } else if (!strcmp (layout, "interplay")) {
3887 id = AV_CODEC_ID_INTERPLAY_DPCM;
3888 } else if (!strcmp (layout, "xan")) {
3889 id = AV_CODEC_ID_XAN_DPCM;
3890 } else if (!strcmp (layout, "sol")) {
3891 id = AV_CODEC_ID_SOL_DPCM;
3893 if (id != AV_CODEC_ID_NONE)
3895 } else if (!strcmp (mimetype, "audio/x-flac")) {
3896 id = AV_CODEC_ID_FLAC;
3898 } else if (!strcmp (mimetype, "audio/x-shorten")) {
3899 id = AV_CODEC_ID_SHORTEN;
3901 } else if (!strcmp (mimetype, "audio/x-alac")) {
3902 id = AV_CODEC_ID_ALAC;
3904 } else if (!strcmp (mimetype, "video/x-cinepak")) {
3905 id = AV_CODEC_ID_CINEPAK;
3907 } else if (!strcmp (mimetype, "video/x-pn-realvideo")) {
3910 if (gst_structure_get_int (structure, "rmversion", &rmversion)) {
3911 switch (rmversion) {
3913 id = AV_CODEC_ID_RV10;
3916 id = AV_CODEC_ID_RV20;
3919 id = AV_CODEC_ID_RV30;
3922 id = AV_CODEC_ID_RV40;
3926 if (id != AV_CODEC_ID_NONE)
3928 } else if (!strcmp (mimetype, "audio/x-sipro")) {
3929 id = AV_CODEC_ID_SIPR;
3931 } else if (!strcmp (mimetype, "audio/x-pn-realaudio")) {
3934 if (gst_structure_get_int (structure, "raversion", &raversion)) {
3935 switch (raversion) {
3937 id = AV_CODEC_ID_RA_144;
3940 id = AV_CODEC_ID_RA_288;
3943 id = AV_CODEC_ID_COOK;
3947 if (id != AV_CODEC_ID_NONE)
3949 } else if (!strcmp (mimetype, "video/x-rle")) {
3950 const gchar *layout;
3952 if ((layout = gst_structure_get_string (structure, "layout"))) {
3953 if (!strcmp (layout, "microsoft")) {
3954 id = AV_CODEC_ID_MSRLE;
3958 } else if (!strcmp (mimetype, "video/x-xan")) {
3961 if ((gst_structure_get_int (structure, "wcversion", &wcversion))) {
3962 switch (wcversion) {
3964 id = AV_CODEC_ID_XAN_WC3;
3968 id = AV_CODEC_ID_XAN_WC4;
3975 } else if (!strcmp (mimetype, "audio/AMR")) {
3977 id = AV_CODEC_ID_AMR_NB;
3978 } else if (!strcmp (mimetype, "audio/AMR-WB")) {
3979 id = AV_CODEC_ID_AMR_WB;
3981 } else if (!strcmp (mimetype, "audio/qcelp")) {
3982 id = AV_CODEC_ID_QCELP;
3984 } else if (!strcmp (mimetype, "video/x-h264")) {
3985 id = AV_CODEC_ID_H264;
3987 } else if (!strcmp (mimetype, "video/x-h265")) {
3988 id = AV_CODEC_ID_HEVC;
3990 } else if (!strcmp (mimetype, "video/x-flash-video")) {
3991 gint flvversion = 0;
3993 if ((gst_structure_get_int (structure, "flvversion", &flvversion))) {
3994 switch (flvversion) {
3996 id = AV_CODEC_ID_FLV1;
4004 } else if (!strcmp (mimetype, "audio/x-nellymoser")) {
4005 id = AV_CODEC_ID_NELLYMOSER;
4007 } else if (!strncmp (mimetype, "audio/x-gst-av-", 15)) {
4011 if (strlen (mimetype) <= 30 &&
4012 sscanf (mimetype, "audio/x-gst-av-%s", ext) == 1) {
4013 if ((codec = avcodec_find_decoder_by_name (ext)) ||
4014 (codec = avcodec_find_encoder_by_name (ext))) {
4019 } else if (!strncmp (mimetype, "video/x-gst-av-", 15)) {
4023 if (strlen (mimetype) <= 30 &&
4024 sscanf (mimetype, "video/x-gst-av-%s", ext) == 1) {
4025 if ((codec = avcodec_find_decoder_by_name (ext)) ||
4026 (codec = avcodec_find_encoder_by_name (ext))) {
4033 if (context != NULL) {
4034 if (video == TRUE) {
4035 context->codec_type = AVMEDIA_TYPE_VIDEO;
4036 } else if (audio == TRUE) {
4037 context->codec_type = AVMEDIA_TYPE_AUDIO;
4039 context->codec_type = AVMEDIA_TYPE_UNKNOWN;
4041 context->codec_id = id;
4042 gst_ffmpeg_caps_with_codecid (id, context->codec_type, caps, context);
4045 if (id != AV_CODEC_ID_NONE) {
4046 GST_DEBUG ("The id=%d belongs to the caps %" GST_PTR_FORMAT, id, caps);
4048 GST_WARNING ("Couldn't figure out the id for caps %" GST_PTR_FORMAT, caps);