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 CodecID 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 CodecID 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];
526 caps = gst_caps_new_simple (mimetype,
527 "rate", G_TYPE_INT, context->sample_rate,
528 "channels", G_TYPE_INT, context->channels, NULL);
530 if (gst_ffmpeg_channel_layout_to_gst (context->channel_layout,
531 context->channels, pos)) {
534 if (gst_audio_channel_positions_to_mask (pos, context->channels, FALSE,
536 gst_caps_set_simple (caps, "channel-mask", GST_TYPE_BITMASK, mask,
541 gint maxchannels = 2;
542 const gint *rates = NULL;
545 /* so we must be after restricted caps in this case */
547 case AV_CODEC_ID_AAC:
548 case AV_CODEC_ID_AAC_LATM:
549 case AV_CODEC_ID_DTS:
552 case AV_CODEC_ID_MP2:
554 const static gint l_rates[] =
555 { 48000, 44100, 32000, 24000, 22050, 16000 };
556 n_rates = G_N_ELEMENTS (l_rates);
560 case AV_CODEC_ID_EAC3:
561 case AV_CODEC_ID_AC3:
563 const static gint l_rates[] = { 48000, 44100, 32000 };
565 n_rates = G_N_ELEMENTS (l_rates);
569 case AV_CODEC_ID_ADPCM_G722:
571 const static gint l_rates[] = { 16000 };
572 n_rates = G_N_ELEMENTS (l_rates);
577 case AV_CODEC_ID_ADPCM_G726:
579 const static gint l_rates[] = { 8000 };
580 n_rates = G_N_ELEMENTS (l_rates);
585 case AV_CODEC_ID_ADPCM_SWF:
587 const static gint l_rates[] = { 11025, 22050, 44100 };
588 n_rates = G_N_ELEMENTS (l_rates);
592 case AV_CODEC_ID_ROQ_DPCM:
594 const static gint l_rates[] = { 22050 };
595 n_rates = G_N_ELEMENTS (l_rates);
599 case AV_CODEC_ID_AMR_NB:
601 const static gint l_rates[] = { 8000 };
603 n_rates = G_N_ELEMENTS (l_rates);
607 case AV_CODEC_ID_AMR_WB:
609 const static gint l_rates[] = { 16000 };
611 n_rates = G_N_ELEMENTS (l_rates);
619 /* regardless of encode/decode, open up channels if applicable */
620 /* Until decoders/encoders expose the maximum number of channels
621 * they support, we whitelist them here. */
623 case AV_CODEC_ID_WMAPRO:
624 case AV_CODEC_ID_TRUEHD:
631 if (codec && codec->channel_layouts) {
632 const uint64_t *layouts = codec->channel_layouts;
633 GstAudioChannelPosition pos[64];
635 caps = gst_caps_new_empty ();
637 gint nbits_set = get_nbits_set (*layouts);
639 if (gst_ffmpeg_channel_layout_to_gst (*layouts, nbits_set, pos)) {
642 if (gst_audio_channel_positions_to_mask (pos, nbits_set, FALSE,
645 gst_caps_new_simple (mimetype, "channel-mask", GST_TYPE_BITMASK,
647 "channels", G_TYPE_INT, nbits_set, NULL);
649 gst_caps_append (caps, tmp);
655 if (maxchannels == 1)
656 caps = gst_caps_new_simple (mimetype,
657 "channels", G_TYPE_INT, maxchannels, NULL);
659 caps = gst_caps_new_simple (mimetype,
660 "channels", GST_TYPE_INT_RANGE, 1, maxchannels, NULL);
664 GValue list = { 0, };
666 g_value_init (&list, GST_TYPE_LIST);
667 for (i = 0; i < n_rates; i++) {
670 g_value_init (&v, G_TYPE_INT);
671 g_value_set_int (&v, rates[i]);
672 gst_value_list_append_value (&list, &v);
675 gst_caps_set_value (caps, "rate", &list);
676 g_value_unset (&list);
677 } else if (codec && codec->supported_samplerates
678 && codec->supported_samplerates[0]) {
682 if (!codec->supported_samplerates[1]) {
683 gst_caps_set_simple (caps, "rate", G_TYPE_INT,
684 codec->supported_samplerates[0], NULL);
686 const int *rates = codec->supported_samplerates;
688 g_value_init (&va, GST_TYPE_LIST);
689 g_value_init (&v, G_TYPE_INT);
692 g_value_set_int (&v, *rates);
693 gst_value_list_append_value (&va, &v);
696 gst_caps_set_value (caps, "rate", &va);
701 gst_caps_set_simple (caps, "rate", GST_TYPE_INT_RANGE, 4000, 96000, NULL);
704 caps = gst_caps_new_empty_simple (mimetype);
707 va_start (var_args, fieldname);
708 gst_caps_set_simple_valist (caps, fieldname, var_args);
714 /* Convert a FFMPEG codec ID and optional AVCodecContext
715 * to a GstCaps. If the context is ommitted, no fixed values
716 * for video/audio size will be included in the GstCaps
718 * CodecID is primarily meant for compressed data GstCaps!
720 * encode is a special parameter. gstffmpegdec will say
721 * FALSE, gstffmpegenc will say TRUE. The output caps
722 * depends on this, in such a way that it will be very
723 * specific, defined, fixed and correct caps for encoders,
724 * yet very wide, "forgiving" caps for decoders. Example
725 * for mp3: decode: audio/mpeg,mpegversion=1,layer=[1-3]
726 * but encode: audio/mpeg,mpegversion=1,layer=3,bitrate=x,
731 gst_ffmpeg_codecid_to_caps (enum CodecID codec_id,
732 AVCodecContext * context, gboolean encode)
734 GstCaps *caps = NULL;
735 gboolean buildcaps = FALSE;
737 GST_LOG ("codec_id:%d, context:%p, encode:%d", codec_id, context, encode);
740 case AV_CODEC_ID_MPEG1VIDEO:
742 caps = gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
743 "mpegversion", G_TYPE_INT, 1,
744 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
747 case AV_CODEC_ID_MPEG2VIDEO:
751 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
752 "mpegversion", G_TYPE_INT, 2, "systemstream", G_TYPE_BOOLEAN, FALSE,
755 /* decode both MPEG-1 and MPEG-2; width/height/fps are all in
756 * the MPEG video stream headers, so may be omitted from caps. */
757 caps = gst_caps_new_simple ("video/mpeg",
758 "mpegversion", GST_TYPE_INT_RANGE, 1, 2,
759 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
763 case AV_CODEC_ID_MPEG2VIDEO_XVMC:
764 /* this is a special ID - don't need it in GStreamer, I think */
767 case AV_CODEC_ID_H263:
770 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
771 "video/x-h263", "variant", G_TYPE_STRING, "itu", "h263version",
772 G_TYPE_STRING, "h263", NULL);
774 /* don't pass codec_id, we can decode other variants with the H263
775 * decoder that don't have specific size requirements
778 gst_ff_vid_caps_new (context, NULL, AV_CODEC_ID_NONE, encode,
779 "video/x-h263", "variant", G_TYPE_STRING, "itu", NULL);
783 case AV_CODEC_ID_H263P:
785 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h263",
786 "variant", G_TYPE_STRING, "itu", "h263version", G_TYPE_STRING,
788 if (encode && context) {
790 gst_caps_set_simple (caps,
791 "annex-f", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_4MV,
792 "annex-j", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_LOOP_FILTER,
793 "annex-i", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_AC_PRED,
794 "annex-t", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_AC_PRED,
799 case AV_CODEC_ID_H263I:
801 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
802 "video/x-intel-h263", "variant", G_TYPE_STRING, "intel", NULL);
805 case AV_CODEC_ID_H261:
807 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h261",
811 case AV_CODEC_ID_RV10:
812 case AV_CODEC_ID_RV20:
813 case AV_CODEC_ID_RV30:
814 case AV_CODEC_ID_RV40:
819 case AV_CODEC_ID_RV40:
822 case AV_CODEC_ID_RV30:
825 case AV_CODEC_ID_RV20:
833 /* FIXME: context->sub_id must be filled in during decoding */
835 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
836 "video/x-pn-realvideo", "rmversion", G_TYPE_INT, version, NULL);
838 gst_caps_set_simple (caps, "format", G_TYPE_INT, context->sub_id, NULL);
839 if (context->extradata_size >= 8) {
840 gst_caps_set_simple (caps,
841 "subformat", G_TYPE_INT, GST_READ_UINT32_BE (context->extradata),
848 case AV_CODEC_ID_MP1:
850 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
851 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 1, NULL);
854 case AV_CODEC_ID_MP2:
856 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
857 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 2, NULL);
860 case AV_CODEC_ID_MP3:
864 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
865 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 3, NULL);
867 /* Decodes MPEG-1 layer 1/2/3. Samplerate, channels et al are
868 * in the MPEG audio header, so may be omitted from caps. */
869 caps = gst_caps_new_simple ("audio/mpeg",
870 "mpegversion", G_TYPE_INT, 1,
871 "layer", GST_TYPE_INT_RANGE, 1, 3, NULL);
875 case AV_CODEC_ID_MUSEPACK7:
877 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
878 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 7,
882 case AV_CODEC_ID_MUSEPACK8:
884 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
885 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 8,
889 case AV_CODEC_ID_AC3:
892 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-ac3",
896 case AV_CODEC_ID_EAC3:
899 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-eac3",
903 case AV_CODEC_ID_TRUEHD:
905 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
906 "audio/x-true-hd", NULL);
909 case AV_CODEC_ID_ATRAC1:
911 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
912 "audio/x-vnd.sony.atrac1", NULL);
915 case AV_CODEC_ID_ATRAC3:
917 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
918 "audio/x-vnd.sony.atrac3", NULL);
921 case AV_CODEC_ID_DTS:
923 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dts",
927 case AV_CODEC_ID_APE:
929 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
930 "audio/x-ffmpeg-parsed-ape", NULL);
932 gst_caps_set_simple (caps,
933 "depth", G_TYPE_INT, context->bits_per_coded_sample, NULL);
937 case AV_CODEC_ID_MLP:
939 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mlp",
943 case AV_CODEC_ID_IMC:
945 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-imc",
949 /* MJPEG is normal JPEG, Motion-JPEG and Quicktime MJPEG-A. MJPEGB
950 * is Quicktime's MJPEG-B. LJPEG is lossless JPEG. I don't know what
951 * sp5x is, but it's apparently something JPEG... We don't separate
952 * between those in GStreamer. Should we (at least between MJPEG,
953 * MJPEG-B and sp5x decoding...)? */
954 case AV_CODEC_ID_MJPEG:
955 case AV_CODEC_ID_LJPEG:
957 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/jpeg",
958 "parsed", G_TYPE_BOOLEAN, 1, NULL);
961 case AV_CODEC_ID_SP5X:
963 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/sp5x",
967 case AV_CODEC_ID_MJPEGB:
969 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
970 "video/x-mjpeg-b", NULL);
973 case AV_CODEC_ID_MPEG4:
974 if (encode && context != NULL) {
975 /* I'm not exactly sure what ffmpeg outputs... ffmpeg itself uses
976 * the AVI fourcc 'DIVX', but 'mp4v' for Quicktime... */
977 switch (context->codec_tag) {
978 case GST_MAKE_FOURCC ('D', 'I', 'V', 'X'):
980 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
981 "video/x-divx", "divxversion", G_TYPE_INT, 5, NULL);
983 case GST_MAKE_FOURCC ('m', 'p', '4', 'v'):
987 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
988 "video/mpeg", "systemstream", G_TYPE_BOOLEAN, FALSE,
989 "mpegversion", G_TYPE_INT, 4, NULL);
993 /* The trick here is to separate xvid, divx, mpeg4, 3ivx et al */
995 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
996 "mpegversion", G_TYPE_INT, 4, "systemstream", G_TYPE_BOOLEAN, FALSE,
999 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
1000 encode, "video/x-divx", "divxversion", G_TYPE_INT, 5, NULL));
1002 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
1003 encode, "video/x-divx", "divxversion", GST_TYPE_INT_RANGE, 4,
1005 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
1006 encode, "video/x-xvid", NULL));
1007 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
1008 encode, "video/x-3ivx", NULL));
1013 case AV_CODEC_ID_RAWVIDEO:
1015 gst_ffmpeg_codectype_to_video_caps (context, codec_id, encode, NULL);
1018 case AV_CODEC_ID_MSMPEG4V1:
1019 case AV_CODEC_ID_MSMPEG4V2:
1020 case AV_CODEC_ID_MSMPEG4V3:
1022 gint version = 41 + codec_id - AV_CODEC_ID_MSMPEG4V1;
1024 /* encode-FIXME: bitrate */
1026 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1027 "video/x-msmpeg", "msmpegversion", G_TYPE_INT, version, NULL);
1028 if (!encode && codec_id == AV_CODEC_ID_MSMPEG4V3) {
1029 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
1030 encode, "video/x-divx", "divxversion", G_TYPE_INT, 3, NULL));
1035 case AV_CODEC_ID_WMV1:
1036 case AV_CODEC_ID_WMV2:
1038 gint version = (codec_id == AV_CODEC_ID_WMV1) ? 1 : 2;
1041 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1042 "wmvversion", G_TYPE_INT, version, NULL);
1046 case AV_CODEC_ID_FLV1:
1048 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1049 "video/x-flash-video", "flvversion", G_TYPE_INT, 1, NULL);
1052 case AV_CODEC_ID_SVQ1:
1054 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-svq",
1055 "svqversion", G_TYPE_INT, 1, NULL);
1058 case AV_CODEC_ID_SVQ3:
1060 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-svq",
1061 "svqversion", G_TYPE_INT, 3, NULL);
1064 case AV_CODEC_ID_DVAUDIO:
1066 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dv",
1070 case AV_CODEC_ID_DVVIDEO:
1072 if (encode && context) {
1073 const gchar *format;
1075 switch (context->pix_fmt) {
1076 case PIX_FMT_YUYV422:
1079 case PIX_FMT_YUV420P:
1082 case PIX_FMT_YUVA420P:
1085 case PIX_FMT_YUV411P:
1088 case PIX_FMT_YUV422P:
1091 case PIX_FMT_YUV410P:
1096 ("Couldnt' find format for pixfmt %d, defaulting to I420",
1102 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dv",
1103 "systemstream", G_TYPE_BOOLEAN, FALSE, "format", G_TYPE_STRING,
1107 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dv",
1108 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
1113 case AV_CODEC_ID_WMAV1:
1114 case AV_CODEC_ID_WMAV2:
1116 gint version = (codec_id == AV_CODEC_ID_WMAV1) ? 1 : 2;
1120 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1121 "wmaversion", G_TYPE_INT, version, "block_align", G_TYPE_INT,
1122 context->block_align, "bitrate", G_TYPE_INT, context->bit_rate,
1126 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1127 "wmaversion", G_TYPE_INT, version, "block_align",
1128 GST_TYPE_INT_RANGE, 0, G_MAXINT, "bitrate", GST_TYPE_INT_RANGE, 0,
1133 case AV_CODEC_ID_WMAPRO:
1136 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1137 "wmaversion", G_TYPE_INT, 3, NULL);
1140 case AV_CODEC_ID_WMALOSSLESS:
1142 /* libav only supports a depth of 16 at the moment */
1144 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1145 "wmaversion", G_TYPE_INT, 4, "depth", G_TYPE_INT, 16, NULL);
1148 case AV_CODEC_ID_WMAVOICE:
1151 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wms",
1156 case AV_CODEC_ID_MACE3:
1157 case AV_CODEC_ID_MACE6:
1159 gint version = (codec_id == AV_CODEC_ID_MACE3) ? 3 : 6;
1162 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mace",
1163 "maceversion", G_TYPE_INT, version, NULL);
1167 case AV_CODEC_ID_HUFFYUV:
1169 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1170 "video/x-huffyuv", NULL);
1172 gst_caps_set_simple (caps,
1173 "bpp", G_TYPE_INT, context->bits_per_coded_sample, NULL);
1177 case AV_CODEC_ID_CYUV:
1179 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1180 "video/x-compressed-yuv", NULL);
1183 case AV_CODEC_ID_H264:
1185 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h264",
1186 "alignment", G_TYPE_STRING, "au", NULL);
1188 GValue arr = { 0, };
1189 GValue item = { 0, };
1190 g_value_init (&arr, GST_TYPE_LIST);
1191 g_value_init (&item, G_TYPE_STRING);
1192 g_value_set_string (&item, "avc");
1193 gst_value_list_append_value (&arr, &item);
1194 g_value_set_string (&item, "byte-stream");
1195 gst_value_list_append_value (&arr, &item);
1196 g_value_unset (&item);
1197 gst_caps_set_value (caps, "stream-format", &arr);
1198 g_value_unset (&arr);
1202 case AV_CODEC_ID_INDEO5:
1204 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1205 "indeoversion", G_TYPE_INT, 5, NULL);
1208 case AV_CODEC_ID_INDEO4:
1210 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1211 "indeoversion", G_TYPE_INT, 4, NULL);
1214 case AV_CODEC_ID_INDEO3:
1216 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1217 "indeoversion", G_TYPE_INT, 3, NULL);
1220 case AV_CODEC_ID_INDEO2:
1222 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1223 "indeoversion", G_TYPE_INT, 2, NULL);
1226 case AV_CODEC_ID_FLASHSV:
1228 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1229 "video/x-flash-screen", NULL);
1232 case AV_CODEC_ID_VP3:
1234 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp3",
1238 case AV_CODEC_ID_VP5:
1240 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp5",
1244 case AV_CODEC_ID_VP6:
1246 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp6",
1250 case AV_CODEC_ID_VP6F:
1252 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1253 "video/x-vp6-flash", NULL);
1256 case AV_CODEC_ID_VP6A:
1258 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1259 "video/x-vp6-alpha", NULL);
1262 case AV_CODEC_ID_VP8:
1264 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp8",
1268 case AV_CODEC_ID_THEORA:
1270 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1271 "video/x-theora", NULL);
1274 case AV_CODEC_ID_AAC:
1277 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
1281 GValue arr = { 0, };
1282 GValue item = { 0, };
1284 g_value_init (&arr, GST_TYPE_LIST);
1285 g_value_init (&item, G_TYPE_INT);
1286 g_value_set_int (&item, 2);
1287 gst_value_list_append_value (&arr, &item);
1288 g_value_set_int (&item, 4);
1289 gst_value_list_append_value (&arr, &item);
1290 g_value_unset (&item);
1292 gst_caps_set_value (caps, "mpegversion", &arr);
1293 g_value_unset (&arr);
1295 g_value_init (&arr, GST_TYPE_LIST);
1296 g_value_init (&item, G_TYPE_STRING);
1297 g_value_set_string (&item, "raw");
1298 gst_value_list_append_value (&arr, &item);
1299 g_value_set_string (&item, "adts");
1300 gst_value_list_append_value (&arr, &item);
1301 g_value_set_string (&item, "adif");
1302 gst_value_list_append_value (&arr, &item);
1303 g_value_unset (&item);
1305 gst_caps_set_value (caps, "stream-format", &arr);
1306 g_value_unset (&arr);
1308 gst_caps_set_simple (caps, "mpegversion", G_TYPE_INT, 4,
1309 "stream-format", G_TYPE_STRING, "raw",
1310 "base-profile", G_TYPE_STRING, "lc", NULL);
1312 if (context && context->extradata_size > 0)
1313 gst_codec_utils_aac_caps_set_level_and_profile (caps,
1314 context->extradata, context->extradata_size);
1319 case AV_CODEC_ID_AAC_LATM: /* LATM/LOAS AAC syntax */
1320 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
1321 "mpegversion", G_TYPE_INT, 4, "stream-format", G_TYPE_STRING, "loas",
1325 case AV_CODEC_ID_ASV1:
1327 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-asus",
1328 "asusversion", G_TYPE_INT, 1, NULL);
1330 case AV_CODEC_ID_ASV2:
1332 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-asus",
1333 "asusversion", G_TYPE_INT, 2, NULL);
1336 case AV_CODEC_ID_FFV1:
1338 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-ffv",
1339 "ffvversion", G_TYPE_INT, 1, NULL);
1342 case AV_CODEC_ID_4XM:
1344 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-4xm",
1348 case AV_CODEC_ID_XAN_WC3:
1349 case AV_CODEC_ID_XAN_WC4:
1351 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-xan",
1352 "wcversion", G_TYPE_INT, 3 - AV_CODEC_ID_XAN_WC3 + codec_id, NULL);
1355 case AV_CODEC_ID_CLJR:
1357 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1358 "video/x-cirrus-logic-accupak", NULL);
1361 case AV_CODEC_ID_FRAPS:
1363 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-fraps",
1367 case AV_CODEC_ID_MDEC:
1368 case AV_CODEC_ID_ROQ:
1369 case AV_CODEC_ID_INTERPLAY_VIDEO:
1373 case AV_CODEC_ID_VCR1:
1375 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1376 "video/x-ati-vcr", "vcrversion", G_TYPE_INT, 1, NULL);
1379 case AV_CODEC_ID_RPZA:
1381 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1382 "video/x-apple-video", NULL);
1385 case AV_CODEC_ID_CINEPAK:
1387 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1388 "video/x-cinepak", NULL);
1391 /* WS_VQA belogns here (order) */
1393 case AV_CODEC_ID_MSRLE:
1395 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-rle",
1396 "layout", G_TYPE_STRING, "microsoft", NULL);
1398 gst_caps_set_simple (caps,
1399 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1401 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1405 case AV_CODEC_ID_QTRLE:
1407 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-rle",
1408 "layout", G_TYPE_STRING, "quicktime", NULL);
1410 gst_caps_set_simple (caps,
1411 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1413 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1417 case AV_CODEC_ID_MSVIDEO1:
1419 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1420 "video/x-msvideocodec", "msvideoversion", G_TYPE_INT, 1, NULL);
1423 case AV_CODEC_ID_MSS1:
1425 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1426 "wmvversion", G_TYPE_INT, 1, "format", G_TYPE_STRING, "MSS1", NULL);
1429 case AV_CODEC_ID_MSS2:
1431 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1432 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "MSS2", NULL);
1435 case AV_CODEC_ID_WMV3:
1437 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1438 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "WMV3", NULL);
1440 case AV_CODEC_ID_VC1:
1442 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1443 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "WVC1", NULL);
1445 case AV_CODEC_ID_QDM2:
1447 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-qdm2",
1451 case AV_CODEC_ID_MSZH:
1453 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-mszh",
1457 case AV_CODEC_ID_ZLIB:
1459 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-zlib",
1463 case AV_CODEC_ID_TRUEMOTION1:
1465 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1466 "video/x-truemotion", "trueversion", G_TYPE_INT, 1, NULL);
1468 case AV_CODEC_ID_TRUEMOTION2:
1470 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1471 "video/x-truemotion", "trueversion", G_TYPE_INT, 2, NULL);
1474 case AV_CODEC_ID_ULTI:
1476 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1477 "video/x-ultimotion", NULL);
1480 case AV_CODEC_ID_TSCC:
1482 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1483 "video/x-camtasia", NULL);
1485 gst_caps_set_simple (caps,
1486 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1488 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1492 case AV_CODEC_ID_TSCC2:
1494 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1495 "video/x-tscc", "tsccversion", G_TYPE_INT, 2, NULL);
1498 case AV_CODEC_ID_KMVC:
1500 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-kmvc",
1504 case AV_CODEC_ID_NUV:
1506 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-nuv",
1510 case AV_CODEC_ID_GIF:
1512 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/gif",
1516 case AV_CODEC_ID_PNG:
1518 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/png",
1522 case AV_CODEC_ID_PPM:
1524 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/ppm",
1528 case AV_CODEC_ID_PBM:
1530 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/pbm",
1534 case AV_CODEC_ID_PAM:
1536 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1537 "image/x-portable-anymap", NULL);
1540 case AV_CODEC_ID_PGM:
1542 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1543 "image/x-portable-graymap", NULL);
1546 case AV_CODEC_ID_PCX:
1548 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-pcx",
1552 case AV_CODEC_ID_SGI:
1554 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-sgi",
1558 case AV_CODEC_ID_TARGA:
1560 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-tga",
1564 case AV_CODEC_ID_TIFF:
1566 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/tiff",
1570 case AV_CODEC_ID_SUNRAST:
1572 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1573 "image/x-sun-raster", NULL);
1576 case AV_CODEC_ID_SMC:
1578 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-smc",
1582 case AV_CODEC_ID_QDRAW:
1584 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-qdrw",
1588 case AV_CODEC_ID_DNXHD:
1590 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dnxhd",
1594 case AV_CODEC_ID_PRORES:
1596 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1597 "video/x-prores", NULL);
1600 case AV_CODEC_ID_MIMIC:
1602 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-mimic",
1606 case AV_CODEC_ID_VMNC:
1608 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vmnc",
1612 case AV_CODEC_ID_TRUESPEECH:
1614 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1615 "audio/x-truespeech", NULL);
1618 case AV_CODEC_ID_QCELP:
1620 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/qcelp",
1624 case AV_CODEC_ID_AMV:
1626 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-amv",
1630 case AV_CODEC_ID_AASC:
1632 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-aasc",
1636 case AV_CODEC_ID_LOCO:
1638 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-loco",
1642 case AV_CODEC_ID_ZMBV:
1644 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-zmbv",
1648 case AV_CODEC_ID_LAGARITH:
1650 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1651 "video/x-lagarith", NULL);
1654 case AV_CODEC_ID_CSCD:
1656 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1657 "video/x-camstudio", NULL);
1659 gst_caps_set_simple (caps,
1660 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1662 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1666 case AV_CODEC_ID_WS_VQA:
1667 case AV_CODEC_ID_IDCIN:
1668 case AV_CODEC_ID_8BPS:
1669 case AV_CODEC_ID_FLIC:
1670 case AV_CODEC_ID_VMDVIDEO:
1671 case AV_CODEC_ID_VMDAUDIO:
1672 case AV_CODEC_ID_SNOW:
1673 case AV_CODEC_ID_VIXL:
1674 case AV_CODEC_ID_QPEG:
1675 case AV_CODEC_ID_PGMYUV:
1676 case AV_CODEC_ID_FFVHUFF:
1677 case AV_CODEC_ID_WNV1:
1678 case AV_CODEC_ID_MP3ADU:
1679 case AV_CODEC_ID_MP3ON4:
1680 case AV_CODEC_ID_WESTWOOD_SND1:
1681 case AV_CODEC_ID_MMVIDEO:
1682 case AV_CODEC_ID_AVS:
1683 case AV_CODEC_ID_CAVS:
1687 /* weird quasi-codecs for the demuxers only */
1688 case AV_CODEC_ID_PCM_S16LE:
1689 case AV_CODEC_ID_PCM_S16BE:
1690 case AV_CODEC_ID_PCM_U16LE:
1691 case AV_CODEC_ID_PCM_U16BE:
1692 case AV_CODEC_ID_PCM_S8:
1693 case AV_CODEC_ID_PCM_U8:
1695 GstAudioFormat format;
1698 case AV_CODEC_ID_PCM_S16LE:
1699 format = GST_AUDIO_FORMAT_S16LE;
1701 case AV_CODEC_ID_PCM_S16BE:
1702 format = GST_AUDIO_FORMAT_S16BE;
1704 case AV_CODEC_ID_PCM_U16LE:
1705 format = GST_AUDIO_FORMAT_U16LE;
1707 case AV_CODEC_ID_PCM_U16BE:
1708 format = GST_AUDIO_FORMAT_U16BE;
1710 case AV_CODEC_ID_PCM_S8:
1711 format = GST_AUDIO_FORMAT_S8;
1713 case AV_CODEC_ID_PCM_U8:
1714 format = GST_AUDIO_FORMAT_U8;
1717 g_assert (0); /* don't worry, we never get here */
1722 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-raw",
1723 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
1724 "layout", G_TYPE_STRING, "interleaved", NULL);
1728 case AV_CODEC_ID_PCM_MULAW:
1730 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mulaw",
1734 case AV_CODEC_ID_PCM_ALAW:
1736 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-alaw",
1740 case AV_CODEC_ID_ADPCM_G722:
1742 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/G722",
1745 gst_caps_set_simple (caps,
1746 "block_align", G_TYPE_INT, context->block_align,
1747 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1750 case AV_CODEC_ID_ADPCM_G726:
1752 /* the G726 decoder can also handle G721 */
1754 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-adpcm",
1755 "layout", G_TYPE_STRING, "g726", NULL);
1757 gst_caps_set_simple (caps,
1758 "block_align", G_TYPE_INT, context->block_align,
1759 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1762 gst_caps_append (caps, gst_caps_new_simple ("audio/x-adpcm",
1763 "layout", G_TYPE_STRING, "g721",
1764 "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, 8000, NULL));
1768 case AV_CODEC_ID_ADPCM_IMA_QT:
1769 case AV_CODEC_ID_ADPCM_IMA_WAV:
1770 case AV_CODEC_ID_ADPCM_IMA_DK3:
1771 case AV_CODEC_ID_ADPCM_IMA_DK4:
1772 case AV_CODEC_ID_ADPCM_IMA_WS:
1773 case AV_CODEC_ID_ADPCM_IMA_SMJPEG:
1774 case AV_CODEC_ID_ADPCM_IMA_AMV:
1775 case AV_CODEC_ID_ADPCM_IMA_ISS:
1776 case AV_CODEC_ID_ADPCM_IMA_EA_EACS:
1777 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
1778 case AV_CODEC_ID_ADPCM_MS:
1779 case AV_CODEC_ID_ADPCM_4XM:
1780 case AV_CODEC_ID_ADPCM_XA:
1781 case AV_CODEC_ID_ADPCM_ADX:
1782 case AV_CODEC_ID_ADPCM_EA:
1783 case AV_CODEC_ID_ADPCM_CT:
1784 case AV_CODEC_ID_ADPCM_SWF:
1785 case AV_CODEC_ID_ADPCM_YAMAHA:
1786 case AV_CODEC_ID_ADPCM_SBPRO_2:
1787 case AV_CODEC_ID_ADPCM_SBPRO_3:
1788 case AV_CODEC_ID_ADPCM_SBPRO_4:
1789 case AV_CODEC_ID_ADPCM_EA_R1:
1790 case AV_CODEC_ID_ADPCM_EA_R2:
1791 case AV_CODEC_ID_ADPCM_EA_R3:
1792 case AV_CODEC_ID_ADPCM_EA_MAXIS_XA:
1793 case AV_CODEC_ID_ADPCM_EA_XAS:
1794 case AV_CODEC_ID_ADPCM_THP:
1796 const gchar *layout = NULL;
1799 case AV_CODEC_ID_ADPCM_IMA_QT:
1800 layout = "quicktime";
1802 case AV_CODEC_ID_ADPCM_IMA_WAV:
1805 case AV_CODEC_ID_ADPCM_IMA_DK3:
1808 case AV_CODEC_ID_ADPCM_IMA_DK4:
1811 case AV_CODEC_ID_ADPCM_IMA_WS:
1812 layout = "westwood";
1814 case AV_CODEC_ID_ADPCM_IMA_SMJPEG:
1817 case AV_CODEC_ID_ADPCM_IMA_AMV:
1820 case AV_CODEC_ID_ADPCM_IMA_ISS:
1823 case AV_CODEC_ID_ADPCM_IMA_EA_EACS:
1826 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
1829 case AV_CODEC_ID_ADPCM_MS:
1830 layout = "microsoft";
1832 case AV_CODEC_ID_ADPCM_4XM:
1835 case AV_CODEC_ID_ADPCM_XA:
1838 case AV_CODEC_ID_ADPCM_ADX:
1841 case AV_CODEC_ID_ADPCM_EA:
1844 case AV_CODEC_ID_ADPCM_CT:
1847 case AV_CODEC_ID_ADPCM_SWF:
1850 case AV_CODEC_ID_ADPCM_YAMAHA:
1853 case AV_CODEC_ID_ADPCM_SBPRO_2:
1856 case AV_CODEC_ID_ADPCM_SBPRO_3:
1859 case AV_CODEC_ID_ADPCM_SBPRO_4:
1862 case AV_CODEC_ID_ADPCM_EA_R1:
1865 case AV_CODEC_ID_ADPCM_EA_R2:
1868 case AV_CODEC_ID_ADPCM_EA_R3:
1871 case AV_CODEC_ID_ADPCM_EA_MAXIS_XA:
1872 layout = "ea-maxis-xa";
1874 case AV_CODEC_ID_ADPCM_EA_XAS:
1877 case AV_CODEC_ID_ADPCM_THP:
1881 g_assert (0); /* don't worry, we never get here */
1885 /* FIXME: someone please check whether we need additional properties
1886 * in this caps definition. */
1888 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-adpcm",
1889 "layout", G_TYPE_STRING, layout, NULL);
1891 gst_caps_set_simple (caps,
1892 "block_align", G_TYPE_INT, context->block_align,
1893 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1897 case AV_CODEC_ID_AMR_NB:
1899 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/AMR",
1903 case AV_CODEC_ID_AMR_WB:
1905 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/AMR-WB",
1909 case AV_CODEC_ID_GSM:
1911 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-gsm",
1915 case AV_CODEC_ID_GSM_MS:
1917 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/ms-gsm",
1921 case AV_CODEC_ID_NELLYMOSER:
1923 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1924 "audio/x-nellymoser", NULL);
1927 case AV_CODEC_ID_SIPR:
1930 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-sipro",
1933 gst_caps_set_simple (caps,
1934 "leaf_size", G_TYPE_INT, context->block_align,
1935 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1940 case AV_CODEC_ID_RA_144:
1941 case AV_CODEC_ID_RA_288:
1942 case AV_CODEC_ID_COOK:
1947 case AV_CODEC_ID_RA_144:
1950 case AV_CODEC_ID_RA_288:
1953 case AV_CODEC_ID_COOK:
1960 /* FIXME: properties? */
1962 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1963 "audio/x-pn-realaudio", "raversion", G_TYPE_INT, version, NULL);
1965 gst_caps_set_simple (caps,
1966 "leaf_size", G_TYPE_INT, context->block_align,
1967 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1972 case AV_CODEC_ID_ROQ_DPCM:
1973 case AV_CODEC_ID_INTERPLAY_DPCM:
1974 case AV_CODEC_ID_XAN_DPCM:
1975 case AV_CODEC_ID_SOL_DPCM:
1977 const gchar *layout = NULL;
1980 case AV_CODEC_ID_ROQ_DPCM:
1983 case AV_CODEC_ID_INTERPLAY_DPCM:
1984 layout = "interplay";
1986 case AV_CODEC_ID_XAN_DPCM:
1989 case AV_CODEC_ID_SOL_DPCM:
1993 g_assert (0); /* don't worry, we never get here */
1997 /* FIXME: someone please check whether we need additional properties
1998 * in this caps definition. */
2000 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dpcm",
2001 "layout", G_TYPE_STRING, layout, NULL);
2003 gst_caps_set_simple (caps,
2004 "block_align", G_TYPE_INT, context->block_align,
2005 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
2009 case AV_CODEC_ID_SHORTEN:
2010 caps = gst_caps_new_empty_simple ("audio/x-shorten");
2013 case AV_CODEC_ID_ALAC:
2015 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-alac",
2018 gst_caps_set_simple (caps,
2019 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
2023 case AV_CODEC_ID_FLAC:
2024 /* Note that ffmpeg has no encoder yet, but just for safety. In the
2025 * encoder case, we want to add things like samplerate, channels... */
2027 caps = gst_caps_new_empty_simple ("audio/x-flac");
2031 case AV_CODEC_ID_S302M:
2032 caps = gst_caps_new_empty_simple ("audio/x-smpte-302m");
2035 case AV_CODEC_ID_DVD_SUBTITLE:
2036 case AV_CODEC_ID_DVB_SUBTITLE:
2039 case AV_CODEC_ID_BMP:
2040 caps = gst_caps_new_empty_simple ("image/bmp");
2042 case AV_CODEC_ID_TTA:
2044 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-tta",
2047 gst_caps_set_simple (caps,
2048 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
2051 case AV_CODEC_ID_TWINVQ:
2053 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
2054 "audio/x-twin-vq", NULL);
2057 GST_DEBUG ("Unknown codec ID %d, please add mapping here", codec_id);
2064 if ((codec = avcodec_find_decoder (codec_id)) ||
2065 (codec = avcodec_find_encoder (codec_id))) {
2068 GST_LOG ("Could not create stream format caps for %s", codec->name);
2070 switch (codec->type) {
2071 case AVMEDIA_TYPE_VIDEO:
2072 mime = g_strdup_printf ("video/x-gst-av-%s", codec->name);
2074 gst_ff_vid_caps_new (context, NULL, codec_id, encode, mime, NULL);
2077 case AVMEDIA_TYPE_AUDIO:
2078 mime = g_strdup_printf ("audio/x-gst-av-%s", codec->name);
2080 gst_ff_aud_caps_new (context, NULL, codec_id, encode, mime, NULL);
2082 gst_caps_set_simple (caps,
2083 "block_align", G_TYPE_INT, context->block_align,
2084 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
2095 /* set private data */
2096 if (context && context->extradata_size > 0) {
2097 GstBuffer *data = gst_buffer_new_and_alloc (context->extradata_size);
2099 gst_buffer_fill (data, 0, context->extradata, context->extradata_size);
2100 gst_caps_set_simple (caps, "codec_data", GST_TYPE_BUFFER, data, NULL);
2101 gst_buffer_unref (data);
2104 GST_LOG ("caps for codec_id=%d: %" GST_PTR_FORMAT, codec_id, caps);
2107 GST_LOG ("No caps found for codec_id=%d", codec_id);
2113 /* Convert a FFMPEG Pixel Format and optional AVCodecContext
2114 * to a GstCaps. If the context is ommitted, no fixed values
2115 * for video/audio size will be included in the GstCaps
2117 * See below for usefullness
2121 gst_ffmpeg_pixfmt_to_caps (enum PixelFormat pix_fmt, AVCodecContext * context,
2122 enum CodecID codec_id)
2124 GstCaps *caps = NULL;
2125 GstVideoFormat format;
2127 format = gst_ffmpeg_pixfmt_to_videoformat (pix_fmt);
2129 if (format != GST_VIDEO_FORMAT_UNKNOWN) {
2130 caps = gst_ff_vid_caps_new (context, NULL, codec_id, TRUE, "video/x-raw",
2131 "format", G_TYPE_STRING, gst_video_format_to_string (format), NULL);
2135 GST_DEBUG ("caps for pix_fmt=%d: %" GST_PTR_FORMAT, pix_fmt, caps);
2137 GST_LOG ("No caps found for pix_fmt=%d", pix_fmt);
2144 gst_ffmpeg_smpfmt_to_audioformat (enum AVSampleFormat sample_fmt)
2146 switch (sample_fmt) {
2147 case AV_SAMPLE_FMT_U8:
2148 case AV_SAMPLE_FMT_U8P:
2149 return GST_AUDIO_FORMAT_U8;
2151 case AV_SAMPLE_FMT_S16:
2152 case AV_SAMPLE_FMT_S16P:
2153 return GST_AUDIO_FORMAT_S16;
2155 case AV_SAMPLE_FMT_S32:
2156 case AV_SAMPLE_FMT_S32P:
2157 return GST_AUDIO_FORMAT_S32;
2159 case AV_SAMPLE_FMT_FLT:
2160 case AV_SAMPLE_FMT_FLTP:
2161 return GST_AUDIO_FORMAT_F32;
2163 case AV_SAMPLE_FMT_DBL:
2164 case AV_SAMPLE_FMT_DBLP:
2165 return GST_AUDIO_FORMAT_F64;
2169 return GST_AUDIO_FORMAT_UNKNOWN;
2174 /* Convert a FFMPEG Sample Format and optional AVCodecContext
2175 * to a GstCaps. If the context is ommitted, no fixed values
2176 * for video/audio size will be included in the GstCaps
2178 * See below for usefullness
2182 gst_ffmpeg_smpfmt_to_caps (enum AVSampleFormat sample_fmt,
2183 AVCodecContext * context, AVCodec * codec, enum CodecID codec_id)
2185 GstCaps *caps = NULL;
2186 GstAudioFormat format;
2188 format = gst_ffmpeg_smpfmt_to_audioformat (sample_fmt);
2190 if (format != GST_AUDIO_FORMAT_UNKNOWN) {
2191 caps = gst_ff_aud_caps_new (context, codec, codec_id, TRUE, "audio/x-raw",
2192 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
2193 "layout", G_TYPE_STRING, "interleaved", NULL);
2194 GST_LOG ("caps for sample_fmt=%d: %" GST_PTR_FORMAT, sample_fmt, caps);
2196 GST_LOG ("No caps found for sample_fmt=%d", sample_fmt);
2203 caps_has_field (GstCaps * caps, const gchar * field)
2207 n = gst_caps_get_size (caps);
2208 for (i = 0; i < n; i++) {
2209 GstStructure *s = gst_caps_get_structure (caps, i);
2211 if (gst_structure_has_field (s, field))
2219 gst_ffmpeg_codectype_to_audio_caps (AVCodecContext * context,
2220 enum CodecID codec_id, gboolean encode, AVCodec * codec)
2222 GstCaps *caps = NULL;
2224 GST_DEBUG ("context:%p, codec_id:%d, encode:%d, codec:%p",
2225 context, codec_id, encode, codec);
2227 GST_DEBUG ("sample_fmts:%p, samplerates:%p",
2228 codec->sample_fmts, codec->supported_samplerates);
2231 /* Specific codec context */
2233 gst_ffmpeg_smpfmt_to_caps (context->sample_fmt, context, codec,
2236 caps = gst_ff_aud_caps_new (context, codec, codec_id, encode, "audio/x-raw",
2237 "layout", G_TYPE_STRING, "interleaved", NULL);
2238 if (!caps_has_field (caps, "format"))
2239 gst_ffmpeg_audio_set_sample_fmts (caps,
2240 codec ? codec->sample_fmts : NULL);
2247 gst_ffmpeg_codectype_to_video_caps (AVCodecContext * context,
2248 enum CodecID codec_id, gboolean encode, AVCodec * codec)
2252 GST_LOG ("context:%p, codec_id:%d, encode:%d, codec:%p",
2253 context, codec_id, encode, codec);
2256 caps = gst_ffmpeg_pixfmt_to_caps (context->pix_fmt, context, codec_id);
2259 gst_ff_vid_caps_new (context, codec, codec_id, encode, "video/x-raw",
2261 if (!caps_has_field (caps, "format"))
2262 gst_ffmpeg_video_set_pix_fmts (caps, codec ? codec->pix_fmts : NULL);
2267 /* Convert a GstCaps (audio/raw) to a FFMPEG SampleFmt
2268 * and other audio properties in a AVCodecContext.
2270 * For usefullness, see below
2274 gst_ffmpeg_caps_to_smpfmt (const GstCaps * caps,
2275 AVCodecContext * context, gboolean raw)
2277 GstStructure *structure;
2279 GstAudioFormat format = GST_AUDIO_FORMAT_UNKNOWN;
2281 g_return_if_fail (gst_caps_get_size (caps) == 1);
2283 structure = gst_caps_get_structure (caps, 0);
2285 gst_structure_get_int (structure, "channels", &context->channels);
2286 gst_structure_get_int (structure, "rate", &context->sample_rate);
2287 gst_structure_get_int (structure, "block_align", &context->block_align);
2288 gst_structure_get_int (structure, "bitrate", &context->bit_rate);
2293 if (gst_structure_has_name (structure, "audio/x-raw")) {
2294 if ((fmt = gst_structure_get_string (structure, "format"))) {
2295 format = gst_audio_format_from_string (fmt);
2300 case GST_AUDIO_FORMAT_F32:
2301 context->sample_fmt = AV_SAMPLE_FMT_FLT;
2303 case GST_AUDIO_FORMAT_F64:
2304 context->sample_fmt = AV_SAMPLE_FMT_DBL;
2306 case GST_AUDIO_FORMAT_S32:
2307 context->sample_fmt = AV_SAMPLE_FMT_S32;
2309 case GST_AUDIO_FORMAT_S16:
2310 context->sample_fmt = AV_SAMPLE_FMT_S16;
2317 /* Convert a GstCaps (video/raw) to a FFMPEG PixFmt
2318 * and other video properties in a AVCodecContext.
2320 * For usefullness, see below
2324 gst_ffmpeg_caps_to_pixfmt (const GstCaps * caps,
2325 AVCodecContext * context, gboolean raw)
2327 GstStructure *structure;
2329 const GValue *par = NULL;
2331 GstVideoFormat format = GST_VIDEO_FORMAT_UNKNOWN;
2333 GST_DEBUG ("converting caps %" GST_PTR_FORMAT, caps);
2334 g_return_if_fail (gst_caps_get_size (caps) == 1);
2335 structure = gst_caps_get_structure (caps, 0);
2337 gst_structure_get_int (structure, "width", &context->width);
2338 gst_structure_get_int (structure, "height", &context->height);
2339 gst_structure_get_int (structure, "bpp", &context->bits_per_coded_sample);
2341 fps = gst_structure_get_value (structure, "framerate");
2342 if (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps)) {
2344 /* somehow these seem mixed up.. */
2345 context->time_base.den = gst_value_get_fraction_numerator (fps);
2346 context->time_base.num = gst_value_get_fraction_denominator (fps);
2347 context->ticks_per_frame = 1;
2349 GST_DEBUG ("setting framerate %d/%d = %lf",
2350 context->time_base.den, context->time_base.num,
2351 1. * context->time_base.den / context->time_base.num);
2354 par = gst_structure_get_value (structure, "pixel-aspect-ratio");
2355 if (par && GST_VALUE_HOLDS_FRACTION (par)) {
2357 context->sample_aspect_ratio.num = gst_value_get_fraction_numerator (par);
2358 context->sample_aspect_ratio.den = gst_value_get_fraction_denominator (par);
2360 GST_DEBUG ("setting pixel-aspect-ratio %d/%d = %lf",
2361 context->sample_aspect_ratio.den, context->sample_aspect_ratio.num,
2362 1. * context->sample_aspect_ratio.den /
2363 context->sample_aspect_ratio.num);
2369 g_return_if_fail (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps));
2371 if (gst_structure_has_name (structure, "video/x-raw")) {
2372 if ((fmt = gst_structure_get_string (structure, "format"))) {
2373 format = gst_video_format_from_string (fmt);
2378 case GST_VIDEO_FORMAT_YUY2:
2379 context->pix_fmt = PIX_FMT_YUYV422;
2381 case GST_VIDEO_FORMAT_I420:
2382 context->pix_fmt = PIX_FMT_YUV420P;
2384 case GST_VIDEO_FORMAT_A420:
2385 context->pix_fmt = PIX_FMT_YUVA420P;
2387 case GST_VIDEO_FORMAT_Y41B:
2388 context->pix_fmt = PIX_FMT_YUV411P;
2390 case GST_VIDEO_FORMAT_Y42B:
2391 context->pix_fmt = PIX_FMT_YUV422P;
2393 case GST_VIDEO_FORMAT_YUV9:
2394 context->pix_fmt = PIX_FMT_YUV410P;
2396 case GST_VIDEO_FORMAT_Y444:
2397 context->pix_fmt = PIX_FMT_YUV444P;
2399 case GST_VIDEO_FORMAT_GRAY8:
2400 context->pix_fmt = PIX_FMT_GRAY8;
2402 case GST_VIDEO_FORMAT_xRGB:
2403 #if (G_BYTE_ORDER == G_BIG_ENDIAN)
2404 context->pix_fmt = PIX_FMT_RGB32;
2407 case GST_VIDEO_FORMAT_BGRx:
2408 #if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
2409 context->pix_fmt = PIX_FMT_RGB32;
2412 case GST_VIDEO_FORMAT_RGB:
2413 context->pix_fmt = PIX_FMT_RGB24;
2415 case GST_VIDEO_FORMAT_BGR:
2416 context->pix_fmt = PIX_FMT_BGR24;
2418 case GST_VIDEO_FORMAT_RGB16:
2419 context->pix_fmt = PIX_FMT_RGB565;
2421 case GST_VIDEO_FORMAT_RGB15:
2422 context->pix_fmt = PIX_FMT_RGB555;
2424 case GST_VIDEO_FORMAT_RGB8P:
2425 context->pix_fmt = PIX_FMT_PAL8;
2434 GstVideoFormat format;
2435 enum PixelFormat pixfmt;
2438 /* FIXME : FILLME */
2439 static const PixToFmt pixtofmttable[] = {
2440 /* GST_VIDEO_FORMAT_I420, */
2441 {GST_VIDEO_FORMAT_I420, PIX_FMT_YUV420P},
2442 /* Note : this should use a different chroma placement */
2443 {GST_VIDEO_FORMAT_I420, PIX_FMT_YUVJ420P},
2445 /* GST_VIDEO_FORMAT_YV12, */
2446 /* GST_VIDEO_FORMAT_YUY2, */
2447 {GST_VIDEO_FORMAT_YUY2, PIX_FMT_YUYV422},
2448 /* GST_VIDEO_FORMAT_UYVY, */
2449 {GST_VIDEO_FORMAT_UYVY, PIX_FMT_UYVY422},
2450 /* GST_VIDEO_FORMAT_AYUV, */
2451 /* GST_VIDEO_FORMAT_RGBx, */
2452 /* GST_VIDEO_FORMAT_BGRx, */
2453 /* GST_VIDEO_FORMAT_xRGB, */
2454 /* GST_VIDEO_FORMAT_xBGR, */
2455 /* GST_VIDEO_FORMAT_RGBA, */
2456 {GST_VIDEO_FORMAT_RGBA, PIX_FMT_RGBA},
2457 /* GST_VIDEO_FORMAT_BGRA, */
2458 {GST_VIDEO_FORMAT_BGRA, PIX_FMT_BGRA},
2459 /* GST_VIDEO_FORMAT_ARGB, */
2460 {GST_VIDEO_FORMAT_ARGB, PIX_FMT_ARGB},
2461 /* GST_VIDEO_FORMAT_ABGR, */
2462 {GST_VIDEO_FORMAT_ABGR, PIX_FMT_ABGR},
2463 /* GST_VIDEO_FORMAT_RGB, */
2464 {GST_VIDEO_FORMAT_RGB, PIX_FMT_RGB24},
2465 /* GST_VIDEO_FORMAT_BGR, */
2466 {GST_VIDEO_FORMAT_BGR, PIX_FMT_BGR24},
2467 /* GST_VIDEO_FORMAT_Y41B, */
2468 {GST_VIDEO_FORMAT_Y41B, PIX_FMT_YUV411P},
2469 /* GST_VIDEO_FORMAT_Y42B, */
2470 {GST_VIDEO_FORMAT_Y42B, PIX_FMT_YUV422P},
2471 {GST_VIDEO_FORMAT_Y42B, PIX_FMT_YUVJ422P},
2472 /* GST_VIDEO_FORMAT_YVYU, */
2473 /* GST_VIDEO_FORMAT_Y444, */
2474 {GST_VIDEO_FORMAT_Y444, PIX_FMT_YUV444P},
2475 {GST_VIDEO_FORMAT_Y444, PIX_FMT_YUVJ444P},
2476 /* GST_VIDEO_FORMAT_v210, */
2477 /* GST_VIDEO_FORMAT_v216, */
2478 /* GST_VIDEO_FORMAT_NV12, */
2479 {GST_VIDEO_FORMAT_NV12, PIX_FMT_NV12},
2480 /* GST_VIDEO_FORMAT_NV21, */
2481 {GST_VIDEO_FORMAT_NV21, PIX_FMT_NV21},
2482 /* GST_VIDEO_FORMAT_GRAY8, */
2483 {GST_VIDEO_FORMAT_GRAY8, PIX_FMT_GRAY8},
2484 /* GST_VIDEO_FORMAT_GRAY16_BE, */
2485 {GST_VIDEO_FORMAT_GRAY16_BE, PIX_FMT_GRAY16BE},
2486 /* GST_VIDEO_FORMAT_GRAY16_LE, */
2487 {GST_VIDEO_FORMAT_GRAY16_LE, PIX_FMT_GRAY16LE},
2488 /* GST_VIDEO_FORMAT_v308, */
2489 /* GST_VIDEO_FORMAT_Y800, */
2490 /* GST_VIDEO_FORMAT_Y16, */
2491 /* GST_VIDEO_FORMAT_RGB16, */
2492 {GST_VIDEO_FORMAT_RGB16, PIX_FMT_RGB565},
2493 /* GST_VIDEO_FORMAT_BGR16, */
2494 /* GST_VIDEO_FORMAT_RGB15, */
2495 {GST_VIDEO_FORMAT_RGB15, PIX_FMT_RGB555},
2496 /* GST_VIDEO_FORMAT_BGR15, */
2497 /* GST_VIDEO_FORMAT_UYVP, */
2498 /* GST_VIDEO_FORMAT_A420, */
2499 {GST_VIDEO_FORMAT_A420, PIX_FMT_YUVA420P},
2500 /* GST_VIDEO_FORMAT_RGB8_PALETTED, */
2501 {GST_VIDEO_FORMAT_RGB8P, PIX_FMT_PAL8},
2502 /* GST_VIDEO_FORMAT_YUV9, */
2503 {GST_VIDEO_FORMAT_YUV9, PIX_FMT_YUV410P},
2504 /* GST_VIDEO_FORMAT_YVU9, */
2505 /* GST_VIDEO_FORMAT_IYU1, */
2506 /* GST_VIDEO_FORMAT_ARGB64, */
2507 /* GST_VIDEO_FORMAT_AYUV64, */
2508 /* GST_VIDEO_FORMAT_r210, */
2509 {GST_VIDEO_FORMAT_I420_10LE, PIX_FMT_YUV420P10LE},
2510 {GST_VIDEO_FORMAT_I420_10BE, PIX_FMT_YUV420P10BE},
2511 {GST_VIDEO_FORMAT_I422_10LE, PIX_FMT_YUV422P10LE},
2512 {GST_VIDEO_FORMAT_I422_10BE, PIX_FMT_YUV422P10BE},
2513 {GST_VIDEO_FORMAT_Y444_10LE, PIX_FMT_YUV444P10LE},
2514 {GST_VIDEO_FORMAT_Y444_10BE, PIX_FMT_YUV444P10BE},
2515 {GST_VIDEO_FORMAT_GBR, PIX_FMT_GBRP},
2516 {GST_VIDEO_FORMAT_GBR_10LE, PIX_FMT_GBRP10LE},
2517 {GST_VIDEO_FORMAT_GBR_10BE, PIX_FMT_GBRP10BE},
2521 gst_ffmpeg_pixfmt_to_videoformat (enum PixelFormat pixfmt)
2525 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2526 if (pixtofmttable[i].pixfmt == pixfmt)
2527 return pixtofmttable[i].format;
2529 GST_DEBUG ("Unknown pixel format %d", pixfmt);
2530 return GST_VIDEO_FORMAT_UNKNOWN;
2534 gst_ffmpeg_videoformat_to_pixfmt (GstVideoFormat format)
2538 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2539 if (pixtofmttable[i].format == format)
2540 return pixtofmttable[i].pixfmt;
2541 return PIX_FMT_NONE;
2545 gst_ffmpeg_videoinfo_to_context (GstVideoInfo * info, AVCodecContext * context)
2549 context->width = GST_VIDEO_INFO_WIDTH (info);
2550 context->height = GST_VIDEO_INFO_HEIGHT (info);
2551 for (i = 0; i < GST_VIDEO_INFO_N_COMPONENTS (info); i++)
2552 bpp += GST_VIDEO_INFO_COMP_DEPTH (info, i);
2553 context->bits_per_coded_sample = bpp;
2555 context->ticks_per_frame = 1;
2556 if (GST_VIDEO_INFO_FPS_N (info) == 0) {
2557 GST_DEBUG ("Using 25/1 framerate");
2558 context->time_base.den = 25;
2559 context->time_base.num = 1;
2561 context->time_base.den = GST_VIDEO_INFO_FPS_N (info);
2562 context->time_base.num = GST_VIDEO_INFO_FPS_D (info);
2565 context->sample_aspect_ratio.num = GST_VIDEO_INFO_PAR_N (info);
2566 context->sample_aspect_ratio.den = GST_VIDEO_INFO_PAR_D (info);
2569 gst_ffmpeg_videoformat_to_pixfmt (GST_VIDEO_INFO_FORMAT (info));
2573 gst_ffmpeg_audioinfo_to_context (GstAudioInfo * info, AVCodecContext * context)
2575 const AVCodec *codec;
2576 const enum AVSampleFormat *smpl_fmts;
2577 enum AVSampleFormat smpl_fmt = -1;
2579 context->channels = info->channels;
2580 context->sample_rate = info->rate;
2581 context->channel_layout =
2582 gst_ffmpeg_channel_positions_to_layout (info->position, info->channels);
2584 codec = context->codec;
2586 smpl_fmts = codec->sample_fmts;
2588 switch (info->finfo->format) {
2589 case GST_AUDIO_FORMAT_F32:
2591 while (*smpl_fmts != -1) {
2592 if (*smpl_fmts == AV_SAMPLE_FMT_FLT) {
2593 smpl_fmt = *smpl_fmts;
2595 } else if (*smpl_fmts == AV_SAMPLE_FMT_FLTP) {
2596 smpl_fmt = *smpl_fmts;
2602 smpl_fmt = AV_SAMPLE_FMT_FLT;
2605 case GST_AUDIO_FORMAT_F64:
2607 while (*smpl_fmts != -1) {
2608 if (*smpl_fmts == AV_SAMPLE_FMT_DBL) {
2609 smpl_fmt = *smpl_fmts;
2611 } else if (*smpl_fmts == AV_SAMPLE_FMT_DBLP) {
2612 smpl_fmt = *smpl_fmts;
2618 smpl_fmt = AV_SAMPLE_FMT_DBL;
2621 case GST_AUDIO_FORMAT_S32:
2623 while (*smpl_fmts != -1) {
2624 if (*smpl_fmts == AV_SAMPLE_FMT_S32) {
2625 smpl_fmt = *smpl_fmts;
2627 } else if (*smpl_fmts == AV_SAMPLE_FMT_S32P) {
2628 smpl_fmt = *smpl_fmts;
2634 smpl_fmt = AV_SAMPLE_FMT_S32;
2637 case GST_AUDIO_FORMAT_S16:
2639 while (*smpl_fmts != -1) {
2640 if (*smpl_fmts == AV_SAMPLE_FMT_S16) {
2641 smpl_fmt = *smpl_fmts;
2643 } else if (*smpl_fmts == AV_SAMPLE_FMT_S16P) {
2644 smpl_fmt = *smpl_fmts;
2650 smpl_fmt = AV_SAMPLE_FMT_S16;
2653 case GST_AUDIO_FORMAT_U8:
2655 while (*smpl_fmts != -1) {
2656 if (*smpl_fmts == AV_SAMPLE_FMT_U8) {
2657 smpl_fmt = *smpl_fmts;
2659 } else if (*smpl_fmts == AV_SAMPLE_FMT_U8P) {
2660 smpl_fmt = *smpl_fmts;
2666 smpl_fmt = AV_SAMPLE_FMT_U8;
2673 g_assert (smpl_fmt != -1);
2675 context->sample_fmt = smpl_fmt;
2678 /* Convert a GstCaps and a FFMPEG codec Type to a
2679 * AVCodecContext. If the context is ommitted, no fixed values
2680 * for video/audio size will be included in the context
2682 * AVMediaType is primarily meant for uncompressed data GstCaps!
2686 gst_ffmpeg_caps_with_codectype (enum AVMediaType type,
2687 const GstCaps * caps, AVCodecContext * context)
2689 if (context == NULL)
2693 case AVMEDIA_TYPE_VIDEO:
2694 gst_ffmpeg_caps_to_pixfmt (caps, context, TRUE);
2697 case AVMEDIA_TYPE_AUDIO:
2698 gst_ffmpeg_caps_to_smpfmt (caps, context, TRUE);
2709 nal_escape (guint8 * dst, guint8 * src, guint size, guint * destsize)
2713 guint8 *end = src + size;
2716 while (srcp < end) {
2717 if (count == 2 && *srcp <= 0x03) {
2718 GST_DEBUG ("added escape code");
2727 GST_DEBUG ("copy %02x, count %d", *srcp, count);
2730 *destsize = dstp - dst;
2733 /* copy the config, escaping NAL units as we iterate them, if something fails we
2734 * copy everything and hope for the best. */
2736 copy_config (guint8 * dst, guint8 * src, guint size, guint * destsize)
2741 guint nalsize, esize;
2751 cnt = *(srcp + 5) & 0x1f; /* Number of sps */
2753 GST_DEBUG ("num SPS %d", cnt);
2755 memcpy (dstp, srcp, 6);
2759 for (i = 0; i < cnt; i++) {
2760 GST_DEBUG ("copy SPS %d", i);
2761 nalsize = (srcp[0] << 8) | srcp[1];
2762 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2763 dstp[0] = esize >> 8;
2764 dstp[1] = esize & 0xff;
2766 srcp += nalsize + 2;
2769 cnt = *(dstp++) = *(srcp++); /* Number of pps */
2771 GST_DEBUG ("num PPS %d", cnt);
2773 for (i = 0; i < cnt; i++) {
2774 GST_DEBUG ("copy PPS %d", i);
2775 nalsize = (srcp[0] << 8) | srcp[1];
2776 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2777 dstp[0] = esize >> 8;
2778 dstp[1] = esize & 0xff;
2780 srcp += nalsize + 2;
2782 *destsize = dstp - dst;
2788 GST_DEBUG ("something unexpected, doing full copy");
2789 memcpy (dst, src, size);
2797 * caps_with_codecid () transforms a GstCaps for a known codec
2798 * ID into a filled-in context.
2799 * codec_data from caps will override possible extradata already in the context
2803 gst_ffmpeg_caps_with_codecid (enum CodecID codec_id,
2804 enum AVMediaType codec_type, const GstCaps * caps, AVCodecContext * context)
2807 const GValue *value;
2810 GST_LOG ("codec_id:%d, codec_type:%d, caps:%" GST_PTR_FORMAT " context:%p",
2811 codec_id, codec_type, caps, context);
2813 if (!context || !gst_caps_get_size (caps))
2816 str = gst_caps_get_structure (caps, 0);
2818 /* extradata parsing (esds [mpeg4], wma/wmv, msmpeg4v1/2/3, etc.) */
2819 if ((value = gst_structure_get_value (str, "codec_data"))) {
2822 buf = gst_value_get_buffer (value);
2823 gst_buffer_map (buf, &map, GST_MAP_READ);
2825 /* free the old one if it is there */
2826 if (context->extradata)
2827 av_free (context->extradata);
2830 if (codec_id == AV_CODEC_ID_H264) {
2833 GST_DEBUG ("copy, escaping codec_data %d", size);
2834 /* ffmpeg h264 expects the codec_data to be escaped, there is no real
2835 * reason for this but let's just escape it for now. Start by allocating
2836 * enough space, x2 is more than enough.
2838 * FIXME, we disabled escaping because some file already contain escaped
2839 * codec_data and then we escape twice and fail. It's better to leave it
2840 * as is, as that is what most players do. */
2841 context->extradata =
2842 av_mallocz (GST_ROUND_UP_16 (size * 2 +
2843 FF_INPUT_BUFFER_PADDING_SIZE));
2844 copy_config (context->extradata, data, size, &extrasize);
2845 GST_DEBUG ("escaped size: %d", extrasize);
2846 context->extradata_size = extrasize;
2850 /* allocate with enough padding */
2851 GST_DEBUG ("copy codec_data");
2852 context->extradata =
2853 av_mallocz (GST_ROUND_UP_16 (map.size +
2854 FF_INPUT_BUFFER_PADDING_SIZE));
2855 memcpy (context->extradata, map.data, map.size);
2856 context->extradata_size = map.size;
2859 /* Hack for VC1. Sometimes the first (length) byte is 0 for some files */
2860 if (codec_id == AV_CODEC_ID_VC1 && map.size > 0 && map.data[0] == 0) {
2861 context->extradata[0] = (guint8) map.size;
2864 GST_DEBUG ("have codec data of size %" G_GSIZE_FORMAT, map.size);
2866 gst_buffer_unmap (buf, &map);
2867 } else if (context->extradata == NULL && codec_id != AV_CODEC_ID_AAC_LATM &&
2868 codec_id != AV_CODEC_ID_FLAC) {
2869 /* no extradata, alloc dummy with 0 sized, some codecs insist on reading
2870 * extradata anyway which makes then segfault. */
2871 context->extradata =
2872 av_mallocz (GST_ROUND_UP_16 (FF_INPUT_BUFFER_PADDING_SIZE));
2873 context->extradata_size = 0;
2874 GST_DEBUG ("no codec data");
2878 case AV_CODEC_ID_MPEG4:
2880 const gchar *mime = gst_structure_get_name (str);
2882 if (!strcmp (mime, "video/x-divx"))
2883 context->codec_tag = GST_MAKE_FOURCC ('D', 'I', 'V', 'X');
2884 else if (!strcmp (mime, "video/x-xvid"))
2885 context->codec_tag = GST_MAKE_FOURCC ('X', 'V', 'I', 'D');
2886 else if (!strcmp (mime, "video/x-3ivx"))
2887 context->codec_tag = GST_MAKE_FOURCC ('3', 'I', 'V', '1');
2888 else if (!strcmp (mime, "video/mpeg"))
2889 context->codec_tag = GST_MAKE_FOURCC ('m', 'p', '4', 'v');
2893 case AV_CODEC_ID_SVQ3:
2894 /* FIXME: this is a workaround for older gst-plugins releases
2895 * (<= 0.8.9). This should be removed at some point, because
2896 * it causes wrong decoded frame order. */
2897 if (!context->extradata) {
2898 gint halfpel_flag, thirdpel_flag, low_delay, unknown_svq3_flag;
2901 if (gst_structure_get_int (str, "halfpel_flag", &halfpel_flag) &&
2902 gst_structure_get_int (str, "thirdpel_flag", &thirdpel_flag) &&
2903 gst_structure_get_int (str, "low_delay", &low_delay) &&
2904 gst_structure_get_int (str, "unknown_svq3_flag",
2905 &unknown_svq3_flag)) {
2906 context->extradata = (guint8 *) av_mallocz (0x64);
2907 g_stpcpy ((gchar *) context->extradata, "SVQ3");
2911 flags |= unknown_svq3_flag;
2913 flags |= halfpel_flag;
2915 flags |= thirdpel_flag;
2918 flags = GUINT16_FROM_LE (flags);
2920 memcpy ((gchar *) context->extradata + 0x62, &flags, 2);
2921 context->extradata_size = 0x64;
2926 case AV_CODEC_ID_MSRLE:
2927 case AV_CODEC_ID_QTRLE:
2928 case AV_CODEC_ID_TSCC:
2929 case AV_CODEC_ID_CSCD:
2930 case AV_CODEC_ID_APE:
2934 if (gst_structure_get_int (str, "depth", &depth)) {
2935 context->bits_per_coded_sample = depth;
2937 GST_WARNING ("No depth field in caps %" GST_PTR_FORMAT, caps);
2943 case AV_CODEC_ID_RV10:
2944 case AV_CODEC_ID_RV20:
2945 case AV_CODEC_ID_RV30:
2946 case AV_CODEC_ID_RV40:
2950 if (gst_structure_get_int (str, "format", &format))
2951 context->sub_id = format;
2955 case AV_CODEC_ID_COOK:
2956 case AV_CODEC_ID_RA_288:
2957 case AV_CODEC_ID_RA_144:
2958 case AV_CODEC_ID_SIPR:
2963 if (gst_structure_get_int (str, "leaf_size", &leaf_size))
2964 context->block_align = leaf_size;
2965 if (gst_structure_get_int (str, "bitrate", &bitrate))
2966 context->bit_rate = bitrate;
2968 case AV_CODEC_ID_ALAC:
2969 gst_structure_get_int (str, "samplesize",
2970 &context->bits_per_coded_sample);
2973 case AV_CODEC_ID_DVVIDEO:
2975 const gchar *format;
2977 if ((format = gst_structure_get_string (str, "format"))) {
2979 if (g_str_equal (format, "YUY2"))
2980 context->pix_fmt = PIX_FMT_YUYV422;
2981 else if (g_str_equal (format, "I420"))
2982 context->pix_fmt = PIX_FMT_YUV420P;
2983 else if (g_str_equal (format, "A420"))
2984 context->pix_fmt = PIX_FMT_YUVA420P;
2985 else if (g_str_equal (format, "Y41B"))
2986 context->pix_fmt = PIX_FMT_YUV411P;
2987 else if (g_str_equal (format, "Y42B"))
2988 context->pix_fmt = PIX_FMT_YUV422P;
2989 else if (g_str_equal (format, "YUV9"))
2990 context->pix_fmt = PIX_FMT_YUV410P;
2992 GST_WARNING ("couldn't convert format %s" " to a pixel format",
2996 GST_WARNING ("No specified format");
2999 case AV_CODEC_ID_H263P:
3003 if (!gst_structure_get_boolean (str, "annex-f", &val) || val)
3004 context->flags |= CODEC_FLAG_4MV;
3006 context->flags &= ~CODEC_FLAG_4MV;
3007 if ((!gst_structure_get_boolean (str, "annex-i", &val) || val) &&
3008 (!gst_structure_get_boolean (str, "annex-t", &val) || val))
3009 context->flags |= CODEC_FLAG_AC_PRED;
3011 context->flags &= ~CODEC_FLAG_AC_PRED;
3012 if (!gst_structure_get_boolean (str, "annex-j", &val) || val)
3013 context->flags |= CODEC_FLAG_LOOP_FILTER;
3015 context->flags &= ~CODEC_FLAG_LOOP_FILTER;
3018 case AV_CODEC_ID_ADPCM_G726:
3020 const gchar *layout;
3022 if ((layout = gst_structure_get_string (str, "layout"))) {
3023 if (!strcmp (layout, "g721")) {
3024 context->sample_rate = 8000;
3025 context->channels = 1;
3026 context->bit_rate = 32000;
3035 if (!gst_caps_is_fixed (caps))
3038 /* common properties (width, height, fps) */
3039 switch (codec_type) {
3040 case AVMEDIA_TYPE_VIDEO:
3041 gst_ffmpeg_caps_to_pixfmt (caps, context,
3042 codec_id == AV_CODEC_ID_RAWVIDEO);
3044 case AVMEDIA_TYPE_AUDIO:
3045 gst_ffmpeg_caps_to_smpfmt (caps, context, FALSE);
3051 /* fixup of default settings */
3053 case AV_CODEC_ID_QCELP:
3054 /* QCELP is always mono, no matter what the caps say */
3055 context->channels = 1;
3057 case AV_CODEC_ID_ADPCM_G726:
3058 if (context->sample_rate && context->bit_rate)
3059 context->bits_per_coded_sample =
3060 context->bit_rate / context->sample_rate;
3067 /* _formatid_to_caps () is meant for muxers/demuxers, it
3068 * transforms a name (ffmpeg way of ID'ing these, why don't
3069 * they have unique numerical IDs?) to the corresponding
3070 * caps belonging to that mux-format
3072 * Note: we don't need any additional info because the caps
3073 * isn't supposed to contain any useful info besides the
3078 gst_ffmpeg_formatid_to_caps (const gchar * format_name)
3080 GstCaps *caps = NULL;
3082 if (!strcmp (format_name, "mpeg")) {
3083 caps = gst_caps_new_simple ("video/mpeg",
3084 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3085 } else if (!strcmp (format_name, "mpegts")) {
3086 caps = gst_caps_new_simple ("video/mpegts",
3087 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3088 } else if (!strcmp (format_name, "rm")) {
3089 caps = gst_caps_new_simple ("application/x-pn-realmedia",
3090 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3091 } else if (!strcmp (format_name, "asf")) {
3092 caps = gst_caps_new_empty_simple ("video/x-ms-asf");
3093 } else if (!strcmp (format_name, "avi")) {
3094 caps = gst_caps_new_empty_simple ("video/x-msvideo");
3095 } else if (!strcmp (format_name, "wav")) {
3096 caps = gst_caps_new_empty_simple ("audio/x-wav");
3097 } else if (!strcmp (format_name, "ape")) {
3098 caps = gst_caps_new_empty_simple ("application/x-ape");
3099 } else if (!strcmp (format_name, "swf")) {
3100 caps = gst_caps_new_empty_simple ("application/x-shockwave-flash");
3101 } else if (!strcmp (format_name, "au")) {
3102 caps = gst_caps_new_empty_simple ("audio/x-au");
3103 } else if (!strcmp (format_name, "dv")) {
3104 caps = gst_caps_new_simple ("video/x-dv",
3105 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3106 } else if (!strcmp (format_name, "4xm")) {
3107 caps = gst_caps_new_empty_simple ("video/x-4xm");
3108 } else if (!strcmp (format_name, "matroska")) {
3109 caps = gst_caps_new_empty_simple ("video/x-matroska");
3110 } else if (!strcmp (format_name, "mp3")) {
3111 caps = gst_caps_new_empty_simple ("application/x-id3");
3112 } else if (!strcmp (format_name, "flic")) {
3113 caps = gst_caps_new_empty_simple ("video/x-fli");
3114 } else if (!strcmp (format_name, "flv")) {
3115 caps = gst_caps_new_empty_simple ("video/x-flv");
3116 } else if (!strcmp (format_name, "tta")) {
3117 caps = gst_caps_new_empty_simple ("audio/x-ttafile");
3118 } else if (!strcmp (format_name, "aiff")) {
3119 caps = gst_caps_new_empty_simple ("audio/x-aiff");
3120 } else if (!strcmp (format_name, "mov_mp4_m4a_3gp_3g2")) {
3122 gst_caps_from_string
3123 ("application/x-3gp; video/quicktime; audio/x-m4a");
3124 } else if (!strcmp (format_name, "mov")) {
3125 caps = gst_caps_from_string ("video/quicktime,variant=(string)apple");
3126 } else if (!strcmp (format_name, "mp4")) {
3127 caps = gst_caps_from_string ("video/quicktime,variant=(string)iso");
3128 } else if (!strcmp (format_name, "3gp")) {
3129 caps = gst_caps_from_string ("video/quicktime,variant=(string)3gpp");
3130 } else if (!strcmp (format_name, "3g2")) {
3131 caps = gst_caps_from_string ("video/quicktime,variant=(string)3g2");
3132 } else if (!strcmp (format_name, "psp")) {
3133 caps = gst_caps_from_string ("video/quicktime,variant=(string)psp");
3134 } else if (!strcmp (format_name, "ipod")) {
3135 caps = gst_caps_from_string ("video/quicktime,variant=(string)ipod");
3136 } else if (!strcmp (format_name, "aac")) {
3137 caps = gst_caps_new_simple ("audio/mpeg",
3138 "mpegversion", G_TYPE_INT, 4, NULL);
3139 } else if (!strcmp (format_name, "gif")) {
3140 caps = gst_caps_from_string ("image/gif");
3141 } else if (!strcmp (format_name, "ogg")) {
3142 caps = gst_caps_from_string ("application/ogg");
3143 } else if (!strcmp (format_name, "mxf") || !strcmp (format_name, "mxf_d10")) {
3144 caps = gst_caps_from_string ("application/mxf");
3145 } else if (!strcmp (format_name, "gxf")) {
3146 caps = gst_caps_from_string ("application/gxf");
3147 } else if (!strcmp (format_name, "yuv4mpegpipe")) {
3148 caps = gst_caps_new_simple ("application/x-yuv4mpeg",
3149 "y4mversion", G_TYPE_INT, 2, NULL);
3150 } else if (!strcmp (format_name, "mpc")) {
3151 caps = gst_caps_from_string ("audio/x-musepack, streamversion = (int) 7");
3152 } else if (!strcmp (format_name, "vqf")) {
3153 caps = gst_caps_from_string ("audio/x-vqf");
3154 } else if (!strcmp (format_name, "nsv")) {
3155 caps = gst_caps_from_string ("video/x-nsv");
3156 } else if (!strcmp (format_name, "amr")) {
3157 caps = gst_caps_from_string ("audio/x-amr-nb-sh");
3158 } else if (!strcmp (format_name, "webm")) {
3159 caps = gst_caps_from_string ("video/webm");
3160 } else if (!strcmp (format_name, "voc")) {
3161 caps = gst_caps_from_string ("audio/x-voc");
3162 } else if (!strcmp (format_name, "pva")) {
3163 caps = gst_caps_from_string ("video/x-pva");
3167 GST_LOG ("Could not create stream format caps for %s", format_name);
3168 name = g_strdup_printf ("application/x-gst-av-%s", format_name);
3169 caps = gst_caps_new_empty_simple (name);
3177 gst_ffmpeg_formatid_get_codecids (const gchar * format_name,
3178 enum CodecID ** video_codec_list, enum CodecID ** audio_codec_list,
3179 AVOutputFormat * plugin)
3181 static enum CodecID tmp_vlist[] = {
3185 static enum CodecID tmp_alist[] = {
3190 GST_LOG ("format_name : %s", format_name);
3192 if (!strcmp (format_name, "mp4")) {
3193 static enum CodecID mp4_video_list[] = {
3194 AV_CODEC_ID_MPEG4, AV_CODEC_ID_H264,
3198 static enum CodecID mp4_audio_list[] = {
3199 AV_CODEC_ID_AAC, AV_CODEC_ID_MP3,
3203 *video_codec_list = mp4_video_list;
3204 *audio_codec_list = mp4_audio_list;
3205 } else if (!strcmp (format_name, "mpeg")) {
3206 static enum CodecID mpeg_video_list[] = { AV_CODEC_ID_MPEG1VIDEO,
3207 AV_CODEC_ID_MPEG2VIDEO,
3211 static enum CodecID mpeg_audio_list[] = { AV_CODEC_ID_MP1,
3217 *video_codec_list = mpeg_video_list;
3218 *audio_codec_list = mpeg_audio_list;
3219 } else if (!strcmp (format_name, "dvd")) {
3220 static enum CodecID mpeg_video_list[] = { AV_CODEC_ID_MPEG2VIDEO,
3223 static enum CodecID mpeg_audio_list[] = { AV_CODEC_ID_MP2,
3226 AV_CODEC_ID_PCM_S16BE,
3230 *video_codec_list = mpeg_video_list;
3231 *audio_codec_list = mpeg_audio_list;
3232 } else if (!strcmp (format_name, "mpegts")) {
3233 static enum CodecID mpegts_video_list[] = { AV_CODEC_ID_MPEG1VIDEO,
3234 AV_CODEC_ID_MPEG2VIDEO,
3238 static enum CodecID mpegts_audio_list[] = { AV_CODEC_ID_MP2,
3246 *video_codec_list = mpegts_video_list;
3247 *audio_codec_list = mpegts_audio_list;
3248 } else if (!strcmp (format_name, "vob")) {
3249 static enum CodecID vob_video_list[] =
3250 { AV_CODEC_ID_MPEG2VIDEO, AV_CODEC_ID_NONE };
3251 static enum CodecID vob_audio_list[] = { AV_CODEC_ID_MP2, AV_CODEC_ID_AC3,
3252 AV_CODEC_ID_DTS, AV_CODEC_ID_NONE
3255 *video_codec_list = vob_video_list;
3256 *audio_codec_list = vob_audio_list;
3257 } else if (!strcmp (format_name, "flv")) {
3258 static enum CodecID flv_video_list[] =
3259 { AV_CODEC_ID_FLV1, AV_CODEC_ID_NONE };
3260 static enum CodecID flv_audio_list[] =
3261 { AV_CODEC_ID_MP3, AV_CODEC_ID_NONE };
3263 *video_codec_list = flv_video_list;
3264 *audio_codec_list = flv_audio_list;
3265 } else if (!strcmp (format_name, "asf")) {
3266 static enum CodecID asf_video_list[] =
3267 { AV_CODEC_ID_WMV1, AV_CODEC_ID_WMV2, AV_CODEC_ID_MSMPEG4V3,
3270 static enum CodecID asf_audio_list[] =
3271 { AV_CODEC_ID_WMAV1, AV_CODEC_ID_WMAV2, AV_CODEC_ID_MP3,
3275 *video_codec_list = asf_video_list;
3276 *audio_codec_list = asf_audio_list;
3277 } else if (!strcmp (format_name, "dv")) {
3278 static enum CodecID dv_video_list[] =
3279 { AV_CODEC_ID_DVVIDEO, AV_CODEC_ID_NONE };
3280 static enum CodecID dv_audio_list[] =
3281 { AV_CODEC_ID_PCM_S16LE, AV_CODEC_ID_NONE };
3283 *video_codec_list = dv_video_list;
3284 *audio_codec_list = dv_audio_list;
3285 } else if (!strcmp (format_name, "mov")) {
3286 static enum CodecID mov_video_list[] = {
3287 AV_CODEC_ID_SVQ1, AV_CODEC_ID_SVQ3, AV_CODEC_ID_MPEG4,
3288 AV_CODEC_ID_H263, AV_CODEC_ID_H263P,
3289 AV_CODEC_ID_H264, AV_CODEC_ID_DVVIDEO,
3293 static enum CodecID mov_audio_list[] = {
3294 AV_CODEC_ID_PCM_MULAW, AV_CODEC_ID_PCM_ALAW, AV_CODEC_ID_ADPCM_IMA_QT,
3295 AV_CODEC_ID_MACE3, AV_CODEC_ID_MACE6, AV_CODEC_ID_AAC,
3296 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3297 AV_CODEC_ID_PCM_S16BE, AV_CODEC_ID_PCM_S16LE,
3298 AV_CODEC_ID_MP3, AV_CODEC_ID_NONE
3301 *video_codec_list = mov_video_list;
3302 *audio_codec_list = mov_audio_list;
3303 } else if ((!strcmp (format_name, "3gp") || !strcmp (format_name, "3g2"))) {
3304 static enum CodecID tgp_video_list[] = {
3305 AV_CODEC_ID_MPEG4, AV_CODEC_ID_H263, AV_CODEC_ID_H263P, AV_CODEC_ID_H264,
3308 static enum CodecID tgp_audio_list[] = {
3309 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3314 *video_codec_list = tgp_video_list;
3315 *audio_codec_list = tgp_audio_list;
3316 } else if (!strcmp (format_name, "mmf")) {
3317 static enum CodecID mmf_audio_list[] = {
3318 AV_CODEC_ID_ADPCM_YAMAHA, AV_CODEC_ID_NONE
3320 *video_codec_list = NULL;
3321 *audio_codec_list = mmf_audio_list;
3322 } else if (!strcmp (format_name, "amr")) {
3323 static enum CodecID amr_audio_list[] = {
3324 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3327 *video_codec_list = NULL;
3328 *audio_codec_list = amr_audio_list;
3329 } else if (!strcmp (format_name, "gif")) {
3330 static enum CodecID gif_image_list[] = {
3331 AV_CODEC_ID_RAWVIDEO, AV_CODEC_ID_NONE
3333 *video_codec_list = gif_image_list;
3334 *audio_codec_list = NULL;
3335 } else if ((plugin->audio_codec != AV_CODEC_ID_NONE) ||
3336 (plugin->video_codec != AV_CODEC_ID_NONE)) {
3337 tmp_vlist[0] = plugin->video_codec;
3338 tmp_alist[0] = plugin->audio_codec;
3340 *video_codec_list = tmp_vlist;
3341 *audio_codec_list = tmp_alist;
3342 } else if ((!strcmp (format_name, "pva"))) {
3343 static enum CodecID tgp_video_list[] = {
3344 AV_CODEC_ID_MPEG2VIDEO,
3347 static enum CodecID tgp_audio_list[] = {
3352 *video_codec_list = tgp_video_list;
3353 *audio_codec_list = tgp_audio_list;
3355 GST_LOG ("Format %s not found", format_name);
3362 /* Convert a GstCaps to a FFMPEG codec ID. Size et all
3363 * are omitted, that can be queried by the user itself,
3364 * we're not eating the GstCaps or anything
3365 * A pointer to an allocated context is also needed for
3366 * optional extra info
3370 gst_ffmpeg_caps_to_codecid (const GstCaps * caps, AVCodecContext * context)
3372 enum CodecID id = AV_CODEC_ID_NONE;
3373 const gchar *mimetype;
3374 const GstStructure *structure;
3375 gboolean video = FALSE, audio = FALSE; /* we want to be sure! */
3377 g_return_val_if_fail (caps != NULL, AV_CODEC_ID_NONE);
3378 g_return_val_if_fail (gst_caps_get_size (caps) == 1, AV_CODEC_ID_NONE);
3379 structure = gst_caps_get_structure (caps, 0);
3381 mimetype = gst_structure_get_name (structure);
3383 if (!strcmp (mimetype, "video/x-raw")) {
3384 id = AV_CODEC_ID_RAWVIDEO;
3386 } else if (!strcmp (mimetype, "audio/x-raw")) {
3389 if (gst_audio_info_from_caps (&info, caps)) {
3390 switch (GST_AUDIO_INFO_FORMAT (&info)) {
3391 case GST_AUDIO_FORMAT_S8:
3392 id = AV_CODEC_ID_PCM_S8;
3394 case GST_AUDIO_FORMAT_U8:
3395 id = AV_CODEC_ID_PCM_U8;
3397 case GST_AUDIO_FORMAT_S16LE:
3398 id = AV_CODEC_ID_PCM_S16LE;
3400 case GST_AUDIO_FORMAT_S16BE:
3401 id = AV_CODEC_ID_PCM_S16BE;
3403 case GST_AUDIO_FORMAT_U16LE:
3404 id = AV_CODEC_ID_PCM_U16LE;
3406 case GST_AUDIO_FORMAT_U16BE:
3407 id = AV_CODEC_ID_PCM_U16BE;
3412 if (id != AV_CODEC_ID_NONE)
3415 } else if (!strcmp (mimetype, "audio/x-mulaw")) {
3416 id = AV_CODEC_ID_PCM_MULAW;
3418 } else if (!strcmp (mimetype, "audio/x-alaw")) {
3419 id = AV_CODEC_ID_PCM_ALAW;
3421 } else if (!strcmp (mimetype, "video/x-dv")) {
3424 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3426 id = AV_CODEC_ID_DVVIDEO;
3429 } else if (!strcmp (mimetype, "audio/x-dv")) { /* ??? */
3430 id = AV_CODEC_ID_DVAUDIO;
3432 } else if (!strcmp (mimetype, "video/x-h263")) {
3433 const gchar *h263version =
3434 gst_structure_get_string (structure, "h263version");
3435 if (h263version && !strcmp (h263version, "h263p"))
3436 id = AV_CODEC_ID_H263P;
3438 id = AV_CODEC_ID_H263;
3440 } else if (!strcmp (mimetype, "video/x-intel-h263")) {
3441 id = AV_CODEC_ID_H263I;
3443 } else if (!strcmp (mimetype, "video/x-h261")) {
3444 id = AV_CODEC_ID_H261;
3446 } else if (!strcmp (mimetype, "video/mpeg")) {
3450 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3451 gst_structure_get_int (structure, "mpegversion", &mpegversion) &&
3453 switch (mpegversion) {
3455 id = AV_CODEC_ID_MPEG1VIDEO;
3458 id = AV_CODEC_ID_MPEG2VIDEO;
3461 id = AV_CODEC_ID_MPEG4;
3465 if (id != AV_CODEC_ID_NONE)
3467 } else if (!strcmp (mimetype, "image/jpeg")) {
3468 id = AV_CODEC_ID_MJPEG; /* A... B... */
3470 } else if (!strcmp (mimetype, "video/x-jpeg-b")) {
3471 id = AV_CODEC_ID_MJPEGB;
3473 } else if (!strcmp (mimetype, "video/x-wmv")) {
3474 gint wmvversion = 0;
3476 if (gst_structure_get_int (structure, "wmvversion", &wmvversion)) {
3477 switch (wmvversion) {
3479 id = AV_CODEC_ID_WMV1;
3482 id = AV_CODEC_ID_WMV2;
3486 const gchar *format;
3488 /* WMV3 unless the fourcc exists and says otherwise */
3489 id = AV_CODEC_ID_WMV3;
3491 if ((format = gst_structure_get_string (structure, "format")) &&
3492 (g_str_equal (format, "WVC1") || g_str_equal (format, "WMVA")))
3493 id = AV_CODEC_ID_VC1;
3499 if (id != AV_CODEC_ID_NONE)
3501 } else if (!strcmp (mimetype, "audio/x-vorbis")) {
3502 id = AV_CODEC_ID_VORBIS;
3504 } else if (!strcmp (mimetype, "audio/x-qdm2")) {
3505 id = AV_CODEC_ID_QDM2;
3507 } else if (!strcmp (mimetype, "audio/mpeg")) {
3509 gint mpegversion = 0;
3511 if (gst_structure_get_int (structure, "mpegversion", &mpegversion)) {
3512 switch (mpegversion) {
3513 case 2: /* ffmpeg uses faad for both... */
3515 id = AV_CODEC_ID_AAC;
3518 if (gst_structure_get_int (structure, "layer", &layer)) {
3521 id = AV_CODEC_ID_MP1;
3524 id = AV_CODEC_ID_MP2;
3527 id = AV_CODEC_ID_MP3;
3533 if (id != AV_CODEC_ID_NONE)
3535 } else if (!strcmp (mimetype, "audio/x-musepack")) {
3536 gint streamversion = -1;
3538 if (gst_structure_get_int (structure, "streamversion", &streamversion)) {
3539 if (streamversion == 7)
3540 id = AV_CODEC_ID_MUSEPACK7;
3542 id = AV_CODEC_ID_MUSEPACK7;
3544 } else if (!strcmp (mimetype, "audio/x-wma")) {
3545 gint wmaversion = 0;
3547 if (gst_structure_get_int (structure, "wmaversion", &wmaversion)) {
3548 switch (wmaversion) {
3550 id = AV_CODEC_ID_WMAV1;
3553 id = AV_CODEC_ID_WMAV2;
3556 id = AV_CODEC_ID_WMAPRO;
3560 if (id != AV_CODEC_ID_NONE)
3562 } else if (!strcmp (mimetype, "audio/x-wms")) {
3563 id = AV_CODEC_ID_WMAVOICE;
3565 } else if (!strcmp (mimetype, "audio/x-ac3")) {
3566 id = AV_CODEC_ID_AC3;
3568 } else if (!strcmp (mimetype, "audio/x-eac3")) {
3569 id = AV_CODEC_ID_EAC3;
3571 } else if (!strcmp (mimetype, "audio/x-vnd.sony.atrac3") ||
3572 !strcmp (mimetype, "audio/atrac3")) {
3573 id = AV_CODEC_ID_ATRAC3;
3575 } else if (!strcmp (mimetype, "audio/x-dts")) {
3576 id = AV_CODEC_ID_DTS;
3578 } else if (!strcmp (mimetype, "application/x-ape")) {
3579 id = AV_CODEC_ID_APE;
3581 } else if (!strcmp (mimetype, "video/x-msmpeg")) {
3582 gint msmpegversion = 0;
3584 if (gst_structure_get_int (structure, "msmpegversion", &msmpegversion)) {
3585 switch (msmpegversion) {
3587 id = AV_CODEC_ID_MSMPEG4V1;
3590 id = AV_CODEC_ID_MSMPEG4V2;
3593 id = AV_CODEC_ID_MSMPEG4V3;
3597 if (id != AV_CODEC_ID_NONE)
3599 } else if (!strcmp (mimetype, "video/x-svq")) {
3600 gint svqversion = 0;
3602 if (gst_structure_get_int (structure, "svqversion", &svqversion)) {
3603 switch (svqversion) {
3605 id = AV_CODEC_ID_SVQ1;
3608 id = AV_CODEC_ID_SVQ3;
3612 if (id != AV_CODEC_ID_NONE)
3614 } else if (!strcmp (mimetype, "video/x-huffyuv")) {
3615 id = AV_CODEC_ID_HUFFYUV;
3617 } else if (!strcmp (mimetype, "audio/x-mace")) {
3618 gint maceversion = 0;
3620 if (gst_structure_get_int (structure, "maceversion", &maceversion)) {
3621 switch (maceversion) {
3623 id = AV_CODEC_ID_MACE3;
3626 id = AV_CODEC_ID_MACE6;
3630 if (id != AV_CODEC_ID_NONE)
3632 } else if (!strcmp (mimetype, "video/x-theora")) {
3633 id = AV_CODEC_ID_THEORA;
3635 } else if (!strcmp (mimetype, "video/x-vp3")) {
3636 id = AV_CODEC_ID_VP3;
3638 } else if (!strcmp (mimetype, "video/x-vp5")) {
3639 id = AV_CODEC_ID_VP5;
3641 } else if (!strcmp (mimetype, "video/x-vp6")) {
3642 id = AV_CODEC_ID_VP6;
3644 } else if (!strcmp (mimetype, "video/x-vp6-flash")) {
3645 id = AV_CODEC_ID_VP6F;
3647 } else if (!strcmp (mimetype, "video/x-vp6-alpha")) {
3648 id = AV_CODEC_ID_VP6A;
3650 } else if (!strcmp (mimetype, "video/x-vp8")) {
3651 id = AV_CODEC_ID_VP8;
3653 } else if (!strcmp (mimetype, "video/x-flash-screen")) {
3654 id = AV_CODEC_ID_FLASHSV;
3656 } else if (!strcmp (mimetype, "video/x-indeo")) {
3657 gint indeoversion = 0;
3659 if (gst_structure_get_int (structure, "indeoversion", &indeoversion)) {
3660 switch (indeoversion) {
3662 id = AV_CODEC_ID_INDEO5;
3665 id = AV_CODEC_ID_INDEO4;
3668 id = AV_CODEC_ID_INDEO3;
3671 id = AV_CODEC_ID_INDEO2;
3674 if (id != AV_CODEC_ID_NONE)
3677 } else if (!strcmp (mimetype, "video/x-divx")) {
3678 gint divxversion = 0;
3680 if (gst_structure_get_int (structure, "divxversion", &divxversion)) {
3681 switch (divxversion) {
3683 id = AV_CODEC_ID_MSMPEG4V3;
3687 id = AV_CODEC_ID_MPEG4;
3691 if (id != AV_CODEC_ID_NONE)
3693 } else if (!strcmp (mimetype, "video/x-3ivx")) {
3694 id = AV_CODEC_ID_MPEG4;
3696 } else if (!strcmp (mimetype, "video/x-xvid")) {
3697 id = AV_CODEC_ID_MPEG4;
3699 } else if (!strcmp (mimetype, "video/x-ffv")) {
3700 gint ffvversion = 0;
3702 if (gst_structure_get_int (structure, "ffvversion", &ffvversion) &&
3704 id = AV_CODEC_ID_FFV1;
3707 } else if (!strcmp (mimetype, "audio/x-adpcm")) {
3708 const gchar *layout;
3710 layout = gst_structure_get_string (structure, "layout");
3711 if (layout == NULL) {
3713 } else if (!strcmp (layout, "quicktime")) {
3714 id = AV_CODEC_ID_ADPCM_IMA_QT;
3715 } else if (!strcmp (layout, "microsoft")) {
3716 id = AV_CODEC_ID_ADPCM_MS;
3717 } else if (!strcmp (layout, "dvi")) {
3718 id = AV_CODEC_ID_ADPCM_IMA_WAV;
3719 } else if (!strcmp (layout, "4xm")) {
3720 id = AV_CODEC_ID_ADPCM_4XM;
3721 } else if (!strcmp (layout, "smjpeg")) {
3722 id = AV_CODEC_ID_ADPCM_IMA_SMJPEG;
3723 } else if (!strcmp (layout, "dk3")) {
3724 id = AV_CODEC_ID_ADPCM_IMA_DK3;
3725 } else if (!strcmp (layout, "dk4")) {
3726 id = AV_CODEC_ID_ADPCM_IMA_DK4;
3727 } else if (!strcmp (layout, "westwood")) {
3728 id = AV_CODEC_ID_ADPCM_IMA_WS;
3729 } else if (!strcmp (layout, "iss")) {
3730 id = AV_CODEC_ID_ADPCM_IMA_ISS;
3731 } else if (!strcmp (layout, "xa")) {
3732 id = AV_CODEC_ID_ADPCM_XA;
3733 } else if (!strcmp (layout, "adx")) {
3734 id = AV_CODEC_ID_ADPCM_ADX;
3735 } else if (!strcmp (layout, "ea")) {
3736 id = AV_CODEC_ID_ADPCM_EA;
3737 } else if (!strcmp (layout, "g726")) {
3738 id = AV_CODEC_ID_ADPCM_G726;
3739 } else if (!strcmp (layout, "g721")) {
3740 id = AV_CODEC_ID_ADPCM_G726;
3741 } else if (!strcmp (layout, "ct")) {
3742 id = AV_CODEC_ID_ADPCM_CT;
3743 } else if (!strcmp (layout, "swf")) {
3744 id = AV_CODEC_ID_ADPCM_SWF;
3745 } else if (!strcmp (layout, "yamaha")) {
3746 id = AV_CODEC_ID_ADPCM_YAMAHA;
3747 } else if (!strcmp (layout, "sbpro2")) {
3748 id = AV_CODEC_ID_ADPCM_SBPRO_2;
3749 } else if (!strcmp (layout, "sbpro3")) {
3750 id = AV_CODEC_ID_ADPCM_SBPRO_3;
3751 } else if (!strcmp (layout, "sbpro4")) {
3752 id = AV_CODEC_ID_ADPCM_SBPRO_4;
3754 if (id != AV_CODEC_ID_NONE)
3756 } else if (!strcmp (mimetype, "video/x-4xm")) {
3757 id = AV_CODEC_ID_4XM;
3759 } else if (!strcmp (mimetype, "audio/x-dpcm")) {
3760 const gchar *layout;
3762 layout = gst_structure_get_string (structure, "layout");
3765 } else if (!strcmp (layout, "roq")) {
3766 id = AV_CODEC_ID_ROQ_DPCM;
3767 } else if (!strcmp (layout, "interplay")) {
3768 id = AV_CODEC_ID_INTERPLAY_DPCM;
3769 } else if (!strcmp (layout, "xan")) {
3770 id = AV_CODEC_ID_XAN_DPCM;
3771 } else if (!strcmp (layout, "sol")) {
3772 id = AV_CODEC_ID_SOL_DPCM;
3774 if (id != AV_CODEC_ID_NONE)
3776 } else if (!strcmp (mimetype, "audio/x-flac")) {
3777 id = AV_CODEC_ID_FLAC;
3779 } else if (!strcmp (mimetype, "audio/x-shorten")) {
3780 id = AV_CODEC_ID_SHORTEN;
3782 } else if (!strcmp (mimetype, "audio/x-alac")) {
3783 id = AV_CODEC_ID_ALAC;
3785 } else if (!strcmp (mimetype, "video/x-cinepak")) {
3786 id = AV_CODEC_ID_CINEPAK;
3788 } else if (!strcmp (mimetype, "video/x-pn-realvideo")) {
3791 if (gst_structure_get_int (structure, "rmversion", &rmversion)) {
3792 switch (rmversion) {
3794 id = AV_CODEC_ID_RV10;
3797 id = AV_CODEC_ID_RV20;
3800 id = AV_CODEC_ID_RV30;
3803 id = AV_CODEC_ID_RV40;
3807 if (id != AV_CODEC_ID_NONE)
3809 } else if (!strcmp (mimetype, "audio/x-sipro")) {
3810 id = AV_CODEC_ID_SIPR;
3812 } else if (!strcmp (mimetype, "audio/x-pn-realaudio")) {
3815 if (gst_structure_get_int (structure, "raversion", &raversion)) {
3816 switch (raversion) {
3818 id = AV_CODEC_ID_RA_144;
3821 id = AV_CODEC_ID_RA_288;
3824 id = AV_CODEC_ID_COOK;
3828 if (id != AV_CODEC_ID_NONE)
3830 } else if (!strcmp (mimetype, "video/x-rle")) {
3831 const gchar *layout;
3833 if ((layout = gst_structure_get_string (structure, "layout"))) {
3834 if (!strcmp (layout, "microsoft")) {
3835 id = AV_CODEC_ID_MSRLE;
3839 } else if (!strcmp (mimetype, "video/x-xan")) {
3842 if ((gst_structure_get_int (structure, "wcversion", &wcversion))) {
3843 switch (wcversion) {
3845 id = AV_CODEC_ID_XAN_WC3;
3849 id = AV_CODEC_ID_XAN_WC4;
3856 } else if (!strcmp (mimetype, "audio/AMR")) {
3858 id = AV_CODEC_ID_AMR_NB;
3859 } else if (!strcmp (mimetype, "audio/AMR-WB")) {
3860 id = AV_CODEC_ID_AMR_WB;
3862 } else if (!strcmp (mimetype, "audio/qcelp")) {
3863 id = AV_CODEC_ID_QCELP;
3865 } else if (!strcmp (mimetype, "video/x-h264")) {
3866 id = AV_CODEC_ID_H264;
3868 } else if (!strcmp (mimetype, "video/x-flash-video")) {
3869 gint flvversion = 0;
3871 if ((gst_structure_get_int (structure, "flvversion", &flvversion))) {
3872 switch (flvversion) {
3874 id = AV_CODEC_ID_FLV1;
3882 } else if (!strcmp (mimetype, "audio/x-nellymoser")) {
3883 id = AV_CODEC_ID_NELLYMOSER;
3885 } else if (!strncmp (mimetype, "audio/x-gst-av-", 15)) {
3889 if (strlen (mimetype) <= 30 &&
3890 sscanf (mimetype, "audio/x-gst-av-%s", ext) == 1) {
3891 if ((codec = avcodec_find_decoder_by_name (ext)) ||
3892 (codec = avcodec_find_encoder_by_name (ext))) {
3897 } else if (!strncmp (mimetype, "video/x-gst-av-", 15)) {
3901 if (strlen (mimetype) <= 30 &&
3902 sscanf (mimetype, "video/x-gst-av-%s", ext) == 1) {
3903 if ((codec = avcodec_find_decoder_by_name (ext)) ||
3904 (codec = avcodec_find_encoder_by_name (ext))) {
3911 if (context != NULL) {
3912 if (video == TRUE) {
3913 context->codec_type = AVMEDIA_TYPE_VIDEO;
3914 } else if (audio == TRUE) {
3915 context->codec_type = AVMEDIA_TYPE_AUDIO;
3917 context->codec_type = AVMEDIA_TYPE_UNKNOWN;
3919 context->codec_id = id;
3920 gst_ffmpeg_caps_with_codecid (id, context->codec_type, caps, context);
3923 if (id != AV_CODEC_ID_NONE) {
3924 GST_DEBUG ("The id=%d belongs to the caps %" GST_PTR_FORMAT, id, caps);
3926 GST_WARNING ("Couldn't figure out the id for caps %" GST_PTR_FORMAT, caps);