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_channel_positions_to_layout (GstAudioChannelPosition * pos,
75 gint channels_found = 0;
80 for (i = 0; i < channels; i++) {
81 for (j = 0; j < G_N_ELEMENTS (_ff_to_gst_layout); j++) {
82 if (_ff_to_gst_layout[j].gst == pos[i]) {
83 ret |= _ff_to_gst_layout[j].ff;
90 if (channels_found != channels)
96 gst_ffmpeg_channel_layout_to_gst (guint64 channel_layout, gint channels,
97 GstAudioChannelPosition * pos)
100 gboolean none_layout = FALSE;
102 if (channel_layout == 0) {
103 nchannels = channels;
108 for (i = 0; i < 64; i++) {
109 if ((channel_layout & (G_GUINT64_CONSTANT (1) << i)) != 0) {
114 if (nchannels != channels) {
115 GST_ERROR ("Number of channels is different (%u != %u)", channels,
117 nchannels = channels;
121 for (i = 0, j = 0; i < G_N_ELEMENTS (_ff_to_gst_layout); i++) {
122 if ((channel_layout & _ff_to_gst_layout[i].ff) != 0) {
123 pos[j++] = _ff_to_gst_layout[i].gst;
125 if (_ff_to_gst_layout[i].gst == GST_AUDIO_CHANNEL_POSITION_NONE)
130 if (j != nchannels) {
132 ("Unknown channels in channel layout - assuming NONE layout");
139 && !gst_audio_check_valid_channel_positions (pos, nchannels, FALSE)) {
140 GST_ERROR ("Invalid channel layout %" G_GUINT64_FORMAT
141 " - assuming NONE layout", channel_layout);
146 if (nchannels == 1) {
147 pos[0] = GST_AUDIO_CHANNEL_POSITION_MONO;
148 } else if (nchannels == 2) {
149 pos[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT;
150 pos[1] = GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT;
154 for (i = 0; i < nchannels; i++)
155 pos[i] = GST_AUDIO_CHANNEL_POSITION_NONE;
163 gst_ffmpeg_video_set_pix_fmts (GstCaps * caps, const enum AVPixelFormat *fmts)
167 GstVideoFormat format;
169 if (!fmts || fmts[0] == -1) {
172 g_value_init (&va, GST_TYPE_LIST);
173 g_value_init (&v, G_TYPE_STRING);
174 for (i = 0; i <= PIX_FMT_NB; i++) {
175 format = gst_ffmpeg_pixfmt_to_videoformat (i);
176 if (format == GST_VIDEO_FORMAT_UNKNOWN)
178 g_value_set_string (&v, gst_video_format_to_string (format));
179 gst_value_list_append_value (&va, &v);
181 gst_caps_set_value (caps, "format", &va);
187 /* Only a single format */
188 g_value_init (&va, GST_TYPE_LIST);
189 g_value_init (&v, G_TYPE_STRING);
190 while (*fmts != -1) {
191 format = gst_ffmpeg_pixfmt_to_videoformat (*fmts);
192 if (format != GST_VIDEO_FORMAT_UNKNOWN) {
193 g_value_set_string (&v, gst_video_format_to_string (format));
194 /* Only append values we don't have yet */
195 if (gst_value_list_get_size (&va) == 0
196 || !gst_value_can_intersect (&v, &va))
197 gst_value_list_append_value (&va, &v);
201 if (gst_value_list_get_size (&va) == 1) {
202 /* The single value is still in v */
203 gst_caps_set_value (caps, "format", &v);
204 } else if (gst_value_list_get_size (&va) > 1) {
205 gst_caps_set_value (caps, "format", &va);
211 /* this macro makes a caps width fixed or unfixed width/height
212 * properties depending on whether we've got a context.
214 * See below for why we use this.
216 * We should actually do this stuff at the end, like in riff-media.c,
217 * but I'm too lazy today. Maybe later.
220 gst_ff_vid_caps_new (AVCodecContext * context, AVCodec * codec,
221 enum CodecID codec_id, gboolean encode, const char *mimetype,
222 const char *fieldname, ...)
224 GstCaps *caps = NULL;
228 GST_LOG ("context:%p, codec_id:%d, mimetype:%s", context, codec_id, mimetype);
230 /* fixed, non probing context */
231 if (context != NULL && context->width != -1) {
234 caps = gst_caps_new_simple (mimetype,
235 "width", G_TYPE_INT, context->width,
236 "height", G_TYPE_INT, context->height, NULL);
238 num = context->time_base.den / context->ticks_per_frame;
239 denom = context->time_base.num;
242 GST_LOG ("invalid framerate: %d/0, -> %d/1", num, num);
245 if (gst_util_fraction_compare (num, denom, 1000, 1) > 0) {
246 GST_LOG ("excessive framerate: %d/%d, -> 0/1", num, denom);
250 GST_LOG ("setting framerate: %d/%d", num, denom);
251 gst_caps_set_simple (caps,
252 "framerate", GST_TYPE_FRACTION, num, denom, NULL);
254 /* so we are after restricted caps in this case */
256 case AV_CODEC_ID_H261:
258 caps = gst_caps_new_simple (mimetype,
259 "width", G_TYPE_INT, 352,
260 "height", G_TYPE_INT, 288,
261 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
262 gst_caps_append (caps, gst_caps_new_simple (mimetype,
263 "width", G_TYPE_INT, 176,
264 "height", G_TYPE_INT, 144,
265 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL));
268 case AV_CODEC_ID_H263:
270 /* 128x96, 176x144, 352x288, 704x576, and 1408x1152. slightly reordered
271 * because we want automatic negotiation to go as close to 320x240 as
273 const static gint widths[] = { 352, 704, 176, 1408, 128 };
274 const static gint heights[] = { 288, 576, 144, 1152, 96 };
276 gint n_sizes = G_N_ELEMENTS (widths);
278 caps = gst_caps_new_empty ();
279 for (i = 0; i < n_sizes; i++) {
280 temp = gst_caps_new_simple (mimetype,
281 "width", G_TYPE_INT, widths[i],
282 "height", G_TYPE_INT, heights[i],
283 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
285 gst_caps_append (caps, temp);
289 case AV_CODEC_ID_DVVIDEO:
296 gint framerate_n, framerate_d;
299 "Y41B", 720, 480, 8, 9, 30000, 1001}, {
300 "Y41B", 720, 480, 32, 27, 30000, 1001}, {
301 "Y42B", 720, 480, 8, 9, 30000, 1001}, {
302 "Y42B", 720, 480, 32, 27, 30000, 1001}, {
303 "I420", 720, 576, 16, 15, 25, 1}, {
304 "I420", 720, 576, 64, 45, 25, 1}, {
305 "Y41B", 720, 576, 16, 15, 25, 1}, {
306 "Y41B", 720, 576, 64, 45, 25, 1}, {
307 "Y42B", 720, 576, 16, 15, 25, 1}, {
308 "Y42B", 720, 576, 64, 45, 25, 1}, {
309 "Y42B", 1280, 1080, 1, 1, 30000, 1001}, {
310 "Y42B", 1280, 1080, 3, 2, 30000, 1001}, {
311 "Y42B", 1440, 1080, 1, 1, 25, 1}, {
312 "Y42B", 1440, 1080, 4, 3, 25, 1}, {
313 "Y42B", 960, 720, 1, 1, 60000, 1001}, {
314 "Y42B", 960, 720, 4, 3, 60000, 1001}, {
315 "Y42B", 960, 720, 1, 1, 50, 1}, {
316 "Y42B", 960, 720, 4, 3, 50, 1},};
318 gint n_sizes = G_N_ELEMENTS (profiles);
320 if (strcmp (mimetype, "video/x-raw") == 0) {
321 caps = gst_caps_new_empty ();
322 for (i = 0; i < n_sizes; i++) {
323 temp = gst_caps_new_simple (mimetype,
324 "format", G_TYPE_STRING, profiles[i].csp,
325 "width", G_TYPE_INT, profiles[i].width,
326 "height", G_TYPE_INT, profiles[i].height,
327 "framerate", GST_TYPE_FRACTION, profiles[i].framerate_n,
328 profiles[i].framerate_d, "pixel-aspect-ratio",
329 GST_TYPE_FRACTION, profiles[i].par_n, profiles[i].par_d, NULL);
331 gst_caps_append (caps, temp);
334 caps = gst_caps_new_empty ();
335 for (i = 0; i < n_sizes; i++) {
336 temp = gst_caps_new_simple (mimetype,
337 "width", G_TYPE_INT, profiles[i].width,
338 "height", G_TYPE_INT, profiles[i].height,
339 "framerate", GST_TYPE_FRACTION, profiles[i].framerate_n,
340 profiles[i].framerate_d, "pixel-aspect-ratio",
341 GST_TYPE_FRACTION, profiles[i].par_n, profiles[i].par_d, NULL);
343 gst_caps_append (caps, temp);
348 case AV_CODEC_ID_DNXHD:
350 caps = gst_caps_new_simple (mimetype,
351 "width", G_TYPE_INT, 1920,
352 "height", G_TYPE_INT, 1080,
353 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
354 gst_caps_append (caps, gst_caps_new_simple (mimetype,
355 "width", G_TYPE_INT, 1280,
356 "height", G_TYPE_INT, 720,
357 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL));
362 if (codec && codec->supported_framerates
363 && codec->supported_framerates[0].num != 0
364 && codec->supported_framerates[0].den != 0) {
367 const AVRational *rates = codec->supported_framerates;
369 if (rates[1].num == 0 && rates[1].den == 0) {
371 gst_caps_new_simple (mimetype, "framerate", GST_TYPE_FRACTION,
372 rates[0].num, rates[0].den, NULL);
374 g_value_init (&va, GST_TYPE_LIST);
375 g_value_init (&v, GST_TYPE_FRACTION);
377 while (rates->num != 0 && rates->den != 0) {
378 gst_value_set_fraction (&v, rates->num, rates->den);
379 gst_value_list_append_value (&va, &v);
383 caps = gst_caps_new_simple (mimetype, NULL, NULL, NULL);
384 gst_caps_set_value (caps, "framerate", &va);
390 caps = gst_caps_new_empty_simple (mimetype);
398 /* no fixed caps or special restrictions applied;
399 * default unfixed setting */
401 GST_DEBUG ("Creating default caps");
402 caps = gst_caps_new_empty_simple (mimetype);
405 va_start (var_args, fieldname);
406 gst_caps_set_simple_valist (caps, fieldname, var_args);
413 get_nbits_set (guint64 n)
418 for (i = 0; i < 64; i++) {
419 if ((n & (G_GUINT64_CONSTANT (1) << i)))
427 gst_ffmpeg_audio_set_sample_fmts (GstCaps * caps,
428 const enum AVSampleFormat *fmts)
432 GstAudioFormat format;
434 if (!fmts || fmts[0] == -1) {
437 g_value_init (&va, GST_TYPE_LIST);
438 g_value_init (&v, G_TYPE_STRING);
439 for (i = 0; i <= AV_SAMPLE_FMT_DBL; i++) {
440 format = gst_ffmpeg_smpfmt_to_audioformat (i);
441 if (format == GST_AUDIO_FORMAT_UNKNOWN)
443 g_value_set_string (&v, gst_audio_format_to_string (format));
444 gst_value_list_append_value (&va, &v);
446 gst_caps_set_value (caps, "format", &va);
452 g_value_init (&va, GST_TYPE_LIST);
453 g_value_init (&v, G_TYPE_STRING);
454 while (*fmts != -1) {
455 format = gst_ffmpeg_smpfmt_to_audioformat (*fmts);
456 if (format != GST_AUDIO_FORMAT_UNKNOWN) {
457 g_value_set_string (&v, gst_audio_format_to_string (format));
458 /* Only append values we don't have yet */
459 if (gst_value_list_get_size (&va) == 0
460 || !gst_value_can_intersect (&v, &va))
461 gst_value_list_append_value (&va, &v);
465 if (gst_value_list_get_size (&va) == 1) {
466 /* The single value is still in v */
467 gst_caps_set_value (caps, "format", &v);
468 } else if (gst_value_list_get_size (&va) > 1) {
469 gst_caps_set_value (caps, "format", &va);
475 /* same for audio - now with channels/sample rate
478 gst_ff_aud_caps_new (AVCodecContext * context, AVCodec * codec,
479 enum CodecID codec_id, gboolean encode, const char *mimetype,
480 const char *fieldname, ...)
482 GstCaps *caps = NULL;
486 /* fixed, non-probing context */
487 if (context != NULL && context->channels != -1) {
488 GstAudioChannelPosition pos[64];
490 caps = gst_caps_new_simple (mimetype,
491 "rate", G_TYPE_INT, context->sample_rate,
492 "channels", G_TYPE_INT, context->channels, NULL);
494 if (gst_ffmpeg_channel_layout_to_gst (context->channel_layout,
495 context->channels, pos)) {
498 if (gst_audio_channel_positions_to_mask (pos, context->channels, FALSE,
500 gst_caps_set_simple (caps, "channel-mask", GST_TYPE_BITMASK, mask,
505 gint maxchannels = 2;
506 const gint *rates = NULL;
509 /* so we must be after restricted caps in this case */
511 case AV_CODEC_ID_AAC:
512 case AV_CODEC_ID_AAC_LATM:
513 case AV_CODEC_ID_DTS:
516 case AV_CODEC_ID_MP2:
518 const static gint l_rates[] =
519 { 48000, 44100, 32000, 24000, 22050, 16000 };
520 n_rates = G_N_ELEMENTS (l_rates);
524 case AV_CODEC_ID_EAC3:
525 case AV_CODEC_ID_AC3:
527 const static gint l_rates[] = { 48000, 44100, 32000 };
529 n_rates = G_N_ELEMENTS (l_rates);
533 case AV_CODEC_ID_ADPCM_G722:
535 const static gint l_rates[] = { 16000 };
536 n_rates = G_N_ELEMENTS (l_rates);
541 case AV_CODEC_ID_ADPCM_G726:
543 const static gint l_rates[] = { 8000 };
544 n_rates = G_N_ELEMENTS (l_rates);
549 case AV_CODEC_ID_ADPCM_SWF:
551 const static gint l_rates[] = { 11025, 22050, 44100 };
552 n_rates = G_N_ELEMENTS (l_rates);
556 case AV_CODEC_ID_ROQ_DPCM:
558 const static gint l_rates[] = { 22050 };
559 n_rates = G_N_ELEMENTS (l_rates);
563 case AV_CODEC_ID_AMR_NB:
565 const static gint l_rates[] = { 8000 };
567 n_rates = G_N_ELEMENTS (l_rates);
571 case AV_CODEC_ID_AMR_WB:
573 const static gint l_rates[] = { 16000 };
575 n_rates = G_N_ELEMENTS (l_rates);
583 /* regardless of encode/decode, open up channels if applicable */
584 /* Until decoders/encoders expose the maximum number of channels
585 * they support, we whitelist them here. */
587 case AV_CODEC_ID_WMAPRO:
588 case AV_CODEC_ID_TRUEHD:
595 if (codec && codec->channel_layouts) {
596 const uint64_t *layouts = codec->channel_layouts;
597 GstAudioChannelPosition pos[64];
599 caps = gst_caps_new_empty ();
601 gint nbits_set = get_nbits_set (*layouts);
603 if (gst_ffmpeg_channel_layout_to_gst (*layouts, nbits_set, pos)) {
606 if (gst_audio_channel_positions_to_mask (pos, nbits_set, FALSE,
609 gst_caps_new_simple (mimetype, "channel-mask", GST_TYPE_BITMASK,
611 "channels", G_TYPE_INT, nbits_set, NULL);
613 gst_caps_append (caps, tmp);
619 if (maxchannels == 1)
620 caps = gst_caps_new_simple (mimetype,
621 "channels", G_TYPE_INT, maxchannels, NULL);
623 caps = gst_caps_new_simple (mimetype,
624 "channels", GST_TYPE_INT_RANGE, 1, maxchannels, NULL);
628 GValue list = { 0, };
630 g_value_init (&list, GST_TYPE_LIST);
631 for (i = 0; i < n_rates; i++) {
634 g_value_init (&v, G_TYPE_INT);
635 g_value_set_int (&v, rates[i]);
636 gst_value_list_append_value (&list, &v);
639 gst_caps_set_value (caps, "rate", &list);
640 g_value_unset (&list);
641 } else if (codec && codec->supported_samplerates
642 && codec->supported_samplerates[0]) {
646 if (!codec->supported_samplerates[1]) {
647 gst_caps_set_simple (caps, "rate", G_TYPE_INT,
648 codec->supported_samplerates[0], NULL);
650 const int *rates = codec->supported_samplerates;
652 g_value_init (&va, GST_TYPE_LIST);
653 g_value_init (&v, G_TYPE_INT);
656 g_value_set_int (&v, *rates);
657 gst_value_list_append_value (&va, &v);
660 gst_caps_set_value (caps, "rate", &va);
665 gst_caps_set_simple (caps, "rate", GST_TYPE_INT_RANGE, 4000, 96000, NULL);
668 caps = gst_caps_new_empty_simple (mimetype);
671 va_start (var_args, fieldname);
672 gst_caps_set_simple_valist (caps, fieldname, var_args);
678 /* Convert a FFMPEG codec ID and optional AVCodecContext
679 * to a GstCaps. If the context is ommitted, no fixed values
680 * for video/audio size will be included in the GstCaps
682 * CodecID is primarily meant for compressed data GstCaps!
684 * encode is a special parameter. gstffmpegdec will say
685 * FALSE, gstffmpegenc will say TRUE. The output caps
686 * depends on this, in such a way that it will be very
687 * specific, defined, fixed and correct caps for encoders,
688 * yet very wide, "forgiving" caps for decoders. Example
689 * for mp3: decode: audio/mpeg,mpegversion=1,layer=[1-3]
690 * but encode: audio/mpeg,mpegversion=1,layer=3,bitrate=x,
695 gst_ffmpeg_codecid_to_caps (enum CodecID codec_id,
696 AVCodecContext * context, gboolean encode)
698 GstCaps *caps = NULL;
699 gboolean buildcaps = FALSE;
701 GST_LOG ("codec_id:%d, context:%p, encode:%d", codec_id, context, encode);
704 case AV_CODEC_ID_MPEG1VIDEO:
706 caps = gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
707 "mpegversion", G_TYPE_INT, 1,
708 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
711 case AV_CODEC_ID_MPEG2VIDEO:
715 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
716 "mpegversion", G_TYPE_INT, 2, "systemstream", G_TYPE_BOOLEAN, FALSE,
719 /* decode both MPEG-1 and MPEG-2; width/height/fps are all in
720 * the MPEG video stream headers, so may be omitted from caps. */
721 caps = gst_caps_new_simple ("video/mpeg",
722 "mpegversion", GST_TYPE_INT_RANGE, 1, 2,
723 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
727 case AV_CODEC_ID_MPEG2VIDEO_XVMC:
728 /* this is a special ID - don't need it in GStreamer, I think */
731 case AV_CODEC_ID_H263:
734 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
735 "video/x-h263", "variant", G_TYPE_STRING, "itu", "h263version",
736 G_TYPE_STRING, "h263", NULL);
738 /* don't pass codec_id, we can decode other variants with the H263
739 * decoder that don't have specific size requirements
742 gst_ff_vid_caps_new (context, NULL, AV_CODEC_ID_NONE, encode,
743 "video/x-h263", "variant", G_TYPE_STRING, "itu", NULL);
747 case AV_CODEC_ID_H263P:
749 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h263",
750 "variant", G_TYPE_STRING, "itu", "h263version", G_TYPE_STRING,
752 if (encode && context) {
754 gst_caps_set_simple (caps,
755 "annex-f", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_4MV,
756 "annex-j", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_LOOP_FILTER,
757 "annex-i", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_AC_PRED,
758 "annex-t", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_AC_PRED,
763 case AV_CODEC_ID_H263I:
765 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
766 "video/x-intel-h263", "variant", G_TYPE_STRING, "intel", NULL);
769 case AV_CODEC_ID_H261:
771 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h261",
775 case AV_CODEC_ID_RV10:
776 case AV_CODEC_ID_RV20:
777 case AV_CODEC_ID_RV30:
778 case AV_CODEC_ID_RV40:
783 case AV_CODEC_ID_RV40:
786 case AV_CODEC_ID_RV30:
789 case AV_CODEC_ID_RV20:
797 /* FIXME: context->sub_id must be filled in during decoding */
799 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
800 "video/x-pn-realvideo", "rmversion", G_TYPE_INT, version, NULL);
802 gst_caps_set_simple (caps, "format", G_TYPE_INT, context->sub_id, NULL);
803 if (context->extradata_size >= 8) {
804 gst_caps_set_simple (caps,
805 "subformat", G_TYPE_INT, GST_READ_UINT32_BE (context->extradata),
812 case AV_CODEC_ID_MP1:
814 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
815 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 1, NULL);
818 case AV_CODEC_ID_MP2:
820 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
821 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 2, NULL);
824 case AV_CODEC_ID_MP3:
828 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
829 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 3, NULL);
831 /* Decodes MPEG-1 layer 1/2/3. Samplerate, channels et al are
832 * in the MPEG audio header, so may be omitted from caps. */
833 caps = gst_caps_new_simple ("audio/mpeg",
834 "mpegversion", G_TYPE_INT, 1,
835 "layer", GST_TYPE_INT_RANGE, 1, 3, NULL);
839 case AV_CODEC_ID_MUSEPACK7:
841 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
842 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 7,
846 case AV_CODEC_ID_MUSEPACK8:
848 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
849 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 8,
853 case AV_CODEC_ID_AC3:
856 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-ac3",
860 case AV_CODEC_ID_EAC3:
863 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-eac3",
867 case AV_CODEC_ID_TRUEHD:
869 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
870 "audio/x-true-hd", NULL);
873 case AV_CODEC_ID_ATRAC1:
875 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
876 "audio/x-vnd.sony.atrac1", NULL);
879 case AV_CODEC_ID_ATRAC3:
881 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
882 "audio/x-vnd.sony.atrac3", NULL);
885 case AV_CODEC_ID_DTS:
887 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dts",
891 case AV_CODEC_ID_APE:
893 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
894 "audio/x-ffmpeg-parsed-ape", NULL);
896 gst_caps_set_simple (caps,
897 "depth", G_TYPE_INT, context->bits_per_coded_sample, NULL);
901 case AV_CODEC_ID_MLP:
903 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mlp",
907 case AV_CODEC_ID_IMC:
909 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-imc",
913 /* MJPEG is normal JPEG, Motion-JPEG and Quicktime MJPEG-A. MJPEGB
914 * is Quicktime's MJPEG-B. LJPEG is lossless JPEG. I don't know what
915 * sp5x is, but it's apparently something JPEG... We don't separate
916 * between those in GStreamer. Should we (at least between MJPEG,
917 * MJPEG-B and sp5x decoding...)? */
918 case AV_CODEC_ID_MJPEG:
919 case AV_CODEC_ID_LJPEG:
921 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/jpeg",
925 case AV_CODEC_ID_SP5X:
927 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/sp5x",
931 case AV_CODEC_ID_MJPEGB:
933 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
934 "video/x-mjpeg-b", NULL);
937 case AV_CODEC_ID_MPEG4:
938 if (encode && context != NULL) {
939 /* I'm not exactly sure what ffmpeg outputs... ffmpeg itself uses
940 * the AVI fourcc 'DIVX', but 'mp4v' for Quicktime... */
941 switch (context->codec_tag) {
942 case GST_MAKE_FOURCC ('D', 'I', 'V', 'X'):
944 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
945 "video/x-divx", "divxversion", G_TYPE_INT, 5, NULL);
947 case GST_MAKE_FOURCC ('m', 'p', '4', 'v'):
951 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
952 "video/mpeg", "systemstream", G_TYPE_BOOLEAN, FALSE,
953 "mpegversion", G_TYPE_INT, 4, NULL);
957 /* The trick here is to separate xvid, divx, mpeg4, 3ivx et al */
959 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
960 "mpegversion", G_TYPE_INT, 4, "systemstream", G_TYPE_BOOLEAN, FALSE,
963 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
964 encode, "video/x-divx", "divxversion", G_TYPE_INT, 5, NULL));
966 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
967 encode, "video/x-divx", "divxversion", GST_TYPE_INT_RANGE, 4,
969 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
970 encode, "video/x-xvid", NULL));
971 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
972 encode, "video/x-3ivx", NULL));
977 case AV_CODEC_ID_RAWVIDEO:
979 gst_ffmpeg_codectype_to_video_caps (context, codec_id, encode, NULL);
982 case AV_CODEC_ID_MSMPEG4V1:
983 case AV_CODEC_ID_MSMPEG4V2:
984 case AV_CODEC_ID_MSMPEG4V3:
986 gint version = 41 + codec_id - AV_CODEC_ID_MSMPEG4V1;
988 /* encode-FIXME: bitrate */
990 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
991 "video/x-msmpeg", "msmpegversion", G_TYPE_INT, version, NULL);
992 if (!encode && codec_id == AV_CODEC_ID_MSMPEG4V3) {
993 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
994 encode, "video/x-divx", "divxversion", G_TYPE_INT, 3, NULL));
999 case AV_CODEC_ID_WMV1:
1000 case AV_CODEC_ID_WMV2:
1002 gint version = (codec_id == AV_CODEC_ID_WMV1) ? 1 : 2;
1005 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1006 "wmvversion", G_TYPE_INT, version, NULL);
1010 case AV_CODEC_ID_FLV1:
1012 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1013 "video/x-flash-video", "flvversion", G_TYPE_INT, 1, NULL);
1016 case AV_CODEC_ID_SVQ1:
1018 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-svq",
1019 "svqversion", G_TYPE_INT, 1, NULL);
1022 case AV_CODEC_ID_SVQ3:
1024 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-svq",
1025 "svqversion", G_TYPE_INT, 3, NULL);
1028 case AV_CODEC_ID_DVAUDIO:
1030 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dv",
1034 case AV_CODEC_ID_DVVIDEO:
1036 if (encode && context) {
1037 const gchar *format;
1039 switch (context->pix_fmt) {
1040 case PIX_FMT_YUYV422:
1043 case PIX_FMT_YUV420P:
1046 case PIX_FMT_YUVA420P:
1049 case PIX_FMT_YUV411P:
1052 case PIX_FMT_YUV422P:
1055 case PIX_FMT_YUV410P:
1060 ("Couldnt' find format for pixfmt %d, defaulting to I420",
1066 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dv",
1067 "systemstream", G_TYPE_BOOLEAN, FALSE, "format", G_TYPE_STRING,
1071 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dv",
1072 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
1077 case AV_CODEC_ID_WMAV1:
1078 case AV_CODEC_ID_WMAV2:
1080 gint version = (codec_id == AV_CODEC_ID_WMAV1) ? 1 : 2;
1084 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1085 "wmaversion", G_TYPE_INT, version, "block_align", G_TYPE_INT,
1086 context->block_align, "bitrate", G_TYPE_INT, context->bit_rate,
1090 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1091 "wmaversion", G_TYPE_INT, version, "block_align",
1092 GST_TYPE_INT_RANGE, 0, G_MAXINT, "bitrate", GST_TYPE_INT_RANGE, 0,
1097 case AV_CODEC_ID_WMAPRO:
1100 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1101 "wmaversion", G_TYPE_INT, 3, NULL);
1104 case AV_CODEC_ID_WMALOSSLESS:
1106 /* libav only supports a depth of 16 at the moment */
1108 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1109 "wmaversion", G_TYPE_INT, 4, "depth", G_TYPE_INT, 16, NULL);
1112 case AV_CODEC_ID_WMAVOICE:
1115 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wms",
1120 case AV_CODEC_ID_MACE3:
1121 case AV_CODEC_ID_MACE6:
1123 gint version = (codec_id == AV_CODEC_ID_MACE3) ? 3 : 6;
1126 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mace",
1127 "maceversion", G_TYPE_INT, version, NULL);
1131 case AV_CODEC_ID_HUFFYUV:
1133 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1134 "video/x-huffyuv", NULL);
1136 gst_caps_set_simple (caps,
1137 "bpp", G_TYPE_INT, context->bits_per_coded_sample, NULL);
1141 case AV_CODEC_ID_CYUV:
1143 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1144 "video/x-compressed-yuv", NULL);
1147 case AV_CODEC_ID_H264:
1149 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h264",
1150 "alignment", G_TYPE_STRING, "au", NULL);
1152 GValue arr = { 0, };
1153 GValue item = { 0, };
1154 g_value_init (&arr, GST_TYPE_LIST);
1155 g_value_init (&item, G_TYPE_STRING);
1156 g_value_set_string (&item, "avc");
1157 gst_value_list_append_value (&arr, &item);
1158 g_value_set_string (&item, "byte-stream");
1159 gst_value_list_append_value (&arr, &item);
1160 g_value_unset (&item);
1161 gst_caps_set_value (caps, "stream-format", &arr);
1162 g_value_unset (&arr);
1166 case AV_CODEC_ID_INDEO5:
1168 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1169 "indeoversion", G_TYPE_INT, 5, NULL);
1172 case AV_CODEC_ID_INDEO4:
1174 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1175 "indeoversion", G_TYPE_INT, 4, NULL);
1178 case AV_CODEC_ID_INDEO3:
1180 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1181 "indeoversion", G_TYPE_INT, 3, NULL);
1184 case AV_CODEC_ID_INDEO2:
1186 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1187 "indeoversion", G_TYPE_INT, 2, NULL);
1190 case AV_CODEC_ID_FLASHSV:
1192 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1193 "video/x-flash-screen", NULL);
1196 case AV_CODEC_ID_VP3:
1198 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp3",
1202 case AV_CODEC_ID_VP5:
1204 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp5",
1208 case AV_CODEC_ID_VP6:
1210 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp6",
1214 case AV_CODEC_ID_VP6F:
1216 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1217 "video/x-vp6-flash", NULL);
1220 case AV_CODEC_ID_VP6A:
1222 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1223 "video/x-vp6-alpha", NULL);
1226 case AV_CODEC_ID_VP8:
1228 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp8",
1232 case AV_CODEC_ID_THEORA:
1234 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1235 "video/x-theora", NULL);
1238 case AV_CODEC_ID_AAC:
1241 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
1245 GValue arr = { 0, };
1246 GValue item = { 0, };
1248 g_value_init (&arr, GST_TYPE_LIST);
1249 g_value_init (&item, G_TYPE_INT);
1250 g_value_set_int (&item, 2);
1251 gst_value_list_append_value (&arr, &item);
1252 g_value_set_int (&item, 4);
1253 gst_value_list_append_value (&arr, &item);
1254 g_value_unset (&item);
1256 gst_caps_set_value (caps, "mpegversion", &arr);
1257 g_value_unset (&arr);
1259 g_value_init (&arr, GST_TYPE_LIST);
1260 g_value_init (&item, G_TYPE_STRING);
1261 g_value_set_string (&item, "raw");
1262 gst_value_list_append_value (&arr, &item);
1263 g_value_set_string (&item, "adts");
1264 gst_value_list_append_value (&arr, &item);
1265 g_value_set_string (&item, "adif");
1266 gst_value_list_append_value (&arr, &item);
1267 g_value_unset (&item);
1269 gst_caps_set_value (caps, "stream-format", &arr);
1270 g_value_unset (&arr);
1272 gst_caps_set_simple (caps, "mpegversion", G_TYPE_INT, 4,
1273 "stream-format", G_TYPE_STRING, "raw",
1274 "base-profile", G_TYPE_STRING, "lc", NULL);
1276 if (context && context->extradata_size > 0)
1277 gst_codec_utils_aac_caps_set_level_and_profile (caps,
1278 context->extradata, context->extradata_size);
1283 case AV_CODEC_ID_AAC_LATM: /* LATM/LOAS AAC syntax */
1284 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
1285 "mpegversion", G_TYPE_INT, 4, "stream-format", G_TYPE_STRING, "loas",
1289 case AV_CODEC_ID_ASV1:
1291 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-asus",
1292 "asusversion", G_TYPE_INT, 1, NULL);
1294 case AV_CODEC_ID_ASV2:
1296 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-asus",
1297 "asusversion", G_TYPE_INT, 2, NULL);
1300 case AV_CODEC_ID_FFV1:
1302 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-ffv",
1303 "ffvversion", G_TYPE_INT, 1, NULL);
1306 case AV_CODEC_ID_4XM:
1308 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-4xm",
1312 case AV_CODEC_ID_XAN_WC3:
1313 case AV_CODEC_ID_XAN_WC4:
1315 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-xan",
1316 "wcversion", G_TYPE_INT, 3 - AV_CODEC_ID_XAN_WC3 + codec_id, NULL);
1319 case AV_CODEC_ID_CLJR:
1321 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1322 "video/x-cirrus-logic-accupak", NULL);
1325 case AV_CODEC_ID_FRAPS:
1327 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-fraps",
1331 case AV_CODEC_ID_MDEC:
1332 case AV_CODEC_ID_ROQ:
1333 case AV_CODEC_ID_INTERPLAY_VIDEO:
1337 case AV_CODEC_ID_VCR1:
1339 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1340 "video/x-ati-vcr", "vcrversion", G_TYPE_INT, 1, NULL);
1343 case AV_CODEC_ID_RPZA:
1345 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1346 "video/x-apple-video", NULL);
1349 case AV_CODEC_ID_CINEPAK:
1351 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1352 "video/x-cinepak", NULL);
1355 /* WS_VQA belogns here (order) */
1357 case AV_CODEC_ID_MSRLE:
1359 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-rle",
1360 "layout", G_TYPE_STRING, "microsoft", NULL);
1362 gst_caps_set_simple (caps,
1363 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1365 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1369 case AV_CODEC_ID_QTRLE:
1371 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-rle",
1372 "layout", G_TYPE_STRING, "quicktime", NULL);
1374 gst_caps_set_simple (caps,
1375 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1377 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1381 case AV_CODEC_ID_MSVIDEO1:
1383 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1384 "video/x-msvideocodec", "msvideoversion", G_TYPE_INT, 1, NULL);
1387 case AV_CODEC_ID_MSS1:
1389 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1390 "wmvversion", G_TYPE_INT, 1, "format", G_TYPE_STRING, "MSS1", NULL);
1393 case AV_CODEC_ID_MSS2:
1395 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1396 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "MSS2", NULL);
1399 case AV_CODEC_ID_WMV3:
1401 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1402 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "WMV3", NULL);
1404 case AV_CODEC_ID_VC1:
1406 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1407 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "WVC1", NULL);
1409 case AV_CODEC_ID_QDM2:
1411 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-qdm2",
1415 case AV_CODEC_ID_MSZH:
1417 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-mszh",
1421 case AV_CODEC_ID_ZLIB:
1423 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-zlib",
1427 case AV_CODEC_ID_TRUEMOTION1:
1429 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1430 "video/x-truemotion", "trueversion", G_TYPE_INT, 1, NULL);
1432 case AV_CODEC_ID_TRUEMOTION2:
1434 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1435 "video/x-truemotion", "trueversion", G_TYPE_INT, 2, NULL);
1438 case AV_CODEC_ID_ULTI:
1440 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1441 "video/x-ultimotion", NULL);
1444 case AV_CODEC_ID_TSCC:
1446 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1447 "video/x-camtasia", NULL);
1449 gst_caps_set_simple (caps,
1450 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1452 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1456 case AV_CODEC_ID_TSCC2:
1458 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1459 "video/x-tscc", "tsccversion", G_TYPE_INT, 2, NULL);
1462 case AV_CODEC_ID_KMVC:
1464 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-kmvc",
1468 case AV_CODEC_ID_NUV:
1470 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-nuv",
1474 case AV_CODEC_ID_GIF:
1476 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/gif",
1480 case AV_CODEC_ID_PNG:
1482 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/png",
1486 case AV_CODEC_ID_PPM:
1488 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/ppm",
1492 case AV_CODEC_ID_PBM:
1494 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/pbm",
1498 case AV_CODEC_ID_PAM:
1500 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1501 "image/x-portable-anymap", NULL);
1504 case AV_CODEC_ID_PGM:
1506 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1507 "image/x-portable-graymap", NULL);
1510 case AV_CODEC_ID_PCX:
1512 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-pcx",
1516 case AV_CODEC_ID_SGI:
1518 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-sgi",
1522 case AV_CODEC_ID_TARGA:
1524 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-tga",
1528 case AV_CODEC_ID_TIFF:
1530 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/tiff",
1534 case AV_CODEC_ID_SUNRAST:
1536 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1537 "image/x-sun-raster", NULL);
1540 case AV_CODEC_ID_SMC:
1542 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-smc",
1546 case AV_CODEC_ID_QDRAW:
1548 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-qdrw",
1552 case AV_CODEC_ID_DNXHD:
1554 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dnxhd",
1558 case AV_CODEC_ID_PRORES:
1560 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1561 "video/x-prores", NULL);
1564 case AV_CODEC_ID_MIMIC:
1566 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-mimic",
1570 case AV_CODEC_ID_VMNC:
1572 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vmnc",
1576 case AV_CODEC_ID_TRUESPEECH:
1578 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1579 "audio/x-truespeech", NULL);
1582 case AV_CODEC_ID_QCELP:
1584 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/qcelp",
1588 case AV_CODEC_ID_AMV:
1590 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-amv",
1594 case AV_CODEC_ID_AASC:
1596 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-aasc",
1600 case AV_CODEC_ID_LOCO:
1602 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-loco",
1606 case AV_CODEC_ID_ZMBV:
1608 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-zmbv",
1612 case AV_CODEC_ID_LAGARITH:
1614 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1615 "video/x-lagarith", NULL);
1618 case AV_CODEC_ID_CSCD:
1620 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1621 "video/x-camstudio", NULL);
1623 gst_caps_set_simple (caps,
1624 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1626 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1630 case AV_CODEC_ID_WS_VQA:
1631 case AV_CODEC_ID_IDCIN:
1632 case AV_CODEC_ID_8BPS:
1633 case AV_CODEC_ID_FLIC:
1634 case AV_CODEC_ID_VMDVIDEO:
1635 case AV_CODEC_ID_VMDAUDIO:
1636 case AV_CODEC_ID_SNOW:
1637 case AV_CODEC_ID_VIXL:
1638 case AV_CODEC_ID_QPEG:
1639 case AV_CODEC_ID_PGMYUV:
1640 case AV_CODEC_ID_FFVHUFF:
1641 case AV_CODEC_ID_WNV1:
1642 case AV_CODEC_ID_MP3ADU:
1643 case AV_CODEC_ID_MP3ON4:
1644 case AV_CODEC_ID_WESTWOOD_SND1:
1645 case AV_CODEC_ID_MMVIDEO:
1646 case AV_CODEC_ID_AVS:
1647 case AV_CODEC_ID_CAVS:
1651 /* weird quasi-codecs for the demuxers only */
1652 case AV_CODEC_ID_PCM_S16LE:
1653 case AV_CODEC_ID_PCM_S16BE:
1654 case AV_CODEC_ID_PCM_U16LE:
1655 case AV_CODEC_ID_PCM_U16BE:
1656 case AV_CODEC_ID_PCM_S8:
1657 case AV_CODEC_ID_PCM_U8:
1659 GstAudioFormat format;
1662 case AV_CODEC_ID_PCM_S16LE:
1663 format = GST_AUDIO_FORMAT_S16LE;
1665 case AV_CODEC_ID_PCM_S16BE:
1666 format = GST_AUDIO_FORMAT_S16BE;
1668 case AV_CODEC_ID_PCM_U16LE:
1669 format = GST_AUDIO_FORMAT_U16LE;
1671 case AV_CODEC_ID_PCM_U16BE:
1672 format = GST_AUDIO_FORMAT_U16BE;
1674 case AV_CODEC_ID_PCM_S8:
1675 format = GST_AUDIO_FORMAT_S8;
1677 case AV_CODEC_ID_PCM_U8:
1678 format = GST_AUDIO_FORMAT_U8;
1681 g_assert (0); /* don't worry, we never get here */
1686 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-raw",
1687 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
1688 "layout", G_TYPE_STRING, "interleaved", NULL);
1692 case AV_CODEC_ID_PCM_MULAW:
1694 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mulaw",
1698 case AV_CODEC_ID_PCM_ALAW:
1700 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-alaw",
1704 case AV_CODEC_ID_ADPCM_G722:
1706 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/G722",
1709 gst_caps_set_simple (caps,
1710 "block_align", G_TYPE_INT, context->block_align,
1711 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1714 case AV_CODEC_ID_ADPCM_G726:
1716 /* the G726 decoder can also handle G721 */
1718 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-adpcm",
1719 "layout", G_TYPE_STRING, "g726", NULL);
1721 gst_caps_set_simple (caps,
1722 "block_align", G_TYPE_INT, context->block_align,
1723 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1726 gst_caps_append (caps, gst_caps_new_simple ("audio/x-adpcm",
1727 "layout", G_TYPE_STRING, "g721",
1728 "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, 8000, NULL));
1732 case AV_CODEC_ID_ADPCM_IMA_QT:
1733 case AV_CODEC_ID_ADPCM_IMA_WAV:
1734 case AV_CODEC_ID_ADPCM_IMA_DK3:
1735 case AV_CODEC_ID_ADPCM_IMA_DK4:
1736 case AV_CODEC_ID_ADPCM_IMA_WS:
1737 case AV_CODEC_ID_ADPCM_IMA_SMJPEG:
1738 case AV_CODEC_ID_ADPCM_IMA_AMV:
1739 case AV_CODEC_ID_ADPCM_IMA_ISS:
1740 case AV_CODEC_ID_ADPCM_IMA_EA_EACS:
1741 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
1742 case AV_CODEC_ID_ADPCM_MS:
1743 case AV_CODEC_ID_ADPCM_4XM:
1744 case AV_CODEC_ID_ADPCM_XA:
1745 case AV_CODEC_ID_ADPCM_ADX:
1746 case AV_CODEC_ID_ADPCM_EA:
1747 case AV_CODEC_ID_ADPCM_CT:
1748 case AV_CODEC_ID_ADPCM_SWF:
1749 case AV_CODEC_ID_ADPCM_YAMAHA:
1750 case AV_CODEC_ID_ADPCM_SBPRO_2:
1751 case AV_CODEC_ID_ADPCM_SBPRO_3:
1752 case AV_CODEC_ID_ADPCM_SBPRO_4:
1753 case AV_CODEC_ID_ADPCM_EA_R1:
1754 case AV_CODEC_ID_ADPCM_EA_R2:
1755 case AV_CODEC_ID_ADPCM_EA_R3:
1756 case AV_CODEC_ID_ADPCM_EA_MAXIS_XA:
1757 case AV_CODEC_ID_ADPCM_EA_XAS:
1758 case AV_CODEC_ID_ADPCM_THP:
1760 const gchar *layout = NULL;
1763 case AV_CODEC_ID_ADPCM_IMA_QT:
1764 layout = "quicktime";
1766 case AV_CODEC_ID_ADPCM_IMA_WAV:
1769 case AV_CODEC_ID_ADPCM_IMA_DK3:
1772 case AV_CODEC_ID_ADPCM_IMA_DK4:
1775 case AV_CODEC_ID_ADPCM_IMA_WS:
1776 layout = "westwood";
1778 case AV_CODEC_ID_ADPCM_IMA_SMJPEG:
1781 case AV_CODEC_ID_ADPCM_IMA_AMV:
1784 case AV_CODEC_ID_ADPCM_IMA_ISS:
1787 case AV_CODEC_ID_ADPCM_IMA_EA_EACS:
1790 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
1793 case AV_CODEC_ID_ADPCM_MS:
1794 layout = "microsoft";
1796 case AV_CODEC_ID_ADPCM_4XM:
1799 case AV_CODEC_ID_ADPCM_XA:
1802 case AV_CODEC_ID_ADPCM_ADX:
1805 case AV_CODEC_ID_ADPCM_EA:
1808 case AV_CODEC_ID_ADPCM_CT:
1811 case AV_CODEC_ID_ADPCM_SWF:
1814 case AV_CODEC_ID_ADPCM_YAMAHA:
1817 case AV_CODEC_ID_ADPCM_SBPRO_2:
1820 case AV_CODEC_ID_ADPCM_SBPRO_3:
1823 case AV_CODEC_ID_ADPCM_SBPRO_4:
1826 case AV_CODEC_ID_ADPCM_EA_R1:
1829 case AV_CODEC_ID_ADPCM_EA_R2:
1832 case AV_CODEC_ID_ADPCM_EA_R3:
1835 case AV_CODEC_ID_ADPCM_EA_MAXIS_XA:
1836 layout = "ea-maxis-xa";
1838 case AV_CODEC_ID_ADPCM_EA_XAS:
1841 case AV_CODEC_ID_ADPCM_THP:
1845 g_assert (0); /* don't worry, we never get here */
1849 /* FIXME: someone please check whether we need additional properties
1850 * in this caps definition. */
1852 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-adpcm",
1853 "layout", G_TYPE_STRING, layout, NULL);
1855 gst_caps_set_simple (caps,
1856 "block_align", G_TYPE_INT, context->block_align,
1857 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1861 case AV_CODEC_ID_AMR_NB:
1863 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/AMR",
1867 case AV_CODEC_ID_AMR_WB:
1869 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/AMR-WB",
1873 case AV_CODEC_ID_GSM:
1875 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-gsm",
1879 case AV_CODEC_ID_GSM_MS:
1881 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/ms-gsm",
1885 case AV_CODEC_ID_NELLYMOSER:
1887 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1888 "audio/x-nellymoser", NULL);
1891 case AV_CODEC_ID_SIPR:
1894 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-sipro",
1897 gst_caps_set_simple (caps,
1898 "leaf_size", G_TYPE_INT, context->block_align,
1899 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1904 case AV_CODEC_ID_RA_144:
1905 case AV_CODEC_ID_RA_288:
1906 case AV_CODEC_ID_COOK:
1911 case AV_CODEC_ID_RA_144:
1914 case AV_CODEC_ID_RA_288:
1917 case AV_CODEC_ID_COOK:
1924 /* FIXME: properties? */
1926 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1927 "audio/x-pn-realaudio", "raversion", G_TYPE_INT, version, NULL);
1929 gst_caps_set_simple (caps,
1930 "leaf_size", G_TYPE_INT, context->block_align,
1931 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1936 case AV_CODEC_ID_ROQ_DPCM:
1937 case AV_CODEC_ID_INTERPLAY_DPCM:
1938 case AV_CODEC_ID_XAN_DPCM:
1939 case AV_CODEC_ID_SOL_DPCM:
1941 const gchar *layout = NULL;
1944 case AV_CODEC_ID_ROQ_DPCM:
1947 case AV_CODEC_ID_INTERPLAY_DPCM:
1948 layout = "interplay";
1950 case AV_CODEC_ID_XAN_DPCM:
1953 case AV_CODEC_ID_SOL_DPCM:
1957 g_assert (0); /* don't worry, we never get here */
1961 /* FIXME: someone please check whether we need additional properties
1962 * in this caps definition. */
1964 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dpcm",
1965 "layout", G_TYPE_STRING, layout, NULL);
1967 gst_caps_set_simple (caps,
1968 "block_align", G_TYPE_INT, context->block_align,
1969 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1973 case AV_CODEC_ID_SHORTEN:
1974 caps = gst_caps_new_empty_simple ("audio/x-shorten");
1977 case AV_CODEC_ID_ALAC:
1979 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-alac",
1982 gst_caps_set_simple (caps,
1983 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
1987 case AV_CODEC_ID_FLAC:
1988 /* Note that ffmpeg has no encoder yet, but just for safety. In the
1989 * encoder case, we want to add things like samplerate, channels... */
1991 caps = gst_caps_new_empty_simple ("audio/x-flac");
1995 case AV_CODEC_ID_S302M:
1996 caps = gst_caps_new_empty_simple ("audio/x-smpte-302m");
1999 case AV_CODEC_ID_DVD_SUBTITLE:
2000 case AV_CODEC_ID_DVB_SUBTITLE:
2003 case AV_CODEC_ID_BMP:
2004 caps = gst_caps_new_empty_simple ("image/bmp");
2006 case AV_CODEC_ID_TTA:
2008 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-tta",
2011 gst_caps_set_simple (caps,
2012 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
2015 case AV_CODEC_ID_TWINVQ:
2017 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
2018 "audio/x-twin-vq", NULL);
2021 GST_DEBUG ("Unknown codec ID %d, please add mapping here", codec_id);
2028 if ((codec = avcodec_find_decoder (codec_id)) ||
2029 (codec = avcodec_find_encoder (codec_id))) {
2032 GST_LOG ("Could not create stream format caps for %s", codec->name);
2034 switch (codec->type) {
2035 case AVMEDIA_TYPE_VIDEO:
2036 mime = g_strdup_printf ("video/x-gst-av-%s", codec->name);
2038 gst_ff_vid_caps_new (context, NULL, codec_id, encode, mime, NULL);
2041 case AVMEDIA_TYPE_AUDIO:
2042 mime = g_strdup_printf ("audio/x-gst-av-%s", codec->name);
2044 gst_ff_aud_caps_new (context, NULL, codec_id, encode, mime, NULL);
2046 gst_caps_set_simple (caps,
2047 "block_align", G_TYPE_INT, context->block_align,
2048 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
2059 /* set private data */
2060 if (context && context->extradata_size > 0) {
2061 GstBuffer *data = gst_buffer_new_and_alloc (context->extradata_size);
2063 gst_buffer_fill (data, 0, context->extradata, context->extradata_size);
2064 gst_caps_set_simple (caps, "codec_data", GST_TYPE_BUFFER, data, NULL);
2065 gst_buffer_unref (data);
2068 GST_LOG ("caps for codec_id=%d: %" GST_PTR_FORMAT, codec_id, caps);
2071 GST_LOG ("No caps found for codec_id=%d", codec_id);
2077 /* Convert a FFMPEG Pixel Format and optional AVCodecContext
2078 * to a GstCaps. If the context is ommitted, no fixed values
2079 * for video/audio size will be included in the GstCaps
2081 * See below for usefullness
2085 gst_ffmpeg_pixfmt_to_caps (enum PixelFormat pix_fmt, AVCodecContext * context,
2086 enum CodecID codec_id)
2088 GstCaps *caps = NULL;
2089 GstVideoFormat format;
2091 format = gst_ffmpeg_pixfmt_to_videoformat (pix_fmt);
2093 if (format != GST_VIDEO_FORMAT_UNKNOWN) {
2094 caps = gst_ff_vid_caps_new (context, NULL, codec_id, TRUE, "video/x-raw",
2095 "format", G_TYPE_STRING, gst_video_format_to_string (format), NULL);
2099 GST_DEBUG ("caps for pix_fmt=%d: %" GST_PTR_FORMAT, pix_fmt, caps);
2101 GST_LOG ("No caps found for pix_fmt=%d", pix_fmt);
2108 gst_ffmpeg_smpfmt_to_audioformat (enum AVSampleFormat sample_fmt)
2110 switch (sample_fmt) {
2111 case AV_SAMPLE_FMT_U8:
2112 case AV_SAMPLE_FMT_U8P:
2113 return GST_AUDIO_FORMAT_U8;
2115 case AV_SAMPLE_FMT_S16:
2116 case AV_SAMPLE_FMT_S16P:
2117 return GST_AUDIO_FORMAT_S16;
2119 case AV_SAMPLE_FMT_S32:
2120 case AV_SAMPLE_FMT_S32P:
2121 return GST_AUDIO_FORMAT_S32;
2123 case AV_SAMPLE_FMT_FLT:
2124 case AV_SAMPLE_FMT_FLTP:
2125 return GST_AUDIO_FORMAT_F32;
2127 case AV_SAMPLE_FMT_DBL:
2128 case AV_SAMPLE_FMT_DBLP:
2129 return GST_AUDIO_FORMAT_F64;
2133 return GST_AUDIO_FORMAT_UNKNOWN;
2138 /* Convert a FFMPEG Sample Format and optional AVCodecContext
2139 * to a GstCaps. If the context is ommitted, no fixed values
2140 * for video/audio size will be included in the GstCaps
2142 * See below for usefullness
2146 gst_ffmpeg_smpfmt_to_caps (enum AVSampleFormat sample_fmt,
2147 AVCodecContext * context, AVCodec * codec, enum CodecID codec_id)
2149 GstCaps *caps = NULL;
2150 GstAudioFormat format;
2152 format = gst_ffmpeg_smpfmt_to_audioformat (sample_fmt);
2154 if (format != GST_AUDIO_FORMAT_UNKNOWN) {
2155 caps = gst_ff_aud_caps_new (context, codec, codec_id, TRUE, "audio/x-raw",
2156 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
2157 "layout", G_TYPE_STRING, "interleaved", NULL);
2158 GST_LOG ("caps for sample_fmt=%d: %" GST_PTR_FORMAT, sample_fmt, caps);
2160 GST_LOG ("No caps found for sample_fmt=%d", sample_fmt);
2167 caps_has_field (GstCaps * caps, const gchar * field)
2171 n = gst_caps_get_size (caps);
2172 for (i = 0; i < n; i++) {
2173 GstStructure *s = gst_caps_get_structure (caps, i);
2175 if (gst_structure_has_field (s, field))
2183 gst_ffmpeg_codectype_to_audio_caps (AVCodecContext * context,
2184 enum CodecID codec_id, gboolean encode, AVCodec * codec)
2186 GstCaps *caps = NULL;
2188 GST_DEBUG ("context:%p, codec_id:%d, encode:%d, codec:%p",
2189 context, codec_id, encode, codec);
2191 GST_DEBUG ("sample_fmts:%p, samplerates:%p",
2192 codec->sample_fmts, codec->supported_samplerates);
2195 /* Specific codec context */
2197 gst_ffmpeg_smpfmt_to_caps (context->sample_fmt, context, codec,
2200 caps = gst_ff_aud_caps_new (context, codec, codec_id, encode, "audio/x-raw",
2201 "layout", G_TYPE_STRING, "interleaved", NULL);
2202 if (!caps_has_field (caps, "format"))
2203 gst_ffmpeg_audio_set_sample_fmts (caps,
2204 codec ? codec->sample_fmts : NULL);
2211 gst_ffmpeg_codectype_to_video_caps (AVCodecContext * context,
2212 enum CodecID codec_id, gboolean encode, AVCodec * codec)
2216 GST_LOG ("context:%p, codec_id:%d, encode:%d, codec:%p",
2217 context, codec_id, encode, codec);
2220 caps = gst_ffmpeg_pixfmt_to_caps (context->pix_fmt, context, codec_id);
2223 gst_ff_vid_caps_new (context, codec, codec_id, encode, "video/x-raw",
2225 if (!caps_has_field (caps, "format"))
2226 gst_ffmpeg_video_set_pix_fmts (caps, codec ? codec->pix_fmts : NULL);
2231 /* Convert a GstCaps (audio/raw) to a FFMPEG SampleFmt
2232 * and other audio properties in a AVCodecContext.
2234 * For usefullness, see below
2238 gst_ffmpeg_caps_to_smpfmt (const GstCaps * caps,
2239 AVCodecContext * context, gboolean raw)
2241 GstStructure *structure;
2243 GstAudioFormat format = GST_AUDIO_FORMAT_UNKNOWN;
2245 g_return_if_fail (gst_caps_get_size (caps) == 1);
2247 structure = gst_caps_get_structure (caps, 0);
2249 gst_structure_get_int (structure, "channels", &context->channels);
2250 gst_structure_get_int (structure, "rate", &context->sample_rate);
2251 gst_structure_get_int (structure, "block_align", &context->block_align);
2252 gst_structure_get_int (structure, "bitrate", &context->bit_rate);
2257 if (gst_structure_has_name (structure, "audio/x-raw")) {
2258 if ((fmt = gst_structure_get_string (structure, "format"))) {
2259 format = gst_audio_format_from_string (fmt);
2264 case GST_AUDIO_FORMAT_F32:
2265 context->sample_fmt = AV_SAMPLE_FMT_FLT;
2267 case GST_AUDIO_FORMAT_F64:
2268 context->sample_fmt = AV_SAMPLE_FMT_DBL;
2270 case GST_AUDIO_FORMAT_S32:
2271 context->sample_fmt = AV_SAMPLE_FMT_S32;
2273 case GST_AUDIO_FORMAT_S16:
2274 context->sample_fmt = AV_SAMPLE_FMT_S16;
2281 /* Convert a GstCaps (video/raw) to a FFMPEG PixFmt
2282 * and other video properties in a AVCodecContext.
2284 * For usefullness, see below
2288 gst_ffmpeg_caps_to_pixfmt (const GstCaps * caps,
2289 AVCodecContext * context, gboolean raw)
2291 GstStructure *structure;
2293 const GValue *par = NULL;
2295 GstVideoFormat format = GST_VIDEO_FORMAT_UNKNOWN;
2297 GST_DEBUG ("converting caps %" GST_PTR_FORMAT, caps);
2298 g_return_if_fail (gst_caps_get_size (caps) == 1);
2299 structure = gst_caps_get_structure (caps, 0);
2301 gst_structure_get_int (structure, "width", &context->width);
2302 gst_structure_get_int (structure, "height", &context->height);
2303 gst_structure_get_int (structure, "bpp", &context->bits_per_coded_sample);
2305 fps = gst_structure_get_value (structure, "framerate");
2306 if (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps)) {
2308 /* somehow these seem mixed up.. */
2309 context->time_base.den = gst_value_get_fraction_numerator (fps);
2310 context->time_base.num = gst_value_get_fraction_denominator (fps);
2311 context->ticks_per_frame = 1;
2313 GST_DEBUG ("setting framerate %d/%d = %lf",
2314 context->time_base.den, context->time_base.num,
2315 1. * context->time_base.den / context->time_base.num);
2318 par = gst_structure_get_value (structure, "pixel-aspect-ratio");
2319 if (par && GST_VALUE_HOLDS_FRACTION (par)) {
2321 context->sample_aspect_ratio.num = gst_value_get_fraction_numerator (par);
2322 context->sample_aspect_ratio.den = gst_value_get_fraction_denominator (par);
2324 GST_DEBUG ("setting pixel-aspect-ratio %d/%d = %lf",
2325 context->sample_aspect_ratio.den, context->sample_aspect_ratio.num,
2326 1. * context->sample_aspect_ratio.den /
2327 context->sample_aspect_ratio.num);
2333 g_return_if_fail (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps));
2335 if (gst_structure_has_name (structure, "video/x-raw")) {
2336 if ((fmt = gst_structure_get_string (structure, "format"))) {
2337 format = gst_video_format_from_string (fmt);
2342 case GST_VIDEO_FORMAT_YUY2:
2343 context->pix_fmt = PIX_FMT_YUYV422;
2345 case GST_VIDEO_FORMAT_I420:
2346 context->pix_fmt = PIX_FMT_YUV420P;
2348 case GST_VIDEO_FORMAT_A420:
2349 context->pix_fmt = PIX_FMT_YUVA420P;
2351 case GST_VIDEO_FORMAT_Y41B:
2352 context->pix_fmt = PIX_FMT_YUV411P;
2354 case GST_VIDEO_FORMAT_Y42B:
2355 context->pix_fmt = PIX_FMT_YUV422P;
2357 case GST_VIDEO_FORMAT_YUV9:
2358 context->pix_fmt = PIX_FMT_YUV410P;
2360 case GST_VIDEO_FORMAT_Y444:
2361 context->pix_fmt = PIX_FMT_YUV444P;
2363 case GST_VIDEO_FORMAT_GRAY8:
2364 context->pix_fmt = PIX_FMT_GRAY8;
2366 case GST_VIDEO_FORMAT_xRGB:
2367 #if (G_BYTE_ORDER == G_BIG_ENDIAN)
2368 context->pix_fmt = PIX_FMT_RGB32;
2371 case GST_VIDEO_FORMAT_BGRx:
2372 #if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
2373 context->pix_fmt = PIX_FMT_RGB32;
2376 case GST_VIDEO_FORMAT_RGB:
2377 context->pix_fmt = PIX_FMT_RGB24;
2379 case GST_VIDEO_FORMAT_BGR:
2380 context->pix_fmt = PIX_FMT_BGR24;
2382 case GST_VIDEO_FORMAT_RGB16:
2383 context->pix_fmt = PIX_FMT_RGB565;
2385 case GST_VIDEO_FORMAT_RGB15:
2386 context->pix_fmt = PIX_FMT_RGB555;
2388 case GST_VIDEO_FORMAT_RGB8P:
2389 context->pix_fmt = PIX_FMT_PAL8;
2398 GstVideoFormat format;
2399 enum PixelFormat pixfmt;
2402 /* FIXME : FILLME */
2403 static const PixToFmt pixtofmttable[] = {
2404 /* GST_VIDEO_FORMAT_I420, */
2405 {GST_VIDEO_FORMAT_I420, PIX_FMT_YUV420P},
2406 /* Note : this should use a different chroma placement */
2407 {GST_VIDEO_FORMAT_I420, PIX_FMT_YUVJ420P},
2409 /* GST_VIDEO_FORMAT_YV12, */
2410 /* GST_VIDEO_FORMAT_YUY2, */
2411 {GST_VIDEO_FORMAT_YUY2, PIX_FMT_YUYV422},
2412 /* GST_VIDEO_FORMAT_UYVY, */
2413 {GST_VIDEO_FORMAT_UYVY, PIX_FMT_UYVY422},
2414 /* GST_VIDEO_FORMAT_AYUV, */
2415 /* GST_VIDEO_FORMAT_RGBx, */
2416 /* GST_VIDEO_FORMAT_BGRx, */
2417 /* GST_VIDEO_FORMAT_xRGB, */
2418 /* GST_VIDEO_FORMAT_xBGR, */
2419 /* GST_VIDEO_FORMAT_RGBA, */
2420 {GST_VIDEO_FORMAT_RGBA, PIX_FMT_RGBA},
2421 /* GST_VIDEO_FORMAT_BGRA, */
2422 {GST_VIDEO_FORMAT_BGRA, PIX_FMT_BGRA},
2423 /* GST_VIDEO_FORMAT_ARGB, */
2424 {GST_VIDEO_FORMAT_ARGB, PIX_FMT_ARGB},
2425 /* GST_VIDEO_FORMAT_ABGR, */
2426 {GST_VIDEO_FORMAT_ABGR, PIX_FMT_ABGR},
2427 /* GST_VIDEO_FORMAT_RGB, */
2428 {GST_VIDEO_FORMAT_RGB, PIX_FMT_RGB24},
2429 /* GST_VIDEO_FORMAT_BGR, */
2430 {GST_VIDEO_FORMAT_BGR, PIX_FMT_BGR24},
2431 /* GST_VIDEO_FORMAT_Y41B, */
2432 {GST_VIDEO_FORMAT_Y41B, PIX_FMT_YUV411P},
2433 /* GST_VIDEO_FORMAT_Y42B, */
2434 {GST_VIDEO_FORMAT_Y42B, PIX_FMT_YUV422P},
2435 {GST_VIDEO_FORMAT_Y42B, PIX_FMT_YUVJ422P},
2436 /* GST_VIDEO_FORMAT_YVYU, */
2437 /* GST_VIDEO_FORMAT_Y444, */
2438 {GST_VIDEO_FORMAT_Y444, PIX_FMT_YUV444P},
2439 {GST_VIDEO_FORMAT_Y444, PIX_FMT_YUVJ444P},
2440 /* GST_VIDEO_FORMAT_v210, */
2441 /* GST_VIDEO_FORMAT_v216, */
2442 /* GST_VIDEO_FORMAT_NV12, */
2443 {GST_VIDEO_FORMAT_NV12, PIX_FMT_NV12},
2444 /* GST_VIDEO_FORMAT_NV21, */
2445 {GST_VIDEO_FORMAT_NV21, PIX_FMT_NV21},
2446 /* GST_VIDEO_FORMAT_GRAY8, */
2447 {GST_VIDEO_FORMAT_GRAY8, PIX_FMT_GRAY8},
2448 /* GST_VIDEO_FORMAT_GRAY16_BE, */
2449 {GST_VIDEO_FORMAT_GRAY16_BE, PIX_FMT_GRAY16BE},
2450 /* GST_VIDEO_FORMAT_GRAY16_LE, */
2451 {GST_VIDEO_FORMAT_GRAY16_LE, PIX_FMT_GRAY16LE},
2452 /* GST_VIDEO_FORMAT_v308, */
2453 /* GST_VIDEO_FORMAT_Y800, */
2454 /* GST_VIDEO_FORMAT_Y16, */
2455 /* GST_VIDEO_FORMAT_RGB16, */
2456 {GST_VIDEO_FORMAT_RGB16, PIX_FMT_RGB565},
2457 /* GST_VIDEO_FORMAT_BGR16, */
2458 /* GST_VIDEO_FORMAT_RGB15, */
2459 {GST_VIDEO_FORMAT_RGB15, PIX_FMT_RGB555},
2460 /* GST_VIDEO_FORMAT_BGR15, */
2461 /* GST_VIDEO_FORMAT_UYVP, */
2462 /* GST_VIDEO_FORMAT_A420, */
2463 {GST_VIDEO_FORMAT_A420, PIX_FMT_YUVA420P},
2464 /* GST_VIDEO_FORMAT_RGB8_PALETTED, */
2465 {GST_VIDEO_FORMAT_RGB8P, PIX_FMT_PAL8},
2466 /* GST_VIDEO_FORMAT_YUV9, */
2467 {GST_VIDEO_FORMAT_YUV9, PIX_FMT_YUV410P},
2468 /* GST_VIDEO_FORMAT_YVU9, */
2469 /* GST_VIDEO_FORMAT_IYU1, */
2470 /* GST_VIDEO_FORMAT_ARGB64, */
2471 /* GST_VIDEO_FORMAT_AYUV64, */
2472 /* GST_VIDEO_FORMAT_r210, */
2473 {GST_VIDEO_FORMAT_I420_10LE, PIX_FMT_YUV420P10LE},
2474 {GST_VIDEO_FORMAT_I420_10BE, PIX_FMT_YUV420P10BE},
2475 {GST_VIDEO_FORMAT_I422_10LE, PIX_FMT_YUV422P10LE},
2476 {GST_VIDEO_FORMAT_I422_10BE, PIX_FMT_YUV422P10BE},
2477 {GST_VIDEO_FORMAT_Y444_10LE, PIX_FMT_YUV444P10LE},
2478 {GST_VIDEO_FORMAT_Y444_10BE, PIX_FMT_YUV444P10BE},
2479 {GST_VIDEO_FORMAT_GBR, PIX_FMT_GBRP},
2480 {GST_VIDEO_FORMAT_GBR_10LE, PIX_FMT_GBRP10LE},
2481 {GST_VIDEO_FORMAT_GBR_10BE, PIX_FMT_GBRP10BE},
2485 gst_ffmpeg_pixfmt_to_videoformat (enum PixelFormat pixfmt)
2489 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2490 if (pixtofmttable[i].pixfmt == pixfmt)
2491 return pixtofmttable[i].format;
2493 GST_DEBUG ("Unknown pixel format %d", pixfmt);
2494 return GST_VIDEO_FORMAT_UNKNOWN;
2498 gst_ffmpeg_videoformat_to_pixfmt (GstVideoFormat format)
2502 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2503 if (pixtofmttable[i].format == format)
2504 return pixtofmttable[i].pixfmt;
2505 return PIX_FMT_NONE;
2509 gst_ffmpeg_videoinfo_to_context (GstVideoInfo * info, AVCodecContext * context)
2513 context->width = GST_VIDEO_INFO_WIDTH (info);
2514 context->height = GST_VIDEO_INFO_HEIGHT (info);
2515 for (i = 0; i < GST_VIDEO_INFO_N_COMPONENTS (info); i++)
2516 bpp += GST_VIDEO_INFO_COMP_DEPTH (info, i);
2517 context->bits_per_coded_sample = bpp;
2519 context->ticks_per_frame = 1;
2520 if (GST_VIDEO_INFO_FPS_N (info) == 0) {
2521 GST_DEBUG ("Using 25/1 framerate");
2522 context->time_base.den = 25;
2523 context->time_base.num = 1;
2525 context->time_base.den = GST_VIDEO_INFO_FPS_N (info);
2526 context->time_base.num = GST_VIDEO_INFO_FPS_D (info);
2529 context->sample_aspect_ratio.num = GST_VIDEO_INFO_PAR_N (info);
2530 context->sample_aspect_ratio.den = GST_VIDEO_INFO_PAR_D (info);
2533 gst_ffmpeg_videoformat_to_pixfmt (GST_VIDEO_INFO_FORMAT (info));
2537 gst_ffmpeg_audioinfo_to_context (GstAudioInfo * info, AVCodecContext * context)
2539 const AVCodec *codec;
2540 const enum AVSampleFormat *smpl_fmts;
2541 enum AVSampleFormat smpl_fmt = -1;
2543 context->channels = info->channels;
2544 context->sample_rate = info->rate;
2545 context->channel_layout =
2546 gst_ffmpeg_channel_positions_to_layout (info->position, info->channels);
2548 codec = context->codec;
2550 smpl_fmts = codec->sample_fmts;
2552 switch (info->finfo->format) {
2553 case GST_AUDIO_FORMAT_F32:
2555 while (*smpl_fmts != -1) {
2556 if (*smpl_fmts == AV_SAMPLE_FMT_FLT) {
2557 smpl_fmt = *smpl_fmts;
2559 } else if (*smpl_fmts == AV_SAMPLE_FMT_FLTP) {
2560 smpl_fmt = *smpl_fmts;
2566 smpl_fmt = AV_SAMPLE_FMT_FLT;
2569 case GST_AUDIO_FORMAT_F64:
2571 while (*smpl_fmts != -1) {
2572 if (*smpl_fmts == AV_SAMPLE_FMT_DBL) {
2573 smpl_fmt = *smpl_fmts;
2575 } else if (*smpl_fmts == AV_SAMPLE_FMT_DBLP) {
2576 smpl_fmt = *smpl_fmts;
2582 smpl_fmt = AV_SAMPLE_FMT_DBL;
2585 case GST_AUDIO_FORMAT_S32:
2587 while (*smpl_fmts != -1) {
2588 if (*smpl_fmts == AV_SAMPLE_FMT_S32) {
2589 smpl_fmt = *smpl_fmts;
2591 } else if (*smpl_fmts == AV_SAMPLE_FMT_S32P) {
2592 smpl_fmt = *smpl_fmts;
2598 smpl_fmt = AV_SAMPLE_FMT_S32;
2601 case GST_AUDIO_FORMAT_S16:
2603 while (*smpl_fmts != -1) {
2604 if (*smpl_fmts == AV_SAMPLE_FMT_S16) {
2605 smpl_fmt = *smpl_fmts;
2607 } else if (*smpl_fmts == AV_SAMPLE_FMT_S16P) {
2608 smpl_fmt = *smpl_fmts;
2614 smpl_fmt = AV_SAMPLE_FMT_S16;
2617 case GST_AUDIO_FORMAT_U8:
2619 while (*smpl_fmts != -1) {
2620 if (*smpl_fmts == AV_SAMPLE_FMT_U8) {
2621 smpl_fmt = *smpl_fmts;
2623 } else if (*smpl_fmts == AV_SAMPLE_FMT_U8P) {
2624 smpl_fmt = *smpl_fmts;
2630 smpl_fmt = AV_SAMPLE_FMT_U8;
2637 g_assert (smpl_fmt != -1);
2639 context->sample_fmt = smpl_fmt;
2642 /* Convert a GstCaps and a FFMPEG codec Type to a
2643 * AVCodecContext. If the context is ommitted, no fixed values
2644 * for video/audio size will be included in the context
2646 * AVMediaType is primarily meant for uncompressed data GstCaps!
2650 gst_ffmpeg_caps_with_codectype (enum AVMediaType type,
2651 const GstCaps * caps, AVCodecContext * context)
2653 if (context == NULL)
2657 case AVMEDIA_TYPE_VIDEO:
2658 gst_ffmpeg_caps_to_pixfmt (caps, context, TRUE);
2661 case AVMEDIA_TYPE_AUDIO:
2662 gst_ffmpeg_caps_to_smpfmt (caps, context, TRUE);
2673 nal_escape (guint8 * dst, guint8 * src, guint size, guint * destsize)
2677 guint8 *end = src + size;
2680 while (srcp < end) {
2681 if (count == 2 && *srcp <= 0x03) {
2682 GST_DEBUG ("added escape code");
2691 GST_DEBUG ("copy %02x, count %d", *srcp, count);
2694 *destsize = dstp - dst;
2697 /* copy the config, escaping NAL units as we iterate them, if something fails we
2698 * copy everything and hope for the best. */
2700 copy_config (guint8 * dst, guint8 * src, guint size, guint * destsize)
2705 guint nalsize, esize;
2715 cnt = *(srcp + 5) & 0x1f; /* Number of sps */
2717 GST_DEBUG ("num SPS %d", cnt);
2719 memcpy (dstp, srcp, 6);
2723 for (i = 0; i < cnt; i++) {
2724 GST_DEBUG ("copy SPS %d", i);
2725 nalsize = (srcp[0] << 8) | srcp[1];
2726 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2727 dstp[0] = esize >> 8;
2728 dstp[1] = esize & 0xff;
2730 srcp += nalsize + 2;
2733 cnt = *(dstp++) = *(srcp++); /* Number of pps */
2735 GST_DEBUG ("num PPS %d", cnt);
2737 for (i = 0; i < cnt; i++) {
2738 GST_DEBUG ("copy PPS %d", i);
2739 nalsize = (srcp[0] << 8) | srcp[1];
2740 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2741 dstp[0] = esize >> 8;
2742 dstp[1] = esize & 0xff;
2744 srcp += nalsize + 2;
2746 *destsize = dstp - dst;
2752 GST_DEBUG ("something unexpected, doing full copy");
2753 memcpy (dst, src, size);
2761 * caps_with_codecid () transforms a GstCaps for a known codec
2762 * ID into a filled-in context.
2763 * codec_data from caps will override possible extradata already in the context
2767 gst_ffmpeg_caps_with_codecid (enum CodecID codec_id,
2768 enum AVMediaType codec_type, const GstCaps * caps, AVCodecContext * context)
2771 const GValue *value;
2774 GST_LOG ("codec_id:%d, codec_type:%d, caps:%" GST_PTR_FORMAT " context:%p",
2775 codec_id, codec_type, caps, context);
2777 if (!context || !gst_caps_get_size (caps))
2780 str = gst_caps_get_structure (caps, 0);
2782 /* extradata parsing (esds [mpeg4], wma/wmv, msmpeg4v1/2/3, etc.) */
2783 if ((value = gst_structure_get_value (str, "codec_data"))) {
2786 buf = gst_value_get_buffer (value);
2787 gst_buffer_map (buf, &map, GST_MAP_READ);
2789 /* free the old one if it is there */
2790 if (context->extradata)
2791 av_free (context->extradata);
2794 if (codec_id == AV_CODEC_ID_H264) {
2797 GST_DEBUG ("copy, escaping codec_data %d", size);
2798 /* ffmpeg h264 expects the codec_data to be escaped, there is no real
2799 * reason for this but let's just escape it for now. Start by allocating
2800 * enough space, x2 is more than enough.
2802 * FIXME, we disabled escaping because some file already contain escaped
2803 * codec_data and then we escape twice and fail. It's better to leave it
2804 * as is, as that is what most players do. */
2805 context->extradata =
2806 av_mallocz (GST_ROUND_UP_16 (size * 2 +
2807 FF_INPUT_BUFFER_PADDING_SIZE));
2808 copy_config (context->extradata, data, size, &extrasize);
2809 GST_DEBUG ("escaped size: %d", extrasize);
2810 context->extradata_size = extrasize;
2814 /* allocate with enough padding */
2815 GST_DEBUG ("copy codec_data");
2816 context->extradata =
2817 av_mallocz (GST_ROUND_UP_16 (map.size +
2818 FF_INPUT_BUFFER_PADDING_SIZE));
2819 memcpy (context->extradata, map.data, map.size);
2820 context->extradata_size = map.size;
2823 /* Hack for VC1. Sometimes the first (length) byte is 0 for some files */
2824 if (codec_id == AV_CODEC_ID_VC1 && map.size > 0 && map.data[0] == 0) {
2825 context->extradata[0] = (guint8) map.size;
2828 GST_DEBUG ("have codec data of size %" G_GSIZE_FORMAT, map.size);
2830 gst_buffer_unmap (buf, &map);
2831 } else if (context->extradata == NULL && codec_id != AV_CODEC_ID_AAC_LATM &&
2832 codec_id != AV_CODEC_ID_FLAC) {
2833 /* no extradata, alloc dummy with 0 sized, some codecs insist on reading
2834 * extradata anyway which makes then segfault. */
2835 context->extradata =
2836 av_mallocz (GST_ROUND_UP_16 (FF_INPUT_BUFFER_PADDING_SIZE));
2837 context->extradata_size = 0;
2838 GST_DEBUG ("no codec data");
2842 case AV_CODEC_ID_MPEG4:
2844 const gchar *mime = gst_structure_get_name (str);
2846 if (!strcmp (mime, "video/x-divx"))
2847 context->codec_tag = GST_MAKE_FOURCC ('D', 'I', 'V', 'X');
2848 else if (!strcmp (mime, "video/x-xvid"))
2849 context->codec_tag = GST_MAKE_FOURCC ('X', 'V', 'I', 'D');
2850 else if (!strcmp (mime, "video/x-3ivx"))
2851 context->codec_tag = GST_MAKE_FOURCC ('3', 'I', 'V', '1');
2852 else if (!strcmp (mime, "video/mpeg"))
2853 context->codec_tag = GST_MAKE_FOURCC ('m', 'p', '4', 'v');
2857 case AV_CODEC_ID_SVQ3:
2858 /* FIXME: this is a workaround for older gst-plugins releases
2859 * (<= 0.8.9). This should be removed at some point, because
2860 * it causes wrong decoded frame order. */
2861 if (!context->extradata) {
2862 gint halfpel_flag, thirdpel_flag, low_delay, unknown_svq3_flag;
2865 if (gst_structure_get_int (str, "halfpel_flag", &halfpel_flag) &&
2866 gst_structure_get_int (str, "thirdpel_flag", &thirdpel_flag) &&
2867 gst_structure_get_int (str, "low_delay", &low_delay) &&
2868 gst_structure_get_int (str, "unknown_svq3_flag",
2869 &unknown_svq3_flag)) {
2870 context->extradata = (guint8 *) av_mallocz (0x64);
2871 g_stpcpy ((gchar *) context->extradata, "SVQ3");
2875 flags |= unknown_svq3_flag;
2877 flags |= halfpel_flag;
2879 flags |= thirdpel_flag;
2882 flags = GUINT16_FROM_LE (flags);
2884 memcpy ((gchar *) context->extradata + 0x62, &flags, 2);
2885 context->extradata_size = 0x64;
2890 case AV_CODEC_ID_MSRLE:
2891 case AV_CODEC_ID_QTRLE:
2892 case AV_CODEC_ID_TSCC:
2893 case AV_CODEC_ID_CSCD:
2894 case AV_CODEC_ID_APE:
2898 if (gst_structure_get_int (str, "depth", &depth)) {
2899 context->bits_per_coded_sample = depth;
2901 GST_WARNING ("No depth field in caps %" GST_PTR_FORMAT, caps);
2907 case AV_CODEC_ID_RV10:
2908 case AV_CODEC_ID_RV20:
2909 case AV_CODEC_ID_RV30:
2910 case AV_CODEC_ID_RV40:
2914 if (gst_structure_get_int (str, "format", &format))
2915 context->sub_id = format;
2919 case AV_CODEC_ID_COOK:
2920 case AV_CODEC_ID_RA_288:
2921 case AV_CODEC_ID_RA_144:
2922 case AV_CODEC_ID_SIPR:
2927 if (gst_structure_get_int (str, "leaf_size", &leaf_size))
2928 context->block_align = leaf_size;
2929 if (gst_structure_get_int (str, "bitrate", &bitrate))
2930 context->bit_rate = bitrate;
2932 case AV_CODEC_ID_ALAC:
2933 gst_structure_get_int (str, "samplesize",
2934 &context->bits_per_coded_sample);
2937 case AV_CODEC_ID_DVVIDEO:
2939 const gchar *format;
2941 if ((format = gst_structure_get_string (str, "format"))) {
2943 if (g_str_equal (format, "YUY2"))
2944 context->pix_fmt = PIX_FMT_YUYV422;
2945 else if (g_str_equal (format, "I420"))
2946 context->pix_fmt = PIX_FMT_YUV420P;
2947 else if (g_str_equal (format, "A420"))
2948 context->pix_fmt = PIX_FMT_YUVA420P;
2949 else if (g_str_equal (format, "Y41B"))
2950 context->pix_fmt = PIX_FMT_YUV411P;
2951 else if (g_str_equal (format, "Y42B"))
2952 context->pix_fmt = PIX_FMT_YUV422P;
2953 else if (g_str_equal (format, "YUV9"))
2954 context->pix_fmt = PIX_FMT_YUV410P;
2956 GST_WARNING ("couldn't convert format %s" " to a pixel format",
2960 GST_WARNING ("No specified format");
2963 case AV_CODEC_ID_H263P:
2967 if (!gst_structure_get_boolean (str, "annex-f", &val) || val)
2968 context->flags |= CODEC_FLAG_4MV;
2970 context->flags &= ~CODEC_FLAG_4MV;
2971 if ((!gst_structure_get_boolean (str, "annex-i", &val) || val) &&
2972 (!gst_structure_get_boolean (str, "annex-t", &val) || val))
2973 context->flags |= CODEC_FLAG_AC_PRED;
2975 context->flags &= ~CODEC_FLAG_AC_PRED;
2976 if (!gst_structure_get_boolean (str, "annex-j", &val) || val)
2977 context->flags |= CODEC_FLAG_LOOP_FILTER;
2979 context->flags &= ~CODEC_FLAG_LOOP_FILTER;
2982 case AV_CODEC_ID_ADPCM_G726:
2984 const gchar *layout;
2986 if ((layout = gst_structure_get_string (str, "layout"))) {
2987 if (!strcmp (layout, "g721")) {
2988 context->sample_rate = 8000;
2989 context->channels = 1;
2990 context->bit_rate = 32000;
2999 if (!gst_caps_is_fixed (caps))
3002 /* common properties (width, height, fps) */
3003 switch (codec_type) {
3004 case AVMEDIA_TYPE_VIDEO:
3005 gst_ffmpeg_caps_to_pixfmt (caps, context,
3006 codec_id == AV_CODEC_ID_RAWVIDEO);
3008 case AVMEDIA_TYPE_AUDIO:
3009 gst_ffmpeg_caps_to_smpfmt (caps, context, FALSE);
3015 /* fixup of default settings */
3017 case AV_CODEC_ID_QCELP:
3018 /* QCELP is always mono, no matter what the caps say */
3019 context->channels = 1;
3021 case AV_CODEC_ID_ADPCM_G726:
3022 if (context->sample_rate && context->bit_rate)
3023 context->bits_per_coded_sample =
3024 context->bit_rate / context->sample_rate;
3031 /* _formatid_to_caps () is meant for muxers/demuxers, it
3032 * transforms a name (ffmpeg way of ID'ing these, why don't
3033 * they have unique numerical IDs?) to the corresponding
3034 * caps belonging to that mux-format
3036 * Note: we don't need any additional info because the caps
3037 * isn't supposed to contain any useful info besides the
3042 gst_ffmpeg_formatid_to_caps (const gchar * format_name)
3044 GstCaps *caps = NULL;
3046 if (!strcmp (format_name, "mpeg")) {
3047 caps = gst_caps_new_simple ("video/mpeg",
3048 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3049 } else if (!strcmp (format_name, "mpegts")) {
3050 caps = gst_caps_new_simple ("video/mpegts",
3051 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3052 } else if (!strcmp (format_name, "rm")) {
3053 caps = gst_caps_new_simple ("application/x-pn-realmedia",
3054 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3055 } else if (!strcmp (format_name, "asf")) {
3056 caps = gst_caps_new_empty_simple ("video/x-ms-asf");
3057 } else if (!strcmp (format_name, "avi")) {
3058 caps = gst_caps_new_empty_simple ("video/x-msvideo");
3059 } else if (!strcmp (format_name, "wav")) {
3060 caps = gst_caps_new_empty_simple ("audio/x-wav");
3061 } else if (!strcmp (format_name, "ape")) {
3062 caps = gst_caps_new_empty_simple ("application/x-ape");
3063 } else if (!strcmp (format_name, "swf")) {
3064 caps = gst_caps_new_empty_simple ("application/x-shockwave-flash");
3065 } else if (!strcmp (format_name, "au")) {
3066 caps = gst_caps_new_empty_simple ("audio/x-au");
3067 } else if (!strcmp (format_name, "dv")) {
3068 caps = gst_caps_new_simple ("video/x-dv",
3069 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3070 } else if (!strcmp (format_name, "4xm")) {
3071 caps = gst_caps_new_empty_simple ("video/x-4xm");
3072 } else if (!strcmp (format_name, "matroska")) {
3073 caps = gst_caps_new_empty_simple ("video/x-matroska");
3074 } else if (!strcmp (format_name, "mp3")) {
3075 caps = gst_caps_new_empty_simple ("application/x-id3");
3076 } else if (!strcmp (format_name, "flic")) {
3077 caps = gst_caps_new_empty_simple ("video/x-fli");
3078 } else if (!strcmp (format_name, "flv")) {
3079 caps = gst_caps_new_empty_simple ("video/x-flv");
3080 } else if (!strcmp (format_name, "tta")) {
3081 caps = gst_caps_new_empty_simple ("audio/x-ttafile");
3082 } else if (!strcmp (format_name, "aiff")) {
3083 caps = gst_caps_new_empty_simple ("audio/x-aiff");
3084 } else if (!strcmp (format_name, "mov_mp4_m4a_3gp_3g2")) {
3086 gst_caps_from_string
3087 ("application/x-3gp; video/quicktime; audio/x-m4a");
3088 } else if (!strcmp (format_name, "mov")) {
3089 caps = gst_caps_from_string ("video/quicktime,variant=(string)apple");
3090 } else if (!strcmp (format_name, "mp4")) {
3091 caps = gst_caps_from_string ("video/quicktime,variant=(string)iso");
3092 } else if (!strcmp (format_name, "3gp")) {
3093 caps = gst_caps_from_string ("video/quicktime,variant=(string)3gpp");
3094 } else if (!strcmp (format_name, "3g2")) {
3095 caps = gst_caps_from_string ("video/quicktime,variant=(string)3g2");
3096 } else if (!strcmp (format_name, "psp")) {
3097 caps = gst_caps_from_string ("video/quicktime,variant=(string)psp");
3098 } else if (!strcmp (format_name, "ipod")) {
3099 caps = gst_caps_from_string ("video/quicktime,variant=(string)ipod");
3100 } else if (!strcmp (format_name, "aac")) {
3101 caps = gst_caps_new_simple ("audio/mpeg",
3102 "mpegversion", G_TYPE_INT, 4, NULL);
3103 } else if (!strcmp (format_name, "gif")) {
3104 caps = gst_caps_from_string ("image/gif");
3105 } else if (!strcmp (format_name, "ogg")) {
3106 caps = gst_caps_from_string ("application/ogg");
3107 } else if (!strcmp (format_name, "mxf") || !strcmp (format_name, "mxf_d10")) {
3108 caps = gst_caps_from_string ("application/mxf");
3109 } else if (!strcmp (format_name, "gxf")) {
3110 caps = gst_caps_from_string ("application/gxf");
3111 } else if (!strcmp (format_name, "yuv4mpegpipe")) {
3112 caps = gst_caps_new_simple ("application/x-yuv4mpeg",
3113 "y4mversion", G_TYPE_INT, 2, NULL);
3114 } else if (!strcmp (format_name, "mpc")) {
3115 caps = gst_caps_from_string ("audio/x-musepack, streamversion = (int) 7");
3116 } else if (!strcmp (format_name, "vqf")) {
3117 caps = gst_caps_from_string ("audio/x-vqf");
3118 } else if (!strcmp (format_name, "nsv")) {
3119 caps = gst_caps_from_string ("video/x-nsv");
3120 } else if (!strcmp (format_name, "amr")) {
3121 caps = gst_caps_from_string ("audio/x-amr-nb-sh");
3122 } else if (!strcmp (format_name, "webm")) {
3123 caps = gst_caps_from_string ("video/webm");
3124 } else if (!strcmp (format_name, "voc")) {
3125 caps = gst_caps_from_string ("audio/x-voc");
3126 } else if (!strcmp (format_name, "pva")) {
3127 caps = gst_caps_from_string ("video/x-pva");
3131 GST_LOG ("Could not create stream format caps for %s", format_name);
3132 name = g_strdup_printf ("application/x-gst-av-%s", format_name);
3133 caps = gst_caps_new_empty_simple (name);
3141 gst_ffmpeg_formatid_get_codecids (const gchar * format_name,
3142 enum CodecID ** video_codec_list, enum CodecID ** audio_codec_list,
3143 AVOutputFormat * plugin)
3145 static enum CodecID tmp_vlist[] = {
3149 static enum CodecID tmp_alist[] = {
3154 GST_LOG ("format_name : %s", format_name);
3156 if (!strcmp (format_name, "mp4")) {
3157 static enum CodecID mp4_video_list[] = {
3158 AV_CODEC_ID_MPEG4, AV_CODEC_ID_H264,
3162 static enum CodecID mp4_audio_list[] = {
3163 AV_CODEC_ID_AAC, AV_CODEC_ID_MP3,
3167 *video_codec_list = mp4_video_list;
3168 *audio_codec_list = mp4_audio_list;
3169 } else if (!strcmp (format_name, "mpeg")) {
3170 static enum CodecID mpeg_video_list[] = { AV_CODEC_ID_MPEG1VIDEO,
3171 AV_CODEC_ID_MPEG2VIDEO,
3175 static enum CodecID mpeg_audio_list[] = { AV_CODEC_ID_MP1,
3181 *video_codec_list = mpeg_video_list;
3182 *audio_codec_list = mpeg_audio_list;
3183 } else if (!strcmp (format_name, "dvd")) {
3184 static enum CodecID mpeg_video_list[] = { AV_CODEC_ID_MPEG2VIDEO,
3187 static enum CodecID mpeg_audio_list[] = { AV_CODEC_ID_MP2,
3190 AV_CODEC_ID_PCM_S16BE,
3194 *video_codec_list = mpeg_video_list;
3195 *audio_codec_list = mpeg_audio_list;
3196 } else if (!strcmp (format_name, "mpegts")) {
3197 static enum CodecID mpegts_video_list[] = { AV_CODEC_ID_MPEG1VIDEO,
3198 AV_CODEC_ID_MPEG2VIDEO,
3202 static enum CodecID mpegts_audio_list[] = { AV_CODEC_ID_MP2,
3210 *video_codec_list = mpegts_video_list;
3211 *audio_codec_list = mpegts_audio_list;
3212 } else if (!strcmp (format_name, "vob")) {
3213 static enum CodecID vob_video_list[] =
3214 { AV_CODEC_ID_MPEG2VIDEO, AV_CODEC_ID_NONE };
3215 static enum CodecID vob_audio_list[] = { AV_CODEC_ID_MP2, AV_CODEC_ID_AC3,
3216 AV_CODEC_ID_DTS, AV_CODEC_ID_NONE
3219 *video_codec_list = vob_video_list;
3220 *audio_codec_list = vob_audio_list;
3221 } else if (!strcmp (format_name, "flv")) {
3222 static enum CodecID flv_video_list[] =
3223 { AV_CODEC_ID_FLV1, AV_CODEC_ID_NONE };
3224 static enum CodecID flv_audio_list[] =
3225 { AV_CODEC_ID_MP3, AV_CODEC_ID_NONE };
3227 *video_codec_list = flv_video_list;
3228 *audio_codec_list = flv_audio_list;
3229 } else if (!strcmp (format_name, "asf")) {
3230 static enum CodecID asf_video_list[] =
3231 { AV_CODEC_ID_WMV1, AV_CODEC_ID_WMV2, AV_CODEC_ID_MSMPEG4V3,
3234 static enum CodecID asf_audio_list[] =
3235 { AV_CODEC_ID_WMAV1, AV_CODEC_ID_WMAV2, AV_CODEC_ID_MP3,
3239 *video_codec_list = asf_video_list;
3240 *audio_codec_list = asf_audio_list;
3241 } else if (!strcmp (format_name, "dv")) {
3242 static enum CodecID dv_video_list[] =
3243 { AV_CODEC_ID_DVVIDEO, AV_CODEC_ID_NONE };
3244 static enum CodecID dv_audio_list[] =
3245 { AV_CODEC_ID_PCM_S16LE, AV_CODEC_ID_NONE };
3247 *video_codec_list = dv_video_list;
3248 *audio_codec_list = dv_audio_list;
3249 } else if (!strcmp (format_name, "mov")) {
3250 static enum CodecID mov_video_list[] = {
3251 AV_CODEC_ID_SVQ1, AV_CODEC_ID_SVQ3, AV_CODEC_ID_MPEG4,
3252 AV_CODEC_ID_H263, AV_CODEC_ID_H263P,
3253 AV_CODEC_ID_H264, AV_CODEC_ID_DVVIDEO,
3257 static enum CodecID mov_audio_list[] = {
3258 AV_CODEC_ID_PCM_MULAW, AV_CODEC_ID_PCM_ALAW, AV_CODEC_ID_ADPCM_IMA_QT,
3259 AV_CODEC_ID_MACE3, AV_CODEC_ID_MACE6, AV_CODEC_ID_AAC,
3260 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3261 AV_CODEC_ID_PCM_S16BE, AV_CODEC_ID_PCM_S16LE,
3262 AV_CODEC_ID_MP3, AV_CODEC_ID_NONE
3265 *video_codec_list = mov_video_list;
3266 *audio_codec_list = mov_audio_list;
3267 } else if ((!strcmp (format_name, "3gp") || !strcmp (format_name, "3g2"))) {
3268 static enum CodecID tgp_video_list[] = {
3269 AV_CODEC_ID_MPEG4, AV_CODEC_ID_H263, AV_CODEC_ID_H263P, AV_CODEC_ID_H264,
3272 static enum CodecID tgp_audio_list[] = {
3273 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3278 *video_codec_list = tgp_video_list;
3279 *audio_codec_list = tgp_audio_list;
3280 } else if (!strcmp (format_name, "mmf")) {
3281 static enum CodecID mmf_audio_list[] = {
3282 AV_CODEC_ID_ADPCM_YAMAHA, AV_CODEC_ID_NONE
3284 *video_codec_list = NULL;
3285 *audio_codec_list = mmf_audio_list;
3286 } else if (!strcmp (format_name, "amr")) {
3287 static enum CodecID amr_audio_list[] = {
3288 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3291 *video_codec_list = NULL;
3292 *audio_codec_list = amr_audio_list;
3293 } else if (!strcmp (format_name, "gif")) {
3294 static enum CodecID gif_image_list[] = {
3295 AV_CODEC_ID_RAWVIDEO, AV_CODEC_ID_NONE
3297 *video_codec_list = gif_image_list;
3298 *audio_codec_list = NULL;
3299 } else if ((plugin->audio_codec != AV_CODEC_ID_NONE) ||
3300 (plugin->video_codec != AV_CODEC_ID_NONE)) {
3301 tmp_vlist[0] = plugin->video_codec;
3302 tmp_alist[0] = plugin->audio_codec;
3304 *video_codec_list = tmp_vlist;
3305 *audio_codec_list = tmp_alist;
3306 } else if ((!strcmp (format_name, "pva"))) {
3307 static enum CodecID tgp_video_list[] = {
3308 AV_CODEC_ID_MPEG2VIDEO,
3311 static enum CodecID tgp_audio_list[] = {
3316 *video_codec_list = tgp_video_list;
3317 *audio_codec_list = tgp_audio_list;
3319 GST_LOG ("Format %s not found", format_name);
3326 /* Convert a GstCaps to a FFMPEG codec ID. Size et all
3327 * are omitted, that can be queried by the user itself,
3328 * we're not eating the GstCaps or anything
3329 * A pointer to an allocated context is also needed for
3330 * optional extra info
3334 gst_ffmpeg_caps_to_codecid (const GstCaps * caps, AVCodecContext * context)
3336 enum CodecID id = AV_CODEC_ID_NONE;
3337 const gchar *mimetype;
3338 const GstStructure *structure;
3339 gboolean video = FALSE, audio = FALSE; /* we want to be sure! */
3341 g_return_val_if_fail (caps != NULL, AV_CODEC_ID_NONE);
3342 g_return_val_if_fail (gst_caps_get_size (caps) == 1, AV_CODEC_ID_NONE);
3343 structure = gst_caps_get_structure (caps, 0);
3345 mimetype = gst_structure_get_name (structure);
3347 if (!strcmp (mimetype, "video/x-raw")) {
3348 id = AV_CODEC_ID_RAWVIDEO;
3350 } else if (!strcmp (mimetype, "audio/x-raw")) {
3353 if (gst_audio_info_from_caps (&info, caps)) {
3354 switch (GST_AUDIO_INFO_FORMAT (&info)) {
3355 case GST_AUDIO_FORMAT_S8:
3356 id = AV_CODEC_ID_PCM_S8;
3358 case GST_AUDIO_FORMAT_U8:
3359 id = AV_CODEC_ID_PCM_U8;
3361 case GST_AUDIO_FORMAT_S16LE:
3362 id = AV_CODEC_ID_PCM_S16LE;
3364 case GST_AUDIO_FORMAT_S16BE:
3365 id = AV_CODEC_ID_PCM_S16BE;
3367 case GST_AUDIO_FORMAT_U16LE:
3368 id = AV_CODEC_ID_PCM_U16LE;
3370 case GST_AUDIO_FORMAT_U16BE:
3371 id = AV_CODEC_ID_PCM_U16BE;
3376 if (id != AV_CODEC_ID_NONE)
3379 } else if (!strcmp (mimetype, "audio/x-mulaw")) {
3380 id = AV_CODEC_ID_PCM_MULAW;
3382 } else if (!strcmp (mimetype, "audio/x-alaw")) {
3383 id = AV_CODEC_ID_PCM_ALAW;
3385 } else if (!strcmp (mimetype, "video/x-dv")) {
3388 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3390 id = AV_CODEC_ID_DVVIDEO;
3393 } else if (!strcmp (mimetype, "audio/x-dv")) { /* ??? */
3394 id = AV_CODEC_ID_DVAUDIO;
3396 } else if (!strcmp (mimetype, "video/x-h263")) {
3397 const gchar *h263version =
3398 gst_structure_get_string (structure, "h263version");
3399 if (h263version && !strcmp (h263version, "h263p"))
3400 id = AV_CODEC_ID_H263P;
3402 id = AV_CODEC_ID_H263;
3404 } else if (!strcmp (mimetype, "video/x-intel-h263")) {
3405 id = AV_CODEC_ID_H263I;
3407 } else if (!strcmp (mimetype, "video/x-h261")) {
3408 id = AV_CODEC_ID_H261;
3410 } else if (!strcmp (mimetype, "video/mpeg")) {
3414 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3415 gst_structure_get_int (structure, "mpegversion", &mpegversion) &&
3417 switch (mpegversion) {
3419 id = AV_CODEC_ID_MPEG1VIDEO;
3422 id = AV_CODEC_ID_MPEG2VIDEO;
3425 id = AV_CODEC_ID_MPEG4;
3429 if (id != AV_CODEC_ID_NONE)
3431 } else if (!strcmp (mimetype, "image/jpeg")) {
3432 id = AV_CODEC_ID_MJPEG; /* A... B... */
3434 } else if (!strcmp (mimetype, "video/x-jpeg-b")) {
3435 id = AV_CODEC_ID_MJPEGB;
3437 } else if (!strcmp (mimetype, "video/x-wmv")) {
3438 gint wmvversion = 0;
3440 if (gst_structure_get_int (structure, "wmvversion", &wmvversion)) {
3441 switch (wmvversion) {
3443 id = AV_CODEC_ID_WMV1;
3446 id = AV_CODEC_ID_WMV2;
3450 const gchar *format;
3452 /* WMV3 unless the fourcc exists and says otherwise */
3453 id = AV_CODEC_ID_WMV3;
3455 if ((format = gst_structure_get_string (structure, "format")) &&
3456 (g_str_equal (format, "WVC1") || g_str_equal (format, "WMVA")))
3457 id = AV_CODEC_ID_VC1;
3463 if (id != AV_CODEC_ID_NONE)
3465 } else if (!strcmp (mimetype, "audio/x-vorbis")) {
3466 id = AV_CODEC_ID_VORBIS;
3468 } else if (!strcmp (mimetype, "audio/x-qdm2")) {
3469 id = AV_CODEC_ID_QDM2;
3471 } else if (!strcmp (mimetype, "audio/mpeg")) {
3473 gint mpegversion = 0;
3475 if (gst_structure_get_int (structure, "mpegversion", &mpegversion)) {
3476 switch (mpegversion) {
3477 case 2: /* ffmpeg uses faad for both... */
3479 id = AV_CODEC_ID_AAC;
3482 if (gst_structure_get_int (structure, "layer", &layer)) {
3485 id = AV_CODEC_ID_MP1;
3488 id = AV_CODEC_ID_MP2;
3491 id = AV_CODEC_ID_MP3;
3497 if (id != AV_CODEC_ID_NONE)
3499 } else if (!strcmp (mimetype, "audio/x-musepack")) {
3500 gint streamversion = -1;
3502 if (gst_structure_get_int (structure, "streamversion", &streamversion)) {
3503 if (streamversion == 7)
3504 id = AV_CODEC_ID_MUSEPACK7;
3506 id = AV_CODEC_ID_MUSEPACK7;
3508 } else if (!strcmp (mimetype, "audio/x-wma")) {
3509 gint wmaversion = 0;
3511 if (gst_structure_get_int (structure, "wmaversion", &wmaversion)) {
3512 switch (wmaversion) {
3514 id = AV_CODEC_ID_WMAV1;
3517 id = AV_CODEC_ID_WMAV2;
3520 id = AV_CODEC_ID_WMAPRO;
3524 if (id != AV_CODEC_ID_NONE)
3526 } else if (!strcmp (mimetype, "audio/x-wms")) {
3527 id = AV_CODEC_ID_WMAVOICE;
3529 } else if (!strcmp (mimetype, "audio/x-ac3")) {
3530 id = AV_CODEC_ID_AC3;
3532 } else if (!strcmp (mimetype, "audio/x-eac3")) {
3533 id = AV_CODEC_ID_EAC3;
3535 } else if (!strcmp (mimetype, "audio/x-vnd.sony.atrac3") ||
3536 !strcmp (mimetype, "audio/atrac3")) {
3537 id = AV_CODEC_ID_ATRAC3;
3539 } else if (!strcmp (mimetype, "audio/x-dts")) {
3540 id = AV_CODEC_ID_DTS;
3542 } else if (!strcmp (mimetype, "application/x-ape")) {
3543 id = AV_CODEC_ID_APE;
3545 } else if (!strcmp (mimetype, "video/x-msmpeg")) {
3546 gint msmpegversion = 0;
3548 if (gst_structure_get_int (structure, "msmpegversion", &msmpegversion)) {
3549 switch (msmpegversion) {
3551 id = AV_CODEC_ID_MSMPEG4V1;
3554 id = AV_CODEC_ID_MSMPEG4V2;
3557 id = AV_CODEC_ID_MSMPEG4V3;
3561 if (id != AV_CODEC_ID_NONE)
3563 } else if (!strcmp (mimetype, "video/x-svq")) {
3564 gint svqversion = 0;
3566 if (gst_structure_get_int (structure, "svqversion", &svqversion)) {
3567 switch (svqversion) {
3569 id = AV_CODEC_ID_SVQ1;
3572 id = AV_CODEC_ID_SVQ3;
3576 if (id != AV_CODEC_ID_NONE)
3578 } else if (!strcmp (mimetype, "video/x-huffyuv")) {
3579 id = AV_CODEC_ID_HUFFYUV;
3581 } else if (!strcmp (mimetype, "audio/x-mace")) {
3582 gint maceversion = 0;
3584 if (gst_structure_get_int (structure, "maceversion", &maceversion)) {
3585 switch (maceversion) {
3587 id = AV_CODEC_ID_MACE3;
3590 id = AV_CODEC_ID_MACE6;
3594 if (id != AV_CODEC_ID_NONE)
3596 } else if (!strcmp (mimetype, "video/x-theora")) {
3597 id = AV_CODEC_ID_THEORA;
3599 } else if (!strcmp (mimetype, "video/x-vp3")) {
3600 id = AV_CODEC_ID_VP3;
3602 } else if (!strcmp (mimetype, "video/x-vp5")) {
3603 id = AV_CODEC_ID_VP5;
3605 } else if (!strcmp (mimetype, "video/x-vp6")) {
3606 id = AV_CODEC_ID_VP6;
3608 } else if (!strcmp (mimetype, "video/x-vp6-flash")) {
3609 id = AV_CODEC_ID_VP6F;
3611 } else if (!strcmp (mimetype, "video/x-vp6-alpha")) {
3612 id = AV_CODEC_ID_VP6A;
3614 } else if (!strcmp (mimetype, "video/x-vp8")) {
3615 id = AV_CODEC_ID_VP8;
3617 } else if (!strcmp (mimetype, "video/x-flash-screen")) {
3618 id = AV_CODEC_ID_FLASHSV;
3620 } else if (!strcmp (mimetype, "video/x-indeo")) {
3621 gint indeoversion = 0;
3623 if (gst_structure_get_int (structure, "indeoversion", &indeoversion)) {
3624 switch (indeoversion) {
3626 id = AV_CODEC_ID_INDEO5;
3629 id = AV_CODEC_ID_INDEO4;
3632 id = AV_CODEC_ID_INDEO3;
3635 id = AV_CODEC_ID_INDEO2;
3638 if (id != AV_CODEC_ID_NONE)
3641 } else if (!strcmp (mimetype, "video/x-divx")) {
3642 gint divxversion = 0;
3644 if (gst_structure_get_int (structure, "divxversion", &divxversion)) {
3645 switch (divxversion) {
3647 id = AV_CODEC_ID_MSMPEG4V3;
3651 id = AV_CODEC_ID_MPEG4;
3655 if (id != AV_CODEC_ID_NONE)
3657 } else if (!strcmp (mimetype, "video/x-3ivx")) {
3658 id = AV_CODEC_ID_MPEG4;
3660 } else if (!strcmp (mimetype, "video/x-xvid")) {
3661 id = AV_CODEC_ID_MPEG4;
3663 } else if (!strcmp (mimetype, "video/x-ffv")) {
3664 gint ffvversion = 0;
3666 if (gst_structure_get_int (structure, "ffvversion", &ffvversion) &&
3668 id = AV_CODEC_ID_FFV1;
3671 } else if (!strcmp (mimetype, "audio/x-adpcm")) {
3672 const gchar *layout;
3674 layout = gst_structure_get_string (structure, "layout");
3675 if (layout == NULL) {
3677 } else if (!strcmp (layout, "quicktime")) {
3678 id = AV_CODEC_ID_ADPCM_IMA_QT;
3679 } else if (!strcmp (layout, "microsoft")) {
3680 id = AV_CODEC_ID_ADPCM_MS;
3681 } else if (!strcmp (layout, "dvi")) {
3682 id = AV_CODEC_ID_ADPCM_IMA_WAV;
3683 } else if (!strcmp (layout, "4xm")) {
3684 id = AV_CODEC_ID_ADPCM_4XM;
3685 } else if (!strcmp (layout, "smjpeg")) {
3686 id = AV_CODEC_ID_ADPCM_IMA_SMJPEG;
3687 } else if (!strcmp (layout, "dk3")) {
3688 id = AV_CODEC_ID_ADPCM_IMA_DK3;
3689 } else if (!strcmp (layout, "dk4")) {
3690 id = AV_CODEC_ID_ADPCM_IMA_DK4;
3691 } else if (!strcmp (layout, "westwood")) {
3692 id = AV_CODEC_ID_ADPCM_IMA_WS;
3693 } else if (!strcmp (layout, "iss")) {
3694 id = AV_CODEC_ID_ADPCM_IMA_ISS;
3695 } else if (!strcmp (layout, "xa")) {
3696 id = AV_CODEC_ID_ADPCM_XA;
3697 } else if (!strcmp (layout, "adx")) {
3698 id = AV_CODEC_ID_ADPCM_ADX;
3699 } else if (!strcmp (layout, "ea")) {
3700 id = AV_CODEC_ID_ADPCM_EA;
3701 } else if (!strcmp (layout, "g726")) {
3702 id = AV_CODEC_ID_ADPCM_G726;
3703 } else if (!strcmp (layout, "g721")) {
3704 id = AV_CODEC_ID_ADPCM_G726;
3705 } else if (!strcmp (layout, "ct")) {
3706 id = AV_CODEC_ID_ADPCM_CT;
3707 } else if (!strcmp (layout, "swf")) {
3708 id = AV_CODEC_ID_ADPCM_SWF;
3709 } else if (!strcmp (layout, "yamaha")) {
3710 id = AV_CODEC_ID_ADPCM_YAMAHA;
3711 } else if (!strcmp (layout, "sbpro2")) {
3712 id = AV_CODEC_ID_ADPCM_SBPRO_2;
3713 } else if (!strcmp (layout, "sbpro3")) {
3714 id = AV_CODEC_ID_ADPCM_SBPRO_3;
3715 } else if (!strcmp (layout, "sbpro4")) {
3716 id = AV_CODEC_ID_ADPCM_SBPRO_4;
3718 if (id != AV_CODEC_ID_NONE)
3720 } else if (!strcmp (mimetype, "video/x-4xm")) {
3721 id = AV_CODEC_ID_4XM;
3723 } else if (!strcmp (mimetype, "audio/x-dpcm")) {
3724 const gchar *layout;
3726 layout = gst_structure_get_string (structure, "layout");
3729 } else if (!strcmp (layout, "roq")) {
3730 id = AV_CODEC_ID_ROQ_DPCM;
3731 } else if (!strcmp (layout, "interplay")) {
3732 id = AV_CODEC_ID_INTERPLAY_DPCM;
3733 } else if (!strcmp (layout, "xan")) {
3734 id = AV_CODEC_ID_XAN_DPCM;
3735 } else if (!strcmp (layout, "sol")) {
3736 id = AV_CODEC_ID_SOL_DPCM;
3738 if (id != AV_CODEC_ID_NONE)
3740 } else if (!strcmp (mimetype, "audio/x-flac")) {
3741 id = AV_CODEC_ID_FLAC;
3743 } else if (!strcmp (mimetype, "audio/x-shorten")) {
3744 id = AV_CODEC_ID_SHORTEN;
3746 } else if (!strcmp (mimetype, "audio/x-alac")) {
3747 id = AV_CODEC_ID_ALAC;
3749 } else if (!strcmp (mimetype, "video/x-cinepak")) {
3750 id = AV_CODEC_ID_CINEPAK;
3752 } else if (!strcmp (mimetype, "video/x-pn-realvideo")) {
3755 if (gst_structure_get_int (structure, "rmversion", &rmversion)) {
3756 switch (rmversion) {
3758 id = AV_CODEC_ID_RV10;
3761 id = AV_CODEC_ID_RV20;
3764 id = AV_CODEC_ID_RV30;
3767 id = AV_CODEC_ID_RV40;
3771 if (id != AV_CODEC_ID_NONE)
3773 } else if (!strcmp (mimetype, "audio/x-sipro")) {
3774 id = AV_CODEC_ID_SIPR;
3776 } else if (!strcmp (mimetype, "audio/x-pn-realaudio")) {
3779 if (gst_structure_get_int (structure, "raversion", &raversion)) {
3780 switch (raversion) {
3782 id = AV_CODEC_ID_RA_144;
3785 id = AV_CODEC_ID_RA_288;
3788 id = AV_CODEC_ID_COOK;
3792 if (id != AV_CODEC_ID_NONE)
3794 } else if (!strcmp (mimetype, "video/x-rle")) {
3795 const gchar *layout;
3797 if ((layout = gst_structure_get_string (structure, "layout"))) {
3798 if (!strcmp (layout, "microsoft")) {
3799 id = AV_CODEC_ID_MSRLE;
3803 } else if (!strcmp (mimetype, "video/x-xan")) {
3806 if ((gst_structure_get_int (structure, "wcversion", &wcversion))) {
3807 switch (wcversion) {
3809 id = AV_CODEC_ID_XAN_WC3;
3813 id = AV_CODEC_ID_XAN_WC4;
3820 } else if (!strcmp (mimetype, "audio/AMR")) {
3822 id = AV_CODEC_ID_AMR_NB;
3823 } else if (!strcmp (mimetype, "audio/AMR-WB")) {
3824 id = AV_CODEC_ID_AMR_WB;
3826 } else if (!strcmp (mimetype, "audio/qcelp")) {
3827 id = AV_CODEC_ID_QCELP;
3829 } else if (!strcmp (mimetype, "video/x-h264")) {
3830 id = AV_CODEC_ID_H264;
3832 } else if (!strcmp (mimetype, "video/x-flash-video")) {
3833 gint flvversion = 0;
3835 if ((gst_structure_get_int (structure, "flvversion", &flvversion))) {
3836 switch (flvversion) {
3838 id = AV_CODEC_ID_FLV1;
3846 } else if (!strcmp (mimetype, "audio/x-nellymoser")) {
3847 id = AV_CODEC_ID_NELLYMOSER;
3849 } else if (!strncmp (mimetype, "audio/x-gst-av-", 15)) {
3853 if (strlen (mimetype) <= 30 &&
3854 sscanf (mimetype, "audio/x-gst-av-%s", ext) == 1) {
3855 if ((codec = avcodec_find_decoder_by_name (ext)) ||
3856 (codec = avcodec_find_encoder_by_name (ext))) {
3861 } else if (!strncmp (mimetype, "video/x-gst-av-", 15)) {
3865 if (strlen (mimetype) <= 30 &&
3866 sscanf (mimetype, "video/x-gst-av-%s", ext) == 1) {
3867 if ((codec = avcodec_find_decoder_by_name (ext)) ||
3868 (codec = avcodec_find_encoder_by_name (ext))) {
3875 if (context != NULL) {
3876 if (video == TRUE) {
3877 context->codec_type = AVMEDIA_TYPE_VIDEO;
3878 } else if (audio == TRUE) {
3879 context->codec_type = AVMEDIA_TYPE_AUDIO;
3881 context->codec_type = AVMEDIA_TYPE_UNKNOWN;
3883 context->codec_id = id;
3884 gst_ffmpeg_caps_with_codecid (id, context->codec_type, caps, context);
3887 if (id != AV_CODEC_ID_NONE) {
3888 GST_DEBUG ("The id=%d belongs to the caps %" GST_PTR_FORMAT, id, caps);
3890 GST_WARNING ("Couldn't figure out the id for caps %" GST_PTR_FORMAT, caps);