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_value_list_contains (const GValue * list, const GValue * value)
168 n = gst_value_list_get_size (list);
169 for (i = 0; i < n; i++) {
170 tmp = gst_value_list_get_value (list, i);
171 if (gst_value_compare (value, tmp) == GST_VALUE_EQUAL)
179 gst_ffmpeg_video_set_pix_fmts (GstCaps * caps, const enum AVPixelFormat *fmts)
183 GstVideoFormat format;
185 if (!fmts || fmts[0] == -1) {
188 g_value_init (&va, GST_TYPE_LIST);
189 g_value_init (&v, G_TYPE_STRING);
190 for (i = 0; i <= PIX_FMT_NB; i++) {
191 format = gst_ffmpeg_pixfmt_to_videoformat (i);
192 if (format == GST_VIDEO_FORMAT_UNKNOWN)
194 g_value_set_string (&v, gst_video_format_to_string (format));
195 gst_value_list_append_value (&va, &v);
197 gst_caps_set_value (caps, "format", &va);
203 /* Only a single format */
204 g_value_init (&va, GST_TYPE_LIST);
205 g_value_init (&v, G_TYPE_STRING);
206 while (*fmts != -1) {
207 format = gst_ffmpeg_pixfmt_to_videoformat (*fmts);
208 if (format != GST_VIDEO_FORMAT_UNKNOWN) {
209 g_value_set_string (&v, gst_video_format_to_string (format));
210 /* Only append values we don't have yet */
211 if (!_gst_value_list_contains (&va, &v))
212 gst_value_list_append_value (&va, &v);
216 if (gst_value_list_get_size (&va) == 1) {
217 /* The single value is still in v */
218 gst_caps_set_value (caps, "format", &v);
219 } else if (gst_value_list_get_size (&va) > 1) {
220 gst_caps_set_value (caps, "format", &va);
226 /* this macro makes a caps width fixed or unfixed width/height
227 * properties depending on whether we've got a context.
229 * See below for why we use this.
231 * We should actually do this stuff at the end, like in riff-media.c,
232 * but I'm too lazy today. Maybe later.
235 gst_ff_vid_caps_new (AVCodecContext * context, AVCodec * codec,
236 enum CodecID codec_id, gboolean encode, const char *mimetype,
237 const char *fieldname, ...)
239 GstCaps *caps = NULL;
243 GST_LOG ("context:%p, codec_id:%d, mimetype:%s", context, codec_id, mimetype);
245 /* fixed, non probing context */
246 if (context != NULL && context->width != -1) {
249 caps = gst_caps_new_simple (mimetype,
250 "width", G_TYPE_INT, context->width,
251 "height", G_TYPE_INT, context->height, NULL);
253 num = context->time_base.den / context->ticks_per_frame;
254 denom = context->time_base.num;
257 GST_LOG ("invalid framerate: %d/0, -> %d/1", num, num);
260 if (gst_util_fraction_compare (num, denom, 1000, 1) > 0) {
261 GST_LOG ("excessive framerate: %d/%d, -> 0/1", num, denom);
265 GST_LOG ("setting framerate: %d/%d", num, denom);
266 gst_caps_set_simple (caps,
267 "framerate", GST_TYPE_FRACTION, num, denom, NULL);
269 /* so we are after restricted caps in this case */
271 case AV_CODEC_ID_H261:
273 caps = gst_caps_new_simple (mimetype,
274 "width", G_TYPE_INT, 352,
275 "height", G_TYPE_INT, 288,
276 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
277 gst_caps_append (caps, gst_caps_new_simple (mimetype,
278 "width", G_TYPE_INT, 176,
279 "height", G_TYPE_INT, 144,
280 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL));
283 case AV_CODEC_ID_H263:
285 /* 128x96, 176x144, 352x288, 704x576, and 1408x1152. slightly reordered
286 * because we want automatic negotiation to go as close to 320x240 as
288 const static gint widths[] = { 352, 704, 176, 1408, 128 };
289 const static gint heights[] = { 288, 576, 144, 1152, 96 };
291 gint n_sizes = G_N_ELEMENTS (widths);
293 caps = gst_caps_new_empty ();
294 for (i = 0; i < n_sizes; i++) {
295 temp = gst_caps_new_simple (mimetype,
296 "width", G_TYPE_INT, widths[i],
297 "height", G_TYPE_INT, heights[i],
298 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
300 gst_caps_append (caps, temp);
304 case AV_CODEC_ID_DVVIDEO:
311 gint framerate_n, framerate_d;
314 "Y41B", 720, 480, 8, 9, 30000, 1001}, {
315 "Y41B", 720, 480, 32, 27, 30000, 1001}, {
316 "Y42B", 720, 480, 8, 9, 30000, 1001}, {
317 "Y42B", 720, 480, 32, 27, 30000, 1001}, {
318 "I420", 720, 576, 16, 15, 25, 1}, {
319 "I420", 720, 576, 64, 45, 25, 1}, {
320 "Y41B", 720, 576, 16, 15, 25, 1}, {
321 "Y41B", 720, 576, 64, 45, 25, 1}, {
322 "Y42B", 720, 576, 16, 15, 25, 1}, {
323 "Y42B", 720, 576, 64, 45, 25, 1}, {
324 "Y42B", 1280, 1080, 1, 1, 30000, 1001}, {
325 "Y42B", 1280, 1080, 3, 2, 30000, 1001}, {
326 "Y42B", 1440, 1080, 1, 1, 25, 1}, {
327 "Y42B", 1440, 1080, 4, 3, 25, 1}, {
328 "Y42B", 960, 720, 1, 1, 60000, 1001}, {
329 "Y42B", 960, 720, 4, 3, 60000, 1001}, {
330 "Y42B", 960, 720, 1, 1, 50, 1}, {
331 "Y42B", 960, 720, 4, 3, 50, 1},};
333 gint n_sizes = G_N_ELEMENTS (profiles);
335 if (strcmp (mimetype, "video/x-raw") == 0) {
336 caps = gst_caps_new_empty ();
337 for (i = 0; i < n_sizes; i++) {
338 temp = gst_caps_new_simple (mimetype,
339 "format", G_TYPE_STRING, profiles[i].csp,
340 "width", G_TYPE_INT, profiles[i].width,
341 "height", G_TYPE_INT, profiles[i].height,
342 "framerate", GST_TYPE_FRACTION, profiles[i].framerate_n,
343 profiles[i].framerate_d, "pixel-aspect-ratio",
344 GST_TYPE_FRACTION, profiles[i].par_n, profiles[i].par_d, NULL);
346 gst_caps_append (caps, temp);
349 caps = gst_caps_new_empty ();
350 for (i = 0; i < n_sizes; i++) {
351 temp = gst_caps_new_simple (mimetype,
352 "width", G_TYPE_INT, profiles[i].width,
353 "height", G_TYPE_INT, profiles[i].height,
354 "framerate", GST_TYPE_FRACTION, profiles[i].framerate_n,
355 profiles[i].framerate_d, "pixel-aspect-ratio",
356 GST_TYPE_FRACTION, profiles[i].par_n, profiles[i].par_d, NULL);
358 gst_caps_append (caps, temp);
363 case AV_CODEC_ID_DNXHD:
365 caps = gst_caps_new_simple (mimetype,
366 "width", G_TYPE_INT, 1920,
367 "height", G_TYPE_INT, 1080,
368 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
369 gst_caps_append (caps, gst_caps_new_simple (mimetype,
370 "width", G_TYPE_INT, 1280,
371 "height", G_TYPE_INT, 720,
372 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL));
377 if (codec && codec->supported_framerates
378 && codec->supported_framerates[0].num != 0
379 && codec->supported_framerates[0].den != 0) {
382 const AVRational *rates = codec->supported_framerates;
384 if (rates[1].num == 0 && rates[1].den == 0) {
386 gst_caps_new_simple (mimetype, "framerate", GST_TYPE_FRACTION,
387 rates[0].num, rates[0].den, NULL);
389 g_value_init (&va, GST_TYPE_LIST);
390 g_value_init (&v, GST_TYPE_FRACTION);
392 while (rates->num != 0 && rates->den != 0) {
393 gst_value_set_fraction (&v, rates->num, rates->den);
394 gst_value_list_append_value (&va, &v);
398 caps = gst_caps_new_simple (mimetype, NULL, NULL, NULL);
399 gst_caps_set_value (caps, "framerate", &va);
405 caps = gst_caps_new_empty_simple (mimetype);
413 /* no fixed caps or special restrictions applied;
414 * default unfixed setting */
416 GST_DEBUG ("Creating default caps");
417 caps = gst_caps_new_empty_simple (mimetype);
420 va_start (var_args, fieldname);
421 gst_caps_set_simple_valist (caps, fieldname, var_args);
428 get_nbits_set (guint64 n)
433 for (i = 0; i < 64; i++) {
434 if ((n & (G_GUINT64_CONSTANT (1) << i)))
442 gst_ffmpeg_audio_set_sample_fmts (GstCaps * caps,
443 const enum AVSampleFormat *fmts)
447 GstAudioFormat format;
449 if (!fmts || fmts[0] == -1) {
452 g_value_init (&va, GST_TYPE_LIST);
453 g_value_init (&v, G_TYPE_STRING);
454 for (i = 0; i <= AV_SAMPLE_FMT_DBL; i++) {
455 format = gst_ffmpeg_smpfmt_to_audioformat (i);
456 if (format == GST_AUDIO_FORMAT_UNKNOWN)
458 g_value_set_string (&v, gst_audio_format_to_string (format));
459 gst_value_list_append_value (&va, &v);
461 gst_caps_set_value (caps, "format", &va);
467 g_value_init (&va, GST_TYPE_LIST);
468 g_value_init (&v, G_TYPE_STRING);
469 while (*fmts != -1) {
470 format = gst_ffmpeg_smpfmt_to_audioformat (*fmts);
471 if (format != GST_AUDIO_FORMAT_UNKNOWN) {
472 g_value_set_string (&v, gst_audio_format_to_string (format));
473 /* Only append values we don't have yet */
474 if (!_gst_value_list_contains (&va, &v))
475 gst_value_list_append_value (&va, &v);
479 if (gst_value_list_get_size (&va) == 1) {
480 /* The single value is still in v */
481 gst_caps_set_value (caps, "format", &v);
482 } else if (gst_value_list_get_size (&va) > 1) {
483 gst_caps_set_value (caps, "format", &va);
489 /* same for audio - now with channels/sample rate
492 gst_ff_aud_caps_new (AVCodecContext * context, AVCodec * codec,
493 enum CodecID codec_id, gboolean encode, const char *mimetype,
494 const char *fieldname, ...)
496 GstCaps *caps = NULL;
500 /* fixed, non-probing context */
501 if (context != NULL && context->channels != -1) {
502 GstAudioChannelPosition pos[64];
504 caps = gst_caps_new_simple (mimetype,
505 "rate", G_TYPE_INT, context->sample_rate,
506 "channels", G_TYPE_INT, context->channels, NULL);
508 if (gst_ffmpeg_channel_layout_to_gst (context->channel_layout,
509 context->channels, pos)) {
512 if (gst_audio_channel_positions_to_mask (pos, context->channels, FALSE,
514 gst_caps_set_simple (caps, "channel-mask", GST_TYPE_BITMASK, mask,
519 gint maxchannels = 2;
520 const gint *rates = NULL;
523 /* so we must be after restricted caps in this case */
525 case AV_CODEC_ID_AAC:
526 case AV_CODEC_ID_AAC_LATM:
527 case AV_CODEC_ID_DTS:
530 case AV_CODEC_ID_MP2:
532 const static gint l_rates[] =
533 { 48000, 44100, 32000, 24000, 22050, 16000 };
534 n_rates = G_N_ELEMENTS (l_rates);
538 case AV_CODEC_ID_EAC3:
539 case AV_CODEC_ID_AC3:
541 const static gint l_rates[] = { 48000, 44100, 32000 };
543 n_rates = G_N_ELEMENTS (l_rates);
547 case AV_CODEC_ID_ADPCM_G722:
549 const static gint l_rates[] = { 16000 };
550 n_rates = G_N_ELEMENTS (l_rates);
555 case AV_CODEC_ID_ADPCM_G726:
557 const static gint l_rates[] = { 8000 };
558 n_rates = G_N_ELEMENTS (l_rates);
563 case AV_CODEC_ID_ADPCM_SWF:
565 const static gint l_rates[] = { 11025, 22050, 44100 };
566 n_rates = G_N_ELEMENTS (l_rates);
570 case AV_CODEC_ID_ROQ_DPCM:
572 const static gint l_rates[] = { 22050 };
573 n_rates = G_N_ELEMENTS (l_rates);
577 case AV_CODEC_ID_AMR_NB:
579 const static gint l_rates[] = { 8000 };
581 n_rates = G_N_ELEMENTS (l_rates);
585 case AV_CODEC_ID_AMR_WB:
587 const static gint l_rates[] = { 16000 };
589 n_rates = G_N_ELEMENTS (l_rates);
597 /* regardless of encode/decode, open up channels if applicable */
598 /* Until decoders/encoders expose the maximum number of channels
599 * they support, we whitelist them here. */
601 case AV_CODEC_ID_WMAPRO:
602 case AV_CODEC_ID_TRUEHD:
609 if (codec && codec->channel_layouts) {
610 const uint64_t *layouts = codec->channel_layouts;
611 GstAudioChannelPosition pos[64];
613 caps = gst_caps_new_empty ();
615 gint nbits_set = get_nbits_set (*layouts);
617 if (gst_ffmpeg_channel_layout_to_gst (*layouts, nbits_set, pos)) {
620 if (gst_audio_channel_positions_to_mask (pos, nbits_set, FALSE,
623 gst_caps_new_simple (mimetype, "channel-mask", GST_TYPE_BITMASK,
625 "channels", G_TYPE_INT, nbits_set, NULL);
627 gst_caps_append (caps, tmp);
633 if (maxchannels == 1)
634 caps = gst_caps_new_simple (mimetype,
635 "channels", G_TYPE_INT, maxchannels, NULL);
637 caps = gst_caps_new_simple (mimetype,
638 "channels", GST_TYPE_INT_RANGE, 1, maxchannels, NULL);
642 GValue list = { 0, };
644 g_value_init (&list, GST_TYPE_LIST);
645 for (i = 0; i < n_rates; i++) {
648 g_value_init (&v, G_TYPE_INT);
649 g_value_set_int (&v, rates[i]);
650 gst_value_list_append_value (&list, &v);
653 gst_caps_set_value (caps, "rate", &list);
654 g_value_unset (&list);
655 } else if (codec && codec->supported_samplerates
656 && codec->supported_samplerates[0]) {
660 if (!codec->supported_samplerates[1]) {
661 gst_caps_set_simple (caps, "rate", G_TYPE_INT,
662 codec->supported_samplerates[0], NULL);
664 const int *rates = codec->supported_samplerates;
666 g_value_init (&va, GST_TYPE_LIST);
667 g_value_init (&v, G_TYPE_INT);
670 g_value_set_int (&v, *rates);
671 gst_value_list_append_value (&va, &v);
674 gst_caps_set_value (caps, "rate", &va);
679 gst_caps_set_simple (caps, "rate", GST_TYPE_INT_RANGE, 4000, 96000, NULL);
682 caps = gst_caps_new_empty_simple (mimetype);
685 va_start (var_args, fieldname);
686 gst_caps_set_simple_valist (caps, fieldname, var_args);
692 /* Convert a FFMPEG codec ID and optional AVCodecContext
693 * to a GstCaps. If the context is ommitted, no fixed values
694 * for video/audio size will be included in the GstCaps
696 * CodecID is primarily meant for compressed data GstCaps!
698 * encode is a special parameter. gstffmpegdec will say
699 * FALSE, gstffmpegenc will say TRUE. The output caps
700 * depends on this, in such a way that it will be very
701 * specific, defined, fixed and correct caps for encoders,
702 * yet very wide, "forgiving" caps for decoders. Example
703 * for mp3: decode: audio/mpeg,mpegversion=1,layer=[1-3]
704 * but encode: audio/mpeg,mpegversion=1,layer=3,bitrate=x,
709 gst_ffmpeg_codecid_to_caps (enum CodecID codec_id,
710 AVCodecContext * context, gboolean encode)
712 GstCaps *caps = NULL;
713 gboolean buildcaps = FALSE;
715 GST_LOG ("codec_id:%d, context:%p, encode:%d", codec_id, context, encode);
718 case AV_CODEC_ID_MPEG1VIDEO:
720 caps = gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
721 "mpegversion", G_TYPE_INT, 1,
722 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
725 case AV_CODEC_ID_MPEG2VIDEO:
729 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
730 "mpegversion", G_TYPE_INT, 2, "systemstream", G_TYPE_BOOLEAN, FALSE,
733 /* decode both MPEG-1 and MPEG-2; width/height/fps are all in
734 * the MPEG video stream headers, so may be omitted from caps. */
735 caps = gst_caps_new_simple ("video/mpeg",
736 "mpegversion", GST_TYPE_INT_RANGE, 1, 2,
737 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
741 case AV_CODEC_ID_MPEG2VIDEO_XVMC:
742 /* this is a special ID - don't need it in GStreamer, I think */
745 case AV_CODEC_ID_H263:
748 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
749 "video/x-h263", "variant", G_TYPE_STRING, "itu", "h263version",
750 G_TYPE_STRING, "h263", NULL);
752 /* don't pass codec_id, we can decode other variants with the H263
753 * decoder that don't have specific size requirements
756 gst_ff_vid_caps_new (context, NULL, AV_CODEC_ID_NONE, encode,
757 "video/x-h263", "variant", G_TYPE_STRING, "itu", NULL);
761 case AV_CODEC_ID_H263P:
763 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h263",
764 "variant", G_TYPE_STRING, "itu", "h263version", G_TYPE_STRING,
766 if (encode && context) {
768 gst_caps_set_simple (caps,
769 "annex-f", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_4MV,
770 "annex-j", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_LOOP_FILTER,
771 "annex-i", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_AC_PRED,
772 "annex-t", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_AC_PRED,
777 case AV_CODEC_ID_H263I:
779 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
780 "video/x-intel-h263", "variant", G_TYPE_STRING, "intel", NULL);
783 case AV_CODEC_ID_H261:
785 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h261",
789 case AV_CODEC_ID_RV10:
790 case AV_CODEC_ID_RV20:
791 case AV_CODEC_ID_RV30:
792 case AV_CODEC_ID_RV40:
797 case AV_CODEC_ID_RV40:
800 case AV_CODEC_ID_RV30:
803 case AV_CODEC_ID_RV20:
811 /* FIXME: context->sub_id must be filled in during decoding */
813 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
814 "video/x-pn-realvideo", "rmversion", G_TYPE_INT, version, NULL);
816 gst_caps_set_simple (caps, "format", G_TYPE_INT, context->sub_id, NULL);
817 if (context->extradata_size >= 8) {
818 gst_caps_set_simple (caps,
819 "subformat", G_TYPE_INT, GST_READ_UINT32_BE (context->extradata),
826 case AV_CODEC_ID_MP1:
828 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
829 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 1, NULL);
832 case AV_CODEC_ID_MP2:
834 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
835 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 2, NULL);
838 case AV_CODEC_ID_MP3:
842 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
843 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 3, NULL);
845 /* Decodes MPEG-1 layer 1/2/3. Samplerate, channels et al are
846 * in the MPEG audio header, so may be omitted from caps. */
847 caps = gst_caps_new_simple ("audio/mpeg",
848 "mpegversion", G_TYPE_INT, 1,
849 "layer", GST_TYPE_INT_RANGE, 1, 3, NULL);
853 case AV_CODEC_ID_MUSEPACK7:
855 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
856 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 7,
860 case AV_CODEC_ID_MUSEPACK8:
862 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
863 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 8,
867 case AV_CODEC_ID_AC3:
870 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-ac3",
874 case AV_CODEC_ID_EAC3:
877 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-eac3",
881 case AV_CODEC_ID_TRUEHD:
883 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
884 "audio/x-true-hd", NULL);
887 case AV_CODEC_ID_ATRAC1:
889 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
890 "audio/x-vnd.sony.atrac1", NULL);
893 case AV_CODEC_ID_ATRAC3:
895 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
896 "audio/x-vnd.sony.atrac3", NULL);
899 case AV_CODEC_ID_DTS:
901 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dts",
905 case AV_CODEC_ID_APE:
907 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
908 "audio/x-ffmpeg-parsed-ape", NULL);
910 gst_caps_set_simple (caps,
911 "depth", G_TYPE_INT, context->bits_per_coded_sample, NULL);
915 case AV_CODEC_ID_MLP:
917 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mlp",
921 case AV_CODEC_ID_IMC:
923 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-imc",
927 /* MJPEG is normal JPEG, Motion-JPEG and Quicktime MJPEG-A. MJPEGB
928 * is Quicktime's MJPEG-B. LJPEG is lossless JPEG. I don't know what
929 * sp5x is, but it's apparently something JPEG... We don't separate
930 * between those in GStreamer. Should we (at least between MJPEG,
931 * MJPEG-B and sp5x decoding...)? */
932 case AV_CODEC_ID_MJPEG:
933 case AV_CODEC_ID_LJPEG:
935 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/jpeg",
939 case AV_CODEC_ID_SP5X:
941 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/sp5x",
945 case AV_CODEC_ID_MJPEGB:
947 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
948 "video/x-mjpeg-b", NULL);
951 case AV_CODEC_ID_MPEG4:
952 if (encode && context != NULL) {
953 /* I'm not exactly sure what ffmpeg outputs... ffmpeg itself uses
954 * the AVI fourcc 'DIVX', but 'mp4v' for Quicktime... */
955 switch (context->codec_tag) {
956 case GST_MAKE_FOURCC ('D', 'I', 'V', 'X'):
958 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
959 "video/x-divx", "divxversion", G_TYPE_INT, 5, NULL);
961 case GST_MAKE_FOURCC ('m', 'p', '4', 'v'):
965 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
966 "video/mpeg", "systemstream", G_TYPE_BOOLEAN, FALSE,
967 "mpegversion", G_TYPE_INT, 4, NULL);
971 /* The trick here is to separate xvid, divx, mpeg4, 3ivx et al */
973 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
974 "mpegversion", G_TYPE_INT, 4, "systemstream", G_TYPE_BOOLEAN, FALSE,
977 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
978 encode, "video/x-divx", "divxversion", G_TYPE_INT, 5, NULL));
980 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
981 encode, "video/x-divx", "divxversion", GST_TYPE_INT_RANGE, 4,
983 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
984 encode, "video/x-xvid", NULL));
985 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
986 encode, "video/x-3ivx", NULL));
991 case AV_CODEC_ID_RAWVIDEO:
993 gst_ffmpeg_codectype_to_video_caps (context, codec_id, encode, NULL);
996 case AV_CODEC_ID_MSMPEG4V1:
997 case AV_CODEC_ID_MSMPEG4V2:
998 case AV_CODEC_ID_MSMPEG4V3:
1000 gint version = 41 + codec_id - AV_CODEC_ID_MSMPEG4V1;
1002 /* encode-FIXME: bitrate */
1004 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1005 "video/x-msmpeg", "msmpegversion", G_TYPE_INT, version, NULL);
1006 if (!encode && codec_id == AV_CODEC_ID_MSMPEG4V3) {
1007 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
1008 encode, "video/x-divx", "divxversion", G_TYPE_INT, 3, NULL));
1013 case AV_CODEC_ID_WMV1:
1014 case AV_CODEC_ID_WMV2:
1016 gint version = (codec_id == AV_CODEC_ID_WMV1) ? 1 : 2;
1019 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1020 "wmvversion", G_TYPE_INT, version, NULL);
1024 case AV_CODEC_ID_FLV1:
1026 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1027 "video/x-flash-video", "flvversion", G_TYPE_INT, 1, NULL);
1030 case AV_CODEC_ID_SVQ1:
1032 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-svq",
1033 "svqversion", G_TYPE_INT, 1, NULL);
1036 case AV_CODEC_ID_SVQ3:
1038 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-svq",
1039 "svqversion", G_TYPE_INT, 3, NULL);
1042 case AV_CODEC_ID_DVAUDIO:
1044 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dv",
1048 case AV_CODEC_ID_DVVIDEO:
1050 if (encode && context) {
1051 const gchar *format;
1053 switch (context->pix_fmt) {
1054 case PIX_FMT_YUYV422:
1057 case PIX_FMT_YUV420P:
1060 case PIX_FMT_YUVA420P:
1063 case PIX_FMT_YUV411P:
1066 case PIX_FMT_YUV422P:
1069 case PIX_FMT_YUV410P:
1074 ("Couldnt' find format for pixfmt %d, defaulting to I420",
1080 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dv",
1081 "systemstream", G_TYPE_BOOLEAN, FALSE, "format", G_TYPE_STRING,
1085 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dv",
1086 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
1091 case AV_CODEC_ID_WMAV1:
1092 case AV_CODEC_ID_WMAV2:
1094 gint version = (codec_id == AV_CODEC_ID_WMAV1) ? 1 : 2;
1098 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1099 "wmaversion", G_TYPE_INT, version, "block_align", G_TYPE_INT,
1100 context->block_align, "bitrate", G_TYPE_INT, context->bit_rate,
1104 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1105 "wmaversion", G_TYPE_INT, version, "block_align",
1106 GST_TYPE_INT_RANGE, 0, G_MAXINT, "bitrate", GST_TYPE_INT_RANGE, 0,
1111 case AV_CODEC_ID_WMAPRO:
1114 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1115 "wmaversion", G_TYPE_INT, 3, NULL);
1118 case AV_CODEC_ID_WMALOSSLESS:
1120 /* libav only supports a depth of 16 at the moment */
1122 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1123 "wmaversion", G_TYPE_INT, 4, "depth", G_TYPE_INT, 16, NULL);
1126 case AV_CODEC_ID_WMAVOICE:
1129 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wms",
1134 case AV_CODEC_ID_MACE3:
1135 case AV_CODEC_ID_MACE6:
1137 gint version = (codec_id == AV_CODEC_ID_MACE3) ? 3 : 6;
1140 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mace",
1141 "maceversion", G_TYPE_INT, version, NULL);
1145 case AV_CODEC_ID_HUFFYUV:
1147 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1148 "video/x-huffyuv", NULL);
1150 gst_caps_set_simple (caps,
1151 "bpp", G_TYPE_INT, context->bits_per_coded_sample, NULL);
1155 case AV_CODEC_ID_CYUV:
1157 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1158 "video/x-compressed-yuv", NULL);
1161 case AV_CODEC_ID_H264:
1163 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h264",
1164 "alignment", G_TYPE_STRING, "au", NULL);
1166 GValue arr = { 0, };
1167 GValue item = { 0, };
1168 g_value_init (&arr, GST_TYPE_LIST);
1169 g_value_init (&item, G_TYPE_STRING);
1170 g_value_set_string (&item, "avc");
1171 gst_value_list_append_value (&arr, &item);
1172 g_value_set_string (&item, "byte-stream");
1173 gst_value_list_append_value (&arr, &item);
1174 g_value_unset (&item);
1175 gst_caps_set_value (caps, "stream-format", &arr);
1176 g_value_unset (&arr);
1180 case AV_CODEC_ID_INDEO5:
1182 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1183 "indeoversion", G_TYPE_INT, 5, NULL);
1186 case AV_CODEC_ID_INDEO4:
1188 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1189 "indeoversion", G_TYPE_INT, 4, NULL);
1192 case AV_CODEC_ID_INDEO3:
1194 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1195 "indeoversion", G_TYPE_INT, 3, NULL);
1198 case AV_CODEC_ID_INDEO2:
1200 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1201 "indeoversion", G_TYPE_INT, 2, NULL);
1204 case AV_CODEC_ID_FLASHSV:
1206 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1207 "video/x-flash-screen", NULL);
1210 case AV_CODEC_ID_VP3:
1212 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp3",
1216 case AV_CODEC_ID_VP5:
1218 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp5",
1222 case AV_CODEC_ID_VP6:
1224 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp6",
1228 case AV_CODEC_ID_VP6F:
1230 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1231 "video/x-vp6-flash", NULL);
1234 case AV_CODEC_ID_VP6A:
1236 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1237 "video/x-vp6-alpha", NULL);
1240 case AV_CODEC_ID_VP8:
1242 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp8",
1246 case AV_CODEC_ID_THEORA:
1248 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1249 "video/x-theora", NULL);
1252 case AV_CODEC_ID_AAC:
1255 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
1259 GValue arr = { 0, };
1260 GValue item = { 0, };
1262 g_value_init (&arr, GST_TYPE_LIST);
1263 g_value_init (&item, G_TYPE_INT);
1264 g_value_set_int (&item, 2);
1265 gst_value_list_append_value (&arr, &item);
1266 g_value_set_int (&item, 4);
1267 gst_value_list_append_value (&arr, &item);
1268 g_value_unset (&item);
1270 gst_caps_set_value (caps, "mpegversion", &arr);
1271 g_value_unset (&arr);
1273 g_value_init (&arr, GST_TYPE_LIST);
1274 g_value_init (&item, G_TYPE_STRING);
1275 g_value_set_string (&item, "raw");
1276 gst_value_list_append_value (&arr, &item);
1277 g_value_set_string (&item, "adts");
1278 gst_value_list_append_value (&arr, &item);
1279 g_value_set_string (&item, "adif");
1280 gst_value_list_append_value (&arr, &item);
1281 g_value_unset (&item);
1283 gst_caps_set_value (caps, "stream-format", &arr);
1284 g_value_unset (&arr);
1286 gst_caps_set_simple (caps, "mpegversion", G_TYPE_INT, 4,
1287 "stream-format", G_TYPE_STRING, "raw",
1288 "base-profile", G_TYPE_STRING, "lc", NULL);
1290 if (context && context->extradata_size > 0)
1291 gst_codec_utils_aac_caps_set_level_and_profile (caps,
1292 context->extradata, context->extradata_size);
1297 case AV_CODEC_ID_AAC_LATM: /* LATM/LOAS AAC syntax */
1298 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
1299 "mpegversion", G_TYPE_INT, 4, "stream-format", G_TYPE_STRING, "loas",
1303 case AV_CODEC_ID_ASV1:
1305 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-asus",
1306 "asusversion", G_TYPE_INT, 1, NULL);
1308 case AV_CODEC_ID_ASV2:
1310 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-asus",
1311 "asusversion", G_TYPE_INT, 2, NULL);
1314 case AV_CODEC_ID_FFV1:
1316 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-ffv",
1317 "ffvversion", G_TYPE_INT, 1, NULL);
1320 case AV_CODEC_ID_4XM:
1322 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-4xm",
1326 case AV_CODEC_ID_XAN_WC3:
1327 case AV_CODEC_ID_XAN_WC4:
1329 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-xan",
1330 "wcversion", G_TYPE_INT, 3 - AV_CODEC_ID_XAN_WC3 + codec_id, NULL);
1333 case AV_CODEC_ID_CLJR:
1335 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1336 "video/x-cirrus-logic-accupak", NULL);
1339 case AV_CODEC_ID_FRAPS:
1341 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-fraps",
1345 case AV_CODEC_ID_MDEC:
1346 case AV_CODEC_ID_ROQ:
1347 case AV_CODEC_ID_INTERPLAY_VIDEO:
1351 case AV_CODEC_ID_VCR1:
1353 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1354 "video/x-ati-vcr", "vcrversion", G_TYPE_INT, 1, NULL);
1357 case AV_CODEC_ID_RPZA:
1359 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1360 "video/x-apple-video", NULL);
1363 case AV_CODEC_ID_CINEPAK:
1365 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1366 "video/x-cinepak", NULL);
1369 /* WS_VQA belogns here (order) */
1371 case AV_CODEC_ID_MSRLE:
1373 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-rle",
1374 "layout", G_TYPE_STRING, "microsoft", NULL);
1376 gst_caps_set_simple (caps,
1377 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1379 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1383 case AV_CODEC_ID_QTRLE:
1385 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-rle",
1386 "layout", G_TYPE_STRING, "quicktime", NULL);
1388 gst_caps_set_simple (caps,
1389 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1391 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1395 case AV_CODEC_ID_MSVIDEO1:
1397 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1398 "video/x-msvideocodec", "msvideoversion", G_TYPE_INT, 1, NULL);
1401 case AV_CODEC_ID_MSS1:
1403 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1404 "wmvversion", G_TYPE_INT, 1, "format", G_TYPE_STRING, "MSS1", NULL);
1407 case AV_CODEC_ID_MSS2:
1409 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1410 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "MSS2", NULL);
1413 case AV_CODEC_ID_WMV3:
1415 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1416 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "WMV3", NULL);
1418 case AV_CODEC_ID_VC1:
1420 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1421 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "WVC1", NULL);
1423 case AV_CODEC_ID_QDM2:
1425 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-qdm2",
1429 case AV_CODEC_ID_MSZH:
1431 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-mszh",
1435 case AV_CODEC_ID_ZLIB:
1437 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-zlib",
1441 case AV_CODEC_ID_TRUEMOTION1:
1443 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1444 "video/x-truemotion", "trueversion", G_TYPE_INT, 1, NULL);
1446 case AV_CODEC_ID_TRUEMOTION2:
1448 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1449 "video/x-truemotion", "trueversion", G_TYPE_INT, 2, NULL);
1452 case AV_CODEC_ID_ULTI:
1454 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1455 "video/x-ultimotion", NULL);
1458 case AV_CODEC_ID_TSCC:
1460 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1461 "video/x-camtasia", NULL);
1463 gst_caps_set_simple (caps,
1464 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1466 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1470 case AV_CODEC_ID_TSCC2:
1472 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1473 "video/x-tscc", "tsccversion", G_TYPE_INT, 2, NULL);
1476 case AV_CODEC_ID_KMVC:
1478 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-kmvc",
1482 case AV_CODEC_ID_NUV:
1484 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-nuv",
1488 case AV_CODEC_ID_GIF:
1490 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/gif",
1494 case AV_CODEC_ID_PNG:
1496 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/png",
1500 case AV_CODEC_ID_PPM:
1502 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/ppm",
1506 case AV_CODEC_ID_PBM:
1508 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/pbm",
1512 case AV_CODEC_ID_PAM:
1514 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1515 "image/x-portable-anymap", NULL);
1518 case AV_CODEC_ID_PGM:
1520 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1521 "image/x-portable-graymap", NULL);
1524 case AV_CODEC_ID_PCX:
1526 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-pcx",
1530 case AV_CODEC_ID_SGI:
1532 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-sgi",
1536 case AV_CODEC_ID_TARGA:
1538 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-tga",
1542 case AV_CODEC_ID_TIFF:
1544 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/tiff",
1548 case AV_CODEC_ID_SUNRAST:
1550 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1551 "image/x-sun-raster", NULL);
1554 case AV_CODEC_ID_SMC:
1556 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-smc",
1560 case AV_CODEC_ID_QDRAW:
1562 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-qdrw",
1566 case AV_CODEC_ID_DNXHD:
1568 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dnxhd",
1572 case AV_CODEC_ID_PRORES:
1574 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1575 "video/x-prores", NULL);
1578 case AV_CODEC_ID_MIMIC:
1580 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-mimic",
1584 case AV_CODEC_ID_VMNC:
1586 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vmnc",
1590 case AV_CODEC_ID_TRUESPEECH:
1592 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1593 "audio/x-truespeech", NULL);
1596 case AV_CODEC_ID_QCELP:
1598 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/qcelp",
1602 case AV_CODEC_ID_AMV:
1604 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-amv",
1608 case AV_CODEC_ID_AASC:
1610 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-aasc",
1614 case AV_CODEC_ID_LOCO:
1616 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-loco",
1620 case AV_CODEC_ID_ZMBV:
1622 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-zmbv",
1626 case AV_CODEC_ID_LAGARITH:
1628 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1629 "video/x-lagarith", NULL);
1632 case AV_CODEC_ID_CSCD:
1634 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1635 "video/x-camstudio", NULL);
1637 gst_caps_set_simple (caps,
1638 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1640 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1644 case AV_CODEC_ID_WS_VQA:
1645 case AV_CODEC_ID_IDCIN:
1646 case AV_CODEC_ID_8BPS:
1647 case AV_CODEC_ID_FLIC:
1648 case AV_CODEC_ID_VMDVIDEO:
1649 case AV_CODEC_ID_VMDAUDIO:
1650 case AV_CODEC_ID_SNOW:
1651 case AV_CODEC_ID_VIXL:
1652 case AV_CODEC_ID_QPEG:
1653 case AV_CODEC_ID_PGMYUV:
1654 case AV_CODEC_ID_FFVHUFF:
1655 case AV_CODEC_ID_WNV1:
1656 case AV_CODEC_ID_MP3ADU:
1657 case AV_CODEC_ID_MP3ON4:
1658 case AV_CODEC_ID_WESTWOOD_SND1:
1659 case AV_CODEC_ID_MMVIDEO:
1660 case AV_CODEC_ID_AVS:
1661 case AV_CODEC_ID_CAVS:
1665 /* weird quasi-codecs for the demuxers only */
1666 case AV_CODEC_ID_PCM_S16LE:
1667 case AV_CODEC_ID_PCM_S16BE:
1668 case AV_CODEC_ID_PCM_U16LE:
1669 case AV_CODEC_ID_PCM_U16BE:
1670 case AV_CODEC_ID_PCM_S8:
1671 case AV_CODEC_ID_PCM_U8:
1673 GstAudioFormat format;
1676 case AV_CODEC_ID_PCM_S16LE:
1677 format = GST_AUDIO_FORMAT_S16LE;
1679 case AV_CODEC_ID_PCM_S16BE:
1680 format = GST_AUDIO_FORMAT_S16BE;
1682 case AV_CODEC_ID_PCM_U16LE:
1683 format = GST_AUDIO_FORMAT_U16LE;
1685 case AV_CODEC_ID_PCM_U16BE:
1686 format = GST_AUDIO_FORMAT_U16BE;
1688 case AV_CODEC_ID_PCM_S8:
1689 format = GST_AUDIO_FORMAT_S8;
1691 case AV_CODEC_ID_PCM_U8:
1692 format = GST_AUDIO_FORMAT_U8;
1695 g_assert (0); /* don't worry, we never get here */
1700 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-raw",
1701 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
1702 "layout", G_TYPE_STRING, "interleaved", NULL);
1706 case AV_CODEC_ID_PCM_MULAW:
1708 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mulaw",
1712 case AV_CODEC_ID_PCM_ALAW:
1714 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-alaw",
1718 case AV_CODEC_ID_ADPCM_G722:
1720 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/G722",
1723 gst_caps_set_simple (caps,
1724 "block_align", G_TYPE_INT, context->block_align,
1725 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1728 case AV_CODEC_ID_ADPCM_G726:
1730 /* the G726 decoder can also handle G721 */
1732 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-adpcm",
1733 "layout", G_TYPE_STRING, "g726", NULL);
1735 gst_caps_set_simple (caps,
1736 "block_align", G_TYPE_INT, context->block_align,
1737 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1740 gst_caps_append (caps, gst_caps_new_simple ("audio/x-adpcm",
1741 "layout", G_TYPE_STRING, "g721",
1742 "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, 8000, NULL));
1746 case AV_CODEC_ID_ADPCM_IMA_QT:
1747 case AV_CODEC_ID_ADPCM_IMA_WAV:
1748 case AV_CODEC_ID_ADPCM_IMA_DK3:
1749 case AV_CODEC_ID_ADPCM_IMA_DK4:
1750 case AV_CODEC_ID_ADPCM_IMA_WS:
1751 case AV_CODEC_ID_ADPCM_IMA_SMJPEG:
1752 case AV_CODEC_ID_ADPCM_IMA_AMV:
1753 case AV_CODEC_ID_ADPCM_IMA_ISS:
1754 case AV_CODEC_ID_ADPCM_IMA_EA_EACS:
1755 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
1756 case AV_CODEC_ID_ADPCM_MS:
1757 case AV_CODEC_ID_ADPCM_4XM:
1758 case AV_CODEC_ID_ADPCM_XA:
1759 case AV_CODEC_ID_ADPCM_ADX:
1760 case AV_CODEC_ID_ADPCM_EA:
1761 case AV_CODEC_ID_ADPCM_CT:
1762 case AV_CODEC_ID_ADPCM_SWF:
1763 case AV_CODEC_ID_ADPCM_YAMAHA:
1764 case AV_CODEC_ID_ADPCM_SBPRO_2:
1765 case AV_CODEC_ID_ADPCM_SBPRO_3:
1766 case AV_CODEC_ID_ADPCM_SBPRO_4:
1767 case AV_CODEC_ID_ADPCM_EA_R1:
1768 case AV_CODEC_ID_ADPCM_EA_R2:
1769 case AV_CODEC_ID_ADPCM_EA_R3:
1770 case AV_CODEC_ID_ADPCM_EA_MAXIS_XA:
1771 case AV_CODEC_ID_ADPCM_EA_XAS:
1772 case AV_CODEC_ID_ADPCM_THP:
1774 const gchar *layout = NULL;
1777 case AV_CODEC_ID_ADPCM_IMA_QT:
1778 layout = "quicktime";
1780 case AV_CODEC_ID_ADPCM_IMA_WAV:
1783 case AV_CODEC_ID_ADPCM_IMA_DK3:
1786 case AV_CODEC_ID_ADPCM_IMA_DK4:
1789 case AV_CODEC_ID_ADPCM_IMA_WS:
1790 layout = "westwood";
1792 case AV_CODEC_ID_ADPCM_IMA_SMJPEG:
1795 case AV_CODEC_ID_ADPCM_IMA_AMV:
1798 case AV_CODEC_ID_ADPCM_IMA_ISS:
1801 case AV_CODEC_ID_ADPCM_IMA_EA_EACS:
1804 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
1807 case AV_CODEC_ID_ADPCM_MS:
1808 layout = "microsoft";
1810 case AV_CODEC_ID_ADPCM_4XM:
1813 case AV_CODEC_ID_ADPCM_XA:
1816 case AV_CODEC_ID_ADPCM_ADX:
1819 case AV_CODEC_ID_ADPCM_EA:
1822 case AV_CODEC_ID_ADPCM_CT:
1825 case AV_CODEC_ID_ADPCM_SWF:
1828 case AV_CODEC_ID_ADPCM_YAMAHA:
1831 case AV_CODEC_ID_ADPCM_SBPRO_2:
1834 case AV_CODEC_ID_ADPCM_SBPRO_3:
1837 case AV_CODEC_ID_ADPCM_SBPRO_4:
1840 case AV_CODEC_ID_ADPCM_EA_R1:
1843 case AV_CODEC_ID_ADPCM_EA_R2:
1846 case AV_CODEC_ID_ADPCM_EA_R3:
1849 case AV_CODEC_ID_ADPCM_EA_MAXIS_XA:
1850 layout = "ea-maxis-xa";
1852 case AV_CODEC_ID_ADPCM_EA_XAS:
1855 case AV_CODEC_ID_ADPCM_THP:
1859 g_assert (0); /* don't worry, we never get here */
1863 /* FIXME: someone please check whether we need additional properties
1864 * in this caps definition. */
1866 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-adpcm",
1867 "layout", G_TYPE_STRING, layout, NULL);
1869 gst_caps_set_simple (caps,
1870 "block_align", G_TYPE_INT, context->block_align,
1871 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1875 case AV_CODEC_ID_AMR_NB:
1877 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/AMR",
1881 case AV_CODEC_ID_AMR_WB:
1883 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/AMR-WB",
1887 case AV_CODEC_ID_GSM:
1889 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-gsm",
1893 case AV_CODEC_ID_GSM_MS:
1895 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/ms-gsm",
1899 case AV_CODEC_ID_NELLYMOSER:
1901 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1902 "audio/x-nellymoser", NULL);
1905 case AV_CODEC_ID_SIPR:
1908 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-sipro",
1911 gst_caps_set_simple (caps,
1912 "leaf_size", G_TYPE_INT, context->block_align,
1913 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1918 case AV_CODEC_ID_RA_144:
1919 case AV_CODEC_ID_RA_288:
1920 case AV_CODEC_ID_COOK:
1925 case AV_CODEC_ID_RA_144:
1928 case AV_CODEC_ID_RA_288:
1931 case AV_CODEC_ID_COOK:
1938 /* FIXME: properties? */
1940 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1941 "audio/x-pn-realaudio", "raversion", G_TYPE_INT, version, NULL);
1943 gst_caps_set_simple (caps,
1944 "leaf_size", G_TYPE_INT, context->block_align,
1945 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1950 case AV_CODEC_ID_ROQ_DPCM:
1951 case AV_CODEC_ID_INTERPLAY_DPCM:
1952 case AV_CODEC_ID_XAN_DPCM:
1953 case AV_CODEC_ID_SOL_DPCM:
1955 const gchar *layout = NULL;
1958 case AV_CODEC_ID_ROQ_DPCM:
1961 case AV_CODEC_ID_INTERPLAY_DPCM:
1962 layout = "interplay";
1964 case AV_CODEC_ID_XAN_DPCM:
1967 case AV_CODEC_ID_SOL_DPCM:
1971 g_assert (0); /* don't worry, we never get here */
1975 /* FIXME: someone please check whether we need additional properties
1976 * in this caps definition. */
1978 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dpcm",
1979 "layout", G_TYPE_STRING, layout, NULL);
1981 gst_caps_set_simple (caps,
1982 "block_align", G_TYPE_INT, context->block_align,
1983 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1987 case AV_CODEC_ID_SHORTEN:
1988 caps = gst_caps_new_empty_simple ("audio/x-shorten");
1991 case AV_CODEC_ID_ALAC:
1993 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-alac",
1996 gst_caps_set_simple (caps,
1997 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
2001 case AV_CODEC_ID_FLAC:
2002 /* Note that ffmpeg has no encoder yet, but just for safety. In the
2003 * encoder case, we want to add things like samplerate, channels... */
2005 caps = gst_caps_new_empty_simple ("audio/x-flac");
2009 case AV_CODEC_ID_S302M:
2010 caps = gst_caps_new_empty_simple ("audio/x-smpte-302m");
2013 case AV_CODEC_ID_DVD_SUBTITLE:
2014 case AV_CODEC_ID_DVB_SUBTITLE:
2017 case AV_CODEC_ID_BMP:
2018 caps = gst_caps_new_empty_simple ("image/bmp");
2020 case AV_CODEC_ID_TTA:
2022 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-tta",
2025 gst_caps_set_simple (caps,
2026 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
2029 case AV_CODEC_ID_TWINVQ:
2031 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
2032 "audio/x-twin-vq", NULL);
2035 GST_DEBUG ("Unknown codec ID %d, please add mapping here", codec_id);
2042 if ((codec = avcodec_find_decoder (codec_id)) ||
2043 (codec = avcodec_find_encoder (codec_id))) {
2046 GST_LOG ("Could not create stream format caps for %s", codec->name);
2048 switch (codec->type) {
2049 case AVMEDIA_TYPE_VIDEO:
2050 mime = g_strdup_printf ("video/x-gst-av-%s", codec->name);
2052 gst_ff_vid_caps_new (context, NULL, codec_id, encode, mime, NULL);
2055 case AVMEDIA_TYPE_AUDIO:
2056 mime = g_strdup_printf ("audio/x-gst-av-%s", codec->name);
2058 gst_ff_aud_caps_new (context, NULL, codec_id, encode, mime, NULL);
2060 gst_caps_set_simple (caps,
2061 "block_align", G_TYPE_INT, context->block_align,
2062 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
2073 /* set private data */
2074 if (context && context->extradata_size > 0) {
2075 GstBuffer *data = gst_buffer_new_and_alloc (context->extradata_size);
2077 gst_buffer_fill (data, 0, context->extradata, context->extradata_size);
2078 gst_caps_set_simple (caps, "codec_data", GST_TYPE_BUFFER, data, NULL);
2079 gst_buffer_unref (data);
2082 GST_LOG ("caps for codec_id=%d: %" GST_PTR_FORMAT, codec_id, caps);
2085 GST_LOG ("No caps found for codec_id=%d", codec_id);
2091 /* Convert a FFMPEG Pixel Format and optional AVCodecContext
2092 * to a GstCaps. If the context is ommitted, no fixed values
2093 * for video/audio size will be included in the GstCaps
2095 * See below for usefullness
2099 gst_ffmpeg_pixfmt_to_caps (enum PixelFormat pix_fmt, AVCodecContext * context,
2100 enum CodecID codec_id)
2102 GstCaps *caps = NULL;
2103 GstVideoFormat format;
2105 format = gst_ffmpeg_pixfmt_to_videoformat (pix_fmt);
2107 if (format != GST_VIDEO_FORMAT_UNKNOWN) {
2108 caps = gst_ff_vid_caps_new (context, NULL, codec_id, TRUE, "video/x-raw",
2109 "format", G_TYPE_STRING, gst_video_format_to_string (format), NULL);
2113 GST_DEBUG ("caps for pix_fmt=%d: %" GST_PTR_FORMAT, pix_fmt, caps);
2115 GST_LOG ("No caps found for pix_fmt=%d", pix_fmt);
2122 gst_ffmpeg_smpfmt_to_audioformat (enum AVSampleFormat sample_fmt)
2124 switch (sample_fmt) {
2125 case AV_SAMPLE_FMT_U8:
2126 case AV_SAMPLE_FMT_U8P:
2127 return GST_AUDIO_FORMAT_U8;
2129 case AV_SAMPLE_FMT_S16:
2130 case AV_SAMPLE_FMT_S16P:
2131 return GST_AUDIO_FORMAT_S16;
2133 case AV_SAMPLE_FMT_S32:
2134 case AV_SAMPLE_FMT_S32P:
2135 return GST_AUDIO_FORMAT_S32;
2137 case AV_SAMPLE_FMT_FLT:
2138 case AV_SAMPLE_FMT_FLTP:
2139 return GST_AUDIO_FORMAT_F32;
2141 case AV_SAMPLE_FMT_DBL:
2142 case AV_SAMPLE_FMT_DBLP:
2143 return GST_AUDIO_FORMAT_F64;
2147 return GST_AUDIO_FORMAT_UNKNOWN;
2152 /* Convert a FFMPEG Sample Format and optional AVCodecContext
2153 * to a GstCaps. If the context is ommitted, no fixed values
2154 * for video/audio size will be included in the GstCaps
2156 * See below for usefullness
2160 gst_ffmpeg_smpfmt_to_caps (enum AVSampleFormat sample_fmt,
2161 AVCodecContext * context, AVCodec * codec, enum CodecID codec_id)
2163 GstCaps *caps = NULL;
2164 GstAudioFormat format;
2166 format = gst_ffmpeg_smpfmt_to_audioformat (sample_fmt);
2168 if (format != GST_AUDIO_FORMAT_UNKNOWN) {
2169 caps = gst_ff_aud_caps_new (context, codec, codec_id, TRUE, "audio/x-raw",
2170 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
2171 "layout", G_TYPE_STRING, "interleaved", NULL);
2172 GST_LOG ("caps for sample_fmt=%d: %" GST_PTR_FORMAT, sample_fmt, caps);
2174 GST_LOG ("No caps found for sample_fmt=%d", sample_fmt);
2181 caps_has_field (GstCaps * caps, const gchar * field)
2185 n = gst_caps_get_size (caps);
2186 for (i = 0; i < n; i++) {
2187 GstStructure *s = gst_caps_get_structure (caps, i);
2189 if (gst_structure_has_field (s, field))
2197 gst_ffmpeg_codectype_to_audio_caps (AVCodecContext * context,
2198 enum CodecID codec_id, gboolean encode, AVCodec * codec)
2200 GstCaps *caps = NULL;
2202 GST_DEBUG ("context:%p, codec_id:%d, encode:%d, codec:%p",
2203 context, codec_id, encode, codec);
2205 GST_DEBUG ("sample_fmts:%p, samplerates:%p",
2206 codec->sample_fmts, codec->supported_samplerates);
2209 /* Specific codec context */
2211 gst_ffmpeg_smpfmt_to_caps (context->sample_fmt, context, codec,
2214 caps = gst_ff_aud_caps_new (context, codec, codec_id, encode, "audio/x-raw",
2215 "layout", G_TYPE_STRING, "interleaved", NULL);
2216 if (!caps_has_field (caps, "format"))
2217 gst_ffmpeg_audio_set_sample_fmts (caps,
2218 codec ? codec->sample_fmts : NULL);
2225 gst_ffmpeg_codectype_to_video_caps (AVCodecContext * context,
2226 enum CodecID codec_id, gboolean encode, AVCodec * codec)
2230 GST_LOG ("context:%p, codec_id:%d, encode:%d, codec:%p",
2231 context, codec_id, encode, codec);
2234 caps = gst_ffmpeg_pixfmt_to_caps (context->pix_fmt, context, codec_id);
2237 gst_ff_vid_caps_new (context, codec, codec_id, encode, "video/x-raw",
2239 if (!caps_has_field (caps, "format"))
2240 gst_ffmpeg_video_set_pix_fmts (caps, codec ? codec->pix_fmts : NULL);
2245 /* Convert a GstCaps (audio/raw) to a FFMPEG SampleFmt
2246 * and other audio properties in a AVCodecContext.
2248 * For usefullness, see below
2252 gst_ffmpeg_caps_to_smpfmt (const GstCaps * caps,
2253 AVCodecContext * context, gboolean raw)
2255 GstStructure *structure;
2257 GstAudioFormat format = GST_AUDIO_FORMAT_UNKNOWN;
2259 g_return_if_fail (gst_caps_get_size (caps) == 1);
2261 structure = gst_caps_get_structure (caps, 0);
2263 gst_structure_get_int (structure, "channels", &context->channels);
2264 gst_structure_get_int (structure, "rate", &context->sample_rate);
2265 gst_structure_get_int (structure, "block_align", &context->block_align);
2266 gst_structure_get_int (structure, "bitrate", &context->bit_rate);
2271 if (gst_structure_has_name (structure, "audio/x-raw")) {
2272 if ((fmt = gst_structure_get_string (structure, "format"))) {
2273 format = gst_audio_format_from_string (fmt);
2278 case GST_AUDIO_FORMAT_F32:
2279 context->sample_fmt = AV_SAMPLE_FMT_FLT;
2281 case GST_AUDIO_FORMAT_F64:
2282 context->sample_fmt = AV_SAMPLE_FMT_DBL;
2284 case GST_AUDIO_FORMAT_S32:
2285 context->sample_fmt = AV_SAMPLE_FMT_S32;
2287 case GST_AUDIO_FORMAT_S16:
2288 context->sample_fmt = AV_SAMPLE_FMT_S16;
2295 /* Convert a GstCaps (video/raw) to a FFMPEG PixFmt
2296 * and other video properties in a AVCodecContext.
2298 * For usefullness, see below
2302 gst_ffmpeg_caps_to_pixfmt (const GstCaps * caps,
2303 AVCodecContext * context, gboolean raw)
2305 GstStructure *structure;
2307 const GValue *par = NULL;
2309 GstVideoFormat format = GST_VIDEO_FORMAT_UNKNOWN;
2311 GST_DEBUG ("converting caps %" GST_PTR_FORMAT, caps);
2312 g_return_if_fail (gst_caps_get_size (caps) == 1);
2313 structure = gst_caps_get_structure (caps, 0);
2315 gst_structure_get_int (structure, "width", &context->width);
2316 gst_structure_get_int (structure, "height", &context->height);
2317 gst_structure_get_int (structure, "bpp", &context->bits_per_coded_sample);
2319 fps = gst_structure_get_value (structure, "framerate");
2320 if (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps)) {
2322 /* somehow these seem mixed up.. */
2323 context->time_base.den = gst_value_get_fraction_numerator (fps);
2324 context->time_base.num = gst_value_get_fraction_denominator (fps);
2325 context->ticks_per_frame = 1;
2327 GST_DEBUG ("setting framerate %d/%d = %lf",
2328 context->time_base.den, context->time_base.num,
2329 1. * context->time_base.den / context->time_base.num);
2332 par = gst_structure_get_value (structure, "pixel-aspect-ratio");
2333 if (par && GST_VALUE_HOLDS_FRACTION (par)) {
2335 context->sample_aspect_ratio.num = gst_value_get_fraction_numerator (par);
2336 context->sample_aspect_ratio.den = gst_value_get_fraction_denominator (par);
2338 GST_DEBUG ("setting pixel-aspect-ratio %d/%d = %lf",
2339 context->sample_aspect_ratio.den, context->sample_aspect_ratio.num,
2340 1. * context->sample_aspect_ratio.den /
2341 context->sample_aspect_ratio.num);
2347 g_return_if_fail (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps));
2349 if (gst_structure_has_name (structure, "video/x-raw")) {
2350 if ((fmt = gst_structure_get_string (structure, "format"))) {
2351 format = gst_video_format_from_string (fmt);
2356 case GST_VIDEO_FORMAT_YUY2:
2357 context->pix_fmt = PIX_FMT_YUYV422;
2359 case GST_VIDEO_FORMAT_I420:
2360 context->pix_fmt = PIX_FMT_YUV420P;
2362 case GST_VIDEO_FORMAT_A420:
2363 context->pix_fmt = PIX_FMT_YUVA420P;
2365 case GST_VIDEO_FORMAT_Y41B:
2366 context->pix_fmt = PIX_FMT_YUV411P;
2368 case GST_VIDEO_FORMAT_Y42B:
2369 context->pix_fmt = PIX_FMT_YUV422P;
2371 case GST_VIDEO_FORMAT_YUV9:
2372 context->pix_fmt = PIX_FMT_YUV410P;
2374 case GST_VIDEO_FORMAT_Y444:
2375 context->pix_fmt = PIX_FMT_YUV444P;
2377 case GST_VIDEO_FORMAT_GRAY8:
2378 context->pix_fmt = PIX_FMT_GRAY8;
2380 case GST_VIDEO_FORMAT_xRGB:
2381 #if (G_BYTE_ORDER == G_BIG_ENDIAN)
2382 context->pix_fmt = PIX_FMT_RGB32;
2385 case GST_VIDEO_FORMAT_BGRx:
2386 #if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
2387 context->pix_fmt = PIX_FMT_RGB32;
2390 case GST_VIDEO_FORMAT_RGB:
2391 context->pix_fmt = PIX_FMT_RGB24;
2393 case GST_VIDEO_FORMAT_BGR:
2394 context->pix_fmt = PIX_FMT_BGR24;
2396 case GST_VIDEO_FORMAT_RGB16:
2397 context->pix_fmt = PIX_FMT_RGB565;
2399 case GST_VIDEO_FORMAT_RGB15:
2400 context->pix_fmt = PIX_FMT_RGB555;
2402 case GST_VIDEO_FORMAT_RGB8P:
2403 context->pix_fmt = PIX_FMT_PAL8;
2412 GstVideoFormat format;
2413 enum PixelFormat pixfmt;
2416 /* FIXME : FILLME */
2417 static const PixToFmt pixtofmttable[] = {
2418 /* GST_VIDEO_FORMAT_I420, */
2419 {GST_VIDEO_FORMAT_I420, PIX_FMT_YUV420P},
2420 /* Note : this should use a different chroma placement */
2421 {GST_VIDEO_FORMAT_I420, PIX_FMT_YUVJ420P},
2423 /* GST_VIDEO_FORMAT_YV12, */
2424 /* GST_VIDEO_FORMAT_YUY2, */
2425 {GST_VIDEO_FORMAT_YUY2, PIX_FMT_YUYV422},
2426 /* GST_VIDEO_FORMAT_UYVY, */
2427 {GST_VIDEO_FORMAT_UYVY, PIX_FMT_UYVY422},
2428 /* GST_VIDEO_FORMAT_AYUV, */
2429 /* GST_VIDEO_FORMAT_RGBx, */
2430 /* GST_VIDEO_FORMAT_BGRx, */
2431 /* GST_VIDEO_FORMAT_xRGB, */
2432 /* GST_VIDEO_FORMAT_xBGR, */
2433 /* GST_VIDEO_FORMAT_RGBA, */
2434 {GST_VIDEO_FORMAT_RGBA, PIX_FMT_RGBA},
2435 /* GST_VIDEO_FORMAT_BGRA, */
2436 {GST_VIDEO_FORMAT_BGRA, PIX_FMT_BGRA},
2437 /* GST_VIDEO_FORMAT_ARGB, */
2438 {GST_VIDEO_FORMAT_ARGB, PIX_FMT_ARGB},
2439 /* GST_VIDEO_FORMAT_ABGR, */
2440 {GST_VIDEO_FORMAT_ABGR, PIX_FMT_ABGR},
2441 /* GST_VIDEO_FORMAT_RGB, */
2442 {GST_VIDEO_FORMAT_RGB, PIX_FMT_RGB24},
2443 /* GST_VIDEO_FORMAT_BGR, */
2444 {GST_VIDEO_FORMAT_BGR, PIX_FMT_BGR24},
2445 /* GST_VIDEO_FORMAT_Y41B, */
2446 {GST_VIDEO_FORMAT_Y41B, PIX_FMT_YUV411P},
2447 /* GST_VIDEO_FORMAT_Y42B, */
2448 {GST_VIDEO_FORMAT_Y42B, PIX_FMT_YUV422P},
2449 {GST_VIDEO_FORMAT_Y42B, PIX_FMT_YUVJ422P},
2450 /* GST_VIDEO_FORMAT_YVYU, */
2451 /* GST_VIDEO_FORMAT_Y444, */
2452 {GST_VIDEO_FORMAT_Y444, PIX_FMT_YUV444P},
2453 {GST_VIDEO_FORMAT_Y444, PIX_FMT_YUVJ444P},
2454 /* GST_VIDEO_FORMAT_v210, */
2455 /* GST_VIDEO_FORMAT_v216, */
2456 /* GST_VIDEO_FORMAT_NV12, */
2457 {GST_VIDEO_FORMAT_NV12, PIX_FMT_NV12},
2458 /* GST_VIDEO_FORMAT_NV21, */
2459 {GST_VIDEO_FORMAT_NV21, PIX_FMT_NV21},
2460 /* GST_VIDEO_FORMAT_GRAY8, */
2461 {GST_VIDEO_FORMAT_GRAY8, PIX_FMT_GRAY8},
2462 /* GST_VIDEO_FORMAT_GRAY16_BE, */
2463 {GST_VIDEO_FORMAT_GRAY16_BE, PIX_FMT_GRAY16BE},
2464 /* GST_VIDEO_FORMAT_GRAY16_LE, */
2465 {GST_VIDEO_FORMAT_GRAY16_LE, PIX_FMT_GRAY16LE},
2466 /* GST_VIDEO_FORMAT_v308, */
2467 /* GST_VIDEO_FORMAT_Y800, */
2468 /* GST_VIDEO_FORMAT_Y16, */
2469 /* GST_VIDEO_FORMAT_RGB16, */
2470 {GST_VIDEO_FORMAT_RGB16, PIX_FMT_RGB565},
2471 /* GST_VIDEO_FORMAT_BGR16, */
2472 /* GST_VIDEO_FORMAT_RGB15, */
2473 {GST_VIDEO_FORMAT_RGB15, PIX_FMT_RGB555},
2474 /* GST_VIDEO_FORMAT_BGR15, */
2475 /* GST_VIDEO_FORMAT_UYVP, */
2476 /* GST_VIDEO_FORMAT_A420, */
2477 {GST_VIDEO_FORMAT_A420, PIX_FMT_YUVA420P},
2478 /* GST_VIDEO_FORMAT_RGB8_PALETTED, */
2479 {GST_VIDEO_FORMAT_RGB8P, PIX_FMT_PAL8},
2480 /* GST_VIDEO_FORMAT_YUV9, */
2481 {GST_VIDEO_FORMAT_YUV9, PIX_FMT_YUV410P},
2482 /* GST_VIDEO_FORMAT_YVU9, */
2483 /* GST_VIDEO_FORMAT_IYU1, */
2484 /* GST_VIDEO_FORMAT_ARGB64, */
2485 /* GST_VIDEO_FORMAT_AYUV64, */
2486 /* GST_VIDEO_FORMAT_r210, */
2487 {GST_VIDEO_FORMAT_I420_10LE, PIX_FMT_YUV420P10LE},
2488 {GST_VIDEO_FORMAT_I420_10BE, PIX_FMT_YUV420P10BE},
2489 {GST_VIDEO_FORMAT_I422_10LE, PIX_FMT_YUV422P10LE},
2490 {GST_VIDEO_FORMAT_I422_10BE, PIX_FMT_YUV422P10BE},
2491 {GST_VIDEO_FORMAT_Y444_10LE, PIX_FMT_YUV444P10LE},
2492 {GST_VIDEO_FORMAT_Y444_10BE, PIX_FMT_YUV444P10BE},
2493 {GST_VIDEO_FORMAT_GBR, PIX_FMT_GBRP},
2494 {GST_VIDEO_FORMAT_GBR_10LE, PIX_FMT_GBRP10LE},
2495 {GST_VIDEO_FORMAT_GBR_10BE, PIX_FMT_GBRP10BE},
2499 gst_ffmpeg_pixfmt_to_videoformat (enum PixelFormat pixfmt)
2503 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2504 if (pixtofmttable[i].pixfmt == pixfmt)
2505 return pixtofmttable[i].format;
2507 GST_DEBUG ("Unknown pixel format %d", pixfmt);
2508 return GST_VIDEO_FORMAT_UNKNOWN;
2512 gst_ffmpeg_videoformat_to_pixfmt (GstVideoFormat format)
2516 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2517 if (pixtofmttable[i].format == format)
2518 return pixtofmttable[i].pixfmt;
2519 return PIX_FMT_NONE;
2523 gst_ffmpeg_videoinfo_to_context (GstVideoInfo * info, AVCodecContext * context)
2527 context->width = GST_VIDEO_INFO_WIDTH (info);
2528 context->height = GST_VIDEO_INFO_HEIGHT (info);
2529 for (i = 0; i < GST_VIDEO_INFO_N_COMPONENTS (info); i++)
2530 bpp += GST_VIDEO_INFO_COMP_DEPTH (info, i);
2531 context->bits_per_coded_sample = bpp;
2533 context->ticks_per_frame = 1;
2534 if (GST_VIDEO_INFO_FPS_N (info) == 0) {
2535 GST_DEBUG ("Using 25/1 framerate");
2536 context->time_base.den = 25;
2537 context->time_base.num = 1;
2539 context->time_base.den = GST_VIDEO_INFO_FPS_N (info);
2540 context->time_base.num = GST_VIDEO_INFO_FPS_D (info);
2543 context->sample_aspect_ratio.num = GST_VIDEO_INFO_PAR_N (info);
2544 context->sample_aspect_ratio.den = GST_VIDEO_INFO_PAR_D (info);
2547 gst_ffmpeg_videoformat_to_pixfmt (GST_VIDEO_INFO_FORMAT (info));
2551 gst_ffmpeg_audioinfo_to_context (GstAudioInfo * info, AVCodecContext * context)
2553 const AVCodec *codec;
2554 const enum AVSampleFormat *smpl_fmts;
2555 enum AVSampleFormat smpl_fmt = -1;
2557 context->channels = info->channels;
2558 context->sample_rate = info->rate;
2559 context->channel_layout =
2560 gst_ffmpeg_channel_positions_to_layout (info->position, info->channels);
2562 codec = context->codec;
2564 smpl_fmts = codec->sample_fmts;
2566 switch (info->finfo->format) {
2567 case GST_AUDIO_FORMAT_F32:
2569 while (*smpl_fmts != -1) {
2570 if (*smpl_fmts == AV_SAMPLE_FMT_FLT) {
2571 smpl_fmt = *smpl_fmts;
2573 } else if (*smpl_fmts == AV_SAMPLE_FMT_FLTP) {
2574 smpl_fmt = *smpl_fmts;
2580 smpl_fmt = AV_SAMPLE_FMT_FLT;
2583 case GST_AUDIO_FORMAT_F64:
2585 while (*smpl_fmts != -1) {
2586 if (*smpl_fmts == AV_SAMPLE_FMT_DBL) {
2587 smpl_fmt = *smpl_fmts;
2589 } else if (*smpl_fmts == AV_SAMPLE_FMT_DBLP) {
2590 smpl_fmt = *smpl_fmts;
2596 smpl_fmt = AV_SAMPLE_FMT_DBL;
2599 case GST_AUDIO_FORMAT_S32:
2601 while (*smpl_fmts != -1) {
2602 if (*smpl_fmts == AV_SAMPLE_FMT_S32) {
2603 smpl_fmt = *smpl_fmts;
2605 } else if (*smpl_fmts == AV_SAMPLE_FMT_S32P) {
2606 smpl_fmt = *smpl_fmts;
2612 smpl_fmt = AV_SAMPLE_FMT_S32;
2615 case GST_AUDIO_FORMAT_S16:
2617 while (*smpl_fmts != -1) {
2618 if (*smpl_fmts == AV_SAMPLE_FMT_S16) {
2619 smpl_fmt = *smpl_fmts;
2621 } else if (*smpl_fmts == AV_SAMPLE_FMT_S16P) {
2622 smpl_fmt = *smpl_fmts;
2628 smpl_fmt = AV_SAMPLE_FMT_S16;
2631 case GST_AUDIO_FORMAT_U8:
2633 while (*smpl_fmts != -1) {
2634 if (*smpl_fmts == AV_SAMPLE_FMT_U8) {
2635 smpl_fmt = *smpl_fmts;
2637 } else if (*smpl_fmts == AV_SAMPLE_FMT_U8P) {
2638 smpl_fmt = *smpl_fmts;
2644 smpl_fmt = AV_SAMPLE_FMT_U8;
2651 g_assert (smpl_fmt != -1);
2653 context->sample_fmt = smpl_fmt;
2656 /* Convert a GstCaps and a FFMPEG codec Type to a
2657 * AVCodecContext. If the context is ommitted, no fixed values
2658 * for video/audio size will be included in the context
2660 * AVMediaType is primarily meant for uncompressed data GstCaps!
2664 gst_ffmpeg_caps_with_codectype (enum AVMediaType type,
2665 const GstCaps * caps, AVCodecContext * context)
2667 if (context == NULL)
2671 case AVMEDIA_TYPE_VIDEO:
2672 gst_ffmpeg_caps_to_pixfmt (caps, context, TRUE);
2675 case AVMEDIA_TYPE_AUDIO:
2676 gst_ffmpeg_caps_to_smpfmt (caps, context, TRUE);
2687 nal_escape (guint8 * dst, guint8 * src, guint size, guint * destsize)
2691 guint8 *end = src + size;
2694 while (srcp < end) {
2695 if (count == 2 && *srcp <= 0x03) {
2696 GST_DEBUG ("added escape code");
2705 GST_DEBUG ("copy %02x, count %d", *srcp, count);
2708 *destsize = dstp - dst;
2711 /* copy the config, escaping NAL units as we iterate them, if something fails we
2712 * copy everything and hope for the best. */
2714 copy_config (guint8 * dst, guint8 * src, guint size, guint * destsize)
2719 guint nalsize, esize;
2729 cnt = *(srcp + 5) & 0x1f; /* Number of sps */
2731 GST_DEBUG ("num SPS %d", cnt);
2733 memcpy (dstp, srcp, 6);
2737 for (i = 0; i < cnt; i++) {
2738 GST_DEBUG ("copy SPS %d", i);
2739 nalsize = (srcp[0] << 8) | srcp[1];
2740 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2741 dstp[0] = esize >> 8;
2742 dstp[1] = esize & 0xff;
2744 srcp += nalsize + 2;
2747 cnt = *(dstp++) = *(srcp++); /* Number of pps */
2749 GST_DEBUG ("num PPS %d", cnt);
2751 for (i = 0; i < cnt; i++) {
2752 GST_DEBUG ("copy PPS %d", i);
2753 nalsize = (srcp[0] << 8) | srcp[1];
2754 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2755 dstp[0] = esize >> 8;
2756 dstp[1] = esize & 0xff;
2758 srcp += nalsize + 2;
2760 *destsize = dstp - dst;
2766 GST_DEBUG ("something unexpected, doing full copy");
2767 memcpy (dst, src, size);
2775 * caps_with_codecid () transforms a GstCaps for a known codec
2776 * ID into a filled-in context.
2777 * codec_data from caps will override possible extradata already in the context
2781 gst_ffmpeg_caps_with_codecid (enum CodecID codec_id,
2782 enum AVMediaType codec_type, const GstCaps * caps, AVCodecContext * context)
2785 const GValue *value;
2788 GST_LOG ("codec_id:%d, codec_type:%d, caps:%" GST_PTR_FORMAT " context:%p",
2789 codec_id, codec_type, caps, context);
2791 if (!context || !gst_caps_get_size (caps))
2794 str = gst_caps_get_structure (caps, 0);
2796 /* extradata parsing (esds [mpeg4], wma/wmv, msmpeg4v1/2/3, etc.) */
2797 if ((value = gst_structure_get_value (str, "codec_data"))) {
2800 buf = gst_value_get_buffer (value);
2801 gst_buffer_map (buf, &map, GST_MAP_READ);
2803 /* free the old one if it is there */
2804 if (context->extradata)
2805 av_free (context->extradata);
2808 if (codec_id == AV_CODEC_ID_H264) {
2811 GST_DEBUG ("copy, escaping codec_data %d", size);
2812 /* ffmpeg h264 expects the codec_data to be escaped, there is no real
2813 * reason for this but let's just escape it for now. Start by allocating
2814 * enough space, x2 is more than enough.
2816 * FIXME, we disabled escaping because some file already contain escaped
2817 * codec_data and then we escape twice and fail. It's better to leave it
2818 * as is, as that is what most players do. */
2819 context->extradata =
2820 av_mallocz (GST_ROUND_UP_16 (size * 2 +
2821 FF_INPUT_BUFFER_PADDING_SIZE));
2822 copy_config (context->extradata, data, size, &extrasize);
2823 GST_DEBUG ("escaped size: %d", extrasize);
2824 context->extradata_size = extrasize;
2828 /* allocate with enough padding */
2829 GST_DEBUG ("copy codec_data");
2830 context->extradata =
2831 av_mallocz (GST_ROUND_UP_16 (map.size +
2832 FF_INPUT_BUFFER_PADDING_SIZE));
2833 memcpy (context->extradata, map.data, map.size);
2834 context->extradata_size = map.size;
2837 /* Hack for VC1. Sometimes the first (length) byte is 0 for some files */
2838 if (codec_id == AV_CODEC_ID_VC1 && map.size > 0 && map.data[0] == 0) {
2839 context->extradata[0] = (guint8) map.size;
2842 GST_DEBUG ("have codec data of size %" G_GSIZE_FORMAT, map.size);
2844 gst_buffer_unmap (buf, &map);
2845 } else if (context->extradata == NULL && codec_id != AV_CODEC_ID_AAC_LATM &&
2846 codec_id != AV_CODEC_ID_FLAC) {
2847 /* no extradata, alloc dummy with 0 sized, some codecs insist on reading
2848 * extradata anyway which makes then segfault. */
2849 context->extradata =
2850 av_mallocz (GST_ROUND_UP_16 (FF_INPUT_BUFFER_PADDING_SIZE));
2851 context->extradata_size = 0;
2852 GST_DEBUG ("no codec data");
2856 case AV_CODEC_ID_MPEG4:
2858 const gchar *mime = gst_structure_get_name (str);
2860 if (!strcmp (mime, "video/x-divx"))
2861 context->codec_tag = GST_MAKE_FOURCC ('D', 'I', 'V', 'X');
2862 else if (!strcmp (mime, "video/x-xvid"))
2863 context->codec_tag = GST_MAKE_FOURCC ('X', 'V', 'I', 'D');
2864 else if (!strcmp (mime, "video/x-3ivx"))
2865 context->codec_tag = GST_MAKE_FOURCC ('3', 'I', 'V', '1');
2866 else if (!strcmp (mime, "video/mpeg"))
2867 context->codec_tag = GST_MAKE_FOURCC ('m', 'p', '4', 'v');
2871 case AV_CODEC_ID_SVQ3:
2872 /* FIXME: this is a workaround for older gst-plugins releases
2873 * (<= 0.8.9). This should be removed at some point, because
2874 * it causes wrong decoded frame order. */
2875 if (!context->extradata) {
2876 gint halfpel_flag, thirdpel_flag, low_delay, unknown_svq3_flag;
2879 if (gst_structure_get_int (str, "halfpel_flag", &halfpel_flag) &&
2880 gst_structure_get_int (str, "thirdpel_flag", &thirdpel_flag) &&
2881 gst_structure_get_int (str, "low_delay", &low_delay) &&
2882 gst_structure_get_int (str, "unknown_svq3_flag",
2883 &unknown_svq3_flag)) {
2884 context->extradata = (guint8 *) av_mallocz (0x64);
2885 g_stpcpy ((gchar *) context->extradata, "SVQ3");
2889 flags |= unknown_svq3_flag;
2891 flags |= halfpel_flag;
2893 flags |= thirdpel_flag;
2896 flags = GUINT16_FROM_LE (flags);
2898 memcpy ((gchar *) context->extradata + 0x62, &flags, 2);
2899 context->extradata_size = 0x64;
2904 case AV_CODEC_ID_MSRLE:
2905 case AV_CODEC_ID_QTRLE:
2906 case AV_CODEC_ID_TSCC:
2907 case AV_CODEC_ID_CSCD:
2908 case AV_CODEC_ID_APE:
2912 if (gst_structure_get_int (str, "depth", &depth)) {
2913 context->bits_per_coded_sample = depth;
2915 GST_WARNING ("No depth field in caps %" GST_PTR_FORMAT, caps);
2921 case AV_CODEC_ID_RV10:
2922 case AV_CODEC_ID_RV20:
2923 case AV_CODEC_ID_RV30:
2924 case AV_CODEC_ID_RV40:
2928 if (gst_structure_get_int (str, "format", &format))
2929 context->sub_id = format;
2933 case AV_CODEC_ID_COOK:
2934 case AV_CODEC_ID_RA_288:
2935 case AV_CODEC_ID_RA_144:
2936 case AV_CODEC_ID_SIPR:
2941 if (gst_structure_get_int (str, "leaf_size", &leaf_size))
2942 context->block_align = leaf_size;
2943 if (gst_structure_get_int (str, "bitrate", &bitrate))
2944 context->bit_rate = bitrate;
2946 case AV_CODEC_ID_ALAC:
2947 gst_structure_get_int (str, "samplesize",
2948 &context->bits_per_coded_sample);
2951 case AV_CODEC_ID_DVVIDEO:
2953 const gchar *format;
2955 if ((format = gst_structure_get_string (str, "format"))) {
2957 if (g_str_equal (format, "YUY2"))
2958 context->pix_fmt = PIX_FMT_YUYV422;
2959 else if (g_str_equal (format, "I420"))
2960 context->pix_fmt = PIX_FMT_YUV420P;
2961 else if (g_str_equal (format, "A420"))
2962 context->pix_fmt = PIX_FMT_YUVA420P;
2963 else if (g_str_equal (format, "Y41B"))
2964 context->pix_fmt = PIX_FMT_YUV411P;
2965 else if (g_str_equal (format, "Y42B"))
2966 context->pix_fmt = PIX_FMT_YUV422P;
2967 else if (g_str_equal (format, "YUV9"))
2968 context->pix_fmt = PIX_FMT_YUV410P;
2970 GST_WARNING ("couldn't convert format %s" " to a pixel format",
2974 GST_WARNING ("No specified format");
2977 case AV_CODEC_ID_H263P:
2981 if (!gst_structure_get_boolean (str, "annex-f", &val) || val)
2982 context->flags |= CODEC_FLAG_4MV;
2984 context->flags &= ~CODEC_FLAG_4MV;
2985 if ((!gst_structure_get_boolean (str, "annex-i", &val) || val) &&
2986 (!gst_structure_get_boolean (str, "annex-t", &val) || val))
2987 context->flags |= CODEC_FLAG_AC_PRED;
2989 context->flags &= ~CODEC_FLAG_AC_PRED;
2990 if (!gst_structure_get_boolean (str, "annex-j", &val) || val)
2991 context->flags |= CODEC_FLAG_LOOP_FILTER;
2993 context->flags &= ~CODEC_FLAG_LOOP_FILTER;
2996 case AV_CODEC_ID_ADPCM_G726:
2998 const gchar *layout;
3000 if ((layout = gst_structure_get_string (str, "layout"))) {
3001 if (!strcmp (layout, "g721")) {
3002 context->sample_rate = 8000;
3003 context->channels = 1;
3004 context->bit_rate = 32000;
3013 if (!gst_caps_is_fixed (caps))
3016 /* common properties (width, height, fps) */
3017 switch (codec_type) {
3018 case AVMEDIA_TYPE_VIDEO:
3019 gst_ffmpeg_caps_to_pixfmt (caps, context,
3020 codec_id == AV_CODEC_ID_RAWVIDEO);
3022 case AVMEDIA_TYPE_AUDIO:
3023 gst_ffmpeg_caps_to_smpfmt (caps, context, FALSE);
3029 /* fixup of default settings */
3031 case AV_CODEC_ID_QCELP:
3032 /* QCELP is always mono, no matter what the caps say */
3033 context->channels = 1;
3035 case AV_CODEC_ID_ADPCM_G726:
3036 if (context->sample_rate && context->bit_rate)
3037 context->bits_per_coded_sample =
3038 context->bit_rate / context->sample_rate;
3045 /* _formatid_to_caps () is meant for muxers/demuxers, it
3046 * transforms a name (ffmpeg way of ID'ing these, why don't
3047 * they have unique numerical IDs?) to the corresponding
3048 * caps belonging to that mux-format
3050 * Note: we don't need any additional info because the caps
3051 * isn't supposed to contain any useful info besides the
3056 gst_ffmpeg_formatid_to_caps (const gchar * format_name)
3058 GstCaps *caps = NULL;
3060 if (!strcmp (format_name, "mpeg")) {
3061 caps = gst_caps_new_simple ("video/mpeg",
3062 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3063 } else if (!strcmp (format_name, "mpegts")) {
3064 caps = gst_caps_new_simple ("video/mpegts",
3065 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3066 } else if (!strcmp (format_name, "rm")) {
3067 caps = gst_caps_new_simple ("application/x-pn-realmedia",
3068 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3069 } else if (!strcmp (format_name, "asf")) {
3070 caps = gst_caps_new_empty_simple ("video/x-ms-asf");
3071 } else if (!strcmp (format_name, "avi")) {
3072 caps = gst_caps_new_empty_simple ("video/x-msvideo");
3073 } else if (!strcmp (format_name, "wav")) {
3074 caps = gst_caps_new_empty_simple ("audio/x-wav");
3075 } else if (!strcmp (format_name, "ape")) {
3076 caps = gst_caps_new_empty_simple ("application/x-ape");
3077 } else if (!strcmp (format_name, "swf")) {
3078 caps = gst_caps_new_empty_simple ("application/x-shockwave-flash");
3079 } else if (!strcmp (format_name, "au")) {
3080 caps = gst_caps_new_empty_simple ("audio/x-au");
3081 } else if (!strcmp (format_name, "dv")) {
3082 caps = gst_caps_new_simple ("video/x-dv",
3083 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3084 } else if (!strcmp (format_name, "4xm")) {
3085 caps = gst_caps_new_empty_simple ("video/x-4xm");
3086 } else if (!strcmp (format_name, "matroska")) {
3087 caps = gst_caps_new_empty_simple ("video/x-matroska");
3088 } else if (!strcmp (format_name, "mp3")) {
3089 caps = gst_caps_new_empty_simple ("application/x-id3");
3090 } else if (!strcmp (format_name, "flic")) {
3091 caps = gst_caps_new_empty_simple ("video/x-fli");
3092 } else if (!strcmp (format_name, "flv")) {
3093 caps = gst_caps_new_empty_simple ("video/x-flv");
3094 } else if (!strcmp (format_name, "tta")) {
3095 caps = gst_caps_new_empty_simple ("audio/x-ttafile");
3096 } else if (!strcmp (format_name, "aiff")) {
3097 caps = gst_caps_new_empty_simple ("audio/x-aiff");
3098 } else if (!strcmp (format_name, "mov_mp4_m4a_3gp_3g2")) {
3100 gst_caps_from_string
3101 ("application/x-3gp; video/quicktime; audio/x-m4a");
3102 } else if (!strcmp (format_name, "mov")) {
3103 caps = gst_caps_from_string ("video/quicktime,variant=(string)apple");
3104 } else if (!strcmp (format_name, "mp4")) {
3105 caps = gst_caps_from_string ("video/quicktime,variant=(string)iso");
3106 } else if (!strcmp (format_name, "3gp")) {
3107 caps = gst_caps_from_string ("video/quicktime,variant=(string)3gpp");
3108 } else if (!strcmp (format_name, "3g2")) {
3109 caps = gst_caps_from_string ("video/quicktime,variant=(string)3g2");
3110 } else if (!strcmp (format_name, "psp")) {
3111 caps = gst_caps_from_string ("video/quicktime,variant=(string)psp");
3112 } else if (!strcmp (format_name, "ipod")) {
3113 caps = gst_caps_from_string ("video/quicktime,variant=(string)ipod");
3114 } else if (!strcmp (format_name, "aac")) {
3115 caps = gst_caps_new_simple ("audio/mpeg",
3116 "mpegversion", G_TYPE_INT, 4, NULL);
3117 } else if (!strcmp (format_name, "gif")) {
3118 caps = gst_caps_from_string ("image/gif");
3119 } else if (!strcmp (format_name, "ogg")) {
3120 caps = gst_caps_from_string ("application/ogg");
3121 } else if (!strcmp (format_name, "mxf") || !strcmp (format_name, "mxf_d10")) {
3122 caps = gst_caps_from_string ("application/mxf");
3123 } else if (!strcmp (format_name, "gxf")) {
3124 caps = gst_caps_from_string ("application/gxf");
3125 } else if (!strcmp (format_name, "yuv4mpegpipe")) {
3126 caps = gst_caps_new_simple ("application/x-yuv4mpeg",
3127 "y4mversion", G_TYPE_INT, 2, NULL);
3128 } else if (!strcmp (format_name, "mpc")) {
3129 caps = gst_caps_from_string ("audio/x-musepack, streamversion = (int) 7");
3130 } else if (!strcmp (format_name, "vqf")) {
3131 caps = gst_caps_from_string ("audio/x-vqf");
3132 } else if (!strcmp (format_name, "nsv")) {
3133 caps = gst_caps_from_string ("video/x-nsv");
3134 } else if (!strcmp (format_name, "amr")) {
3135 caps = gst_caps_from_string ("audio/x-amr-nb-sh");
3136 } else if (!strcmp (format_name, "webm")) {
3137 caps = gst_caps_from_string ("video/webm");
3138 } else if (!strcmp (format_name, "voc")) {
3139 caps = gst_caps_from_string ("audio/x-voc");
3140 } else if (!strcmp (format_name, "pva")) {
3141 caps = gst_caps_from_string ("video/x-pva");
3145 GST_LOG ("Could not create stream format caps for %s", format_name);
3146 name = g_strdup_printf ("application/x-gst-av-%s", format_name);
3147 caps = gst_caps_new_empty_simple (name);
3155 gst_ffmpeg_formatid_get_codecids (const gchar * format_name,
3156 enum CodecID ** video_codec_list, enum CodecID ** audio_codec_list,
3157 AVOutputFormat * plugin)
3159 static enum CodecID tmp_vlist[] = {
3163 static enum CodecID tmp_alist[] = {
3168 GST_LOG ("format_name : %s", format_name);
3170 if (!strcmp (format_name, "mp4")) {
3171 static enum CodecID mp4_video_list[] = {
3172 AV_CODEC_ID_MPEG4, AV_CODEC_ID_H264,
3176 static enum CodecID mp4_audio_list[] = {
3177 AV_CODEC_ID_AAC, AV_CODEC_ID_MP3,
3181 *video_codec_list = mp4_video_list;
3182 *audio_codec_list = mp4_audio_list;
3183 } else if (!strcmp (format_name, "mpeg")) {
3184 static enum CodecID mpeg_video_list[] = { AV_CODEC_ID_MPEG1VIDEO,
3185 AV_CODEC_ID_MPEG2VIDEO,
3189 static enum CodecID mpeg_audio_list[] = { AV_CODEC_ID_MP1,
3195 *video_codec_list = mpeg_video_list;
3196 *audio_codec_list = mpeg_audio_list;
3197 } else if (!strcmp (format_name, "dvd")) {
3198 static enum CodecID mpeg_video_list[] = { AV_CODEC_ID_MPEG2VIDEO,
3201 static enum CodecID mpeg_audio_list[] = { AV_CODEC_ID_MP2,
3204 AV_CODEC_ID_PCM_S16BE,
3208 *video_codec_list = mpeg_video_list;
3209 *audio_codec_list = mpeg_audio_list;
3210 } else if (!strcmp (format_name, "mpegts")) {
3211 static enum CodecID mpegts_video_list[] = { AV_CODEC_ID_MPEG1VIDEO,
3212 AV_CODEC_ID_MPEG2VIDEO,
3216 static enum CodecID mpegts_audio_list[] = { AV_CODEC_ID_MP2,
3224 *video_codec_list = mpegts_video_list;
3225 *audio_codec_list = mpegts_audio_list;
3226 } else if (!strcmp (format_name, "vob")) {
3227 static enum CodecID vob_video_list[] =
3228 { AV_CODEC_ID_MPEG2VIDEO, AV_CODEC_ID_NONE };
3229 static enum CodecID vob_audio_list[] = { AV_CODEC_ID_MP2, AV_CODEC_ID_AC3,
3230 AV_CODEC_ID_DTS, AV_CODEC_ID_NONE
3233 *video_codec_list = vob_video_list;
3234 *audio_codec_list = vob_audio_list;
3235 } else if (!strcmp (format_name, "flv")) {
3236 static enum CodecID flv_video_list[] =
3237 { AV_CODEC_ID_FLV1, AV_CODEC_ID_NONE };
3238 static enum CodecID flv_audio_list[] =
3239 { AV_CODEC_ID_MP3, AV_CODEC_ID_NONE };
3241 *video_codec_list = flv_video_list;
3242 *audio_codec_list = flv_audio_list;
3243 } else if (!strcmp (format_name, "asf")) {
3244 static enum CodecID asf_video_list[] =
3245 { AV_CODEC_ID_WMV1, AV_CODEC_ID_WMV2, AV_CODEC_ID_MSMPEG4V3,
3248 static enum CodecID asf_audio_list[] =
3249 { AV_CODEC_ID_WMAV1, AV_CODEC_ID_WMAV2, AV_CODEC_ID_MP3,
3253 *video_codec_list = asf_video_list;
3254 *audio_codec_list = asf_audio_list;
3255 } else if (!strcmp (format_name, "dv")) {
3256 static enum CodecID dv_video_list[] =
3257 { AV_CODEC_ID_DVVIDEO, AV_CODEC_ID_NONE };
3258 static enum CodecID dv_audio_list[] =
3259 { AV_CODEC_ID_PCM_S16LE, AV_CODEC_ID_NONE };
3261 *video_codec_list = dv_video_list;
3262 *audio_codec_list = dv_audio_list;
3263 } else if (!strcmp (format_name, "mov")) {
3264 static enum CodecID mov_video_list[] = {
3265 AV_CODEC_ID_SVQ1, AV_CODEC_ID_SVQ3, AV_CODEC_ID_MPEG4,
3266 AV_CODEC_ID_H263, AV_CODEC_ID_H263P,
3267 AV_CODEC_ID_H264, AV_CODEC_ID_DVVIDEO,
3271 static enum CodecID mov_audio_list[] = {
3272 AV_CODEC_ID_PCM_MULAW, AV_CODEC_ID_PCM_ALAW, AV_CODEC_ID_ADPCM_IMA_QT,
3273 AV_CODEC_ID_MACE3, AV_CODEC_ID_MACE6, AV_CODEC_ID_AAC,
3274 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3275 AV_CODEC_ID_PCM_S16BE, AV_CODEC_ID_PCM_S16LE,
3276 AV_CODEC_ID_MP3, AV_CODEC_ID_NONE
3279 *video_codec_list = mov_video_list;
3280 *audio_codec_list = mov_audio_list;
3281 } else if ((!strcmp (format_name, "3gp") || !strcmp (format_name, "3g2"))) {
3282 static enum CodecID tgp_video_list[] = {
3283 AV_CODEC_ID_MPEG4, AV_CODEC_ID_H263, AV_CODEC_ID_H263P, AV_CODEC_ID_H264,
3286 static enum CodecID tgp_audio_list[] = {
3287 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3292 *video_codec_list = tgp_video_list;
3293 *audio_codec_list = tgp_audio_list;
3294 } else if (!strcmp (format_name, "mmf")) {
3295 static enum CodecID mmf_audio_list[] = {
3296 AV_CODEC_ID_ADPCM_YAMAHA, AV_CODEC_ID_NONE
3298 *video_codec_list = NULL;
3299 *audio_codec_list = mmf_audio_list;
3300 } else if (!strcmp (format_name, "amr")) {
3301 static enum CodecID amr_audio_list[] = {
3302 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3305 *video_codec_list = NULL;
3306 *audio_codec_list = amr_audio_list;
3307 } else if (!strcmp (format_name, "gif")) {
3308 static enum CodecID gif_image_list[] = {
3309 AV_CODEC_ID_RAWVIDEO, AV_CODEC_ID_NONE
3311 *video_codec_list = gif_image_list;
3312 *audio_codec_list = NULL;
3313 } else if ((plugin->audio_codec != AV_CODEC_ID_NONE) ||
3314 (plugin->video_codec != AV_CODEC_ID_NONE)) {
3315 tmp_vlist[0] = plugin->video_codec;
3316 tmp_alist[0] = plugin->audio_codec;
3318 *video_codec_list = tmp_vlist;
3319 *audio_codec_list = tmp_alist;
3320 } else if ((!strcmp (format_name, "pva"))) {
3321 static enum CodecID tgp_video_list[] = {
3322 AV_CODEC_ID_MPEG2VIDEO,
3325 static enum CodecID tgp_audio_list[] = {
3330 *video_codec_list = tgp_video_list;
3331 *audio_codec_list = tgp_audio_list;
3333 GST_LOG ("Format %s not found", format_name);
3340 /* Convert a GstCaps to a FFMPEG codec ID. Size et all
3341 * are omitted, that can be queried by the user itself,
3342 * we're not eating the GstCaps or anything
3343 * A pointer to an allocated context is also needed for
3344 * optional extra info
3348 gst_ffmpeg_caps_to_codecid (const GstCaps * caps, AVCodecContext * context)
3350 enum CodecID id = AV_CODEC_ID_NONE;
3351 const gchar *mimetype;
3352 const GstStructure *structure;
3353 gboolean video = FALSE, audio = FALSE; /* we want to be sure! */
3355 g_return_val_if_fail (caps != NULL, AV_CODEC_ID_NONE);
3356 g_return_val_if_fail (gst_caps_get_size (caps) == 1, AV_CODEC_ID_NONE);
3357 structure = gst_caps_get_structure (caps, 0);
3359 mimetype = gst_structure_get_name (structure);
3361 if (!strcmp (mimetype, "video/x-raw")) {
3362 id = AV_CODEC_ID_RAWVIDEO;
3364 } else if (!strcmp (mimetype, "audio/x-raw")) {
3367 if (gst_audio_info_from_caps (&info, caps)) {
3368 switch (GST_AUDIO_INFO_FORMAT (&info)) {
3369 case GST_AUDIO_FORMAT_S8:
3370 id = AV_CODEC_ID_PCM_S8;
3372 case GST_AUDIO_FORMAT_U8:
3373 id = AV_CODEC_ID_PCM_U8;
3375 case GST_AUDIO_FORMAT_S16LE:
3376 id = AV_CODEC_ID_PCM_S16LE;
3378 case GST_AUDIO_FORMAT_S16BE:
3379 id = AV_CODEC_ID_PCM_S16BE;
3381 case GST_AUDIO_FORMAT_U16LE:
3382 id = AV_CODEC_ID_PCM_U16LE;
3384 case GST_AUDIO_FORMAT_U16BE:
3385 id = AV_CODEC_ID_PCM_U16BE;
3390 if (id != AV_CODEC_ID_NONE)
3393 } else if (!strcmp (mimetype, "audio/x-mulaw")) {
3394 id = AV_CODEC_ID_PCM_MULAW;
3396 } else if (!strcmp (mimetype, "audio/x-alaw")) {
3397 id = AV_CODEC_ID_PCM_ALAW;
3399 } else if (!strcmp (mimetype, "video/x-dv")) {
3402 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3404 id = AV_CODEC_ID_DVVIDEO;
3407 } else if (!strcmp (mimetype, "audio/x-dv")) { /* ??? */
3408 id = AV_CODEC_ID_DVAUDIO;
3410 } else if (!strcmp (mimetype, "video/x-h263")) {
3411 const gchar *h263version =
3412 gst_structure_get_string (structure, "h263version");
3413 if (h263version && !strcmp (h263version, "h263p"))
3414 id = AV_CODEC_ID_H263P;
3416 id = AV_CODEC_ID_H263;
3418 } else if (!strcmp (mimetype, "video/x-intel-h263")) {
3419 id = AV_CODEC_ID_H263I;
3421 } else if (!strcmp (mimetype, "video/x-h261")) {
3422 id = AV_CODEC_ID_H261;
3424 } else if (!strcmp (mimetype, "video/mpeg")) {
3428 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3429 gst_structure_get_int (structure, "mpegversion", &mpegversion) &&
3431 switch (mpegversion) {
3433 id = AV_CODEC_ID_MPEG1VIDEO;
3436 id = AV_CODEC_ID_MPEG2VIDEO;
3439 id = AV_CODEC_ID_MPEG4;
3443 if (id != AV_CODEC_ID_NONE)
3445 } else if (!strcmp (mimetype, "image/jpeg")) {
3446 id = AV_CODEC_ID_MJPEG; /* A... B... */
3448 } else if (!strcmp (mimetype, "video/x-jpeg-b")) {
3449 id = AV_CODEC_ID_MJPEGB;
3451 } else if (!strcmp (mimetype, "video/x-wmv")) {
3452 gint wmvversion = 0;
3454 if (gst_structure_get_int (structure, "wmvversion", &wmvversion)) {
3455 switch (wmvversion) {
3457 id = AV_CODEC_ID_WMV1;
3460 id = AV_CODEC_ID_WMV2;
3464 const gchar *format;
3466 /* WMV3 unless the fourcc exists and says otherwise */
3467 id = AV_CODEC_ID_WMV3;
3469 if ((format = gst_structure_get_string (structure, "format")) &&
3470 (g_str_equal (format, "WVC1") || g_str_equal (format, "WMVA")))
3471 id = AV_CODEC_ID_VC1;
3477 if (id != AV_CODEC_ID_NONE)
3479 } else if (!strcmp (mimetype, "audio/x-vorbis")) {
3480 id = AV_CODEC_ID_VORBIS;
3482 } else if (!strcmp (mimetype, "audio/x-qdm2")) {
3483 id = AV_CODEC_ID_QDM2;
3485 } else if (!strcmp (mimetype, "audio/mpeg")) {
3487 gint mpegversion = 0;
3489 if (gst_structure_get_int (structure, "mpegversion", &mpegversion)) {
3490 switch (mpegversion) {
3491 case 2: /* ffmpeg uses faad for both... */
3493 id = AV_CODEC_ID_AAC;
3496 if (gst_structure_get_int (structure, "layer", &layer)) {
3499 id = AV_CODEC_ID_MP1;
3502 id = AV_CODEC_ID_MP2;
3505 id = AV_CODEC_ID_MP3;
3511 if (id != AV_CODEC_ID_NONE)
3513 } else if (!strcmp (mimetype, "audio/x-musepack")) {
3514 gint streamversion = -1;
3516 if (gst_structure_get_int (structure, "streamversion", &streamversion)) {
3517 if (streamversion == 7)
3518 id = AV_CODEC_ID_MUSEPACK7;
3520 id = AV_CODEC_ID_MUSEPACK7;
3522 } else if (!strcmp (mimetype, "audio/x-wma")) {
3523 gint wmaversion = 0;
3525 if (gst_structure_get_int (structure, "wmaversion", &wmaversion)) {
3526 switch (wmaversion) {
3528 id = AV_CODEC_ID_WMAV1;
3531 id = AV_CODEC_ID_WMAV2;
3534 id = AV_CODEC_ID_WMAPRO;
3538 if (id != AV_CODEC_ID_NONE)
3540 } else if (!strcmp (mimetype, "audio/x-wms")) {
3541 id = AV_CODEC_ID_WMAVOICE;
3543 } else if (!strcmp (mimetype, "audio/x-ac3")) {
3544 id = AV_CODEC_ID_AC3;
3546 } else if (!strcmp (mimetype, "audio/x-eac3")) {
3547 id = AV_CODEC_ID_EAC3;
3549 } else if (!strcmp (mimetype, "audio/x-vnd.sony.atrac3") ||
3550 !strcmp (mimetype, "audio/atrac3")) {
3551 id = AV_CODEC_ID_ATRAC3;
3553 } else if (!strcmp (mimetype, "audio/x-dts")) {
3554 id = AV_CODEC_ID_DTS;
3556 } else if (!strcmp (mimetype, "application/x-ape")) {
3557 id = AV_CODEC_ID_APE;
3559 } else if (!strcmp (mimetype, "video/x-msmpeg")) {
3560 gint msmpegversion = 0;
3562 if (gst_structure_get_int (structure, "msmpegversion", &msmpegversion)) {
3563 switch (msmpegversion) {
3565 id = AV_CODEC_ID_MSMPEG4V1;
3568 id = AV_CODEC_ID_MSMPEG4V2;
3571 id = AV_CODEC_ID_MSMPEG4V3;
3575 if (id != AV_CODEC_ID_NONE)
3577 } else if (!strcmp (mimetype, "video/x-svq")) {
3578 gint svqversion = 0;
3580 if (gst_structure_get_int (structure, "svqversion", &svqversion)) {
3581 switch (svqversion) {
3583 id = AV_CODEC_ID_SVQ1;
3586 id = AV_CODEC_ID_SVQ3;
3590 if (id != AV_CODEC_ID_NONE)
3592 } else if (!strcmp (mimetype, "video/x-huffyuv")) {
3593 id = AV_CODEC_ID_HUFFYUV;
3595 } else if (!strcmp (mimetype, "audio/x-mace")) {
3596 gint maceversion = 0;
3598 if (gst_structure_get_int (structure, "maceversion", &maceversion)) {
3599 switch (maceversion) {
3601 id = AV_CODEC_ID_MACE3;
3604 id = AV_CODEC_ID_MACE6;
3608 if (id != AV_CODEC_ID_NONE)
3610 } else if (!strcmp (mimetype, "video/x-theora")) {
3611 id = AV_CODEC_ID_THEORA;
3613 } else if (!strcmp (mimetype, "video/x-vp3")) {
3614 id = AV_CODEC_ID_VP3;
3616 } else if (!strcmp (mimetype, "video/x-vp5")) {
3617 id = AV_CODEC_ID_VP5;
3619 } else if (!strcmp (mimetype, "video/x-vp6")) {
3620 id = AV_CODEC_ID_VP6;
3622 } else if (!strcmp (mimetype, "video/x-vp6-flash")) {
3623 id = AV_CODEC_ID_VP6F;
3625 } else if (!strcmp (mimetype, "video/x-vp6-alpha")) {
3626 id = AV_CODEC_ID_VP6A;
3628 } else if (!strcmp (mimetype, "video/x-vp8")) {
3629 id = AV_CODEC_ID_VP8;
3631 } else if (!strcmp (mimetype, "video/x-flash-screen")) {
3632 id = AV_CODEC_ID_FLASHSV;
3634 } else if (!strcmp (mimetype, "video/x-indeo")) {
3635 gint indeoversion = 0;
3637 if (gst_structure_get_int (structure, "indeoversion", &indeoversion)) {
3638 switch (indeoversion) {
3640 id = AV_CODEC_ID_INDEO5;
3643 id = AV_CODEC_ID_INDEO4;
3646 id = AV_CODEC_ID_INDEO3;
3649 id = AV_CODEC_ID_INDEO2;
3652 if (id != AV_CODEC_ID_NONE)
3655 } else if (!strcmp (mimetype, "video/x-divx")) {
3656 gint divxversion = 0;
3658 if (gst_structure_get_int (structure, "divxversion", &divxversion)) {
3659 switch (divxversion) {
3661 id = AV_CODEC_ID_MSMPEG4V3;
3665 id = AV_CODEC_ID_MPEG4;
3669 if (id != AV_CODEC_ID_NONE)
3671 } else if (!strcmp (mimetype, "video/x-3ivx")) {
3672 id = AV_CODEC_ID_MPEG4;
3674 } else if (!strcmp (mimetype, "video/x-xvid")) {
3675 id = AV_CODEC_ID_MPEG4;
3677 } else if (!strcmp (mimetype, "video/x-ffv")) {
3678 gint ffvversion = 0;
3680 if (gst_structure_get_int (structure, "ffvversion", &ffvversion) &&
3682 id = AV_CODEC_ID_FFV1;
3685 } else if (!strcmp (mimetype, "audio/x-adpcm")) {
3686 const gchar *layout;
3688 layout = gst_structure_get_string (structure, "layout");
3689 if (layout == NULL) {
3691 } else if (!strcmp (layout, "quicktime")) {
3692 id = AV_CODEC_ID_ADPCM_IMA_QT;
3693 } else if (!strcmp (layout, "microsoft")) {
3694 id = AV_CODEC_ID_ADPCM_MS;
3695 } else if (!strcmp (layout, "dvi")) {
3696 id = AV_CODEC_ID_ADPCM_IMA_WAV;
3697 } else if (!strcmp (layout, "4xm")) {
3698 id = AV_CODEC_ID_ADPCM_4XM;
3699 } else if (!strcmp (layout, "smjpeg")) {
3700 id = AV_CODEC_ID_ADPCM_IMA_SMJPEG;
3701 } else if (!strcmp (layout, "dk3")) {
3702 id = AV_CODEC_ID_ADPCM_IMA_DK3;
3703 } else if (!strcmp (layout, "dk4")) {
3704 id = AV_CODEC_ID_ADPCM_IMA_DK4;
3705 } else if (!strcmp (layout, "westwood")) {
3706 id = AV_CODEC_ID_ADPCM_IMA_WS;
3707 } else if (!strcmp (layout, "iss")) {
3708 id = AV_CODEC_ID_ADPCM_IMA_ISS;
3709 } else if (!strcmp (layout, "xa")) {
3710 id = AV_CODEC_ID_ADPCM_XA;
3711 } else if (!strcmp (layout, "adx")) {
3712 id = AV_CODEC_ID_ADPCM_ADX;
3713 } else if (!strcmp (layout, "ea")) {
3714 id = AV_CODEC_ID_ADPCM_EA;
3715 } else if (!strcmp (layout, "g726")) {
3716 id = AV_CODEC_ID_ADPCM_G726;
3717 } else if (!strcmp (layout, "g721")) {
3718 id = AV_CODEC_ID_ADPCM_G726;
3719 } else if (!strcmp (layout, "ct")) {
3720 id = AV_CODEC_ID_ADPCM_CT;
3721 } else if (!strcmp (layout, "swf")) {
3722 id = AV_CODEC_ID_ADPCM_SWF;
3723 } else if (!strcmp (layout, "yamaha")) {
3724 id = AV_CODEC_ID_ADPCM_YAMAHA;
3725 } else if (!strcmp (layout, "sbpro2")) {
3726 id = AV_CODEC_ID_ADPCM_SBPRO_2;
3727 } else if (!strcmp (layout, "sbpro3")) {
3728 id = AV_CODEC_ID_ADPCM_SBPRO_3;
3729 } else if (!strcmp (layout, "sbpro4")) {
3730 id = AV_CODEC_ID_ADPCM_SBPRO_4;
3732 if (id != AV_CODEC_ID_NONE)
3734 } else if (!strcmp (mimetype, "video/x-4xm")) {
3735 id = AV_CODEC_ID_4XM;
3737 } else if (!strcmp (mimetype, "audio/x-dpcm")) {
3738 const gchar *layout;
3740 layout = gst_structure_get_string (structure, "layout");
3743 } else if (!strcmp (layout, "roq")) {
3744 id = AV_CODEC_ID_ROQ_DPCM;
3745 } else if (!strcmp (layout, "interplay")) {
3746 id = AV_CODEC_ID_INTERPLAY_DPCM;
3747 } else if (!strcmp (layout, "xan")) {
3748 id = AV_CODEC_ID_XAN_DPCM;
3749 } else if (!strcmp (layout, "sol")) {
3750 id = AV_CODEC_ID_SOL_DPCM;
3752 if (id != AV_CODEC_ID_NONE)
3754 } else if (!strcmp (mimetype, "audio/x-flac")) {
3755 id = AV_CODEC_ID_FLAC;
3757 } else if (!strcmp (mimetype, "audio/x-shorten")) {
3758 id = AV_CODEC_ID_SHORTEN;
3760 } else if (!strcmp (mimetype, "audio/x-alac")) {
3761 id = AV_CODEC_ID_ALAC;
3763 } else if (!strcmp (mimetype, "video/x-cinepak")) {
3764 id = AV_CODEC_ID_CINEPAK;
3766 } else if (!strcmp (mimetype, "video/x-pn-realvideo")) {
3769 if (gst_structure_get_int (structure, "rmversion", &rmversion)) {
3770 switch (rmversion) {
3772 id = AV_CODEC_ID_RV10;
3775 id = AV_CODEC_ID_RV20;
3778 id = AV_CODEC_ID_RV30;
3781 id = AV_CODEC_ID_RV40;
3785 if (id != AV_CODEC_ID_NONE)
3787 } else if (!strcmp (mimetype, "audio/x-sipro")) {
3788 id = AV_CODEC_ID_SIPR;
3790 } else if (!strcmp (mimetype, "audio/x-pn-realaudio")) {
3793 if (gst_structure_get_int (structure, "raversion", &raversion)) {
3794 switch (raversion) {
3796 id = AV_CODEC_ID_RA_144;
3799 id = AV_CODEC_ID_RA_288;
3802 id = AV_CODEC_ID_COOK;
3806 if (id != AV_CODEC_ID_NONE)
3808 } else if (!strcmp (mimetype, "video/x-rle")) {
3809 const gchar *layout;
3811 if ((layout = gst_structure_get_string (structure, "layout"))) {
3812 if (!strcmp (layout, "microsoft")) {
3813 id = AV_CODEC_ID_MSRLE;
3817 } else if (!strcmp (mimetype, "video/x-xan")) {
3820 if ((gst_structure_get_int (structure, "wcversion", &wcversion))) {
3821 switch (wcversion) {
3823 id = AV_CODEC_ID_XAN_WC3;
3827 id = AV_CODEC_ID_XAN_WC4;
3834 } else if (!strcmp (mimetype, "audio/AMR")) {
3836 id = AV_CODEC_ID_AMR_NB;
3837 } else if (!strcmp (mimetype, "audio/AMR-WB")) {
3838 id = AV_CODEC_ID_AMR_WB;
3840 } else if (!strcmp (mimetype, "audio/qcelp")) {
3841 id = AV_CODEC_ID_QCELP;
3843 } else if (!strcmp (mimetype, "video/x-h264")) {
3844 id = AV_CODEC_ID_H264;
3846 } else if (!strcmp (mimetype, "video/x-flash-video")) {
3847 gint flvversion = 0;
3849 if ((gst_structure_get_int (structure, "flvversion", &flvversion))) {
3850 switch (flvversion) {
3852 id = AV_CODEC_ID_FLV1;
3860 } else if (!strcmp (mimetype, "audio/x-nellymoser")) {
3861 id = AV_CODEC_ID_NELLYMOSER;
3863 } else if (!strncmp (mimetype, "audio/x-gst-av-", 15)) {
3867 if (strlen (mimetype) <= 30 &&
3868 sscanf (mimetype, "audio/x-gst-av-%s", ext) == 1) {
3869 if ((codec = avcodec_find_decoder_by_name (ext)) ||
3870 (codec = avcodec_find_encoder_by_name (ext))) {
3875 } else if (!strncmp (mimetype, "video/x-gst-av-", 15)) {
3879 if (strlen (mimetype) <= 30 &&
3880 sscanf (mimetype, "video/x-gst-av-%s", ext) == 1) {
3881 if ((codec = avcodec_find_decoder_by_name (ext)) ||
3882 (codec = avcodec_find_encoder_by_name (ext))) {
3889 if (context != NULL) {
3890 if (video == TRUE) {
3891 context->codec_type = AVMEDIA_TYPE_VIDEO;
3892 } else if (audio == TRUE) {
3893 context->codec_type = AVMEDIA_TYPE_AUDIO;
3895 context->codec_type = AVMEDIA_TYPE_UNKNOWN;
3897 context->codec_id = id;
3898 gst_ffmpeg_caps_with_codecid (id, context->codec_type, caps, context);
3901 if (id != AV_CODEC_ID_NONE) {
3902 GST_DEBUG ("The id=%d belongs to the caps %" GST_PTR_FORMAT, id, caps);
3904 GST_WARNING ("Couldn't figure out the id for caps %" GST_PTR_FORMAT, caps);