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_TSCC2:
1452 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1453 "video/x-tscc", "tsccversion", G_TYPE_INT, 2, NULL);
1456 case AV_CODEC_ID_KMVC:
1458 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-kmvc",
1462 case AV_CODEC_ID_NUV:
1464 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-nuv",
1468 case AV_CODEC_ID_GIF:
1470 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/gif",
1474 case AV_CODEC_ID_PNG:
1476 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/png",
1480 case AV_CODEC_ID_PPM:
1482 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/ppm",
1486 case AV_CODEC_ID_PBM:
1488 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/pbm",
1492 case AV_CODEC_ID_PAM:
1494 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1495 "image/x-portable-anymap", NULL);
1498 case AV_CODEC_ID_PGM:
1500 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1501 "image/x-portable-graymap", NULL);
1504 case AV_CODEC_ID_PCX:
1506 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-pcx",
1510 case AV_CODEC_ID_SGI:
1512 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-sgi",
1516 case AV_CODEC_ID_TARGA:
1518 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-tga",
1522 case AV_CODEC_ID_TIFF:
1524 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/tiff",
1528 case AV_CODEC_ID_SUNRAST:
1530 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1531 "image/x-sun-raster", NULL);
1534 case AV_CODEC_ID_SMC:
1536 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-smc",
1540 case AV_CODEC_ID_QDRAW:
1542 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-qdrw",
1546 case AV_CODEC_ID_DNXHD:
1548 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dnxhd",
1552 case AV_CODEC_ID_PRORES:
1554 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1555 "video/x-prores", NULL);
1558 case AV_CODEC_ID_MIMIC:
1560 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-mimic",
1564 case AV_CODEC_ID_VMNC:
1566 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vmnc",
1570 case AV_CODEC_ID_TRUESPEECH:
1572 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1573 "audio/x-truespeech", NULL);
1576 case AV_CODEC_ID_QCELP:
1578 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/qcelp",
1582 case AV_CODEC_ID_AMV:
1584 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-amv",
1588 case AV_CODEC_ID_AASC:
1590 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-aasc",
1594 case AV_CODEC_ID_LOCO:
1596 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-loco",
1600 case AV_CODEC_ID_ZMBV:
1602 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-zmbv",
1606 case AV_CODEC_ID_LAGARITH:
1608 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1609 "video/x-lagarith", NULL);
1612 case AV_CODEC_ID_CSCD:
1614 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1615 "video/x-camstudio", NULL);
1617 gst_caps_set_simple (caps,
1618 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1620 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1624 case AV_CODEC_ID_WS_VQA:
1625 case AV_CODEC_ID_IDCIN:
1626 case AV_CODEC_ID_8BPS:
1627 case AV_CODEC_ID_FLIC:
1628 case AV_CODEC_ID_VMDVIDEO:
1629 case AV_CODEC_ID_VMDAUDIO:
1630 case AV_CODEC_ID_SNOW:
1631 case AV_CODEC_ID_VIXL:
1632 case AV_CODEC_ID_QPEG:
1633 case AV_CODEC_ID_PGMYUV:
1634 case AV_CODEC_ID_FFVHUFF:
1635 case AV_CODEC_ID_WNV1:
1636 case AV_CODEC_ID_MP3ADU:
1637 case AV_CODEC_ID_MP3ON4:
1638 case AV_CODEC_ID_WESTWOOD_SND1:
1639 case AV_CODEC_ID_MMVIDEO:
1640 case AV_CODEC_ID_AVS:
1641 case AV_CODEC_ID_CAVS:
1645 /* weird quasi-codecs for the demuxers only */
1646 case AV_CODEC_ID_PCM_S16LE:
1647 case AV_CODEC_ID_PCM_S16BE:
1648 case AV_CODEC_ID_PCM_U16LE:
1649 case AV_CODEC_ID_PCM_U16BE:
1650 case AV_CODEC_ID_PCM_S8:
1651 case AV_CODEC_ID_PCM_U8:
1653 GstAudioFormat format;
1656 case AV_CODEC_ID_PCM_S16LE:
1657 format = GST_AUDIO_FORMAT_S16LE;
1659 case AV_CODEC_ID_PCM_S16BE:
1660 format = GST_AUDIO_FORMAT_S16BE;
1662 case AV_CODEC_ID_PCM_U16LE:
1663 format = GST_AUDIO_FORMAT_U16LE;
1665 case AV_CODEC_ID_PCM_U16BE:
1666 format = GST_AUDIO_FORMAT_U16BE;
1668 case AV_CODEC_ID_PCM_S8:
1669 format = GST_AUDIO_FORMAT_S8;
1671 case AV_CODEC_ID_PCM_U8:
1672 format = GST_AUDIO_FORMAT_U8;
1675 g_assert (0); /* don't worry, we never get here */
1680 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-raw",
1681 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
1682 "layout", G_TYPE_STRING, "interleaved", NULL);
1686 case AV_CODEC_ID_PCM_MULAW:
1688 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mulaw",
1692 case AV_CODEC_ID_PCM_ALAW:
1694 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-alaw",
1698 case AV_CODEC_ID_ADPCM_G722:
1700 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/G722",
1703 gst_caps_set_simple (caps,
1704 "block_align", G_TYPE_INT, context->block_align,
1705 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1708 case AV_CODEC_ID_ADPCM_G726:
1710 /* the G726 decoder can also handle G721 */
1712 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-adpcm",
1713 "layout", G_TYPE_STRING, "g726", NULL);
1715 gst_caps_set_simple (caps,
1716 "block_align", G_TYPE_INT, context->block_align,
1717 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1720 gst_caps_append (caps, gst_caps_new_simple ("audio/x-adpcm",
1721 "layout", G_TYPE_STRING, "g721",
1722 "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, 8000, NULL));
1726 case AV_CODEC_ID_ADPCM_IMA_QT:
1727 case AV_CODEC_ID_ADPCM_IMA_WAV:
1728 case AV_CODEC_ID_ADPCM_IMA_DK3:
1729 case AV_CODEC_ID_ADPCM_IMA_DK4:
1730 case AV_CODEC_ID_ADPCM_IMA_WS:
1731 case AV_CODEC_ID_ADPCM_IMA_SMJPEG:
1732 case AV_CODEC_ID_ADPCM_IMA_AMV:
1733 case AV_CODEC_ID_ADPCM_IMA_ISS:
1734 case AV_CODEC_ID_ADPCM_IMA_EA_EACS:
1735 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
1736 case AV_CODEC_ID_ADPCM_MS:
1737 case AV_CODEC_ID_ADPCM_4XM:
1738 case AV_CODEC_ID_ADPCM_XA:
1739 case AV_CODEC_ID_ADPCM_ADX:
1740 case AV_CODEC_ID_ADPCM_EA:
1741 case AV_CODEC_ID_ADPCM_CT:
1742 case AV_CODEC_ID_ADPCM_SWF:
1743 case AV_CODEC_ID_ADPCM_YAMAHA:
1744 case AV_CODEC_ID_ADPCM_SBPRO_2:
1745 case AV_CODEC_ID_ADPCM_SBPRO_3:
1746 case AV_CODEC_ID_ADPCM_SBPRO_4:
1747 case AV_CODEC_ID_ADPCM_EA_R1:
1748 case AV_CODEC_ID_ADPCM_EA_R2:
1749 case AV_CODEC_ID_ADPCM_EA_R3:
1750 case AV_CODEC_ID_ADPCM_EA_MAXIS_XA:
1751 case AV_CODEC_ID_ADPCM_EA_XAS:
1752 case AV_CODEC_ID_ADPCM_THP:
1754 const gchar *layout = NULL;
1757 case AV_CODEC_ID_ADPCM_IMA_QT:
1758 layout = "quicktime";
1760 case AV_CODEC_ID_ADPCM_IMA_WAV:
1763 case AV_CODEC_ID_ADPCM_IMA_DK3:
1766 case AV_CODEC_ID_ADPCM_IMA_DK4:
1769 case AV_CODEC_ID_ADPCM_IMA_WS:
1770 layout = "westwood";
1772 case AV_CODEC_ID_ADPCM_IMA_SMJPEG:
1775 case AV_CODEC_ID_ADPCM_IMA_AMV:
1778 case AV_CODEC_ID_ADPCM_IMA_ISS:
1781 case AV_CODEC_ID_ADPCM_IMA_EA_EACS:
1784 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
1787 case AV_CODEC_ID_ADPCM_MS:
1788 layout = "microsoft";
1790 case AV_CODEC_ID_ADPCM_4XM:
1793 case AV_CODEC_ID_ADPCM_XA:
1796 case AV_CODEC_ID_ADPCM_ADX:
1799 case AV_CODEC_ID_ADPCM_EA:
1802 case AV_CODEC_ID_ADPCM_CT:
1805 case AV_CODEC_ID_ADPCM_SWF:
1808 case AV_CODEC_ID_ADPCM_YAMAHA:
1811 case AV_CODEC_ID_ADPCM_SBPRO_2:
1814 case AV_CODEC_ID_ADPCM_SBPRO_3:
1817 case AV_CODEC_ID_ADPCM_SBPRO_4:
1820 case AV_CODEC_ID_ADPCM_EA_R1:
1823 case AV_CODEC_ID_ADPCM_EA_R2:
1826 case AV_CODEC_ID_ADPCM_EA_R3:
1829 case AV_CODEC_ID_ADPCM_EA_MAXIS_XA:
1830 layout = "ea-maxis-xa";
1832 case AV_CODEC_ID_ADPCM_EA_XAS:
1835 case AV_CODEC_ID_ADPCM_THP:
1839 g_assert (0); /* don't worry, we never get here */
1843 /* FIXME: someone please check whether we need additional properties
1844 * in this caps definition. */
1846 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-adpcm",
1847 "layout", G_TYPE_STRING, layout, NULL);
1849 gst_caps_set_simple (caps,
1850 "block_align", G_TYPE_INT, context->block_align,
1851 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1855 case AV_CODEC_ID_AMR_NB:
1857 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/AMR",
1861 case AV_CODEC_ID_AMR_WB:
1863 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/AMR-WB",
1867 case AV_CODEC_ID_GSM:
1869 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-gsm",
1873 case AV_CODEC_ID_GSM_MS:
1875 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/ms-gsm",
1879 case AV_CODEC_ID_NELLYMOSER:
1881 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1882 "audio/x-nellymoser", NULL);
1885 case AV_CODEC_ID_SIPR:
1888 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-sipro",
1891 gst_caps_set_simple (caps,
1892 "leaf_size", G_TYPE_INT, context->block_align,
1893 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1898 case AV_CODEC_ID_RA_144:
1899 case AV_CODEC_ID_RA_288:
1900 case AV_CODEC_ID_COOK:
1905 case AV_CODEC_ID_RA_144:
1908 case AV_CODEC_ID_RA_288:
1911 case AV_CODEC_ID_COOK:
1918 /* FIXME: properties? */
1920 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1921 "audio/x-pn-realaudio", "raversion", G_TYPE_INT, version, NULL);
1923 gst_caps_set_simple (caps,
1924 "leaf_size", G_TYPE_INT, context->block_align,
1925 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1930 case AV_CODEC_ID_ROQ_DPCM:
1931 case AV_CODEC_ID_INTERPLAY_DPCM:
1932 case AV_CODEC_ID_XAN_DPCM:
1933 case AV_CODEC_ID_SOL_DPCM:
1935 const gchar *layout = NULL;
1938 case AV_CODEC_ID_ROQ_DPCM:
1941 case AV_CODEC_ID_INTERPLAY_DPCM:
1942 layout = "interplay";
1944 case AV_CODEC_ID_XAN_DPCM:
1947 case AV_CODEC_ID_SOL_DPCM:
1951 g_assert (0); /* don't worry, we never get here */
1955 /* FIXME: someone please check whether we need additional properties
1956 * in this caps definition. */
1958 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dpcm",
1959 "layout", G_TYPE_STRING, layout, NULL);
1961 gst_caps_set_simple (caps,
1962 "block_align", G_TYPE_INT, context->block_align,
1963 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1967 case AV_CODEC_ID_SHORTEN:
1968 caps = gst_caps_new_empty_simple ("audio/x-shorten");
1971 case AV_CODEC_ID_ALAC:
1973 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-alac",
1976 gst_caps_set_simple (caps,
1977 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
1981 case AV_CODEC_ID_FLAC:
1982 /* Note that ffmpeg has no encoder yet, but just for safety. In the
1983 * encoder case, we want to add things like samplerate, channels... */
1985 caps = gst_caps_new_empty_simple ("audio/x-flac");
1989 case AV_CODEC_ID_S302M:
1990 caps = gst_caps_new_empty_simple ("audio/x-smpte-302m");
1993 case AV_CODEC_ID_DVD_SUBTITLE:
1994 case AV_CODEC_ID_DVB_SUBTITLE:
1997 case AV_CODEC_ID_BMP:
1998 caps = gst_caps_new_empty_simple ("image/bmp");
2000 case AV_CODEC_ID_TTA:
2002 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-tta",
2005 gst_caps_set_simple (caps,
2006 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
2009 case AV_CODEC_ID_TWINVQ:
2011 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
2012 "audio/x-twin-vq", NULL);
2015 GST_DEBUG ("Unknown codec ID %d, please add mapping here", codec_id);
2022 if ((codec = avcodec_find_decoder (codec_id)) ||
2023 (codec = avcodec_find_encoder (codec_id))) {
2026 GST_LOG ("Could not create stream format caps for %s", codec->name);
2028 switch (codec->type) {
2029 case AVMEDIA_TYPE_VIDEO:
2030 mime = g_strdup_printf ("video/x-gst-av-%s", codec->name);
2032 gst_ff_vid_caps_new (context, NULL, codec_id, encode, mime, NULL);
2035 case AVMEDIA_TYPE_AUDIO:
2036 mime = g_strdup_printf ("audio/x-gst-av-%s", codec->name);
2038 gst_ff_aud_caps_new (context, NULL, codec_id, encode, mime, NULL);
2040 gst_caps_set_simple (caps,
2041 "block_align", G_TYPE_INT, context->block_align,
2042 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
2053 /* set private data */
2054 if (context && context->extradata_size > 0) {
2055 GstBuffer *data = gst_buffer_new_and_alloc (context->extradata_size);
2057 gst_buffer_fill (data, 0, context->extradata, context->extradata_size);
2058 gst_caps_set_simple (caps, "codec_data", GST_TYPE_BUFFER, data, NULL);
2059 gst_buffer_unref (data);
2062 GST_LOG ("caps for codec_id=%d: %" GST_PTR_FORMAT, codec_id, caps);
2065 GST_LOG ("No caps found for codec_id=%d", codec_id);
2071 /* Convert a FFMPEG Pixel Format and optional AVCodecContext
2072 * to a GstCaps. If the context is ommitted, no fixed values
2073 * for video/audio size will be included in the GstCaps
2075 * See below for usefullness
2079 gst_ffmpeg_pixfmt_to_caps (enum PixelFormat pix_fmt, AVCodecContext * context,
2080 enum CodecID codec_id)
2082 GstCaps *caps = NULL;
2083 GstVideoFormat format;
2085 format = gst_ffmpeg_pixfmt_to_videoformat (pix_fmt);
2087 if (format != GST_VIDEO_FORMAT_UNKNOWN) {
2088 caps = gst_ff_vid_caps_new (context, NULL, codec_id, TRUE, "video/x-raw",
2089 "format", G_TYPE_STRING, gst_video_format_to_string (format), NULL);
2093 GST_DEBUG ("caps for pix_fmt=%d: %" GST_PTR_FORMAT, pix_fmt, caps);
2095 GST_LOG ("No caps found for pix_fmt=%d", pix_fmt);
2102 gst_ffmpeg_smpfmt_to_audioformat (enum AVSampleFormat sample_fmt)
2104 switch (sample_fmt) {
2105 case AV_SAMPLE_FMT_U8:
2106 case AV_SAMPLE_FMT_U8P:
2107 return GST_AUDIO_FORMAT_U8;
2109 case AV_SAMPLE_FMT_S16:
2110 case AV_SAMPLE_FMT_S16P:
2111 return GST_AUDIO_FORMAT_S16;
2113 case AV_SAMPLE_FMT_S32:
2114 case AV_SAMPLE_FMT_S32P:
2115 return GST_AUDIO_FORMAT_S32;
2117 case AV_SAMPLE_FMT_FLT:
2118 case AV_SAMPLE_FMT_FLTP:
2119 return GST_AUDIO_FORMAT_F32;
2121 case AV_SAMPLE_FMT_DBL:
2122 case AV_SAMPLE_FMT_DBLP:
2123 return GST_AUDIO_FORMAT_F64;
2127 return GST_AUDIO_FORMAT_UNKNOWN;
2132 /* Convert a FFMPEG Sample Format and optional AVCodecContext
2133 * to a GstCaps. If the context is ommitted, no fixed values
2134 * for video/audio size will be included in the GstCaps
2136 * See below for usefullness
2140 gst_ffmpeg_smpfmt_to_caps (enum AVSampleFormat sample_fmt,
2141 AVCodecContext * context, AVCodec * codec, enum CodecID codec_id)
2143 GstCaps *caps = NULL;
2144 GstAudioFormat format;
2146 format = gst_ffmpeg_smpfmt_to_audioformat (sample_fmt);
2148 if (format != GST_AUDIO_FORMAT_UNKNOWN) {
2149 caps = gst_ff_aud_caps_new (context, codec, codec_id, TRUE, "audio/x-raw",
2150 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
2151 "layout", G_TYPE_STRING, "interleaved", NULL);
2152 GST_LOG ("caps for sample_fmt=%d: %" GST_PTR_FORMAT, sample_fmt, caps);
2154 GST_LOG ("No caps found for sample_fmt=%d", sample_fmt);
2161 caps_has_field (GstCaps * caps, const gchar * field)
2165 n = gst_caps_get_size (caps);
2166 for (i = 0; i < n; i++) {
2167 GstStructure *s = gst_caps_get_structure (caps, i);
2169 if (gst_structure_has_field (s, field))
2177 gst_ffmpeg_codectype_to_audio_caps (AVCodecContext * context,
2178 enum CodecID codec_id, gboolean encode, AVCodec * codec)
2180 GstCaps *caps = NULL;
2182 GST_DEBUG ("context:%p, codec_id:%d, encode:%d, codec:%p",
2183 context, codec_id, encode, codec);
2185 GST_DEBUG ("sample_fmts:%p, samplerates:%p",
2186 codec->sample_fmts, codec->supported_samplerates);
2189 /* Specific codec context */
2191 gst_ffmpeg_smpfmt_to_caps (context->sample_fmt, context, codec,
2194 caps = gst_ff_aud_caps_new (context, codec, codec_id, encode, "audio/x-raw",
2195 "layout", G_TYPE_STRING, "interleaved", NULL);
2196 if (!caps_has_field (caps, "format"))
2197 gst_ffmpeg_audio_set_sample_fmts (caps,
2198 codec ? codec->sample_fmts : NULL);
2205 gst_ffmpeg_codectype_to_video_caps (AVCodecContext * context,
2206 enum CodecID codec_id, gboolean encode, AVCodec * codec)
2210 GST_LOG ("context:%p, codec_id:%d, encode:%d, codec:%p",
2211 context, codec_id, encode, codec);
2214 caps = gst_ffmpeg_pixfmt_to_caps (context->pix_fmt, context, codec_id);
2217 gst_ff_vid_caps_new (context, codec, codec_id, encode, "video/x-raw",
2219 if (!caps_has_field (caps, "format"))
2220 gst_ffmpeg_video_set_pix_fmts (caps, codec ? codec->pix_fmts : NULL);
2225 /* Convert a GstCaps (audio/raw) to a FFMPEG SampleFmt
2226 * and other audio properties in a AVCodecContext.
2228 * For usefullness, see below
2232 gst_ffmpeg_caps_to_smpfmt (const GstCaps * caps,
2233 AVCodecContext * context, gboolean raw)
2235 GstStructure *structure;
2237 GstAudioFormat format = GST_AUDIO_FORMAT_UNKNOWN;
2239 g_return_if_fail (gst_caps_get_size (caps) == 1);
2241 structure = gst_caps_get_structure (caps, 0);
2243 gst_structure_get_int (structure, "channels", &context->channels);
2244 gst_structure_get_int (structure, "rate", &context->sample_rate);
2245 gst_structure_get_int (structure, "block_align", &context->block_align);
2246 gst_structure_get_int (structure, "bitrate", &context->bit_rate);
2251 if (gst_structure_has_name (structure, "audio/x-raw")) {
2252 if ((fmt = gst_structure_get_string (structure, "format"))) {
2253 format = gst_audio_format_from_string (fmt);
2258 case GST_AUDIO_FORMAT_F32:
2259 context->sample_fmt = AV_SAMPLE_FMT_FLT;
2261 case GST_AUDIO_FORMAT_F64:
2262 context->sample_fmt = AV_SAMPLE_FMT_DBL;
2264 case GST_AUDIO_FORMAT_S32:
2265 context->sample_fmt = AV_SAMPLE_FMT_S32;
2267 case GST_AUDIO_FORMAT_S16:
2268 context->sample_fmt = AV_SAMPLE_FMT_S16;
2275 /* Convert a GstCaps (video/raw) to a FFMPEG PixFmt
2276 * and other video properties in a AVCodecContext.
2278 * For usefullness, see below
2282 gst_ffmpeg_caps_to_pixfmt (const GstCaps * caps,
2283 AVCodecContext * context, gboolean raw)
2285 GstStructure *structure;
2287 const GValue *par = NULL;
2289 GstVideoFormat format = GST_VIDEO_FORMAT_UNKNOWN;
2291 GST_DEBUG ("converting caps %" GST_PTR_FORMAT, caps);
2292 g_return_if_fail (gst_caps_get_size (caps) == 1);
2293 structure = gst_caps_get_structure (caps, 0);
2295 gst_structure_get_int (structure, "width", &context->width);
2296 gst_structure_get_int (structure, "height", &context->height);
2297 gst_structure_get_int (structure, "bpp", &context->bits_per_coded_sample);
2299 fps = gst_structure_get_value (structure, "framerate");
2300 if (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps)) {
2302 /* somehow these seem mixed up.. */
2303 context->time_base.den = gst_value_get_fraction_numerator (fps);
2304 context->time_base.num = gst_value_get_fraction_denominator (fps);
2305 context->ticks_per_frame = 1;
2307 GST_DEBUG ("setting framerate %d/%d = %lf",
2308 context->time_base.den, context->time_base.num,
2309 1. * context->time_base.den / context->time_base.num);
2312 par = gst_structure_get_value (structure, "pixel-aspect-ratio");
2313 if (par && GST_VALUE_HOLDS_FRACTION (par)) {
2315 context->sample_aspect_ratio.num = gst_value_get_fraction_numerator (par);
2316 context->sample_aspect_ratio.den = gst_value_get_fraction_denominator (par);
2318 GST_DEBUG ("setting pixel-aspect-ratio %d/%d = %lf",
2319 context->sample_aspect_ratio.den, context->sample_aspect_ratio.num,
2320 1. * context->sample_aspect_ratio.den /
2321 context->sample_aspect_ratio.num);
2327 g_return_if_fail (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps));
2329 if (gst_structure_has_name (structure, "video/x-raw")) {
2330 if ((fmt = gst_structure_get_string (structure, "format"))) {
2331 format = gst_video_format_from_string (fmt);
2336 case GST_VIDEO_FORMAT_YUY2:
2337 context->pix_fmt = PIX_FMT_YUYV422;
2339 case GST_VIDEO_FORMAT_I420:
2340 context->pix_fmt = PIX_FMT_YUV420P;
2342 case GST_VIDEO_FORMAT_A420:
2343 context->pix_fmt = PIX_FMT_YUVA420P;
2345 case GST_VIDEO_FORMAT_Y41B:
2346 context->pix_fmt = PIX_FMT_YUV411P;
2348 case GST_VIDEO_FORMAT_Y42B:
2349 context->pix_fmt = PIX_FMT_YUV422P;
2351 case GST_VIDEO_FORMAT_YUV9:
2352 context->pix_fmt = PIX_FMT_YUV410P;
2354 case GST_VIDEO_FORMAT_Y444:
2355 context->pix_fmt = PIX_FMT_YUV444P;
2357 case GST_VIDEO_FORMAT_GRAY8:
2358 context->pix_fmt = PIX_FMT_GRAY8;
2360 case GST_VIDEO_FORMAT_xRGB:
2361 #if (G_BYTE_ORDER == G_BIG_ENDIAN)
2362 context->pix_fmt = PIX_FMT_RGB32;
2365 case GST_VIDEO_FORMAT_BGRx:
2366 #if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
2367 context->pix_fmt = PIX_FMT_RGB32;
2370 case GST_VIDEO_FORMAT_RGB:
2371 context->pix_fmt = PIX_FMT_RGB24;
2373 case GST_VIDEO_FORMAT_BGR:
2374 context->pix_fmt = PIX_FMT_BGR24;
2376 case GST_VIDEO_FORMAT_RGB16:
2377 context->pix_fmt = PIX_FMT_RGB565;
2379 case GST_VIDEO_FORMAT_RGB15:
2380 context->pix_fmt = PIX_FMT_RGB555;
2382 case GST_VIDEO_FORMAT_RGB8P:
2383 context->pix_fmt = PIX_FMT_PAL8;
2392 GstVideoFormat format;
2393 enum PixelFormat pixfmt;
2396 /* FIXME : FILLME */
2397 static const PixToFmt pixtofmttable[] = {
2398 /* GST_VIDEO_FORMAT_I420, */
2399 {GST_VIDEO_FORMAT_I420, PIX_FMT_YUV420P},
2400 /* Note : this should use a different chroma placement */
2401 {GST_VIDEO_FORMAT_I420, PIX_FMT_YUVJ420P},
2403 /* GST_VIDEO_FORMAT_YV12, */
2404 /* GST_VIDEO_FORMAT_YUY2, */
2405 {GST_VIDEO_FORMAT_YUY2, PIX_FMT_YUYV422},
2406 /* GST_VIDEO_FORMAT_UYVY, */
2407 {GST_VIDEO_FORMAT_UYVY, PIX_FMT_UYVY422},
2408 /* GST_VIDEO_FORMAT_AYUV, */
2409 /* GST_VIDEO_FORMAT_RGBx, */
2410 /* GST_VIDEO_FORMAT_BGRx, */
2411 /* GST_VIDEO_FORMAT_xRGB, */
2412 /* GST_VIDEO_FORMAT_xBGR, */
2413 /* GST_VIDEO_FORMAT_RGBA, */
2414 {GST_VIDEO_FORMAT_RGBA, PIX_FMT_RGBA},
2415 /* GST_VIDEO_FORMAT_BGRA, */
2416 {GST_VIDEO_FORMAT_BGRA, PIX_FMT_BGRA},
2417 /* GST_VIDEO_FORMAT_ARGB, */
2418 {GST_VIDEO_FORMAT_ARGB, PIX_FMT_ARGB},
2419 /* GST_VIDEO_FORMAT_ABGR, */
2420 {GST_VIDEO_FORMAT_ABGR, PIX_FMT_ABGR},
2421 /* GST_VIDEO_FORMAT_RGB, */
2422 {GST_VIDEO_FORMAT_RGB, PIX_FMT_RGB24},
2423 /* GST_VIDEO_FORMAT_BGR, */
2424 {GST_VIDEO_FORMAT_BGR, PIX_FMT_BGR24},
2425 /* GST_VIDEO_FORMAT_Y41B, */
2426 {GST_VIDEO_FORMAT_Y41B, PIX_FMT_YUV411P},
2427 /* GST_VIDEO_FORMAT_Y42B, */
2428 {GST_VIDEO_FORMAT_Y42B, PIX_FMT_YUV422P},
2429 {GST_VIDEO_FORMAT_Y42B, PIX_FMT_YUVJ422P},
2430 /* GST_VIDEO_FORMAT_YVYU, */
2431 /* GST_VIDEO_FORMAT_Y444, */
2432 {GST_VIDEO_FORMAT_Y444, PIX_FMT_YUV444P},
2433 {GST_VIDEO_FORMAT_Y444, PIX_FMT_YUVJ444P},
2434 /* GST_VIDEO_FORMAT_v210, */
2435 /* GST_VIDEO_FORMAT_v216, */
2436 /* GST_VIDEO_FORMAT_NV12, */
2437 {GST_VIDEO_FORMAT_NV12, PIX_FMT_NV12},
2438 /* GST_VIDEO_FORMAT_NV21, */
2439 {GST_VIDEO_FORMAT_NV21, PIX_FMT_NV21},
2440 /* GST_VIDEO_FORMAT_GRAY8, */
2441 {GST_VIDEO_FORMAT_GRAY8, PIX_FMT_GRAY8},
2442 /* GST_VIDEO_FORMAT_GRAY16_BE, */
2443 {GST_VIDEO_FORMAT_GRAY16_BE, PIX_FMT_GRAY16BE},
2444 /* GST_VIDEO_FORMAT_GRAY16_LE, */
2445 {GST_VIDEO_FORMAT_GRAY16_LE, PIX_FMT_GRAY16LE},
2446 /* GST_VIDEO_FORMAT_v308, */
2447 /* GST_VIDEO_FORMAT_Y800, */
2448 /* GST_VIDEO_FORMAT_Y16, */
2449 /* GST_VIDEO_FORMAT_RGB16, */
2450 {GST_VIDEO_FORMAT_RGB16, PIX_FMT_RGB565},
2451 /* GST_VIDEO_FORMAT_BGR16, */
2452 /* GST_VIDEO_FORMAT_RGB15, */
2453 {GST_VIDEO_FORMAT_RGB15, PIX_FMT_RGB555},
2454 /* GST_VIDEO_FORMAT_BGR15, */
2455 /* GST_VIDEO_FORMAT_UYVP, */
2456 /* GST_VIDEO_FORMAT_A420, */
2457 {GST_VIDEO_FORMAT_A420, PIX_FMT_YUVA420P},
2458 /* GST_VIDEO_FORMAT_RGB8_PALETTED, */
2459 {GST_VIDEO_FORMAT_RGB8P, PIX_FMT_PAL8},
2460 /* GST_VIDEO_FORMAT_YUV9, */
2461 {GST_VIDEO_FORMAT_YUV9, PIX_FMT_YUV410P},
2462 /* GST_VIDEO_FORMAT_YVU9, */
2463 /* GST_VIDEO_FORMAT_IYU1, */
2464 /* GST_VIDEO_FORMAT_ARGB64, */
2465 /* GST_VIDEO_FORMAT_AYUV64, */
2466 /* GST_VIDEO_FORMAT_r210, */
2467 {GST_VIDEO_FORMAT_I420_10LE, PIX_FMT_YUV420P10LE},
2468 {GST_VIDEO_FORMAT_I420_10BE, PIX_FMT_YUV420P10BE},
2469 {GST_VIDEO_FORMAT_I422_10LE, PIX_FMT_YUV422P10LE},
2470 {GST_VIDEO_FORMAT_I422_10BE, PIX_FMT_YUV422P10BE},
2471 {GST_VIDEO_FORMAT_Y444_10LE, PIX_FMT_YUV444P10LE},
2472 {GST_VIDEO_FORMAT_Y444_10BE, PIX_FMT_YUV444P10BE},
2473 {GST_VIDEO_FORMAT_GBR, PIX_FMT_GBRP},
2474 {GST_VIDEO_FORMAT_GBR_10LE, PIX_FMT_GBRP10LE},
2475 {GST_VIDEO_FORMAT_GBR_10BE, PIX_FMT_GBRP10BE},
2479 gst_ffmpeg_pixfmt_to_videoformat (enum PixelFormat pixfmt)
2483 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2484 if (pixtofmttable[i].pixfmt == pixfmt)
2485 return pixtofmttable[i].format;
2487 GST_DEBUG ("Unknown pixel format %d", pixfmt);
2488 return GST_VIDEO_FORMAT_UNKNOWN;
2492 gst_ffmpeg_videoformat_to_pixfmt (GstVideoFormat format)
2496 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2497 if (pixtofmttable[i].format == format)
2498 return pixtofmttable[i].pixfmt;
2499 return PIX_FMT_NONE;
2503 gst_ffmpeg_videoinfo_to_context (GstVideoInfo * info, AVCodecContext * context)
2507 context->width = GST_VIDEO_INFO_WIDTH (info);
2508 context->height = GST_VIDEO_INFO_HEIGHT (info);
2509 for (i = 0; i < GST_VIDEO_INFO_N_COMPONENTS (info); i++)
2510 bpp += GST_VIDEO_INFO_COMP_DEPTH (info, i);
2511 context->bits_per_coded_sample = bpp;
2513 context->ticks_per_frame = 1;
2514 context->time_base.den = GST_VIDEO_INFO_FPS_N (info);
2515 context->time_base.num = GST_VIDEO_INFO_FPS_D (info);
2517 context->sample_aspect_ratio.num = GST_VIDEO_INFO_PAR_N (info);
2518 context->sample_aspect_ratio.den = GST_VIDEO_INFO_PAR_D (info);
2521 gst_ffmpeg_videoformat_to_pixfmt (GST_VIDEO_INFO_FORMAT (info));
2525 gst_ffmpeg_audioinfo_to_context (GstAudioInfo * info, AVCodecContext * context)
2527 const AVCodec *codec;
2528 const enum AVSampleFormat *smpl_fmts;
2529 enum AVSampleFormat smpl_fmt = -1;
2531 context->channels = info->channels;
2532 context->sample_rate = info->rate;
2533 context->channel_layout =
2534 gst_ffmpeg_channel_positions_to_layout (info->position, info->channels);
2536 codec = context->codec;
2538 smpl_fmts = codec->sample_fmts;
2540 switch (info->finfo->format) {
2541 case GST_AUDIO_FORMAT_F32:
2543 while (*smpl_fmts != -1) {
2544 if (*smpl_fmts == AV_SAMPLE_FMT_FLT) {
2545 smpl_fmt = *smpl_fmts;
2547 } else if (*smpl_fmts == AV_SAMPLE_FMT_FLTP) {
2548 smpl_fmt = *smpl_fmts;
2554 smpl_fmt = AV_SAMPLE_FMT_FLT;
2557 case GST_AUDIO_FORMAT_F64:
2559 while (*smpl_fmts != -1) {
2560 if (*smpl_fmts == AV_SAMPLE_FMT_DBL) {
2561 smpl_fmt = *smpl_fmts;
2563 } else if (*smpl_fmts == AV_SAMPLE_FMT_DBLP) {
2564 smpl_fmt = *smpl_fmts;
2570 smpl_fmt = AV_SAMPLE_FMT_DBL;
2573 case GST_AUDIO_FORMAT_S32:
2575 while (*smpl_fmts != -1) {
2576 if (*smpl_fmts == AV_SAMPLE_FMT_S32) {
2577 smpl_fmt = *smpl_fmts;
2579 } else if (*smpl_fmts == AV_SAMPLE_FMT_S32P) {
2580 smpl_fmt = *smpl_fmts;
2586 smpl_fmt = AV_SAMPLE_FMT_S32;
2589 case GST_AUDIO_FORMAT_S16:
2591 while (*smpl_fmts != -1) {
2592 if (*smpl_fmts == AV_SAMPLE_FMT_S16) {
2593 smpl_fmt = *smpl_fmts;
2595 } else if (*smpl_fmts == AV_SAMPLE_FMT_S16P) {
2596 smpl_fmt = *smpl_fmts;
2602 smpl_fmt = AV_SAMPLE_FMT_S16;
2605 case GST_AUDIO_FORMAT_U8:
2607 while (*smpl_fmts != -1) {
2608 if (*smpl_fmts == AV_SAMPLE_FMT_U8) {
2609 smpl_fmt = *smpl_fmts;
2611 } else if (*smpl_fmts == AV_SAMPLE_FMT_U8P) {
2612 smpl_fmt = *smpl_fmts;
2618 smpl_fmt = AV_SAMPLE_FMT_U8;
2625 g_assert (smpl_fmt != -1);
2627 context->sample_fmt = smpl_fmt;
2630 /* Convert a GstCaps and a FFMPEG codec Type to a
2631 * AVCodecContext. If the context is ommitted, no fixed values
2632 * for video/audio size will be included in the context
2634 * AVMediaType is primarily meant for uncompressed data GstCaps!
2638 gst_ffmpeg_caps_with_codectype (enum AVMediaType type,
2639 const GstCaps * caps, AVCodecContext * context)
2641 if (context == NULL)
2645 case AVMEDIA_TYPE_VIDEO:
2646 gst_ffmpeg_caps_to_pixfmt (caps, context, TRUE);
2649 case AVMEDIA_TYPE_AUDIO:
2650 gst_ffmpeg_caps_to_smpfmt (caps, context, TRUE);
2661 nal_escape (guint8 * dst, guint8 * src, guint size, guint * destsize)
2665 guint8 *end = src + size;
2668 while (srcp < end) {
2669 if (count == 2 && *srcp <= 0x03) {
2670 GST_DEBUG ("added escape code");
2679 GST_DEBUG ("copy %02x, count %d", *srcp, count);
2682 *destsize = dstp - dst;
2685 /* copy the config, escaping NAL units as we iterate them, if something fails we
2686 * copy everything and hope for the best. */
2688 copy_config (guint8 * dst, guint8 * src, guint size, guint * destsize)
2693 guint nalsize, esize;
2703 cnt = *(srcp + 5) & 0x1f; /* Number of sps */
2705 GST_DEBUG ("num SPS %d", cnt);
2707 memcpy (dstp, srcp, 6);
2711 for (i = 0; i < cnt; i++) {
2712 GST_DEBUG ("copy SPS %d", i);
2713 nalsize = (srcp[0] << 8) | srcp[1];
2714 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2715 dstp[0] = esize >> 8;
2716 dstp[1] = esize & 0xff;
2718 srcp += nalsize + 2;
2721 cnt = *(dstp++) = *(srcp++); /* Number of pps */
2723 GST_DEBUG ("num PPS %d", cnt);
2725 for (i = 0; i < cnt; i++) {
2726 GST_DEBUG ("copy PPS %d", i);
2727 nalsize = (srcp[0] << 8) | srcp[1];
2728 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2729 dstp[0] = esize >> 8;
2730 dstp[1] = esize & 0xff;
2732 srcp += nalsize + 2;
2734 *destsize = dstp - dst;
2740 GST_DEBUG ("something unexpected, doing full copy");
2741 memcpy (dst, src, size);
2749 * caps_with_codecid () transforms a GstCaps for a known codec
2750 * ID into a filled-in context.
2751 * codec_data from caps will override possible extradata already in the context
2755 gst_ffmpeg_caps_with_codecid (enum CodecID codec_id,
2756 enum AVMediaType codec_type, const GstCaps * caps, AVCodecContext * context)
2759 const GValue *value;
2762 GST_LOG ("codec_id:%d, codec_type:%d, caps:%" GST_PTR_FORMAT " context:%p",
2763 codec_id, codec_type, caps, context);
2765 if (!context || !gst_caps_get_size (caps))
2768 str = gst_caps_get_structure (caps, 0);
2770 /* extradata parsing (esds [mpeg4], wma/wmv, msmpeg4v1/2/3, etc.) */
2771 if ((value = gst_structure_get_value (str, "codec_data"))) {
2774 buf = gst_value_get_buffer (value);
2775 gst_buffer_map (buf, &map, GST_MAP_READ);
2777 /* free the old one if it is there */
2778 if (context->extradata)
2779 av_free (context->extradata);
2782 if (codec_id == AV_CODEC_ID_H264) {
2785 GST_DEBUG ("copy, escaping codec_data %d", size);
2786 /* ffmpeg h264 expects the codec_data to be escaped, there is no real
2787 * reason for this but let's just escape it for now. Start by allocating
2788 * enough space, x2 is more than enough.
2790 * FIXME, we disabled escaping because some file already contain escaped
2791 * codec_data and then we escape twice and fail. It's better to leave it
2792 * as is, as that is what most players do. */
2793 context->extradata =
2794 av_mallocz (GST_ROUND_UP_16 (size * 2 +
2795 FF_INPUT_BUFFER_PADDING_SIZE));
2796 copy_config (context->extradata, data, size, &extrasize);
2797 GST_DEBUG ("escaped size: %d", extrasize);
2798 context->extradata_size = extrasize;
2802 /* allocate with enough padding */
2803 GST_DEBUG ("copy codec_data");
2804 context->extradata =
2805 av_mallocz (GST_ROUND_UP_16 (map.size +
2806 FF_INPUT_BUFFER_PADDING_SIZE));
2807 memcpy (context->extradata, map.data, map.size);
2808 context->extradata_size = map.size;
2811 /* Hack for VC1. Sometimes the first (length) byte is 0 for some files */
2812 if (codec_id == AV_CODEC_ID_VC1 && map.size > 0 && map.data[0] == 0) {
2813 context->extradata[0] = (guint8) map.size;
2816 GST_DEBUG ("have codec data of size %" G_GSIZE_FORMAT, map.size);
2818 gst_buffer_unmap (buf, &map);
2819 } else if (context->extradata == NULL && codec_id != AV_CODEC_ID_AAC_LATM &&
2820 codec_id != AV_CODEC_ID_FLAC) {
2821 /* no extradata, alloc dummy with 0 sized, some codecs insist on reading
2822 * extradata anyway which makes then segfault. */
2823 context->extradata =
2824 av_mallocz (GST_ROUND_UP_16 (FF_INPUT_BUFFER_PADDING_SIZE));
2825 context->extradata_size = 0;
2826 GST_DEBUG ("no codec data");
2830 case AV_CODEC_ID_MPEG4:
2832 const gchar *mime = gst_structure_get_name (str);
2834 if (!strcmp (mime, "video/x-divx"))
2835 context->codec_tag = GST_MAKE_FOURCC ('D', 'I', 'V', 'X');
2836 else if (!strcmp (mime, "video/x-xvid"))
2837 context->codec_tag = GST_MAKE_FOURCC ('X', 'V', 'I', 'D');
2838 else if (!strcmp (mime, "video/x-3ivx"))
2839 context->codec_tag = GST_MAKE_FOURCC ('3', 'I', 'V', '1');
2840 else if (!strcmp (mime, "video/mpeg"))
2841 context->codec_tag = GST_MAKE_FOURCC ('m', 'p', '4', 'v');
2845 case AV_CODEC_ID_SVQ3:
2846 /* FIXME: this is a workaround for older gst-plugins releases
2847 * (<= 0.8.9). This should be removed at some point, because
2848 * it causes wrong decoded frame order. */
2849 if (!context->extradata) {
2850 gint halfpel_flag, thirdpel_flag, low_delay, unknown_svq3_flag;
2853 if (gst_structure_get_int (str, "halfpel_flag", &halfpel_flag) ||
2854 gst_structure_get_int (str, "thirdpel_flag", &thirdpel_flag) ||
2855 gst_structure_get_int (str, "low_delay", &low_delay) ||
2856 gst_structure_get_int (str, "unknown_svq3_flag",
2857 &unknown_svq3_flag)) {
2858 context->extradata = (guint8 *) av_mallocz (0x64);
2859 g_stpcpy ((gchar *) context->extradata, "SVQ3");
2863 flags |= unknown_svq3_flag;
2865 flags |= halfpel_flag;
2867 flags |= thirdpel_flag;
2870 flags = GUINT16_FROM_LE (flags);
2872 memcpy ((gchar *) context->extradata + 0x62, &flags, 2);
2873 context->extradata_size = 0x64;
2878 case AV_CODEC_ID_MSRLE:
2879 case AV_CODEC_ID_QTRLE:
2880 case AV_CODEC_ID_TSCC:
2881 case AV_CODEC_ID_CSCD:
2882 case AV_CODEC_ID_APE:
2886 if (gst_structure_get_int (str, "depth", &depth)) {
2887 context->bits_per_coded_sample = depth;
2889 GST_WARNING ("No depth field in caps %" GST_PTR_FORMAT, caps);
2895 case AV_CODEC_ID_RV10:
2896 case AV_CODEC_ID_RV20:
2897 case AV_CODEC_ID_RV30:
2898 case AV_CODEC_ID_RV40:
2902 if (gst_structure_get_int (str, "format", &format))
2903 context->sub_id = format;
2907 case AV_CODEC_ID_COOK:
2908 case AV_CODEC_ID_RA_288:
2909 case AV_CODEC_ID_RA_144:
2910 case AV_CODEC_ID_SIPR:
2915 if (gst_structure_get_int (str, "leaf_size", &leaf_size))
2916 context->block_align = leaf_size;
2917 if (gst_structure_get_int (str, "bitrate", &bitrate))
2918 context->bit_rate = bitrate;
2920 case AV_CODEC_ID_ALAC:
2921 gst_structure_get_int (str, "samplesize",
2922 &context->bits_per_coded_sample);
2925 case AV_CODEC_ID_DVVIDEO:
2927 const gchar *format;
2929 if ((format = gst_structure_get_string (str, "format"))) {
2931 if (g_str_equal (format, "YUY2"))
2932 context->pix_fmt = PIX_FMT_YUYV422;
2933 else if (g_str_equal (format, "I420"))
2934 context->pix_fmt = PIX_FMT_YUV420P;
2935 else if (g_str_equal (format, "A420"))
2936 context->pix_fmt = PIX_FMT_YUVA420P;
2937 else if (g_str_equal (format, "Y41B"))
2938 context->pix_fmt = PIX_FMT_YUV411P;
2939 else if (g_str_equal (format, "Y42B"))
2940 context->pix_fmt = PIX_FMT_YUV422P;
2941 else if (g_str_equal (format, "YUV9"))
2942 context->pix_fmt = PIX_FMT_YUV410P;
2944 GST_WARNING ("couldn't convert format %s" " to a pixel format",
2948 GST_WARNING ("No specified format");
2951 case AV_CODEC_ID_H263P:
2955 if (!gst_structure_get_boolean (str, "annex-f", &val) || val)
2956 context->flags |= CODEC_FLAG_4MV;
2958 context->flags &= ~CODEC_FLAG_4MV;
2959 if ((!gst_structure_get_boolean (str, "annex-i", &val) || val) &&
2960 (!gst_structure_get_boolean (str, "annex-t", &val) || val))
2961 context->flags |= CODEC_FLAG_AC_PRED;
2963 context->flags &= ~CODEC_FLAG_AC_PRED;
2964 if (!gst_structure_get_boolean (str, "annex-j", &val) || val)
2965 context->flags |= CODEC_FLAG_LOOP_FILTER;
2967 context->flags &= ~CODEC_FLAG_LOOP_FILTER;
2970 case AV_CODEC_ID_ADPCM_G726:
2972 const gchar *layout;
2974 if ((layout = gst_structure_get_string (str, "layout"))) {
2975 if (!strcmp (layout, "g721")) {
2976 context->sample_rate = 8000;
2977 context->channels = 1;
2978 context->bit_rate = 32000;
2987 if (!gst_caps_is_fixed (caps))
2990 /* common properties (width, height, fps) */
2991 switch (codec_type) {
2992 case AVMEDIA_TYPE_VIDEO:
2993 gst_ffmpeg_caps_to_pixfmt (caps, context,
2994 codec_id == AV_CODEC_ID_RAWVIDEO);
2996 case AVMEDIA_TYPE_AUDIO:
2997 gst_ffmpeg_caps_to_smpfmt (caps, context, FALSE);
3003 /* fixup of default settings */
3005 case AV_CODEC_ID_QCELP:
3006 /* QCELP is always mono, no matter what the caps say */
3007 context->channels = 1;
3009 case AV_CODEC_ID_ADPCM_G726:
3010 if (context->sample_rate && context->bit_rate)
3011 context->bits_per_coded_sample =
3012 context->bit_rate / context->sample_rate;
3019 /* _formatid_to_caps () is meant for muxers/demuxers, it
3020 * transforms a name (ffmpeg way of ID'ing these, why don't
3021 * they have unique numerical IDs?) to the corresponding
3022 * caps belonging to that mux-format
3024 * Note: we don't need any additional info because the caps
3025 * isn't supposed to contain any useful info besides the
3030 gst_ffmpeg_formatid_to_caps (const gchar * format_name)
3032 GstCaps *caps = NULL;
3034 if (!strcmp (format_name, "mpeg")) {
3035 caps = gst_caps_new_simple ("video/mpeg",
3036 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3037 } else if (!strcmp (format_name, "mpegts")) {
3038 caps = gst_caps_new_simple ("video/mpegts",
3039 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3040 } else if (!strcmp (format_name, "rm")) {
3041 caps = gst_caps_new_simple ("application/x-pn-realmedia",
3042 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3043 } else if (!strcmp (format_name, "asf")) {
3044 caps = gst_caps_new_empty_simple ("video/x-ms-asf");
3045 } else if (!strcmp (format_name, "avi")) {
3046 caps = gst_caps_new_empty_simple ("video/x-msvideo");
3047 } else if (!strcmp (format_name, "wav")) {
3048 caps = gst_caps_new_empty_simple ("audio/x-wav");
3049 } else if (!strcmp (format_name, "ape")) {
3050 caps = gst_caps_new_empty_simple ("application/x-ape");
3051 } else if (!strcmp (format_name, "swf")) {
3052 caps = gst_caps_new_empty_simple ("application/x-shockwave-flash");
3053 } else if (!strcmp (format_name, "au")) {
3054 caps = gst_caps_new_empty_simple ("audio/x-au");
3055 } else if (!strcmp (format_name, "dv")) {
3056 caps = gst_caps_new_simple ("video/x-dv",
3057 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3058 } else if (!strcmp (format_name, "4xm")) {
3059 caps = gst_caps_new_empty_simple ("video/x-4xm");
3060 } else if (!strcmp (format_name, "matroska")) {
3061 caps = gst_caps_new_empty_simple ("video/x-matroska");
3062 } else if (!strcmp (format_name, "mp3")) {
3063 caps = gst_caps_new_empty_simple ("application/x-id3");
3064 } else if (!strcmp (format_name, "flic")) {
3065 caps = gst_caps_new_empty_simple ("video/x-fli");
3066 } else if (!strcmp (format_name, "flv")) {
3067 caps = gst_caps_new_empty_simple ("video/x-flv");
3068 } else if (!strcmp (format_name, "tta")) {
3069 caps = gst_caps_new_empty_simple ("audio/x-ttafile");
3070 } else if (!strcmp (format_name, "aiff")) {
3071 caps = gst_caps_new_empty_simple ("audio/x-aiff");
3072 } else if (!strcmp (format_name, "mov_mp4_m4a_3gp_3g2")) {
3074 gst_caps_from_string
3075 ("application/x-3gp; video/quicktime; audio/x-m4a");
3076 } else if (!strcmp (format_name, "mov")) {
3077 caps = gst_caps_from_string ("video/quicktime,variant=(string)apple");
3078 } else if (!strcmp (format_name, "mp4")) {
3079 caps = gst_caps_from_string ("video/quicktime,variant=(string)iso");
3080 } else if (!strcmp (format_name, "3gp")) {
3081 caps = gst_caps_from_string ("video/quicktime,variant=(string)3gpp");
3082 } else if (!strcmp (format_name, "3g2")) {
3083 caps = gst_caps_from_string ("video/quicktime,variant=(string)3g2");
3084 } else if (!strcmp (format_name, "psp")) {
3085 caps = gst_caps_from_string ("video/quicktime,variant=(string)psp");
3086 } else if (!strcmp (format_name, "ipod")) {
3087 caps = gst_caps_from_string ("video/quicktime,variant=(string)ipod");
3088 } else if (!strcmp (format_name, "aac")) {
3089 caps = gst_caps_new_simple ("audio/mpeg",
3090 "mpegversion", G_TYPE_INT, 4, NULL);
3091 } else if (!strcmp (format_name, "gif")) {
3092 caps = gst_caps_from_string ("image/gif");
3093 } else if (!strcmp (format_name, "ogg")) {
3094 caps = gst_caps_from_string ("application/ogg");
3095 } else if (!strcmp (format_name, "mxf") || !strcmp (format_name, "mxf_d10")) {
3096 caps = gst_caps_from_string ("application/mxf");
3097 } else if (!strcmp (format_name, "gxf")) {
3098 caps = gst_caps_from_string ("application/gxf");
3099 } else if (!strcmp (format_name, "yuv4mpegpipe")) {
3100 caps = gst_caps_new_simple ("application/x-yuv4mpeg",
3101 "y4mversion", G_TYPE_INT, 2, NULL);
3102 } else if (!strcmp (format_name, "mpc")) {
3103 caps = gst_caps_from_string ("audio/x-musepack, streamversion = (int) 7");
3104 } else if (!strcmp (format_name, "vqf")) {
3105 caps = gst_caps_from_string ("audio/x-vqf");
3106 } else if (!strcmp (format_name, "nsv")) {
3107 caps = gst_caps_from_string ("video/x-nsv");
3108 } else if (!strcmp (format_name, "amr")) {
3109 caps = gst_caps_from_string ("audio/x-amr-nb-sh");
3110 } else if (!strcmp (format_name, "webm")) {
3111 caps = gst_caps_from_string ("video/webm");
3112 } else if (!strcmp (format_name, "voc")) {
3113 caps = gst_caps_from_string ("audio/x-voc");
3114 } else if (!strcmp (format_name, "pva")) {
3115 caps = gst_caps_from_string ("video/x-pva");
3119 GST_LOG ("Could not create stream format caps for %s", format_name);
3120 name = g_strdup_printf ("application/x-gst-av-%s", format_name);
3121 caps = gst_caps_new_empty_simple (name);
3129 gst_ffmpeg_formatid_get_codecids (const gchar * format_name,
3130 enum CodecID ** video_codec_list, enum CodecID ** audio_codec_list,
3131 AVOutputFormat * plugin)
3133 static enum CodecID tmp_vlist[] = {
3137 static enum CodecID tmp_alist[] = {
3142 GST_LOG ("format_name : %s", format_name);
3144 if (!strcmp (format_name, "mp4")) {
3145 static enum CodecID mp4_video_list[] = {
3146 AV_CODEC_ID_MPEG4, AV_CODEC_ID_H264,
3150 static enum CodecID mp4_audio_list[] = {
3151 AV_CODEC_ID_AAC, AV_CODEC_ID_MP3,
3155 *video_codec_list = mp4_video_list;
3156 *audio_codec_list = mp4_audio_list;
3157 } else if (!strcmp (format_name, "mpeg")) {
3158 static enum CodecID mpeg_video_list[] = { AV_CODEC_ID_MPEG1VIDEO,
3159 AV_CODEC_ID_MPEG2VIDEO,
3163 static enum CodecID mpeg_audio_list[] = { AV_CODEC_ID_MP1,
3169 *video_codec_list = mpeg_video_list;
3170 *audio_codec_list = mpeg_audio_list;
3171 } else if (!strcmp (format_name, "dvd")) {
3172 static enum CodecID mpeg_video_list[] = { AV_CODEC_ID_MPEG2VIDEO,
3175 static enum CodecID mpeg_audio_list[] = { AV_CODEC_ID_MP2,
3178 AV_CODEC_ID_PCM_S16BE,
3182 *video_codec_list = mpeg_video_list;
3183 *audio_codec_list = mpeg_audio_list;
3184 } else if (!strcmp (format_name, "mpegts")) {
3185 static enum CodecID mpegts_video_list[] = { AV_CODEC_ID_MPEG1VIDEO,
3186 AV_CODEC_ID_MPEG2VIDEO,
3190 static enum CodecID mpegts_audio_list[] = { AV_CODEC_ID_MP2,
3198 *video_codec_list = mpegts_video_list;
3199 *audio_codec_list = mpegts_audio_list;
3200 } else if (!strcmp (format_name, "vob")) {
3201 static enum CodecID vob_video_list[] =
3202 { AV_CODEC_ID_MPEG2VIDEO, AV_CODEC_ID_NONE };
3203 static enum CodecID vob_audio_list[] = { AV_CODEC_ID_MP2, AV_CODEC_ID_AC3,
3204 AV_CODEC_ID_DTS, AV_CODEC_ID_NONE
3207 *video_codec_list = vob_video_list;
3208 *audio_codec_list = vob_audio_list;
3209 } else if (!strcmp (format_name, "flv")) {
3210 static enum CodecID flv_video_list[] =
3211 { AV_CODEC_ID_FLV1, AV_CODEC_ID_NONE };
3212 static enum CodecID flv_audio_list[] =
3213 { AV_CODEC_ID_MP3, AV_CODEC_ID_NONE };
3215 *video_codec_list = flv_video_list;
3216 *audio_codec_list = flv_audio_list;
3217 } else if (!strcmp (format_name, "asf")) {
3218 static enum CodecID asf_video_list[] =
3219 { AV_CODEC_ID_WMV1, AV_CODEC_ID_WMV2, AV_CODEC_ID_MSMPEG4V3,
3222 static enum CodecID asf_audio_list[] =
3223 { AV_CODEC_ID_WMAV1, AV_CODEC_ID_WMAV2, AV_CODEC_ID_MP3,
3227 *video_codec_list = asf_video_list;
3228 *audio_codec_list = asf_audio_list;
3229 } else if (!strcmp (format_name, "dv")) {
3230 static enum CodecID dv_video_list[] =
3231 { AV_CODEC_ID_DVVIDEO, AV_CODEC_ID_NONE };
3232 static enum CodecID dv_audio_list[] =
3233 { AV_CODEC_ID_PCM_S16LE, AV_CODEC_ID_NONE };
3235 *video_codec_list = dv_video_list;
3236 *audio_codec_list = dv_audio_list;
3237 } else if (!strcmp (format_name, "mov")) {
3238 static enum CodecID mov_video_list[] = {
3239 AV_CODEC_ID_SVQ1, AV_CODEC_ID_SVQ3, AV_CODEC_ID_MPEG4,
3240 AV_CODEC_ID_H263, AV_CODEC_ID_H263P,
3241 AV_CODEC_ID_H264, AV_CODEC_ID_DVVIDEO,
3245 static enum CodecID mov_audio_list[] = {
3246 AV_CODEC_ID_PCM_MULAW, AV_CODEC_ID_PCM_ALAW, AV_CODEC_ID_ADPCM_IMA_QT,
3247 AV_CODEC_ID_MACE3, AV_CODEC_ID_MACE6, AV_CODEC_ID_AAC,
3248 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3249 AV_CODEC_ID_PCM_S16BE, AV_CODEC_ID_PCM_S16LE,
3250 AV_CODEC_ID_MP3, AV_CODEC_ID_NONE
3253 *video_codec_list = mov_video_list;
3254 *audio_codec_list = mov_audio_list;
3255 } else if ((!strcmp (format_name, "3gp") || !strcmp (format_name, "3g2"))) {
3256 static enum CodecID tgp_video_list[] = {
3257 AV_CODEC_ID_MPEG4, AV_CODEC_ID_H263, AV_CODEC_ID_H263P, AV_CODEC_ID_H264,
3260 static enum CodecID tgp_audio_list[] = {
3261 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3266 *video_codec_list = tgp_video_list;
3267 *audio_codec_list = tgp_audio_list;
3268 } else if (!strcmp (format_name, "mmf")) {
3269 static enum CodecID mmf_audio_list[] = {
3270 AV_CODEC_ID_ADPCM_YAMAHA, AV_CODEC_ID_NONE
3272 *video_codec_list = NULL;
3273 *audio_codec_list = mmf_audio_list;
3274 } else if (!strcmp (format_name, "amr")) {
3275 static enum CodecID amr_audio_list[] = {
3276 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3279 *video_codec_list = NULL;
3280 *audio_codec_list = amr_audio_list;
3281 } else if (!strcmp (format_name, "gif")) {
3282 static enum CodecID gif_image_list[] = {
3283 AV_CODEC_ID_RAWVIDEO, AV_CODEC_ID_NONE
3285 *video_codec_list = gif_image_list;
3286 *audio_codec_list = NULL;
3287 } else if ((plugin->audio_codec != AV_CODEC_ID_NONE) ||
3288 (plugin->video_codec != AV_CODEC_ID_NONE)) {
3289 tmp_vlist[0] = plugin->video_codec;
3290 tmp_alist[0] = plugin->audio_codec;
3292 *video_codec_list = tmp_vlist;
3293 *audio_codec_list = tmp_alist;
3294 } else if ((!strcmp (format_name, "pva"))) {
3295 static enum CodecID tgp_video_list[] = {
3296 AV_CODEC_ID_MPEG2VIDEO,
3299 static enum CodecID tgp_audio_list[] = {
3304 *video_codec_list = tgp_video_list;
3305 *audio_codec_list = tgp_audio_list;
3307 GST_LOG ("Format %s not found", format_name);
3314 /* Convert a GstCaps to a FFMPEG codec ID. Size et all
3315 * are omitted, that can be queried by the user itself,
3316 * we're not eating the GstCaps or anything
3317 * A pointer to an allocated context is also needed for
3318 * optional extra info
3322 gst_ffmpeg_caps_to_codecid (const GstCaps * caps, AVCodecContext * context)
3324 enum CodecID id = AV_CODEC_ID_NONE;
3325 const gchar *mimetype;
3326 const GstStructure *structure;
3327 gboolean video = FALSE, audio = FALSE; /* we want to be sure! */
3329 g_return_val_if_fail (caps != NULL, AV_CODEC_ID_NONE);
3330 g_return_val_if_fail (gst_caps_get_size (caps) == 1, AV_CODEC_ID_NONE);
3331 structure = gst_caps_get_structure (caps, 0);
3333 mimetype = gst_structure_get_name (structure);
3335 if (!strcmp (mimetype, "video/x-raw")) {
3336 id = AV_CODEC_ID_RAWVIDEO;
3338 } else if (!strcmp (mimetype, "audio/x-raw")) {
3341 if (gst_audio_info_from_caps (&info, caps)) {
3342 switch (GST_AUDIO_INFO_FORMAT (&info)) {
3343 case GST_AUDIO_FORMAT_S8:
3344 id = AV_CODEC_ID_PCM_S8;
3346 case GST_AUDIO_FORMAT_U8:
3347 id = AV_CODEC_ID_PCM_U8;
3349 case GST_AUDIO_FORMAT_S16LE:
3350 id = AV_CODEC_ID_PCM_S16LE;
3352 case GST_AUDIO_FORMAT_S16BE:
3353 id = AV_CODEC_ID_PCM_S16BE;
3355 case GST_AUDIO_FORMAT_U16LE:
3356 id = AV_CODEC_ID_PCM_U16LE;
3358 case GST_AUDIO_FORMAT_U16BE:
3359 id = AV_CODEC_ID_PCM_U16BE;
3364 if (id != AV_CODEC_ID_NONE)
3367 } else if (!strcmp (mimetype, "audio/x-mulaw")) {
3368 id = AV_CODEC_ID_PCM_MULAW;
3370 } else if (!strcmp (mimetype, "audio/x-alaw")) {
3371 id = AV_CODEC_ID_PCM_ALAW;
3373 } else if (!strcmp (mimetype, "video/x-dv")) {
3376 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3378 id = AV_CODEC_ID_DVVIDEO;
3381 } else if (!strcmp (mimetype, "audio/x-dv")) { /* ??? */
3382 id = AV_CODEC_ID_DVAUDIO;
3384 } else if (!strcmp (mimetype, "video/x-h263")) {
3385 const gchar *h263version =
3386 gst_structure_get_string (structure, "h263version");
3387 if (h263version && !strcmp (h263version, "h263p"))
3388 id = AV_CODEC_ID_H263P;
3390 id = AV_CODEC_ID_H263;
3392 } else if (!strcmp (mimetype, "video/x-intel-h263")) {
3393 id = AV_CODEC_ID_H263I;
3395 } else if (!strcmp (mimetype, "video/x-h261")) {
3396 id = AV_CODEC_ID_H261;
3398 } else if (!strcmp (mimetype, "video/mpeg")) {
3402 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3403 gst_structure_get_int (structure, "mpegversion", &mpegversion) &&
3405 switch (mpegversion) {
3407 id = AV_CODEC_ID_MPEG1VIDEO;
3410 id = AV_CODEC_ID_MPEG2VIDEO;
3413 id = AV_CODEC_ID_MPEG4;
3417 if (id != AV_CODEC_ID_NONE)
3419 } else if (!strcmp (mimetype, "image/jpeg")) {
3420 id = AV_CODEC_ID_MJPEG; /* A... B... */
3422 } else if (!strcmp (mimetype, "video/x-jpeg-b")) {
3423 id = AV_CODEC_ID_MJPEGB;
3425 } else if (!strcmp (mimetype, "video/x-wmv")) {
3426 gint wmvversion = 0;
3428 if (gst_structure_get_int (structure, "wmvversion", &wmvversion)) {
3429 switch (wmvversion) {
3431 id = AV_CODEC_ID_WMV1;
3434 id = AV_CODEC_ID_WMV2;
3438 const gchar *format;
3440 /* WMV3 unless the fourcc exists and says otherwise */
3441 id = AV_CODEC_ID_WMV3;
3443 if ((format = gst_structure_get_string (structure, "format")) &&
3444 (g_str_equal (format, "WVC1") || g_str_equal (format, "WMVA")))
3445 id = AV_CODEC_ID_VC1;
3451 if (id != AV_CODEC_ID_NONE)
3453 } else if (!strcmp (mimetype, "audio/x-vorbis")) {
3454 id = AV_CODEC_ID_VORBIS;
3456 } else if (!strcmp (mimetype, "audio/x-qdm2")) {
3457 id = AV_CODEC_ID_QDM2;
3459 } else if (!strcmp (mimetype, "audio/mpeg")) {
3461 gint mpegversion = 0;
3463 if (gst_structure_get_int (structure, "mpegversion", &mpegversion)) {
3464 switch (mpegversion) {
3465 case 2: /* ffmpeg uses faad for both... */
3467 id = AV_CODEC_ID_AAC;
3470 if (gst_structure_get_int (structure, "layer", &layer)) {
3473 id = AV_CODEC_ID_MP1;
3476 id = AV_CODEC_ID_MP2;
3479 id = AV_CODEC_ID_MP3;
3485 if (id != AV_CODEC_ID_NONE)
3487 } else if (!strcmp (mimetype, "audio/x-musepack")) {
3488 gint streamversion = -1;
3490 if (gst_structure_get_int (structure, "streamversion", &streamversion)) {
3491 if (streamversion == 7)
3492 id = AV_CODEC_ID_MUSEPACK7;
3494 id = AV_CODEC_ID_MUSEPACK7;
3496 } else if (!strcmp (mimetype, "audio/x-wma")) {
3497 gint wmaversion = 0;
3499 if (gst_structure_get_int (structure, "wmaversion", &wmaversion)) {
3500 switch (wmaversion) {
3502 id = AV_CODEC_ID_WMAV1;
3505 id = AV_CODEC_ID_WMAV2;
3508 id = AV_CODEC_ID_WMAPRO;
3512 if (id != AV_CODEC_ID_NONE)
3514 } else if (!strcmp (mimetype, "audio/x-wms")) {
3515 id = AV_CODEC_ID_WMAVOICE;
3517 } else if (!strcmp (mimetype, "audio/x-ac3")) {
3518 id = AV_CODEC_ID_AC3;
3520 } else if (!strcmp (mimetype, "audio/x-eac3")) {
3521 id = AV_CODEC_ID_EAC3;
3523 } else if (!strcmp (mimetype, "audio/x-vnd.sony.atrac3") ||
3524 !strcmp (mimetype, "audio/atrac3")) {
3525 id = AV_CODEC_ID_ATRAC3;
3527 } else if (!strcmp (mimetype, "audio/x-dts")) {
3528 id = AV_CODEC_ID_DTS;
3530 } else if (!strcmp (mimetype, "application/x-ape")) {
3531 id = AV_CODEC_ID_APE;
3533 } else if (!strcmp (mimetype, "video/x-msmpeg")) {
3534 gint msmpegversion = 0;
3536 if (gst_structure_get_int (structure, "msmpegversion", &msmpegversion)) {
3537 switch (msmpegversion) {
3539 id = AV_CODEC_ID_MSMPEG4V1;
3542 id = AV_CODEC_ID_MSMPEG4V2;
3545 id = AV_CODEC_ID_MSMPEG4V3;
3549 if (id != AV_CODEC_ID_NONE)
3551 } else if (!strcmp (mimetype, "video/x-svq")) {
3552 gint svqversion = 0;
3554 if (gst_structure_get_int (structure, "svqversion", &svqversion)) {
3555 switch (svqversion) {
3557 id = AV_CODEC_ID_SVQ1;
3560 id = AV_CODEC_ID_SVQ3;
3564 if (id != AV_CODEC_ID_NONE)
3566 } else if (!strcmp (mimetype, "video/x-huffyuv")) {
3567 id = AV_CODEC_ID_HUFFYUV;
3569 } else if (!strcmp (mimetype, "audio/x-mace")) {
3570 gint maceversion = 0;
3572 if (gst_structure_get_int (structure, "maceversion", &maceversion)) {
3573 switch (maceversion) {
3575 id = AV_CODEC_ID_MACE3;
3578 id = AV_CODEC_ID_MACE6;
3582 if (id != AV_CODEC_ID_NONE)
3584 } else if (!strcmp (mimetype, "video/x-theora")) {
3585 id = AV_CODEC_ID_THEORA;
3587 } else if (!strcmp (mimetype, "video/x-vp3")) {
3588 id = AV_CODEC_ID_VP3;
3590 } else if (!strcmp (mimetype, "video/x-vp5")) {
3591 id = AV_CODEC_ID_VP5;
3593 } else if (!strcmp (mimetype, "video/x-vp6")) {
3594 id = AV_CODEC_ID_VP6;
3596 } else if (!strcmp (mimetype, "video/x-vp6-flash")) {
3597 id = AV_CODEC_ID_VP6F;
3599 } else if (!strcmp (mimetype, "video/x-vp6-alpha")) {
3600 id = AV_CODEC_ID_VP6A;
3602 } else if (!strcmp (mimetype, "video/x-vp8")) {
3603 id = AV_CODEC_ID_VP8;
3605 } else if (!strcmp (mimetype, "video/x-flash-screen")) {
3606 id = AV_CODEC_ID_FLASHSV;
3608 } else if (!strcmp (mimetype, "video/x-indeo")) {
3609 gint indeoversion = 0;
3611 if (gst_structure_get_int (structure, "indeoversion", &indeoversion)) {
3612 switch (indeoversion) {
3614 id = AV_CODEC_ID_INDEO5;
3617 id = AV_CODEC_ID_INDEO4;
3620 id = AV_CODEC_ID_INDEO3;
3623 id = AV_CODEC_ID_INDEO2;
3626 if (id != AV_CODEC_ID_NONE)
3629 } else if (!strcmp (mimetype, "video/x-divx")) {
3630 gint divxversion = 0;
3632 if (gst_structure_get_int (structure, "divxversion", &divxversion)) {
3633 switch (divxversion) {
3635 id = AV_CODEC_ID_MSMPEG4V3;
3639 id = AV_CODEC_ID_MPEG4;
3643 if (id != AV_CODEC_ID_NONE)
3645 } else if (!strcmp (mimetype, "video/x-3ivx")) {
3646 id = AV_CODEC_ID_MPEG4;
3648 } else if (!strcmp (mimetype, "video/x-xvid")) {
3649 id = AV_CODEC_ID_MPEG4;
3651 } else if (!strcmp (mimetype, "video/x-ffv")) {
3652 gint ffvversion = 0;
3654 if (gst_structure_get_int (structure, "ffvversion", &ffvversion) &&
3656 id = AV_CODEC_ID_FFV1;
3659 } else if (!strcmp (mimetype, "audio/x-adpcm")) {
3660 const gchar *layout;
3662 layout = gst_structure_get_string (structure, "layout");
3663 if (layout == NULL) {
3665 } else if (!strcmp (layout, "quicktime")) {
3666 id = AV_CODEC_ID_ADPCM_IMA_QT;
3667 } else if (!strcmp (layout, "microsoft")) {
3668 id = AV_CODEC_ID_ADPCM_MS;
3669 } else if (!strcmp (layout, "dvi")) {
3670 id = AV_CODEC_ID_ADPCM_IMA_WAV;
3671 } else if (!strcmp (layout, "4xm")) {
3672 id = AV_CODEC_ID_ADPCM_4XM;
3673 } else if (!strcmp (layout, "smjpeg")) {
3674 id = AV_CODEC_ID_ADPCM_IMA_SMJPEG;
3675 } else if (!strcmp (layout, "dk3")) {
3676 id = AV_CODEC_ID_ADPCM_IMA_DK3;
3677 } else if (!strcmp (layout, "dk4")) {
3678 id = AV_CODEC_ID_ADPCM_IMA_DK4;
3679 } else if (!strcmp (layout, "westwood")) {
3680 id = AV_CODEC_ID_ADPCM_IMA_WS;
3681 } else if (!strcmp (layout, "iss")) {
3682 id = AV_CODEC_ID_ADPCM_IMA_ISS;
3683 } else if (!strcmp (layout, "xa")) {
3684 id = AV_CODEC_ID_ADPCM_XA;
3685 } else if (!strcmp (layout, "adx")) {
3686 id = AV_CODEC_ID_ADPCM_ADX;
3687 } else if (!strcmp (layout, "ea")) {
3688 id = AV_CODEC_ID_ADPCM_EA;
3689 } else if (!strcmp (layout, "g726")) {
3690 id = AV_CODEC_ID_ADPCM_G726;
3691 } else if (!strcmp (layout, "g721")) {
3692 id = AV_CODEC_ID_ADPCM_G726;
3693 } else if (!strcmp (layout, "ct")) {
3694 id = AV_CODEC_ID_ADPCM_CT;
3695 } else if (!strcmp (layout, "swf")) {
3696 id = AV_CODEC_ID_ADPCM_SWF;
3697 } else if (!strcmp (layout, "yamaha")) {
3698 id = AV_CODEC_ID_ADPCM_YAMAHA;
3699 } else if (!strcmp (layout, "sbpro2")) {
3700 id = AV_CODEC_ID_ADPCM_SBPRO_2;
3701 } else if (!strcmp (layout, "sbpro3")) {
3702 id = AV_CODEC_ID_ADPCM_SBPRO_3;
3703 } else if (!strcmp (layout, "sbpro4")) {
3704 id = AV_CODEC_ID_ADPCM_SBPRO_4;
3706 if (id != AV_CODEC_ID_NONE)
3708 } else if (!strcmp (mimetype, "video/x-4xm")) {
3709 id = AV_CODEC_ID_4XM;
3711 } else if (!strcmp (mimetype, "audio/x-dpcm")) {
3712 const gchar *layout;
3714 layout = gst_structure_get_string (structure, "layout");
3717 } else if (!strcmp (layout, "roq")) {
3718 id = AV_CODEC_ID_ROQ_DPCM;
3719 } else if (!strcmp (layout, "interplay")) {
3720 id = AV_CODEC_ID_INTERPLAY_DPCM;
3721 } else if (!strcmp (layout, "xan")) {
3722 id = AV_CODEC_ID_XAN_DPCM;
3723 } else if (!strcmp (layout, "sol")) {
3724 id = AV_CODEC_ID_SOL_DPCM;
3726 if (id != AV_CODEC_ID_NONE)
3728 } else if (!strcmp (mimetype, "audio/x-flac")) {
3729 id = AV_CODEC_ID_FLAC;
3731 } else if (!strcmp (mimetype, "audio/x-shorten")) {
3732 id = AV_CODEC_ID_SHORTEN;
3734 } else if (!strcmp (mimetype, "audio/x-alac")) {
3735 id = AV_CODEC_ID_ALAC;
3737 } else if (!strcmp (mimetype, "video/x-cinepak")) {
3738 id = AV_CODEC_ID_CINEPAK;
3740 } else if (!strcmp (mimetype, "video/x-pn-realvideo")) {
3743 if (gst_structure_get_int (structure, "rmversion", &rmversion)) {
3744 switch (rmversion) {
3746 id = AV_CODEC_ID_RV10;
3749 id = AV_CODEC_ID_RV20;
3752 id = AV_CODEC_ID_RV30;
3755 id = AV_CODEC_ID_RV40;
3759 if (id != AV_CODEC_ID_NONE)
3761 } else if (!strcmp (mimetype, "audio/x-sipro")) {
3762 id = AV_CODEC_ID_SIPR;
3764 } else if (!strcmp (mimetype, "audio/x-pn-realaudio")) {
3767 if (gst_structure_get_int (structure, "raversion", &raversion)) {
3768 switch (raversion) {
3770 id = AV_CODEC_ID_RA_144;
3773 id = AV_CODEC_ID_RA_288;
3776 id = AV_CODEC_ID_COOK;
3780 if (id != AV_CODEC_ID_NONE)
3782 } else if (!strcmp (mimetype, "video/x-rle")) {
3783 const gchar *layout;
3785 if ((layout = gst_structure_get_string (structure, "layout"))) {
3786 if (!strcmp (layout, "microsoft")) {
3787 id = AV_CODEC_ID_MSRLE;
3791 } else if (!strcmp (mimetype, "video/x-xan")) {
3794 if ((gst_structure_get_int (structure, "wcversion", &wcversion))) {
3795 switch (wcversion) {
3797 id = AV_CODEC_ID_XAN_WC3;
3801 id = AV_CODEC_ID_XAN_WC4;
3808 } else if (!strcmp (mimetype, "audio/AMR")) {
3810 id = AV_CODEC_ID_AMR_NB;
3811 } else if (!strcmp (mimetype, "audio/AMR-WB")) {
3812 id = AV_CODEC_ID_AMR_WB;
3814 } else if (!strcmp (mimetype, "audio/qcelp")) {
3815 id = AV_CODEC_ID_QCELP;
3817 } else if (!strcmp (mimetype, "video/x-h264")) {
3818 id = AV_CODEC_ID_H264;
3820 } else if (!strcmp (mimetype, "video/x-flash-video")) {
3821 gint flvversion = 0;
3823 if ((gst_structure_get_int (structure, "flvversion", &flvversion))) {
3824 switch (flvversion) {
3826 id = AV_CODEC_ID_FLV1;
3834 } else if (!strcmp (mimetype, "audio/x-nellymoser")) {
3835 id = AV_CODEC_ID_NELLYMOSER;
3837 } else if (!strncmp (mimetype, "audio/x-gst-av-", 15)) {
3841 if (strlen (mimetype) <= 30 &&
3842 sscanf (mimetype, "audio/x-gst-av-%s", ext) == 1) {
3843 if ((codec = avcodec_find_decoder_by_name (ext)) ||
3844 (codec = avcodec_find_encoder_by_name (ext))) {
3849 } else if (!strncmp (mimetype, "video/x-gst-av-", 15)) {
3853 if (strlen (mimetype) <= 30 &&
3854 sscanf (mimetype, "video/x-gst-av-%s", ext) == 1) {
3855 if ((codec = avcodec_find_decoder_by_name (ext)) ||
3856 (codec = avcodec_find_encoder_by_name (ext))) {
3863 if (context != NULL) {
3864 if (video == TRUE) {
3865 context->codec_type = AVMEDIA_TYPE_VIDEO;
3866 } else if (audio == TRUE) {
3867 context->codec_type = AVMEDIA_TYPE_AUDIO;
3869 context->codec_type = AVMEDIA_TYPE_UNKNOWN;
3871 context->codec_id = id;
3872 gst_ffmpeg_caps_with_codecid (id, context->codec_type, caps, context);
3875 if (id != AV_CODEC_ID_NONE) {
3876 GST_DEBUG ("The id=%d belongs to the caps %" GST_PTR_FORMAT, id, caps);
3878 GST_WARNING ("Couldn't figure out the id for caps %" GST_PTR_FORMAT, caps);