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 gst_value_list_append_value (&va, &v);
198 if (gst_value_list_get_size (&va) == 1) {
199 /* The single value is still in v */
200 gst_caps_set_value (caps, "format", &v);
201 } else if (gst_value_list_get_size (&va) > 1) {
202 gst_caps_set_value (caps, "format", &va);
208 /* this macro makes a caps width fixed or unfixed width/height
209 * properties depending on whether we've got a context.
211 * See below for why we use this.
213 * We should actually do this stuff at the end, like in riff-media.c,
214 * but I'm too lazy today. Maybe later.
217 gst_ff_vid_caps_new (AVCodecContext * context, AVCodec * codec,
218 enum CodecID codec_id, gboolean encode, const char *mimetype,
219 const char *fieldname, ...)
221 GstCaps *caps = NULL;
225 GST_LOG ("context:%p, codec_id:%d, mimetype:%s", context, codec_id, mimetype);
227 /* fixed, non probing context */
228 if (context != NULL && context->width != -1) {
231 caps = gst_caps_new_simple (mimetype,
232 "width", G_TYPE_INT, context->width,
233 "height", G_TYPE_INT, context->height, NULL);
235 num = context->time_base.den / context->ticks_per_frame;
236 denom = context->time_base.num;
239 GST_LOG ("invalid framerate: %d/0, -> %d/1", num, num);
242 if (gst_util_fraction_compare (num, denom, 1000, 1) > 0) {
243 GST_LOG ("excessive framerate: %d/%d, -> 0/1", num, denom);
247 GST_LOG ("setting framerate: %d/%d", num, denom);
248 gst_caps_set_simple (caps,
249 "framerate", GST_TYPE_FRACTION, num, denom, NULL);
251 /* so we are after restricted caps in this case */
253 case AV_CODEC_ID_H261:
255 caps = gst_caps_new_simple (mimetype,
256 "width", G_TYPE_INT, 352,
257 "height", G_TYPE_INT, 288,
258 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
259 gst_caps_append (caps, gst_caps_new_simple (mimetype,
260 "width", G_TYPE_INT, 176,
261 "height", G_TYPE_INT, 144,
262 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL));
265 case AV_CODEC_ID_H263:
267 /* 128x96, 176x144, 352x288, 704x576, and 1408x1152. slightly reordered
268 * because we want automatic negotiation to go as close to 320x240 as
270 const static gint widths[] = { 352, 704, 176, 1408, 128 };
271 const static gint heights[] = { 288, 576, 144, 1152, 96 };
273 gint n_sizes = G_N_ELEMENTS (widths);
275 caps = gst_caps_new_empty ();
276 for (i = 0; i < n_sizes; i++) {
277 temp = gst_caps_new_simple (mimetype,
278 "width", G_TYPE_INT, widths[i],
279 "height", G_TYPE_INT, heights[i],
280 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
282 gst_caps_append (caps, temp);
286 case AV_CODEC_ID_DVVIDEO:
293 gint framerate_n, framerate_d;
296 "Y41B", 720, 480, 8, 9, 30000, 1001}, {
297 "Y41B", 720, 480, 32, 27, 30000, 1001}, {
298 "Y42B", 720, 480, 8, 9, 30000, 1001}, {
299 "Y42B", 720, 480, 32, 27, 30000, 1001}, {
300 "I420", 720, 576, 16, 15, 25, 1}, {
301 "I420", 720, 576, 64, 45, 25, 1}, {
302 "Y41B", 720, 576, 16, 15, 25, 1}, {
303 "Y41B", 720, 576, 64, 45, 25, 1}, {
304 "Y42B", 720, 576, 16, 15, 25, 1}, {
305 "Y42B", 720, 576, 64, 45, 25, 1}, {
306 "Y42B", 1280, 1080, 1, 1, 30000, 1001}, {
307 "Y42B", 1280, 1080, 3, 2, 30000, 1001}, {
308 "Y42B", 1440, 1080, 1, 1, 25, 1}, {
309 "Y42B", 1440, 1080, 4, 3, 25, 1}, {
310 "Y42B", 960, 720, 1, 1, 60000, 1001}, {
311 "Y42B", 960, 720, 4, 3, 60000, 1001}, {
312 "Y42B", 960, 720, 1, 1, 50, 1}, {
313 "Y42B", 960, 720, 4, 3, 50, 1},};
315 gint n_sizes = G_N_ELEMENTS (profiles);
317 if (strcmp (mimetype, "video/x-raw") == 0) {
318 caps = gst_caps_new_empty ();
319 for (i = 0; i < n_sizes; i++) {
320 temp = gst_caps_new_simple (mimetype,
321 "format", G_TYPE_STRING, profiles[i].csp,
322 "width", G_TYPE_INT, profiles[i].width,
323 "height", G_TYPE_INT, profiles[i].height,
324 "framerate", GST_TYPE_FRACTION, profiles[i].framerate_n,
325 profiles[i].framerate_d, "pixel-aspect-ratio",
326 GST_TYPE_FRACTION, profiles[i].par_n, profiles[i].par_d, NULL);
328 gst_caps_append (caps, temp);
331 caps = gst_caps_new_empty ();
332 for (i = 0; i < n_sizes; i++) {
333 temp = gst_caps_new_simple (mimetype,
334 "width", G_TYPE_INT, profiles[i].width,
335 "height", G_TYPE_INT, profiles[i].height,
336 "framerate", GST_TYPE_FRACTION, profiles[i].framerate_n,
337 profiles[i].framerate_d, "pixel-aspect-ratio",
338 GST_TYPE_FRACTION, profiles[i].par_n, profiles[i].par_d, NULL);
340 gst_caps_append (caps, temp);
345 case AV_CODEC_ID_DNXHD:
347 caps = gst_caps_new_simple (mimetype,
348 "width", G_TYPE_INT, 1920,
349 "height", G_TYPE_INT, 1080,
350 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
351 gst_caps_append (caps, gst_caps_new_simple (mimetype,
352 "width", G_TYPE_INT, 1280,
353 "height", G_TYPE_INT, 720,
354 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL));
359 if (codec && codec->supported_framerates
360 && codec->supported_framerates[0].num != 0
361 && codec->supported_framerates[0].den != 0) {
364 const AVRational *rates = codec->supported_framerates;
366 if (rates[1].num == 0 && rates[1].den == 0) {
368 gst_caps_new_simple (mimetype, "framerate", GST_TYPE_FRACTION,
369 rates[0].num, rates[0].den, NULL);
371 g_value_init (&va, GST_TYPE_LIST);
372 g_value_init (&v, GST_TYPE_FRACTION);
374 while (rates->num != 0 && rates->den != 0) {
375 gst_value_set_fraction (&v, rates->num, rates->den);
376 gst_value_list_append_value (&va, &v);
380 caps = gst_caps_new_simple (mimetype, NULL, NULL, NULL);
381 gst_caps_set_value (caps, "framerate", &va);
387 caps = gst_caps_new_empty_simple (mimetype);
395 /* no fixed caps or special restrictions applied;
396 * default unfixed setting */
398 GST_DEBUG ("Creating default caps");
399 caps = gst_caps_new_empty_simple (mimetype);
402 va_start (var_args, fieldname);
403 gst_caps_set_simple_valist (caps, fieldname, var_args);
410 get_nbits_set (guint64 n)
415 for (i = 0; i < 64; i++) {
416 if ((n & (G_GUINT64_CONSTANT (1) << i)))
424 gst_ffmpeg_audio_set_sample_fmts (GstCaps * caps,
425 const enum AVSampleFormat *fmts)
429 GstAudioFormat format;
431 if (!fmts || fmts[0] == -1) {
434 g_value_init (&va, GST_TYPE_LIST);
435 g_value_init (&v, G_TYPE_STRING);
436 for (i = 0; i <= AV_SAMPLE_FMT_DBL; i++) {
437 format = gst_ffmpeg_smpfmt_to_audioformat (i);
438 if (format == GST_AUDIO_FORMAT_UNKNOWN)
440 g_value_set_string (&v, gst_audio_format_to_string (format));
441 gst_value_list_append_value (&va, &v);
443 gst_caps_set_value (caps, "format", &va);
449 g_value_init (&va, GST_TYPE_LIST);
450 g_value_init (&v, G_TYPE_STRING);
451 while (*fmts != -1) {
452 format = gst_ffmpeg_smpfmt_to_audioformat (*fmts);
453 if (format != GST_AUDIO_FORMAT_UNKNOWN) {
454 g_value_set_string (&v, gst_audio_format_to_string (format));
455 gst_value_list_append_value (&va, &v);
459 if (gst_value_list_get_size (&va) == 1) {
460 /* The single value is still in v */
461 gst_caps_set_value (caps, "format", &v);
462 } else if (gst_value_list_get_size (&va) > 1) {
463 gst_caps_set_value (caps, "format", &va);
469 /* same for audio - now with channels/sample rate
472 gst_ff_aud_caps_new (AVCodecContext * context, AVCodec * codec,
473 enum CodecID codec_id, gboolean encode, const char *mimetype,
474 const char *fieldname, ...)
476 GstCaps *caps = NULL;
480 /* fixed, non-probing context */
481 if (context != NULL && context->channels != -1) {
482 GstAudioChannelPosition pos[64];
484 caps = gst_caps_new_simple (mimetype,
485 "rate", G_TYPE_INT, context->sample_rate,
486 "channels", G_TYPE_INT, context->channels, NULL);
488 if (gst_ffmpeg_channel_layout_to_gst (context->channel_layout,
489 context->channels, pos)) {
492 if (gst_audio_channel_positions_to_mask (pos, context->channels, FALSE,
494 gst_caps_set_simple (caps, "channel-mask", GST_TYPE_BITMASK, mask,
499 gint maxchannels = 2;
500 const gint *rates = NULL;
503 /* so we must be after restricted caps in this case */
505 case AV_CODEC_ID_AAC:
506 case AV_CODEC_ID_AAC_LATM:
507 case AV_CODEC_ID_DTS:
510 case AV_CODEC_ID_MP2:
512 const static gint l_rates[] =
513 { 48000, 44100, 32000, 24000, 22050, 16000 };
514 n_rates = G_N_ELEMENTS (l_rates);
518 case AV_CODEC_ID_EAC3:
519 case AV_CODEC_ID_AC3:
521 const static gint l_rates[] = { 48000, 44100, 32000 };
523 n_rates = G_N_ELEMENTS (l_rates);
527 case AV_CODEC_ID_ADPCM_G722:
529 const static gint l_rates[] = { 16000 };
530 n_rates = G_N_ELEMENTS (l_rates);
535 case AV_CODEC_ID_ADPCM_G726:
537 const static gint l_rates[] = { 8000 };
538 n_rates = G_N_ELEMENTS (l_rates);
543 case AV_CODEC_ID_ADPCM_SWF:
545 const static gint l_rates[] = { 11025, 22050, 44100 };
546 n_rates = G_N_ELEMENTS (l_rates);
550 case AV_CODEC_ID_ROQ_DPCM:
552 const static gint l_rates[] = { 22050 };
553 n_rates = G_N_ELEMENTS (l_rates);
557 case AV_CODEC_ID_AMR_NB:
559 const static gint l_rates[] = { 8000 };
561 n_rates = G_N_ELEMENTS (l_rates);
565 case AV_CODEC_ID_AMR_WB:
567 const static gint l_rates[] = { 16000 };
569 n_rates = G_N_ELEMENTS (l_rates);
577 /* regardless of encode/decode, open up channels if applicable */
578 /* Until decoders/encoders expose the maximum number of channels
579 * they support, we whitelist them here. */
581 case AV_CODEC_ID_WMAPRO:
582 case AV_CODEC_ID_TRUEHD:
589 if (codec && codec->channel_layouts) {
590 const uint64_t *layouts = codec->channel_layouts;
591 GstAudioChannelPosition pos[64];
593 caps = gst_caps_new_empty ();
595 gint nbits_set = get_nbits_set (*layouts);
597 if (gst_ffmpeg_channel_layout_to_gst (*layouts, nbits_set, pos)) {
600 if (gst_audio_channel_positions_to_mask (pos, nbits_set, FALSE,
603 gst_caps_new_simple (mimetype, "channel-mask", GST_TYPE_BITMASK,
605 "channels", G_TYPE_INT, nbits_set, NULL);
607 gst_caps_append (caps, tmp);
613 if (maxchannels == 1)
614 caps = gst_caps_new_simple (mimetype,
615 "channels", G_TYPE_INT, maxchannels, NULL);
617 caps = gst_caps_new_simple (mimetype,
618 "channels", GST_TYPE_INT_RANGE, 1, maxchannels, NULL);
622 GValue list = { 0, };
624 g_value_init (&list, GST_TYPE_LIST);
625 for (i = 0; i < n_rates; i++) {
628 g_value_init (&v, G_TYPE_INT);
629 g_value_set_int (&v, rates[i]);
630 gst_value_list_append_value (&list, &v);
633 gst_caps_set_value (caps, "rate", &list);
634 g_value_unset (&list);
635 } else if (codec && codec->supported_samplerates
636 && codec->supported_samplerates[0]) {
640 if (!codec->supported_samplerates[1]) {
641 gst_caps_set_simple (caps, "rate", G_TYPE_INT,
642 codec->supported_samplerates[0], NULL);
644 const int *rates = codec->supported_samplerates;
646 g_value_init (&va, GST_TYPE_LIST);
647 g_value_init (&v, G_TYPE_INT);
650 g_value_set_int (&v, *rates);
651 gst_value_list_append_value (&va, &v);
654 gst_caps_set_value (caps, "rate", &va);
659 gst_caps_set_simple (caps, "rate", GST_TYPE_INT_RANGE, 4000, 96000, NULL);
662 caps = gst_caps_new_empty_simple (mimetype);
665 va_start (var_args, fieldname);
666 gst_caps_set_simple_valist (caps, fieldname, var_args);
672 /* Convert a FFMPEG codec ID and optional AVCodecContext
673 * to a GstCaps. If the context is ommitted, no fixed values
674 * for video/audio size will be included in the GstCaps
676 * CodecID is primarily meant for compressed data GstCaps!
678 * encode is a special parameter. gstffmpegdec will say
679 * FALSE, gstffmpegenc will say TRUE. The output caps
680 * depends on this, in such a way that it will be very
681 * specific, defined, fixed and correct caps for encoders,
682 * yet very wide, "forgiving" caps for decoders. Example
683 * for mp3: decode: audio/mpeg,mpegversion=1,layer=[1-3]
684 * but encode: audio/mpeg,mpegversion=1,layer=3,bitrate=x,
689 gst_ffmpeg_codecid_to_caps (enum CodecID codec_id,
690 AVCodecContext * context, gboolean encode)
692 GstCaps *caps = NULL;
693 gboolean buildcaps = FALSE;
695 GST_LOG ("codec_id:%d, context:%p, encode:%d", codec_id, context, encode);
698 case AV_CODEC_ID_MPEG1VIDEO:
700 caps = gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
701 "mpegversion", G_TYPE_INT, 1,
702 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
705 case AV_CODEC_ID_MPEG2VIDEO:
709 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
710 "mpegversion", G_TYPE_INT, 2, "systemstream", G_TYPE_BOOLEAN, FALSE,
713 /* decode both MPEG-1 and MPEG-2; width/height/fps are all in
714 * the MPEG video stream headers, so may be omitted from caps. */
715 caps = gst_caps_new_simple ("video/mpeg",
716 "mpegversion", GST_TYPE_INT_RANGE, 1, 2,
717 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
721 case AV_CODEC_ID_MPEG2VIDEO_XVMC:
722 /* this is a special ID - don't need it in GStreamer, I think */
725 case AV_CODEC_ID_H263:
728 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
729 "video/x-h263", "variant", G_TYPE_STRING, "itu", "h263version",
730 G_TYPE_STRING, "h263", NULL);
732 /* don't pass codec_id, we can decode other variants with the H263
733 * decoder that don't have specific size requirements
736 gst_ff_vid_caps_new (context, NULL, AV_CODEC_ID_NONE, encode,
737 "video/x-h263", "variant", G_TYPE_STRING, "itu", NULL);
741 case AV_CODEC_ID_H263P:
743 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h263",
744 "variant", G_TYPE_STRING, "itu", "h263version", G_TYPE_STRING,
746 if (encode && context) {
748 gst_caps_set_simple (caps,
749 "annex-f", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_4MV,
750 "annex-j", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_LOOP_FILTER,
751 "annex-i", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_AC_PRED,
752 "annex-t", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_AC_PRED,
757 case AV_CODEC_ID_H263I:
759 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
760 "video/x-intel-h263", "variant", G_TYPE_STRING, "intel", NULL);
763 case AV_CODEC_ID_H261:
765 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h261",
769 case AV_CODEC_ID_RV10:
770 case AV_CODEC_ID_RV20:
771 case AV_CODEC_ID_RV30:
772 case AV_CODEC_ID_RV40:
777 case AV_CODEC_ID_RV40:
780 case AV_CODEC_ID_RV30:
783 case AV_CODEC_ID_RV20:
791 /* FIXME: context->sub_id must be filled in during decoding */
793 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
794 "video/x-pn-realvideo", "rmversion", G_TYPE_INT, version, NULL);
796 gst_caps_set_simple (caps, "format", G_TYPE_INT, context->sub_id, NULL);
797 if (context->extradata_size >= 8) {
798 gst_caps_set_simple (caps,
799 "subformat", G_TYPE_INT, GST_READ_UINT32_BE (context->extradata),
806 case AV_CODEC_ID_MP1:
808 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
809 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 1, NULL);
812 case AV_CODEC_ID_MP2:
814 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
815 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 2, NULL);
818 case AV_CODEC_ID_MP3:
822 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
823 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 3, NULL);
825 /* Decodes MPEG-1 layer 1/2/3. Samplerate, channels et al are
826 * in the MPEG audio header, so may be omitted from caps. */
827 caps = gst_caps_new_simple ("audio/mpeg",
828 "mpegversion", G_TYPE_INT, 1,
829 "layer", GST_TYPE_INT_RANGE, 1, 3, NULL);
833 case AV_CODEC_ID_MUSEPACK7:
835 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
836 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 7,
840 case AV_CODEC_ID_MUSEPACK8:
842 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
843 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 8,
847 case AV_CODEC_ID_AC3:
850 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-ac3",
854 case AV_CODEC_ID_EAC3:
857 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-eac3",
861 case AV_CODEC_ID_TRUEHD:
863 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
864 "audio/x-true-hd", NULL);
867 case AV_CODEC_ID_ATRAC1:
869 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
870 "audio/x-vnd.sony.atrac1", NULL);
873 case AV_CODEC_ID_ATRAC3:
875 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
876 "audio/x-vnd.sony.atrac3", NULL);
879 case AV_CODEC_ID_DTS:
881 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dts",
885 case AV_CODEC_ID_APE:
887 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
888 "audio/x-ffmpeg-parsed-ape", NULL);
890 gst_caps_set_simple (caps,
891 "depth", G_TYPE_INT, context->bits_per_coded_sample, NULL);
895 case AV_CODEC_ID_MLP:
897 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mlp",
901 case AV_CODEC_ID_IMC:
903 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-imc",
907 /* MJPEG is normal JPEG, Motion-JPEG and Quicktime MJPEG-A. MJPEGB
908 * is Quicktime's MJPEG-B. LJPEG is lossless JPEG. I don't know what
909 * sp5x is, but it's apparently something JPEG... We don't separate
910 * between those in GStreamer. Should we (at least between MJPEG,
911 * MJPEG-B and sp5x decoding...)? */
912 case AV_CODEC_ID_MJPEG:
913 case AV_CODEC_ID_LJPEG:
915 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/jpeg",
919 case AV_CODEC_ID_SP5X:
921 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/sp5x",
925 case AV_CODEC_ID_MJPEGB:
927 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
928 "video/x-mjpeg-b", NULL);
931 case AV_CODEC_ID_MPEG4:
932 if (encode && context != NULL) {
933 /* I'm not exactly sure what ffmpeg outputs... ffmpeg itself uses
934 * the AVI fourcc 'DIVX', but 'mp4v' for Quicktime... */
935 switch (context->codec_tag) {
936 case GST_MAKE_FOURCC ('D', 'I', 'V', 'X'):
938 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
939 "video/x-divx", "divxversion", G_TYPE_INT, 5, NULL);
941 case GST_MAKE_FOURCC ('m', 'p', '4', 'v'):
945 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
946 "video/mpeg", "systemstream", G_TYPE_BOOLEAN, FALSE,
947 "mpegversion", G_TYPE_INT, 4, NULL);
951 /* The trick here is to separate xvid, divx, mpeg4, 3ivx et al */
953 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
954 "mpegversion", G_TYPE_INT, 4, "systemstream", G_TYPE_BOOLEAN, FALSE,
957 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
958 encode, "video/x-divx", "divxversion", G_TYPE_INT, 5, NULL));
960 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
961 encode, "video/x-divx", "divxversion", GST_TYPE_INT_RANGE, 4,
963 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
964 encode, "video/x-xvid", NULL));
965 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
966 encode, "video/x-3ivx", NULL));
971 case AV_CODEC_ID_RAWVIDEO:
973 gst_ffmpeg_codectype_to_video_caps (context, codec_id, encode, NULL);
976 case AV_CODEC_ID_MSMPEG4V1:
977 case AV_CODEC_ID_MSMPEG4V2:
978 case AV_CODEC_ID_MSMPEG4V3:
980 gint version = 41 + codec_id - AV_CODEC_ID_MSMPEG4V1;
982 /* encode-FIXME: bitrate */
984 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
985 "video/x-msmpeg", "msmpegversion", G_TYPE_INT, version, NULL);
986 if (!encode && codec_id == AV_CODEC_ID_MSMPEG4V3) {
987 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
988 encode, "video/x-divx", "divxversion", G_TYPE_INT, 3, NULL));
993 case AV_CODEC_ID_WMV1:
994 case AV_CODEC_ID_WMV2:
996 gint version = (codec_id == AV_CODEC_ID_WMV1) ? 1 : 2;
999 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1000 "wmvversion", G_TYPE_INT, version, NULL);
1004 case AV_CODEC_ID_FLV1:
1006 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1007 "video/x-flash-video", "flvversion", G_TYPE_INT, 1, NULL);
1010 case AV_CODEC_ID_SVQ1:
1012 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-svq",
1013 "svqversion", G_TYPE_INT, 1, NULL);
1016 case AV_CODEC_ID_SVQ3:
1018 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-svq",
1019 "svqversion", G_TYPE_INT, 3, NULL);
1022 case AV_CODEC_ID_DVAUDIO:
1024 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dv",
1028 case AV_CODEC_ID_DVVIDEO:
1030 if (encode && context) {
1031 const gchar *format;
1033 switch (context->pix_fmt) {
1034 case PIX_FMT_YUYV422:
1037 case PIX_FMT_YUV420P:
1040 case PIX_FMT_YUVA420P:
1043 case PIX_FMT_YUV411P:
1046 case PIX_FMT_YUV422P:
1049 case PIX_FMT_YUV410P:
1054 ("Couldnt' find format for pixfmt %d, defaulting to I420",
1060 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dv",
1061 "systemstream", G_TYPE_BOOLEAN, FALSE, "format", G_TYPE_STRING,
1065 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dv",
1066 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
1071 case AV_CODEC_ID_WMAV1:
1072 case AV_CODEC_ID_WMAV2:
1074 gint version = (codec_id == AV_CODEC_ID_WMAV1) ? 1 : 2;
1078 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1079 "wmaversion", G_TYPE_INT, version, "block_align", G_TYPE_INT,
1080 context->block_align, "bitrate", G_TYPE_INT, context->bit_rate,
1084 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1085 "wmaversion", G_TYPE_INT, version, "block_align",
1086 GST_TYPE_INT_RANGE, 0, G_MAXINT, "bitrate", GST_TYPE_INT_RANGE, 0,
1091 case AV_CODEC_ID_WMAPRO:
1094 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1095 "wmaversion", G_TYPE_INT, 3, NULL);
1098 case AV_CODEC_ID_WMALOSSLESS:
1100 /* libav only supports a depth of 16 at the moment */
1102 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1103 "wmaversion", G_TYPE_INT, 4, "depth", G_TYPE_INT, 16, NULL);
1106 case AV_CODEC_ID_WMAVOICE:
1109 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wms",
1114 case AV_CODEC_ID_MACE3:
1115 case AV_CODEC_ID_MACE6:
1117 gint version = (codec_id == AV_CODEC_ID_MACE3) ? 3 : 6;
1120 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mace",
1121 "maceversion", G_TYPE_INT, version, NULL);
1125 case AV_CODEC_ID_HUFFYUV:
1127 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1128 "video/x-huffyuv", NULL);
1130 gst_caps_set_simple (caps,
1131 "bpp", G_TYPE_INT, context->bits_per_coded_sample, NULL);
1135 case AV_CODEC_ID_CYUV:
1137 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1138 "video/x-compressed-yuv", NULL);
1141 case AV_CODEC_ID_H264:
1143 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h264",
1144 "alignment", G_TYPE_STRING, "au", NULL);
1146 GValue arr = { 0, };
1147 GValue item = { 0, };
1148 g_value_init (&arr, GST_TYPE_LIST);
1149 g_value_init (&item, G_TYPE_STRING);
1150 g_value_set_string (&item, "avc");
1151 gst_value_list_append_value (&arr, &item);
1152 g_value_set_string (&item, "byte-stream");
1153 gst_value_list_append_value (&arr, &item);
1154 g_value_unset (&item);
1155 gst_caps_set_value (caps, "stream-format", &arr);
1156 g_value_unset (&arr);
1160 case AV_CODEC_ID_INDEO5:
1162 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1163 "indeoversion", G_TYPE_INT, 5, NULL);
1166 case AV_CODEC_ID_INDEO4:
1168 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1169 "indeoversion", G_TYPE_INT, 4, NULL);
1172 case AV_CODEC_ID_INDEO3:
1174 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1175 "indeoversion", G_TYPE_INT, 3, NULL);
1178 case AV_CODEC_ID_INDEO2:
1180 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1181 "indeoversion", G_TYPE_INT, 2, NULL);
1184 case AV_CODEC_ID_FLASHSV:
1186 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1187 "video/x-flash-screen", NULL);
1190 case AV_CODEC_ID_VP3:
1192 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp3",
1196 case AV_CODEC_ID_VP5:
1198 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp5",
1202 case AV_CODEC_ID_VP6:
1204 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp6",
1208 case AV_CODEC_ID_VP6F:
1210 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1211 "video/x-vp6-flash", NULL);
1214 case AV_CODEC_ID_VP6A:
1216 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1217 "video/x-vp6-alpha", NULL);
1220 case AV_CODEC_ID_VP8:
1222 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp8",
1226 case AV_CODEC_ID_THEORA:
1228 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1229 "video/x-theora", NULL);
1232 case AV_CODEC_ID_AAC:
1235 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
1239 GValue arr = { 0, };
1240 GValue item = { 0, };
1242 g_value_init (&arr, GST_TYPE_LIST);
1243 g_value_init (&item, G_TYPE_INT);
1244 g_value_set_int (&item, 2);
1245 gst_value_list_append_value (&arr, &item);
1246 g_value_set_int (&item, 4);
1247 gst_value_list_append_value (&arr, &item);
1248 g_value_unset (&item);
1250 gst_caps_set_value (caps, "mpegversion", &arr);
1251 g_value_unset (&arr);
1253 g_value_init (&arr, GST_TYPE_LIST);
1254 g_value_init (&item, G_TYPE_STRING);
1255 g_value_set_string (&item, "raw");
1256 gst_value_list_append_value (&arr, &item);
1257 g_value_set_string (&item, "adts");
1258 gst_value_list_append_value (&arr, &item);
1259 g_value_set_string (&item, "adif");
1260 gst_value_list_append_value (&arr, &item);
1261 g_value_unset (&item);
1263 gst_caps_set_value (caps, "stream-format", &arr);
1264 g_value_unset (&arr);
1266 gst_caps_set_simple (caps, "mpegversion", G_TYPE_INT, 4,
1267 "stream-format", G_TYPE_STRING, "raw",
1268 "base-profile", G_TYPE_STRING, "lc", NULL);
1270 if (context && context->extradata_size > 0)
1271 gst_codec_utils_aac_caps_set_level_and_profile (caps,
1272 context->extradata, context->extradata_size);
1277 case AV_CODEC_ID_AAC_LATM: /* LATM/LOAS AAC syntax */
1278 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
1279 "mpegversion", G_TYPE_INT, 4, "stream-format", G_TYPE_STRING, "loas",
1283 case AV_CODEC_ID_ASV1:
1285 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-asus",
1286 "asusversion", G_TYPE_INT, 1, NULL);
1288 case AV_CODEC_ID_ASV2:
1290 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-asus",
1291 "asusversion", G_TYPE_INT, 2, NULL);
1294 case AV_CODEC_ID_FFV1:
1296 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-ffv",
1297 "ffvversion", G_TYPE_INT, 1, NULL);
1300 case AV_CODEC_ID_4XM:
1302 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-4xm",
1306 case AV_CODEC_ID_XAN_WC3:
1307 case AV_CODEC_ID_XAN_WC4:
1309 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-xan",
1310 "wcversion", G_TYPE_INT, 3 - AV_CODEC_ID_XAN_WC3 + codec_id, NULL);
1313 case AV_CODEC_ID_CLJR:
1315 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1316 "video/x-cirrus-logic-accupak", NULL);
1319 case AV_CODEC_ID_FRAPS:
1321 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-fraps",
1325 case AV_CODEC_ID_MDEC:
1326 case AV_CODEC_ID_ROQ:
1327 case AV_CODEC_ID_INTERPLAY_VIDEO:
1331 case AV_CODEC_ID_VCR1:
1333 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1334 "video/x-ati-vcr", "vcrversion", G_TYPE_INT, 1, NULL);
1337 case AV_CODEC_ID_RPZA:
1339 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1340 "video/x-apple-video", NULL);
1343 case AV_CODEC_ID_CINEPAK:
1345 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1346 "video/x-cinepak", NULL);
1349 /* WS_VQA belogns here (order) */
1351 case AV_CODEC_ID_MSRLE:
1353 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-rle",
1354 "layout", G_TYPE_STRING, "microsoft", NULL);
1356 gst_caps_set_simple (caps,
1357 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1359 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1363 case AV_CODEC_ID_QTRLE:
1365 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-rle",
1366 "layout", G_TYPE_STRING, "quicktime", NULL);
1368 gst_caps_set_simple (caps,
1369 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1371 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1375 case AV_CODEC_ID_MSVIDEO1:
1377 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1378 "video/x-msvideocodec", "msvideoversion", G_TYPE_INT, 1, NULL);
1381 case AV_CODEC_ID_MSS1:
1383 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1384 "wmvversion", G_TYPE_INT, 1, "format", G_TYPE_STRING, "MSS1", NULL);
1387 case AV_CODEC_ID_MSS2:
1389 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1390 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "MSS2", NULL);
1393 case AV_CODEC_ID_WMV3:
1395 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1396 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "WMV3", NULL);
1398 case AV_CODEC_ID_VC1:
1400 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1401 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "WVC1", NULL);
1403 case AV_CODEC_ID_QDM2:
1405 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-qdm2",
1409 case AV_CODEC_ID_MSZH:
1411 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-mszh",
1415 case AV_CODEC_ID_ZLIB:
1417 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-zlib",
1421 case AV_CODEC_ID_TRUEMOTION1:
1423 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1424 "video/x-truemotion", "trueversion", G_TYPE_INT, 1, NULL);
1426 case AV_CODEC_ID_TRUEMOTION2:
1428 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1429 "video/x-truemotion", "trueversion", G_TYPE_INT, 2, NULL);
1432 case AV_CODEC_ID_ULTI:
1434 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1435 "video/x-ultimotion", NULL);
1438 case AV_CODEC_ID_TSCC:
1440 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1441 "video/x-camtasia", NULL);
1443 gst_caps_set_simple (caps,
1444 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1446 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1450 case AV_CODEC_ID_KMVC:
1452 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-kmvc",
1456 case AV_CODEC_ID_NUV:
1458 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-nuv",
1462 case AV_CODEC_ID_GIF:
1464 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/gif",
1468 case AV_CODEC_ID_PNG:
1470 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/png",
1474 case AV_CODEC_ID_PPM:
1476 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/ppm",
1480 case AV_CODEC_ID_PBM:
1482 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/pbm",
1486 case AV_CODEC_ID_PAM:
1488 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1489 "image/x-portable-anymap", NULL);
1492 case AV_CODEC_ID_PGM:
1494 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1495 "image/x-portable-graymap", NULL);
1498 case AV_CODEC_ID_PCX:
1500 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-pcx",
1504 case AV_CODEC_ID_SGI:
1506 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-sgi",
1510 case AV_CODEC_ID_TARGA:
1512 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-tga",
1516 case AV_CODEC_ID_TIFF:
1518 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/tiff",
1522 case AV_CODEC_ID_SUNRAST:
1524 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1525 "image/x-sun-raster", NULL);
1528 case AV_CODEC_ID_SMC:
1530 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-smc",
1534 case AV_CODEC_ID_QDRAW:
1536 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-qdrw",
1540 case AV_CODEC_ID_DNXHD:
1542 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dnxhd",
1546 case AV_CODEC_ID_PRORES:
1548 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1549 "video/x-prores", NULL);
1552 case AV_CODEC_ID_MIMIC:
1554 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-mimic",
1558 case AV_CODEC_ID_VMNC:
1560 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vmnc",
1564 case AV_CODEC_ID_TRUESPEECH:
1566 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1567 "audio/x-truespeech", NULL);
1570 case AV_CODEC_ID_QCELP:
1572 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/qcelp",
1576 case AV_CODEC_ID_AMV:
1578 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-amv",
1582 case AV_CODEC_ID_AASC:
1584 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-aasc",
1588 case AV_CODEC_ID_LOCO:
1590 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-loco",
1594 case AV_CODEC_ID_ZMBV:
1596 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-zmbv",
1600 case AV_CODEC_ID_LAGARITH:
1602 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1603 "video/x-lagarith", NULL);
1606 case AV_CODEC_ID_CSCD:
1608 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1609 "video/x-camstudio", NULL);
1611 gst_caps_set_simple (caps,
1612 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1614 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1618 case AV_CODEC_ID_WS_VQA:
1619 case AV_CODEC_ID_IDCIN:
1620 case AV_CODEC_ID_8BPS:
1621 case AV_CODEC_ID_FLIC:
1622 case AV_CODEC_ID_VMDVIDEO:
1623 case AV_CODEC_ID_VMDAUDIO:
1624 case AV_CODEC_ID_SNOW:
1625 case AV_CODEC_ID_VIXL:
1626 case AV_CODEC_ID_QPEG:
1627 case AV_CODEC_ID_PGMYUV:
1628 case AV_CODEC_ID_FFVHUFF:
1629 case AV_CODEC_ID_WNV1:
1630 case AV_CODEC_ID_MP3ADU:
1631 case AV_CODEC_ID_MP3ON4:
1632 case AV_CODEC_ID_WESTWOOD_SND1:
1633 case AV_CODEC_ID_MMVIDEO:
1634 case AV_CODEC_ID_AVS:
1635 case AV_CODEC_ID_CAVS:
1639 /* weird quasi-codecs for the demuxers only */
1640 case AV_CODEC_ID_PCM_S16LE:
1641 case AV_CODEC_ID_PCM_S16BE:
1642 case AV_CODEC_ID_PCM_U16LE:
1643 case AV_CODEC_ID_PCM_U16BE:
1644 case AV_CODEC_ID_PCM_S8:
1645 case AV_CODEC_ID_PCM_U8:
1647 GstAudioFormat format;
1650 case AV_CODEC_ID_PCM_S16LE:
1651 format = GST_AUDIO_FORMAT_S16LE;
1653 case AV_CODEC_ID_PCM_S16BE:
1654 format = GST_AUDIO_FORMAT_S16BE;
1656 case AV_CODEC_ID_PCM_U16LE:
1657 format = GST_AUDIO_FORMAT_U16LE;
1659 case AV_CODEC_ID_PCM_U16BE:
1660 format = GST_AUDIO_FORMAT_U16BE;
1662 case AV_CODEC_ID_PCM_S8:
1663 format = GST_AUDIO_FORMAT_S8;
1665 case AV_CODEC_ID_PCM_U8:
1666 format = GST_AUDIO_FORMAT_U8;
1669 g_assert (0); /* don't worry, we never get here */
1674 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-raw",
1675 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
1676 "layout", G_TYPE_STRING, "interleaved", NULL);
1680 case AV_CODEC_ID_PCM_MULAW:
1682 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mulaw",
1686 case AV_CODEC_ID_PCM_ALAW:
1688 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-alaw",
1692 case AV_CODEC_ID_ADPCM_G722:
1694 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/G722",
1697 gst_caps_set_simple (caps,
1698 "block_align", G_TYPE_INT, context->block_align,
1699 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1702 case AV_CODEC_ID_ADPCM_G726:
1704 /* the G726 decoder can also handle G721 */
1706 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-adpcm",
1707 "layout", G_TYPE_STRING, "g726", NULL);
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 gst_caps_append (caps, gst_caps_new_simple ("audio/x-adpcm",
1715 "layout", G_TYPE_STRING, "g721",
1716 "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, 8000, NULL));
1720 case AV_CODEC_ID_ADPCM_IMA_QT:
1721 case AV_CODEC_ID_ADPCM_IMA_WAV:
1722 case AV_CODEC_ID_ADPCM_IMA_DK3:
1723 case AV_CODEC_ID_ADPCM_IMA_DK4:
1724 case AV_CODEC_ID_ADPCM_IMA_WS:
1725 case AV_CODEC_ID_ADPCM_IMA_SMJPEG:
1726 case AV_CODEC_ID_ADPCM_IMA_AMV:
1727 case AV_CODEC_ID_ADPCM_IMA_ISS:
1728 case AV_CODEC_ID_ADPCM_IMA_EA_EACS:
1729 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
1730 case AV_CODEC_ID_ADPCM_MS:
1731 case AV_CODEC_ID_ADPCM_4XM:
1732 case AV_CODEC_ID_ADPCM_XA:
1733 case AV_CODEC_ID_ADPCM_ADX:
1734 case AV_CODEC_ID_ADPCM_EA:
1735 case AV_CODEC_ID_ADPCM_CT:
1736 case AV_CODEC_ID_ADPCM_SWF:
1737 case AV_CODEC_ID_ADPCM_YAMAHA:
1738 case AV_CODEC_ID_ADPCM_SBPRO_2:
1739 case AV_CODEC_ID_ADPCM_SBPRO_3:
1740 case AV_CODEC_ID_ADPCM_SBPRO_4:
1741 case AV_CODEC_ID_ADPCM_EA_R1:
1742 case AV_CODEC_ID_ADPCM_EA_R2:
1743 case AV_CODEC_ID_ADPCM_EA_R3:
1744 case AV_CODEC_ID_ADPCM_EA_MAXIS_XA:
1745 case AV_CODEC_ID_ADPCM_EA_XAS:
1746 case AV_CODEC_ID_ADPCM_THP:
1748 const gchar *layout = NULL;
1751 case AV_CODEC_ID_ADPCM_IMA_QT:
1752 layout = "quicktime";
1754 case AV_CODEC_ID_ADPCM_IMA_WAV:
1757 case AV_CODEC_ID_ADPCM_IMA_DK3:
1760 case AV_CODEC_ID_ADPCM_IMA_DK4:
1763 case AV_CODEC_ID_ADPCM_IMA_WS:
1764 layout = "westwood";
1766 case AV_CODEC_ID_ADPCM_IMA_SMJPEG:
1769 case AV_CODEC_ID_ADPCM_IMA_AMV:
1772 case AV_CODEC_ID_ADPCM_IMA_ISS:
1775 case AV_CODEC_ID_ADPCM_IMA_EA_EACS:
1778 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
1781 case AV_CODEC_ID_ADPCM_MS:
1782 layout = "microsoft";
1784 case AV_CODEC_ID_ADPCM_4XM:
1787 case AV_CODEC_ID_ADPCM_XA:
1790 case AV_CODEC_ID_ADPCM_ADX:
1793 case AV_CODEC_ID_ADPCM_EA:
1796 case AV_CODEC_ID_ADPCM_CT:
1799 case AV_CODEC_ID_ADPCM_SWF:
1802 case AV_CODEC_ID_ADPCM_YAMAHA:
1805 case AV_CODEC_ID_ADPCM_SBPRO_2:
1808 case AV_CODEC_ID_ADPCM_SBPRO_3:
1811 case AV_CODEC_ID_ADPCM_SBPRO_4:
1814 case AV_CODEC_ID_ADPCM_EA_R1:
1817 case AV_CODEC_ID_ADPCM_EA_R2:
1820 case AV_CODEC_ID_ADPCM_EA_R3:
1823 case AV_CODEC_ID_ADPCM_EA_MAXIS_XA:
1824 layout = "ea-maxis-xa";
1826 case AV_CODEC_ID_ADPCM_EA_XAS:
1829 case AV_CODEC_ID_ADPCM_THP:
1833 g_assert (0); /* don't worry, we never get here */
1837 /* FIXME: someone please check whether we need additional properties
1838 * in this caps definition. */
1840 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-adpcm",
1841 "layout", G_TYPE_STRING, layout, NULL);
1843 gst_caps_set_simple (caps,
1844 "block_align", G_TYPE_INT, context->block_align,
1845 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1849 case AV_CODEC_ID_AMR_NB:
1851 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/AMR",
1855 case AV_CODEC_ID_AMR_WB:
1857 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/AMR-WB",
1861 case AV_CODEC_ID_GSM:
1863 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-gsm",
1867 case AV_CODEC_ID_GSM_MS:
1869 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/ms-gsm",
1873 case AV_CODEC_ID_NELLYMOSER:
1875 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1876 "audio/x-nellymoser", NULL);
1879 case AV_CODEC_ID_SIPR:
1882 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-sipro",
1885 gst_caps_set_simple (caps,
1886 "leaf_size", G_TYPE_INT, context->block_align,
1887 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1892 case AV_CODEC_ID_RA_144:
1893 case AV_CODEC_ID_RA_288:
1894 case AV_CODEC_ID_COOK:
1899 case AV_CODEC_ID_RA_144:
1902 case AV_CODEC_ID_RA_288:
1905 case AV_CODEC_ID_COOK:
1912 /* FIXME: properties? */
1914 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1915 "audio/x-pn-realaudio", "raversion", G_TYPE_INT, version, NULL);
1917 gst_caps_set_simple (caps,
1918 "leaf_size", G_TYPE_INT, context->block_align,
1919 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1924 case AV_CODEC_ID_ROQ_DPCM:
1925 case AV_CODEC_ID_INTERPLAY_DPCM:
1926 case AV_CODEC_ID_XAN_DPCM:
1927 case AV_CODEC_ID_SOL_DPCM:
1929 const gchar *layout = NULL;
1932 case AV_CODEC_ID_ROQ_DPCM:
1935 case AV_CODEC_ID_INTERPLAY_DPCM:
1936 layout = "interplay";
1938 case AV_CODEC_ID_XAN_DPCM:
1941 case AV_CODEC_ID_SOL_DPCM:
1945 g_assert (0); /* don't worry, we never get here */
1949 /* FIXME: someone please check whether we need additional properties
1950 * in this caps definition. */
1952 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dpcm",
1953 "layout", G_TYPE_STRING, layout, NULL);
1955 gst_caps_set_simple (caps,
1956 "block_align", G_TYPE_INT, context->block_align,
1957 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1961 case AV_CODEC_ID_SHORTEN:
1962 caps = gst_caps_new_empty_simple ("audio/x-shorten");
1965 case AV_CODEC_ID_ALAC:
1967 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-alac",
1970 gst_caps_set_simple (caps,
1971 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
1975 case AV_CODEC_ID_FLAC:
1976 /* Note that ffmpeg has no encoder yet, but just for safety. In the
1977 * encoder case, we want to add things like samplerate, channels... */
1979 caps = gst_caps_new_empty_simple ("audio/x-flac");
1983 case AV_CODEC_ID_S302M:
1984 caps = gst_caps_new_empty_simple ("audio/x-smpte-302m");
1987 case AV_CODEC_ID_DVD_SUBTITLE:
1988 case AV_CODEC_ID_DVB_SUBTITLE:
1991 case AV_CODEC_ID_BMP:
1992 caps = gst_caps_new_empty_simple ("image/bmp");
1994 case AV_CODEC_ID_TTA:
1996 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-tta",
1999 gst_caps_set_simple (caps,
2000 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
2003 case AV_CODEC_ID_TWINVQ:
2005 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
2006 "audio/x-twin-vq", NULL);
2009 GST_DEBUG ("Unknown codec ID %d, please add mapping here", codec_id);
2016 if ((codec = avcodec_find_decoder (codec_id)) ||
2017 (codec = avcodec_find_encoder (codec_id))) {
2020 GST_LOG ("Could not create stream format caps for %s", codec->name);
2022 switch (codec->type) {
2023 case AVMEDIA_TYPE_VIDEO:
2024 mime = g_strdup_printf ("video/x-gst-av-%s", codec->name);
2026 gst_ff_vid_caps_new (context, NULL, codec_id, encode, mime, NULL);
2029 case AVMEDIA_TYPE_AUDIO:
2030 mime = g_strdup_printf ("audio/x-gst-av-%s", codec->name);
2032 gst_ff_aud_caps_new (context, NULL, codec_id, encode, mime, NULL);
2034 gst_caps_set_simple (caps,
2035 "block_align", G_TYPE_INT, context->block_align,
2036 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
2047 /* set private data */
2048 if (context && context->extradata_size > 0) {
2049 GstBuffer *data = gst_buffer_new_and_alloc (context->extradata_size);
2051 gst_buffer_fill (data, 0, context->extradata, context->extradata_size);
2052 gst_caps_set_simple (caps, "codec_data", GST_TYPE_BUFFER, data, NULL);
2053 gst_buffer_unref (data);
2056 GST_LOG ("caps for codec_id=%d: %" GST_PTR_FORMAT, codec_id, caps);
2059 GST_LOG ("No caps found for codec_id=%d", codec_id);
2065 /* Convert a FFMPEG Pixel Format and optional AVCodecContext
2066 * to a GstCaps. If the context is ommitted, no fixed values
2067 * for video/audio size will be included in the GstCaps
2069 * See below for usefullness
2073 gst_ffmpeg_pixfmt_to_caps (enum PixelFormat pix_fmt, AVCodecContext * context,
2074 enum CodecID codec_id)
2076 GstCaps *caps = NULL;
2077 GstVideoFormat format;
2079 format = gst_ffmpeg_pixfmt_to_videoformat (pix_fmt);
2081 if (format != GST_VIDEO_FORMAT_UNKNOWN) {
2082 caps = gst_ff_vid_caps_new (context, NULL, codec_id, TRUE, "video/x-raw",
2083 "format", G_TYPE_STRING, gst_video_format_to_string (format), NULL);
2087 GST_DEBUG ("caps for pix_fmt=%d: %" GST_PTR_FORMAT, pix_fmt, caps);
2089 GST_LOG ("No caps found for pix_fmt=%d", pix_fmt);
2096 gst_ffmpeg_smpfmt_to_audioformat (enum AVSampleFormat sample_fmt)
2098 switch (sample_fmt) {
2099 case AV_SAMPLE_FMT_U8:
2100 case AV_SAMPLE_FMT_U8P:
2101 return GST_AUDIO_FORMAT_U8;
2103 case AV_SAMPLE_FMT_S16:
2104 case AV_SAMPLE_FMT_S16P:
2105 return GST_AUDIO_FORMAT_S16;
2107 case AV_SAMPLE_FMT_S32:
2108 case AV_SAMPLE_FMT_S32P:
2109 return GST_AUDIO_FORMAT_S32;
2111 case AV_SAMPLE_FMT_FLT:
2112 case AV_SAMPLE_FMT_FLTP:
2113 return GST_AUDIO_FORMAT_F32;
2115 case AV_SAMPLE_FMT_DBL:
2116 case AV_SAMPLE_FMT_DBLP:
2117 return GST_AUDIO_FORMAT_F64;
2121 return GST_AUDIO_FORMAT_UNKNOWN;
2126 /* Convert a FFMPEG Sample Format and optional AVCodecContext
2127 * to a GstCaps. If the context is ommitted, no fixed values
2128 * for video/audio size will be included in the GstCaps
2130 * See below for usefullness
2134 gst_ffmpeg_smpfmt_to_caps (enum AVSampleFormat sample_fmt,
2135 AVCodecContext * context, AVCodec * codec, enum CodecID codec_id)
2137 GstCaps *caps = NULL;
2138 GstAudioFormat format;
2140 format = gst_ffmpeg_smpfmt_to_audioformat (sample_fmt);
2142 if (format != GST_AUDIO_FORMAT_UNKNOWN) {
2143 caps = gst_ff_aud_caps_new (context, codec, codec_id, TRUE, "audio/x-raw",
2144 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
2145 "layout", G_TYPE_STRING, "interleaved", NULL);
2146 GST_LOG ("caps for sample_fmt=%d: %" GST_PTR_FORMAT, sample_fmt, caps);
2148 GST_LOG ("No caps found for sample_fmt=%d", sample_fmt);
2155 caps_has_field (GstCaps * caps, const gchar * field)
2159 n = gst_caps_get_size (caps);
2160 for (i = 0; i < n; i++) {
2161 GstStructure *s = gst_caps_get_structure (caps, i);
2163 if (gst_structure_has_field (s, field))
2171 gst_ffmpeg_codectype_to_audio_caps (AVCodecContext * context,
2172 enum CodecID codec_id, gboolean encode, AVCodec * codec)
2174 GstCaps *caps = NULL;
2176 GST_DEBUG ("context:%p, codec_id:%d, encode:%d, codec:%p",
2177 context, codec_id, encode, codec);
2179 GST_DEBUG ("sample_fmts:%p, samplerates:%p",
2180 codec->sample_fmts, codec->supported_samplerates);
2183 /* Specific codec context */
2185 gst_ffmpeg_smpfmt_to_caps (context->sample_fmt, context, codec,
2188 caps = gst_ff_aud_caps_new (context, codec, codec_id, encode, "audio/x-raw",
2189 "layout", G_TYPE_STRING, "interleaved", NULL);
2190 if (!caps_has_field (caps, "format"))
2191 gst_ffmpeg_audio_set_sample_fmts (caps,
2192 codec ? codec->sample_fmts : NULL);
2199 gst_ffmpeg_codectype_to_video_caps (AVCodecContext * context,
2200 enum CodecID codec_id, gboolean encode, AVCodec * codec)
2204 GST_LOG ("context:%p, codec_id:%d, encode:%d, codec:%p",
2205 context, codec_id, encode, codec);
2208 caps = gst_ffmpeg_pixfmt_to_caps (context->pix_fmt, context, codec_id);
2211 gst_ff_vid_caps_new (context, codec, codec_id, encode, "video/x-raw",
2213 if (!caps_has_field (caps, "format"))
2214 gst_ffmpeg_video_set_pix_fmts (caps, codec ? codec->pix_fmts : NULL);
2219 /* Convert a GstCaps (audio/raw) to a FFMPEG SampleFmt
2220 * and other audio properties in a AVCodecContext.
2222 * For usefullness, see below
2226 gst_ffmpeg_caps_to_smpfmt (const GstCaps * caps,
2227 AVCodecContext * context, gboolean raw)
2229 GstStructure *structure;
2231 GstAudioFormat format = GST_AUDIO_FORMAT_UNKNOWN;
2233 g_return_if_fail (gst_caps_get_size (caps) == 1);
2235 structure = gst_caps_get_structure (caps, 0);
2237 gst_structure_get_int (structure, "channels", &context->channels);
2238 gst_structure_get_int (structure, "rate", &context->sample_rate);
2239 gst_structure_get_int (structure, "block_align", &context->block_align);
2240 gst_structure_get_int (structure, "bitrate", &context->bit_rate);
2245 if (gst_structure_has_name (structure, "audio/x-raw")) {
2246 if ((fmt = gst_structure_get_string (structure, "format"))) {
2247 format = gst_audio_format_from_string (fmt);
2252 case GST_AUDIO_FORMAT_F32:
2253 context->sample_fmt = AV_SAMPLE_FMT_FLT;
2255 case GST_AUDIO_FORMAT_F64:
2256 context->sample_fmt = AV_SAMPLE_FMT_DBL;
2258 case GST_AUDIO_FORMAT_S32:
2259 context->sample_fmt = AV_SAMPLE_FMT_S32;
2261 case GST_AUDIO_FORMAT_S16:
2262 context->sample_fmt = AV_SAMPLE_FMT_S16;
2269 /* Convert a GstCaps (video/raw) to a FFMPEG PixFmt
2270 * and other video properties in a AVCodecContext.
2272 * For usefullness, see below
2276 gst_ffmpeg_caps_to_pixfmt (const GstCaps * caps,
2277 AVCodecContext * context, gboolean raw)
2279 GstStructure *structure;
2281 const GValue *par = NULL;
2283 GstVideoFormat format = GST_VIDEO_FORMAT_UNKNOWN;
2285 GST_DEBUG ("converting caps %" GST_PTR_FORMAT, caps);
2286 g_return_if_fail (gst_caps_get_size (caps) == 1);
2287 structure = gst_caps_get_structure (caps, 0);
2289 gst_structure_get_int (structure, "width", &context->width);
2290 gst_structure_get_int (structure, "height", &context->height);
2291 gst_structure_get_int (structure, "bpp", &context->bits_per_coded_sample);
2293 fps = gst_structure_get_value (structure, "framerate");
2294 if (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps)) {
2296 /* somehow these seem mixed up.. */
2297 context->time_base.den = gst_value_get_fraction_numerator (fps);
2298 context->time_base.num = gst_value_get_fraction_denominator (fps);
2299 context->ticks_per_frame = 1;
2301 GST_DEBUG ("setting framerate %d/%d = %lf",
2302 context->time_base.den, context->time_base.num,
2303 1. * context->time_base.den / context->time_base.num);
2306 par = gst_structure_get_value (structure, "pixel-aspect-ratio");
2307 if (par && GST_VALUE_HOLDS_FRACTION (par)) {
2309 context->sample_aspect_ratio.num = gst_value_get_fraction_numerator (par);
2310 context->sample_aspect_ratio.den = gst_value_get_fraction_denominator (par);
2312 GST_DEBUG ("setting pixel-aspect-ratio %d/%d = %lf",
2313 context->sample_aspect_ratio.den, context->sample_aspect_ratio.num,
2314 1. * context->sample_aspect_ratio.den /
2315 context->sample_aspect_ratio.num);
2321 g_return_if_fail (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps));
2323 if (gst_structure_has_name (structure, "video/x-raw")) {
2324 if ((fmt = gst_structure_get_string (structure, "format"))) {
2325 format = gst_video_format_from_string (fmt);
2330 case GST_VIDEO_FORMAT_YUY2:
2331 context->pix_fmt = PIX_FMT_YUYV422;
2333 case GST_VIDEO_FORMAT_I420:
2334 context->pix_fmt = PIX_FMT_YUV420P;
2336 case GST_VIDEO_FORMAT_A420:
2337 context->pix_fmt = PIX_FMT_YUVA420P;
2339 case GST_VIDEO_FORMAT_Y41B:
2340 context->pix_fmt = PIX_FMT_YUV411P;
2342 case GST_VIDEO_FORMAT_Y42B:
2343 context->pix_fmt = PIX_FMT_YUV422P;
2345 case GST_VIDEO_FORMAT_YUV9:
2346 context->pix_fmt = PIX_FMT_YUV410P;
2348 case GST_VIDEO_FORMAT_Y444:
2349 context->pix_fmt = PIX_FMT_YUV444P;
2351 case GST_VIDEO_FORMAT_GRAY8:
2352 context->pix_fmt = PIX_FMT_GRAY8;
2354 case GST_VIDEO_FORMAT_xRGB:
2355 #if (G_BYTE_ORDER == G_BIG_ENDIAN)
2356 context->pix_fmt = PIX_FMT_RGB32;
2359 case GST_VIDEO_FORMAT_BGRx:
2360 #if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
2361 context->pix_fmt = PIX_FMT_RGB32;
2364 case GST_VIDEO_FORMAT_RGB:
2365 context->pix_fmt = PIX_FMT_RGB24;
2367 case GST_VIDEO_FORMAT_BGR:
2368 context->pix_fmt = PIX_FMT_BGR24;
2370 case GST_VIDEO_FORMAT_RGB16:
2371 context->pix_fmt = PIX_FMT_RGB565;
2373 case GST_VIDEO_FORMAT_RGB15:
2374 context->pix_fmt = PIX_FMT_RGB555;
2376 case GST_VIDEO_FORMAT_RGB8P:
2377 context->pix_fmt = PIX_FMT_PAL8;
2386 GstVideoFormat format;
2387 enum PixelFormat pixfmt;
2390 /* FIXME : FILLME */
2391 static const PixToFmt pixtofmttable[] = {
2392 /* GST_VIDEO_FORMAT_I420, */
2393 {GST_VIDEO_FORMAT_I420, PIX_FMT_YUV420P},
2394 /* Note : this should use a different chroma placement */
2395 {GST_VIDEO_FORMAT_I420, PIX_FMT_YUVJ420P},
2397 /* GST_VIDEO_FORMAT_YV12, */
2398 /* GST_VIDEO_FORMAT_YUY2, */
2399 {GST_VIDEO_FORMAT_YUY2, PIX_FMT_YUYV422},
2400 /* GST_VIDEO_FORMAT_UYVY, */
2401 {GST_VIDEO_FORMAT_UYVY, PIX_FMT_UYVY422},
2402 /* GST_VIDEO_FORMAT_AYUV, */
2403 /* GST_VIDEO_FORMAT_RGBx, */
2404 /* GST_VIDEO_FORMAT_BGRx, */
2405 /* GST_VIDEO_FORMAT_xRGB, */
2406 /* GST_VIDEO_FORMAT_xBGR, */
2407 /* GST_VIDEO_FORMAT_RGBA, */
2408 {GST_VIDEO_FORMAT_RGBA, PIX_FMT_RGBA},
2409 /* GST_VIDEO_FORMAT_BGRA, */
2410 {GST_VIDEO_FORMAT_BGRA, PIX_FMT_BGRA},
2411 /* GST_VIDEO_FORMAT_ARGB, */
2412 {GST_VIDEO_FORMAT_ARGB, PIX_FMT_ARGB},
2413 /* GST_VIDEO_FORMAT_ABGR, */
2414 {GST_VIDEO_FORMAT_ABGR, PIX_FMT_ABGR},
2415 /* GST_VIDEO_FORMAT_RGB, */
2416 {GST_VIDEO_FORMAT_RGB, PIX_FMT_RGB24},
2417 /* GST_VIDEO_FORMAT_BGR, */
2418 {GST_VIDEO_FORMAT_BGR, PIX_FMT_BGR24},
2419 /* GST_VIDEO_FORMAT_Y41B, */
2420 {GST_VIDEO_FORMAT_Y41B, PIX_FMT_YUV411P},
2421 /* GST_VIDEO_FORMAT_Y42B, */
2422 {GST_VIDEO_FORMAT_Y42B, PIX_FMT_YUV422P},
2423 {GST_VIDEO_FORMAT_Y42B, PIX_FMT_YUVJ422P},
2424 /* GST_VIDEO_FORMAT_YVYU, */
2425 /* GST_VIDEO_FORMAT_Y444, */
2426 {GST_VIDEO_FORMAT_Y444, PIX_FMT_YUV444P},
2427 {GST_VIDEO_FORMAT_Y444, PIX_FMT_YUVJ444P},
2428 /* GST_VIDEO_FORMAT_v210, */
2429 /* GST_VIDEO_FORMAT_v216, */
2430 /* GST_VIDEO_FORMAT_NV12, */
2431 {GST_VIDEO_FORMAT_NV12, PIX_FMT_NV12},
2432 /* GST_VIDEO_FORMAT_NV21, */
2433 {GST_VIDEO_FORMAT_NV21, PIX_FMT_NV21},
2434 /* GST_VIDEO_FORMAT_GRAY8, */
2435 {GST_VIDEO_FORMAT_GRAY8, PIX_FMT_GRAY8},
2436 /* GST_VIDEO_FORMAT_GRAY16_BE, */
2437 {GST_VIDEO_FORMAT_GRAY16_BE, PIX_FMT_GRAY16BE},
2438 /* GST_VIDEO_FORMAT_GRAY16_LE, */
2439 {GST_VIDEO_FORMAT_GRAY16_LE, PIX_FMT_GRAY16LE},
2440 /* GST_VIDEO_FORMAT_v308, */
2441 /* GST_VIDEO_FORMAT_Y800, */
2442 /* GST_VIDEO_FORMAT_Y16, */
2443 /* GST_VIDEO_FORMAT_RGB16, */
2444 {GST_VIDEO_FORMAT_RGB16, PIX_FMT_RGB565},
2445 /* GST_VIDEO_FORMAT_BGR16, */
2446 /* GST_VIDEO_FORMAT_RGB15, */
2447 {GST_VIDEO_FORMAT_RGB15, PIX_FMT_RGB555},
2448 /* GST_VIDEO_FORMAT_BGR15, */
2449 /* GST_VIDEO_FORMAT_UYVP, */
2450 /* GST_VIDEO_FORMAT_A420, */
2451 {GST_VIDEO_FORMAT_A420, PIX_FMT_YUVA420P},
2452 /* GST_VIDEO_FORMAT_RGB8_PALETTED, */
2453 {GST_VIDEO_FORMAT_RGB8P, PIX_FMT_PAL8},
2454 /* GST_VIDEO_FORMAT_YUV9, */
2455 {GST_VIDEO_FORMAT_YUV9, PIX_FMT_YUV410P},
2456 /* GST_VIDEO_FORMAT_YVU9, */
2457 /* GST_VIDEO_FORMAT_IYU1, */
2458 /* GST_VIDEO_FORMAT_ARGB64, */
2459 /* GST_VIDEO_FORMAT_AYUV64, */
2460 /* GST_VIDEO_FORMAT_r210, */
2461 {GST_VIDEO_FORMAT_I420_10LE, PIX_FMT_YUV420P10LE},
2462 {GST_VIDEO_FORMAT_I420_10BE, PIX_FMT_YUV420P10BE},
2463 {GST_VIDEO_FORMAT_I422_10LE, PIX_FMT_YUV422P10LE},
2464 {GST_VIDEO_FORMAT_I422_10BE, PIX_FMT_YUV422P10BE},
2465 {GST_VIDEO_FORMAT_Y444_10LE, PIX_FMT_YUV444P10LE},
2466 {GST_VIDEO_FORMAT_Y444_10BE, PIX_FMT_YUV444P10BE},
2467 {GST_VIDEO_FORMAT_GBR, PIX_FMT_GBRP},
2468 {GST_VIDEO_FORMAT_GBR_10LE, PIX_FMT_GBRP10LE},
2469 {GST_VIDEO_FORMAT_GBR_10BE, PIX_FMT_GBRP10BE},
2473 gst_ffmpeg_pixfmt_to_videoformat (enum PixelFormat pixfmt)
2477 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2478 if (pixtofmttable[i].pixfmt == pixfmt)
2479 return pixtofmttable[i].format;
2481 GST_DEBUG ("Unknown pixel format %d", pixfmt);
2482 return GST_VIDEO_FORMAT_UNKNOWN;
2486 gst_ffmpeg_videoformat_to_pixfmt (GstVideoFormat format)
2490 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2491 if (pixtofmttable[i].format == format)
2492 return pixtofmttable[i].pixfmt;
2493 return PIX_FMT_NONE;
2497 gst_ffmpeg_videoinfo_to_context (GstVideoInfo * info, AVCodecContext * context)
2501 context->width = GST_VIDEO_INFO_WIDTH (info);
2502 context->height = GST_VIDEO_INFO_HEIGHT (info);
2503 for (i = 0; i < GST_VIDEO_INFO_N_COMPONENTS (info); i++)
2504 bpp += GST_VIDEO_INFO_COMP_DEPTH (info, i);
2505 context->bits_per_coded_sample = bpp;
2507 context->ticks_per_frame = 1;
2508 context->time_base.den = GST_VIDEO_INFO_FPS_N (info);
2509 context->time_base.num = GST_VIDEO_INFO_FPS_D (info);
2511 context->sample_aspect_ratio.num = GST_VIDEO_INFO_PAR_N (info);
2512 context->sample_aspect_ratio.den = GST_VIDEO_INFO_PAR_D (info);
2515 gst_ffmpeg_videoformat_to_pixfmt (GST_VIDEO_INFO_FORMAT (info));
2519 gst_ffmpeg_audioinfo_to_context (GstAudioInfo * info, AVCodecContext * context)
2521 const AVCodec *codec;
2522 const enum AVSampleFormat *smpl_fmts;
2523 enum AVSampleFormat smpl_fmt = -1;
2525 context->channels = info->channels;
2526 context->sample_rate = info->rate;
2527 context->channel_layout =
2528 gst_ffmpeg_channel_positions_to_layout (info->position, info->channels);
2530 codec = context->codec;
2532 smpl_fmts = codec->sample_fmts;
2534 switch (info->finfo->format) {
2535 case GST_AUDIO_FORMAT_F32:
2537 while (*smpl_fmts != -1) {
2538 if (*smpl_fmts == AV_SAMPLE_FMT_FLT) {
2539 smpl_fmt = *smpl_fmts;
2541 } else if (*smpl_fmts == AV_SAMPLE_FMT_FLTP) {
2542 smpl_fmt = *smpl_fmts;
2548 smpl_fmt = AV_SAMPLE_FMT_FLT;
2551 case GST_AUDIO_FORMAT_F64:
2553 while (*smpl_fmts != -1) {
2554 if (*smpl_fmts == AV_SAMPLE_FMT_DBL) {
2555 smpl_fmt = *smpl_fmts;
2557 } else if (*smpl_fmts == AV_SAMPLE_FMT_DBLP) {
2558 smpl_fmt = *smpl_fmts;
2564 smpl_fmt = AV_SAMPLE_FMT_DBL;
2567 case GST_AUDIO_FORMAT_S32:
2569 while (*smpl_fmts != -1) {
2570 if (*smpl_fmts == AV_SAMPLE_FMT_S32) {
2571 smpl_fmt = *smpl_fmts;
2573 } else if (*smpl_fmts == AV_SAMPLE_FMT_S32P) {
2574 smpl_fmt = *smpl_fmts;
2580 smpl_fmt = AV_SAMPLE_FMT_S32;
2583 case GST_AUDIO_FORMAT_S16:
2585 while (*smpl_fmts != -1) {
2586 if (*smpl_fmts == AV_SAMPLE_FMT_S16) {
2587 smpl_fmt = *smpl_fmts;
2589 } else if (*smpl_fmts == AV_SAMPLE_FMT_S16P) {
2590 smpl_fmt = *smpl_fmts;
2596 smpl_fmt = AV_SAMPLE_FMT_S16;
2599 case GST_AUDIO_FORMAT_U8:
2601 while (*smpl_fmts != -1) {
2602 if (*smpl_fmts == AV_SAMPLE_FMT_U8) {
2603 smpl_fmt = *smpl_fmts;
2605 } else if (*smpl_fmts == AV_SAMPLE_FMT_U8P) {
2606 smpl_fmt = *smpl_fmts;
2612 smpl_fmt = AV_SAMPLE_FMT_U8;
2619 g_assert (smpl_fmt != -1);
2621 context->sample_fmt = smpl_fmt;
2624 /* Convert a GstCaps and a FFMPEG codec Type to a
2625 * AVCodecContext. If the context is ommitted, no fixed values
2626 * for video/audio size will be included in the context
2628 * AVMediaType is primarily meant for uncompressed data GstCaps!
2632 gst_ffmpeg_caps_with_codectype (enum AVMediaType type,
2633 const GstCaps * caps, AVCodecContext * context)
2635 if (context == NULL)
2639 case AVMEDIA_TYPE_VIDEO:
2640 gst_ffmpeg_caps_to_pixfmt (caps, context, TRUE);
2643 case AVMEDIA_TYPE_AUDIO:
2644 gst_ffmpeg_caps_to_smpfmt (caps, context, TRUE);
2655 nal_escape (guint8 * dst, guint8 * src, guint size, guint * destsize)
2659 guint8 *end = src + size;
2662 while (srcp < end) {
2663 if (count == 2 && *srcp <= 0x03) {
2664 GST_DEBUG ("added escape code");
2673 GST_DEBUG ("copy %02x, count %d", *srcp, count);
2676 *destsize = dstp - dst;
2679 /* copy the config, escaping NAL units as we iterate them, if something fails we
2680 * copy everything and hope for the best. */
2682 copy_config (guint8 * dst, guint8 * src, guint size, guint * destsize)
2687 guint nalsize, esize;
2697 cnt = *(srcp + 5) & 0x1f; /* Number of sps */
2699 GST_DEBUG ("num SPS %d", cnt);
2701 memcpy (dstp, srcp, 6);
2705 for (i = 0; i < cnt; i++) {
2706 GST_DEBUG ("copy SPS %d", i);
2707 nalsize = (srcp[0] << 8) | srcp[1];
2708 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2709 dstp[0] = esize >> 8;
2710 dstp[1] = esize & 0xff;
2712 srcp += nalsize + 2;
2715 cnt = *(dstp++) = *(srcp++); /* Number of pps */
2717 GST_DEBUG ("num PPS %d", cnt);
2719 for (i = 0; i < cnt; i++) {
2720 GST_DEBUG ("copy PPS %d", i);
2721 nalsize = (srcp[0] << 8) | srcp[1];
2722 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2723 dstp[0] = esize >> 8;
2724 dstp[1] = esize & 0xff;
2726 srcp += nalsize + 2;
2728 *destsize = dstp - dst;
2734 GST_DEBUG ("something unexpected, doing full copy");
2735 memcpy (dst, src, size);
2743 * caps_with_codecid () transforms a GstCaps for a known codec
2744 * ID into a filled-in context.
2745 * codec_data from caps will override possible extradata already in the context
2749 gst_ffmpeg_caps_with_codecid (enum CodecID codec_id,
2750 enum AVMediaType codec_type, const GstCaps * caps, AVCodecContext * context)
2753 const GValue *value;
2756 GST_LOG ("codec_id:%d, codec_type:%d, caps:%" GST_PTR_FORMAT " context:%p",
2757 codec_id, codec_type, caps, context);
2759 if (!context || !gst_caps_get_size (caps))
2762 str = gst_caps_get_structure (caps, 0);
2764 /* extradata parsing (esds [mpeg4], wma/wmv, msmpeg4v1/2/3, etc.) */
2765 if ((value = gst_structure_get_value (str, "codec_data"))) {
2768 buf = gst_value_get_buffer (value);
2769 gst_buffer_map (buf, &map, GST_MAP_READ);
2771 /* free the old one if it is there */
2772 if (context->extradata)
2773 av_free (context->extradata);
2776 if (codec_id == AV_CODEC_ID_H264) {
2779 GST_DEBUG ("copy, escaping codec_data %d", size);
2780 /* ffmpeg h264 expects the codec_data to be escaped, there is no real
2781 * reason for this but let's just escape it for now. Start by allocating
2782 * enough space, x2 is more than enough.
2784 * FIXME, we disabled escaping because some file already contain escaped
2785 * codec_data and then we escape twice and fail. It's better to leave it
2786 * as is, as that is what most players do. */
2787 context->extradata =
2788 av_mallocz (GST_ROUND_UP_16 (size * 2 +
2789 FF_INPUT_BUFFER_PADDING_SIZE));
2790 copy_config (context->extradata, data, size, &extrasize);
2791 GST_DEBUG ("escaped size: %d", extrasize);
2792 context->extradata_size = extrasize;
2796 /* allocate with enough padding */
2797 GST_DEBUG ("copy codec_data");
2798 context->extradata =
2799 av_mallocz (GST_ROUND_UP_16 (map.size +
2800 FF_INPUT_BUFFER_PADDING_SIZE));
2801 memcpy (context->extradata, map.data, map.size);
2802 context->extradata_size = map.size;
2805 /* Hack for VC1. Sometimes the first (length) byte is 0 for some files */
2806 if (codec_id == AV_CODEC_ID_VC1 && map.size > 0 && map.data[0] == 0) {
2807 context->extradata[0] = (guint8) map.size;
2810 GST_DEBUG ("have codec data of size %" G_GSIZE_FORMAT, map.size);
2812 gst_buffer_unmap (buf, &map);
2813 } else if (context->extradata == NULL && codec_id != AV_CODEC_ID_AAC_LATM &&
2814 codec_id != AV_CODEC_ID_FLAC) {
2815 /* no extradata, alloc dummy with 0 sized, some codecs insist on reading
2816 * extradata anyway which makes then segfault. */
2817 context->extradata =
2818 av_mallocz (GST_ROUND_UP_16 (FF_INPUT_BUFFER_PADDING_SIZE));
2819 context->extradata_size = 0;
2820 GST_DEBUG ("no codec data");
2824 case AV_CODEC_ID_MPEG4:
2826 const gchar *mime = gst_structure_get_name (str);
2828 if (!strcmp (mime, "video/x-divx"))
2829 context->codec_tag = GST_MAKE_FOURCC ('D', 'I', 'V', 'X');
2830 else if (!strcmp (mime, "video/x-xvid"))
2831 context->codec_tag = GST_MAKE_FOURCC ('X', 'V', 'I', 'D');
2832 else if (!strcmp (mime, "video/x-3ivx"))
2833 context->codec_tag = GST_MAKE_FOURCC ('3', 'I', 'V', '1');
2834 else if (!strcmp (mime, "video/mpeg"))
2835 context->codec_tag = GST_MAKE_FOURCC ('m', 'p', '4', 'v');
2839 case AV_CODEC_ID_SVQ3:
2840 /* FIXME: this is a workaround for older gst-plugins releases
2841 * (<= 0.8.9). This should be removed at some point, because
2842 * it causes wrong decoded frame order. */
2843 if (!context->extradata) {
2844 gint halfpel_flag, thirdpel_flag, low_delay, unknown_svq3_flag;
2847 if (gst_structure_get_int (str, "halfpel_flag", &halfpel_flag) ||
2848 gst_structure_get_int (str, "thirdpel_flag", &thirdpel_flag) ||
2849 gst_structure_get_int (str, "low_delay", &low_delay) ||
2850 gst_structure_get_int (str, "unknown_svq3_flag",
2851 &unknown_svq3_flag)) {
2852 context->extradata = (guint8 *) av_mallocz (0x64);
2853 g_stpcpy ((gchar *) context->extradata, "SVQ3");
2857 flags |= unknown_svq3_flag;
2859 flags |= halfpel_flag;
2861 flags |= thirdpel_flag;
2864 flags = GUINT16_FROM_LE (flags);
2866 memcpy ((gchar *) context->extradata + 0x62, &flags, 2);
2867 context->extradata_size = 0x64;
2872 case AV_CODEC_ID_MSRLE:
2873 case AV_CODEC_ID_QTRLE:
2874 case AV_CODEC_ID_TSCC:
2875 case AV_CODEC_ID_CSCD:
2876 case AV_CODEC_ID_APE:
2880 if (gst_structure_get_int (str, "depth", &depth)) {
2881 context->bits_per_coded_sample = depth;
2883 GST_WARNING ("No depth field in caps %" GST_PTR_FORMAT, caps);
2889 case AV_CODEC_ID_RV10:
2890 case AV_CODEC_ID_RV20:
2891 case AV_CODEC_ID_RV30:
2892 case AV_CODEC_ID_RV40:
2896 if (gst_structure_get_int (str, "format", &format))
2897 context->sub_id = format;
2901 case AV_CODEC_ID_COOK:
2902 case AV_CODEC_ID_RA_288:
2903 case AV_CODEC_ID_RA_144:
2904 case AV_CODEC_ID_SIPR:
2909 if (gst_structure_get_int (str, "leaf_size", &leaf_size))
2910 context->block_align = leaf_size;
2911 if (gst_structure_get_int (str, "bitrate", &bitrate))
2912 context->bit_rate = bitrate;
2914 case AV_CODEC_ID_ALAC:
2915 gst_structure_get_int (str, "samplesize",
2916 &context->bits_per_coded_sample);
2919 case AV_CODEC_ID_DVVIDEO:
2921 const gchar *format;
2923 if ((format = gst_structure_get_string (str, "format"))) {
2925 if (g_str_equal (format, "YUY2"))
2926 context->pix_fmt = PIX_FMT_YUYV422;
2927 else if (g_str_equal (format, "I420"))
2928 context->pix_fmt = PIX_FMT_YUV420P;
2929 else if (g_str_equal (format, "A420"))
2930 context->pix_fmt = PIX_FMT_YUVA420P;
2931 else if (g_str_equal (format, "Y41B"))
2932 context->pix_fmt = PIX_FMT_YUV411P;
2933 else if (g_str_equal (format, "Y42B"))
2934 context->pix_fmt = PIX_FMT_YUV422P;
2935 else if (g_str_equal (format, "YUV9"))
2936 context->pix_fmt = PIX_FMT_YUV410P;
2938 GST_WARNING ("couldn't convert format %s" " to a pixel format",
2942 GST_WARNING ("No specified format");
2945 case AV_CODEC_ID_H263P:
2949 if (!gst_structure_get_boolean (str, "annex-f", &val) || val)
2950 context->flags |= CODEC_FLAG_4MV;
2952 context->flags &= ~CODEC_FLAG_4MV;
2953 if ((!gst_structure_get_boolean (str, "annex-i", &val) || val) &&
2954 (!gst_structure_get_boolean (str, "annex-t", &val) || val))
2955 context->flags |= CODEC_FLAG_AC_PRED;
2957 context->flags &= ~CODEC_FLAG_AC_PRED;
2958 if (!gst_structure_get_boolean (str, "annex-j", &val) || val)
2959 context->flags |= CODEC_FLAG_LOOP_FILTER;
2961 context->flags &= ~CODEC_FLAG_LOOP_FILTER;
2964 case AV_CODEC_ID_ADPCM_G726:
2966 const gchar *layout;
2968 if ((layout = gst_structure_get_string (str, "layout"))) {
2969 if (!strcmp (layout, "g721")) {
2970 context->sample_rate = 8000;
2971 context->channels = 1;
2972 context->bit_rate = 32000;
2981 if (!gst_caps_is_fixed (caps))
2984 /* common properties (width, height, fps) */
2985 switch (codec_type) {
2986 case AVMEDIA_TYPE_VIDEO:
2987 gst_ffmpeg_caps_to_pixfmt (caps, context,
2988 codec_id == AV_CODEC_ID_RAWVIDEO);
2990 case AVMEDIA_TYPE_AUDIO:
2991 gst_ffmpeg_caps_to_smpfmt (caps, context, FALSE);
2997 /* fixup of default settings */
2999 case AV_CODEC_ID_QCELP:
3000 /* QCELP is always mono, no matter what the caps say */
3001 context->channels = 1;
3003 case AV_CODEC_ID_ADPCM_G726:
3004 if (context->sample_rate && context->bit_rate)
3005 context->bits_per_coded_sample =
3006 context->bit_rate / context->sample_rate;
3013 /* _formatid_to_caps () is meant for muxers/demuxers, it
3014 * transforms a name (ffmpeg way of ID'ing these, why don't
3015 * they have unique numerical IDs?) to the corresponding
3016 * caps belonging to that mux-format
3018 * Note: we don't need any additional info because the caps
3019 * isn't supposed to contain any useful info besides the
3024 gst_ffmpeg_formatid_to_caps (const gchar * format_name)
3026 GstCaps *caps = NULL;
3028 if (!strcmp (format_name, "mpeg")) {
3029 caps = gst_caps_new_simple ("video/mpeg",
3030 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3031 } else if (!strcmp (format_name, "mpegts")) {
3032 caps = gst_caps_new_simple ("video/mpegts",
3033 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3034 } else if (!strcmp (format_name, "rm")) {
3035 caps = gst_caps_new_simple ("application/x-pn-realmedia",
3036 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3037 } else if (!strcmp (format_name, "asf")) {
3038 caps = gst_caps_new_empty_simple ("video/x-ms-asf");
3039 } else if (!strcmp (format_name, "avi")) {
3040 caps = gst_caps_new_empty_simple ("video/x-msvideo");
3041 } else if (!strcmp (format_name, "wav")) {
3042 caps = gst_caps_new_empty_simple ("audio/x-wav");
3043 } else if (!strcmp (format_name, "ape")) {
3044 caps = gst_caps_new_empty_simple ("application/x-ape");
3045 } else if (!strcmp (format_name, "swf")) {
3046 caps = gst_caps_new_empty_simple ("application/x-shockwave-flash");
3047 } else if (!strcmp (format_name, "au")) {
3048 caps = gst_caps_new_empty_simple ("audio/x-au");
3049 } else if (!strcmp (format_name, "dv")) {
3050 caps = gst_caps_new_simple ("video/x-dv",
3051 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3052 } else if (!strcmp (format_name, "4xm")) {
3053 caps = gst_caps_new_empty_simple ("video/x-4xm");
3054 } else if (!strcmp (format_name, "matroska")) {
3055 caps = gst_caps_new_empty_simple ("video/x-matroska");
3056 } else if (!strcmp (format_name, "mp3")) {
3057 caps = gst_caps_new_empty_simple ("application/x-id3");
3058 } else if (!strcmp (format_name, "flic")) {
3059 caps = gst_caps_new_empty_simple ("video/x-fli");
3060 } else if (!strcmp (format_name, "flv")) {
3061 caps = gst_caps_new_empty_simple ("video/x-flv");
3062 } else if (!strcmp (format_name, "tta")) {
3063 caps = gst_caps_new_empty_simple ("audio/x-ttafile");
3064 } else if (!strcmp (format_name, "aiff")) {
3065 caps = gst_caps_new_empty_simple ("audio/x-aiff");
3066 } else if (!strcmp (format_name, "mov_mp4_m4a_3gp_3g2")) {
3068 gst_caps_from_string
3069 ("application/x-3gp; video/quicktime; audio/x-m4a");
3070 } else if (!strcmp (format_name, "mov")) {
3071 caps = gst_caps_from_string ("video/quicktime,variant=(string)apple");
3072 } else if (!strcmp (format_name, "mp4")) {
3073 caps = gst_caps_from_string ("video/quicktime,variant=(string)iso");
3074 } else if (!strcmp (format_name, "3gp")) {
3075 caps = gst_caps_from_string ("video/quicktime,variant=(string)3gpp");
3076 } else if (!strcmp (format_name, "3g2")) {
3077 caps = gst_caps_from_string ("video/quicktime,variant=(string)3g2");
3078 } else if (!strcmp (format_name, "psp")) {
3079 caps = gst_caps_from_string ("video/quicktime,variant=(string)psp");
3080 } else if (!strcmp (format_name, "ipod")) {
3081 caps = gst_caps_from_string ("video/quicktime,variant=(string)ipod");
3082 } else if (!strcmp (format_name, "aac")) {
3083 caps = gst_caps_new_simple ("audio/mpeg",
3084 "mpegversion", G_TYPE_INT, 4, NULL);
3085 } else if (!strcmp (format_name, "gif")) {
3086 caps = gst_caps_from_string ("image/gif");
3087 } else if (!strcmp (format_name, "ogg")) {
3088 caps = gst_caps_from_string ("application/ogg");
3089 } else if (!strcmp (format_name, "mxf") || !strcmp (format_name, "mxf_d10")) {
3090 caps = gst_caps_from_string ("application/mxf");
3091 } else if (!strcmp (format_name, "gxf")) {
3092 caps = gst_caps_from_string ("application/gxf");
3093 } else if (!strcmp (format_name, "yuv4mpegpipe")) {
3094 caps = gst_caps_new_simple ("application/x-yuv4mpeg",
3095 "y4mversion", G_TYPE_INT, 2, NULL);
3096 } else if (!strcmp (format_name, "mpc")) {
3097 caps = gst_caps_from_string ("audio/x-musepack, streamversion = (int) 7");
3098 } else if (!strcmp (format_name, "vqf")) {
3099 caps = gst_caps_from_string ("audio/x-vqf");
3100 } else if (!strcmp (format_name, "nsv")) {
3101 caps = gst_caps_from_string ("video/x-nsv");
3102 } else if (!strcmp (format_name, "amr")) {
3103 caps = gst_caps_from_string ("audio/x-amr-nb-sh");
3104 } else if (!strcmp (format_name, "webm")) {
3105 caps = gst_caps_from_string ("video/webm");
3106 } else if (!strcmp (format_name, "voc")) {
3107 caps = gst_caps_from_string ("audio/x-voc");
3108 } else if (!strcmp (format_name, "pva")) {
3109 caps = gst_caps_from_string ("video/x-pva");
3113 GST_LOG ("Could not create stream format caps for %s", format_name);
3114 name = g_strdup_printf ("application/x-gst-av-%s", format_name);
3115 caps = gst_caps_new_empty_simple (name);
3123 gst_ffmpeg_formatid_get_codecids (const gchar * format_name,
3124 enum CodecID ** video_codec_list, enum CodecID ** audio_codec_list,
3125 AVOutputFormat * plugin)
3127 static enum CodecID tmp_vlist[] = {
3131 static enum CodecID tmp_alist[] = {
3136 GST_LOG ("format_name : %s", format_name);
3138 if (!strcmp (format_name, "mp4")) {
3139 static enum CodecID mp4_video_list[] = {
3140 AV_CODEC_ID_MPEG4, AV_CODEC_ID_H264,
3144 static enum CodecID mp4_audio_list[] = {
3145 AV_CODEC_ID_AAC, AV_CODEC_ID_MP3,
3149 *video_codec_list = mp4_video_list;
3150 *audio_codec_list = mp4_audio_list;
3151 } else if (!strcmp (format_name, "mpeg")) {
3152 static enum CodecID mpeg_video_list[] = { AV_CODEC_ID_MPEG1VIDEO,
3153 AV_CODEC_ID_MPEG2VIDEO,
3157 static enum CodecID mpeg_audio_list[] = { AV_CODEC_ID_MP1,
3163 *video_codec_list = mpeg_video_list;
3164 *audio_codec_list = mpeg_audio_list;
3165 } else if (!strcmp (format_name, "dvd")) {
3166 static enum CodecID mpeg_video_list[] = { AV_CODEC_ID_MPEG2VIDEO,
3169 static enum CodecID mpeg_audio_list[] = { AV_CODEC_ID_MP2,
3172 AV_CODEC_ID_PCM_S16BE,
3176 *video_codec_list = mpeg_video_list;
3177 *audio_codec_list = mpeg_audio_list;
3178 } else if (!strcmp (format_name, "mpegts")) {
3179 static enum CodecID mpegts_video_list[] = { AV_CODEC_ID_MPEG1VIDEO,
3180 AV_CODEC_ID_MPEG2VIDEO,
3184 static enum CodecID mpegts_audio_list[] = { AV_CODEC_ID_MP2,
3192 *video_codec_list = mpegts_video_list;
3193 *audio_codec_list = mpegts_audio_list;
3194 } else if (!strcmp (format_name, "vob")) {
3195 static enum CodecID vob_video_list[] =
3196 { AV_CODEC_ID_MPEG2VIDEO, AV_CODEC_ID_NONE };
3197 static enum CodecID vob_audio_list[] = { AV_CODEC_ID_MP2, AV_CODEC_ID_AC3,
3198 AV_CODEC_ID_DTS, AV_CODEC_ID_NONE
3201 *video_codec_list = vob_video_list;
3202 *audio_codec_list = vob_audio_list;
3203 } else if (!strcmp (format_name, "flv")) {
3204 static enum CodecID flv_video_list[] =
3205 { AV_CODEC_ID_FLV1, AV_CODEC_ID_NONE };
3206 static enum CodecID flv_audio_list[] =
3207 { AV_CODEC_ID_MP3, AV_CODEC_ID_NONE };
3209 *video_codec_list = flv_video_list;
3210 *audio_codec_list = flv_audio_list;
3211 } else if (!strcmp (format_name, "asf")) {
3212 static enum CodecID asf_video_list[] =
3213 { AV_CODEC_ID_WMV1, AV_CODEC_ID_WMV2, AV_CODEC_ID_MSMPEG4V3,
3216 static enum CodecID asf_audio_list[] =
3217 { AV_CODEC_ID_WMAV1, AV_CODEC_ID_WMAV2, AV_CODEC_ID_MP3,
3221 *video_codec_list = asf_video_list;
3222 *audio_codec_list = asf_audio_list;
3223 } else if (!strcmp (format_name, "dv")) {
3224 static enum CodecID dv_video_list[] =
3225 { AV_CODEC_ID_DVVIDEO, AV_CODEC_ID_NONE };
3226 static enum CodecID dv_audio_list[] =
3227 { AV_CODEC_ID_PCM_S16LE, AV_CODEC_ID_NONE };
3229 *video_codec_list = dv_video_list;
3230 *audio_codec_list = dv_audio_list;
3231 } else if (!strcmp (format_name, "mov")) {
3232 static enum CodecID mov_video_list[] = {
3233 AV_CODEC_ID_SVQ1, AV_CODEC_ID_SVQ3, AV_CODEC_ID_MPEG4,
3234 AV_CODEC_ID_H263, AV_CODEC_ID_H263P,
3235 AV_CODEC_ID_H264, AV_CODEC_ID_DVVIDEO,
3239 static enum CodecID mov_audio_list[] = {
3240 AV_CODEC_ID_PCM_MULAW, AV_CODEC_ID_PCM_ALAW, AV_CODEC_ID_ADPCM_IMA_QT,
3241 AV_CODEC_ID_MACE3, AV_CODEC_ID_MACE6, AV_CODEC_ID_AAC,
3242 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3243 AV_CODEC_ID_PCM_S16BE, AV_CODEC_ID_PCM_S16LE,
3244 AV_CODEC_ID_MP3, AV_CODEC_ID_NONE
3247 *video_codec_list = mov_video_list;
3248 *audio_codec_list = mov_audio_list;
3249 } else if ((!strcmp (format_name, "3gp") || !strcmp (format_name, "3g2"))) {
3250 static enum CodecID tgp_video_list[] = {
3251 AV_CODEC_ID_MPEG4, AV_CODEC_ID_H263, AV_CODEC_ID_H263P, AV_CODEC_ID_H264,
3254 static enum CodecID tgp_audio_list[] = {
3255 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3260 *video_codec_list = tgp_video_list;
3261 *audio_codec_list = tgp_audio_list;
3262 } else if (!strcmp (format_name, "mmf")) {
3263 static enum CodecID mmf_audio_list[] = {
3264 AV_CODEC_ID_ADPCM_YAMAHA, AV_CODEC_ID_NONE
3266 *video_codec_list = NULL;
3267 *audio_codec_list = mmf_audio_list;
3268 } else if (!strcmp (format_name, "amr")) {
3269 static enum CodecID amr_audio_list[] = {
3270 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3273 *video_codec_list = NULL;
3274 *audio_codec_list = amr_audio_list;
3275 } else if (!strcmp (format_name, "gif")) {
3276 static enum CodecID gif_image_list[] = {
3277 AV_CODEC_ID_RAWVIDEO, AV_CODEC_ID_NONE
3279 *video_codec_list = gif_image_list;
3280 *audio_codec_list = NULL;
3281 } else if ((plugin->audio_codec != AV_CODEC_ID_NONE) ||
3282 (plugin->video_codec != AV_CODEC_ID_NONE)) {
3283 tmp_vlist[0] = plugin->video_codec;
3284 tmp_alist[0] = plugin->audio_codec;
3286 *video_codec_list = tmp_vlist;
3287 *audio_codec_list = tmp_alist;
3288 } else if ((!strcmp (format_name, "pva"))) {
3289 static enum CodecID tgp_video_list[] = {
3290 AV_CODEC_ID_MPEG2VIDEO,
3293 static enum CodecID tgp_audio_list[] = {
3298 *video_codec_list = tgp_video_list;
3299 *audio_codec_list = tgp_audio_list;
3301 GST_LOG ("Format %s not found", format_name);
3308 /* Convert a GstCaps to a FFMPEG codec ID. Size et all
3309 * are omitted, that can be queried by the user itself,
3310 * we're not eating the GstCaps or anything
3311 * A pointer to an allocated context is also needed for
3312 * optional extra info
3316 gst_ffmpeg_caps_to_codecid (const GstCaps * caps, AVCodecContext * context)
3318 enum CodecID id = AV_CODEC_ID_NONE;
3319 const gchar *mimetype;
3320 const GstStructure *structure;
3321 gboolean video = FALSE, audio = FALSE; /* we want to be sure! */
3323 g_return_val_if_fail (caps != NULL, AV_CODEC_ID_NONE);
3324 g_return_val_if_fail (gst_caps_get_size (caps) == 1, AV_CODEC_ID_NONE);
3325 structure = gst_caps_get_structure (caps, 0);
3327 mimetype = gst_structure_get_name (structure);
3329 if (!strcmp (mimetype, "video/x-raw")) {
3330 id = AV_CODEC_ID_RAWVIDEO;
3332 } else if (!strcmp (mimetype, "audio/x-raw")) {
3335 if (gst_audio_info_from_caps (&info, caps)) {
3336 switch (GST_AUDIO_INFO_FORMAT (&info)) {
3337 case GST_AUDIO_FORMAT_S8:
3338 id = AV_CODEC_ID_PCM_S8;
3340 case GST_AUDIO_FORMAT_U8:
3341 id = AV_CODEC_ID_PCM_U8;
3343 case GST_AUDIO_FORMAT_S16LE:
3344 id = AV_CODEC_ID_PCM_S16LE;
3346 case GST_AUDIO_FORMAT_S16BE:
3347 id = AV_CODEC_ID_PCM_S16BE;
3349 case GST_AUDIO_FORMAT_U16LE:
3350 id = AV_CODEC_ID_PCM_U16LE;
3352 case GST_AUDIO_FORMAT_U16BE:
3353 id = AV_CODEC_ID_PCM_U16BE;
3358 if (id != AV_CODEC_ID_NONE)
3361 } else if (!strcmp (mimetype, "audio/x-mulaw")) {
3362 id = AV_CODEC_ID_PCM_MULAW;
3364 } else if (!strcmp (mimetype, "audio/x-alaw")) {
3365 id = AV_CODEC_ID_PCM_ALAW;
3367 } else if (!strcmp (mimetype, "video/x-dv")) {
3370 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3372 id = AV_CODEC_ID_DVVIDEO;
3375 } else if (!strcmp (mimetype, "audio/x-dv")) { /* ??? */
3376 id = AV_CODEC_ID_DVAUDIO;
3378 } else if (!strcmp (mimetype, "video/x-h263")) {
3379 const gchar *h263version =
3380 gst_structure_get_string (structure, "h263version");
3381 if (h263version && !strcmp (h263version, "h263p"))
3382 id = AV_CODEC_ID_H263P;
3384 id = AV_CODEC_ID_H263;
3386 } else if (!strcmp (mimetype, "video/x-intel-h263")) {
3387 id = AV_CODEC_ID_H263I;
3389 } else if (!strcmp (mimetype, "video/x-h261")) {
3390 id = AV_CODEC_ID_H261;
3392 } else if (!strcmp (mimetype, "video/mpeg")) {
3396 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3397 gst_structure_get_int (structure, "mpegversion", &mpegversion) &&
3399 switch (mpegversion) {
3401 id = AV_CODEC_ID_MPEG1VIDEO;
3404 id = AV_CODEC_ID_MPEG2VIDEO;
3407 id = AV_CODEC_ID_MPEG4;
3411 if (id != AV_CODEC_ID_NONE)
3413 } else if (!strcmp (mimetype, "image/jpeg")) {
3414 id = AV_CODEC_ID_MJPEG; /* A... B... */
3416 } else if (!strcmp (mimetype, "video/x-jpeg-b")) {
3417 id = AV_CODEC_ID_MJPEGB;
3419 } else if (!strcmp (mimetype, "video/x-wmv")) {
3420 gint wmvversion = 0;
3422 if (gst_structure_get_int (structure, "wmvversion", &wmvversion)) {
3423 switch (wmvversion) {
3425 id = AV_CODEC_ID_WMV1;
3428 id = AV_CODEC_ID_WMV2;
3432 const gchar *format;
3434 /* WMV3 unless the fourcc exists and says otherwise */
3435 id = AV_CODEC_ID_WMV3;
3437 if ((format = gst_structure_get_string (structure, "format")) &&
3438 (g_str_equal (format, "WVC1") || g_str_equal (format, "WMVA")))
3439 id = AV_CODEC_ID_VC1;
3445 if (id != AV_CODEC_ID_NONE)
3447 } else if (!strcmp (mimetype, "audio/x-vorbis")) {
3448 id = AV_CODEC_ID_VORBIS;
3450 } else if (!strcmp (mimetype, "audio/x-qdm2")) {
3451 id = AV_CODEC_ID_QDM2;
3453 } else if (!strcmp (mimetype, "audio/mpeg")) {
3455 gint mpegversion = 0;
3457 if (gst_structure_get_int (structure, "mpegversion", &mpegversion)) {
3458 switch (mpegversion) {
3459 case 2: /* ffmpeg uses faad for both... */
3461 id = AV_CODEC_ID_AAC;
3464 if (gst_structure_get_int (structure, "layer", &layer)) {
3467 id = AV_CODEC_ID_MP1;
3470 id = AV_CODEC_ID_MP2;
3473 id = AV_CODEC_ID_MP3;
3479 if (id != AV_CODEC_ID_NONE)
3481 } else if (!strcmp (mimetype, "audio/x-musepack")) {
3482 gint streamversion = -1;
3484 if (gst_structure_get_int (structure, "streamversion", &streamversion)) {
3485 if (streamversion == 7)
3486 id = AV_CODEC_ID_MUSEPACK7;
3488 id = AV_CODEC_ID_MUSEPACK7;
3490 } else if (!strcmp (mimetype, "audio/x-wma")) {
3491 gint wmaversion = 0;
3493 if (gst_structure_get_int (structure, "wmaversion", &wmaversion)) {
3494 switch (wmaversion) {
3496 id = AV_CODEC_ID_WMAV1;
3499 id = AV_CODEC_ID_WMAV2;
3502 id = AV_CODEC_ID_WMAPRO;
3506 if (id != AV_CODEC_ID_NONE)
3508 } else if (!strcmp (mimetype, "audio/x-wms")) {
3509 id = AV_CODEC_ID_WMAVOICE;
3511 } else if (!strcmp (mimetype, "audio/x-ac3")) {
3512 id = AV_CODEC_ID_AC3;
3514 } else if (!strcmp (mimetype, "audio/x-eac3")) {
3515 id = AV_CODEC_ID_EAC3;
3517 } else if (!strcmp (mimetype, "audio/x-vnd.sony.atrac3") ||
3518 !strcmp (mimetype, "audio/atrac3")) {
3519 id = AV_CODEC_ID_ATRAC3;
3521 } else if (!strcmp (mimetype, "audio/x-dts")) {
3522 id = AV_CODEC_ID_DTS;
3524 } else if (!strcmp (mimetype, "application/x-ape")) {
3525 id = AV_CODEC_ID_APE;
3527 } else if (!strcmp (mimetype, "video/x-msmpeg")) {
3528 gint msmpegversion = 0;
3530 if (gst_structure_get_int (structure, "msmpegversion", &msmpegversion)) {
3531 switch (msmpegversion) {
3533 id = AV_CODEC_ID_MSMPEG4V1;
3536 id = AV_CODEC_ID_MSMPEG4V2;
3539 id = AV_CODEC_ID_MSMPEG4V3;
3543 if (id != AV_CODEC_ID_NONE)
3545 } else if (!strcmp (mimetype, "video/x-svq")) {
3546 gint svqversion = 0;
3548 if (gst_structure_get_int (structure, "svqversion", &svqversion)) {
3549 switch (svqversion) {
3551 id = AV_CODEC_ID_SVQ1;
3554 id = AV_CODEC_ID_SVQ3;
3558 if (id != AV_CODEC_ID_NONE)
3560 } else if (!strcmp (mimetype, "video/x-huffyuv")) {
3561 id = AV_CODEC_ID_HUFFYUV;
3563 } else if (!strcmp (mimetype, "audio/x-mace")) {
3564 gint maceversion = 0;
3566 if (gst_structure_get_int (structure, "maceversion", &maceversion)) {
3567 switch (maceversion) {
3569 id = AV_CODEC_ID_MACE3;
3572 id = AV_CODEC_ID_MACE6;
3576 if (id != AV_CODEC_ID_NONE)
3578 } else if (!strcmp (mimetype, "video/x-theora")) {
3579 id = AV_CODEC_ID_THEORA;
3581 } else if (!strcmp (mimetype, "video/x-vp3")) {
3582 id = AV_CODEC_ID_VP3;
3584 } else if (!strcmp (mimetype, "video/x-vp5")) {
3585 id = AV_CODEC_ID_VP5;
3587 } else if (!strcmp (mimetype, "video/x-vp6")) {
3588 id = AV_CODEC_ID_VP6;
3590 } else if (!strcmp (mimetype, "video/x-vp6-flash")) {
3591 id = AV_CODEC_ID_VP6F;
3593 } else if (!strcmp (mimetype, "video/x-vp6-alpha")) {
3594 id = AV_CODEC_ID_VP6A;
3596 } else if (!strcmp (mimetype, "video/x-vp8")) {
3597 id = AV_CODEC_ID_VP8;
3599 } else if (!strcmp (mimetype, "video/x-flash-screen")) {
3600 id = AV_CODEC_ID_FLASHSV;
3602 } else if (!strcmp (mimetype, "video/x-indeo")) {
3603 gint indeoversion = 0;
3605 if (gst_structure_get_int (structure, "indeoversion", &indeoversion)) {
3606 switch (indeoversion) {
3608 id = AV_CODEC_ID_INDEO5;
3611 id = AV_CODEC_ID_INDEO4;
3614 id = AV_CODEC_ID_INDEO3;
3617 id = AV_CODEC_ID_INDEO2;
3620 if (id != AV_CODEC_ID_NONE)
3623 } else if (!strcmp (mimetype, "video/x-divx")) {
3624 gint divxversion = 0;
3626 if (gst_structure_get_int (structure, "divxversion", &divxversion)) {
3627 switch (divxversion) {
3629 id = AV_CODEC_ID_MSMPEG4V3;
3633 id = AV_CODEC_ID_MPEG4;
3637 if (id != AV_CODEC_ID_NONE)
3639 } else if (!strcmp (mimetype, "video/x-3ivx")) {
3640 id = AV_CODEC_ID_MPEG4;
3642 } else if (!strcmp (mimetype, "video/x-xvid")) {
3643 id = AV_CODEC_ID_MPEG4;
3645 } else if (!strcmp (mimetype, "video/x-ffv")) {
3646 gint ffvversion = 0;
3648 if (gst_structure_get_int (structure, "ffvversion", &ffvversion) &&
3650 id = AV_CODEC_ID_FFV1;
3653 } else if (!strcmp (mimetype, "audio/x-adpcm")) {
3654 const gchar *layout;
3656 layout = gst_structure_get_string (structure, "layout");
3657 if (layout == NULL) {
3659 } else if (!strcmp (layout, "quicktime")) {
3660 id = AV_CODEC_ID_ADPCM_IMA_QT;
3661 } else if (!strcmp (layout, "microsoft")) {
3662 id = AV_CODEC_ID_ADPCM_MS;
3663 } else if (!strcmp (layout, "dvi")) {
3664 id = AV_CODEC_ID_ADPCM_IMA_WAV;
3665 } else if (!strcmp (layout, "4xm")) {
3666 id = AV_CODEC_ID_ADPCM_4XM;
3667 } else if (!strcmp (layout, "smjpeg")) {
3668 id = AV_CODEC_ID_ADPCM_IMA_SMJPEG;
3669 } else if (!strcmp (layout, "dk3")) {
3670 id = AV_CODEC_ID_ADPCM_IMA_DK3;
3671 } else if (!strcmp (layout, "dk4")) {
3672 id = AV_CODEC_ID_ADPCM_IMA_DK4;
3673 } else if (!strcmp (layout, "westwood")) {
3674 id = AV_CODEC_ID_ADPCM_IMA_WS;
3675 } else if (!strcmp (layout, "iss")) {
3676 id = AV_CODEC_ID_ADPCM_IMA_ISS;
3677 } else if (!strcmp (layout, "xa")) {
3678 id = AV_CODEC_ID_ADPCM_XA;
3679 } else if (!strcmp (layout, "adx")) {
3680 id = AV_CODEC_ID_ADPCM_ADX;
3681 } else if (!strcmp (layout, "ea")) {
3682 id = AV_CODEC_ID_ADPCM_EA;
3683 } else if (!strcmp (layout, "g726")) {
3684 id = AV_CODEC_ID_ADPCM_G726;
3685 } else if (!strcmp (layout, "g721")) {
3686 id = AV_CODEC_ID_ADPCM_G726;
3687 } else if (!strcmp (layout, "ct")) {
3688 id = AV_CODEC_ID_ADPCM_CT;
3689 } else if (!strcmp (layout, "swf")) {
3690 id = AV_CODEC_ID_ADPCM_SWF;
3691 } else if (!strcmp (layout, "yamaha")) {
3692 id = AV_CODEC_ID_ADPCM_YAMAHA;
3693 } else if (!strcmp (layout, "sbpro2")) {
3694 id = AV_CODEC_ID_ADPCM_SBPRO_2;
3695 } else if (!strcmp (layout, "sbpro3")) {
3696 id = AV_CODEC_ID_ADPCM_SBPRO_3;
3697 } else if (!strcmp (layout, "sbpro4")) {
3698 id = AV_CODEC_ID_ADPCM_SBPRO_4;
3700 if (id != AV_CODEC_ID_NONE)
3702 } else if (!strcmp (mimetype, "video/x-4xm")) {
3703 id = AV_CODEC_ID_4XM;
3705 } else if (!strcmp (mimetype, "audio/x-dpcm")) {
3706 const gchar *layout;
3708 layout = gst_structure_get_string (structure, "layout");
3711 } else if (!strcmp (layout, "roq")) {
3712 id = AV_CODEC_ID_ROQ_DPCM;
3713 } else if (!strcmp (layout, "interplay")) {
3714 id = AV_CODEC_ID_INTERPLAY_DPCM;
3715 } else if (!strcmp (layout, "xan")) {
3716 id = AV_CODEC_ID_XAN_DPCM;
3717 } else if (!strcmp (layout, "sol")) {
3718 id = AV_CODEC_ID_SOL_DPCM;
3720 if (id != AV_CODEC_ID_NONE)
3722 } else if (!strcmp (mimetype, "audio/x-flac")) {
3723 id = AV_CODEC_ID_FLAC;
3725 } else if (!strcmp (mimetype, "audio/x-shorten")) {
3726 id = AV_CODEC_ID_SHORTEN;
3728 } else if (!strcmp (mimetype, "audio/x-alac")) {
3729 id = AV_CODEC_ID_ALAC;
3731 } else if (!strcmp (mimetype, "video/x-cinepak")) {
3732 id = AV_CODEC_ID_CINEPAK;
3734 } else if (!strcmp (mimetype, "video/x-pn-realvideo")) {
3737 if (gst_structure_get_int (structure, "rmversion", &rmversion)) {
3738 switch (rmversion) {
3740 id = AV_CODEC_ID_RV10;
3743 id = AV_CODEC_ID_RV20;
3746 id = AV_CODEC_ID_RV30;
3749 id = AV_CODEC_ID_RV40;
3753 if (id != AV_CODEC_ID_NONE)
3755 } else if (!strcmp (mimetype, "audio/x-sipro")) {
3756 id = AV_CODEC_ID_SIPR;
3758 } else if (!strcmp (mimetype, "audio/x-pn-realaudio")) {
3761 if (gst_structure_get_int (structure, "raversion", &raversion)) {
3762 switch (raversion) {
3764 id = AV_CODEC_ID_RA_144;
3767 id = AV_CODEC_ID_RA_288;
3770 id = AV_CODEC_ID_COOK;
3774 if (id != AV_CODEC_ID_NONE)
3776 } else if (!strcmp (mimetype, "video/x-rle")) {
3777 const gchar *layout;
3779 if ((layout = gst_structure_get_string (structure, "layout"))) {
3780 if (!strcmp (layout, "microsoft")) {
3781 id = AV_CODEC_ID_MSRLE;
3785 } else if (!strcmp (mimetype, "video/x-xan")) {
3788 if ((gst_structure_get_int (structure, "wcversion", &wcversion))) {
3789 switch (wcversion) {
3791 id = AV_CODEC_ID_XAN_WC3;
3795 id = AV_CODEC_ID_XAN_WC4;
3802 } else if (!strcmp (mimetype, "audio/AMR")) {
3804 id = AV_CODEC_ID_AMR_NB;
3805 } else if (!strcmp (mimetype, "audio/AMR-WB")) {
3806 id = AV_CODEC_ID_AMR_WB;
3808 } else if (!strcmp (mimetype, "audio/qcelp")) {
3809 id = AV_CODEC_ID_QCELP;
3811 } else if (!strcmp (mimetype, "video/x-h264")) {
3812 id = AV_CODEC_ID_H264;
3814 } else if (!strcmp (mimetype, "video/x-flash-video")) {
3815 gint flvversion = 0;
3817 if ((gst_structure_get_int (structure, "flvversion", &flvversion))) {
3818 switch (flvversion) {
3820 id = AV_CODEC_ID_FLV1;
3828 } else if (!strcmp (mimetype, "audio/x-nellymoser")) {
3829 id = AV_CODEC_ID_NELLYMOSER;
3831 } else if (!strncmp (mimetype, "audio/x-gst-av-", 15)) {
3835 if (strlen (mimetype) <= 30 &&
3836 sscanf (mimetype, "audio/x-gst-av-%s", ext) == 1) {
3837 if ((codec = avcodec_find_decoder_by_name (ext)) ||
3838 (codec = avcodec_find_encoder_by_name (ext))) {
3843 } else if (!strncmp (mimetype, "video/x-gst-av-", 15)) {
3847 if (strlen (mimetype) <= 30 &&
3848 sscanf (mimetype, "video/x-gst-av-%s", ext) == 1) {
3849 if ((codec = avcodec_find_decoder_by_name (ext)) ||
3850 (codec = avcodec_find_encoder_by_name (ext))) {
3857 if (context != NULL) {
3858 if (video == TRUE) {
3859 context->codec_type = AVMEDIA_TYPE_VIDEO;
3860 } else if (audio == TRUE) {
3861 context->codec_type = AVMEDIA_TYPE_AUDIO;
3863 context->codec_type = AVMEDIA_TYPE_UNKNOWN;
3865 context->codec_id = id;
3866 gst_ffmpeg_caps_with_codecid (id, context->codec_type, caps, context);
3869 if (id != AV_CODEC_ID_NONE) {
3870 GST_DEBUG ("The id=%d belongs to the caps %" GST_PTR_FORMAT, id, caps);
3872 GST_WARNING ("Couldn't figure out the id for caps %" GST_PTR_FORMAT, caps);