2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
4 * Copyright (c) 2002-2004 Ronald Bultje <rbultje@ronald.bitfreak.net>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
29 #include <libavcodec/avcodec.h>
30 #include <libavutil/channel_layout.h>
33 #include "gstavcodecmap.h"
35 #include <gst/video/video.h>
36 #include <gst/audio/audio.h>
37 #include <gst/pbutils/codec-utils.h>
39 /* IMPORTANT: Keep this sorted by the ffmpeg channel masks */
43 GstAudioChannelPosition gst;
44 } _ff_to_gst_layout[] = {
46 AV_CH_FRONT_LEFT, GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT}, {
47 AV_CH_FRONT_RIGHT, GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT}, {
48 AV_CH_FRONT_CENTER, GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER}, {
49 AV_CH_LOW_FREQUENCY, GST_AUDIO_CHANNEL_POSITION_LFE1}, {
50 AV_CH_BACK_LEFT, GST_AUDIO_CHANNEL_POSITION_REAR_LEFT}, {
51 AV_CH_BACK_RIGHT, GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT}, {
52 AV_CH_FRONT_LEFT_OF_CENTER, GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER}, {
53 AV_CH_FRONT_RIGHT_OF_CENTER,
54 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER}, {
55 AV_CH_BACK_CENTER, GST_AUDIO_CHANNEL_POSITION_REAR_CENTER}, {
56 AV_CH_SIDE_LEFT, GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT}, {
57 AV_CH_SIDE_RIGHT, GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT}, {
58 AV_CH_TOP_CENTER, GST_AUDIO_CHANNEL_POSITION_TOP_CENTER}, {
59 AV_CH_TOP_FRONT_LEFT, GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_LEFT}, {
60 AV_CH_TOP_FRONT_CENTER, GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_CENTER}, {
61 AV_CH_TOP_FRONT_RIGHT, GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_RIGHT}, {
62 AV_CH_TOP_BACK_LEFT, GST_AUDIO_CHANNEL_POSITION_TOP_REAR_LEFT}, {
63 AV_CH_TOP_BACK_CENTER, GST_AUDIO_CHANNEL_POSITION_TOP_REAR_CENTER}, {
64 AV_CH_TOP_BACK_RIGHT, GST_AUDIO_CHANNEL_POSITION_TOP_REAR_RIGHT}, {
65 AV_CH_STEREO_LEFT, GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT}, {
66 AV_CH_STEREO_RIGHT, GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT}
70 gst_ffmpeg_compliance_get_type (void)
72 static GType ffmpeg_compliance_type = 0;
73 static const GEnumValue compliance_types[] = {
74 {GST_FFMPEG_VERY_STRICT, "Strictly conform to older spec",
76 {GST_FFMPEG_STRICT, "Strictly conform to current spec", "strict"},
77 {GST_FFMPEG_NORMAL, "Normal behavior", "normal"},
78 {GST_FFMPEG_UNOFFICIAL, "Allow unofficial extensions", "unofficial"},
79 {GST_FFMPEG_EXPERIMENTAL, "Allow nonstandardized experimental things",
84 if (!ffmpeg_compliance_type) {
85 ffmpeg_compliance_type =
86 g_enum_register_static ("GstFFMpegCompliance", compliance_types);
88 return ffmpeg_compliance_type;
92 gst_ffmpeg_channel_positions_to_layout (GstAudioChannelPosition * pos,
97 gint channels_found = 0;
102 for (i = 0; i < channels; i++) {
103 for (j = 0; j < G_N_ELEMENTS (_ff_to_gst_layout); j++) {
104 if (_ff_to_gst_layout[j].gst == pos[i]) {
105 ret |= _ff_to_gst_layout[j].ff;
112 if (channels_found != channels)
118 gst_ffmpeg_channel_layout_to_gst (guint64 channel_layout, gint channels,
119 GstAudioChannelPosition * pos)
122 gboolean none_layout = FALSE;
124 if (channel_layout == 0) {
125 nchannels = channels;
130 for (i = 0; i < 64; i++) {
131 if ((channel_layout & (G_GUINT64_CONSTANT (1) << i)) != 0) {
136 if (nchannels != channels) {
137 GST_ERROR ("Number of channels is different (%u != %u)", channels,
139 nchannels = channels;
143 for (i = 0, j = 0; i < G_N_ELEMENTS (_ff_to_gst_layout); i++) {
144 if ((channel_layout & _ff_to_gst_layout[i].ff) != 0) {
145 pos[j++] = _ff_to_gst_layout[i].gst;
147 if (_ff_to_gst_layout[i].gst == GST_AUDIO_CHANNEL_POSITION_NONE)
152 if (j != nchannels) {
154 ("Unknown channels in channel layout - assuming NONE layout");
161 && !gst_audio_check_valid_channel_positions (pos, nchannels, FALSE)) {
162 GST_ERROR ("Invalid channel layout %" G_GUINT64_FORMAT
163 " - assuming NONE layout", channel_layout);
168 if (nchannels == 1) {
169 pos[0] = GST_AUDIO_CHANNEL_POSITION_MONO;
170 } else if (nchannels == 2) {
171 pos[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT;
172 pos[1] = GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT;
176 for (i = 0; i < nchannels; i++)
177 pos[i] = GST_AUDIO_CHANNEL_POSITION_NONE;
185 _gst_value_list_contains (const GValue * list, const GValue * value)
190 n = gst_value_list_get_size (list);
191 for (i = 0; i < n; i++) {
192 tmp = gst_value_list_get_value (list, i);
193 if (gst_value_compare (value, tmp) == GST_VALUE_EQUAL)
201 gst_ffmpeg_video_set_pix_fmts (GstCaps * caps, const enum AVPixelFormat *fmts)
205 GstVideoFormat format;
207 if (!fmts || fmts[0] == -1) {
210 g_value_init (&va, GST_TYPE_LIST);
211 g_value_init (&v, G_TYPE_STRING);
212 for (i = 0; i <= PIX_FMT_NB; i++) {
213 format = gst_ffmpeg_pixfmt_to_videoformat (i);
214 if (format == GST_VIDEO_FORMAT_UNKNOWN)
216 g_value_set_string (&v, gst_video_format_to_string (format));
217 gst_value_list_append_value (&va, &v);
219 gst_caps_set_value (caps, "format", &va);
225 /* Only a single format */
226 g_value_init (&va, GST_TYPE_LIST);
227 g_value_init (&v, G_TYPE_STRING);
228 while (*fmts != -1) {
229 format = gst_ffmpeg_pixfmt_to_videoformat (*fmts);
230 if (format != GST_VIDEO_FORMAT_UNKNOWN) {
231 g_value_set_string (&v, gst_video_format_to_string (format));
232 /* Only append values we don't have yet */
233 if (!_gst_value_list_contains (&va, &v))
234 gst_value_list_append_value (&va, &v);
238 if (gst_value_list_get_size (&va) == 1) {
239 /* The single value is still in v */
240 gst_caps_set_value (caps, "format", &v);
241 } else if (gst_value_list_get_size (&va) > 1) {
242 gst_caps_set_value (caps, "format", &va);
248 /* this macro makes a caps width fixed or unfixed width/height
249 * properties depending on whether we've got a context.
251 * See below for why we use this.
253 * We should actually do this stuff at the end, like in riff-media.c,
254 * but I'm too lazy today. Maybe later.
257 gst_ff_vid_caps_new (AVCodecContext * context, AVCodec * codec,
258 enum AVCodecID codec_id, gboolean encode, const char *mimetype,
259 const char *fieldname, ...)
261 GstCaps *caps = NULL;
265 GST_LOG ("context:%p, codec_id:%d, mimetype:%s", context, codec_id, mimetype);
267 /* fixed, non probing context */
268 if (context != NULL && context->width != -1) {
271 caps = gst_caps_new_simple (mimetype,
272 "width", G_TYPE_INT, context->width,
273 "height", G_TYPE_INT, context->height, NULL);
275 num = context->time_base.den / context->ticks_per_frame;
276 denom = context->time_base.num;
279 GST_LOG ("invalid framerate: %d/0, -> %d/1", num, num);
282 if (gst_util_fraction_compare (num, denom, 1000, 1) > 0) {
283 GST_LOG ("excessive framerate: %d/%d, -> 0/1", num, denom);
287 GST_LOG ("setting framerate: %d/%d", num, denom);
288 gst_caps_set_simple (caps,
289 "framerate", GST_TYPE_FRACTION, num, denom, NULL);
291 /* so we are after restricted caps in this case */
293 case AV_CODEC_ID_H261:
295 caps = gst_caps_new_simple (mimetype,
296 "width", G_TYPE_INT, 352,
297 "height", G_TYPE_INT, 288,
298 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
299 gst_caps_append (caps, gst_caps_new_simple (mimetype,
300 "width", G_TYPE_INT, 176,
301 "height", G_TYPE_INT, 144,
302 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL));
305 case AV_CODEC_ID_H263:
307 /* 128x96, 176x144, 352x288, 704x576, and 1408x1152. slightly reordered
308 * because we want automatic negotiation to go as close to 320x240 as
310 const static gint widths[] = { 352, 704, 176, 1408, 128 };
311 const static gint heights[] = { 288, 576, 144, 1152, 96 };
313 gint n_sizes = G_N_ELEMENTS (widths);
315 caps = gst_caps_new_empty ();
316 for (i = 0; i < n_sizes; i++) {
317 temp = gst_caps_new_simple (mimetype,
318 "width", G_TYPE_INT, widths[i],
319 "height", G_TYPE_INT, heights[i],
320 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
322 gst_caps_append (caps, temp);
326 case AV_CODEC_ID_DVVIDEO:
333 gint framerate_n, framerate_d;
336 "Y41B", 720, 480, 8, 9, 30000, 1001}, {
337 "Y41B", 720, 480, 32, 27, 30000, 1001}, {
338 "Y42B", 720, 480, 8, 9, 30000, 1001}, {
339 "Y42B", 720, 480, 32, 27, 30000, 1001}, {
340 "I420", 720, 576, 16, 15, 25, 1}, {
341 "I420", 720, 576, 64, 45, 25, 1}, {
342 "Y41B", 720, 576, 16, 15, 25, 1}, {
343 "Y41B", 720, 576, 64, 45, 25, 1}, {
344 "Y42B", 720, 576, 16, 15, 25, 1}, {
345 "Y42B", 720, 576, 64, 45, 25, 1}, {
346 "Y42B", 1280, 1080, 1, 1, 30000, 1001}, {
347 "Y42B", 1280, 1080, 3, 2, 30000, 1001}, {
348 "Y42B", 1440, 1080, 1, 1, 25, 1}, {
349 "Y42B", 1440, 1080, 4, 3, 25, 1}, {
350 "Y42B", 960, 720, 1, 1, 60000, 1001}, {
351 "Y42B", 960, 720, 4, 3, 60000, 1001}, {
352 "Y42B", 960, 720, 1, 1, 50, 1}, {
353 "Y42B", 960, 720, 4, 3, 50, 1},};
355 gint n_sizes = G_N_ELEMENTS (profiles);
357 if (strcmp (mimetype, "video/x-raw") == 0) {
358 caps = gst_caps_new_empty ();
359 for (i = 0; i < n_sizes; i++) {
360 temp = gst_caps_new_simple (mimetype,
361 "format", G_TYPE_STRING, profiles[i].csp,
362 "width", G_TYPE_INT, profiles[i].width,
363 "height", G_TYPE_INT, profiles[i].height,
364 "framerate", GST_TYPE_FRACTION, profiles[i].framerate_n,
365 profiles[i].framerate_d, "pixel-aspect-ratio",
366 GST_TYPE_FRACTION, profiles[i].par_n, profiles[i].par_d, NULL);
368 gst_caps_append (caps, temp);
371 caps = gst_caps_new_empty ();
372 for (i = 0; i < n_sizes; i++) {
373 temp = gst_caps_new_simple (mimetype,
374 "width", G_TYPE_INT, profiles[i].width,
375 "height", G_TYPE_INT, profiles[i].height,
376 "framerate", GST_TYPE_FRACTION, profiles[i].framerate_n,
377 profiles[i].framerate_d, "pixel-aspect-ratio",
378 GST_TYPE_FRACTION, profiles[i].par_n, profiles[i].par_d, NULL);
380 gst_caps_append (caps, temp);
385 case AV_CODEC_ID_DNXHD:
387 caps = gst_caps_new_simple (mimetype,
388 "width", G_TYPE_INT, 1920,
389 "height", G_TYPE_INT, 1080,
390 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
391 gst_caps_append (caps, gst_caps_new_simple (mimetype,
392 "width", G_TYPE_INT, 1280,
393 "height", G_TYPE_INT, 720,
394 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL));
399 if (codec && codec->supported_framerates
400 && codec->supported_framerates[0].num != 0
401 && codec->supported_framerates[0].den != 0) {
404 const AVRational *rates = codec->supported_framerates;
406 if (rates[1].num == 0 && rates[1].den == 0) {
408 gst_caps_new_simple (mimetype, "framerate", GST_TYPE_FRACTION,
409 rates[0].num, rates[0].den, NULL);
411 g_value_init (&va, GST_TYPE_LIST);
412 g_value_init (&v, GST_TYPE_FRACTION);
414 while (rates->num != 0 && rates->den != 0) {
415 gst_value_set_fraction (&v, rates->num, rates->den);
416 gst_value_list_append_value (&va, &v);
420 caps = gst_caps_new_simple (mimetype, NULL, NULL, NULL);
421 gst_caps_set_value (caps, "framerate", &va);
427 caps = gst_caps_new_empty_simple (mimetype);
435 /* no fixed caps or special restrictions applied;
436 * default unfixed setting */
438 GST_DEBUG ("Creating default caps");
439 caps = gst_caps_new_empty_simple (mimetype);
442 va_start (var_args, fieldname);
443 gst_caps_set_simple_valist (caps, fieldname, var_args);
450 get_nbits_set (guint64 n)
455 for (i = 0; i < 64; i++) {
456 if ((n & (G_GUINT64_CONSTANT (1) << i)))
464 gst_ffmpeg_audio_set_sample_fmts (GstCaps * caps,
465 const enum AVSampleFormat *fmts)
469 GstAudioFormat format;
471 if (!fmts || fmts[0] == -1) {
474 g_value_init (&va, GST_TYPE_LIST);
475 g_value_init (&v, G_TYPE_STRING);
476 for (i = 0; i <= AV_SAMPLE_FMT_DBL; i++) {
477 format = gst_ffmpeg_smpfmt_to_audioformat (i);
478 if (format == GST_AUDIO_FORMAT_UNKNOWN)
480 g_value_set_string (&v, gst_audio_format_to_string (format));
481 gst_value_list_append_value (&va, &v);
483 gst_caps_set_value (caps, "format", &va);
489 g_value_init (&va, GST_TYPE_LIST);
490 g_value_init (&v, G_TYPE_STRING);
491 while (*fmts != -1) {
492 format = gst_ffmpeg_smpfmt_to_audioformat (*fmts);
493 if (format != GST_AUDIO_FORMAT_UNKNOWN) {
494 g_value_set_string (&v, gst_audio_format_to_string (format));
495 /* Only append values we don't have yet */
496 if (!_gst_value_list_contains (&va, &v))
497 gst_value_list_append_value (&va, &v);
501 if (gst_value_list_get_size (&va) == 1) {
502 /* The single value is still in v */
503 gst_caps_set_value (caps, "format", &v);
504 } else if (gst_value_list_get_size (&va) > 1) {
505 gst_caps_set_value (caps, "format", &va);
511 /* same for audio - now with channels/sample rate
514 gst_ff_aud_caps_new (AVCodecContext * context, AVCodec * codec,
515 enum AVCodecID codec_id, gboolean encode, const char *mimetype,
516 const char *fieldname, ...)
518 GstCaps *caps = NULL;
522 /* fixed, non-probing context */
523 if (context != NULL && context->channels != -1) {
524 GstAudioChannelPosition pos[64];
527 caps = gst_caps_new_simple (mimetype,
528 "rate", G_TYPE_INT, context->sample_rate,
529 "channels", G_TYPE_INT, context->channels, NULL);
531 if (context->channels > 1 &&
532 gst_ffmpeg_channel_layout_to_gst (context->channel_layout,
533 context->channels, pos) &&
534 gst_audio_channel_positions_to_mask (pos, context->channels, FALSE,
536 gst_caps_set_simple (caps, "channel-mask", GST_TYPE_BITMASK, mask, NULL);
539 gint maxchannels = 2;
540 const gint *rates = NULL;
543 /* so we must be after restricted caps in this case */
545 case AV_CODEC_ID_AAC:
546 case AV_CODEC_ID_AAC_LATM:
547 case AV_CODEC_ID_DTS:
550 case AV_CODEC_ID_MP2:
552 const static gint l_rates[] =
553 { 48000, 44100, 32000, 24000, 22050, 16000 };
554 n_rates = G_N_ELEMENTS (l_rates);
558 case AV_CODEC_ID_EAC3:
559 case AV_CODEC_ID_AC3:
561 const static gint l_rates[] = { 48000, 44100, 32000 };
563 n_rates = G_N_ELEMENTS (l_rates);
567 case AV_CODEC_ID_ADPCM_G722:
569 const static gint l_rates[] = { 16000 };
570 n_rates = G_N_ELEMENTS (l_rates);
575 case AV_CODEC_ID_ADPCM_G726:
577 const static gint l_rates[] = { 8000 };
578 n_rates = G_N_ELEMENTS (l_rates);
583 case AV_CODEC_ID_ADPCM_SWF:
585 const static gint l_rates[] = { 11025, 22050, 44100 };
586 n_rates = G_N_ELEMENTS (l_rates);
590 case AV_CODEC_ID_ROQ_DPCM:
592 const static gint l_rates[] = { 22050 };
593 n_rates = G_N_ELEMENTS (l_rates);
597 case AV_CODEC_ID_AMR_NB:
599 const static gint l_rates[] = { 8000 };
601 n_rates = G_N_ELEMENTS (l_rates);
605 case AV_CODEC_ID_AMR_WB:
607 const static gint l_rates[] = { 16000 };
609 n_rates = G_N_ELEMENTS (l_rates);
617 /* regardless of encode/decode, open up channels if applicable */
618 /* Until decoders/encoders expose the maximum number of channels
619 * they support, we whitelist them here. */
621 case AV_CODEC_ID_WMAPRO:
622 case AV_CODEC_ID_TRUEHD:
629 if (codec && codec->channel_layouts) {
630 const uint64_t *layouts = codec->channel_layouts;
631 GstAudioChannelPosition pos[64];
633 caps = gst_caps_new_empty ();
635 gint nbits_set = get_nbits_set (*layouts);
637 if (gst_ffmpeg_channel_layout_to_gst (*layouts, nbits_set, pos)) {
640 if (gst_audio_channel_positions_to_mask (pos, nbits_set, FALSE,
643 gst_caps_new_simple (mimetype, "channel-mask", GST_TYPE_BITMASK,
645 "channels", G_TYPE_INT, nbits_set, NULL);
647 gst_caps_append (caps, tmp);
653 if (maxchannels == 1)
654 caps = gst_caps_new_simple (mimetype,
655 "channels", G_TYPE_INT, maxchannels, NULL);
657 caps = gst_caps_new_simple (mimetype,
658 "channels", GST_TYPE_INT_RANGE, 1, maxchannels, NULL);
662 GValue list = { 0, };
664 g_value_init (&list, GST_TYPE_LIST);
665 for (i = 0; i < n_rates; i++) {
668 g_value_init (&v, G_TYPE_INT);
669 g_value_set_int (&v, rates[i]);
670 gst_value_list_append_value (&list, &v);
673 gst_caps_set_value (caps, "rate", &list);
674 g_value_unset (&list);
675 } else if (codec && codec->supported_samplerates
676 && codec->supported_samplerates[0]) {
680 if (!codec->supported_samplerates[1]) {
681 gst_caps_set_simple (caps, "rate", G_TYPE_INT,
682 codec->supported_samplerates[0], NULL);
684 const int *rates = codec->supported_samplerates;
686 g_value_init (&va, GST_TYPE_LIST);
687 g_value_init (&v, G_TYPE_INT);
690 g_value_set_int (&v, *rates);
691 gst_value_list_append_value (&va, &v);
694 gst_caps_set_value (caps, "rate", &va);
699 gst_caps_set_simple (caps, "rate", GST_TYPE_INT_RANGE, 4000, 96000, NULL);
702 caps = gst_caps_new_empty_simple (mimetype);
705 va_start (var_args, fieldname);
706 gst_caps_set_simple_valist (caps, fieldname, var_args);
712 /* Convert a FFMPEG codec ID and optional AVCodecContext
713 * to a GstCaps. If the context is ommitted, no fixed values
714 * for video/audio size will be included in the GstCaps
716 * CodecID is primarily meant for compressed data GstCaps!
718 * encode is a special parameter. gstffmpegdec will say
719 * FALSE, gstffmpegenc will say TRUE. The output caps
720 * depends on this, in such a way that it will be very
721 * specific, defined, fixed and correct caps for encoders,
722 * yet very wide, "forgiving" caps for decoders. Example
723 * for mp3: decode: audio/mpeg,mpegversion=1,layer=[1-3]
724 * but encode: audio/mpeg,mpegversion=1,layer=3,bitrate=x,
729 gst_ffmpeg_codecid_to_caps (enum AVCodecID codec_id,
730 AVCodecContext * context, gboolean encode)
732 GstCaps *caps = NULL;
733 gboolean buildcaps = FALSE;
735 GST_LOG ("codec_id:%d, context:%p, encode:%d", codec_id, context, encode);
738 case AV_CODEC_ID_MPEG1VIDEO:
740 caps = gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
741 "mpegversion", G_TYPE_INT, 1,
742 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
745 case AV_CODEC_ID_MPEG2VIDEO:
749 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
750 "mpegversion", G_TYPE_INT, 2, "systemstream", G_TYPE_BOOLEAN, FALSE,
753 /* decode both MPEG-1 and MPEG-2; width/height/fps are all in
754 * the MPEG video stream headers, so may be omitted from caps. */
755 caps = gst_caps_new_simple ("video/mpeg",
756 "mpegversion", GST_TYPE_INT_RANGE, 1, 2,
757 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
761 case AV_CODEC_ID_MPEG2VIDEO_XVMC:
762 /* this is a special ID - don't need it in GStreamer, I think */
765 case AV_CODEC_ID_H263:
768 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
769 "video/x-h263", "variant", G_TYPE_STRING, "itu", "h263version",
770 G_TYPE_STRING, "h263", NULL);
772 /* don't pass codec_id, we can decode other variants with the H263
773 * decoder that don't have specific size requirements
776 gst_ff_vid_caps_new (context, NULL, AV_CODEC_ID_NONE, encode,
777 "video/x-h263", "variant", G_TYPE_STRING, "itu", NULL);
781 case AV_CODEC_ID_H263P:
783 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h263",
784 "variant", G_TYPE_STRING, "itu", "h263version", G_TYPE_STRING,
786 if (encode && context) {
788 gst_caps_set_simple (caps,
789 "annex-f", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_4MV,
790 "annex-j", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_LOOP_FILTER,
791 "annex-i", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_AC_PRED,
792 "annex-t", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_AC_PRED,
797 case AV_CODEC_ID_H263I:
799 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
800 "video/x-intel-h263", "variant", G_TYPE_STRING, "intel", NULL);
803 case AV_CODEC_ID_H261:
805 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h261",
809 case AV_CODEC_ID_RV10:
810 case AV_CODEC_ID_RV20:
811 case AV_CODEC_ID_RV30:
812 case AV_CODEC_ID_RV40:
817 case AV_CODEC_ID_RV40:
820 case AV_CODEC_ID_RV30:
823 case AV_CODEC_ID_RV20:
832 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
833 "video/x-pn-realvideo", "rmversion", G_TYPE_INT, version, NULL);
835 if (context->extradata_size >= 8) {
836 gst_caps_set_simple (caps,
837 "subformat", G_TYPE_INT, GST_READ_UINT32_BE (context->extradata),
844 case AV_CODEC_ID_MP1:
846 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
847 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 1, NULL);
850 case AV_CODEC_ID_MP2:
852 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
853 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 2, NULL);
856 case AV_CODEC_ID_MP3:
860 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
861 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 3, NULL);
863 /* Decodes MPEG-1 layer 1/2/3. Samplerate, channels et al are
864 * in the MPEG audio header, so may be omitted from caps. */
865 caps = gst_caps_new_simple ("audio/mpeg",
866 "mpegversion", G_TYPE_INT, 1,
867 "layer", GST_TYPE_INT_RANGE, 1, 3, NULL);
871 case AV_CODEC_ID_MUSEPACK7:
873 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
874 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 7,
878 case AV_CODEC_ID_MUSEPACK8:
880 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
881 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 8,
885 case AV_CODEC_ID_AC3:
888 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-ac3",
892 case AV_CODEC_ID_EAC3:
895 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-eac3",
899 case AV_CODEC_ID_TRUEHD:
901 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
902 "audio/x-true-hd", NULL);
905 case AV_CODEC_ID_ATRAC1:
907 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
908 "audio/x-vnd.sony.atrac1", NULL);
911 case AV_CODEC_ID_ATRAC3:
913 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
914 "audio/x-vnd.sony.atrac3", NULL);
917 case AV_CODEC_ID_DTS:
919 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dts",
923 case AV_CODEC_ID_APE:
925 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
926 "audio/x-ffmpeg-parsed-ape", NULL);
928 gst_caps_set_simple (caps,
929 "depth", G_TYPE_INT, context->bits_per_coded_sample, NULL);
933 case AV_CODEC_ID_MLP:
935 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mlp",
939 case AV_CODEC_ID_IMC:
941 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-imc",
945 /* MJPEG is normal JPEG, Motion-JPEG and Quicktime MJPEG-A. MJPEGB
946 * is Quicktime's MJPEG-B. LJPEG is lossless JPEG. I don't know what
947 * sp5x is, but it's apparently something JPEG... We don't separate
948 * between those in GStreamer. Should we (at least between MJPEG,
949 * MJPEG-B and sp5x decoding...)? */
950 case AV_CODEC_ID_MJPEG:
951 case AV_CODEC_ID_LJPEG:
953 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/jpeg",
954 "parsed", G_TYPE_BOOLEAN, TRUE, NULL);
957 case AV_CODEC_ID_SP5X:
959 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/sp5x",
963 case AV_CODEC_ID_MJPEGB:
965 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
966 "video/x-mjpeg-b", NULL);
969 case AV_CODEC_ID_MPEG4:
970 if (encode && context != NULL) {
971 /* I'm not exactly sure what ffmpeg outputs... ffmpeg itself uses
972 * the AVI fourcc 'DIVX', but 'mp4v' for Quicktime... */
973 switch (context->codec_tag) {
974 case GST_MAKE_FOURCC ('D', 'I', 'V', 'X'):
976 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
977 "video/x-divx", "divxversion", G_TYPE_INT, 5, NULL);
979 case GST_MAKE_FOURCC ('m', 'p', '4', 'v'):
983 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
984 "video/mpeg", "systemstream", G_TYPE_BOOLEAN, FALSE,
985 "mpegversion", G_TYPE_INT, 4, NULL);
989 /* The trick here is to separate xvid, divx, mpeg4, 3ivx et al */
991 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
992 "mpegversion", G_TYPE_INT, 4, "systemstream", G_TYPE_BOOLEAN, FALSE,
995 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
996 encode, "video/x-divx", "divxversion", G_TYPE_INT, 5, NULL));
998 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
999 encode, "video/x-divx", "divxversion", GST_TYPE_INT_RANGE, 4,
1001 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
1002 encode, "video/x-xvid", NULL));
1003 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
1004 encode, "video/x-3ivx", NULL));
1009 case AV_CODEC_ID_RAWVIDEO:
1011 gst_ffmpeg_codectype_to_video_caps (context, codec_id, encode, NULL);
1014 case AV_CODEC_ID_MSMPEG4V1:
1015 case AV_CODEC_ID_MSMPEG4V2:
1016 case AV_CODEC_ID_MSMPEG4V3:
1018 gint version = 41 + codec_id - AV_CODEC_ID_MSMPEG4V1;
1020 /* encode-FIXME: bitrate */
1022 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1023 "video/x-msmpeg", "msmpegversion", G_TYPE_INT, version, NULL);
1024 if (!encode && codec_id == AV_CODEC_ID_MSMPEG4V3) {
1025 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
1026 encode, "video/x-divx", "divxversion", G_TYPE_INT, 3, NULL));
1031 case AV_CODEC_ID_WMV1:
1032 case AV_CODEC_ID_WMV2:
1034 gint version = (codec_id == AV_CODEC_ID_WMV1) ? 1 : 2;
1037 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1038 "wmvversion", G_TYPE_INT, version, NULL);
1042 case AV_CODEC_ID_FLV1:
1044 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1045 "video/x-flash-video", "flvversion", G_TYPE_INT, 1, NULL);
1048 case AV_CODEC_ID_SVQ1:
1050 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-svq",
1051 "svqversion", G_TYPE_INT, 1, NULL);
1054 case AV_CODEC_ID_SVQ3:
1056 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-svq",
1057 "svqversion", G_TYPE_INT, 3, NULL);
1060 case AV_CODEC_ID_DVAUDIO:
1062 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dv",
1066 case AV_CODEC_ID_DVVIDEO:
1068 if (encode && context) {
1069 const gchar *format;
1071 switch (context->pix_fmt) {
1072 case PIX_FMT_YUYV422:
1075 case PIX_FMT_YUV420P:
1078 case PIX_FMT_YUVA420P:
1081 case PIX_FMT_YUV411P:
1084 case PIX_FMT_YUV422P:
1087 case PIX_FMT_YUV410P:
1092 ("Couldnt' find format for pixfmt %d, defaulting to I420",
1098 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dv",
1099 "systemstream", G_TYPE_BOOLEAN, FALSE, "format", G_TYPE_STRING,
1103 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dv",
1104 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
1109 case AV_CODEC_ID_WMAV1:
1110 case AV_CODEC_ID_WMAV2:
1112 gint version = (codec_id == AV_CODEC_ID_WMAV1) ? 1 : 2;
1116 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1117 "wmaversion", G_TYPE_INT, version, "block_align", G_TYPE_INT,
1118 context->block_align, "bitrate", G_TYPE_INT, context->bit_rate,
1122 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1123 "wmaversion", G_TYPE_INT, version, "block_align",
1124 GST_TYPE_INT_RANGE, 0, G_MAXINT, "bitrate", GST_TYPE_INT_RANGE, 0,
1129 case AV_CODEC_ID_WMAPRO:
1132 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1133 "wmaversion", G_TYPE_INT, 3, NULL);
1136 case AV_CODEC_ID_WMALOSSLESS:
1138 /* libav only supports a depth of 16 at the moment */
1140 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1141 "wmaversion", G_TYPE_INT, 4, "depth", G_TYPE_INT, 16, NULL);
1144 case AV_CODEC_ID_WMAVOICE:
1147 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wms",
1152 case AV_CODEC_ID_MACE3:
1153 case AV_CODEC_ID_MACE6:
1155 gint version = (codec_id == AV_CODEC_ID_MACE3) ? 3 : 6;
1158 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mace",
1159 "maceversion", G_TYPE_INT, version, NULL);
1163 case AV_CODEC_ID_HUFFYUV:
1165 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1166 "video/x-huffyuv", NULL);
1168 gst_caps_set_simple (caps,
1169 "bpp", G_TYPE_INT, context->bits_per_coded_sample, NULL);
1173 case AV_CODEC_ID_CYUV:
1175 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1176 "video/x-compressed-yuv", NULL);
1179 case AV_CODEC_ID_H264:
1181 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h264",
1182 "alignment", G_TYPE_STRING, "au", NULL);
1184 GValue arr = { 0, };
1185 GValue item = { 0, };
1186 g_value_init (&arr, GST_TYPE_LIST);
1187 g_value_init (&item, G_TYPE_STRING);
1188 g_value_set_string (&item, "avc");
1189 gst_value_list_append_value (&arr, &item);
1190 g_value_set_string (&item, "byte-stream");
1191 gst_value_list_append_value (&arr, &item);
1192 g_value_unset (&item);
1193 gst_caps_set_value (caps, "stream-format", &arr);
1194 g_value_unset (&arr);
1198 case AV_CODEC_ID_INDEO5:
1200 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1201 "indeoversion", G_TYPE_INT, 5, NULL);
1204 case AV_CODEC_ID_INDEO4:
1206 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1207 "indeoversion", G_TYPE_INT, 4, NULL);
1210 case AV_CODEC_ID_INDEO3:
1212 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1213 "indeoversion", G_TYPE_INT, 3, NULL);
1216 case AV_CODEC_ID_INDEO2:
1218 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1219 "indeoversion", G_TYPE_INT, 2, NULL);
1222 case AV_CODEC_ID_FLASHSV:
1224 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1225 "video/x-flash-screen", NULL);
1228 case AV_CODEC_ID_VP3:
1230 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp3",
1234 case AV_CODEC_ID_VP5:
1236 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp5",
1240 case AV_CODEC_ID_VP6:
1242 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp6",
1246 case AV_CODEC_ID_VP6F:
1248 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1249 "video/x-vp6-flash", NULL);
1252 case AV_CODEC_ID_VP6A:
1254 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1255 "video/x-vp6-alpha", NULL);
1258 case AV_CODEC_ID_VP8:
1260 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp8",
1264 case AV_CODEC_ID_THEORA:
1266 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1267 "video/x-theora", NULL);
1270 case AV_CODEC_ID_AAC:
1273 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
1277 GValue arr = { 0, };
1278 GValue item = { 0, };
1280 g_value_init (&arr, GST_TYPE_LIST);
1281 g_value_init (&item, G_TYPE_INT);
1282 g_value_set_int (&item, 2);
1283 gst_value_list_append_value (&arr, &item);
1284 g_value_set_int (&item, 4);
1285 gst_value_list_append_value (&arr, &item);
1286 g_value_unset (&item);
1288 gst_caps_set_value (caps, "mpegversion", &arr);
1289 g_value_unset (&arr);
1291 g_value_init (&arr, GST_TYPE_LIST);
1292 g_value_init (&item, G_TYPE_STRING);
1293 g_value_set_string (&item, "raw");
1294 gst_value_list_append_value (&arr, &item);
1295 g_value_set_string (&item, "adts");
1296 gst_value_list_append_value (&arr, &item);
1297 g_value_set_string (&item, "adif");
1298 gst_value_list_append_value (&arr, &item);
1299 g_value_unset (&item);
1301 gst_caps_set_value (caps, "stream-format", &arr);
1302 g_value_unset (&arr);
1304 gst_caps_set_simple (caps, "mpegversion", G_TYPE_INT, 4,
1305 "stream-format", G_TYPE_STRING, "raw",
1306 "base-profile", G_TYPE_STRING, "lc", NULL);
1308 if (context && context->extradata_size > 0)
1309 gst_codec_utils_aac_caps_set_level_and_profile (caps,
1310 context->extradata, context->extradata_size);
1315 case AV_CODEC_ID_AAC_LATM: /* LATM/LOAS AAC syntax */
1316 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
1317 "mpegversion", G_TYPE_INT, 4, "stream-format", G_TYPE_STRING, "loas",
1321 case AV_CODEC_ID_ASV1:
1323 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-asus",
1324 "asusversion", G_TYPE_INT, 1, NULL);
1326 case AV_CODEC_ID_ASV2:
1328 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-asus",
1329 "asusversion", G_TYPE_INT, 2, NULL);
1332 case AV_CODEC_ID_FFV1:
1334 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-ffv",
1335 "ffvversion", G_TYPE_INT, 1, NULL);
1338 case AV_CODEC_ID_4XM:
1340 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-4xm",
1344 case AV_CODEC_ID_XAN_WC3:
1345 case AV_CODEC_ID_XAN_WC4:
1347 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-xan",
1348 "wcversion", G_TYPE_INT, 3 - AV_CODEC_ID_XAN_WC3 + codec_id, NULL);
1351 case AV_CODEC_ID_CLJR:
1353 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1354 "video/x-cirrus-logic-accupak", NULL);
1357 case AV_CODEC_ID_FRAPS:
1359 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-fraps",
1363 case AV_CODEC_ID_MDEC:
1364 case AV_CODEC_ID_ROQ:
1365 case AV_CODEC_ID_INTERPLAY_VIDEO:
1369 case AV_CODEC_ID_VCR1:
1371 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1372 "video/x-ati-vcr", "vcrversion", G_TYPE_INT, 1, NULL);
1375 case AV_CODEC_ID_RPZA:
1377 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1378 "video/x-apple-video", NULL);
1381 case AV_CODEC_ID_CINEPAK:
1383 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1384 "video/x-cinepak", NULL);
1387 /* WS_VQA belogns here (order) */
1389 case AV_CODEC_ID_MSRLE:
1391 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-rle",
1392 "layout", G_TYPE_STRING, "microsoft", NULL);
1394 gst_caps_set_simple (caps,
1395 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1397 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1401 case AV_CODEC_ID_QTRLE:
1403 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-rle",
1404 "layout", G_TYPE_STRING, "quicktime", NULL);
1406 gst_caps_set_simple (caps,
1407 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1409 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1413 case AV_CODEC_ID_MSVIDEO1:
1415 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1416 "video/x-msvideocodec", "msvideoversion", G_TYPE_INT, 1, NULL);
1419 case AV_CODEC_ID_MSS1:
1421 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1422 "wmvversion", G_TYPE_INT, 1, "format", G_TYPE_STRING, "MSS1", NULL);
1425 case AV_CODEC_ID_MSS2:
1427 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1428 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "MSS2", NULL);
1431 case AV_CODEC_ID_WMV3:
1433 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1434 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "WMV3", NULL);
1436 case AV_CODEC_ID_VC1:
1438 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1439 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "WVC1", NULL);
1441 case AV_CODEC_ID_QDM2:
1443 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-qdm2",
1447 case AV_CODEC_ID_MSZH:
1449 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-mszh",
1453 case AV_CODEC_ID_ZLIB:
1455 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-zlib",
1459 case AV_CODEC_ID_TRUEMOTION1:
1461 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1462 "video/x-truemotion", "trueversion", G_TYPE_INT, 1, NULL);
1464 case AV_CODEC_ID_TRUEMOTION2:
1466 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1467 "video/x-truemotion", "trueversion", G_TYPE_INT, 2, NULL);
1470 case AV_CODEC_ID_ULTI:
1472 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1473 "video/x-ultimotion", NULL);
1476 case AV_CODEC_ID_TSCC:
1478 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1479 "video/x-camtasia", NULL);
1481 gst_caps_set_simple (caps,
1482 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1484 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1488 case AV_CODEC_ID_TSCC2:
1490 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1491 "video/x-tscc", "tsccversion", G_TYPE_INT, 2, NULL);
1494 case AV_CODEC_ID_KMVC:
1496 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-kmvc",
1500 case AV_CODEC_ID_NUV:
1502 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-nuv",
1506 case AV_CODEC_ID_GIF:
1508 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/gif",
1512 case AV_CODEC_ID_PNG:
1514 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/png",
1518 case AV_CODEC_ID_PPM:
1520 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/ppm",
1524 case AV_CODEC_ID_PBM:
1526 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/pbm",
1530 case AV_CODEC_ID_PAM:
1532 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1533 "image/x-portable-anymap", NULL);
1536 case AV_CODEC_ID_PGM:
1538 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1539 "image/x-portable-graymap", NULL);
1542 case AV_CODEC_ID_PCX:
1544 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-pcx",
1548 case AV_CODEC_ID_SGI:
1550 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-sgi",
1554 case AV_CODEC_ID_TARGA:
1556 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-tga",
1560 case AV_CODEC_ID_TIFF:
1562 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/tiff",
1566 case AV_CODEC_ID_SUNRAST:
1568 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1569 "image/x-sun-raster", NULL);
1572 case AV_CODEC_ID_SMC:
1574 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-smc",
1578 case AV_CODEC_ID_QDRAW:
1580 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-qdrw",
1584 case AV_CODEC_ID_DNXHD:
1586 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dnxhd",
1590 case AV_CODEC_ID_PRORES:
1592 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1593 "video/x-prores", NULL);
1596 case AV_CODEC_ID_MIMIC:
1598 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-mimic",
1602 case AV_CODEC_ID_VMNC:
1604 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vmnc",
1608 case AV_CODEC_ID_TRUESPEECH:
1610 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1611 "audio/x-truespeech", NULL);
1614 case AV_CODEC_ID_QCELP:
1616 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/qcelp",
1620 case AV_CODEC_ID_AMV:
1622 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-amv",
1626 case AV_CODEC_ID_AASC:
1628 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-aasc",
1632 case AV_CODEC_ID_LOCO:
1634 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-loco",
1638 case AV_CODEC_ID_ZMBV:
1640 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-zmbv",
1644 case AV_CODEC_ID_LAGARITH:
1646 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1647 "video/x-lagarith", NULL);
1650 case AV_CODEC_ID_CSCD:
1652 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1653 "video/x-camstudio", NULL);
1655 gst_caps_set_simple (caps,
1656 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1658 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1662 case AV_CODEC_ID_WS_VQA:
1663 case AV_CODEC_ID_IDCIN:
1664 case AV_CODEC_ID_8BPS:
1665 case AV_CODEC_ID_FLIC:
1666 case AV_CODEC_ID_VMDVIDEO:
1667 case AV_CODEC_ID_VMDAUDIO:
1668 case AV_CODEC_ID_VIXL:
1669 case AV_CODEC_ID_QPEG:
1670 case AV_CODEC_ID_PGMYUV:
1671 case AV_CODEC_ID_FFVHUFF:
1672 case AV_CODEC_ID_WNV1:
1673 case AV_CODEC_ID_MP3ADU:
1674 case AV_CODEC_ID_MP3ON4:
1675 case AV_CODEC_ID_WESTWOOD_SND1:
1676 case AV_CODEC_ID_MMVIDEO:
1677 case AV_CODEC_ID_AVS:
1678 case AV_CODEC_ID_CAVS:
1682 /* weird quasi-codecs for the demuxers only */
1683 case AV_CODEC_ID_PCM_S16LE:
1684 case AV_CODEC_ID_PCM_S16BE:
1685 case AV_CODEC_ID_PCM_U16LE:
1686 case AV_CODEC_ID_PCM_U16BE:
1687 case AV_CODEC_ID_PCM_S8:
1688 case AV_CODEC_ID_PCM_U8:
1690 GstAudioFormat format;
1693 case AV_CODEC_ID_PCM_S16LE:
1694 format = GST_AUDIO_FORMAT_S16LE;
1696 case AV_CODEC_ID_PCM_S16BE:
1697 format = GST_AUDIO_FORMAT_S16BE;
1699 case AV_CODEC_ID_PCM_U16LE:
1700 format = GST_AUDIO_FORMAT_U16LE;
1702 case AV_CODEC_ID_PCM_U16BE:
1703 format = GST_AUDIO_FORMAT_U16BE;
1705 case AV_CODEC_ID_PCM_S8:
1706 format = GST_AUDIO_FORMAT_S8;
1708 case AV_CODEC_ID_PCM_U8:
1709 format = GST_AUDIO_FORMAT_U8;
1713 g_assert (0); /* don't worry, we never get here */
1718 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-raw",
1719 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
1720 "layout", G_TYPE_STRING, "interleaved", NULL);
1724 case AV_CODEC_ID_PCM_MULAW:
1726 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mulaw",
1730 case AV_CODEC_ID_PCM_ALAW:
1732 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-alaw",
1736 case AV_CODEC_ID_ADPCM_G722:
1738 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/G722",
1741 gst_caps_set_simple (caps,
1742 "block_align", G_TYPE_INT, context->block_align,
1743 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1746 case AV_CODEC_ID_ADPCM_G726:
1748 /* the G726 decoder can also handle G721 */
1750 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-adpcm",
1751 "layout", G_TYPE_STRING, "g726", NULL);
1753 gst_caps_set_simple (caps,
1754 "block_align", G_TYPE_INT, context->block_align,
1755 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1758 gst_caps_append (caps, gst_caps_new_simple ("audio/x-adpcm",
1759 "layout", G_TYPE_STRING, "g721",
1760 "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, 8000, NULL));
1764 case AV_CODEC_ID_ADPCM_IMA_QT:
1765 case AV_CODEC_ID_ADPCM_IMA_WAV:
1766 case AV_CODEC_ID_ADPCM_IMA_DK3:
1767 case AV_CODEC_ID_ADPCM_IMA_DK4:
1768 case AV_CODEC_ID_ADPCM_IMA_WS:
1769 case AV_CODEC_ID_ADPCM_IMA_SMJPEG:
1770 case AV_CODEC_ID_ADPCM_IMA_AMV:
1771 case AV_CODEC_ID_ADPCM_IMA_ISS:
1772 case AV_CODEC_ID_ADPCM_IMA_EA_EACS:
1773 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
1774 case AV_CODEC_ID_ADPCM_MS:
1775 case AV_CODEC_ID_ADPCM_4XM:
1776 case AV_CODEC_ID_ADPCM_XA:
1777 case AV_CODEC_ID_ADPCM_ADX:
1778 case AV_CODEC_ID_ADPCM_EA:
1779 case AV_CODEC_ID_ADPCM_CT:
1780 case AV_CODEC_ID_ADPCM_SWF:
1781 case AV_CODEC_ID_ADPCM_YAMAHA:
1782 case AV_CODEC_ID_ADPCM_SBPRO_2:
1783 case AV_CODEC_ID_ADPCM_SBPRO_3:
1784 case AV_CODEC_ID_ADPCM_SBPRO_4:
1785 case AV_CODEC_ID_ADPCM_EA_R1:
1786 case AV_CODEC_ID_ADPCM_EA_R2:
1787 case AV_CODEC_ID_ADPCM_EA_R3:
1788 case AV_CODEC_ID_ADPCM_EA_MAXIS_XA:
1789 case AV_CODEC_ID_ADPCM_EA_XAS:
1790 case AV_CODEC_ID_ADPCM_THP:
1792 const gchar *layout = NULL;
1795 case AV_CODEC_ID_ADPCM_IMA_QT:
1796 layout = "quicktime";
1798 case AV_CODEC_ID_ADPCM_IMA_WAV:
1801 case AV_CODEC_ID_ADPCM_IMA_DK3:
1804 case AV_CODEC_ID_ADPCM_IMA_DK4:
1807 case AV_CODEC_ID_ADPCM_IMA_WS:
1808 layout = "westwood";
1810 case AV_CODEC_ID_ADPCM_IMA_SMJPEG:
1813 case AV_CODEC_ID_ADPCM_IMA_AMV:
1816 case AV_CODEC_ID_ADPCM_IMA_ISS:
1819 case AV_CODEC_ID_ADPCM_IMA_EA_EACS:
1822 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
1825 case AV_CODEC_ID_ADPCM_MS:
1826 layout = "microsoft";
1828 case AV_CODEC_ID_ADPCM_4XM:
1831 case AV_CODEC_ID_ADPCM_XA:
1834 case AV_CODEC_ID_ADPCM_ADX:
1837 case AV_CODEC_ID_ADPCM_EA:
1840 case AV_CODEC_ID_ADPCM_CT:
1843 case AV_CODEC_ID_ADPCM_SWF:
1846 case AV_CODEC_ID_ADPCM_YAMAHA:
1849 case AV_CODEC_ID_ADPCM_SBPRO_2:
1852 case AV_CODEC_ID_ADPCM_SBPRO_3:
1855 case AV_CODEC_ID_ADPCM_SBPRO_4:
1858 case AV_CODEC_ID_ADPCM_EA_R1:
1861 case AV_CODEC_ID_ADPCM_EA_R2:
1864 case AV_CODEC_ID_ADPCM_EA_R3:
1867 case AV_CODEC_ID_ADPCM_EA_MAXIS_XA:
1868 layout = "ea-maxis-xa";
1870 case AV_CODEC_ID_ADPCM_EA_XAS:
1873 case AV_CODEC_ID_ADPCM_THP:
1877 g_assert (0); /* don't worry, we never get here */
1881 /* FIXME: someone please check whether we need additional properties
1882 * in this caps definition. */
1884 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-adpcm",
1885 "layout", G_TYPE_STRING, layout, NULL);
1887 gst_caps_set_simple (caps,
1888 "block_align", G_TYPE_INT, context->block_align,
1889 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1893 case AV_CODEC_ID_AMR_NB:
1895 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/AMR",
1899 case AV_CODEC_ID_AMR_WB:
1901 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/AMR-WB",
1905 case AV_CODEC_ID_GSM:
1907 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-gsm",
1911 case AV_CODEC_ID_GSM_MS:
1913 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/ms-gsm",
1917 case AV_CODEC_ID_NELLYMOSER:
1919 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1920 "audio/x-nellymoser", NULL);
1923 case AV_CODEC_ID_SIPR:
1926 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-sipro",
1929 gst_caps_set_simple (caps,
1930 "leaf_size", G_TYPE_INT, context->block_align,
1931 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1936 case AV_CODEC_ID_RA_144:
1937 case AV_CODEC_ID_RA_288:
1938 case AV_CODEC_ID_COOK:
1943 case AV_CODEC_ID_RA_144:
1946 case AV_CODEC_ID_RA_288:
1949 case AV_CODEC_ID_COOK:
1956 /* FIXME: properties? */
1958 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1959 "audio/x-pn-realaudio", "raversion", G_TYPE_INT, version, NULL);
1961 gst_caps_set_simple (caps,
1962 "leaf_size", G_TYPE_INT, context->block_align,
1963 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1968 case AV_CODEC_ID_ROQ_DPCM:
1969 case AV_CODEC_ID_INTERPLAY_DPCM:
1970 case AV_CODEC_ID_XAN_DPCM:
1971 case AV_CODEC_ID_SOL_DPCM:
1973 const gchar *layout = NULL;
1976 case AV_CODEC_ID_ROQ_DPCM:
1979 case AV_CODEC_ID_INTERPLAY_DPCM:
1980 layout = "interplay";
1982 case AV_CODEC_ID_XAN_DPCM:
1985 case AV_CODEC_ID_SOL_DPCM:
1989 g_assert (0); /* don't worry, we never get here */
1993 /* FIXME: someone please check whether we need additional properties
1994 * in this caps definition. */
1996 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dpcm",
1997 "layout", G_TYPE_STRING, layout, NULL);
1999 gst_caps_set_simple (caps,
2000 "block_align", G_TYPE_INT, context->block_align,
2001 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
2005 case AV_CODEC_ID_SHORTEN:
2006 caps = gst_caps_new_empty_simple ("audio/x-shorten");
2009 case AV_CODEC_ID_ALAC:
2011 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-alac",
2014 gst_caps_set_simple (caps,
2015 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
2019 case AV_CODEC_ID_FLAC:
2020 /* Note that ffmpeg has no encoder yet, but just for safety. In the
2021 * encoder case, we want to add things like samplerate, channels... */
2023 caps = gst_caps_new_empty_simple ("audio/x-flac");
2027 case AV_CODEC_ID_S302M:
2028 caps = gst_caps_new_empty_simple ("audio/x-smpte-302m");
2031 case AV_CODEC_ID_DVD_SUBTITLE:
2032 case AV_CODEC_ID_DVB_SUBTITLE:
2035 case AV_CODEC_ID_BMP:
2036 caps = gst_caps_new_empty_simple ("image/bmp");
2038 case AV_CODEC_ID_TTA:
2040 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-tta",
2043 gst_caps_set_simple (caps,
2044 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
2047 case AV_CODEC_ID_TWINVQ:
2049 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
2050 "audio/x-twin-vq", NULL);
2053 GST_DEBUG ("Unknown codec ID %d, please add mapping here", codec_id);
2060 if ((codec = avcodec_find_decoder (codec_id)) ||
2061 (codec = avcodec_find_encoder (codec_id))) {
2064 GST_LOG ("Could not create stream format caps for %s", codec->name);
2066 switch (codec->type) {
2067 case AVMEDIA_TYPE_VIDEO:
2068 mime = g_strdup_printf ("video/x-gst-av-%s", codec->name);
2070 gst_ff_vid_caps_new (context, NULL, codec_id, encode, mime, NULL);
2073 case AVMEDIA_TYPE_AUDIO:
2074 mime = g_strdup_printf ("audio/x-gst-av-%s", codec->name);
2076 gst_ff_aud_caps_new (context, NULL, codec_id, encode, mime, NULL);
2078 gst_caps_set_simple (caps,
2079 "block_align", G_TYPE_INT, context->block_align,
2080 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
2091 /* set private data */
2092 if (context && context->extradata_size > 0) {
2093 GstBuffer *data = gst_buffer_new_and_alloc (context->extradata_size);
2095 gst_buffer_fill (data, 0, context->extradata, context->extradata_size);
2096 gst_caps_set_simple (caps, "codec_data", GST_TYPE_BUFFER, data, NULL);
2097 gst_buffer_unref (data);
2100 GST_LOG ("caps for codec_id=%d: %" GST_PTR_FORMAT, codec_id, caps);
2103 GST_LOG ("No caps found for codec_id=%d", codec_id);
2109 /* Convert a FFMPEG Pixel Format and optional AVCodecContext
2110 * to a GstCaps. If the context is ommitted, no fixed values
2111 * for video/audio size will be included in the GstCaps
2113 * See below for usefullness
2117 gst_ffmpeg_pixfmt_to_caps (enum PixelFormat pix_fmt, AVCodecContext * context,
2118 enum AVCodecID codec_id)
2120 GstCaps *caps = NULL;
2121 GstVideoFormat format;
2123 format = gst_ffmpeg_pixfmt_to_videoformat (pix_fmt);
2125 if (format != GST_VIDEO_FORMAT_UNKNOWN) {
2126 caps = gst_ff_vid_caps_new (context, NULL, codec_id, TRUE, "video/x-raw",
2127 "format", G_TYPE_STRING, gst_video_format_to_string (format), NULL);
2131 GST_DEBUG ("caps for pix_fmt=%d: %" GST_PTR_FORMAT, pix_fmt, caps);
2133 GST_LOG ("No caps found for pix_fmt=%d", pix_fmt);
2140 gst_ffmpeg_smpfmt_to_audioformat (enum AVSampleFormat sample_fmt)
2142 switch (sample_fmt) {
2143 case AV_SAMPLE_FMT_U8:
2144 case AV_SAMPLE_FMT_U8P:
2145 return GST_AUDIO_FORMAT_U8;
2147 case AV_SAMPLE_FMT_S16:
2148 case AV_SAMPLE_FMT_S16P:
2149 return GST_AUDIO_FORMAT_S16;
2151 case AV_SAMPLE_FMT_S32:
2152 case AV_SAMPLE_FMT_S32P:
2153 return GST_AUDIO_FORMAT_S32;
2155 case AV_SAMPLE_FMT_FLT:
2156 case AV_SAMPLE_FMT_FLTP:
2157 return GST_AUDIO_FORMAT_F32;
2159 case AV_SAMPLE_FMT_DBL:
2160 case AV_SAMPLE_FMT_DBLP:
2161 return GST_AUDIO_FORMAT_F64;
2165 return GST_AUDIO_FORMAT_UNKNOWN;
2170 /* Convert a FFMPEG Sample Format and optional AVCodecContext
2171 * to a GstCaps. If the context is ommitted, no fixed values
2172 * for video/audio size will be included in the GstCaps
2174 * See below for usefullness
2178 gst_ffmpeg_smpfmt_to_caps (enum AVSampleFormat sample_fmt,
2179 AVCodecContext * context, AVCodec * codec, enum AVCodecID codec_id)
2181 GstCaps *caps = NULL;
2182 GstAudioFormat format;
2184 format = gst_ffmpeg_smpfmt_to_audioformat (sample_fmt);
2186 if (format != GST_AUDIO_FORMAT_UNKNOWN) {
2187 caps = gst_ff_aud_caps_new (context, codec, codec_id, TRUE, "audio/x-raw",
2188 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
2189 "layout", G_TYPE_STRING, "interleaved", NULL);
2190 GST_LOG ("caps for sample_fmt=%d: %" GST_PTR_FORMAT, sample_fmt, caps);
2192 GST_LOG ("No caps found for sample_fmt=%d", sample_fmt);
2199 caps_has_field (GstCaps * caps, const gchar * field)
2203 n = gst_caps_get_size (caps);
2204 for (i = 0; i < n; i++) {
2205 GstStructure *s = gst_caps_get_structure (caps, i);
2207 if (gst_structure_has_field (s, field))
2215 gst_ffmpeg_codectype_to_audio_caps (AVCodecContext * context,
2216 enum AVCodecID codec_id, gboolean encode, AVCodec * codec)
2218 GstCaps *caps = NULL;
2220 GST_DEBUG ("context:%p, codec_id:%d, encode:%d, codec:%p",
2221 context, codec_id, encode, codec);
2223 GST_DEBUG ("sample_fmts:%p, samplerates:%p",
2224 codec->sample_fmts, codec->supported_samplerates);
2227 /* Specific codec context */
2229 gst_ffmpeg_smpfmt_to_caps (context->sample_fmt, context, codec,
2232 caps = gst_ff_aud_caps_new (context, codec, codec_id, encode, "audio/x-raw",
2233 "layout", G_TYPE_STRING, "interleaved", NULL);
2234 if (!caps_has_field (caps, "format"))
2235 gst_ffmpeg_audio_set_sample_fmts (caps,
2236 codec ? codec->sample_fmts : NULL);
2243 gst_ffmpeg_codectype_to_video_caps (AVCodecContext * context,
2244 enum AVCodecID codec_id, gboolean encode, AVCodec * codec)
2248 GST_LOG ("context:%p, codec_id:%d, encode:%d, codec:%p",
2249 context, codec_id, encode, codec);
2252 caps = gst_ffmpeg_pixfmt_to_caps (context->pix_fmt, context, codec_id);
2255 gst_ff_vid_caps_new (context, codec, codec_id, encode, "video/x-raw",
2257 if (!caps_has_field (caps, "format"))
2258 gst_ffmpeg_video_set_pix_fmts (caps, codec ? codec->pix_fmts : NULL);
2263 /* Convert a GstCaps (audio/raw) to a FFMPEG SampleFmt
2264 * and other audio properties in a AVCodecContext.
2266 * For usefullness, see below
2270 gst_ffmpeg_caps_to_smpfmt (const GstCaps * caps,
2271 AVCodecContext * context, gboolean raw)
2273 GstStructure *structure;
2275 GstAudioFormat format = GST_AUDIO_FORMAT_UNKNOWN;
2277 g_return_if_fail (gst_caps_get_size (caps) == 1);
2279 structure = gst_caps_get_structure (caps, 0);
2281 gst_structure_get_int (structure, "channels", &context->channels);
2282 gst_structure_get_int (structure, "rate", &context->sample_rate);
2283 gst_structure_get_int (structure, "block_align", &context->block_align);
2284 gst_structure_get_int (structure, "bitrate", &context->bit_rate);
2289 if (gst_structure_has_name (structure, "audio/x-raw")) {
2290 if ((fmt = gst_structure_get_string (structure, "format"))) {
2291 format = gst_audio_format_from_string (fmt);
2296 case GST_AUDIO_FORMAT_F32:
2297 context->sample_fmt = AV_SAMPLE_FMT_FLT;
2299 case GST_AUDIO_FORMAT_F64:
2300 context->sample_fmt = AV_SAMPLE_FMT_DBL;
2302 case GST_AUDIO_FORMAT_S32:
2303 context->sample_fmt = AV_SAMPLE_FMT_S32;
2305 case GST_AUDIO_FORMAT_S16:
2306 context->sample_fmt = AV_SAMPLE_FMT_S16;
2313 /* Convert a GstCaps (video/raw) to a FFMPEG PixFmt
2314 * and other video properties in a AVCodecContext.
2316 * For usefullness, see below
2320 gst_ffmpeg_caps_to_pixfmt (const GstCaps * caps,
2321 AVCodecContext * context, gboolean raw)
2323 GstStructure *structure;
2325 const GValue *par = NULL;
2327 GstVideoFormat format = GST_VIDEO_FORMAT_UNKNOWN;
2329 GST_DEBUG ("converting caps %" GST_PTR_FORMAT, caps);
2330 g_return_if_fail (gst_caps_get_size (caps) == 1);
2331 structure = gst_caps_get_structure (caps, 0);
2333 gst_structure_get_int (structure, "width", &context->width);
2334 gst_structure_get_int (structure, "height", &context->height);
2335 gst_structure_get_int (structure, "bpp", &context->bits_per_coded_sample);
2337 fps = gst_structure_get_value (structure, "framerate");
2338 if (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps)) {
2340 /* somehow these seem mixed up.. */
2341 context->time_base.den = gst_value_get_fraction_numerator (fps);
2342 context->time_base.num = gst_value_get_fraction_denominator (fps);
2343 context->ticks_per_frame = 1;
2345 GST_DEBUG ("setting framerate %d/%d = %lf",
2346 context->time_base.den, context->time_base.num,
2347 1. * context->time_base.den / context->time_base.num);
2350 par = gst_structure_get_value (structure, "pixel-aspect-ratio");
2351 if (par && GST_VALUE_HOLDS_FRACTION (par)) {
2353 context->sample_aspect_ratio.num = gst_value_get_fraction_numerator (par);
2354 context->sample_aspect_ratio.den = gst_value_get_fraction_denominator (par);
2356 GST_DEBUG ("setting pixel-aspect-ratio %d/%d = %lf",
2357 context->sample_aspect_ratio.den, context->sample_aspect_ratio.num,
2358 1. * context->sample_aspect_ratio.den /
2359 context->sample_aspect_ratio.num);
2365 g_return_if_fail (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps));
2367 if (gst_structure_has_name (structure, "video/x-raw")) {
2368 if ((fmt = gst_structure_get_string (structure, "format"))) {
2369 format = gst_video_format_from_string (fmt);
2374 case GST_VIDEO_FORMAT_YUY2:
2375 context->pix_fmt = PIX_FMT_YUYV422;
2377 case GST_VIDEO_FORMAT_I420:
2378 context->pix_fmt = PIX_FMT_YUV420P;
2380 case GST_VIDEO_FORMAT_A420:
2381 context->pix_fmt = PIX_FMT_YUVA420P;
2383 case GST_VIDEO_FORMAT_Y41B:
2384 context->pix_fmt = PIX_FMT_YUV411P;
2386 case GST_VIDEO_FORMAT_Y42B:
2387 context->pix_fmt = PIX_FMT_YUV422P;
2389 case GST_VIDEO_FORMAT_YUV9:
2390 context->pix_fmt = PIX_FMT_YUV410P;
2392 case GST_VIDEO_FORMAT_Y444:
2393 context->pix_fmt = PIX_FMT_YUV444P;
2395 case GST_VIDEO_FORMAT_GRAY8:
2396 context->pix_fmt = PIX_FMT_GRAY8;
2398 case GST_VIDEO_FORMAT_xRGB:
2399 #if (G_BYTE_ORDER == G_BIG_ENDIAN)
2400 context->pix_fmt = PIX_FMT_RGB32;
2403 case GST_VIDEO_FORMAT_BGRx:
2404 #if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
2405 context->pix_fmt = PIX_FMT_RGB32;
2408 case GST_VIDEO_FORMAT_RGB:
2409 context->pix_fmt = PIX_FMT_RGB24;
2411 case GST_VIDEO_FORMAT_BGR:
2412 context->pix_fmt = PIX_FMT_BGR24;
2414 case GST_VIDEO_FORMAT_RGB16:
2415 context->pix_fmt = PIX_FMT_RGB565;
2417 case GST_VIDEO_FORMAT_RGB15:
2418 context->pix_fmt = PIX_FMT_RGB555;
2420 case GST_VIDEO_FORMAT_RGB8P:
2421 context->pix_fmt = PIX_FMT_PAL8;
2430 GstVideoFormat format;
2431 enum PixelFormat pixfmt;
2434 /* FIXME : FILLME */
2435 static const PixToFmt pixtofmttable[] = {
2436 /* GST_VIDEO_FORMAT_I420, */
2437 {GST_VIDEO_FORMAT_I420, PIX_FMT_YUV420P},
2438 /* Note : this should use a different chroma placement */
2439 {GST_VIDEO_FORMAT_I420, PIX_FMT_YUVJ420P},
2441 /* GST_VIDEO_FORMAT_YV12, */
2442 /* GST_VIDEO_FORMAT_YUY2, */
2443 {GST_VIDEO_FORMAT_YUY2, PIX_FMT_YUYV422},
2444 /* GST_VIDEO_FORMAT_UYVY, */
2445 {GST_VIDEO_FORMAT_UYVY, PIX_FMT_UYVY422},
2446 /* GST_VIDEO_FORMAT_AYUV, */
2447 /* GST_VIDEO_FORMAT_RGBx, */
2448 /* GST_VIDEO_FORMAT_BGRx, */
2449 /* GST_VIDEO_FORMAT_xRGB, */
2450 /* GST_VIDEO_FORMAT_xBGR, */
2451 /* GST_VIDEO_FORMAT_RGBA, */
2452 {GST_VIDEO_FORMAT_RGBA, PIX_FMT_RGBA},
2453 /* GST_VIDEO_FORMAT_BGRA, */
2454 {GST_VIDEO_FORMAT_BGRA, PIX_FMT_BGRA},
2455 /* GST_VIDEO_FORMAT_ARGB, */
2456 {GST_VIDEO_FORMAT_ARGB, PIX_FMT_ARGB},
2457 /* GST_VIDEO_FORMAT_ABGR, */
2458 {GST_VIDEO_FORMAT_ABGR, PIX_FMT_ABGR},
2459 /* GST_VIDEO_FORMAT_RGB, */
2460 {GST_VIDEO_FORMAT_RGB, PIX_FMT_RGB24},
2461 /* GST_VIDEO_FORMAT_BGR, */
2462 {GST_VIDEO_FORMAT_BGR, PIX_FMT_BGR24},
2463 /* GST_VIDEO_FORMAT_Y41B, */
2464 {GST_VIDEO_FORMAT_Y41B, PIX_FMT_YUV411P},
2465 /* GST_VIDEO_FORMAT_Y42B, */
2466 {GST_VIDEO_FORMAT_Y42B, PIX_FMT_YUV422P},
2467 {GST_VIDEO_FORMAT_Y42B, PIX_FMT_YUVJ422P},
2468 /* GST_VIDEO_FORMAT_YVYU, */
2469 /* GST_VIDEO_FORMAT_Y444, */
2470 {GST_VIDEO_FORMAT_Y444, PIX_FMT_YUV444P},
2471 {GST_VIDEO_FORMAT_Y444, PIX_FMT_YUVJ444P},
2472 /* GST_VIDEO_FORMAT_v210, */
2473 /* GST_VIDEO_FORMAT_v216, */
2474 /* GST_VIDEO_FORMAT_NV12, */
2475 {GST_VIDEO_FORMAT_NV12, PIX_FMT_NV12},
2476 /* GST_VIDEO_FORMAT_NV21, */
2477 {GST_VIDEO_FORMAT_NV21, PIX_FMT_NV21},
2478 /* GST_VIDEO_FORMAT_GRAY8, */
2479 {GST_VIDEO_FORMAT_GRAY8, PIX_FMT_GRAY8},
2480 /* GST_VIDEO_FORMAT_GRAY16_BE, */
2481 {GST_VIDEO_FORMAT_GRAY16_BE, PIX_FMT_GRAY16BE},
2482 /* GST_VIDEO_FORMAT_GRAY16_LE, */
2483 {GST_VIDEO_FORMAT_GRAY16_LE, PIX_FMT_GRAY16LE},
2484 /* GST_VIDEO_FORMAT_v308, */
2485 /* GST_VIDEO_FORMAT_Y800, */
2486 /* GST_VIDEO_FORMAT_Y16, */
2487 /* GST_VIDEO_FORMAT_RGB16, */
2488 {GST_VIDEO_FORMAT_RGB16, PIX_FMT_RGB565},
2489 /* GST_VIDEO_FORMAT_BGR16, */
2490 /* GST_VIDEO_FORMAT_RGB15, */
2491 {GST_VIDEO_FORMAT_RGB15, PIX_FMT_RGB555},
2492 /* GST_VIDEO_FORMAT_BGR15, */
2493 /* GST_VIDEO_FORMAT_UYVP, */
2494 /* GST_VIDEO_FORMAT_A420, */
2495 {GST_VIDEO_FORMAT_A420, PIX_FMT_YUVA420P},
2496 /* GST_VIDEO_FORMAT_RGB8_PALETTED, */
2497 {GST_VIDEO_FORMAT_RGB8P, PIX_FMT_PAL8},
2498 /* GST_VIDEO_FORMAT_YUV9, */
2499 {GST_VIDEO_FORMAT_YUV9, PIX_FMT_YUV410P},
2500 /* GST_VIDEO_FORMAT_YVU9, */
2501 /* GST_VIDEO_FORMAT_IYU1, */
2502 /* GST_VIDEO_FORMAT_ARGB64, */
2503 /* GST_VIDEO_FORMAT_AYUV64, */
2504 /* GST_VIDEO_FORMAT_r210, */
2505 {GST_VIDEO_FORMAT_I420_10LE, PIX_FMT_YUV420P10LE},
2506 {GST_VIDEO_FORMAT_I420_10BE, PIX_FMT_YUV420P10BE},
2507 {GST_VIDEO_FORMAT_I422_10LE, PIX_FMT_YUV422P10LE},
2508 {GST_VIDEO_FORMAT_I422_10BE, PIX_FMT_YUV422P10BE},
2509 {GST_VIDEO_FORMAT_Y444_10LE, PIX_FMT_YUV444P10LE},
2510 {GST_VIDEO_FORMAT_Y444_10BE, PIX_FMT_YUV444P10BE},
2511 {GST_VIDEO_FORMAT_GBR, PIX_FMT_GBRP},
2512 {GST_VIDEO_FORMAT_GBR_10LE, PIX_FMT_GBRP10LE},
2513 {GST_VIDEO_FORMAT_GBR_10BE, PIX_FMT_GBRP10BE},
2517 gst_ffmpeg_pixfmt_to_videoformat (enum PixelFormat pixfmt)
2521 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2522 if (pixtofmttable[i].pixfmt == pixfmt)
2523 return pixtofmttable[i].format;
2525 GST_DEBUG ("Unknown pixel format %d", pixfmt);
2526 return GST_VIDEO_FORMAT_UNKNOWN;
2530 gst_ffmpeg_videoformat_to_pixfmt (GstVideoFormat format)
2534 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2535 if (pixtofmttable[i].format == format)
2536 return pixtofmttable[i].pixfmt;
2537 return PIX_FMT_NONE;
2541 gst_ffmpeg_videoinfo_to_context (GstVideoInfo * info, AVCodecContext * context)
2545 context->width = GST_VIDEO_INFO_WIDTH (info);
2546 context->height = GST_VIDEO_INFO_HEIGHT (info);
2547 for (i = 0; i < GST_VIDEO_INFO_N_COMPONENTS (info); i++)
2548 bpp += GST_VIDEO_INFO_COMP_DEPTH (info, i);
2549 context->bits_per_coded_sample = bpp;
2551 context->ticks_per_frame = 1;
2552 if (GST_VIDEO_INFO_FPS_N (info) == 0) {
2553 GST_DEBUG ("Using 25/1 framerate");
2554 context->time_base.den = 25;
2555 context->time_base.num = 1;
2557 context->time_base.den = GST_VIDEO_INFO_FPS_N (info);
2558 context->time_base.num = GST_VIDEO_INFO_FPS_D (info);
2561 context->sample_aspect_ratio.num = GST_VIDEO_INFO_PAR_N (info);
2562 context->sample_aspect_ratio.den = GST_VIDEO_INFO_PAR_D (info);
2565 gst_ffmpeg_videoformat_to_pixfmt (GST_VIDEO_INFO_FORMAT (info));
2569 gst_ffmpeg_audioinfo_to_context (GstAudioInfo * info, AVCodecContext * context)
2571 const AVCodec *codec;
2572 const enum AVSampleFormat *smpl_fmts;
2573 enum AVSampleFormat smpl_fmt = -1;
2575 context->channels = info->channels;
2576 context->sample_rate = info->rate;
2577 context->channel_layout =
2578 gst_ffmpeg_channel_positions_to_layout (info->position, info->channels);
2580 codec = context->codec;
2582 smpl_fmts = codec->sample_fmts;
2584 switch (info->finfo->format) {
2585 case GST_AUDIO_FORMAT_F32:
2587 while (*smpl_fmts != -1) {
2588 if (*smpl_fmts == AV_SAMPLE_FMT_FLT) {
2589 smpl_fmt = *smpl_fmts;
2591 } else if (*smpl_fmts == AV_SAMPLE_FMT_FLTP) {
2592 smpl_fmt = *smpl_fmts;
2598 smpl_fmt = AV_SAMPLE_FMT_FLT;
2601 case GST_AUDIO_FORMAT_F64:
2603 while (*smpl_fmts != -1) {
2604 if (*smpl_fmts == AV_SAMPLE_FMT_DBL) {
2605 smpl_fmt = *smpl_fmts;
2607 } else if (*smpl_fmts == AV_SAMPLE_FMT_DBLP) {
2608 smpl_fmt = *smpl_fmts;
2614 smpl_fmt = AV_SAMPLE_FMT_DBL;
2617 case GST_AUDIO_FORMAT_S32:
2619 while (*smpl_fmts != -1) {
2620 if (*smpl_fmts == AV_SAMPLE_FMT_S32) {
2621 smpl_fmt = *smpl_fmts;
2623 } else if (*smpl_fmts == AV_SAMPLE_FMT_S32P) {
2624 smpl_fmt = *smpl_fmts;
2630 smpl_fmt = AV_SAMPLE_FMT_S32;
2633 case GST_AUDIO_FORMAT_S16:
2635 while (*smpl_fmts != -1) {
2636 if (*smpl_fmts == AV_SAMPLE_FMT_S16) {
2637 smpl_fmt = *smpl_fmts;
2639 } else if (*smpl_fmts == AV_SAMPLE_FMT_S16P) {
2640 smpl_fmt = *smpl_fmts;
2646 smpl_fmt = AV_SAMPLE_FMT_S16;
2649 case GST_AUDIO_FORMAT_U8:
2651 while (*smpl_fmts != -1) {
2652 if (*smpl_fmts == AV_SAMPLE_FMT_U8) {
2653 smpl_fmt = *smpl_fmts;
2655 } else if (*smpl_fmts == AV_SAMPLE_FMT_U8P) {
2656 smpl_fmt = *smpl_fmts;
2662 smpl_fmt = AV_SAMPLE_FMT_U8;
2669 g_assert (smpl_fmt != -1);
2671 context->sample_fmt = smpl_fmt;
2674 /* Convert a GstCaps and a FFMPEG codec Type to a
2675 * AVCodecContext. If the context is ommitted, no fixed values
2676 * for video/audio size will be included in the context
2678 * AVMediaType is primarily meant for uncompressed data GstCaps!
2682 gst_ffmpeg_caps_with_codectype (enum AVMediaType type,
2683 const GstCaps * caps, AVCodecContext * context)
2685 if (context == NULL)
2689 case AVMEDIA_TYPE_VIDEO:
2690 gst_ffmpeg_caps_to_pixfmt (caps, context, TRUE);
2693 case AVMEDIA_TYPE_AUDIO:
2694 gst_ffmpeg_caps_to_smpfmt (caps, context, TRUE);
2705 nal_escape (guint8 * dst, guint8 * src, guint size, guint * destsize)
2709 guint8 *end = src + size;
2712 while (srcp < end) {
2713 if (count == 2 && *srcp <= 0x03) {
2714 GST_DEBUG ("added escape code");
2723 GST_DEBUG ("copy %02x, count %d", *srcp, count);
2726 *destsize = dstp - dst;
2729 /* copy the config, escaping NAL units as we iterate them, if something fails we
2730 * copy everything and hope for the best. */
2732 copy_config (guint8 * dst, guint8 * src, guint size, guint * destsize)
2737 guint nalsize, esize;
2747 cnt = *(srcp + 5) & 0x1f; /* Number of sps */
2749 GST_DEBUG ("num SPS %d", cnt);
2751 memcpy (dstp, srcp, 6);
2755 for (i = 0; i < cnt; i++) {
2756 GST_DEBUG ("copy SPS %d", i);
2757 nalsize = (srcp[0] << 8) | srcp[1];
2758 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2759 dstp[0] = esize >> 8;
2760 dstp[1] = esize & 0xff;
2762 srcp += nalsize + 2;
2765 cnt = *(dstp++) = *(srcp++); /* Number of pps */
2767 GST_DEBUG ("num PPS %d", cnt);
2769 for (i = 0; i < cnt; i++) {
2770 GST_DEBUG ("copy PPS %d", i);
2771 nalsize = (srcp[0] << 8) | srcp[1];
2772 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2773 dstp[0] = esize >> 8;
2774 dstp[1] = esize & 0xff;
2776 srcp += nalsize + 2;
2778 *destsize = dstp - dst;
2784 GST_DEBUG ("something unexpected, doing full copy");
2785 memcpy (dst, src, size);
2793 * caps_with_codecid () transforms a GstCaps for a known codec
2794 * ID into a filled-in context.
2795 * codec_data from caps will override possible extradata already in the context
2799 gst_ffmpeg_caps_with_codecid (enum AVCodecID codec_id,
2800 enum AVMediaType codec_type, const GstCaps * caps, AVCodecContext * context)
2803 const GValue *value;
2806 GST_LOG ("codec_id:%d, codec_type:%d, caps:%" GST_PTR_FORMAT " context:%p",
2807 codec_id, codec_type, caps, context);
2809 if (!context || !gst_caps_get_size (caps))
2812 str = gst_caps_get_structure (caps, 0);
2814 /* extradata parsing (esds [mpeg4], wma/wmv, msmpeg4v1/2/3, etc.) */
2815 if ((value = gst_structure_get_value (str, "codec_data"))) {
2818 buf = gst_value_get_buffer (value);
2819 gst_buffer_map (buf, &map, GST_MAP_READ);
2821 /* free the old one if it is there */
2822 if (context->extradata)
2823 av_free (context->extradata);
2826 if (codec_id == AV_CODEC_ID_H264) {
2829 GST_DEBUG ("copy, escaping codec_data %d", size);
2830 /* ffmpeg h264 expects the codec_data to be escaped, there is no real
2831 * reason for this but let's just escape it for now. Start by allocating
2832 * enough space, x2 is more than enough.
2834 * FIXME, we disabled escaping because some file already contain escaped
2835 * codec_data and then we escape twice and fail. It's better to leave it
2836 * as is, as that is what most players do. */
2837 context->extradata =
2838 av_mallocz (GST_ROUND_UP_16 (size * 2 +
2839 FF_INPUT_BUFFER_PADDING_SIZE));
2840 copy_config (context->extradata, data, size, &extrasize);
2841 GST_DEBUG ("escaped size: %d", extrasize);
2842 context->extradata_size = extrasize;
2846 /* allocate with enough padding */
2847 GST_DEBUG ("copy codec_data");
2848 context->extradata =
2849 av_mallocz (GST_ROUND_UP_16 (map.size +
2850 FF_INPUT_BUFFER_PADDING_SIZE));
2851 memcpy (context->extradata, map.data, map.size);
2852 context->extradata_size = map.size;
2855 /* Hack for VC1. Sometimes the first (length) byte is 0 for some files */
2856 if (codec_id == AV_CODEC_ID_VC1 && map.size > 0 && map.data[0] == 0) {
2857 context->extradata[0] = (guint8) map.size;
2860 GST_DEBUG ("have codec data of size %" G_GSIZE_FORMAT, map.size);
2862 gst_buffer_unmap (buf, &map);
2863 } else if (context->extradata == NULL && codec_id != AV_CODEC_ID_AAC_LATM &&
2864 codec_id != AV_CODEC_ID_FLAC) {
2865 /* no extradata, alloc dummy with 0 sized, some codecs insist on reading
2866 * extradata anyway which makes then segfault. */
2867 context->extradata =
2868 av_mallocz (GST_ROUND_UP_16 (FF_INPUT_BUFFER_PADDING_SIZE));
2869 context->extradata_size = 0;
2870 GST_DEBUG ("no codec data");
2874 case AV_CODEC_ID_MPEG4:
2876 const gchar *mime = gst_structure_get_name (str);
2878 if (!strcmp (mime, "video/x-divx"))
2879 context->codec_tag = GST_MAKE_FOURCC ('D', 'I', 'V', 'X');
2880 else if (!strcmp (mime, "video/x-xvid"))
2881 context->codec_tag = GST_MAKE_FOURCC ('X', 'V', 'I', 'D');
2882 else if (!strcmp (mime, "video/x-3ivx"))
2883 context->codec_tag = GST_MAKE_FOURCC ('3', 'I', 'V', '1');
2884 else if (!strcmp (mime, "video/mpeg"))
2885 context->codec_tag = GST_MAKE_FOURCC ('m', 'p', '4', 'v');
2889 case AV_CODEC_ID_SVQ3:
2890 /* FIXME: this is a workaround for older gst-plugins releases
2891 * (<= 0.8.9). This should be removed at some point, because
2892 * it causes wrong decoded frame order. */
2893 if (!context->extradata) {
2894 gint halfpel_flag, thirdpel_flag, low_delay, unknown_svq3_flag;
2897 if (gst_structure_get_int (str, "halfpel_flag", &halfpel_flag) &&
2898 gst_structure_get_int (str, "thirdpel_flag", &thirdpel_flag) &&
2899 gst_structure_get_int (str, "low_delay", &low_delay) &&
2900 gst_structure_get_int (str, "unknown_svq3_flag",
2901 &unknown_svq3_flag)) {
2902 context->extradata = (guint8 *) av_mallocz (0x64);
2903 g_stpcpy ((gchar *) context->extradata, "SVQ3");
2907 flags |= unknown_svq3_flag;
2909 flags |= halfpel_flag;
2911 flags |= thirdpel_flag;
2914 flags = GUINT16_FROM_LE (flags);
2916 memcpy ((gchar *) context->extradata + 0x62, &flags, 2);
2917 context->extradata_size = 0x64;
2922 case AV_CODEC_ID_MSRLE:
2923 case AV_CODEC_ID_QTRLE:
2924 case AV_CODEC_ID_TSCC:
2925 case AV_CODEC_ID_CSCD:
2926 case AV_CODEC_ID_APE:
2930 if (gst_structure_get_int (str, "depth", &depth)) {
2931 context->bits_per_coded_sample = depth;
2933 GST_WARNING ("No depth field in caps %" GST_PTR_FORMAT, caps);
2939 case AV_CODEC_ID_COOK:
2940 case AV_CODEC_ID_RA_288:
2941 case AV_CODEC_ID_RA_144:
2942 case AV_CODEC_ID_SIPR:
2947 if (gst_structure_get_int (str, "leaf_size", &leaf_size))
2948 context->block_align = leaf_size;
2949 if (gst_structure_get_int (str, "bitrate", &bitrate))
2950 context->bit_rate = bitrate;
2952 case AV_CODEC_ID_ALAC:
2953 gst_structure_get_int (str, "samplesize",
2954 &context->bits_per_coded_sample);
2957 case AV_CODEC_ID_DVVIDEO:
2959 const gchar *format;
2961 if ((format = gst_structure_get_string (str, "format"))) {
2963 if (g_str_equal (format, "YUY2"))
2964 context->pix_fmt = PIX_FMT_YUYV422;
2965 else if (g_str_equal (format, "I420"))
2966 context->pix_fmt = PIX_FMT_YUV420P;
2967 else if (g_str_equal (format, "A420"))
2968 context->pix_fmt = PIX_FMT_YUVA420P;
2969 else if (g_str_equal (format, "Y41B"))
2970 context->pix_fmt = PIX_FMT_YUV411P;
2971 else if (g_str_equal (format, "Y42B"))
2972 context->pix_fmt = PIX_FMT_YUV422P;
2973 else if (g_str_equal (format, "YUV9"))
2974 context->pix_fmt = PIX_FMT_YUV410P;
2976 GST_WARNING ("couldn't convert format %s" " to a pixel format",
2980 GST_WARNING ("No specified format");
2983 case AV_CODEC_ID_H263P:
2987 if (!gst_structure_get_boolean (str, "annex-f", &val) || val)
2988 context->flags |= CODEC_FLAG_4MV;
2990 context->flags &= ~CODEC_FLAG_4MV;
2991 if ((!gst_structure_get_boolean (str, "annex-i", &val) || val) &&
2992 (!gst_structure_get_boolean (str, "annex-t", &val) || val))
2993 context->flags |= CODEC_FLAG_AC_PRED;
2995 context->flags &= ~CODEC_FLAG_AC_PRED;
2996 if (!gst_structure_get_boolean (str, "annex-j", &val) || val)
2997 context->flags |= CODEC_FLAG_LOOP_FILTER;
2999 context->flags &= ~CODEC_FLAG_LOOP_FILTER;
3002 case AV_CODEC_ID_ADPCM_G726:
3004 const gchar *layout;
3006 if ((layout = gst_structure_get_string (str, "layout"))) {
3007 if (!strcmp (layout, "g721")) {
3008 context->sample_rate = 8000;
3009 context->channels = 1;
3010 context->bit_rate = 32000;
3019 if (!gst_caps_is_fixed (caps))
3022 /* common properties (width, height, fps) */
3023 switch (codec_type) {
3024 case AVMEDIA_TYPE_VIDEO:
3025 gst_ffmpeg_caps_to_pixfmt (caps, context,
3026 codec_id == AV_CODEC_ID_RAWVIDEO);
3028 case AVMEDIA_TYPE_AUDIO:
3029 gst_ffmpeg_caps_to_smpfmt (caps, context, FALSE);
3035 /* fixup of default settings */
3037 case AV_CODEC_ID_QCELP:
3038 /* QCELP is always mono, no matter what the caps say */
3039 context->channels = 1;
3041 case AV_CODEC_ID_ADPCM_G726:
3042 if (context->sample_rate && context->bit_rate)
3043 context->bits_per_coded_sample =
3044 context->bit_rate / context->sample_rate;
3051 /* _formatid_to_caps () is meant for muxers/demuxers, it
3052 * transforms a name (ffmpeg way of ID'ing these, why don't
3053 * they have unique numerical IDs?) to the corresponding
3054 * caps belonging to that mux-format
3056 * Note: we don't need any additional info because the caps
3057 * isn't supposed to contain any useful info besides the
3062 gst_ffmpeg_formatid_to_caps (const gchar * format_name)
3064 GstCaps *caps = NULL;
3066 if (!strcmp (format_name, "mpeg")) {
3067 caps = gst_caps_new_simple ("video/mpeg",
3068 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3069 } else if (!strcmp (format_name, "mpegts")) {
3070 caps = gst_caps_new_simple ("video/mpegts",
3071 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3072 } else if (!strcmp (format_name, "rm")) {
3073 caps = gst_caps_new_simple ("application/x-pn-realmedia",
3074 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3075 } else if (!strcmp (format_name, "asf")) {
3076 caps = gst_caps_new_empty_simple ("video/x-ms-asf");
3077 } else if (!strcmp (format_name, "avi")) {
3078 caps = gst_caps_new_empty_simple ("video/x-msvideo");
3079 } else if (!strcmp (format_name, "wav")) {
3080 caps = gst_caps_new_empty_simple ("audio/x-wav");
3081 } else if (!strcmp (format_name, "ape")) {
3082 caps = gst_caps_new_empty_simple ("application/x-ape");
3083 } else if (!strcmp (format_name, "swf")) {
3084 caps = gst_caps_new_empty_simple ("application/x-shockwave-flash");
3085 } else if (!strcmp (format_name, "au")) {
3086 caps = gst_caps_new_empty_simple ("audio/x-au");
3087 } else if (!strcmp (format_name, "dv")) {
3088 caps = gst_caps_new_simple ("video/x-dv",
3089 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3090 } else if (!strcmp (format_name, "4xm")) {
3091 caps = gst_caps_new_empty_simple ("video/x-4xm");
3092 } else if (!strcmp (format_name, "matroska")) {
3093 caps = gst_caps_new_empty_simple ("video/x-matroska");
3094 } else if (!strcmp (format_name, "mp3")) {
3095 caps = gst_caps_new_empty_simple ("application/x-id3");
3096 } else if (!strcmp (format_name, "flic")) {
3097 caps = gst_caps_new_empty_simple ("video/x-fli");
3098 } else if (!strcmp (format_name, "flv")) {
3099 caps = gst_caps_new_empty_simple ("video/x-flv");
3100 } else if (!strcmp (format_name, "tta")) {
3101 caps = gst_caps_new_empty_simple ("audio/x-ttafile");
3102 } else if (!strcmp (format_name, "aiff")) {
3103 caps = gst_caps_new_empty_simple ("audio/x-aiff");
3104 } else if (!strcmp (format_name, "mov_mp4_m4a_3gp_3g2")) {
3106 gst_caps_from_string
3107 ("application/x-3gp; video/quicktime; audio/x-m4a");
3108 } else if (!strcmp (format_name, "mov")) {
3109 caps = gst_caps_from_string ("video/quicktime,variant=(string)apple");
3110 } else if (!strcmp (format_name, "mp4")) {
3111 caps = gst_caps_from_string ("video/quicktime,variant=(string)iso");
3112 } else if (!strcmp (format_name, "3gp")) {
3113 caps = gst_caps_from_string ("video/quicktime,variant=(string)3gpp");
3114 } else if (!strcmp (format_name, "3g2")) {
3115 caps = gst_caps_from_string ("video/quicktime,variant=(string)3g2");
3116 } else if (!strcmp (format_name, "psp")) {
3117 caps = gst_caps_from_string ("video/quicktime,variant=(string)psp");
3118 } else if (!strcmp (format_name, "ipod")) {
3119 caps = gst_caps_from_string ("video/quicktime,variant=(string)ipod");
3120 } else if (!strcmp (format_name, "aac")) {
3121 caps = gst_caps_new_simple ("audio/mpeg",
3122 "mpegversion", G_TYPE_INT, 4, NULL);
3123 } else if (!strcmp (format_name, "gif")) {
3124 caps = gst_caps_from_string ("image/gif");
3125 } else if (!strcmp (format_name, "ogg")) {
3126 caps = gst_caps_from_string ("application/ogg");
3127 } else if (!strcmp (format_name, "mxf") || !strcmp (format_name, "mxf_d10")) {
3128 caps = gst_caps_from_string ("application/mxf");
3129 } else if (!strcmp (format_name, "gxf")) {
3130 caps = gst_caps_from_string ("application/gxf");
3131 } else if (!strcmp (format_name, "yuv4mpegpipe")) {
3132 caps = gst_caps_new_simple ("application/x-yuv4mpeg",
3133 "y4mversion", G_TYPE_INT, 2, NULL);
3134 } else if (!strcmp (format_name, "mpc")) {
3135 caps = gst_caps_from_string ("audio/x-musepack, streamversion = (int) 7");
3136 } else if (!strcmp (format_name, "vqf")) {
3137 caps = gst_caps_from_string ("audio/x-vqf");
3138 } else if (!strcmp (format_name, "nsv")) {
3139 caps = gst_caps_from_string ("video/x-nsv");
3140 } else if (!strcmp (format_name, "amr")) {
3141 caps = gst_caps_from_string ("audio/x-amr-nb-sh");
3142 } else if (!strcmp (format_name, "webm")) {
3143 caps = gst_caps_from_string ("video/webm");
3144 } else if (!strcmp (format_name, "voc")) {
3145 caps = gst_caps_from_string ("audio/x-voc");
3146 } else if (!strcmp (format_name, "pva")) {
3147 caps = gst_caps_from_string ("video/x-pva");
3151 GST_LOG ("Could not create stream format caps for %s", format_name);
3152 name = g_strdup_printf ("application/x-gst-av-%s", format_name);
3153 caps = gst_caps_new_empty_simple (name);
3161 gst_ffmpeg_formatid_get_codecids (const gchar * format_name,
3162 enum AVCodecID ** video_codec_list, enum AVCodecID ** audio_codec_list,
3163 AVOutputFormat * plugin)
3165 static enum AVCodecID tmp_vlist[] = {
3169 static enum AVCodecID tmp_alist[] = {
3174 GST_LOG ("format_name : %s", format_name);
3176 if (!strcmp (format_name, "mp4")) {
3177 static enum AVCodecID mp4_video_list[] = {
3178 AV_CODEC_ID_MPEG4, AV_CODEC_ID_H264,
3182 static enum AVCodecID mp4_audio_list[] = {
3183 AV_CODEC_ID_AAC, AV_CODEC_ID_MP3,
3187 *video_codec_list = mp4_video_list;
3188 *audio_codec_list = mp4_audio_list;
3189 } else if (!strcmp (format_name, "mpeg")) {
3190 static enum AVCodecID mpeg_video_list[] = { AV_CODEC_ID_MPEG1VIDEO,
3191 AV_CODEC_ID_MPEG2VIDEO,
3195 static enum AVCodecID mpeg_audio_list[] = { AV_CODEC_ID_MP1,
3201 *video_codec_list = mpeg_video_list;
3202 *audio_codec_list = mpeg_audio_list;
3203 } else if (!strcmp (format_name, "dvd")) {
3204 static enum AVCodecID mpeg_video_list[] = { AV_CODEC_ID_MPEG2VIDEO,
3207 static enum AVCodecID mpeg_audio_list[] = { AV_CODEC_ID_MP2,
3210 AV_CODEC_ID_PCM_S16BE,
3214 *video_codec_list = mpeg_video_list;
3215 *audio_codec_list = mpeg_audio_list;
3216 } else if (!strcmp (format_name, "mpegts")) {
3217 static enum AVCodecID mpegts_video_list[] = { AV_CODEC_ID_MPEG1VIDEO,
3218 AV_CODEC_ID_MPEG2VIDEO,
3222 static enum AVCodecID mpegts_audio_list[] = { AV_CODEC_ID_MP2,
3230 *video_codec_list = mpegts_video_list;
3231 *audio_codec_list = mpegts_audio_list;
3232 } else if (!strcmp (format_name, "vob")) {
3233 static enum AVCodecID vob_video_list[] =
3234 { AV_CODEC_ID_MPEG2VIDEO, AV_CODEC_ID_NONE };
3235 static enum AVCodecID vob_audio_list[] = { AV_CODEC_ID_MP2, AV_CODEC_ID_AC3,
3236 AV_CODEC_ID_DTS, AV_CODEC_ID_NONE
3239 *video_codec_list = vob_video_list;
3240 *audio_codec_list = vob_audio_list;
3241 } else if (!strcmp (format_name, "flv")) {
3242 static enum AVCodecID flv_video_list[] =
3243 { AV_CODEC_ID_FLV1, AV_CODEC_ID_NONE };
3244 static enum AVCodecID flv_audio_list[] =
3245 { AV_CODEC_ID_MP3, AV_CODEC_ID_NONE };
3247 *video_codec_list = flv_video_list;
3248 *audio_codec_list = flv_audio_list;
3249 } else if (!strcmp (format_name, "asf")) {
3250 static enum AVCodecID asf_video_list[] =
3251 { AV_CODEC_ID_WMV1, AV_CODEC_ID_WMV2, AV_CODEC_ID_MSMPEG4V3,
3254 static enum AVCodecID asf_audio_list[] =
3255 { AV_CODEC_ID_WMAV1, AV_CODEC_ID_WMAV2, AV_CODEC_ID_MP3,
3259 *video_codec_list = asf_video_list;
3260 *audio_codec_list = asf_audio_list;
3261 } else if (!strcmp (format_name, "dv")) {
3262 static enum AVCodecID dv_video_list[] =
3263 { AV_CODEC_ID_DVVIDEO, AV_CODEC_ID_NONE };
3264 static enum AVCodecID dv_audio_list[] =
3265 { AV_CODEC_ID_PCM_S16LE, AV_CODEC_ID_NONE };
3267 *video_codec_list = dv_video_list;
3268 *audio_codec_list = dv_audio_list;
3269 } else if (!strcmp (format_name, "mov")) {
3270 static enum AVCodecID mov_video_list[] = {
3271 AV_CODEC_ID_SVQ1, AV_CODEC_ID_SVQ3, AV_CODEC_ID_MPEG4,
3272 AV_CODEC_ID_H263, AV_CODEC_ID_H263P,
3273 AV_CODEC_ID_H264, AV_CODEC_ID_DVVIDEO,
3277 static enum AVCodecID mov_audio_list[] = {
3278 AV_CODEC_ID_PCM_MULAW, AV_CODEC_ID_PCM_ALAW, AV_CODEC_ID_ADPCM_IMA_QT,
3279 AV_CODEC_ID_MACE3, AV_CODEC_ID_MACE6, AV_CODEC_ID_AAC,
3280 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3281 AV_CODEC_ID_PCM_S16BE, AV_CODEC_ID_PCM_S16LE,
3282 AV_CODEC_ID_MP3, AV_CODEC_ID_NONE
3285 *video_codec_list = mov_video_list;
3286 *audio_codec_list = mov_audio_list;
3287 } else if ((!strcmp (format_name, "3gp") || !strcmp (format_name, "3g2"))) {
3288 static enum AVCodecID tgp_video_list[] = {
3289 AV_CODEC_ID_MPEG4, AV_CODEC_ID_H263, AV_CODEC_ID_H263P, AV_CODEC_ID_H264,
3292 static enum AVCodecID tgp_audio_list[] = {
3293 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3298 *video_codec_list = tgp_video_list;
3299 *audio_codec_list = tgp_audio_list;
3300 } else if (!strcmp (format_name, "mmf")) {
3301 static enum AVCodecID mmf_audio_list[] = {
3302 AV_CODEC_ID_ADPCM_YAMAHA, AV_CODEC_ID_NONE
3304 *video_codec_list = NULL;
3305 *audio_codec_list = mmf_audio_list;
3306 } else if (!strcmp (format_name, "amr")) {
3307 static enum AVCodecID amr_audio_list[] = {
3308 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3311 *video_codec_list = NULL;
3312 *audio_codec_list = amr_audio_list;
3313 } else if (!strcmp (format_name, "gif")) {
3314 static enum AVCodecID gif_image_list[] = {
3315 AV_CODEC_ID_RAWVIDEO, AV_CODEC_ID_NONE
3317 *video_codec_list = gif_image_list;
3318 *audio_codec_list = NULL;
3319 } else if ((plugin->audio_codec != AV_CODEC_ID_NONE) ||
3320 (plugin->video_codec != AV_CODEC_ID_NONE)) {
3321 tmp_vlist[0] = plugin->video_codec;
3322 tmp_alist[0] = plugin->audio_codec;
3324 *video_codec_list = tmp_vlist;
3325 *audio_codec_list = tmp_alist;
3326 } else if ((!strcmp (format_name, "pva"))) {
3327 static enum AVCodecID tgp_video_list[] = {
3328 AV_CODEC_ID_MPEG2VIDEO,
3331 static enum AVCodecID tgp_audio_list[] = {
3336 *video_codec_list = tgp_video_list;
3337 *audio_codec_list = tgp_audio_list;
3339 GST_LOG ("Format %s not found", format_name);
3346 /* Convert a GstCaps to a FFMPEG codec ID. Size et all
3347 * are omitted, that can be queried by the user itself,
3348 * we're not eating the GstCaps or anything
3349 * A pointer to an allocated context is also needed for
3350 * optional extra info
3354 gst_ffmpeg_caps_to_codecid (const GstCaps * caps, AVCodecContext * context)
3356 enum AVCodecID id = AV_CODEC_ID_NONE;
3357 const gchar *mimetype;
3358 const GstStructure *structure;
3359 gboolean video = FALSE, audio = FALSE; /* we want to be sure! */
3361 g_return_val_if_fail (caps != NULL, AV_CODEC_ID_NONE);
3362 g_return_val_if_fail (gst_caps_get_size (caps) == 1, AV_CODEC_ID_NONE);
3363 structure = gst_caps_get_structure (caps, 0);
3365 mimetype = gst_structure_get_name (structure);
3367 if (!strcmp (mimetype, "video/x-raw")) {
3368 id = AV_CODEC_ID_RAWVIDEO;
3370 } else if (!strcmp (mimetype, "audio/x-raw")) {
3373 if (gst_audio_info_from_caps (&info, caps)) {
3374 switch (GST_AUDIO_INFO_FORMAT (&info)) {
3375 case GST_AUDIO_FORMAT_S8:
3376 id = AV_CODEC_ID_PCM_S8;
3378 case GST_AUDIO_FORMAT_U8:
3379 id = AV_CODEC_ID_PCM_U8;
3381 case GST_AUDIO_FORMAT_S16LE:
3382 id = AV_CODEC_ID_PCM_S16LE;
3384 case GST_AUDIO_FORMAT_S16BE:
3385 id = AV_CODEC_ID_PCM_S16BE;
3387 case GST_AUDIO_FORMAT_U16LE:
3388 id = AV_CODEC_ID_PCM_U16LE;
3390 case GST_AUDIO_FORMAT_U16BE:
3391 id = AV_CODEC_ID_PCM_U16BE;
3396 if (id != AV_CODEC_ID_NONE)
3399 } else if (!strcmp (mimetype, "audio/x-mulaw")) {
3400 id = AV_CODEC_ID_PCM_MULAW;
3402 } else if (!strcmp (mimetype, "audio/x-alaw")) {
3403 id = AV_CODEC_ID_PCM_ALAW;
3405 } else if (!strcmp (mimetype, "video/x-dv")) {
3408 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3410 id = AV_CODEC_ID_DVVIDEO;
3413 } else if (!strcmp (mimetype, "audio/x-dv")) { /* ??? */
3414 id = AV_CODEC_ID_DVAUDIO;
3416 } else if (!strcmp (mimetype, "video/x-h263")) {
3417 const gchar *h263version =
3418 gst_structure_get_string (structure, "h263version");
3419 if (h263version && !strcmp (h263version, "h263p"))
3420 id = AV_CODEC_ID_H263P;
3422 id = AV_CODEC_ID_H263;
3424 } else if (!strcmp (mimetype, "video/x-intel-h263")) {
3425 id = AV_CODEC_ID_H263I;
3427 } else if (!strcmp (mimetype, "video/x-h261")) {
3428 id = AV_CODEC_ID_H261;
3430 } else if (!strcmp (mimetype, "video/mpeg")) {
3434 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3435 gst_structure_get_int (structure, "mpegversion", &mpegversion) &&
3437 switch (mpegversion) {
3439 id = AV_CODEC_ID_MPEG1VIDEO;
3442 id = AV_CODEC_ID_MPEG2VIDEO;
3445 id = AV_CODEC_ID_MPEG4;
3449 if (id != AV_CODEC_ID_NONE)
3451 } else if (!strcmp (mimetype, "image/jpeg")) {
3452 id = AV_CODEC_ID_MJPEG; /* A... B... */
3454 } else if (!strcmp (mimetype, "video/x-jpeg-b")) {
3455 id = AV_CODEC_ID_MJPEGB;
3457 } else if (!strcmp (mimetype, "video/x-wmv")) {
3458 gint wmvversion = 0;
3460 if (gst_structure_get_int (structure, "wmvversion", &wmvversion)) {
3461 switch (wmvversion) {
3463 id = AV_CODEC_ID_WMV1;
3466 id = AV_CODEC_ID_WMV2;
3470 const gchar *format;
3472 /* WMV3 unless the fourcc exists and says otherwise */
3473 id = AV_CODEC_ID_WMV3;
3475 if ((format = gst_structure_get_string (structure, "format")) &&
3476 (g_str_equal (format, "WVC1") || g_str_equal (format, "WMVA")))
3477 id = AV_CODEC_ID_VC1;
3483 if (id != AV_CODEC_ID_NONE)
3485 } else if (!strcmp (mimetype, "audio/x-vorbis")) {
3486 id = AV_CODEC_ID_VORBIS;
3488 } else if (!strcmp (mimetype, "audio/x-qdm2")) {
3489 id = AV_CODEC_ID_QDM2;
3491 } else if (!strcmp (mimetype, "audio/mpeg")) {
3493 gint mpegversion = 0;
3495 if (gst_structure_get_int (structure, "mpegversion", &mpegversion)) {
3496 switch (mpegversion) {
3497 case 2: /* ffmpeg uses faad for both... */
3499 id = AV_CODEC_ID_AAC;
3502 if (gst_structure_get_int (structure, "layer", &layer)) {
3505 id = AV_CODEC_ID_MP1;
3508 id = AV_CODEC_ID_MP2;
3511 id = AV_CODEC_ID_MP3;
3517 if (id != AV_CODEC_ID_NONE)
3519 } else if (!strcmp (mimetype, "audio/x-musepack")) {
3520 gint streamversion = -1;
3522 if (gst_structure_get_int (structure, "streamversion", &streamversion)) {
3523 if (streamversion == 7)
3524 id = AV_CODEC_ID_MUSEPACK7;
3526 id = AV_CODEC_ID_MUSEPACK7;
3528 } else if (!strcmp (mimetype, "audio/x-wma")) {
3529 gint wmaversion = 0;
3531 if (gst_structure_get_int (structure, "wmaversion", &wmaversion)) {
3532 switch (wmaversion) {
3534 id = AV_CODEC_ID_WMAV1;
3537 id = AV_CODEC_ID_WMAV2;
3540 id = AV_CODEC_ID_WMAPRO;
3544 if (id != AV_CODEC_ID_NONE)
3546 } else if (!strcmp (mimetype, "audio/x-wms")) {
3547 id = AV_CODEC_ID_WMAVOICE;
3549 } else if (!strcmp (mimetype, "audio/x-ac3")) {
3550 id = AV_CODEC_ID_AC3;
3552 } else if (!strcmp (mimetype, "audio/x-eac3")) {
3553 id = AV_CODEC_ID_EAC3;
3555 } else if (!strcmp (mimetype, "audio/x-vnd.sony.atrac3") ||
3556 !strcmp (mimetype, "audio/atrac3")) {
3557 id = AV_CODEC_ID_ATRAC3;
3559 } else if (!strcmp (mimetype, "audio/x-dts")) {
3560 id = AV_CODEC_ID_DTS;
3562 } else if (!strcmp (mimetype, "application/x-ape")) {
3563 id = AV_CODEC_ID_APE;
3565 } else if (!strcmp (mimetype, "video/x-msmpeg")) {
3566 gint msmpegversion = 0;
3568 if (gst_structure_get_int (structure, "msmpegversion", &msmpegversion)) {
3569 switch (msmpegversion) {
3571 id = AV_CODEC_ID_MSMPEG4V1;
3574 id = AV_CODEC_ID_MSMPEG4V2;
3577 id = AV_CODEC_ID_MSMPEG4V3;
3581 if (id != AV_CODEC_ID_NONE)
3583 } else if (!strcmp (mimetype, "video/x-svq")) {
3584 gint svqversion = 0;
3586 if (gst_structure_get_int (structure, "svqversion", &svqversion)) {
3587 switch (svqversion) {
3589 id = AV_CODEC_ID_SVQ1;
3592 id = AV_CODEC_ID_SVQ3;
3596 if (id != AV_CODEC_ID_NONE)
3598 } else if (!strcmp (mimetype, "video/x-huffyuv")) {
3599 id = AV_CODEC_ID_HUFFYUV;
3601 } else if (!strcmp (mimetype, "audio/x-mace")) {
3602 gint maceversion = 0;
3604 if (gst_structure_get_int (structure, "maceversion", &maceversion)) {
3605 switch (maceversion) {
3607 id = AV_CODEC_ID_MACE3;
3610 id = AV_CODEC_ID_MACE6;
3614 if (id != AV_CODEC_ID_NONE)
3616 } else if (!strcmp (mimetype, "video/x-theora")) {
3617 id = AV_CODEC_ID_THEORA;
3619 } else if (!strcmp (mimetype, "video/x-vp3")) {
3620 id = AV_CODEC_ID_VP3;
3622 } else if (!strcmp (mimetype, "video/x-vp5")) {
3623 id = AV_CODEC_ID_VP5;
3625 } else if (!strcmp (mimetype, "video/x-vp6")) {
3626 id = AV_CODEC_ID_VP6;
3628 } else if (!strcmp (mimetype, "video/x-vp6-flash")) {
3629 id = AV_CODEC_ID_VP6F;
3631 } else if (!strcmp (mimetype, "video/x-vp6-alpha")) {
3632 id = AV_CODEC_ID_VP6A;
3634 } else if (!strcmp (mimetype, "video/x-vp8")) {
3635 id = AV_CODEC_ID_VP8;
3637 } else if (!strcmp (mimetype, "video/x-flash-screen")) {
3638 id = AV_CODEC_ID_FLASHSV;
3640 } else if (!strcmp (mimetype, "video/x-indeo")) {
3641 gint indeoversion = 0;
3643 if (gst_structure_get_int (structure, "indeoversion", &indeoversion)) {
3644 switch (indeoversion) {
3646 id = AV_CODEC_ID_INDEO5;
3649 id = AV_CODEC_ID_INDEO4;
3652 id = AV_CODEC_ID_INDEO3;
3655 id = AV_CODEC_ID_INDEO2;
3658 if (id != AV_CODEC_ID_NONE)
3661 } else if (!strcmp (mimetype, "video/x-divx")) {
3662 gint divxversion = 0;
3664 if (gst_structure_get_int (structure, "divxversion", &divxversion)) {
3665 switch (divxversion) {
3667 id = AV_CODEC_ID_MSMPEG4V3;
3671 id = AV_CODEC_ID_MPEG4;
3675 if (id != AV_CODEC_ID_NONE)
3677 } else if (!strcmp (mimetype, "video/x-3ivx")) {
3678 id = AV_CODEC_ID_MPEG4;
3680 } else if (!strcmp (mimetype, "video/x-xvid")) {
3681 id = AV_CODEC_ID_MPEG4;
3683 } else if (!strcmp (mimetype, "video/x-ffv")) {
3684 gint ffvversion = 0;
3686 if (gst_structure_get_int (structure, "ffvversion", &ffvversion) &&
3688 id = AV_CODEC_ID_FFV1;
3691 } else if (!strcmp (mimetype, "audio/x-adpcm")) {
3692 const gchar *layout;
3694 layout = gst_structure_get_string (structure, "layout");
3695 if (layout == NULL) {
3697 } else if (!strcmp (layout, "quicktime")) {
3698 id = AV_CODEC_ID_ADPCM_IMA_QT;
3699 } else if (!strcmp (layout, "microsoft")) {
3700 id = AV_CODEC_ID_ADPCM_MS;
3701 } else if (!strcmp (layout, "dvi")) {
3702 id = AV_CODEC_ID_ADPCM_IMA_WAV;
3703 } else if (!strcmp (layout, "4xm")) {
3704 id = AV_CODEC_ID_ADPCM_4XM;
3705 } else if (!strcmp (layout, "smjpeg")) {
3706 id = AV_CODEC_ID_ADPCM_IMA_SMJPEG;
3707 } else if (!strcmp (layout, "dk3")) {
3708 id = AV_CODEC_ID_ADPCM_IMA_DK3;
3709 } else if (!strcmp (layout, "dk4")) {
3710 id = AV_CODEC_ID_ADPCM_IMA_DK4;
3711 } else if (!strcmp (layout, "westwood")) {
3712 id = AV_CODEC_ID_ADPCM_IMA_WS;
3713 } else if (!strcmp (layout, "iss")) {
3714 id = AV_CODEC_ID_ADPCM_IMA_ISS;
3715 } else if (!strcmp (layout, "xa")) {
3716 id = AV_CODEC_ID_ADPCM_XA;
3717 } else if (!strcmp (layout, "adx")) {
3718 id = AV_CODEC_ID_ADPCM_ADX;
3719 } else if (!strcmp (layout, "ea")) {
3720 id = AV_CODEC_ID_ADPCM_EA;
3721 } else if (!strcmp (layout, "g726")) {
3722 id = AV_CODEC_ID_ADPCM_G726;
3723 } else if (!strcmp (layout, "g721")) {
3724 id = AV_CODEC_ID_ADPCM_G726;
3725 } else if (!strcmp (layout, "ct")) {
3726 id = AV_CODEC_ID_ADPCM_CT;
3727 } else if (!strcmp (layout, "swf")) {
3728 id = AV_CODEC_ID_ADPCM_SWF;
3729 } else if (!strcmp (layout, "yamaha")) {
3730 id = AV_CODEC_ID_ADPCM_YAMAHA;
3731 } else if (!strcmp (layout, "sbpro2")) {
3732 id = AV_CODEC_ID_ADPCM_SBPRO_2;
3733 } else if (!strcmp (layout, "sbpro3")) {
3734 id = AV_CODEC_ID_ADPCM_SBPRO_3;
3735 } else if (!strcmp (layout, "sbpro4")) {
3736 id = AV_CODEC_ID_ADPCM_SBPRO_4;
3738 if (id != AV_CODEC_ID_NONE)
3740 } else if (!strcmp (mimetype, "video/x-4xm")) {
3741 id = AV_CODEC_ID_4XM;
3743 } else if (!strcmp (mimetype, "audio/x-dpcm")) {
3744 const gchar *layout;
3746 layout = gst_structure_get_string (structure, "layout");
3749 } else if (!strcmp (layout, "roq")) {
3750 id = AV_CODEC_ID_ROQ_DPCM;
3751 } else if (!strcmp (layout, "interplay")) {
3752 id = AV_CODEC_ID_INTERPLAY_DPCM;
3753 } else if (!strcmp (layout, "xan")) {
3754 id = AV_CODEC_ID_XAN_DPCM;
3755 } else if (!strcmp (layout, "sol")) {
3756 id = AV_CODEC_ID_SOL_DPCM;
3758 if (id != AV_CODEC_ID_NONE)
3760 } else if (!strcmp (mimetype, "audio/x-flac")) {
3761 id = AV_CODEC_ID_FLAC;
3763 } else if (!strcmp (mimetype, "audio/x-shorten")) {
3764 id = AV_CODEC_ID_SHORTEN;
3766 } else if (!strcmp (mimetype, "audio/x-alac")) {
3767 id = AV_CODEC_ID_ALAC;
3769 } else if (!strcmp (mimetype, "video/x-cinepak")) {
3770 id = AV_CODEC_ID_CINEPAK;
3772 } else if (!strcmp (mimetype, "video/x-pn-realvideo")) {
3775 if (gst_structure_get_int (structure, "rmversion", &rmversion)) {
3776 switch (rmversion) {
3778 id = AV_CODEC_ID_RV10;
3781 id = AV_CODEC_ID_RV20;
3784 id = AV_CODEC_ID_RV30;
3787 id = AV_CODEC_ID_RV40;
3791 if (id != AV_CODEC_ID_NONE)
3793 } else if (!strcmp (mimetype, "audio/x-sipro")) {
3794 id = AV_CODEC_ID_SIPR;
3796 } else if (!strcmp (mimetype, "audio/x-pn-realaudio")) {
3799 if (gst_structure_get_int (structure, "raversion", &raversion)) {
3800 switch (raversion) {
3802 id = AV_CODEC_ID_RA_144;
3805 id = AV_CODEC_ID_RA_288;
3808 id = AV_CODEC_ID_COOK;
3812 if (id != AV_CODEC_ID_NONE)
3814 } else if (!strcmp (mimetype, "video/x-rle")) {
3815 const gchar *layout;
3817 if ((layout = gst_structure_get_string (structure, "layout"))) {
3818 if (!strcmp (layout, "microsoft")) {
3819 id = AV_CODEC_ID_MSRLE;
3823 } else if (!strcmp (mimetype, "video/x-xan")) {
3826 if ((gst_structure_get_int (structure, "wcversion", &wcversion))) {
3827 switch (wcversion) {
3829 id = AV_CODEC_ID_XAN_WC3;
3833 id = AV_CODEC_ID_XAN_WC4;
3840 } else if (!strcmp (mimetype, "audio/AMR")) {
3842 id = AV_CODEC_ID_AMR_NB;
3843 } else if (!strcmp (mimetype, "audio/AMR-WB")) {
3844 id = AV_CODEC_ID_AMR_WB;
3846 } else if (!strcmp (mimetype, "audio/qcelp")) {
3847 id = AV_CODEC_ID_QCELP;
3849 } else if (!strcmp (mimetype, "video/x-h264")) {
3850 id = AV_CODEC_ID_H264;
3852 } else if (!strcmp (mimetype, "video/x-flash-video")) {
3853 gint flvversion = 0;
3855 if ((gst_structure_get_int (structure, "flvversion", &flvversion))) {
3856 switch (flvversion) {
3858 id = AV_CODEC_ID_FLV1;
3866 } else if (!strcmp (mimetype, "audio/x-nellymoser")) {
3867 id = AV_CODEC_ID_NELLYMOSER;
3869 } else if (!strncmp (mimetype, "audio/x-gst-av-", 15)) {
3873 if (strlen (mimetype) <= 30 &&
3874 sscanf (mimetype, "audio/x-gst-av-%s", ext) == 1) {
3875 if ((codec = avcodec_find_decoder_by_name (ext)) ||
3876 (codec = avcodec_find_encoder_by_name (ext))) {
3881 } else if (!strncmp (mimetype, "video/x-gst-av-", 15)) {
3885 if (strlen (mimetype) <= 30 &&
3886 sscanf (mimetype, "video/x-gst-av-%s", ext) == 1) {
3887 if ((codec = avcodec_find_decoder_by_name (ext)) ||
3888 (codec = avcodec_find_encoder_by_name (ext))) {
3895 if (context != NULL) {
3896 if (video == TRUE) {
3897 context->codec_type = AVMEDIA_TYPE_VIDEO;
3898 } else if (audio == TRUE) {
3899 context->codec_type = AVMEDIA_TYPE_AUDIO;
3901 context->codec_type = AVMEDIA_TYPE_UNKNOWN;
3903 context->codec_id = id;
3904 gst_ffmpeg_caps_with_codecid (id, context->codec_type, caps, context);
3907 if (id != AV_CODEC_ID_NONE) {
3908 GST_DEBUG ("The id=%d belongs to the caps %" GST_PTR_FORMAT, id, caps);
3910 GST_WARNING ("Couldn't figure out the id for caps %" GST_PTR_FORMAT, caps);