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 <= AV_PIX_FMT_NB; i++) {
213 format = gst_ffmpeg_pixfmt_to_videoformat (i);
214 if (format == GST_VIDEO_FORMAT_UNKNOWN)
216 g_value_set_string (&v, gst_video_format_to_string (format));
217 gst_value_list_append_value (&va, &v);
219 gst_caps_set_value (caps, "format", &va);
225 /* Only a single format */
226 g_value_init (&va, GST_TYPE_LIST);
227 g_value_init (&v, G_TYPE_STRING);
228 while (*fmts != -1) {
229 format = gst_ffmpeg_pixfmt_to_videoformat (*fmts);
230 if (format != GST_VIDEO_FORMAT_UNKNOWN) {
231 g_value_set_string (&v, gst_video_format_to_string (format));
232 /* Only append values we don't have yet */
233 if (!_gst_value_list_contains (&va, &v))
234 gst_value_list_append_value (&va, &v);
238 if (gst_value_list_get_size (&va) == 1) {
239 /* The single value is still in v */
240 gst_caps_set_value (caps, "format", &v);
241 } else if (gst_value_list_get_size (&va) > 1) {
242 gst_caps_set_value (caps, "format", &va);
248 /* this macro makes a caps width fixed or unfixed width/height
249 * properties depending on whether we've got a context.
251 * See below for why we use this.
253 * We should actually do this stuff at the end, like in riff-media.c,
254 * but I'm too lazy today. Maybe later.
257 gst_ff_vid_caps_new (AVCodecContext * context, AVCodec * codec,
258 enum AVCodecID codec_id, gboolean encode, const char *mimetype,
259 const char *fieldname, ...)
261 GstCaps *caps = NULL;
265 GST_LOG ("context:%p, codec_id:%d, mimetype:%s", context, codec_id, mimetype);
267 /* fixed, non probing context */
268 if (context != NULL && context->width != -1) {
271 caps = gst_caps_new_simple (mimetype,
272 "width", G_TYPE_INT, context->width,
273 "height", G_TYPE_INT, context->height, NULL);
275 num = context->time_base.den / context->ticks_per_frame;
276 denom = context->time_base.num;
279 GST_LOG ("invalid framerate: %d/0, -> %d/1", num, num);
282 if (gst_util_fraction_compare (num, denom, 1000, 1) > 0) {
283 GST_LOG ("excessive framerate: %d/%d, -> 0/1", num, denom);
287 GST_LOG ("setting framerate: %d/%d", num, denom);
288 gst_caps_set_simple (caps,
289 "framerate", GST_TYPE_FRACTION, num, denom, NULL);
291 /* so we are after restricted caps in this case */
293 case AV_CODEC_ID_H261:
295 caps = gst_caps_new_simple (mimetype,
296 "width", G_TYPE_INT, 352,
297 "height", G_TYPE_INT, 288,
298 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
299 gst_caps_append (caps, gst_caps_new_simple (mimetype,
300 "width", G_TYPE_INT, 176,
301 "height", G_TYPE_INT, 144,
302 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL));
305 case AV_CODEC_ID_H263:
307 /* 128x96, 176x144, 352x288, 704x576, and 1408x1152. slightly reordered
308 * because we want automatic negotiation to go as close to 320x240 as
310 const static gint widths[] = { 352, 704, 176, 1408, 128 };
311 const static gint heights[] = { 288, 576, 144, 1152, 96 };
313 gint n_sizes = G_N_ELEMENTS (widths);
315 caps = gst_caps_new_empty ();
316 for (i = 0; i < n_sizes; i++) {
317 temp = gst_caps_new_simple (mimetype,
318 "width", G_TYPE_INT, widths[i],
319 "height", G_TYPE_INT, heights[i],
320 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
322 gst_caps_append (caps, temp);
326 case AV_CODEC_ID_DVVIDEO:
333 gint framerate_n, framerate_d;
336 "Y41B", 720, 480, 8, 9, 30000, 1001}, {
337 "Y41B", 720, 480, 32, 27, 30000, 1001}, {
338 "Y42B", 720, 480, 8, 9, 30000, 1001}, {
339 "Y42B", 720, 480, 32, 27, 30000, 1001}, {
340 "I420", 720, 576, 16, 15, 25, 1}, {
341 "I420", 720, 576, 64, 45, 25, 1}, {
342 "Y41B", 720, 576, 16, 15, 25, 1}, {
343 "Y41B", 720, 576, 64, 45, 25, 1}, {
344 "Y42B", 720, 576, 16, 15, 25, 1}, {
345 "Y42B", 720, 576, 64, 45, 25, 1}, {
346 "Y42B", 1280, 1080, 1, 1, 30000, 1001}, {
347 "Y42B", 1280, 1080, 3, 2, 30000, 1001}, {
348 "Y42B", 1440, 1080, 1, 1, 25, 1}, {
349 "Y42B", 1440, 1080, 4, 3, 25, 1}, {
350 "Y42B", 960, 720, 1, 1, 60000, 1001}, {
351 "Y42B", 960, 720, 4, 3, 60000, 1001}, {
352 "Y42B", 960, 720, 1, 1, 50, 1}, {
353 "Y42B", 960, 720, 4, 3, 50, 1},};
355 gint n_sizes = G_N_ELEMENTS (profiles);
357 if (strcmp (mimetype, "video/x-raw") == 0) {
358 caps = gst_caps_new_empty ();
359 for (i = 0; i < n_sizes; i++) {
360 temp = gst_caps_new_simple (mimetype,
361 "format", G_TYPE_STRING, profiles[i].csp,
362 "width", G_TYPE_INT, profiles[i].width,
363 "height", G_TYPE_INT, profiles[i].height,
364 "framerate", GST_TYPE_FRACTION, profiles[i].framerate_n,
365 profiles[i].framerate_d, "pixel-aspect-ratio",
366 GST_TYPE_FRACTION, profiles[i].par_n, profiles[i].par_d, NULL);
368 gst_caps_append (caps, temp);
371 caps = gst_caps_new_empty ();
372 for (i = 0; i < n_sizes; i++) {
373 temp = gst_caps_new_simple (mimetype,
374 "width", G_TYPE_INT, profiles[i].width,
375 "height", G_TYPE_INT, profiles[i].height,
376 "framerate", GST_TYPE_FRACTION, profiles[i].framerate_n,
377 profiles[i].framerate_d, "pixel-aspect-ratio",
378 GST_TYPE_FRACTION, profiles[i].par_n, profiles[i].par_d, NULL);
380 gst_caps_append (caps, temp);
385 case AV_CODEC_ID_DNXHD:
387 caps = gst_caps_new_simple (mimetype,
388 "width", G_TYPE_INT, 1920,
389 "height", G_TYPE_INT, 1080,
390 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
391 gst_caps_append (caps, gst_caps_new_simple (mimetype,
392 "width", G_TYPE_INT, 1280,
393 "height", G_TYPE_INT, 720,
394 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL));
399 if (codec && codec->supported_framerates
400 && codec->supported_framerates[0].num != 0
401 && codec->supported_framerates[0].den != 0) {
404 const AVRational *rates = codec->supported_framerates;
406 if (rates[1].num == 0 && rates[1].den == 0) {
408 gst_caps_new_simple (mimetype, "framerate", GST_TYPE_FRACTION,
409 rates[0].num, rates[0].den, NULL);
411 g_value_init (&va, GST_TYPE_LIST);
412 g_value_init (&v, GST_TYPE_FRACTION);
414 while (rates->num != 0 && rates->den != 0) {
415 gst_value_set_fraction (&v, rates->num, rates->den);
416 gst_value_list_append_value (&va, &v);
420 caps = gst_caps_new_simple (mimetype, NULL, NULL, NULL);
421 gst_caps_set_value (caps, "framerate", &va);
427 caps = gst_caps_new_empty_simple (mimetype);
435 /* no fixed caps or special restrictions applied;
436 * default unfixed setting */
438 GST_DEBUG ("Creating default caps");
439 caps = gst_caps_new_empty_simple (mimetype);
442 va_start (var_args, fieldname);
443 gst_caps_set_simple_valist (caps, fieldname, var_args);
450 get_nbits_set (guint64 n)
455 for (i = 0; i < 64; i++) {
456 if ((n & (G_GUINT64_CONSTANT (1) << i)))
464 gst_ffmpeg_audio_set_sample_fmts (GstCaps * caps,
465 const enum AVSampleFormat *fmts)
469 GstAudioFormat format;
471 if (!fmts || fmts[0] == -1) {
474 g_value_init (&va, GST_TYPE_LIST);
475 g_value_init (&v, G_TYPE_STRING);
476 for (i = 0; i <= AV_SAMPLE_FMT_DBL; i++) {
477 format = gst_ffmpeg_smpfmt_to_audioformat (i);
478 if (format == GST_AUDIO_FORMAT_UNKNOWN)
480 g_value_set_string (&v, gst_audio_format_to_string (format));
481 gst_value_list_append_value (&va, &v);
483 gst_caps_set_value (caps, "format", &va);
489 g_value_init (&va, GST_TYPE_LIST);
490 g_value_init (&v, G_TYPE_STRING);
491 while (*fmts != -1) {
492 format = gst_ffmpeg_smpfmt_to_audioformat (*fmts);
493 if (format != GST_AUDIO_FORMAT_UNKNOWN) {
494 g_value_set_string (&v, gst_audio_format_to_string (format));
495 /* Only append values we don't have yet */
496 if (!_gst_value_list_contains (&va, &v))
497 gst_value_list_append_value (&va, &v);
501 if (gst_value_list_get_size (&va) == 1) {
502 /* The single value is still in v */
503 gst_caps_set_value (caps, "format", &v);
504 } else if (gst_value_list_get_size (&va) > 1) {
505 gst_caps_set_value (caps, "format", &va);
511 /* same for audio - now with channels/sample rate
514 gst_ff_aud_caps_new (AVCodecContext * context, AVCodec * codec,
515 enum AVCodecID codec_id, gboolean encode, const char *mimetype,
516 const char *fieldname, ...)
518 GstCaps *caps = NULL;
522 /* fixed, non-probing context */
523 if (context != NULL && context->channels != -1) {
524 GstAudioChannelPosition pos[64];
527 caps = gst_caps_new_simple (mimetype,
528 "rate", G_TYPE_INT, context->sample_rate,
529 "channels", G_TYPE_INT, context->channels, NULL);
531 if (context->channels > 1 &&
532 gst_ffmpeg_channel_layout_to_gst (context->channel_layout,
533 context->channels, pos) &&
534 gst_audio_channel_positions_to_mask (pos, context->channels, FALSE,
536 gst_caps_set_simple (caps, "channel-mask", GST_TYPE_BITMASK, mask, NULL);
539 gint maxchannels = 2;
540 const gint *rates = NULL;
543 /* so we must be after restricted caps in this case */
545 case AV_CODEC_ID_AAC:
546 case AV_CODEC_ID_AAC_LATM:
547 case AV_CODEC_ID_DTS:
550 case AV_CODEC_ID_MP2:
552 const static gint l_rates[] =
553 { 48000, 44100, 32000, 24000, 22050, 16000 };
554 n_rates = G_N_ELEMENTS (l_rates);
558 case AV_CODEC_ID_EAC3:
559 case AV_CODEC_ID_AC3:
561 const static gint l_rates[] = { 48000, 44100, 32000 };
563 n_rates = G_N_ELEMENTS (l_rates);
567 case AV_CODEC_ID_ADPCM_G722:
569 const static gint l_rates[] = { 16000 };
570 n_rates = G_N_ELEMENTS (l_rates);
575 case AV_CODEC_ID_ADPCM_G726:
577 const static gint l_rates[] = { 8000 };
578 n_rates = G_N_ELEMENTS (l_rates);
583 case AV_CODEC_ID_ADPCM_SWF:
585 const static gint l_rates[] = { 11025, 22050, 44100 };
586 n_rates = G_N_ELEMENTS (l_rates);
590 case AV_CODEC_ID_ROQ_DPCM:
592 const static gint l_rates[] = { 22050 };
593 n_rates = G_N_ELEMENTS (l_rates);
597 case AV_CODEC_ID_AMR_NB:
599 const static gint l_rates[] = { 8000 };
601 n_rates = G_N_ELEMENTS (l_rates);
605 case AV_CODEC_ID_AMR_WB:
607 const static gint l_rates[] = { 16000 };
609 n_rates = G_N_ELEMENTS (l_rates);
617 /* regardless of encode/decode, open up channels if applicable */
618 /* Until decoders/encoders expose the maximum number of channels
619 * they support, we whitelist them here. */
621 case AV_CODEC_ID_WMAPRO:
622 case AV_CODEC_ID_TRUEHD:
629 if (codec && codec->channel_layouts) {
630 const uint64_t *layouts = codec->channel_layouts;
631 GstAudioChannelPosition pos[64];
633 caps = gst_caps_new_empty ();
635 gint nbits_set = get_nbits_set (*layouts);
637 if (gst_ffmpeg_channel_layout_to_gst (*layouts, nbits_set, pos)) {
640 if (gst_audio_channel_positions_to_mask (pos, nbits_set, FALSE,
643 gst_caps_new_simple (mimetype, "channel-mask", GST_TYPE_BITMASK,
645 "channels", G_TYPE_INT, nbits_set, NULL);
647 gst_caps_append (caps, tmp);
653 if (maxchannels == 1)
654 caps = gst_caps_new_simple (mimetype,
655 "channels", G_TYPE_INT, maxchannels, NULL);
657 caps = gst_caps_new_simple (mimetype,
658 "channels", GST_TYPE_INT_RANGE, 1, maxchannels, NULL);
662 GValue list = { 0, };
664 g_value_init (&list, GST_TYPE_LIST);
665 for (i = 0; i < n_rates; i++) {
668 g_value_init (&v, G_TYPE_INT);
669 g_value_set_int (&v, rates[i]);
670 gst_value_list_append_value (&list, &v);
673 gst_caps_set_value (caps, "rate", &list);
674 g_value_unset (&list);
675 } else if (codec && codec->supported_samplerates
676 && codec->supported_samplerates[0]) {
680 if (!codec->supported_samplerates[1]) {
681 gst_caps_set_simple (caps, "rate", G_TYPE_INT,
682 codec->supported_samplerates[0], NULL);
684 const int *rates = codec->supported_samplerates;
686 g_value_init (&va, GST_TYPE_LIST);
687 g_value_init (&v, G_TYPE_INT);
690 g_value_set_int (&v, *rates);
691 gst_value_list_append_value (&va, &v);
694 gst_caps_set_value (caps, "rate", &va);
699 gst_caps_set_simple (caps, "rate", GST_TYPE_INT_RANGE, 4000, 96000, NULL);
702 caps = gst_caps_new_empty_simple (mimetype);
705 va_start (var_args, fieldname);
706 gst_caps_set_simple_valist (caps, fieldname, var_args);
712 /* Convert a FFMPEG codec ID and optional AVCodecContext
713 * to a GstCaps. If the context is ommitted, no fixed values
714 * for video/audio size will be included in the GstCaps
716 * CodecID is primarily meant for compressed data GstCaps!
718 * encode is a special parameter. gstffmpegdec will say
719 * FALSE, gstffmpegenc will say TRUE. The output caps
720 * depends on this, in such a way that it will be very
721 * specific, defined, fixed and correct caps for encoders,
722 * yet very wide, "forgiving" caps for decoders. Example
723 * for mp3: decode: audio/mpeg,mpegversion=1,layer=[1-3]
724 * but encode: audio/mpeg,mpegversion=1,layer=3,bitrate=x,
729 gst_ffmpeg_codecid_to_caps (enum AVCodecID codec_id,
730 AVCodecContext * context, gboolean encode)
732 GstCaps *caps = NULL;
733 gboolean buildcaps = FALSE;
735 GST_LOG ("codec_id:%d, context:%p, encode:%d", codec_id, context, encode);
738 case AV_CODEC_ID_MPEG1VIDEO:
740 caps = gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
741 "mpegversion", G_TYPE_INT, 1,
742 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
745 case AV_CODEC_ID_MPEG2VIDEO:
749 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
750 "mpegversion", G_TYPE_INT, 2, "systemstream", G_TYPE_BOOLEAN, FALSE,
753 /* decode both MPEG-1 and MPEG-2; width/height/fps are all in
754 * the MPEG video stream headers, so may be omitted from caps. */
755 caps = gst_caps_new_simple ("video/mpeg",
756 "mpegversion", GST_TYPE_INT_RANGE, 1, 2,
757 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
761 case AV_CODEC_ID_MPEG2VIDEO_XVMC:
762 /* this is a special ID - don't need it in GStreamer, I think */
765 case AV_CODEC_ID_H263:
768 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
769 "video/x-h263", "variant", G_TYPE_STRING, "itu", "h263version",
770 G_TYPE_STRING, "h263", NULL);
772 /* don't pass codec_id, we can decode other variants with the H263
773 * decoder that don't have specific size requirements
776 gst_ff_vid_caps_new (context, NULL, AV_CODEC_ID_NONE, encode,
777 "video/x-h263", "variant", G_TYPE_STRING, "itu", NULL);
781 case AV_CODEC_ID_H263P:
783 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h263",
784 "variant", G_TYPE_STRING, "itu", "h263version", G_TYPE_STRING,
786 if (encode && context) {
788 gst_caps_set_simple (caps,
789 "annex-f", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_4MV,
790 "annex-j", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_LOOP_FILTER,
791 "annex-i", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_AC_PRED,
792 "annex-t", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_AC_PRED,
797 case AV_CODEC_ID_H263I:
799 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
800 "video/x-intel-h263", "variant", G_TYPE_STRING, "intel", NULL);
803 case AV_CODEC_ID_H261:
805 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h261",
809 case AV_CODEC_ID_RV10:
810 case AV_CODEC_ID_RV20:
811 case AV_CODEC_ID_RV30:
812 case AV_CODEC_ID_RV40:
817 case AV_CODEC_ID_RV40:
820 case AV_CODEC_ID_RV30:
823 case AV_CODEC_ID_RV20:
832 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
833 "video/x-pn-realvideo", "rmversion", G_TYPE_INT, version, NULL);
835 if (context->extradata_size >= 8) {
836 gst_caps_set_simple (caps,
837 "subformat", G_TYPE_INT, GST_READ_UINT32_BE (context->extradata),
844 case AV_CODEC_ID_MP1:
846 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
847 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 1, NULL);
850 case AV_CODEC_ID_MP2:
852 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
853 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 2, NULL);
856 case AV_CODEC_ID_MP3:
860 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
861 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 3, NULL);
863 /* Decodes MPEG-1 layer 1/2/3. Samplerate, channels et al are
864 * in the MPEG audio header, so may be omitted from caps. */
865 caps = gst_caps_new_simple ("audio/mpeg",
866 "mpegversion", G_TYPE_INT, 1,
867 "layer", GST_TYPE_INT_RANGE, 1, 3, NULL);
871 case AV_CODEC_ID_MUSEPACK7:
873 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
874 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 7,
878 case AV_CODEC_ID_MUSEPACK8:
880 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
881 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 8,
885 case AV_CODEC_ID_AC3:
888 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-ac3",
892 case AV_CODEC_ID_EAC3:
895 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-eac3",
899 case AV_CODEC_ID_TRUEHD:
901 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
902 "audio/x-true-hd", NULL);
905 case AV_CODEC_ID_ATRAC1:
907 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
908 "audio/x-vnd.sony.atrac1", NULL);
911 case AV_CODEC_ID_ATRAC3:
913 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
914 "audio/x-vnd.sony.atrac3", NULL);
917 case AV_CODEC_ID_DTS:
919 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dts",
923 case AV_CODEC_ID_APE:
925 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
926 "audio/x-ffmpeg-parsed-ape", NULL);
928 gst_caps_set_simple (caps,
929 "depth", G_TYPE_INT, context->bits_per_coded_sample, NULL);
933 case AV_CODEC_ID_MLP:
935 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mlp",
939 case AV_CODEC_ID_IMC:
941 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-imc",
945 /* MJPEG is normal JPEG, Motion-JPEG and Quicktime MJPEG-A. MJPEGB
946 * is Quicktime's MJPEG-B. LJPEG is lossless JPEG. I don't know what
947 * sp5x is, but it's apparently something JPEG... We don't separate
948 * between those in GStreamer. Should we (at least between MJPEG,
949 * MJPEG-B and sp5x decoding...)? */
950 case AV_CODEC_ID_MJPEG:
951 case AV_CODEC_ID_LJPEG:
953 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/jpeg",
954 "parsed", G_TYPE_BOOLEAN, TRUE, NULL);
957 case AV_CODEC_ID_SP5X:
959 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/sp5x",
963 case AV_CODEC_ID_MJPEGB:
965 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
966 "video/x-mjpeg-b", NULL);
969 case AV_CODEC_ID_MPEG4:
970 if (encode && context != NULL) {
971 /* I'm not exactly sure what ffmpeg outputs... ffmpeg itself uses
972 * the AVI fourcc 'DIVX', but 'mp4v' for Quicktime... */
973 switch (context->codec_tag) {
974 case GST_MAKE_FOURCC ('D', 'I', 'V', 'X'):
976 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
977 "video/x-divx", "divxversion", G_TYPE_INT, 5, NULL);
979 case GST_MAKE_FOURCC ('m', 'p', '4', 'v'):
981 /* FIXME: bitrate. libav doesn't expose the used profile and level */
983 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
984 "video/mpeg", "systemstream", G_TYPE_BOOLEAN, FALSE,
985 "mpegversion", G_TYPE_INT, 4, NULL);
989 /* The trick here is to separate xvid, divx, mpeg4, 3ivx et al */
991 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
992 "mpegversion", G_TYPE_INT, 4, "systemstream", G_TYPE_BOOLEAN, FALSE,
997 GValue item = { 0, };
999 g_value_init (&arr, GST_TYPE_LIST);
1000 g_value_init (&item, G_TYPE_STRING);
1001 g_value_set_string (&item, "simple");
1002 gst_value_list_append_value (&arr, &item);
1003 g_value_set_string (&item, "advanced-simple");
1004 gst_value_list_append_value (&arr, &item);
1005 g_value_unset (&item);
1007 gst_caps_set_value (caps, "profile", &arr);
1008 g_value_unset (&arr);
1010 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
1011 encode, "video/x-divx", "divxversion", G_TYPE_INT, 5, NULL));
1013 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
1014 encode, "video/x-divx", "divxversion", GST_TYPE_INT_RANGE, 4,
1020 case AV_CODEC_ID_RAWVIDEO:
1022 gst_ffmpeg_codectype_to_video_caps (context, codec_id, encode, NULL);
1025 case AV_CODEC_ID_MSMPEG4V1:
1026 case AV_CODEC_ID_MSMPEG4V2:
1027 case AV_CODEC_ID_MSMPEG4V3:
1029 gint version = 41 + codec_id - AV_CODEC_ID_MSMPEG4V1;
1031 /* encode-FIXME: bitrate */
1033 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1034 "video/x-msmpeg", "msmpegversion", G_TYPE_INT, version, NULL);
1035 if (!encode && codec_id == AV_CODEC_ID_MSMPEG4V3) {
1036 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
1037 encode, "video/x-divx", "divxversion", G_TYPE_INT, 3, NULL));
1042 case AV_CODEC_ID_WMV1:
1043 case AV_CODEC_ID_WMV2:
1045 gint version = (codec_id == AV_CODEC_ID_WMV1) ? 1 : 2;
1048 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1049 "wmvversion", G_TYPE_INT, version, NULL);
1053 case AV_CODEC_ID_FLV1:
1055 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1056 "video/x-flash-video", "flvversion", G_TYPE_INT, 1, NULL);
1059 case AV_CODEC_ID_SVQ1:
1061 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-svq",
1062 "svqversion", G_TYPE_INT, 1, NULL);
1065 case AV_CODEC_ID_SVQ3:
1067 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-svq",
1068 "svqversion", G_TYPE_INT, 3, NULL);
1071 case AV_CODEC_ID_DVAUDIO:
1073 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dv",
1077 case AV_CODEC_ID_DVVIDEO:
1079 if (encode && context) {
1080 const gchar *format;
1082 switch (context->pix_fmt) {
1083 case AV_PIX_FMT_YUYV422:
1086 case AV_PIX_FMT_YUV420P:
1089 case AV_PIX_FMT_YUVA420P:
1092 case AV_PIX_FMT_YUV411P:
1095 case AV_PIX_FMT_YUV422P:
1098 case AV_PIX_FMT_YUV410P:
1103 ("Couldnt' find format for pixfmt %d, defaulting to I420",
1109 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dv",
1110 "systemstream", G_TYPE_BOOLEAN, FALSE, "format", G_TYPE_STRING,
1114 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dv",
1115 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
1120 case AV_CODEC_ID_WMAV1:
1121 case AV_CODEC_ID_WMAV2:
1123 gint version = (codec_id == AV_CODEC_ID_WMAV1) ? 1 : 2;
1127 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1128 "wmaversion", G_TYPE_INT, version, "block_align", G_TYPE_INT,
1129 context->block_align, "bitrate", G_TYPE_INT, context->bit_rate,
1133 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1134 "wmaversion", G_TYPE_INT, version, "block_align",
1135 GST_TYPE_INT_RANGE, 0, G_MAXINT, "bitrate", GST_TYPE_INT_RANGE, 0,
1140 case AV_CODEC_ID_WMAPRO:
1143 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1144 "wmaversion", G_TYPE_INT, 3, NULL);
1147 case AV_CODEC_ID_WMALOSSLESS:
1149 /* libav only supports a depth of 16 at the moment */
1151 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1152 "wmaversion", G_TYPE_INT, 4, "depth", G_TYPE_INT, 16, NULL);
1155 case AV_CODEC_ID_WMAVOICE:
1158 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wms",
1163 case AV_CODEC_ID_MACE3:
1164 case AV_CODEC_ID_MACE6:
1166 gint version = (codec_id == AV_CODEC_ID_MACE3) ? 3 : 6;
1169 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mace",
1170 "maceversion", G_TYPE_INT, version, NULL);
1174 case AV_CODEC_ID_HUFFYUV:
1176 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1177 "video/x-huffyuv", NULL);
1179 gst_caps_set_simple (caps,
1180 "bpp", G_TYPE_INT, context->bits_per_coded_sample, NULL);
1184 case AV_CODEC_ID_CYUV:
1186 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1187 "video/x-compressed-yuv", NULL);
1190 case AV_CODEC_ID_H264:
1192 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h264",
1193 "alignment", G_TYPE_STRING, "au", NULL);
1195 GValue arr = { 0, };
1196 GValue item = { 0, };
1197 g_value_init (&arr, GST_TYPE_LIST);
1198 g_value_init (&item, G_TYPE_STRING);
1199 g_value_set_string (&item, "avc");
1200 gst_value_list_append_value (&arr, &item);
1201 g_value_set_string (&item, "byte-stream");
1202 gst_value_list_append_value (&arr, &item);
1203 g_value_unset (&item);
1204 gst_caps_set_value (caps, "stream-format", &arr);
1205 g_value_unset (&arr);
1209 case AV_CODEC_ID_HEVC:
1211 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h265",
1212 "alignment", G_TYPE_STRING, "au", NULL);
1214 GValue arr = { 0, };
1215 GValue item = { 0, };
1216 g_value_init (&arr, GST_TYPE_LIST);
1217 g_value_init (&item, G_TYPE_STRING);
1218 g_value_set_string (&item, "hvc1");
1219 gst_value_list_append_value (&arr, &item);
1220 g_value_set_string (&item, "hev1");
1221 gst_value_list_append_value (&arr, &item);
1222 g_value_set_string (&item, "byte-stream");
1223 gst_value_list_append_value (&arr, &item);
1224 g_value_unset (&item);
1225 gst_caps_set_value (caps, "stream-format", &arr);
1226 g_value_unset (&arr);
1230 case AV_CODEC_ID_INDEO5:
1232 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1233 "indeoversion", G_TYPE_INT, 5, NULL);
1236 case AV_CODEC_ID_INDEO4:
1238 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1239 "indeoversion", G_TYPE_INT, 4, NULL);
1242 case AV_CODEC_ID_INDEO3:
1244 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1245 "indeoversion", G_TYPE_INT, 3, NULL);
1248 case AV_CODEC_ID_INDEO2:
1250 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1251 "indeoversion", G_TYPE_INT, 2, NULL);
1254 case AV_CODEC_ID_FLASHSV:
1256 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1257 "video/x-flash-screen", NULL);
1260 case AV_CODEC_ID_VP3:
1262 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp3",
1266 case AV_CODEC_ID_VP5:
1268 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp5",
1272 case AV_CODEC_ID_VP6:
1274 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp6",
1278 case AV_CODEC_ID_VP6F:
1280 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1281 "video/x-vp6-flash", NULL);
1284 case AV_CODEC_ID_VP6A:
1286 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1287 "video/x-vp6-alpha", NULL);
1290 case AV_CODEC_ID_VP8:
1292 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp8",
1296 case AV_CODEC_ID_THEORA:
1298 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1299 "video/x-theora", NULL);
1302 case AV_CODEC_ID_AAC:
1305 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
1309 GValue arr = { 0, };
1310 GValue item = { 0, };
1312 g_value_init (&arr, GST_TYPE_LIST);
1313 g_value_init (&item, G_TYPE_INT);
1314 g_value_set_int (&item, 2);
1315 gst_value_list_append_value (&arr, &item);
1316 g_value_set_int (&item, 4);
1317 gst_value_list_append_value (&arr, &item);
1318 g_value_unset (&item);
1320 gst_caps_set_value (caps, "mpegversion", &arr);
1321 g_value_unset (&arr);
1323 g_value_init (&arr, GST_TYPE_LIST);
1324 g_value_init (&item, G_TYPE_STRING);
1325 g_value_set_string (&item, "raw");
1326 gst_value_list_append_value (&arr, &item);
1327 g_value_set_string (&item, "adts");
1328 gst_value_list_append_value (&arr, &item);
1329 g_value_set_string (&item, "adif");
1330 gst_value_list_append_value (&arr, &item);
1331 g_value_unset (&item);
1333 gst_caps_set_value (caps, "stream-format", &arr);
1334 g_value_unset (&arr);
1336 gst_caps_set_simple (caps, "mpegversion", G_TYPE_INT, 4,
1337 "stream-format", G_TYPE_STRING, "raw",
1338 "base-profile", G_TYPE_STRING, "lc", NULL);
1340 if (context && context->extradata_size > 0)
1341 gst_codec_utils_aac_caps_set_level_and_profile (caps,
1342 context->extradata, context->extradata_size);
1347 case AV_CODEC_ID_AAC_LATM: /* LATM/LOAS AAC syntax */
1348 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
1349 "mpegversion", G_TYPE_INT, 4, "stream-format", G_TYPE_STRING, "loas",
1353 case AV_CODEC_ID_ASV1:
1355 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-asus",
1356 "asusversion", G_TYPE_INT, 1, NULL);
1358 case AV_CODEC_ID_ASV2:
1360 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-asus",
1361 "asusversion", G_TYPE_INT, 2, NULL);
1364 case AV_CODEC_ID_FFV1:
1366 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-ffv",
1367 "ffvversion", G_TYPE_INT, 1, NULL);
1370 case AV_CODEC_ID_4XM:
1372 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-4xm",
1376 case AV_CODEC_ID_XAN_WC3:
1377 case AV_CODEC_ID_XAN_WC4:
1379 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-xan",
1380 "wcversion", G_TYPE_INT, 3 - AV_CODEC_ID_XAN_WC3 + codec_id, NULL);
1383 case AV_CODEC_ID_CLJR:
1385 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1386 "video/x-cirrus-logic-accupak", NULL);
1389 case AV_CODEC_ID_FRAPS:
1391 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-fraps",
1395 case AV_CODEC_ID_MDEC:
1396 case AV_CODEC_ID_ROQ:
1397 case AV_CODEC_ID_INTERPLAY_VIDEO:
1401 case AV_CODEC_ID_VCR1:
1403 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1404 "video/x-ati-vcr", "vcrversion", G_TYPE_INT, 1, NULL);
1407 case AV_CODEC_ID_RPZA:
1409 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1410 "video/x-apple-video", NULL);
1413 case AV_CODEC_ID_CINEPAK:
1415 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1416 "video/x-cinepak", NULL);
1419 /* WS_VQA belogns here (order) */
1421 case AV_CODEC_ID_MSRLE:
1423 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-rle",
1424 "layout", G_TYPE_STRING, "microsoft", NULL);
1426 gst_caps_set_simple (caps,
1427 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1429 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1433 case AV_CODEC_ID_QTRLE:
1435 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-rle",
1436 "layout", G_TYPE_STRING, "quicktime", NULL);
1438 gst_caps_set_simple (caps,
1439 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1441 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1445 case AV_CODEC_ID_MSVIDEO1:
1447 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1448 "video/x-msvideocodec", "msvideoversion", G_TYPE_INT, 1, NULL);
1451 case AV_CODEC_ID_MSS1:
1453 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1454 "wmvversion", G_TYPE_INT, 1, "format", G_TYPE_STRING, "MSS1", NULL);
1457 case AV_CODEC_ID_MSS2:
1459 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1460 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "MSS2", NULL);
1463 case AV_CODEC_ID_WMV3:
1465 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1466 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "WMV3", NULL);
1468 case AV_CODEC_ID_VC1:
1470 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1471 "wmvversion", G_TYPE_INT, 3, NULL);
1472 if (!context && !encode) {
1473 GValue arr = { 0, };
1474 GValue item = { 0, };
1476 g_value_init (&arr, GST_TYPE_LIST);
1477 g_value_init (&item, G_TYPE_STRING);
1478 g_value_set_string (&item, "WVC1");
1479 gst_value_list_append_value (&arr, &item);
1480 g_value_set_string (&item, "WMVA");
1481 gst_value_list_append_and_take_value (&arr, &item);
1482 gst_caps_set_value (caps, "format", &arr);
1483 g_value_unset (&arr);
1485 gst_caps_set_simple (caps, "format", G_TYPE_STRING, "WVC1", NULL);
1488 case AV_CODEC_ID_QDM2:
1490 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-qdm2",
1494 case AV_CODEC_ID_MSZH:
1496 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-mszh",
1500 case AV_CODEC_ID_ZLIB:
1502 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-zlib",
1506 case AV_CODEC_ID_TRUEMOTION1:
1508 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1509 "video/x-truemotion", "trueversion", G_TYPE_INT, 1, NULL);
1511 case AV_CODEC_ID_TRUEMOTION2:
1513 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1514 "video/x-truemotion", "trueversion", G_TYPE_INT, 2, NULL);
1517 case AV_CODEC_ID_ULTI:
1519 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1520 "video/x-ultimotion", NULL);
1523 case AV_CODEC_ID_TSCC:
1525 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1526 "video/x-camtasia", NULL);
1528 gst_caps_set_simple (caps,
1529 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1531 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1535 case AV_CODEC_ID_TSCC2:
1537 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1538 "video/x-tscc", "tsccversion", G_TYPE_INT, 2, NULL);
1541 case AV_CODEC_ID_KMVC:
1543 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-kmvc",
1547 case AV_CODEC_ID_NUV:
1549 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-nuv",
1553 case AV_CODEC_ID_GIF:
1555 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/gif",
1559 case AV_CODEC_ID_PNG:
1561 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/png",
1565 case AV_CODEC_ID_PPM:
1567 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/ppm",
1571 case AV_CODEC_ID_PBM:
1573 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/pbm",
1577 case AV_CODEC_ID_PAM:
1579 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1580 "image/x-portable-anymap", NULL);
1583 case AV_CODEC_ID_PGM:
1585 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1586 "image/x-portable-graymap", NULL);
1589 case AV_CODEC_ID_PCX:
1591 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-pcx",
1595 case AV_CODEC_ID_SGI:
1597 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-sgi",
1601 case AV_CODEC_ID_TARGA:
1603 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-tga",
1607 case AV_CODEC_ID_TIFF:
1609 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/tiff",
1613 case AV_CODEC_ID_SUNRAST:
1615 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1616 "image/x-sun-raster", NULL);
1619 case AV_CODEC_ID_SMC:
1621 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-smc",
1625 case AV_CODEC_ID_QDRAW:
1627 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-qdrw",
1631 case AV_CODEC_ID_DNXHD:
1633 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dnxhd",
1637 case AV_CODEC_ID_PRORES:
1639 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1640 "video/x-prores", NULL);
1643 case AV_CODEC_ID_MIMIC:
1645 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-mimic",
1649 case AV_CODEC_ID_VMNC:
1651 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vmnc",
1655 case AV_CODEC_ID_TRUESPEECH:
1657 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1658 "audio/x-truespeech", NULL);
1661 case AV_CODEC_ID_QCELP:
1663 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/qcelp",
1667 case AV_CODEC_ID_AMV:
1669 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-amv",
1673 case AV_CODEC_ID_AASC:
1675 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-aasc",
1679 case AV_CODEC_ID_LOCO:
1681 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-loco",
1685 case AV_CODEC_ID_ZMBV:
1687 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-zmbv",
1691 case AV_CODEC_ID_LAGARITH:
1693 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1694 "video/x-lagarith", NULL);
1697 case AV_CODEC_ID_CSCD:
1699 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1700 "video/x-camstudio", NULL);
1702 gst_caps_set_simple (caps,
1703 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1705 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1709 case AV_CODEC_ID_AIC:
1711 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1712 "video/x-apple-intermediate-codec", NULL);
1715 case AV_CODEC_ID_CAVS:
1717 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1718 "video/x-cavs", NULL);
1721 case AV_CODEC_ID_WS_VQA:
1722 case AV_CODEC_ID_IDCIN:
1723 case AV_CODEC_ID_8BPS:
1724 case AV_CODEC_ID_FLIC:
1725 case AV_CODEC_ID_VMDVIDEO:
1726 case AV_CODEC_ID_VMDAUDIO:
1727 case AV_CODEC_ID_VIXL:
1728 case AV_CODEC_ID_QPEG:
1729 case AV_CODEC_ID_PGMYUV:
1730 case AV_CODEC_ID_FFVHUFF:
1731 case AV_CODEC_ID_WNV1:
1732 case AV_CODEC_ID_MP3ADU:
1733 case AV_CODEC_ID_MP3ON4:
1734 case AV_CODEC_ID_WESTWOOD_SND1:
1735 case AV_CODEC_ID_MMVIDEO:
1736 case AV_CODEC_ID_AVS:
1740 /* weird quasi-codecs for the demuxers only */
1741 case AV_CODEC_ID_PCM_S16LE:
1742 case AV_CODEC_ID_PCM_S16BE:
1743 case AV_CODEC_ID_PCM_U16LE:
1744 case AV_CODEC_ID_PCM_U16BE:
1745 case AV_CODEC_ID_PCM_S8:
1746 case AV_CODEC_ID_PCM_U8:
1748 GstAudioFormat format;
1751 case AV_CODEC_ID_PCM_S16LE:
1752 format = GST_AUDIO_FORMAT_S16LE;
1754 case AV_CODEC_ID_PCM_S16BE:
1755 format = GST_AUDIO_FORMAT_S16BE;
1757 case AV_CODEC_ID_PCM_U16LE:
1758 format = GST_AUDIO_FORMAT_U16LE;
1760 case AV_CODEC_ID_PCM_U16BE:
1761 format = GST_AUDIO_FORMAT_U16BE;
1763 case AV_CODEC_ID_PCM_S8:
1764 format = GST_AUDIO_FORMAT_S8;
1766 case AV_CODEC_ID_PCM_U8:
1767 format = GST_AUDIO_FORMAT_U8;
1771 g_assert (0); /* don't worry, we never get here */
1776 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-raw",
1777 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
1778 "layout", G_TYPE_STRING, "interleaved", NULL);
1782 case AV_CODEC_ID_PCM_MULAW:
1784 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mulaw",
1788 case AV_CODEC_ID_PCM_ALAW:
1790 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-alaw",
1794 case AV_CODEC_ID_ADPCM_G722:
1796 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/G722",
1799 gst_caps_set_simple (caps,
1800 "block_align", G_TYPE_INT, context->block_align,
1801 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1804 case AV_CODEC_ID_ADPCM_G726:
1806 /* the G726 decoder can also handle G721 */
1808 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-adpcm",
1809 "layout", G_TYPE_STRING, "g726", NULL);
1811 gst_caps_set_simple (caps,
1812 "block_align", G_TYPE_INT, context->block_align,
1813 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1816 gst_caps_append (caps, gst_caps_new_simple ("audio/x-adpcm",
1817 "layout", G_TYPE_STRING, "g721",
1818 "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, 8000, NULL));
1822 case AV_CODEC_ID_ADPCM_IMA_QT:
1823 case AV_CODEC_ID_ADPCM_IMA_WAV:
1824 case AV_CODEC_ID_ADPCM_IMA_DK3:
1825 case AV_CODEC_ID_ADPCM_IMA_DK4:
1826 case AV_CODEC_ID_ADPCM_IMA_WS:
1827 case AV_CODEC_ID_ADPCM_IMA_SMJPEG:
1828 case AV_CODEC_ID_ADPCM_IMA_AMV:
1829 case AV_CODEC_ID_ADPCM_IMA_ISS:
1830 case AV_CODEC_ID_ADPCM_IMA_EA_EACS:
1831 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
1832 case AV_CODEC_ID_ADPCM_MS:
1833 case AV_CODEC_ID_ADPCM_4XM:
1834 case AV_CODEC_ID_ADPCM_XA:
1835 case AV_CODEC_ID_ADPCM_ADX:
1836 case AV_CODEC_ID_ADPCM_EA:
1837 case AV_CODEC_ID_ADPCM_CT:
1838 case AV_CODEC_ID_ADPCM_SWF:
1839 case AV_CODEC_ID_ADPCM_YAMAHA:
1840 case AV_CODEC_ID_ADPCM_SBPRO_2:
1841 case AV_CODEC_ID_ADPCM_SBPRO_3:
1842 case AV_CODEC_ID_ADPCM_SBPRO_4:
1843 case AV_CODEC_ID_ADPCM_EA_R1:
1844 case AV_CODEC_ID_ADPCM_EA_R2:
1845 case AV_CODEC_ID_ADPCM_EA_R3:
1846 case AV_CODEC_ID_ADPCM_EA_MAXIS_XA:
1847 case AV_CODEC_ID_ADPCM_EA_XAS:
1848 case AV_CODEC_ID_ADPCM_THP:
1850 const gchar *layout = NULL;
1853 case AV_CODEC_ID_ADPCM_IMA_QT:
1854 layout = "quicktime";
1856 case AV_CODEC_ID_ADPCM_IMA_WAV:
1859 case AV_CODEC_ID_ADPCM_IMA_DK3:
1862 case AV_CODEC_ID_ADPCM_IMA_DK4:
1865 case AV_CODEC_ID_ADPCM_IMA_WS:
1866 layout = "westwood";
1868 case AV_CODEC_ID_ADPCM_IMA_SMJPEG:
1871 case AV_CODEC_ID_ADPCM_IMA_AMV:
1874 case AV_CODEC_ID_ADPCM_IMA_ISS:
1877 case AV_CODEC_ID_ADPCM_IMA_EA_EACS:
1880 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
1883 case AV_CODEC_ID_ADPCM_MS:
1884 layout = "microsoft";
1886 case AV_CODEC_ID_ADPCM_4XM:
1889 case AV_CODEC_ID_ADPCM_XA:
1892 case AV_CODEC_ID_ADPCM_ADX:
1895 case AV_CODEC_ID_ADPCM_EA:
1898 case AV_CODEC_ID_ADPCM_CT:
1901 case AV_CODEC_ID_ADPCM_SWF:
1904 case AV_CODEC_ID_ADPCM_YAMAHA:
1907 case AV_CODEC_ID_ADPCM_SBPRO_2:
1910 case AV_CODEC_ID_ADPCM_SBPRO_3:
1913 case AV_CODEC_ID_ADPCM_SBPRO_4:
1916 case AV_CODEC_ID_ADPCM_EA_R1:
1919 case AV_CODEC_ID_ADPCM_EA_R2:
1922 case AV_CODEC_ID_ADPCM_EA_R3:
1925 case AV_CODEC_ID_ADPCM_EA_MAXIS_XA:
1926 layout = "ea-maxis-xa";
1928 case AV_CODEC_ID_ADPCM_EA_XAS:
1931 case AV_CODEC_ID_ADPCM_THP:
1935 g_assert (0); /* don't worry, we never get here */
1939 /* FIXME: someone please check whether we need additional properties
1940 * in this caps definition. */
1942 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-adpcm",
1943 "layout", G_TYPE_STRING, layout, NULL);
1945 gst_caps_set_simple (caps,
1946 "block_align", G_TYPE_INT, context->block_align,
1947 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1951 case AV_CODEC_ID_AMR_NB:
1953 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/AMR",
1957 case AV_CODEC_ID_AMR_WB:
1959 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/AMR-WB",
1963 case AV_CODEC_ID_GSM:
1965 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-gsm",
1969 case AV_CODEC_ID_GSM_MS:
1971 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/ms-gsm",
1975 case AV_CODEC_ID_NELLYMOSER:
1977 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1978 "audio/x-nellymoser", NULL);
1981 case AV_CODEC_ID_SIPR:
1984 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-sipro",
1987 gst_caps_set_simple (caps,
1988 "leaf_size", G_TYPE_INT, context->block_align,
1989 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1994 case AV_CODEC_ID_RA_144:
1995 case AV_CODEC_ID_RA_288:
1996 case AV_CODEC_ID_COOK:
2001 case AV_CODEC_ID_RA_144:
2004 case AV_CODEC_ID_RA_288:
2007 case AV_CODEC_ID_COOK:
2014 /* FIXME: properties? */
2016 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
2017 "audio/x-pn-realaudio", "raversion", G_TYPE_INT, version, NULL);
2019 gst_caps_set_simple (caps,
2020 "leaf_size", G_TYPE_INT, context->block_align,
2021 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
2026 case AV_CODEC_ID_ROQ_DPCM:
2027 case AV_CODEC_ID_INTERPLAY_DPCM:
2028 case AV_CODEC_ID_XAN_DPCM:
2029 case AV_CODEC_ID_SOL_DPCM:
2031 const gchar *layout = NULL;
2034 case AV_CODEC_ID_ROQ_DPCM:
2037 case AV_CODEC_ID_INTERPLAY_DPCM:
2038 layout = "interplay";
2040 case AV_CODEC_ID_XAN_DPCM:
2043 case AV_CODEC_ID_SOL_DPCM:
2047 g_assert (0); /* don't worry, we never get here */
2051 /* FIXME: someone please check whether we need additional properties
2052 * in this caps definition. */
2054 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dpcm",
2055 "layout", G_TYPE_STRING, layout, NULL);
2057 gst_caps_set_simple (caps,
2058 "block_align", G_TYPE_INT, context->block_align,
2059 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
2063 case AV_CODEC_ID_SHORTEN:
2064 caps = gst_caps_new_empty_simple ("audio/x-shorten");
2067 case AV_CODEC_ID_ALAC:
2069 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-alac",
2072 gst_caps_set_simple (caps,
2073 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
2077 case AV_CODEC_ID_FLAC:
2078 /* Note that ffmpeg has no encoder yet, but just for safety. In the
2079 * encoder case, we want to add things like samplerate, channels... */
2081 caps = gst_caps_new_empty_simple ("audio/x-flac");
2085 case AV_CODEC_ID_S302M:
2086 caps = gst_caps_new_empty_simple ("audio/x-smpte-302m");
2089 case AV_CODEC_ID_DVD_SUBTITLE:
2090 case AV_CODEC_ID_DVB_SUBTITLE:
2093 case AV_CODEC_ID_BMP:
2094 caps = gst_caps_new_empty_simple ("image/bmp");
2096 case AV_CODEC_ID_TTA:
2098 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-tta",
2101 gst_caps_set_simple (caps,
2102 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
2105 case AV_CODEC_ID_TWINVQ:
2107 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
2108 "audio/x-twin-vq", NULL);
2111 GST_DEBUG ("Unknown codec ID %d, please add mapping here", codec_id);
2118 if ((codec = avcodec_find_decoder (codec_id)) ||
2119 (codec = avcodec_find_encoder (codec_id))) {
2122 GST_LOG ("Could not create stream format caps for %s", codec->name);
2124 switch (codec->type) {
2125 case AVMEDIA_TYPE_VIDEO:
2126 mime = g_strdup_printf ("video/x-gst-av-%s", codec->name);
2128 gst_ff_vid_caps_new (context, NULL, codec_id, encode, mime, NULL);
2131 case AVMEDIA_TYPE_AUDIO:
2132 mime = g_strdup_printf ("audio/x-gst-av-%s", codec->name);
2134 gst_ff_aud_caps_new (context, NULL, codec_id, encode, mime, NULL);
2136 gst_caps_set_simple (caps,
2137 "block_align", G_TYPE_INT, context->block_align,
2138 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
2149 /* set private data */
2150 if (context && context->extradata_size > 0) {
2151 GstBuffer *data = gst_buffer_new_and_alloc (context->extradata_size);
2153 gst_buffer_fill (data, 0, context->extradata, context->extradata_size);
2154 gst_caps_set_simple (caps, "codec_data", GST_TYPE_BUFFER, data, NULL);
2155 gst_buffer_unref (data);
2158 GST_LOG ("caps for codec_id=%d: %" GST_PTR_FORMAT, codec_id, caps);
2161 GST_LOG ("No caps found for codec_id=%d", codec_id);
2167 /* Convert a FFMPEG Pixel Format and optional AVCodecContext
2168 * to a GstCaps. If the context is ommitted, no fixed values
2169 * for video/audio size will be included in the GstCaps
2171 * See below for usefullness
2175 gst_ffmpeg_pixfmt_to_caps (enum PixelFormat pix_fmt, AVCodecContext * context,
2176 enum AVCodecID codec_id)
2178 GstCaps *caps = NULL;
2179 GstVideoFormat format;
2181 format = gst_ffmpeg_pixfmt_to_videoformat (pix_fmt);
2183 if (format != GST_VIDEO_FORMAT_UNKNOWN) {
2184 caps = gst_ff_vid_caps_new (context, NULL, codec_id, TRUE, "video/x-raw",
2185 "format", G_TYPE_STRING, gst_video_format_to_string (format), NULL);
2189 GST_DEBUG ("caps for pix_fmt=%d: %" GST_PTR_FORMAT, pix_fmt, caps);
2191 GST_LOG ("No caps found for pix_fmt=%d", pix_fmt);
2198 gst_ffmpeg_smpfmt_to_audioformat (enum AVSampleFormat sample_fmt)
2200 switch (sample_fmt) {
2201 case AV_SAMPLE_FMT_U8:
2202 case AV_SAMPLE_FMT_U8P:
2203 return GST_AUDIO_FORMAT_U8;
2205 case AV_SAMPLE_FMT_S16:
2206 case AV_SAMPLE_FMT_S16P:
2207 return GST_AUDIO_FORMAT_S16;
2209 case AV_SAMPLE_FMT_S32:
2210 case AV_SAMPLE_FMT_S32P:
2211 return GST_AUDIO_FORMAT_S32;
2213 case AV_SAMPLE_FMT_FLT:
2214 case AV_SAMPLE_FMT_FLTP:
2215 return GST_AUDIO_FORMAT_F32;
2217 case AV_SAMPLE_FMT_DBL:
2218 case AV_SAMPLE_FMT_DBLP:
2219 return GST_AUDIO_FORMAT_F64;
2223 return GST_AUDIO_FORMAT_UNKNOWN;
2228 /* Convert a FFMPEG Sample Format and optional AVCodecContext
2229 * to a GstCaps. If the context is ommitted, no fixed values
2230 * for video/audio size will be included in the GstCaps
2232 * See below for usefullness
2236 gst_ffmpeg_smpfmt_to_caps (enum AVSampleFormat sample_fmt,
2237 AVCodecContext * context, AVCodec * codec, enum AVCodecID codec_id)
2239 GstCaps *caps = NULL;
2240 GstAudioFormat format;
2242 format = gst_ffmpeg_smpfmt_to_audioformat (sample_fmt);
2244 if (format != GST_AUDIO_FORMAT_UNKNOWN) {
2245 caps = gst_ff_aud_caps_new (context, codec, codec_id, TRUE, "audio/x-raw",
2246 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
2247 "layout", G_TYPE_STRING, "interleaved", NULL);
2248 GST_LOG ("caps for sample_fmt=%d: %" GST_PTR_FORMAT, sample_fmt, caps);
2250 GST_LOG ("No caps found for sample_fmt=%d", sample_fmt);
2257 caps_has_field (GstCaps * caps, const gchar * field)
2261 n = gst_caps_get_size (caps);
2262 for (i = 0; i < n; i++) {
2263 GstStructure *s = gst_caps_get_structure (caps, i);
2265 if (gst_structure_has_field (s, field))
2273 gst_ffmpeg_codectype_to_audio_caps (AVCodecContext * context,
2274 enum AVCodecID codec_id, gboolean encode, AVCodec * codec)
2276 GstCaps *caps = NULL;
2278 GST_DEBUG ("context:%p, codec_id:%d, encode:%d, codec:%p",
2279 context, codec_id, encode, codec);
2281 GST_DEBUG ("sample_fmts:%p, samplerates:%p",
2282 codec->sample_fmts, codec->supported_samplerates);
2285 /* Specific codec context */
2287 gst_ffmpeg_smpfmt_to_caps (context->sample_fmt, context, codec,
2290 caps = gst_ff_aud_caps_new (context, codec, codec_id, encode, "audio/x-raw",
2291 "layout", G_TYPE_STRING, "interleaved", NULL);
2292 if (!caps_has_field (caps, "format"))
2293 gst_ffmpeg_audio_set_sample_fmts (caps,
2294 codec ? codec->sample_fmts : NULL);
2301 gst_ffmpeg_codectype_to_video_caps (AVCodecContext * context,
2302 enum AVCodecID codec_id, gboolean encode, AVCodec * codec)
2306 GST_LOG ("context:%p, codec_id:%d, encode:%d, codec:%p",
2307 context, codec_id, encode, codec);
2310 caps = gst_ffmpeg_pixfmt_to_caps (context->pix_fmt, context, codec_id);
2313 gst_ff_vid_caps_new (context, codec, codec_id, encode, "video/x-raw",
2315 if (!caps_has_field (caps, "format"))
2316 gst_ffmpeg_video_set_pix_fmts (caps, codec ? codec->pix_fmts : NULL);
2321 /* Convert a GstCaps (audio/raw) to a FFMPEG SampleFmt
2322 * and other audio properties in a AVCodecContext.
2324 * For usefullness, see below
2328 gst_ffmpeg_caps_to_smpfmt (const GstCaps * caps,
2329 AVCodecContext * context, gboolean raw)
2331 GstStructure *structure;
2333 GstAudioFormat format = GST_AUDIO_FORMAT_UNKNOWN;
2335 g_return_if_fail (gst_caps_get_size (caps) == 1);
2337 structure = gst_caps_get_structure (caps, 0);
2339 gst_structure_get_int (structure, "channels", &context->channels);
2340 gst_structure_get_int (structure, "rate", &context->sample_rate);
2341 gst_structure_get_int (structure, "block_align", &context->block_align);
2342 gst_structure_get_int (structure, "bitrate", &context->bit_rate);
2347 if (gst_structure_has_name (structure, "audio/x-raw")) {
2348 if ((fmt = gst_structure_get_string (structure, "format"))) {
2349 format = gst_audio_format_from_string (fmt);
2354 case GST_AUDIO_FORMAT_F32:
2355 context->sample_fmt = AV_SAMPLE_FMT_FLT;
2357 case GST_AUDIO_FORMAT_F64:
2358 context->sample_fmt = AV_SAMPLE_FMT_DBL;
2360 case GST_AUDIO_FORMAT_S32:
2361 context->sample_fmt = AV_SAMPLE_FMT_S32;
2363 case GST_AUDIO_FORMAT_S16:
2364 context->sample_fmt = AV_SAMPLE_FMT_S16;
2371 /* Convert a GstCaps (video/raw) to a FFMPEG PixFmt
2372 * and other video properties in a AVCodecContext.
2374 * For usefullness, see below
2378 gst_ffmpeg_caps_to_pixfmt (const GstCaps * caps,
2379 AVCodecContext * context, gboolean raw)
2381 GstStructure *structure;
2383 const GValue *par = NULL;
2385 GstVideoFormat format = GST_VIDEO_FORMAT_UNKNOWN;
2387 GST_DEBUG ("converting caps %" GST_PTR_FORMAT, caps);
2388 g_return_if_fail (gst_caps_get_size (caps) == 1);
2389 structure = gst_caps_get_structure (caps, 0);
2391 gst_structure_get_int (structure, "width", &context->width);
2392 gst_structure_get_int (structure, "height", &context->height);
2393 gst_structure_get_int (structure, "bpp", &context->bits_per_coded_sample);
2395 fps = gst_structure_get_value (structure, "framerate");
2396 if (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps)) {
2398 int num = gst_value_get_fraction_numerator (fps);
2399 int den = gst_value_get_fraction_denominator (fps);
2401 if (num > 0 && den > 0) {
2402 /* somehow these seem mixed up.. */
2403 /* they're fine, this is because it does period=1/frequency */
2404 context->time_base.den = gst_value_get_fraction_numerator (fps);
2405 context->time_base.num = gst_value_get_fraction_denominator (fps);
2406 context->ticks_per_frame = 1;
2408 GST_DEBUG ("setting framerate %d/%d = %lf",
2409 context->time_base.den, context->time_base.num,
2410 1. * context->time_base.den / context->time_base.num);
2412 GST_WARNING ("ignoring insane framerate %d/%d",
2413 context->time_base.den, context->time_base.num);
2417 par = gst_structure_get_value (structure, "pixel-aspect-ratio");
2418 if (par && GST_VALUE_HOLDS_FRACTION (par)) {
2420 int num = gst_value_get_fraction_numerator (par);
2421 int den = gst_value_get_fraction_denominator (par);
2423 if (num > 0 && den > 0) {
2424 context->sample_aspect_ratio.num = num;
2425 context->sample_aspect_ratio.den = den;
2427 GST_DEBUG ("setting pixel-aspect-ratio %d/%d = %lf",
2428 context->sample_aspect_ratio.num, context->sample_aspect_ratio.den,
2429 1. * context->sample_aspect_ratio.num /
2430 context->sample_aspect_ratio.den);
2432 GST_WARNING ("ignoring insane pixel-aspect-ratio %d/%d",
2433 context->sample_aspect_ratio.num, context->sample_aspect_ratio.den);
2440 g_return_if_fail (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps));
2442 if (gst_structure_has_name (structure, "video/x-raw")) {
2443 if ((fmt = gst_structure_get_string (structure, "format"))) {
2444 format = gst_video_format_from_string (fmt);
2449 case GST_VIDEO_FORMAT_YUY2:
2450 context->pix_fmt = AV_PIX_FMT_YUYV422;
2452 case GST_VIDEO_FORMAT_I420:
2453 context->pix_fmt = AV_PIX_FMT_YUV420P;
2455 case GST_VIDEO_FORMAT_A420:
2456 context->pix_fmt = AV_PIX_FMT_YUVA420P;
2458 case GST_VIDEO_FORMAT_Y41B:
2459 context->pix_fmt = AV_PIX_FMT_YUV411P;
2461 case GST_VIDEO_FORMAT_Y42B:
2462 context->pix_fmt = AV_PIX_FMT_YUV422P;
2464 case GST_VIDEO_FORMAT_YUV9:
2465 context->pix_fmt = AV_PIX_FMT_YUV410P;
2467 case GST_VIDEO_FORMAT_Y444:
2468 context->pix_fmt = AV_PIX_FMT_YUV444P;
2470 case GST_VIDEO_FORMAT_GRAY8:
2471 context->pix_fmt = AV_PIX_FMT_GRAY8;
2473 case GST_VIDEO_FORMAT_xRGB:
2474 #if (G_BYTE_ORDER == G_BIG_ENDIAN)
2475 context->pix_fmt = AV_PIX_FMT_RGB32;
2478 case GST_VIDEO_FORMAT_BGRx:
2479 #if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
2480 context->pix_fmt = AV_PIX_FMT_RGB32;
2483 case GST_VIDEO_FORMAT_RGB:
2484 context->pix_fmt = AV_PIX_FMT_RGB24;
2486 case GST_VIDEO_FORMAT_BGR:
2487 context->pix_fmt = AV_PIX_FMT_BGR24;
2489 case GST_VIDEO_FORMAT_RGB16:
2490 context->pix_fmt = AV_PIX_FMT_RGB565;
2492 case GST_VIDEO_FORMAT_RGB15:
2493 context->pix_fmt = AV_PIX_FMT_RGB555;
2495 case GST_VIDEO_FORMAT_RGB8P:
2496 context->pix_fmt = AV_PIX_FMT_PAL8;
2505 GstVideoFormat format;
2506 enum PixelFormat pixfmt;
2509 /* FIXME : FILLME */
2510 static const PixToFmt pixtofmttable[] = {
2511 /* GST_VIDEO_FORMAT_I420, */
2512 {GST_VIDEO_FORMAT_I420, AV_PIX_FMT_YUV420P},
2513 /* Note : this should use a different chroma placement */
2514 {GST_VIDEO_FORMAT_I420, AV_PIX_FMT_YUVJ420P},
2516 /* GST_VIDEO_FORMAT_YV12, */
2517 /* GST_VIDEO_FORMAT_YUY2, */
2518 {GST_VIDEO_FORMAT_YUY2, AV_PIX_FMT_YUYV422},
2519 /* GST_VIDEO_FORMAT_UYVY, */
2520 {GST_VIDEO_FORMAT_UYVY, AV_PIX_FMT_UYVY422},
2521 /* GST_VIDEO_FORMAT_AYUV, */
2522 /* GST_VIDEO_FORMAT_RGBx, */
2523 /* GST_VIDEO_FORMAT_BGRx, */
2524 /* GST_VIDEO_FORMAT_xRGB, */
2525 /* GST_VIDEO_FORMAT_xBGR, */
2526 /* GST_VIDEO_FORMAT_RGBA, */
2527 {GST_VIDEO_FORMAT_RGBA, AV_PIX_FMT_RGBA},
2528 /* GST_VIDEO_FORMAT_BGRA, */
2529 {GST_VIDEO_FORMAT_BGRA, AV_PIX_FMT_BGRA},
2530 /* GST_VIDEO_FORMAT_ARGB, */
2531 {GST_VIDEO_FORMAT_ARGB, AV_PIX_FMT_ARGB},
2532 /* GST_VIDEO_FORMAT_ABGR, */
2533 {GST_VIDEO_FORMAT_ABGR, AV_PIX_FMT_ABGR},
2534 /* GST_VIDEO_FORMAT_RGB, */
2535 {GST_VIDEO_FORMAT_RGB, AV_PIX_FMT_RGB24},
2536 /* GST_VIDEO_FORMAT_BGR, */
2537 {GST_VIDEO_FORMAT_BGR, AV_PIX_FMT_BGR24},
2538 /* GST_VIDEO_FORMAT_Y41B, */
2539 {GST_VIDEO_FORMAT_Y41B, AV_PIX_FMT_YUV411P},
2540 /* GST_VIDEO_FORMAT_Y42B, */
2541 {GST_VIDEO_FORMAT_Y42B, AV_PIX_FMT_YUV422P},
2542 {GST_VIDEO_FORMAT_Y42B, AV_PIX_FMT_YUVJ422P},
2543 /* GST_VIDEO_FORMAT_YVYU, */
2544 /* GST_VIDEO_FORMAT_Y444, */
2545 {GST_VIDEO_FORMAT_Y444, AV_PIX_FMT_YUV444P},
2546 {GST_VIDEO_FORMAT_Y444, AV_PIX_FMT_YUVJ444P},
2547 /* GST_VIDEO_FORMAT_v210, */
2548 /* GST_VIDEO_FORMAT_v216, */
2549 /* GST_VIDEO_FORMAT_NV12, */
2550 {GST_VIDEO_FORMAT_NV12, AV_PIX_FMT_NV12},
2551 /* GST_VIDEO_FORMAT_NV21, */
2552 {GST_VIDEO_FORMAT_NV21, AV_PIX_FMT_NV21},
2553 /* GST_VIDEO_FORMAT_GRAY8, */
2554 {GST_VIDEO_FORMAT_GRAY8, AV_PIX_FMT_GRAY8},
2555 /* GST_VIDEO_FORMAT_GRAY16_BE, */
2556 {GST_VIDEO_FORMAT_GRAY16_BE, AV_PIX_FMT_GRAY16BE},
2557 /* GST_VIDEO_FORMAT_GRAY16_LE, */
2558 {GST_VIDEO_FORMAT_GRAY16_LE, AV_PIX_FMT_GRAY16LE},
2559 /* GST_VIDEO_FORMAT_v308, */
2560 /* GST_VIDEO_FORMAT_Y800, */
2561 /* GST_VIDEO_FORMAT_Y16, */
2562 /* GST_VIDEO_FORMAT_RGB16, */
2563 {GST_VIDEO_FORMAT_RGB16, AV_PIX_FMT_RGB565},
2564 /* GST_VIDEO_FORMAT_BGR16, */
2565 /* GST_VIDEO_FORMAT_RGB15, */
2566 {GST_VIDEO_FORMAT_RGB15, AV_PIX_FMT_RGB555},
2567 /* GST_VIDEO_FORMAT_BGR15, */
2568 /* GST_VIDEO_FORMAT_UYVP, */
2569 /* GST_VIDEO_FORMAT_A420, */
2570 {GST_VIDEO_FORMAT_A420, AV_PIX_FMT_YUVA420P},
2571 /* GST_VIDEO_FORMAT_RGB8_PALETTED, */
2572 {GST_VIDEO_FORMAT_RGB8P, AV_PIX_FMT_PAL8},
2573 /* GST_VIDEO_FORMAT_YUV9, */
2574 {GST_VIDEO_FORMAT_YUV9, AV_PIX_FMT_YUV410P},
2575 /* GST_VIDEO_FORMAT_YVU9, */
2576 /* GST_VIDEO_FORMAT_IYU1, */
2577 /* GST_VIDEO_FORMAT_ARGB64, */
2578 /* GST_VIDEO_FORMAT_AYUV64, */
2579 /* GST_VIDEO_FORMAT_r210, */
2580 {GST_VIDEO_FORMAT_I420_10LE, AV_PIX_FMT_YUV420P10LE},
2581 {GST_VIDEO_FORMAT_I420_10BE, AV_PIX_FMT_YUV420P10BE},
2582 {GST_VIDEO_FORMAT_I422_10LE, AV_PIX_FMT_YUV422P10LE},
2583 {GST_VIDEO_FORMAT_I422_10BE, AV_PIX_FMT_YUV422P10BE},
2584 {GST_VIDEO_FORMAT_Y444_10LE, AV_PIX_FMT_YUV444P10LE},
2585 {GST_VIDEO_FORMAT_Y444_10BE, AV_PIX_FMT_YUV444P10BE},
2586 {GST_VIDEO_FORMAT_GBR, AV_PIX_FMT_GBRP},
2587 {GST_VIDEO_FORMAT_GBR_10LE, AV_PIX_FMT_GBRP10LE},
2588 {GST_VIDEO_FORMAT_GBR_10BE, AV_PIX_FMT_GBRP10BE},
2589 {GST_VIDEO_FORMAT_A420_10LE, AV_PIX_FMT_YUVA420P10LE},
2590 {GST_VIDEO_FORMAT_A420_10BE, AV_PIX_FMT_YUVA420P10BE},
2591 {GST_VIDEO_FORMAT_A422_10LE, AV_PIX_FMT_YUVA422P10LE},
2592 {GST_VIDEO_FORMAT_A422_10BE, AV_PIX_FMT_YUVA422P10BE},
2593 {GST_VIDEO_FORMAT_A444_10LE, AV_PIX_FMT_YUVA444P10LE},
2594 {GST_VIDEO_FORMAT_A444_10BE, AV_PIX_FMT_YUVA444P10BE},
2598 gst_ffmpeg_pixfmt_to_videoformat (enum PixelFormat pixfmt)
2602 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2603 if (pixtofmttable[i].pixfmt == pixfmt)
2604 return pixtofmttable[i].format;
2606 GST_DEBUG ("Unknown pixel format %d", pixfmt);
2607 return GST_VIDEO_FORMAT_UNKNOWN;
2611 gst_ffmpeg_videoformat_to_pixfmt (GstVideoFormat format)
2615 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2616 if (pixtofmttable[i].format == format)
2617 return pixtofmttable[i].pixfmt;
2618 return AV_PIX_FMT_NONE;
2622 gst_ffmpeg_videoinfo_to_context (GstVideoInfo * info, AVCodecContext * context)
2626 context->width = GST_VIDEO_INFO_WIDTH (info);
2627 context->height = GST_VIDEO_INFO_HEIGHT (info);
2628 for (i = 0; i < GST_VIDEO_INFO_N_COMPONENTS (info); i++)
2629 bpp += GST_VIDEO_INFO_COMP_DEPTH (info, i);
2630 context->bits_per_coded_sample = bpp;
2632 context->ticks_per_frame = 1;
2633 if (GST_VIDEO_INFO_FPS_N (info) == 0) {
2634 GST_DEBUG ("Using 25/1 framerate");
2635 context->time_base.den = 25;
2636 context->time_base.num = 1;
2638 context->time_base.den = GST_VIDEO_INFO_FPS_N (info);
2639 context->time_base.num = GST_VIDEO_INFO_FPS_D (info);
2642 context->sample_aspect_ratio.num = GST_VIDEO_INFO_PAR_N (info);
2643 context->sample_aspect_ratio.den = GST_VIDEO_INFO_PAR_D (info);
2646 gst_ffmpeg_videoformat_to_pixfmt (GST_VIDEO_INFO_FORMAT (info));
2650 gst_ffmpeg_audioinfo_to_context (GstAudioInfo * info, AVCodecContext * context)
2652 const AVCodec *codec;
2653 const enum AVSampleFormat *smpl_fmts;
2654 enum AVSampleFormat smpl_fmt = -1;
2656 context->channels = info->channels;
2657 context->sample_rate = info->rate;
2658 context->channel_layout =
2659 gst_ffmpeg_channel_positions_to_layout (info->position, info->channels);
2661 codec = context->codec;
2663 smpl_fmts = codec->sample_fmts;
2665 switch (info->finfo->format) {
2666 case GST_AUDIO_FORMAT_F32:
2668 while (*smpl_fmts != -1) {
2669 if (*smpl_fmts == AV_SAMPLE_FMT_FLT) {
2670 smpl_fmt = *smpl_fmts;
2672 } else if (*smpl_fmts == AV_SAMPLE_FMT_FLTP) {
2673 smpl_fmt = *smpl_fmts;
2679 smpl_fmt = AV_SAMPLE_FMT_FLT;
2682 case GST_AUDIO_FORMAT_F64:
2684 while (*smpl_fmts != -1) {
2685 if (*smpl_fmts == AV_SAMPLE_FMT_DBL) {
2686 smpl_fmt = *smpl_fmts;
2688 } else if (*smpl_fmts == AV_SAMPLE_FMT_DBLP) {
2689 smpl_fmt = *smpl_fmts;
2695 smpl_fmt = AV_SAMPLE_FMT_DBL;
2698 case GST_AUDIO_FORMAT_S32:
2700 while (*smpl_fmts != -1) {
2701 if (*smpl_fmts == AV_SAMPLE_FMT_S32) {
2702 smpl_fmt = *smpl_fmts;
2704 } else if (*smpl_fmts == AV_SAMPLE_FMT_S32P) {
2705 smpl_fmt = *smpl_fmts;
2711 smpl_fmt = AV_SAMPLE_FMT_S32;
2714 case GST_AUDIO_FORMAT_S16:
2716 while (*smpl_fmts != -1) {
2717 if (*smpl_fmts == AV_SAMPLE_FMT_S16) {
2718 smpl_fmt = *smpl_fmts;
2720 } else if (*smpl_fmts == AV_SAMPLE_FMT_S16P) {
2721 smpl_fmt = *smpl_fmts;
2727 smpl_fmt = AV_SAMPLE_FMT_S16;
2730 case GST_AUDIO_FORMAT_U8:
2732 while (*smpl_fmts != -1) {
2733 if (*smpl_fmts == AV_SAMPLE_FMT_U8) {
2734 smpl_fmt = *smpl_fmts;
2736 } else if (*smpl_fmts == AV_SAMPLE_FMT_U8P) {
2737 smpl_fmt = *smpl_fmts;
2743 smpl_fmt = AV_SAMPLE_FMT_U8;
2750 g_assert (smpl_fmt != -1);
2752 context->sample_fmt = smpl_fmt;
2755 /* Convert a GstCaps and a FFMPEG codec Type to a
2756 * AVCodecContext. If the context is ommitted, no fixed values
2757 * for video/audio size will be included in the context
2759 * AVMediaType is primarily meant for uncompressed data GstCaps!
2763 gst_ffmpeg_caps_with_codectype (enum AVMediaType type,
2764 const GstCaps * caps, AVCodecContext * context)
2766 if (context == NULL)
2770 case AVMEDIA_TYPE_VIDEO:
2771 gst_ffmpeg_caps_to_pixfmt (caps, context, TRUE);
2774 case AVMEDIA_TYPE_AUDIO:
2775 gst_ffmpeg_caps_to_smpfmt (caps, context, TRUE);
2786 nal_escape (guint8 * dst, guint8 * src, guint size, guint * destsize)
2790 guint8 *end = src + size;
2793 while (srcp < end) {
2794 if (count == 2 && *srcp <= 0x03) {
2795 GST_DEBUG ("added escape code");
2804 GST_DEBUG ("copy %02x, count %d", *srcp, count);
2807 *destsize = dstp - dst;
2810 /* copy the config, escaping NAL units as we iterate them, if something fails we
2811 * copy everything and hope for the best. */
2813 copy_config (guint8 * dst, guint8 * src, guint size, guint * destsize)
2818 guint nalsize, esize;
2828 cnt = *(srcp + 5) & 0x1f; /* Number of sps */
2830 GST_DEBUG ("num SPS %d", cnt);
2832 memcpy (dstp, srcp, 6);
2836 for (i = 0; i < cnt; i++) {
2837 GST_DEBUG ("copy SPS %d", i);
2838 nalsize = (srcp[0] << 8) | srcp[1];
2839 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2840 dstp[0] = esize >> 8;
2841 dstp[1] = esize & 0xff;
2843 srcp += nalsize + 2;
2846 cnt = *(dstp++) = *(srcp++); /* Number of pps */
2848 GST_DEBUG ("num PPS %d", cnt);
2850 for (i = 0; i < cnt; i++) {
2851 GST_DEBUG ("copy PPS %d", i);
2852 nalsize = (srcp[0] << 8) | srcp[1];
2853 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2854 dstp[0] = esize >> 8;
2855 dstp[1] = esize & 0xff;
2857 srcp += nalsize + 2;
2859 *destsize = dstp - dst;
2865 GST_DEBUG ("something unexpected, doing full copy");
2866 memcpy (dst, src, size);
2874 * caps_with_codecid () transforms a GstCaps for a known codec
2875 * ID into a filled-in context.
2876 * codec_data from caps will override possible extradata already in the context
2880 gst_ffmpeg_caps_with_codecid (enum AVCodecID codec_id,
2881 enum AVMediaType codec_type, const GstCaps * caps, AVCodecContext * context)
2884 const GValue *value;
2887 GST_LOG ("codec_id:%d, codec_type:%d, caps:%" GST_PTR_FORMAT " context:%p",
2888 codec_id, codec_type, caps, context);
2890 if (!context || !gst_caps_get_size (caps))
2893 str = gst_caps_get_structure (caps, 0);
2895 /* extradata parsing (esds [mpeg4], wma/wmv, msmpeg4v1/2/3, etc.) */
2896 if ((value = gst_structure_get_value (str, "codec_data"))) {
2899 buf = gst_value_get_buffer (value);
2900 gst_buffer_map (buf, &map, GST_MAP_READ);
2902 /* free the old one if it is there */
2903 if (context->extradata)
2904 av_free (context->extradata);
2907 if (codec_id == AV_CODEC_ID_H264) {
2910 GST_DEBUG ("copy, escaping codec_data %d", size);
2911 /* ffmpeg h264 expects the codec_data to be escaped, there is no real
2912 * reason for this but let's just escape it for now. Start by allocating
2913 * enough space, x2 is more than enough.
2915 * FIXME, we disabled escaping because some file already contain escaped
2916 * codec_data and then we escape twice and fail. It's better to leave it
2917 * as is, as that is what most players do. */
2918 context->extradata =
2919 av_mallocz (GST_ROUND_UP_16 (size * 2 +
2920 FF_INPUT_BUFFER_PADDING_SIZE));
2921 copy_config (context->extradata, data, size, &extrasize);
2922 GST_DEBUG ("escaped size: %d", extrasize);
2923 context->extradata_size = extrasize;
2927 /* allocate with enough padding */
2928 GST_DEBUG ("copy codec_data");
2929 context->extradata =
2930 av_mallocz (GST_ROUND_UP_16 (map.size +
2931 FF_INPUT_BUFFER_PADDING_SIZE));
2932 memcpy (context->extradata, map.data, map.size);
2933 context->extradata_size = map.size;
2936 /* Hack for VC1. Sometimes the first (length) byte is 0 for some files */
2937 if (codec_id == AV_CODEC_ID_VC1 && map.size > 0 && map.data[0] == 0) {
2938 context->extradata[0] = (guint8) map.size;
2941 GST_DEBUG ("have codec data of size %" G_GSIZE_FORMAT, map.size);
2943 gst_buffer_unmap (buf, &map);
2944 } else if (context->extradata == NULL && codec_id != AV_CODEC_ID_AAC_LATM &&
2945 codec_id != AV_CODEC_ID_FLAC) {
2946 /* no extradata, alloc dummy with 0 sized, some codecs insist on reading
2947 * extradata anyway which makes then segfault. */
2948 context->extradata =
2949 av_mallocz (GST_ROUND_UP_16 (FF_INPUT_BUFFER_PADDING_SIZE));
2950 context->extradata_size = 0;
2951 GST_DEBUG ("no codec data");
2955 case AV_CODEC_ID_MPEG4:
2957 const gchar *mime = gst_structure_get_name (str);
2959 context->flags |= CODEC_FLAG_4MV;
2961 if (!strcmp (mime, "video/x-divx"))
2962 context->codec_tag = GST_MAKE_FOURCC ('D', 'I', 'V', 'X');
2963 else if (!strcmp (mime, "video/mpeg")) {
2964 const gchar *profile;
2966 context->codec_tag = GST_MAKE_FOURCC ('m', 'p', '4', 'v');
2968 profile = gst_structure_get_string (str, "profile");
2970 if (g_strcmp0 (profile, "advanced-simple") == 0)
2971 context->flags |= CODEC_FLAG_GMC | CODEC_FLAG_QPEL;
2977 case AV_CODEC_ID_SVQ3:
2978 /* FIXME: this is a workaround for older gst-plugins releases
2979 * (<= 0.8.9). This should be removed at some point, because
2980 * it causes wrong decoded frame order. */
2981 if (!context->extradata) {
2982 gint halfpel_flag, thirdpel_flag, low_delay, unknown_svq3_flag;
2985 if (gst_structure_get_int (str, "halfpel_flag", &halfpel_flag) &&
2986 gst_structure_get_int (str, "thirdpel_flag", &thirdpel_flag) &&
2987 gst_structure_get_int (str, "low_delay", &low_delay) &&
2988 gst_structure_get_int (str, "unknown_svq3_flag",
2989 &unknown_svq3_flag)) {
2990 context->extradata = (guint8 *) av_mallocz (0x64);
2991 g_stpcpy ((gchar *) context->extradata, "SVQ3");
2995 flags |= unknown_svq3_flag;
2997 flags |= halfpel_flag;
2999 flags |= thirdpel_flag;
3002 flags = GUINT16_FROM_LE (flags);
3004 memcpy ((gchar *) context->extradata + 0x62, &flags, 2);
3005 context->extradata_size = 0x64;
3010 case AV_CODEC_ID_MSRLE:
3011 case AV_CODEC_ID_QTRLE:
3012 case AV_CODEC_ID_TSCC:
3013 case AV_CODEC_ID_CSCD:
3014 case AV_CODEC_ID_APE:
3018 if (gst_structure_get_int (str, "depth", &depth)) {
3019 context->bits_per_coded_sample = depth;
3021 GST_WARNING ("No depth field in caps %" GST_PTR_FORMAT, caps);
3027 case AV_CODEC_ID_COOK:
3028 case AV_CODEC_ID_RA_288:
3029 case AV_CODEC_ID_RA_144:
3030 case AV_CODEC_ID_SIPR:
3035 if (gst_structure_get_int (str, "leaf_size", &leaf_size))
3036 context->block_align = leaf_size;
3037 if (gst_structure_get_int (str, "bitrate", &bitrate))
3038 context->bit_rate = bitrate;
3041 case AV_CODEC_ID_ALAC:
3042 gst_structure_get_int (str, "samplesize",
3043 &context->bits_per_coded_sample);
3046 case AV_CODEC_ID_DVVIDEO:
3048 const gchar *format;
3050 if ((format = gst_structure_get_string (str, "format"))) {
3052 if (g_str_equal (format, "YUY2"))
3053 context->pix_fmt = AV_PIX_FMT_YUYV422;
3054 else if (g_str_equal (format, "I420"))
3055 context->pix_fmt = AV_PIX_FMT_YUV420P;
3056 else if (g_str_equal (format, "A420"))
3057 context->pix_fmt = AV_PIX_FMT_YUVA420P;
3058 else if (g_str_equal (format, "Y41B"))
3059 context->pix_fmt = AV_PIX_FMT_YUV411P;
3060 else if (g_str_equal (format, "Y42B"))
3061 context->pix_fmt = AV_PIX_FMT_YUV422P;
3062 else if (g_str_equal (format, "YUV9"))
3063 context->pix_fmt = AV_PIX_FMT_YUV410P;
3065 GST_WARNING ("couldn't convert format %s" " to a pixel format",
3069 GST_WARNING ("No specified format");
3072 case AV_CODEC_ID_H263P:
3076 if (!gst_structure_get_boolean (str, "annex-f", &val) || val)
3077 context->flags |= CODEC_FLAG_4MV;
3079 context->flags &= ~CODEC_FLAG_4MV;
3080 if ((!gst_structure_get_boolean (str, "annex-i", &val) || val) &&
3081 (!gst_structure_get_boolean (str, "annex-t", &val) || val))
3082 context->flags |= CODEC_FLAG_AC_PRED;
3084 context->flags &= ~CODEC_FLAG_AC_PRED;
3085 if (!gst_structure_get_boolean (str, "annex-j", &val) || val)
3086 context->flags |= CODEC_FLAG_LOOP_FILTER;
3088 context->flags &= ~CODEC_FLAG_LOOP_FILTER;
3091 case AV_CODEC_ID_ADPCM_G726:
3093 const gchar *layout;
3095 if ((layout = gst_structure_get_string (str, "layout"))) {
3096 if (!strcmp (layout, "g721")) {
3097 context->sample_rate = 8000;
3098 context->channels = 1;
3099 context->bit_rate = 32000;
3108 if (!gst_caps_is_fixed (caps))
3111 /* common properties (width, height, fps) */
3112 switch (codec_type) {
3113 case AVMEDIA_TYPE_VIDEO:
3114 gst_ffmpeg_caps_to_pixfmt (caps, context,
3115 codec_id == AV_CODEC_ID_RAWVIDEO);
3117 case AVMEDIA_TYPE_AUDIO:
3118 gst_ffmpeg_caps_to_smpfmt (caps, context, FALSE);
3124 /* fixup of default settings */
3126 case AV_CODEC_ID_QCELP:
3127 /* QCELP is always mono, no matter what the caps say */
3128 context->channels = 1;
3130 case AV_CODEC_ID_ADPCM_G726:
3131 if (context->sample_rate && context->bit_rate)
3132 context->bits_per_coded_sample =
3133 context->bit_rate / context->sample_rate;
3140 /* _formatid_to_caps () is meant for muxers/demuxers, it
3141 * transforms a name (ffmpeg way of ID'ing these, why don't
3142 * they have unique numerical IDs?) to the corresponding
3143 * caps belonging to that mux-format
3145 * Note: we don't need any additional info because the caps
3146 * isn't supposed to contain any useful info besides the
3151 gst_ffmpeg_formatid_to_caps (const gchar * format_name)
3153 GstCaps *caps = NULL;
3155 if (!strcmp (format_name, "mpeg")) {
3156 caps = gst_caps_new_simple ("video/mpeg",
3157 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3158 } else if (!strcmp (format_name, "mpegts")) {
3159 caps = gst_caps_new_simple ("video/mpegts",
3160 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3161 } else if (!strcmp (format_name, "rm")) {
3162 caps = gst_caps_new_simple ("application/x-pn-realmedia",
3163 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3164 } else if (!strcmp (format_name, "asf")) {
3165 caps = gst_caps_new_empty_simple ("video/x-ms-asf");
3166 } else if (!strcmp (format_name, "avi")) {
3167 caps = gst_caps_new_empty_simple ("video/x-msvideo");
3168 } else if (!strcmp (format_name, "wav")) {
3169 caps = gst_caps_new_empty_simple ("audio/x-wav");
3170 } else if (!strcmp (format_name, "ape")) {
3171 caps = gst_caps_new_empty_simple ("application/x-ape");
3172 } else if (!strcmp (format_name, "swf")) {
3173 caps = gst_caps_new_empty_simple ("application/x-shockwave-flash");
3174 } else if (!strcmp (format_name, "au")) {
3175 caps = gst_caps_new_empty_simple ("audio/x-au");
3176 } else if (!strcmp (format_name, "dv")) {
3177 caps = gst_caps_new_simple ("video/x-dv",
3178 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3179 } else if (!strcmp (format_name, "4xm")) {
3180 caps = gst_caps_new_empty_simple ("video/x-4xm");
3181 } else if (!strcmp (format_name, "matroska")) {
3182 caps = gst_caps_new_empty_simple ("video/x-matroska");
3183 } else if (!strcmp (format_name, "mp3")) {
3184 caps = gst_caps_new_empty_simple ("application/x-id3");
3185 } else if (!strcmp (format_name, "flic")) {
3186 caps = gst_caps_new_empty_simple ("video/x-fli");
3187 } else if (!strcmp (format_name, "flv")) {
3188 caps = gst_caps_new_empty_simple ("video/x-flv");
3189 } else if (!strcmp (format_name, "tta")) {
3190 caps = gst_caps_new_empty_simple ("audio/x-ttafile");
3191 } else if (!strcmp (format_name, "aiff")) {
3192 caps = gst_caps_new_empty_simple ("audio/x-aiff");
3193 } else if (!strcmp (format_name, "mov_mp4_m4a_3gp_3g2")) {
3195 gst_caps_from_string
3196 ("application/x-3gp; video/quicktime; audio/x-m4a");
3197 } else if (!strcmp (format_name, "mov")) {
3198 caps = gst_caps_from_string ("video/quicktime,variant=(string)apple");
3199 } else if (!strcmp (format_name, "mp4")) {
3200 caps = gst_caps_from_string ("video/quicktime,variant=(string)iso");
3201 } else if (!strcmp (format_name, "3gp")) {
3202 caps = gst_caps_from_string ("video/quicktime,variant=(string)3gpp");
3203 } else if (!strcmp (format_name, "3g2")) {
3204 caps = gst_caps_from_string ("video/quicktime,variant=(string)3g2");
3205 } else if (!strcmp (format_name, "psp")) {
3206 caps = gst_caps_from_string ("video/quicktime,variant=(string)psp");
3207 } else if (!strcmp (format_name, "ipod")) {
3208 caps = gst_caps_from_string ("video/quicktime,variant=(string)ipod");
3209 } else if (!strcmp (format_name, "aac")) {
3210 caps = gst_caps_new_simple ("audio/mpeg",
3211 "mpegversion", G_TYPE_INT, 4, NULL);
3212 } else if (!strcmp (format_name, "gif")) {
3213 caps = gst_caps_from_string ("image/gif");
3214 } else if (!strcmp (format_name, "ogg")) {
3215 caps = gst_caps_from_string ("application/ogg");
3216 } else if (!strcmp (format_name, "mxf") || !strcmp (format_name, "mxf_d10")) {
3217 caps = gst_caps_from_string ("application/mxf");
3218 } else if (!strcmp (format_name, "gxf")) {
3219 caps = gst_caps_from_string ("application/gxf");
3220 } else if (!strcmp (format_name, "yuv4mpegpipe")) {
3221 caps = gst_caps_new_simple ("application/x-yuv4mpeg",
3222 "y4mversion", G_TYPE_INT, 2, NULL);
3223 } else if (!strcmp (format_name, "mpc")) {
3224 caps = gst_caps_from_string ("audio/x-musepack, streamversion = (int) 7");
3225 } else if (!strcmp (format_name, "vqf")) {
3226 caps = gst_caps_from_string ("audio/x-vqf");
3227 } else if (!strcmp (format_name, "nsv")) {
3228 caps = gst_caps_from_string ("video/x-nsv");
3229 } else if (!strcmp (format_name, "amr")) {
3230 caps = gst_caps_from_string ("audio/x-amr-nb-sh");
3231 } else if (!strcmp (format_name, "webm")) {
3232 caps = gst_caps_from_string ("video/webm");
3233 } else if (!strcmp (format_name, "voc")) {
3234 caps = gst_caps_from_string ("audio/x-voc");
3235 } else if (!strcmp (format_name, "pva")) {
3236 caps = gst_caps_from_string ("video/x-pva");
3240 GST_LOG ("Could not create stream format caps for %s", format_name);
3241 name = g_strdup_printf ("application/x-gst-av-%s", format_name);
3242 caps = gst_caps_new_empty_simple (name);
3250 gst_ffmpeg_formatid_get_codecids (const gchar * format_name,
3251 enum AVCodecID ** video_codec_list, enum AVCodecID ** audio_codec_list,
3252 AVOutputFormat * plugin)
3254 static enum AVCodecID tmp_vlist[] = {
3258 static enum AVCodecID tmp_alist[] = {
3263 GST_LOG ("format_name : %s", format_name);
3265 if (!strcmp (format_name, "mp4")) {
3266 static enum AVCodecID mp4_video_list[] = {
3267 AV_CODEC_ID_MPEG4, AV_CODEC_ID_H264,
3271 static enum AVCodecID mp4_audio_list[] = {
3272 AV_CODEC_ID_AAC, AV_CODEC_ID_MP3,
3276 *video_codec_list = mp4_video_list;
3277 *audio_codec_list = mp4_audio_list;
3278 } else if (!strcmp (format_name, "mpeg")) {
3279 static enum AVCodecID mpeg_video_list[] = { AV_CODEC_ID_MPEG1VIDEO,
3280 AV_CODEC_ID_MPEG2VIDEO,
3284 static enum AVCodecID mpeg_audio_list[] = { AV_CODEC_ID_MP1,
3290 *video_codec_list = mpeg_video_list;
3291 *audio_codec_list = mpeg_audio_list;
3292 } else if (!strcmp (format_name, "dvd")) {
3293 static enum AVCodecID mpeg_video_list[] = { AV_CODEC_ID_MPEG2VIDEO,
3296 static enum AVCodecID mpeg_audio_list[] = { AV_CODEC_ID_MP2,
3299 AV_CODEC_ID_PCM_S16BE,
3303 *video_codec_list = mpeg_video_list;
3304 *audio_codec_list = mpeg_audio_list;
3305 } else if (!strcmp (format_name, "mpegts")) {
3306 static enum AVCodecID mpegts_video_list[] = { AV_CODEC_ID_MPEG1VIDEO,
3307 AV_CODEC_ID_MPEG2VIDEO,
3311 static enum AVCodecID mpegts_audio_list[] = { AV_CODEC_ID_MP2,
3319 *video_codec_list = mpegts_video_list;
3320 *audio_codec_list = mpegts_audio_list;
3321 } else if (!strcmp (format_name, "vob")) {
3322 static enum AVCodecID vob_video_list[] =
3323 { AV_CODEC_ID_MPEG2VIDEO, AV_CODEC_ID_NONE };
3324 static enum AVCodecID vob_audio_list[] = { AV_CODEC_ID_MP2, AV_CODEC_ID_AC3,
3325 AV_CODEC_ID_DTS, AV_CODEC_ID_NONE
3328 *video_codec_list = vob_video_list;
3329 *audio_codec_list = vob_audio_list;
3330 } else if (!strcmp (format_name, "flv")) {
3331 static enum AVCodecID flv_video_list[] =
3332 { AV_CODEC_ID_FLV1, AV_CODEC_ID_NONE };
3333 static enum AVCodecID flv_audio_list[] =
3334 { AV_CODEC_ID_MP3, AV_CODEC_ID_NONE };
3336 *video_codec_list = flv_video_list;
3337 *audio_codec_list = flv_audio_list;
3338 } else if (!strcmp (format_name, "asf")) {
3339 static enum AVCodecID asf_video_list[] =
3340 { AV_CODEC_ID_WMV1, AV_CODEC_ID_WMV2, AV_CODEC_ID_MSMPEG4V3,
3343 static enum AVCodecID asf_audio_list[] =
3344 { AV_CODEC_ID_WMAV1, AV_CODEC_ID_WMAV2, AV_CODEC_ID_MP3,
3348 *video_codec_list = asf_video_list;
3349 *audio_codec_list = asf_audio_list;
3350 } else if (!strcmp (format_name, "dv")) {
3351 static enum AVCodecID dv_video_list[] =
3352 { AV_CODEC_ID_DVVIDEO, AV_CODEC_ID_NONE };
3353 static enum AVCodecID dv_audio_list[] =
3354 { AV_CODEC_ID_PCM_S16LE, AV_CODEC_ID_NONE };
3356 *video_codec_list = dv_video_list;
3357 *audio_codec_list = dv_audio_list;
3358 } else if (!strcmp (format_name, "mov")) {
3359 static enum AVCodecID mov_video_list[] = {
3360 AV_CODEC_ID_SVQ1, AV_CODEC_ID_SVQ3, AV_CODEC_ID_MPEG4,
3361 AV_CODEC_ID_H263, AV_CODEC_ID_H263P,
3362 AV_CODEC_ID_H264, AV_CODEC_ID_DVVIDEO,
3366 static enum AVCodecID mov_audio_list[] = {
3367 AV_CODEC_ID_PCM_MULAW, AV_CODEC_ID_PCM_ALAW, AV_CODEC_ID_ADPCM_IMA_QT,
3368 AV_CODEC_ID_MACE3, AV_CODEC_ID_MACE6, AV_CODEC_ID_AAC,
3369 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3370 AV_CODEC_ID_PCM_S16BE, AV_CODEC_ID_PCM_S16LE,
3371 AV_CODEC_ID_MP3, AV_CODEC_ID_NONE
3374 *video_codec_list = mov_video_list;
3375 *audio_codec_list = mov_audio_list;
3376 } else if ((!strcmp (format_name, "3gp") || !strcmp (format_name, "3g2"))) {
3377 static enum AVCodecID tgp_video_list[] = {
3378 AV_CODEC_ID_MPEG4, AV_CODEC_ID_H263, AV_CODEC_ID_H263P, AV_CODEC_ID_H264,
3381 static enum AVCodecID tgp_audio_list[] = {
3382 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3387 *video_codec_list = tgp_video_list;
3388 *audio_codec_list = tgp_audio_list;
3389 } else if (!strcmp (format_name, "mmf")) {
3390 static enum AVCodecID mmf_audio_list[] = {
3391 AV_CODEC_ID_ADPCM_YAMAHA, AV_CODEC_ID_NONE
3393 *video_codec_list = NULL;
3394 *audio_codec_list = mmf_audio_list;
3395 } else if (!strcmp (format_name, "amr")) {
3396 static enum AVCodecID amr_audio_list[] = {
3397 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3400 *video_codec_list = NULL;
3401 *audio_codec_list = amr_audio_list;
3402 } else if (!strcmp (format_name, "gif")) {
3403 static enum AVCodecID gif_image_list[] = {
3404 AV_CODEC_ID_RAWVIDEO, AV_CODEC_ID_NONE
3406 *video_codec_list = gif_image_list;
3407 *audio_codec_list = NULL;
3408 } else if ((plugin->audio_codec != AV_CODEC_ID_NONE) ||
3409 (plugin->video_codec != AV_CODEC_ID_NONE)) {
3410 tmp_vlist[0] = plugin->video_codec;
3411 tmp_alist[0] = plugin->audio_codec;
3413 *video_codec_list = tmp_vlist;
3414 *audio_codec_list = tmp_alist;
3415 } else if ((!strcmp (format_name, "pva"))) {
3416 static enum AVCodecID tgp_video_list[] = {
3417 AV_CODEC_ID_MPEG2VIDEO,
3420 static enum AVCodecID tgp_audio_list[] = {
3425 *video_codec_list = tgp_video_list;
3426 *audio_codec_list = tgp_audio_list;
3428 GST_LOG ("Format %s not found", format_name);
3435 /* Convert a GstCaps to a FFMPEG codec ID. Size et all
3436 * are omitted, that can be queried by the user itself,
3437 * we're not eating the GstCaps or anything
3438 * A pointer to an allocated context is also needed for
3439 * optional extra info
3443 gst_ffmpeg_caps_to_codecid (const GstCaps * caps, AVCodecContext * context)
3445 enum AVCodecID id = AV_CODEC_ID_NONE;
3446 const gchar *mimetype;
3447 const GstStructure *structure;
3448 gboolean video = FALSE, audio = FALSE; /* we want to be sure! */
3450 g_return_val_if_fail (caps != NULL, AV_CODEC_ID_NONE);
3451 g_return_val_if_fail (gst_caps_get_size (caps) == 1, AV_CODEC_ID_NONE);
3452 structure = gst_caps_get_structure (caps, 0);
3454 mimetype = gst_structure_get_name (structure);
3456 if (!strcmp (mimetype, "video/x-raw")) {
3457 id = AV_CODEC_ID_RAWVIDEO;
3459 } else if (!strcmp (mimetype, "audio/x-raw")) {
3462 if (gst_audio_info_from_caps (&info, caps)) {
3463 switch (GST_AUDIO_INFO_FORMAT (&info)) {
3464 case GST_AUDIO_FORMAT_S8:
3465 id = AV_CODEC_ID_PCM_S8;
3467 case GST_AUDIO_FORMAT_U8:
3468 id = AV_CODEC_ID_PCM_U8;
3470 case GST_AUDIO_FORMAT_S16LE:
3471 id = AV_CODEC_ID_PCM_S16LE;
3473 case GST_AUDIO_FORMAT_S16BE:
3474 id = AV_CODEC_ID_PCM_S16BE;
3476 case GST_AUDIO_FORMAT_U16LE:
3477 id = AV_CODEC_ID_PCM_U16LE;
3479 case GST_AUDIO_FORMAT_U16BE:
3480 id = AV_CODEC_ID_PCM_U16BE;
3485 if (id != AV_CODEC_ID_NONE)
3488 } else if (!strcmp (mimetype, "audio/x-mulaw")) {
3489 id = AV_CODEC_ID_PCM_MULAW;
3491 } else if (!strcmp (mimetype, "audio/x-alaw")) {
3492 id = AV_CODEC_ID_PCM_ALAW;
3494 } else if (!strcmp (mimetype, "video/x-dv")) {
3497 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3499 id = AV_CODEC_ID_DVVIDEO;
3502 } else if (!strcmp (mimetype, "audio/x-dv")) { /* ??? */
3503 id = AV_CODEC_ID_DVAUDIO;
3505 } else if (!strcmp (mimetype, "video/x-h263")) {
3506 const gchar *h263version =
3507 gst_structure_get_string (structure, "h263version");
3508 if (h263version && !strcmp (h263version, "h263p"))
3509 id = AV_CODEC_ID_H263P;
3511 id = AV_CODEC_ID_H263;
3513 } else if (!strcmp (mimetype, "video/x-intel-h263")) {
3514 id = AV_CODEC_ID_H263I;
3516 } else if (!strcmp (mimetype, "video/x-h261")) {
3517 id = AV_CODEC_ID_H261;
3519 } else if (!strcmp (mimetype, "video/mpeg")) {
3523 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3524 gst_structure_get_int (structure, "mpegversion", &mpegversion) &&
3526 switch (mpegversion) {
3528 id = AV_CODEC_ID_MPEG1VIDEO;
3531 id = AV_CODEC_ID_MPEG2VIDEO;
3534 id = AV_CODEC_ID_MPEG4;
3538 if (id != AV_CODEC_ID_NONE)
3540 } else if (!strcmp (mimetype, "image/jpeg")) {
3541 id = AV_CODEC_ID_MJPEG; /* A... B... */
3543 } else if (!strcmp (mimetype, "video/x-jpeg-b")) {
3544 id = AV_CODEC_ID_MJPEGB;
3546 } else if (!strcmp (mimetype, "video/x-wmv")) {
3547 gint wmvversion = 0;
3549 if (gst_structure_get_int (structure, "wmvversion", &wmvversion)) {
3550 switch (wmvversion) {
3552 id = AV_CODEC_ID_WMV1;
3555 id = AV_CODEC_ID_WMV2;
3559 const gchar *format;
3561 /* WMV3 unless the fourcc exists and says otherwise */
3562 id = AV_CODEC_ID_WMV3;
3564 if ((format = gst_structure_get_string (structure, "format")) &&
3565 (g_str_equal (format, "WVC1") || g_str_equal (format, "WMVA")))
3566 id = AV_CODEC_ID_VC1;
3572 if (id != AV_CODEC_ID_NONE)
3574 } else if (!strcmp (mimetype, "audio/x-vorbis")) {
3575 id = AV_CODEC_ID_VORBIS;
3577 } else if (!strcmp (mimetype, "audio/x-qdm2")) {
3578 id = AV_CODEC_ID_QDM2;
3580 } else if (!strcmp (mimetype, "audio/mpeg")) {
3582 gint mpegversion = 0;
3584 if (gst_structure_get_int (structure, "mpegversion", &mpegversion)) {
3585 switch (mpegversion) {
3586 case 2: /* ffmpeg uses faad for both... */
3588 id = AV_CODEC_ID_AAC;
3591 if (gst_structure_get_int (structure, "layer", &layer)) {
3594 id = AV_CODEC_ID_MP1;
3597 id = AV_CODEC_ID_MP2;
3600 id = AV_CODEC_ID_MP3;
3606 if (id != AV_CODEC_ID_NONE)
3608 } else if (!strcmp (mimetype, "audio/x-musepack")) {
3609 gint streamversion = -1;
3611 if (gst_structure_get_int (structure, "streamversion", &streamversion)) {
3612 if (streamversion == 7)
3613 id = AV_CODEC_ID_MUSEPACK7;
3615 id = AV_CODEC_ID_MUSEPACK7;
3617 } else if (!strcmp (mimetype, "audio/x-wma")) {
3618 gint wmaversion = 0;
3620 if (gst_structure_get_int (structure, "wmaversion", &wmaversion)) {
3621 switch (wmaversion) {
3623 id = AV_CODEC_ID_WMAV1;
3626 id = AV_CODEC_ID_WMAV2;
3629 id = AV_CODEC_ID_WMAPRO;
3633 if (id != AV_CODEC_ID_NONE)
3635 } else if (!strcmp (mimetype, "audio/x-wms")) {
3636 id = AV_CODEC_ID_WMAVOICE;
3638 } else if (!strcmp (mimetype, "audio/x-ac3")) {
3639 id = AV_CODEC_ID_AC3;
3641 } else if (!strcmp (mimetype, "audio/x-eac3")) {
3642 id = AV_CODEC_ID_EAC3;
3644 } else if (!strcmp (mimetype, "audio/x-vnd.sony.atrac3") ||
3645 !strcmp (mimetype, "audio/atrac3")) {
3646 id = AV_CODEC_ID_ATRAC3;
3648 } else if (!strcmp (mimetype, "audio/x-dts")) {
3649 id = AV_CODEC_ID_DTS;
3651 } else if (!strcmp (mimetype, "application/x-ape")) {
3652 id = AV_CODEC_ID_APE;
3654 } else if (!strcmp (mimetype, "video/x-msmpeg")) {
3655 gint msmpegversion = 0;
3657 if (gst_structure_get_int (structure, "msmpegversion", &msmpegversion)) {
3658 switch (msmpegversion) {
3660 id = AV_CODEC_ID_MSMPEG4V1;
3663 id = AV_CODEC_ID_MSMPEG4V2;
3666 id = AV_CODEC_ID_MSMPEG4V3;
3670 if (id != AV_CODEC_ID_NONE)
3672 } else if (!strcmp (mimetype, "video/x-svq")) {
3673 gint svqversion = 0;
3675 if (gst_structure_get_int (structure, "svqversion", &svqversion)) {
3676 switch (svqversion) {
3678 id = AV_CODEC_ID_SVQ1;
3681 id = AV_CODEC_ID_SVQ3;
3685 if (id != AV_CODEC_ID_NONE)
3687 } else if (!strcmp (mimetype, "video/x-huffyuv")) {
3688 id = AV_CODEC_ID_HUFFYUV;
3690 } else if (!strcmp (mimetype, "audio/x-mace")) {
3691 gint maceversion = 0;
3693 if (gst_structure_get_int (structure, "maceversion", &maceversion)) {
3694 switch (maceversion) {
3696 id = AV_CODEC_ID_MACE3;
3699 id = AV_CODEC_ID_MACE6;
3703 if (id != AV_CODEC_ID_NONE)
3705 } else if (!strcmp (mimetype, "video/x-theora")) {
3706 id = AV_CODEC_ID_THEORA;
3708 } else if (!strcmp (mimetype, "video/x-vp3")) {
3709 id = AV_CODEC_ID_VP3;
3711 } else if (!strcmp (mimetype, "video/x-vp5")) {
3712 id = AV_CODEC_ID_VP5;
3714 } else if (!strcmp (mimetype, "video/x-vp6")) {
3715 id = AV_CODEC_ID_VP6;
3717 } else if (!strcmp (mimetype, "video/x-vp6-flash")) {
3718 id = AV_CODEC_ID_VP6F;
3720 } else if (!strcmp (mimetype, "video/x-vp6-alpha")) {
3721 id = AV_CODEC_ID_VP6A;
3723 } else if (!strcmp (mimetype, "video/x-vp8")) {
3724 id = AV_CODEC_ID_VP8;
3726 } else if (!strcmp (mimetype, "video/x-flash-screen")) {
3727 id = AV_CODEC_ID_FLASHSV;
3729 } else if (!strcmp (mimetype, "video/x-indeo")) {
3730 gint indeoversion = 0;
3732 if (gst_structure_get_int (structure, "indeoversion", &indeoversion)) {
3733 switch (indeoversion) {
3735 id = AV_CODEC_ID_INDEO5;
3738 id = AV_CODEC_ID_INDEO4;
3741 id = AV_CODEC_ID_INDEO3;
3744 id = AV_CODEC_ID_INDEO2;
3747 if (id != AV_CODEC_ID_NONE)
3750 } else if (!strcmp (mimetype, "video/x-divx")) {
3751 gint divxversion = 0;
3753 if (gst_structure_get_int (structure, "divxversion", &divxversion)) {
3754 switch (divxversion) {
3756 id = AV_CODEC_ID_MSMPEG4V3;
3760 id = AV_CODEC_ID_MPEG4;
3764 if (id != AV_CODEC_ID_NONE)
3766 } else if (!strcmp (mimetype, "video/x-ffv")) {
3767 gint ffvversion = 0;
3769 if (gst_structure_get_int (structure, "ffvversion", &ffvversion) &&
3771 id = AV_CODEC_ID_FFV1;
3774 } else if (!strcmp (mimetype, "video/x-apple-intermediate-codec")) {
3775 id = AV_CODEC_ID_AIC;
3777 } else if (!strcmp (mimetype, "audio/x-adpcm")) {
3778 const gchar *layout;
3780 layout = gst_structure_get_string (structure, "layout");
3781 if (layout == NULL) {
3783 } else if (!strcmp (layout, "quicktime")) {
3784 id = AV_CODEC_ID_ADPCM_IMA_QT;
3785 } else if (!strcmp (layout, "microsoft")) {
3786 id = AV_CODEC_ID_ADPCM_MS;
3787 } else if (!strcmp (layout, "dvi")) {
3788 id = AV_CODEC_ID_ADPCM_IMA_WAV;
3789 } else if (!strcmp (layout, "4xm")) {
3790 id = AV_CODEC_ID_ADPCM_4XM;
3791 } else if (!strcmp (layout, "smjpeg")) {
3792 id = AV_CODEC_ID_ADPCM_IMA_SMJPEG;
3793 } else if (!strcmp (layout, "dk3")) {
3794 id = AV_CODEC_ID_ADPCM_IMA_DK3;
3795 } else if (!strcmp (layout, "dk4")) {
3796 id = AV_CODEC_ID_ADPCM_IMA_DK4;
3797 } else if (!strcmp (layout, "westwood")) {
3798 id = AV_CODEC_ID_ADPCM_IMA_WS;
3799 } else if (!strcmp (layout, "iss")) {
3800 id = AV_CODEC_ID_ADPCM_IMA_ISS;
3801 } else if (!strcmp (layout, "xa")) {
3802 id = AV_CODEC_ID_ADPCM_XA;
3803 } else if (!strcmp (layout, "adx")) {
3804 id = AV_CODEC_ID_ADPCM_ADX;
3805 } else if (!strcmp (layout, "ea")) {
3806 id = AV_CODEC_ID_ADPCM_EA;
3807 } else if (!strcmp (layout, "g726")) {
3808 id = AV_CODEC_ID_ADPCM_G726;
3809 } else if (!strcmp (layout, "g721")) {
3810 id = AV_CODEC_ID_ADPCM_G726;
3811 } else if (!strcmp (layout, "ct")) {
3812 id = AV_CODEC_ID_ADPCM_CT;
3813 } else if (!strcmp (layout, "swf")) {
3814 id = AV_CODEC_ID_ADPCM_SWF;
3815 } else if (!strcmp (layout, "yamaha")) {
3816 id = AV_CODEC_ID_ADPCM_YAMAHA;
3817 } else if (!strcmp (layout, "sbpro2")) {
3818 id = AV_CODEC_ID_ADPCM_SBPRO_2;
3819 } else if (!strcmp (layout, "sbpro3")) {
3820 id = AV_CODEC_ID_ADPCM_SBPRO_3;
3821 } else if (!strcmp (layout, "sbpro4")) {
3822 id = AV_CODEC_ID_ADPCM_SBPRO_4;
3824 if (id != AV_CODEC_ID_NONE)
3826 } else if (!strcmp (mimetype, "video/x-4xm")) {
3827 id = AV_CODEC_ID_4XM;
3829 } else if (!strcmp (mimetype, "audio/x-dpcm")) {
3830 const gchar *layout;
3832 layout = gst_structure_get_string (structure, "layout");
3835 } else if (!strcmp (layout, "roq")) {
3836 id = AV_CODEC_ID_ROQ_DPCM;
3837 } else if (!strcmp (layout, "interplay")) {
3838 id = AV_CODEC_ID_INTERPLAY_DPCM;
3839 } else if (!strcmp (layout, "xan")) {
3840 id = AV_CODEC_ID_XAN_DPCM;
3841 } else if (!strcmp (layout, "sol")) {
3842 id = AV_CODEC_ID_SOL_DPCM;
3844 if (id != AV_CODEC_ID_NONE)
3846 } else if (!strcmp (mimetype, "audio/x-flac")) {
3847 id = AV_CODEC_ID_FLAC;
3849 } else if (!strcmp (mimetype, "audio/x-shorten")) {
3850 id = AV_CODEC_ID_SHORTEN;
3852 } else if (!strcmp (mimetype, "audio/x-alac")) {
3853 id = AV_CODEC_ID_ALAC;
3855 } else if (!strcmp (mimetype, "video/x-cinepak")) {
3856 id = AV_CODEC_ID_CINEPAK;
3858 } else if (!strcmp (mimetype, "video/x-pn-realvideo")) {
3861 if (gst_structure_get_int (structure, "rmversion", &rmversion)) {
3862 switch (rmversion) {
3864 id = AV_CODEC_ID_RV10;
3867 id = AV_CODEC_ID_RV20;
3870 id = AV_CODEC_ID_RV30;
3873 id = AV_CODEC_ID_RV40;
3877 if (id != AV_CODEC_ID_NONE)
3879 } else if (!strcmp (mimetype, "audio/x-sipro")) {
3880 id = AV_CODEC_ID_SIPR;
3882 } else if (!strcmp (mimetype, "audio/x-pn-realaudio")) {
3885 if (gst_structure_get_int (structure, "raversion", &raversion)) {
3886 switch (raversion) {
3888 id = AV_CODEC_ID_RA_144;
3891 id = AV_CODEC_ID_RA_288;
3894 id = AV_CODEC_ID_COOK;
3898 if (id != AV_CODEC_ID_NONE)
3900 } else if (!strcmp (mimetype, "video/x-rle")) {
3901 const gchar *layout;
3903 if ((layout = gst_structure_get_string (structure, "layout"))) {
3904 if (!strcmp (layout, "microsoft")) {
3905 id = AV_CODEC_ID_MSRLE;
3909 } else if (!strcmp (mimetype, "video/x-xan")) {
3912 if ((gst_structure_get_int (structure, "wcversion", &wcversion))) {
3913 switch (wcversion) {
3915 id = AV_CODEC_ID_XAN_WC3;
3919 id = AV_CODEC_ID_XAN_WC4;
3926 } else if (!strcmp (mimetype, "audio/AMR")) {
3928 id = AV_CODEC_ID_AMR_NB;
3929 } else if (!strcmp (mimetype, "audio/AMR-WB")) {
3930 id = AV_CODEC_ID_AMR_WB;
3932 } else if (!strcmp (mimetype, "audio/qcelp")) {
3933 id = AV_CODEC_ID_QCELP;
3935 } else if (!strcmp (mimetype, "video/x-h264")) {
3936 id = AV_CODEC_ID_H264;
3938 } else if (!strcmp (mimetype, "video/x-h265")) {
3939 id = AV_CODEC_ID_HEVC;
3941 } else if (!strcmp (mimetype, "video/x-flash-video")) {
3942 gint flvversion = 0;
3944 if ((gst_structure_get_int (structure, "flvversion", &flvversion))) {
3945 switch (flvversion) {
3947 id = AV_CODEC_ID_FLV1;
3955 } else if (!strcmp (mimetype, "audio/x-nellymoser")) {
3956 id = AV_CODEC_ID_NELLYMOSER;
3958 } else if (!strncmp (mimetype, "audio/x-gst-av-", 15)) {
3962 if (strlen (mimetype) <= 30 &&
3963 sscanf (mimetype, "audio/x-gst-av-%s", ext) == 1) {
3964 if ((codec = avcodec_find_decoder_by_name (ext)) ||
3965 (codec = avcodec_find_encoder_by_name (ext))) {
3970 } else if (!strncmp (mimetype, "video/x-gst-av-", 15)) {
3974 if (strlen (mimetype) <= 30 &&
3975 sscanf (mimetype, "video/x-gst-av-%s", ext) == 1) {
3976 if ((codec = avcodec_find_decoder_by_name (ext)) ||
3977 (codec = avcodec_find_encoder_by_name (ext))) {
3984 if (context != NULL) {
3985 if (video == TRUE) {
3986 context->codec_type = AVMEDIA_TYPE_VIDEO;
3987 } else if (audio == TRUE) {
3988 context->codec_type = AVMEDIA_TYPE_AUDIO;
3990 context->codec_type = AVMEDIA_TYPE_UNKNOWN;
3992 context->codec_id = id;
3993 gst_ffmpeg_caps_with_codecid (id, context->codec_type, caps, context);
3996 if (id != AV_CODEC_ID_NONE) {
3997 GST_DEBUG ("The id=%d belongs to the caps %" GST_PTR_FORMAT, id, caps);
3999 GST_WARNING ("Couldn't figure out the id for caps %" GST_PTR_FORMAT, caps);