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,
1150 (guint) context->bit_rate, NULL);
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, (guint) 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, (guint) 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, (guint) 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, (guint) 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, (guint) 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, (guint) 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_OPUS:
2112 /* Note that ffmpeg has no encoder yet, but just for safety. In the
2113 * encoder case, we want to add things like samplerate, channels... */
2115 /* FIXME: can ffmpeg handle multichannel Opus? */
2116 caps = gst_caps_new_simple ("audio/x-opus",
2117 "channel-mapping-family", G_TYPE_INT, 0, NULL);
2121 case AV_CODEC_ID_S302M:
2122 caps = gst_caps_new_empty_simple ("audio/x-smpte-302m");
2125 case AV_CODEC_ID_DVD_SUBTITLE:
2126 case AV_CODEC_ID_DVB_SUBTITLE:
2129 case AV_CODEC_ID_BMP:
2130 caps = gst_caps_new_empty_simple ("image/bmp");
2132 case AV_CODEC_ID_TTA:
2134 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-tta",
2137 gst_caps_set_simple (caps,
2138 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
2141 case AV_CODEC_ID_TWINVQ:
2143 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
2144 "audio/x-twin-vq", NULL);
2146 case AV_CODEC_ID_G729:
2148 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/G729",
2152 GST_DEBUG ("Unknown codec ID %d, please add mapping here", codec_id);
2159 if ((codec = avcodec_find_decoder (codec_id)) ||
2160 (codec = avcodec_find_encoder (codec_id))) {
2163 GST_LOG ("Could not create stream format caps for %s", codec->name);
2165 switch (codec->type) {
2166 case AVMEDIA_TYPE_VIDEO:
2167 mime = g_strdup_printf ("video/x-gst-av-%s", codec->name);
2169 gst_ff_vid_caps_new (context, NULL, codec_id, encode, mime, NULL);
2172 case AVMEDIA_TYPE_AUDIO:
2173 mime = g_strdup_printf ("audio/x-gst-av-%s", codec->name);
2175 gst_ff_aud_caps_new (context, NULL, codec_id, encode, mime, NULL);
2177 gst_caps_set_simple (caps,
2178 "block_align", G_TYPE_INT, context->block_align,
2179 "bitrate", G_TYPE_INT, (guint) context->bit_rate, NULL);
2190 /* set private data */
2191 if (context && context->extradata_size > 0) {
2192 GstBuffer *data = gst_buffer_new_and_alloc (context->extradata_size);
2194 gst_buffer_fill (data, 0, context->extradata, context->extradata_size);
2195 gst_caps_set_simple (caps, "codec_data", GST_TYPE_BUFFER, data, NULL);
2196 gst_buffer_unref (data);
2199 GST_LOG ("caps for codec_id=%d: %" GST_PTR_FORMAT, codec_id, caps);
2202 GST_LOG ("No caps found for codec_id=%d", codec_id);
2208 /* Convert a FFMPEG Pixel Format and optional AVCodecContext
2209 * to a GstCaps. If the context is ommitted, no fixed values
2210 * for video/audio size will be included in the GstCaps
2212 * See below for usefullness
2216 gst_ffmpeg_pixfmt_to_caps (enum AVPixelFormat pix_fmt, AVCodecContext * context,
2217 enum AVCodecID codec_id)
2219 GstCaps *caps = NULL;
2220 GstVideoFormat format;
2222 format = gst_ffmpeg_pixfmt_to_videoformat (pix_fmt);
2224 if (format != GST_VIDEO_FORMAT_UNKNOWN) {
2225 caps = gst_ff_vid_caps_new (context, NULL, codec_id, TRUE, "video/x-raw",
2226 "format", G_TYPE_STRING, gst_video_format_to_string (format), NULL);
2230 GST_DEBUG ("caps for pix_fmt=%d: %" GST_PTR_FORMAT, pix_fmt, caps);
2232 GST_LOG ("No caps found for pix_fmt=%d", pix_fmt);
2239 gst_ffmpeg_smpfmt_to_audioformat (enum AVSampleFormat sample_fmt)
2241 switch (sample_fmt) {
2242 case AV_SAMPLE_FMT_U8:
2243 case AV_SAMPLE_FMT_U8P:
2244 return GST_AUDIO_FORMAT_U8;
2246 case AV_SAMPLE_FMT_S16:
2247 case AV_SAMPLE_FMT_S16P:
2248 return GST_AUDIO_FORMAT_S16;
2250 case AV_SAMPLE_FMT_S32:
2251 case AV_SAMPLE_FMT_S32P:
2252 return GST_AUDIO_FORMAT_S32;
2254 case AV_SAMPLE_FMT_FLT:
2255 case AV_SAMPLE_FMT_FLTP:
2256 return GST_AUDIO_FORMAT_F32;
2258 case AV_SAMPLE_FMT_DBL:
2259 case AV_SAMPLE_FMT_DBLP:
2260 return GST_AUDIO_FORMAT_F64;
2264 return GST_AUDIO_FORMAT_UNKNOWN;
2269 /* Convert a FFMPEG Sample Format and optional AVCodecContext
2270 * to a GstCaps. If the context is ommitted, no fixed values
2271 * for video/audio size will be included in the GstCaps
2273 * See below for usefullness
2277 gst_ffmpeg_smpfmt_to_caps (enum AVSampleFormat sample_fmt,
2278 AVCodecContext * context, AVCodec * codec, enum AVCodecID codec_id)
2280 GstCaps *caps = NULL;
2281 GstAudioFormat format;
2283 format = gst_ffmpeg_smpfmt_to_audioformat (sample_fmt);
2285 if (format != GST_AUDIO_FORMAT_UNKNOWN) {
2286 caps = gst_ff_aud_caps_new (context, codec, codec_id, TRUE, "audio/x-raw",
2287 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
2288 "layout", G_TYPE_STRING, "interleaved", NULL);
2289 GST_LOG ("caps for sample_fmt=%d: %" GST_PTR_FORMAT, sample_fmt, caps);
2291 GST_LOG ("No caps found for sample_fmt=%d", sample_fmt);
2298 caps_has_field (GstCaps * caps, const gchar * field)
2302 n = gst_caps_get_size (caps);
2303 for (i = 0; i < n; i++) {
2304 GstStructure *s = gst_caps_get_structure (caps, i);
2306 if (gst_structure_has_field (s, field))
2314 gst_ffmpeg_codectype_to_audio_caps (AVCodecContext * context,
2315 enum AVCodecID codec_id, gboolean encode, AVCodec * codec)
2317 GstCaps *caps = NULL;
2319 GST_DEBUG ("context:%p, codec_id:%d, encode:%d, codec:%p",
2320 context, codec_id, encode, codec);
2322 GST_DEBUG ("sample_fmts:%p, samplerates:%p",
2323 codec->sample_fmts, codec->supported_samplerates);
2326 /* Specific codec context */
2328 gst_ffmpeg_smpfmt_to_caps (context->sample_fmt, context, codec,
2331 caps = gst_ff_aud_caps_new (context, codec, codec_id, encode, "audio/x-raw",
2332 "layout", G_TYPE_STRING, "interleaved", NULL);
2333 if (!caps_has_field (caps, "format"))
2334 gst_ffmpeg_audio_set_sample_fmts (caps,
2335 codec ? codec->sample_fmts : NULL);
2342 gst_ffmpeg_codectype_to_video_caps (AVCodecContext * context,
2343 enum AVCodecID codec_id, gboolean encode, AVCodec * codec)
2347 GST_LOG ("context:%p, codec_id:%d, encode:%d, codec:%p",
2348 context, codec_id, encode, codec);
2351 caps = gst_ffmpeg_pixfmt_to_caps (context->pix_fmt, context, codec_id);
2354 gst_ff_vid_caps_new (context, codec, codec_id, encode, "video/x-raw",
2356 if (!caps_has_field (caps, "format"))
2357 gst_ffmpeg_video_set_pix_fmts (caps, codec ? codec->pix_fmts : NULL);
2362 /* Convert a GstCaps (audio/raw) to a FFMPEG SampleFmt
2363 * and other audio properties in a AVCodecContext.
2365 * For usefullness, see below
2369 gst_ffmpeg_caps_to_smpfmt (const GstCaps * caps,
2370 AVCodecContext * context, gboolean raw)
2372 GstStructure *structure;
2374 GstAudioFormat format = GST_AUDIO_FORMAT_UNKNOWN;
2377 g_return_if_fail (gst_caps_get_size (caps) == 1);
2379 structure = gst_caps_get_structure (caps, 0);
2381 gst_structure_get_int (structure, "channels", &context->channels);
2382 gst_structure_get_int (structure, "rate", &context->sample_rate);
2383 gst_structure_get_int (structure, "block_align", &context->block_align);
2384 if (gst_structure_get_int (structure, "bitrate", &bitrate))
2385 context->bit_rate = bitrate;
2390 if (gst_structure_has_name (structure, "audio/x-raw")) {
2391 if ((fmt = gst_structure_get_string (structure, "format"))) {
2392 format = gst_audio_format_from_string (fmt);
2397 case GST_AUDIO_FORMAT_F32:
2398 context->sample_fmt = AV_SAMPLE_FMT_FLT;
2400 case GST_AUDIO_FORMAT_F64:
2401 context->sample_fmt = AV_SAMPLE_FMT_DBL;
2403 case GST_AUDIO_FORMAT_S32:
2404 context->sample_fmt = AV_SAMPLE_FMT_S32;
2406 case GST_AUDIO_FORMAT_S16:
2407 context->sample_fmt = AV_SAMPLE_FMT_S16;
2414 /* Convert a GstCaps (video/raw) to a FFMPEG PixFmt
2415 * and other video properties in a AVCodecContext.
2417 * For usefullness, see below
2421 gst_ffmpeg_caps_to_pixfmt (const GstCaps * caps,
2422 AVCodecContext * context, gboolean raw)
2424 GstStructure *structure;
2426 const GValue *par = NULL;
2428 GstVideoFormat format = GST_VIDEO_FORMAT_UNKNOWN;
2430 GST_DEBUG ("converting caps %" GST_PTR_FORMAT, caps);
2431 g_return_if_fail (gst_caps_get_size (caps) == 1);
2432 structure = gst_caps_get_structure (caps, 0);
2434 gst_structure_get_int (structure, "width", &context->width);
2435 gst_structure_get_int (structure, "height", &context->height);
2436 gst_structure_get_int (structure, "bpp", &context->bits_per_coded_sample);
2438 fps = gst_structure_get_value (structure, "framerate");
2439 if (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps)) {
2441 int num = gst_value_get_fraction_numerator (fps);
2442 int den = gst_value_get_fraction_denominator (fps);
2444 if (num > 0 && den > 0) {
2445 /* somehow these seem mixed up.. */
2446 /* they're fine, this is because it does period=1/frequency */
2447 context->time_base.den = gst_value_get_fraction_numerator (fps);
2448 context->time_base.num = gst_value_get_fraction_denominator (fps);
2449 context->ticks_per_frame = 1;
2451 GST_DEBUG ("setting framerate %d/%d = %lf",
2452 context->time_base.den, context->time_base.num,
2453 1. * context->time_base.den / context->time_base.num);
2455 GST_INFO ("ignoring framerate %d/%d (probably variable framerate)",
2456 context->time_base.num, context->time_base.den);
2460 par = gst_structure_get_value (structure, "pixel-aspect-ratio");
2461 if (par && GST_VALUE_HOLDS_FRACTION (par)) {
2463 int num = gst_value_get_fraction_numerator (par);
2464 int den = gst_value_get_fraction_denominator (par);
2466 if (num > 0 && den > 0) {
2467 context->sample_aspect_ratio.num = num;
2468 context->sample_aspect_ratio.den = den;
2470 GST_DEBUG ("setting pixel-aspect-ratio %d/%d = %lf",
2471 context->sample_aspect_ratio.num, context->sample_aspect_ratio.den,
2472 1. * context->sample_aspect_ratio.num /
2473 context->sample_aspect_ratio.den);
2475 GST_WARNING ("ignoring insane pixel-aspect-ratio %d/%d",
2476 context->sample_aspect_ratio.num, context->sample_aspect_ratio.den);
2483 g_return_if_fail (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps));
2485 if (gst_structure_has_name (structure, "video/x-raw")) {
2486 if ((fmt = gst_structure_get_string (structure, "format"))) {
2487 format = gst_video_format_from_string (fmt);
2492 case GST_VIDEO_FORMAT_YUY2:
2493 context->pix_fmt = AV_PIX_FMT_YUYV422;
2495 case GST_VIDEO_FORMAT_I420:
2496 context->pix_fmt = AV_PIX_FMT_YUV420P;
2498 case GST_VIDEO_FORMAT_A420:
2499 context->pix_fmt = AV_PIX_FMT_YUVA420P;
2501 case GST_VIDEO_FORMAT_Y41B:
2502 context->pix_fmt = AV_PIX_FMT_YUV411P;
2504 case GST_VIDEO_FORMAT_Y42B:
2505 context->pix_fmt = AV_PIX_FMT_YUV422P;
2507 case GST_VIDEO_FORMAT_YUV9:
2508 context->pix_fmt = AV_PIX_FMT_YUV410P;
2510 case GST_VIDEO_FORMAT_Y444:
2511 context->pix_fmt = AV_PIX_FMT_YUV444P;
2513 case GST_VIDEO_FORMAT_GRAY8:
2514 context->pix_fmt = AV_PIX_FMT_GRAY8;
2516 case GST_VIDEO_FORMAT_xRGB:
2517 #if (G_BYTE_ORDER == G_BIG_ENDIAN)
2518 context->pix_fmt = AV_PIX_FMT_RGB32;
2521 case GST_VIDEO_FORMAT_BGRx:
2522 #if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
2523 context->pix_fmt = AV_PIX_FMT_RGB32;
2526 case GST_VIDEO_FORMAT_RGB:
2527 context->pix_fmt = AV_PIX_FMT_RGB24;
2529 case GST_VIDEO_FORMAT_BGR:
2530 context->pix_fmt = AV_PIX_FMT_BGR24;
2532 case GST_VIDEO_FORMAT_RGB16:
2533 context->pix_fmt = AV_PIX_FMT_RGB565;
2535 case GST_VIDEO_FORMAT_RGB15:
2536 context->pix_fmt = AV_PIX_FMT_RGB555;
2538 case GST_VIDEO_FORMAT_RGB8P:
2539 context->pix_fmt = AV_PIX_FMT_PAL8;
2548 GstVideoFormat format;
2549 enum AVPixelFormat pixfmt;
2552 /* FIXME : FILLME */
2553 static const PixToFmt pixtofmttable[] = {
2554 /* GST_VIDEO_FORMAT_I420, */
2555 {GST_VIDEO_FORMAT_I420, AV_PIX_FMT_YUV420P},
2556 /* Note : this should use a different chroma placement */
2557 {GST_VIDEO_FORMAT_I420, AV_PIX_FMT_YUVJ420P},
2559 /* GST_VIDEO_FORMAT_YV12, */
2560 /* GST_VIDEO_FORMAT_YUY2, */
2561 {GST_VIDEO_FORMAT_YUY2, AV_PIX_FMT_YUYV422},
2562 /* GST_VIDEO_FORMAT_UYVY, */
2563 {GST_VIDEO_FORMAT_UYVY, AV_PIX_FMT_UYVY422},
2564 /* GST_VIDEO_FORMAT_AYUV, */
2565 /* GST_VIDEO_FORMAT_RGBx, */
2566 /* GST_VIDEO_FORMAT_BGRx, */
2567 /* GST_VIDEO_FORMAT_xRGB, */
2568 /* GST_VIDEO_FORMAT_xBGR, */
2569 /* GST_VIDEO_FORMAT_RGBA, */
2570 {GST_VIDEO_FORMAT_RGBA, AV_PIX_FMT_RGBA},
2571 /* GST_VIDEO_FORMAT_BGRA, */
2572 {GST_VIDEO_FORMAT_BGRA, AV_PIX_FMT_BGRA},
2573 /* GST_VIDEO_FORMAT_ARGB, */
2574 {GST_VIDEO_FORMAT_ARGB, AV_PIX_FMT_ARGB},
2575 /* GST_VIDEO_FORMAT_ABGR, */
2576 {GST_VIDEO_FORMAT_ABGR, AV_PIX_FMT_ABGR},
2577 /* GST_VIDEO_FORMAT_RGB, */
2578 {GST_VIDEO_FORMAT_RGB, AV_PIX_FMT_RGB24},
2579 /* GST_VIDEO_FORMAT_BGR, */
2580 {GST_VIDEO_FORMAT_BGR, AV_PIX_FMT_BGR24},
2581 /* GST_VIDEO_FORMAT_Y41B, */
2582 {GST_VIDEO_FORMAT_Y41B, AV_PIX_FMT_YUV411P},
2583 /* GST_VIDEO_FORMAT_Y42B, */
2584 {GST_VIDEO_FORMAT_Y42B, AV_PIX_FMT_YUV422P},
2585 {GST_VIDEO_FORMAT_Y42B, AV_PIX_FMT_YUVJ422P},
2586 /* GST_VIDEO_FORMAT_YVYU, */
2587 /* GST_VIDEO_FORMAT_Y444, */
2588 {GST_VIDEO_FORMAT_Y444, AV_PIX_FMT_YUV444P},
2589 {GST_VIDEO_FORMAT_Y444, AV_PIX_FMT_YUVJ444P},
2590 /* GST_VIDEO_FORMAT_v210, */
2591 /* GST_VIDEO_FORMAT_v216, */
2592 /* GST_VIDEO_FORMAT_NV12, */
2593 {GST_VIDEO_FORMAT_NV12, AV_PIX_FMT_NV12},
2594 /* GST_VIDEO_FORMAT_NV21, */
2595 {GST_VIDEO_FORMAT_NV21, AV_PIX_FMT_NV21},
2596 /* GST_VIDEO_FORMAT_GRAY8, */
2597 {GST_VIDEO_FORMAT_GRAY8, AV_PIX_FMT_GRAY8},
2598 /* GST_VIDEO_FORMAT_GRAY16_BE, */
2599 {GST_VIDEO_FORMAT_GRAY16_BE, AV_PIX_FMT_GRAY16BE},
2600 /* GST_VIDEO_FORMAT_GRAY16_LE, */
2601 {GST_VIDEO_FORMAT_GRAY16_LE, AV_PIX_FMT_GRAY16LE},
2602 /* GST_VIDEO_FORMAT_v308, */
2603 /* GST_VIDEO_FORMAT_Y800, */
2604 /* GST_VIDEO_FORMAT_Y16, */
2605 /* GST_VIDEO_FORMAT_RGB16, */
2606 {GST_VIDEO_FORMAT_RGB16, AV_PIX_FMT_RGB565},
2607 /* GST_VIDEO_FORMAT_BGR16, */
2608 /* GST_VIDEO_FORMAT_RGB15, */
2609 {GST_VIDEO_FORMAT_RGB15, AV_PIX_FMT_RGB555},
2610 /* GST_VIDEO_FORMAT_BGR15, */
2611 /* GST_VIDEO_FORMAT_UYVP, */
2612 /* GST_VIDEO_FORMAT_A420, */
2613 {GST_VIDEO_FORMAT_A420, AV_PIX_FMT_YUVA420P},
2614 /* GST_VIDEO_FORMAT_RGB8_PALETTED, */
2615 {GST_VIDEO_FORMAT_RGB8P, AV_PIX_FMT_PAL8},
2616 /* GST_VIDEO_FORMAT_YUV9, */
2617 {GST_VIDEO_FORMAT_YUV9, AV_PIX_FMT_YUV410P},
2618 /* GST_VIDEO_FORMAT_YVU9, */
2619 /* GST_VIDEO_FORMAT_IYU1, */
2620 /* GST_VIDEO_FORMAT_ARGB64, */
2621 /* GST_VIDEO_FORMAT_AYUV64, */
2622 /* GST_VIDEO_FORMAT_r210, */
2623 {GST_VIDEO_FORMAT_I420_10LE, AV_PIX_FMT_YUV420P10LE},
2624 {GST_VIDEO_FORMAT_I420_10BE, AV_PIX_FMT_YUV420P10BE},
2625 {GST_VIDEO_FORMAT_I422_10LE, AV_PIX_FMT_YUV422P10LE},
2626 {GST_VIDEO_FORMAT_I422_10BE, AV_PIX_FMT_YUV422P10BE},
2627 {GST_VIDEO_FORMAT_Y444_10LE, AV_PIX_FMT_YUV444P10LE},
2628 {GST_VIDEO_FORMAT_Y444_10BE, AV_PIX_FMT_YUV444P10BE},
2629 {GST_VIDEO_FORMAT_GBR, AV_PIX_FMT_GBRP},
2630 {GST_VIDEO_FORMAT_GBR_10LE, AV_PIX_FMT_GBRP10LE},
2631 {GST_VIDEO_FORMAT_GBR_10BE, AV_PIX_FMT_GBRP10BE},
2632 {GST_VIDEO_FORMAT_A420_10LE, AV_PIX_FMT_YUVA420P10LE},
2633 {GST_VIDEO_FORMAT_A420_10BE, AV_PIX_FMT_YUVA420P10BE},
2634 {GST_VIDEO_FORMAT_A422_10LE, AV_PIX_FMT_YUVA422P10LE},
2635 {GST_VIDEO_FORMAT_A422_10BE, AV_PIX_FMT_YUVA422P10BE},
2636 {GST_VIDEO_FORMAT_A444_10LE, AV_PIX_FMT_YUVA444P10LE},
2637 {GST_VIDEO_FORMAT_A444_10BE, AV_PIX_FMT_YUVA444P10BE},
2641 gst_ffmpeg_pixfmt_to_videoformat (enum AVPixelFormat pixfmt)
2645 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2646 if (pixtofmttable[i].pixfmt == pixfmt)
2647 return pixtofmttable[i].format;
2649 GST_DEBUG ("Unknown pixel format %d", pixfmt);
2650 return GST_VIDEO_FORMAT_UNKNOWN;
2653 static enum AVPixelFormat
2654 gst_ffmpeg_videoformat_to_pixfmt_for_codec (GstVideoFormat format,
2655 const AVCodec * codec)
2659 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++) {
2660 if (pixtofmttable[i].format == format) {
2663 if (codec && codec->pix_fmts) {
2664 for (j = 0; codec->pix_fmts[j] != -1; j++) {
2665 if (pixtofmttable[i].pixfmt == codec->pix_fmts[j])
2666 return pixtofmttable[i].pixfmt;
2669 return pixtofmttable[i].pixfmt;
2674 return AV_PIX_FMT_NONE;
2678 gst_ffmpeg_videoformat_to_pixfmt (GstVideoFormat format)
2680 return gst_ffmpeg_videoformat_to_pixfmt_for_codec (format, NULL);
2684 gst_ffmpeg_videoinfo_to_context (GstVideoInfo * info, AVCodecContext * context)
2688 context->width = GST_VIDEO_INFO_WIDTH (info);
2689 context->height = GST_VIDEO_INFO_HEIGHT (info);
2690 for (i = 0; i < GST_VIDEO_INFO_N_COMPONENTS (info); i++)
2691 bpp += GST_VIDEO_INFO_COMP_DEPTH (info, i);
2692 context->bits_per_coded_sample = bpp;
2694 context->ticks_per_frame = 1;
2695 if (GST_VIDEO_INFO_FPS_N (info) == 0) {
2696 GST_DEBUG ("Using 25/1 framerate");
2697 context->time_base.den = 25;
2698 context->time_base.num = 1;
2700 context->time_base.den = GST_VIDEO_INFO_FPS_N (info);
2701 context->time_base.num = GST_VIDEO_INFO_FPS_D (info);
2704 context->sample_aspect_ratio.num = GST_VIDEO_INFO_PAR_N (info);
2705 context->sample_aspect_ratio.den = GST_VIDEO_INFO_PAR_D (info);
2708 gst_ffmpeg_videoformat_to_pixfmt_for_codec (GST_VIDEO_INFO_FORMAT (info),
2713 gst_ffmpeg_audioinfo_to_context (GstAudioInfo * info, AVCodecContext * context)
2715 const AVCodec *codec;
2716 const enum AVSampleFormat *smpl_fmts;
2717 enum AVSampleFormat smpl_fmt = -1;
2719 context->channels = info->channels;
2720 context->sample_rate = info->rate;
2721 context->channel_layout =
2722 gst_ffmpeg_channel_positions_to_layout (info->position, info->channels);
2724 codec = context->codec;
2726 smpl_fmts = codec->sample_fmts;
2728 switch (info->finfo->format) {
2729 case GST_AUDIO_FORMAT_F32:
2731 while (*smpl_fmts != -1) {
2732 if (*smpl_fmts == AV_SAMPLE_FMT_FLT) {
2733 smpl_fmt = *smpl_fmts;
2735 } else if (*smpl_fmts == AV_SAMPLE_FMT_FLTP) {
2736 smpl_fmt = *smpl_fmts;
2742 smpl_fmt = AV_SAMPLE_FMT_FLT;
2745 case GST_AUDIO_FORMAT_F64:
2747 while (*smpl_fmts != -1) {
2748 if (*smpl_fmts == AV_SAMPLE_FMT_DBL) {
2749 smpl_fmt = *smpl_fmts;
2751 } else if (*smpl_fmts == AV_SAMPLE_FMT_DBLP) {
2752 smpl_fmt = *smpl_fmts;
2758 smpl_fmt = AV_SAMPLE_FMT_DBL;
2761 case GST_AUDIO_FORMAT_S32:
2763 while (*smpl_fmts != -1) {
2764 if (*smpl_fmts == AV_SAMPLE_FMT_S32) {
2765 smpl_fmt = *smpl_fmts;
2767 } else if (*smpl_fmts == AV_SAMPLE_FMT_S32P) {
2768 smpl_fmt = *smpl_fmts;
2774 smpl_fmt = AV_SAMPLE_FMT_S32;
2777 case GST_AUDIO_FORMAT_S16:
2779 while (*smpl_fmts != -1) {
2780 if (*smpl_fmts == AV_SAMPLE_FMT_S16) {
2781 smpl_fmt = *smpl_fmts;
2783 } else if (*smpl_fmts == AV_SAMPLE_FMT_S16P) {
2784 smpl_fmt = *smpl_fmts;
2790 smpl_fmt = AV_SAMPLE_FMT_S16;
2793 case GST_AUDIO_FORMAT_U8:
2795 while (*smpl_fmts != -1) {
2796 if (*smpl_fmts == AV_SAMPLE_FMT_U8) {
2797 smpl_fmt = *smpl_fmts;
2799 } else if (*smpl_fmts == AV_SAMPLE_FMT_U8P) {
2800 smpl_fmt = *smpl_fmts;
2806 smpl_fmt = AV_SAMPLE_FMT_U8;
2813 g_assert (smpl_fmt != -1);
2815 context->sample_fmt = smpl_fmt;
2818 /* Convert a GstCaps and a FFMPEG codec Type to a
2819 * AVCodecContext. If the context is ommitted, no fixed values
2820 * for video/audio size will be included in the context
2822 * AVMediaType is primarily meant for uncompressed data GstCaps!
2826 gst_ffmpeg_caps_with_codectype (enum AVMediaType type,
2827 const GstCaps * caps, AVCodecContext * context)
2829 if (context == NULL)
2833 case AVMEDIA_TYPE_VIDEO:
2834 gst_ffmpeg_caps_to_pixfmt (caps, context, TRUE);
2837 case AVMEDIA_TYPE_AUDIO:
2838 gst_ffmpeg_caps_to_smpfmt (caps, context, TRUE);
2849 nal_escape (guint8 * dst, guint8 * src, guint size, guint * destsize)
2853 guint8 *end = src + size;
2856 while (srcp < end) {
2857 if (count == 2 && *srcp <= 0x03) {
2858 GST_DEBUG ("added escape code");
2867 GST_DEBUG ("copy %02x, count %d", *srcp, count);
2870 *destsize = dstp - dst;
2873 /* copy the config, escaping NAL units as we iterate them, if something fails we
2874 * copy everything and hope for the best. */
2876 copy_config (guint8 * dst, guint8 * src, guint size, guint * destsize)
2881 guint nalsize, esize;
2891 cnt = *(srcp + 5) & 0x1f; /* Number of sps */
2893 GST_DEBUG ("num SPS %d", cnt);
2895 memcpy (dstp, srcp, 6);
2899 for (i = 0; i < cnt; i++) {
2900 GST_DEBUG ("copy SPS %d", i);
2901 nalsize = (srcp[0] << 8) | srcp[1];
2902 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2903 dstp[0] = esize >> 8;
2904 dstp[1] = esize & 0xff;
2906 srcp += nalsize + 2;
2909 cnt = *(dstp++) = *(srcp++); /* Number of pps */
2911 GST_DEBUG ("num PPS %d", cnt);
2913 for (i = 0; i < cnt; i++) {
2914 GST_DEBUG ("copy PPS %d", i);
2915 nalsize = (srcp[0] << 8) | srcp[1];
2916 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2917 dstp[0] = esize >> 8;
2918 dstp[1] = esize & 0xff;
2920 srcp += nalsize + 2;
2922 *destsize = dstp - dst;
2928 GST_DEBUG ("something unexpected, doing full copy");
2929 memcpy (dst, src, size);
2937 * caps_with_codecid () transforms a GstCaps for a known codec
2938 * ID into a filled-in context.
2939 * codec_data from caps will override possible extradata already in the context
2943 gst_ffmpeg_caps_with_codecid (enum AVCodecID codec_id,
2944 enum AVMediaType codec_type, const GstCaps * caps, AVCodecContext * context)
2947 const GValue *value;
2950 GST_LOG ("codec_id:%d, codec_type:%d, caps:%" GST_PTR_FORMAT " context:%p",
2951 codec_id, codec_type, caps, context);
2953 if (!context || !gst_caps_get_size (caps))
2956 str = gst_caps_get_structure (caps, 0);
2958 /* extradata parsing (esds [mpeg4], wma/wmv, msmpeg4v1/2/3, etc.) */
2959 if ((value = gst_structure_get_value (str, "codec_data"))) {
2962 buf = gst_value_get_buffer (value);
2963 gst_buffer_map (buf, &map, GST_MAP_READ);
2965 /* free the old one if it is there */
2966 if (context->extradata)
2967 av_free (context->extradata);
2970 if (codec_id == AV_CODEC_ID_H264) {
2973 GST_DEBUG ("copy, escaping codec_data %d", size);
2974 /* ffmpeg h264 expects the codec_data to be escaped, there is no real
2975 * reason for this but let's just escape it for now. Start by allocating
2976 * enough space, x2 is more than enough.
2978 * FIXME, we disabled escaping because some file already contain escaped
2979 * codec_data and then we escape twice and fail. It's better to leave it
2980 * as is, as that is what most players do. */
2981 context->extradata =
2982 av_mallocz (GST_ROUND_UP_16 (size * 2 +
2983 FF_INPUT_BUFFER_PADDING_SIZE));
2984 copy_config (context->extradata, data, size, &extrasize);
2985 GST_DEBUG ("escaped size: %d", extrasize);
2986 context->extradata_size = extrasize;
2990 /* allocate with enough padding */
2991 GST_DEBUG ("copy codec_data");
2992 context->extradata =
2993 av_mallocz (GST_ROUND_UP_16 (map.size +
2994 FF_INPUT_BUFFER_PADDING_SIZE));
2995 memcpy (context->extradata, map.data, map.size);
2996 context->extradata_size = map.size;
2999 /* Hack for VC1. Sometimes the first (length) byte is 0 for some files */
3000 if (codec_id == AV_CODEC_ID_VC1 && map.size > 0 && map.data[0] == 0) {
3001 context->extradata[0] = (guint8) map.size;
3004 GST_DEBUG ("have codec data of size %" G_GSIZE_FORMAT, map.size);
3006 gst_buffer_unmap (buf, &map);
3008 context->extradata = NULL;
3009 context->extradata_size = 0;
3010 GST_DEBUG ("no codec data");
3014 case AV_CODEC_ID_MPEG4:
3016 const gchar *mime = gst_structure_get_name (str);
3018 context->flags |= CODEC_FLAG_4MV;
3020 if (!strcmp (mime, "video/x-divx"))
3021 context->codec_tag = GST_MAKE_FOURCC ('D', 'I', 'V', 'X');
3022 else if (!strcmp (mime, "video/mpeg")) {
3023 const gchar *profile;
3025 context->codec_tag = GST_MAKE_FOURCC ('m', 'p', '4', 'v');
3027 profile = gst_structure_get_string (str, "profile");
3029 if (g_strcmp0 (profile, "advanced-simple") == 0)
3030 context->flags |= CODEC_FLAG_GMC | CODEC_FLAG_QPEL;
3036 case AV_CODEC_ID_SVQ3:
3037 /* FIXME: this is a workaround for older gst-plugins releases
3038 * (<= 0.8.9). This should be removed at some point, because
3039 * it causes wrong decoded frame order. */
3040 if (!context->extradata) {
3041 gint halfpel_flag, thirdpel_flag, low_delay, unknown_svq3_flag;
3044 if (gst_structure_get_int (str, "halfpel_flag", &halfpel_flag) &&
3045 gst_structure_get_int (str, "thirdpel_flag", &thirdpel_flag) &&
3046 gst_structure_get_int (str, "low_delay", &low_delay) &&
3047 gst_structure_get_int (str, "unknown_svq3_flag",
3048 &unknown_svq3_flag)) {
3049 context->extradata = (guint8 *) av_mallocz (0x64);
3050 g_stpcpy ((gchar *) context->extradata, "SVQ3");
3054 flags |= unknown_svq3_flag;
3056 flags |= halfpel_flag;
3058 flags |= thirdpel_flag;
3061 flags = GUINT16_FROM_LE (flags);
3063 memcpy ((gchar *) context->extradata + 0x62, &flags, 2);
3064 context->extradata_size = 0x64;
3069 case AV_CODEC_ID_MSRLE:
3070 case AV_CODEC_ID_QTRLE:
3071 case AV_CODEC_ID_TSCC:
3072 case AV_CODEC_ID_CSCD:
3073 case AV_CODEC_ID_APE:
3077 if (gst_structure_get_int (str, "depth", &depth)) {
3078 context->bits_per_coded_sample = depth;
3080 GST_WARNING ("No depth field in caps %" GST_PTR_FORMAT, caps);
3086 case AV_CODEC_ID_COOK:
3087 case AV_CODEC_ID_RA_288:
3088 case AV_CODEC_ID_RA_144:
3089 case AV_CODEC_ID_SIPR:
3094 if (gst_structure_get_int (str, "leaf_size", &leaf_size))
3095 context->block_align = leaf_size;
3096 if (gst_structure_get_int (str, "bitrate", &bitrate))
3097 context->bit_rate = bitrate;
3100 case AV_CODEC_ID_ALAC:
3101 gst_structure_get_int (str, "samplesize",
3102 &context->bits_per_coded_sample);
3105 case AV_CODEC_ID_DVVIDEO:
3107 const gchar *format;
3109 if ((format = gst_structure_get_string (str, "format"))) {
3111 if (g_str_equal (format, "YUY2"))
3112 context->pix_fmt = AV_PIX_FMT_YUYV422;
3113 else if (g_str_equal (format, "I420"))
3114 context->pix_fmt = AV_PIX_FMT_YUV420P;
3115 else if (g_str_equal (format, "A420"))
3116 context->pix_fmt = AV_PIX_FMT_YUVA420P;
3117 else if (g_str_equal (format, "Y41B"))
3118 context->pix_fmt = AV_PIX_FMT_YUV411P;
3119 else if (g_str_equal (format, "Y42B"))
3120 context->pix_fmt = AV_PIX_FMT_YUV422P;
3121 else if (g_str_equal (format, "YUV9"))
3122 context->pix_fmt = AV_PIX_FMT_YUV410P;
3124 GST_WARNING ("couldn't convert format %s" " to a pixel format",
3128 GST_WARNING ("No specified format");
3131 case AV_CODEC_ID_H263P:
3135 if (!gst_structure_get_boolean (str, "annex-f", &val) || val)
3136 context->flags |= CODEC_FLAG_4MV;
3138 context->flags &= ~CODEC_FLAG_4MV;
3139 if ((!gst_structure_get_boolean (str, "annex-i", &val) || val) &&
3140 (!gst_structure_get_boolean (str, "annex-t", &val) || val))
3141 context->flags |= CODEC_FLAG_AC_PRED;
3143 context->flags &= ~CODEC_FLAG_AC_PRED;
3144 if (!gst_structure_get_boolean (str, "annex-j", &val) || val)
3145 context->flags |= CODEC_FLAG_LOOP_FILTER;
3147 context->flags &= ~CODEC_FLAG_LOOP_FILTER;
3150 case AV_CODEC_ID_ADPCM_G726:
3152 const gchar *layout;
3154 if ((layout = gst_structure_get_string (str, "layout"))) {
3155 if (!strcmp (layout, "g721")) {
3156 context->sample_rate = 8000;
3157 context->channels = 1;
3158 context->bit_rate = 32000;
3167 if (!gst_caps_is_fixed (caps))
3170 /* common properties (width, height, fps) */
3171 switch (codec_type) {
3172 case AVMEDIA_TYPE_VIDEO:
3173 gst_ffmpeg_caps_to_pixfmt (caps, context,
3174 codec_id == AV_CODEC_ID_RAWVIDEO);
3176 case AVMEDIA_TYPE_AUDIO:
3177 gst_ffmpeg_caps_to_smpfmt (caps, context, FALSE);
3183 /* fixup of default settings */
3185 case AV_CODEC_ID_QCELP:
3186 /* QCELP is always mono, no matter what the caps say */
3187 context->channels = 1;
3189 case AV_CODEC_ID_ADPCM_G726:
3190 if (context->sample_rate && context->bit_rate)
3191 context->bits_per_coded_sample =
3192 context->bit_rate / context->sample_rate;
3199 /* _formatid_to_caps () is meant for muxers/demuxers, it
3200 * transforms a name (ffmpeg way of ID'ing these, why don't
3201 * they have unique numerical IDs?) to the corresponding
3202 * caps belonging to that mux-format
3204 * Note: we don't need any additional info because the caps
3205 * isn't supposed to contain any useful info besides the
3210 gst_ffmpeg_formatid_to_caps (const gchar * format_name)
3212 GstCaps *caps = NULL;
3214 if (!strcmp (format_name, "mpeg")) {
3215 caps = gst_caps_new_simple ("video/mpeg",
3216 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3217 } else if (!strcmp (format_name, "mpegts")) {
3218 caps = gst_caps_new_simple ("video/mpegts",
3219 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3220 } else if (!strcmp (format_name, "rm")) {
3221 caps = gst_caps_new_simple ("application/x-pn-realmedia",
3222 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3223 } else if (!strcmp (format_name, "asf")) {
3224 caps = gst_caps_new_empty_simple ("video/x-ms-asf");
3225 } else if (!strcmp (format_name, "avi")) {
3226 caps = gst_caps_new_empty_simple ("video/x-msvideo");
3227 } else if (!strcmp (format_name, "wav")) {
3228 caps = gst_caps_new_empty_simple ("audio/x-wav");
3229 } else if (!strcmp (format_name, "ape")) {
3230 caps = gst_caps_new_empty_simple ("application/x-ape");
3231 } else if (!strcmp (format_name, "swf")) {
3232 caps = gst_caps_new_empty_simple ("application/x-shockwave-flash");
3233 } else if (!strcmp (format_name, "au")) {
3234 caps = gst_caps_new_empty_simple ("audio/x-au");
3235 } else if (!strcmp (format_name, "dv")) {
3236 caps = gst_caps_new_simple ("video/x-dv",
3237 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3238 } else if (!strcmp (format_name, "4xm")) {
3239 caps = gst_caps_new_empty_simple ("video/x-4xm");
3240 } else if (!strcmp (format_name, "matroska")) {
3241 caps = gst_caps_new_empty_simple ("video/x-matroska");
3242 } else if (!strcmp (format_name, "mp3")) {
3243 caps = gst_caps_new_empty_simple ("application/x-id3");
3244 } else if (!strcmp (format_name, "flic")) {
3245 caps = gst_caps_new_empty_simple ("video/x-fli");
3246 } else if (!strcmp (format_name, "flv")) {
3247 caps = gst_caps_new_empty_simple ("video/x-flv");
3248 } else if (!strcmp (format_name, "tta")) {
3249 caps = gst_caps_new_empty_simple ("audio/x-ttafile");
3250 } else if (!strcmp (format_name, "aiff")) {
3251 caps = gst_caps_new_empty_simple ("audio/x-aiff");
3252 } else if (!strcmp (format_name, "mov_mp4_m4a_3gp_3g2")) {
3254 gst_caps_from_string
3255 ("application/x-3gp; video/quicktime; audio/x-m4a");
3256 } else if (!strcmp (format_name, "mov")) {
3257 caps = gst_caps_from_string ("video/quicktime,variant=(string)apple");
3258 } else if (!strcmp (format_name, "mp4")) {
3259 caps = gst_caps_from_string ("video/quicktime,variant=(string)iso");
3260 } else if (!strcmp (format_name, "3gp")) {
3261 caps = gst_caps_from_string ("video/quicktime,variant=(string)3gpp");
3262 } else if (!strcmp (format_name, "3g2")) {
3263 caps = gst_caps_from_string ("video/quicktime,variant=(string)3g2");
3264 } else if (!strcmp (format_name, "psp")) {
3265 caps = gst_caps_from_string ("video/quicktime,variant=(string)psp");
3266 } else if (!strcmp (format_name, "ipod")) {
3267 caps = gst_caps_from_string ("video/quicktime,variant=(string)ipod");
3268 } else if (!strcmp (format_name, "aac")) {
3269 caps = gst_caps_new_simple ("audio/mpeg",
3270 "mpegversion", G_TYPE_INT, 4, NULL);
3271 } else if (!strcmp (format_name, "gif")) {
3272 caps = gst_caps_from_string ("image/gif");
3273 } else if (!strcmp (format_name, "ogg")) {
3274 caps = gst_caps_from_string ("application/ogg");
3275 } else if (!strcmp (format_name, "mxf") || !strcmp (format_name, "mxf_d10")) {
3276 caps = gst_caps_from_string ("application/mxf");
3277 } else if (!strcmp (format_name, "gxf")) {
3278 caps = gst_caps_from_string ("application/gxf");
3279 } else if (!strcmp (format_name, "yuv4mpegpipe")) {
3280 caps = gst_caps_new_simple ("application/x-yuv4mpeg",
3281 "y4mversion", G_TYPE_INT, 2, NULL);
3282 } else if (!strcmp (format_name, "mpc")) {
3283 caps = gst_caps_from_string ("audio/x-musepack, streamversion = (int) 7");
3284 } else if (!strcmp (format_name, "mpc8")) {
3285 caps = gst_caps_from_string ("audio/x-musepack, streamversion = (int) 8");
3286 } else if (!strcmp (format_name, "vqf")) {
3287 caps = gst_caps_from_string ("audio/x-vqf");
3288 } else if (!strcmp (format_name, "nsv")) {
3289 caps = gst_caps_from_string ("video/x-nsv");
3290 } else if (!strcmp (format_name, "amr")) {
3291 caps = gst_caps_from_string ("audio/x-amr-nb-sh");
3292 } else if (!strcmp (format_name, "webm")) {
3293 caps = gst_caps_from_string ("video/webm");
3294 } else if (!strcmp (format_name, "voc")) {
3295 caps = gst_caps_from_string ("audio/x-voc");
3296 } else if (!strcmp (format_name, "pva")) {
3297 caps = gst_caps_from_string ("video/x-pva");
3301 GST_LOG ("Could not create stream format caps for %s", format_name);
3302 name = g_strdup_printf ("application/x-gst-av-%s", format_name);
3303 caps = gst_caps_new_empty_simple (name);
3311 gst_ffmpeg_formatid_get_codecids (const gchar * format_name,
3312 enum AVCodecID ** video_codec_list, enum AVCodecID ** audio_codec_list,
3313 AVOutputFormat * plugin)
3315 static enum AVCodecID tmp_vlist[] = {
3319 static enum AVCodecID tmp_alist[] = {
3324 GST_LOG ("format_name : %s", format_name);
3326 if (!strcmp (format_name, "mp4")) {
3327 static enum AVCodecID mp4_video_list[] = {
3328 AV_CODEC_ID_MPEG4, AV_CODEC_ID_H264,
3332 static enum AVCodecID mp4_audio_list[] = {
3333 AV_CODEC_ID_AAC, AV_CODEC_ID_MP3,
3337 *video_codec_list = mp4_video_list;
3338 *audio_codec_list = mp4_audio_list;
3339 } else if (!strcmp (format_name, "mpeg")) {
3340 static enum AVCodecID mpeg_video_list[] = { AV_CODEC_ID_MPEG1VIDEO,
3341 AV_CODEC_ID_MPEG2VIDEO,
3345 static enum AVCodecID mpeg_audio_list[] = { AV_CODEC_ID_MP1,
3351 *video_codec_list = mpeg_video_list;
3352 *audio_codec_list = mpeg_audio_list;
3353 } else if (!strcmp (format_name, "dvd")) {
3354 static enum AVCodecID mpeg_video_list[] = { AV_CODEC_ID_MPEG2VIDEO,
3357 static enum AVCodecID mpeg_audio_list[] = { AV_CODEC_ID_MP2,
3360 AV_CODEC_ID_PCM_S16BE,
3364 *video_codec_list = mpeg_video_list;
3365 *audio_codec_list = mpeg_audio_list;
3366 } else if (!strcmp (format_name, "mpegts")) {
3367 static enum AVCodecID mpegts_video_list[] = { AV_CODEC_ID_MPEG1VIDEO,
3368 AV_CODEC_ID_MPEG2VIDEO,
3372 static enum AVCodecID mpegts_audio_list[] = { AV_CODEC_ID_MP2,
3380 *video_codec_list = mpegts_video_list;
3381 *audio_codec_list = mpegts_audio_list;
3382 } else if (!strcmp (format_name, "vob")) {
3383 static enum AVCodecID vob_video_list[] =
3384 { AV_CODEC_ID_MPEG2VIDEO, AV_CODEC_ID_NONE };
3385 static enum AVCodecID vob_audio_list[] = { AV_CODEC_ID_MP2, AV_CODEC_ID_AC3,
3386 AV_CODEC_ID_DTS, AV_CODEC_ID_NONE
3389 *video_codec_list = vob_video_list;
3390 *audio_codec_list = vob_audio_list;
3391 } else if (!strcmp (format_name, "flv")) {
3392 static enum AVCodecID flv_video_list[] =
3393 { AV_CODEC_ID_FLV1, AV_CODEC_ID_NONE };
3394 static enum AVCodecID flv_audio_list[] =
3395 { AV_CODEC_ID_MP3, AV_CODEC_ID_NONE };
3397 *video_codec_list = flv_video_list;
3398 *audio_codec_list = flv_audio_list;
3399 } else if (!strcmp (format_name, "asf")) {
3400 static enum AVCodecID asf_video_list[] =
3401 { AV_CODEC_ID_WMV1, AV_CODEC_ID_WMV2, AV_CODEC_ID_MSMPEG4V3,
3404 static enum AVCodecID asf_audio_list[] =
3405 { AV_CODEC_ID_WMAV1, AV_CODEC_ID_WMAV2, AV_CODEC_ID_MP3,
3409 *video_codec_list = asf_video_list;
3410 *audio_codec_list = asf_audio_list;
3411 } else if (!strcmp (format_name, "dv")) {
3412 static enum AVCodecID dv_video_list[] =
3413 { AV_CODEC_ID_DVVIDEO, AV_CODEC_ID_NONE };
3414 static enum AVCodecID dv_audio_list[] =
3415 { AV_CODEC_ID_PCM_S16LE, AV_CODEC_ID_NONE };
3417 *video_codec_list = dv_video_list;
3418 *audio_codec_list = dv_audio_list;
3419 } else if (!strcmp (format_name, "mov")) {
3420 static enum AVCodecID mov_video_list[] = {
3421 AV_CODEC_ID_SVQ1, AV_CODEC_ID_SVQ3, AV_CODEC_ID_MPEG4,
3422 AV_CODEC_ID_H263, AV_CODEC_ID_H263P,
3423 AV_CODEC_ID_H264, AV_CODEC_ID_DVVIDEO,
3427 static enum AVCodecID mov_audio_list[] = {
3428 AV_CODEC_ID_PCM_MULAW, AV_CODEC_ID_PCM_ALAW, AV_CODEC_ID_ADPCM_IMA_QT,
3429 AV_CODEC_ID_MACE3, AV_CODEC_ID_MACE6, AV_CODEC_ID_AAC,
3430 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3431 AV_CODEC_ID_PCM_S16BE, AV_CODEC_ID_PCM_S16LE,
3432 AV_CODEC_ID_MP3, AV_CODEC_ID_NONE
3435 *video_codec_list = mov_video_list;
3436 *audio_codec_list = mov_audio_list;
3437 } else if ((!strcmp (format_name, "3gp") || !strcmp (format_name, "3g2"))) {
3438 static enum AVCodecID tgp_video_list[] = {
3439 AV_CODEC_ID_MPEG4, AV_CODEC_ID_H263, AV_CODEC_ID_H263P, AV_CODEC_ID_H264,
3442 static enum AVCodecID tgp_audio_list[] = {
3443 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3448 *video_codec_list = tgp_video_list;
3449 *audio_codec_list = tgp_audio_list;
3450 } else if (!strcmp (format_name, "mmf")) {
3451 static enum AVCodecID mmf_audio_list[] = {
3452 AV_CODEC_ID_ADPCM_YAMAHA, AV_CODEC_ID_NONE
3454 *video_codec_list = NULL;
3455 *audio_codec_list = mmf_audio_list;
3456 } else if (!strcmp (format_name, "amr")) {
3457 static enum AVCodecID amr_audio_list[] = {
3458 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3461 *video_codec_list = NULL;
3462 *audio_codec_list = amr_audio_list;
3463 } else if (!strcmp (format_name, "gif")) {
3464 static enum AVCodecID gif_image_list[] = {
3465 AV_CODEC_ID_RAWVIDEO, AV_CODEC_ID_NONE
3467 *video_codec_list = gif_image_list;
3468 *audio_codec_list = NULL;
3469 } else if ((plugin->audio_codec != AV_CODEC_ID_NONE) ||
3470 (plugin->video_codec != AV_CODEC_ID_NONE)) {
3471 tmp_vlist[0] = plugin->video_codec;
3472 tmp_alist[0] = plugin->audio_codec;
3474 *video_codec_list = tmp_vlist;
3475 *audio_codec_list = tmp_alist;
3476 } else if ((!strcmp (format_name, "pva"))) {
3477 static enum AVCodecID tgp_video_list[] = {
3478 AV_CODEC_ID_MPEG2VIDEO,
3481 static enum AVCodecID tgp_audio_list[] = {
3486 *video_codec_list = tgp_video_list;
3487 *audio_codec_list = tgp_audio_list;
3489 GST_LOG ("Format %s not found", format_name);
3496 /* Convert a GstCaps to a FFMPEG codec ID. Size et all
3497 * are omitted, that can be queried by the user itself,
3498 * we're not eating the GstCaps or anything
3499 * A pointer to an allocated context is also needed for
3500 * optional extra info
3504 gst_ffmpeg_caps_to_codecid (const GstCaps * caps, AVCodecContext * context)
3506 enum AVCodecID id = AV_CODEC_ID_NONE;
3507 const gchar *mimetype;
3508 const GstStructure *structure;
3509 gboolean video = FALSE, audio = FALSE; /* we want to be sure! */
3511 g_return_val_if_fail (caps != NULL, AV_CODEC_ID_NONE);
3512 g_return_val_if_fail (gst_caps_get_size (caps) == 1, AV_CODEC_ID_NONE);
3513 structure = gst_caps_get_structure (caps, 0);
3515 mimetype = gst_structure_get_name (structure);
3517 if (!strcmp (mimetype, "video/x-raw")) {
3518 id = AV_CODEC_ID_RAWVIDEO;
3520 } else if (!strcmp (mimetype, "audio/x-raw")) {
3523 if (gst_audio_info_from_caps (&info, caps)) {
3524 switch (GST_AUDIO_INFO_FORMAT (&info)) {
3525 case GST_AUDIO_FORMAT_S8:
3526 id = AV_CODEC_ID_PCM_S8;
3528 case GST_AUDIO_FORMAT_U8:
3529 id = AV_CODEC_ID_PCM_U8;
3531 case GST_AUDIO_FORMAT_S16LE:
3532 id = AV_CODEC_ID_PCM_S16LE;
3534 case GST_AUDIO_FORMAT_S16BE:
3535 id = AV_CODEC_ID_PCM_S16BE;
3537 case GST_AUDIO_FORMAT_U16LE:
3538 id = AV_CODEC_ID_PCM_U16LE;
3540 case GST_AUDIO_FORMAT_U16BE:
3541 id = AV_CODEC_ID_PCM_U16BE;
3546 if (id != AV_CODEC_ID_NONE)
3549 } else if (!strcmp (mimetype, "audio/x-mulaw")) {
3550 id = AV_CODEC_ID_PCM_MULAW;
3552 } else if (!strcmp (mimetype, "audio/x-alaw")) {
3553 id = AV_CODEC_ID_PCM_ALAW;
3555 } else if (!strcmp (mimetype, "video/x-dv")) {
3558 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3560 id = AV_CODEC_ID_DVVIDEO;
3563 } else if (!strcmp (mimetype, "audio/x-dv")) { /* ??? */
3564 id = AV_CODEC_ID_DVAUDIO;
3566 } else if (!strcmp (mimetype, "video/x-h263")) {
3567 const gchar *h263version =
3568 gst_structure_get_string (structure, "h263version");
3569 if (h263version && !strcmp (h263version, "h263p"))
3570 id = AV_CODEC_ID_H263P;
3572 id = AV_CODEC_ID_H263;
3574 } else if (!strcmp (mimetype, "video/x-intel-h263")) {
3575 id = AV_CODEC_ID_H263I;
3577 } else if (!strcmp (mimetype, "video/x-h261")) {
3578 id = AV_CODEC_ID_H261;
3580 } else if (!strcmp (mimetype, "video/mpeg")) {
3584 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3585 gst_structure_get_int (structure, "mpegversion", &mpegversion) &&
3587 switch (mpegversion) {
3589 id = AV_CODEC_ID_MPEG1VIDEO;
3592 id = AV_CODEC_ID_MPEG2VIDEO;
3595 id = AV_CODEC_ID_MPEG4;
3599 if (id != AV_CODEC_ID_NONE)
3601 } else if (!strcmp (mimetype, "image/jpeg")) {
3602 id = AV_CODEC_ID_MJPEG; /* A... B... */
3604 } else if (!strcmp (mimetype, "video/x-jpeg-b")) {
3605 id = AV_CODEC_ID_MJPEGB;
3607 } else if (!strcmp (mimetype, "video/x-wmv")) {
3608 gint wmvversion = 0;
3610 if (gst_structure_get_int (structure, "wmvversion", &wmvversion)) {
3611 switch (wmvversion) {
3613 id = AV_CODEC_ID_WMV1;
3616 id = AV_CODEC_ID_WMV2;
3620 const gchar *format;
3622 /* WMV3 unless the fourcc exists and says otherwise */
3623 id = AV_CODEC_ID_WMV3;
3625 if ((format = gst_structure_get_string (structure, "format")) &&
3626 (g_str_equal (format, "WVC1") || g_str_equal (format, "WMVA")))
3627 id = AV_CODEC_ID_VC1;
3633 if (id != AV_CODEC_ID_NONE)
3635 } else if (!strcmp (mimetype, "audio/x-vorbis")) {
3636 id = AV_CODEC_ID_VORBIS;
3638 } else if (!strcmp (mimetype, "audio/x-qdm2")) {
3639 id = AV_CODEC_ID_QDM2;
3641 } else if (!strcmp (mimetype, "audio/mpeg")) {
3643 gint mpegversion = 0;
3645 if (gst_structure_get_int (structure, "mpegversion", &mpegversion)) {
3646 switch (mpegversion) {
3647 case 2: /* ffmpeg uses faad for both... */
3649 id = AV_CODEC_ID_AAC;
3652 if (gst_structure_get_int (structure, "layer", &layer)) {
3655 id = AV_CODEC_ID_MP1;
3658 id = AV_CODEC_ID_MP2;
3661 id = AV_CODEC_ID_MP3;
3667 if (id != AV_CODEC_ID_NONE)
3669 } else if (!strcmp (mimetype, "audio/x-musepack")) {
3670 gint streamversion = -1;
3672 if (gst_structure_get_int (structure, "streamversion", &streamversion)) {
3673 if (streamversion == 7)
3674 id = AV_CODEC_ID_MUSEPACK7;
3676 id = AV_CODEC_ID_MUSEPACK7;
3678 } else if (!strcmp (mimetype, "audio/x-wma")) {
3679 gint wmaversion = 0;
3681 if (gst_structure_get_int (structure, "wmaversion", &wmaversion)) {
3682 switch (wmaversion) {
3684 id = AV_CODEC_ID_WMAV1;
3687 id = AV_CODEC_ID_WMAV2;
3690 id = AV_CODEC_ID_WMAPRO;
3694 if (id != AV_CODEC_ID_NONE)
3696 } else if (!strcmp (mimetype, "audio/x-wms")) {
3697 id = AV_CODEC_ID_WMAVOICE;
3699 } else if (!strcmp (mimetype, "audio/x-ac3")) {
3700 id = AV_CODEC_ID_AC3;
3702 } else if (!strcmp (mimetype, "audio/x-eac3")) {
3703 id = AV_CODEC_ID_EAC3;
3705 } else if (!strcmp (mimetype, "audio/x-vnd.sony.atrac3") ||
3706 !strcmp (mimetype, "audio/atrac3")) {
3707 id = AV_CODEC_ID_ATRAC3;
3709 } else if (!strcmp (mimetype, "audio/x-dts")) {
3710 id = AV_CODEC_ID_DTS;
3712 } else if (!strcmp (mimetype, "application/x-ape")) {
3713 id = AV_CODEC_ID_APE;
3715 } else if (!strcmp (mimetype, "video/x-msmpeg")) {
3716 gint msmpegversion = 0;
3718 if (gst_structure_get_int (structure, "msmpegversion", &msmpegversion)) {
3719 switch (msmpegversion) {
3721 id = AV_CODEC_ID_MSMPEG4V1;
3724 id = AV_CODEC_ID_MSMPEG4V2;
3727 id = AV_CODEC_ID_MSMPEG4V3;
3731 if (id != AV_CODEC_ID_NONE)
3733 } else if (!strcmp (mimetype, "video/x-svq")) {
3734 gint svqversion = 0;
3736 if (gst_structure_get_int (structure, "svqversion", &svqversion)) {
3737 switch (svqversion) {
3739 id = AV_CODEC_ID_SVQ1;
3742 id = AV_CODEC_ID_SVQ3;
3746 if (id != AV_CODEC_ID_NONE)
3748 } else if (!strcmp (mimetype, "video/x-huffyuv")) {
3749 id = AV_CODEC_ID_HUFFYUV;
3751 } else if (!strcmp (mimetype, "audio/x-mace")) {
3752 gint maceversion = 0;
3754 if (gst_structure_get_int (structure, "maceversion", &maceversion)) {
3755 switch (maceversion) {
3757 id = AV_CODEC_ID_MACE3;
3760 id = AV_CODEC_ID_MACE6;
3764 if (id != AV_CODEC_ID_NONE)
3766 } else if (!strcmp (mimetype, "video/x-theora")) {
3767 id = AV_CODEC_ID_THEORA;
3769 } else if (!strcmp (mimetype, "video/x-vp3")) {
3770 id = AV_CODEC_ID_VP3;
3772 } else if (!strcmp (mimetype, "video/x-vp5")) {
3773 id = AV_CODEC_ID_VP5;
3775 } else if (!strcmp (mimetype, "video/x-vp6")) {
3776 id = AV_CODEC_ID_VP6;
3778 } else if (!strcmp (mimetype, "video/x-vp6-flash")) {
3779 id = AV_CODEC_ID_VP6F;
3781 } else if (!strcmp (mimetype, "video/x-vp6-alpha")) {
3782 id = AV_CODEC_ID_VP6A;
3784 } else if (!strcmp (mimetype, "video/x-vp8")) {
3785 id = AV_CODEC_ID_VP8;
3787 } else if (!strcmp (mimetype, "video/x-vp9")) {
3788 id = AV_CODEC_ID_VP9;
3790 } else if (!strcmp (mimetype, "video/x-flash-screen")) {
3791 id = AV_CODEC_ID_FLASHSV;
3793 } else if (!strcmp (mimetype, "video/x-indeo")) {
3794 gint indeoversion = 0;
3796 if (gst_structure_get_int (structure, "indeoversion", &indeoversion)) {
3797 switch (indeoversion) {
3799 id = AV_CODEC_ID_INDEO5;
3802 id = AV_CODEC_ID_INDEO4;
3805 id = AV_CODEC_ID_INDEO3;
3808 id = AV_CODEC_ID_INDEO2;
3811 if (id != AV_CODEC_ID_NONE)
3814 } else if (!strcmp (mimetype, "video/x-divx")) {
3815 gint divxversion = 0;
3817 if (gst_structure_get_int (structure, "divxversion", &divxversion)) {
3818 switch (divxversion) {
3820 id = AV_CODEC_ID_MSMPEG4V3;
3824 id = AV_CODEC_ID_MPEG4;
3828 if (id != AV_CODEC_ID_NONE)
3830 } else if (!strcmp (mimetype, "video/x-ffv")) {
3831 gint ffvversion = 0;
3833 if (gst_structure_get_int (structure, "ffvversion", &ffvversion) &&
3835 id = AV_CODEC_ID_FFV1;
3838 } else if (!strcmp (mimetype, "video/x-apple-intermediate-codec")) {
3839 id = AV_CODEC_ID_AIC;
3841 } else if (!strcmp (mimetype, "audio/x-adpcm")) {
3842 const gchar *layout;
3844 layout = gst_structure_get_string (structure, "layout");
3845 if (layout == NULL) {
3847 } else if (!strcmp (layout, "quicktime")) {
3848 id = AV_CODEC_ID_ADPCM_IMA_QT;
3849 } else if (!strcmp (layout, "microsoft")) {
3850 id = AV_CODEC_ID_ADPCM_MS;
3851 } else if (!strcmp (layout, "dvi")) {
3852 id = AV_CODEC_ID_ADPCM_IMA_WAV;
3853 } else if (!strcmp (layout, "4xm")) {
3854 id = AV_CODEC_ID_ADPCM_4XM;
3855 } else if (!strcmp (layout, "smjpeg")) {
3856 id = AV_CODEC_ID_ADPCM_IMA_SMJPEG;
3857 } else if (!strcmp (layout, "dk3")) {
3858 id = AV_CODEC_ID_ADPCM_IMA_DK3;
3859 } else if (!strcmp (layout, "dk4")) {
3860 id = AV_CODEC_ID_ADPCM_IMA_DK4;
3861 } else if (!strcmp (layout, "westwood")) {
3862 id = AV_CODEC_ID_ADPCM_IMA_WS;
3863 } else if (!strcmp (layout, "iss")) {
3864 id = AV_CODEC_ID_ADPCM_IMA_ISS;
3865 } else if (!strcmp (layout, "xa")) {
3866 id = AV_CODEC_ID_ADPCM_XA;
3867 } else if (!strcmp (layout, "adx")) {
3868 id = AV_CODEC_ID_ADPCM_ADX;
3869 } else if (!strcmp (layout, "ea")) {
3870 id = AV_CODEC_ID_ADPCM_EA;
3871 } else if (!strcmp (layout, "g726")) {
3872 id = AV_CODEC_ID_ADPCM_G726;
3873 } else if (!strcmp (layout, "g721")) {
3874 id = AV_CODEC_ID_ADPCM_G726;
3875 } else if (!strcmp (layout, "ct")) {
3876 id = AV_CODEC_ID_ADPCM_CT;
3877 } else if (!strcmp (layout, "swf")) {
3878 id = AV_CODEC_ID_ADPCM_SWF;
3879 } else if (!strcmp (layout, "yamaha")) {
3880 id = AV_CODEC_ID_ADPCM_YAMAHA;
3881 } else if (!strcmp (layout, "sbpro2")) {
3882 id = AV_CODEC_ID_ADPCM_SBPRO_2;
3883 } else if (!strcmp (layout, "sbpro3")) {
3884 id = AV_CODEC_ID_ADPCM_SBPRO_3;
3885 } else if (!strcmp (layout, "sbpro4")) {
3886 id = AV_CODEC_ID_ADPCM_SBPRO_4;
3888 if (id != AV_CODEC_ID_NONE)
3890 } else if (!strcmp (mimetype, "video/x-4xm")) {
3891 id = AV_CODEC_ID_4XM;
3893 } else if (!strcmp (mimetype, "audio/x-dpcm")) {
3894 const gchar *layout;
3896 layout = gst_structure_get_string (structure, "layout");
3899 } else if (!strcmp (layout, "roq")) {
3900 id = AV_CODEC_ID_ROQ_DPCM;
3901 } else if (!strcmp (layout, "interplay")) {
3902 id = AV_CODEC_ID_INTERPLAY_DPCM;
3903 } else if (!strcmp (layout, "xan")) {
3904 id = AV_CODEC_ID_XAN_DPCM;
3905 } else if (!strcmp (layout, "sol")) {
3906 id = AV_CODEC_ID_SOL_DPCM;
3908 if (id != AV_CODEC_ID_NONE)
3910 } else if (!strcmp (mimetype, "audio/x-flac")) {
3911 id = AV_CODEC_ID_FLAC;
3913 } else if (!strcmp (mimetype, "audio/x-shorten")) {
3914 id = AV_CODEC_ID_SHORTEN;
3916 } else if (!strcmp (mimetype, "audio/x-alac")) {
3917 id = AV_CODEC_ID_ALAC;
3919 } else if (!strcmp (mimetype, "video/x-cinepak")) {
3920 id = AV_CODEC_ID_CINEPAK;
3922 } else if (!strcmp (mimetype, "video/x-pn-realvideo")) {
3925 if (gst_structure_get_int (structure, "rmversion", &rmversion)) {
3926 switch (rmversion) {
3928 id = AV_CODEC_ID_RV10;
3931 id = AV_CODEC_ID_RV20;
3934 id = AV_CODEC_ID_RV30;
3937 id = AV_CODEC_ID_RV40;
3941 if (id != AV_CODEC_ID_NONE)
3943 } else if (!strcmp (mimetype, "audio/x-sipro")) {
3944 id = AV_CODEC_ID_SIPR;
3946 } else if (!strcmp (mimetype, "audio/x-pn-realaudio")) {
3949 if (gst_structure_get_int (structure, "raversion", &raversion)) {
3950 switch (raversion) {
3952 id = AV_CODEC_ID_RA_144;
3955 id = AV_CODEC_ID_RA_288;
3958 id = AV_CODEC_ID_COOK;
3962 if (id != AV_CODEC_ID_NONE)
3964 } else if (!strcmp (mimetype, "video/x-rle")) {
3965 const gchar *layout;
3967 if ((layout = gst_structure_get_string (structure, "layout"))) {
3968 if (!strcmp (layout, "microsoft")) {
3969 id = AV_CODEC_ID_MSRLE;
3973 } else if (!strcmp (mimetype, "video/x-xan")) {
3976 if ((gst_structure_get_int (structure, "wcversion", &wcversion))) {
3977 switch (wcversion) {
3979 id = AV_CODEC_ID_XAN_WC3;
3983 id = AV_CODEC_ID_XAN_WC4;
3990 } else if (!strcmp (mimetype, "audio/AMR")) {
3992 id = AV_CODEC_ID_AMR_NB;
3993 } else if (!strcmp (mimetype, "audio/AMR-WB")) {
3994 id = AV_CODEC_ID_AMR_WB;
3996 } else if (!strcmp (mimetype, "audio/qcelp")) {
3997 id = AV_CODEC_ID_QCELP;
3999 } else if (!strcmp (mimetype, "video/x-h264")) {
4000 id = AV_CODEC_ID_H264;
4002 } else if (!strcmp (mimetype, "video/x-h265")) {
4003 id = AV_CODEC_ID_HEVC;
4005 } else if (!strcmp (mimetype, "video/x-flash-video")) {
4006 gint flvversion = 0;
4008 if ((gst_structure_get_int (structure, "flvversion", &flvversion))) {
4009 switch (flvversion) {
4011 id = AV_CODEC_ID_FLV1;
4019 } else if (!strcmp (mimetype, "audio/x-nellymoser")) {
4020 id = AV_CODEC_ID_NELLYMOSER;
4022 } else if (!strncmp (mimetype, "audio/x-gst-av-", 15)) {
4026 if (strlen (mimetype) <= 30 &&
4027 sscanf (mimetype, "audio/x-gst-av-%s", ext) == 1) {
4028 if ((codec = avcodec_find_decoder_by_name (ext)) ||
4029 (codec = avcodec_find_encoder_by_name (ext))) {
4034 } else if (!strncmp (mimetype, "video/x-gst-av-", 15)) {
4038 if (strlen (mimetype) <= 30 &&
4039 sscanf (mimetype, "video/x-gst-av-%s", ext) == 1) {
4040 if ((codec = avcodec_find_decoder_by_name (ext)) ||
4041 (codec = avcodec_find_encoder_by_name (ext))) {
4048 if (context != NULL) {
4049 if (video == TRUE) {
4050 context->codec_type = AVMEDIA_TYPE_VIDEO;
4051 } else if (audio == TRUE) {
4052 context->codec_type = AVMEDIA_TYPE_AUDIO;
4054 context->codec_type = AVMEDIA_TYPE_UNKNOWN;
4056 context->codec_id = id;
4057 gst_ffmpeg_caps_with_codecid (id, context->codec_type, caps, context);
4060 if (id != AV_CODEC_ID_NONE) {
4061 GST_DEBUG ("The id=%d belongs to the caps %" GST_PTR_FORMAT, id, caps);
4063 GST_WARNING ("Couldn't figure out the id for caps %" GST_PTR_FORMAT, caps);