2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
4 * Copyright (c) 2002-2004 Ronald Bultje <rbultje@ronald.bitfreak.net>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
29 #include <libavcodec/avcodec.h>
30 #include <libavutil/channel_layout.h>
33 #include "gstavcodecmap.h"
35 #include <gst/video/video.h>
36 #include <gst/audio/audio.h>
37 #include <gst/pbutils/codec-utils.h>
39 /* IMPORTANT: Keep this sorted by the ffmpeg channel masks */
43 GstAudioChannelPosition gst;
44 } _ff_to_gst_layout[] = {
46 AV_CH_FRONT_LEFT, GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT}, {
47 AV_CH_FRONT_RIGHT, GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT}, {
48 AV_CH_FRONT_CENTER, GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER}, {
49 AV_CH_LOW_FREQUENCY, GST_AUDIO_CHANNEL_POSITION_LFE1}, {
50 AV_CH_BACK_LEFT, GST_AUDIO_CHANNEL_POSITION_REAR_LEFT}, {
51 AV_CH_BACK_RIGHT, GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT}, {
52 AV_CH_FRONT_LEFT_OF_CENTER, GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER}, {
53 AV_CH_FRONT_RIGHT_OF_CENTER,
54 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER}, {
55 AV_CH_BACK_CENTER, GST_AUDIO_CHANNEL_POSITION_REAR_CENTER}, {
56 AV_CH_SIDE_LEFT, GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT}, {
57 AV_CH_SIDE_RIGHT, GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT}, {
58 AV_CH_TOP_CENTER, GST_AUDIO_CHANNEL_POSITION_TOP_CENTER}, {
59 AV_CH_TOP_FRONT_LEFT, GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_LEFT}, {
60 AV_CH_TOP_FRONT_CENTER, GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_CENTER}, {
61 AV_CH_TOP_FRONT_RIGHT, GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_RIGHT}, {
62 AV_CH_TOP_BACK_LEFT, GST_AUDIO_CHANNEL_POSITION_TOP_REAR_LEFT}, {
63 AV_CH_TOP_BACK_CENTER, GST_AUDIO_CHANNEL_POSITION_TOP_REAR_CENTER}, {
64 AV_CH_TOP_BACK_RIGHT, GST_AUDIO_CHANNEL_POSITION_TOP_REAR_RIGHT}, {
65 AV_CH_STEREO_LEFT, GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT}, {
66 AV_CH_STEREO_RIGHT, GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT}
70 gst_ffmpeg_compliance_get_type (void)
72 static GType ffmpeg_compliance_type = 0;
73 static const GEnumValue compliance_types[] = {
74 {GST_FFMPEG_VERY_STRICT, "Strictly conform to older spec",
76 {GST_FFMPEG_STRICT, "Strictly conform to current spec", "strict"},
77 {GST_FFMPEG_NORMAL, "Normal behavior", "normal"},
78 {GST_FFMPEG_UNOFFICIAL, "Allow unofficial extensions", "unofficial"},
79 {GST_FFMPEG_EXPERIMENTAL, "Allow nonstandardized experimental things",
84 if (!ffmpeg_compliance_type) {
85 ffmpeg_compliance_type =
86 g_enum_register_static ("GstFFMpegCompliance", compliance_types);
88 return ffmpeg_compliance_type;
92 gst_ffmpeg_channel_positions_to_layout (GstAudioChannelPosition * pos,
97 gint channels_found = 0;
102 for (i = 0; i < channels; i++) {
103 for (j = 0; j < G_N_ELEMENTS (_ff_to_gst_layout); j++) {
104 if (_ff_to_gst_layout[j].gst == pos[i]) {
105 ret |= _ff_to_gst_layout[j].ff;
112 if (channels_found != channels)
118 gst_ffmpeg_channel_layout_to_gst (guint64 channel_layout, gint channels,
119 GstAudioChannelPosition * pos)
122 gboolean none_layout = FALSE;
124 if (channel_layout == 0) {
125 nchannels = channels;
130 for (i = 0; i < 64; i++) {
131 if ((channel_layout & (G_GUINT64_CONSTANT (1) << i)) != 0) {
136 if (nchannels != channels) {
137 GST_ERROR ("Number of channels is different (%u != %u)", channels,
139 nchannels = channels;
143 for (i = 0, j = 0; i < G_N_ELEMENTS (_ff_to_gst_layout); i++) {
144 if ((channel_layout & _ff_to_gst_layout[i].ff) != 0) {
145 pos[j++] = _ff_to_gst_layout[i].gst;
147 if (_ff_to_gst_layout[i].gst == GST_AUDIO_CHANNEL_POSITION_NONE)
152 if (j != nchannels) {
154 ("Unknown channels in channel layout - assuming NONE layout");
161 && !gst_audio_check_valid_channel_positions (pos, nchannels, FALSE)) {
162 GST_ERROR ("Invalid channel layout %" G_GUINT64_FORMAT
163 " - assuming NONE layout", channel_layout);
168 if (nchannels == 1) {
169 pos[0] = GST_AUDIO_CHANNEL_POSITION_MONO;
170 } else if (nchannels == 2) {
171 pos[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT;
172 pos[1] = GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT;
176 for (i = 0; i < nchannels; i++)
177 pos[i] = GST_AUDIO_CHANNEL_POSITION_NONE;
185 _gst_value_list_contains (const GValue * list, const GValue * value)
190 n = gst_value_list_get_size (list);
191 for (i = 0; i < n; i++) {
192 tmp = gst_value_list_get_value (list, i);
193 if (gst_value_compare (value, tmp) == GST_VALUE_EQUAL)
201 gst_ffmpeg_video_set_pix_fmts (GstCaps * caps, const enum AVPixelFormat *fmts)
205 GstVideoFormat format;
207 if (!fmts || fmts[0] == -1) {
210 g_value_init (&va, GST_TYPE_LIST);
211 g_value_init (&v, G_TYPE_STRING);
212 for (i = 0; i <= PIX_FMT_NB; i++) {
213 format = gst_ffmpeg_pixfmt_to_videoformat (i);
214 if (format == GST_VIDEO_FORMAT_UNKNOWN)
216 g_value_set_string (&v, gst_video_format_to_string (format));
217 gst_value_list_append_value (&va, &v);
219 gst_caps_set_value (caps, "format", &va);
225 /* Only a single format */
226 g_value_init (&va, GST_TYPE_LIST);
227 g_value_init (&v, G_TYPE_STRING);
228 while (*fmts != -1) {
229 format = gst_ffmpeg_pixfmt_to_videoformat (*fmts);
230 if (format != GST_VIDEO_FORMAT_UNKNOWN) {
231 g_value_set_string (&v, gst_video_format_to_string (format));
232 /* Only append values we don't have yet */
233 if (!_gst_value_list_contains (&va, &v))
234 gst_value_list_append_value (&va, &v);
238 if (gst_value_list_get_size (&va) == 1) {
239 /* The single value is still in v */
240 gst_caps_set_value (caps, "format", &v);
241 } else if (gst_value_list_get_size (&va) > 1) {
242 gst_caps_set_value (caps, "format", &va);
248 /* this macro makes a caps width fixed or unfixed width/height
249 * properties depending on whether we've got a context.
251 * See below for why we use this.
253 * We should actually do this stuff at the end, like in riff-media.c,
254 * but I'm too lazy today. Maybe later.
257 gst_ff_vid_caps_new (AVCodecContext * context, AVCodec * codec,
258 enum AVCodecID codec_id, gboolean encode, const char *mimetype,
259 const char *fieldname, ...)
261 GstCaps *caps = NULL;
265 GST_LOG ("context:%p, codec_id:%d, mimetype:%s", context, codec_id, mimetype);
267 /* fixed, non probing context */
268 if (context != NULL && context->width != -1) {
271 caps = gst_caps_new_simple (mimetype,
272 "width", G_TYPE_INT, context->width,
273 "height", G_TYPE_INT, context->height, NULL);
275 num = context->time_base.den / context->ticks_per_frame;
276 denom = context->time_base.num;
279 GST_LOG ("invalid framerate: %d/0, -> %d/1", num, num);
282 if (gst_util_fraction_compare (num, denom, 1000, 1) > 0) {
283 GST_LOG ("excessive framerate: %d/%d, -> 0/1", num, denom);
287 GST_LOG ("setting framerate: %d/%d", num, denom);
288 gst_caps_set_simple (caps,
289 "framerate", GST_TYPE_FRACTION, num, denom, NULL);
291 /* so we are after restricted caps in this case */
293 case AV_CODEC_ID_H261:
295 caps = gst_caps_new_simple (mimetype,
296 "width", G_TYPE_INT, 352,
297 "height", G_TYPE_INT, 288,
298 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
299 gst_caps_append (caps, gst_caps_new_simple (mimetype,
300 "width", G_TYPE_INT, 176,
301 "height", G_TYPE_INT, 144,
302 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL));
305 case AV_CODEC_ID_H263:
307 /* 128x96, 176x144, 352x288, 704x576, and 1408x1152. slightly reordered
308 * because we want automatic negotiation to go as close to 320x240 as
310 const static gint widths[] = { 352, 704, 176, 1408, 128 };
311 const static gint heights[] = { 288, 576, 144, 1152, 96 };
313 gint n_sizes = G_N_ELEMENTS (widths);
315 caps = gst_caps_new_empty ();
316 for (i = 0; i < n_sizes; i++) {
317 temp = gst_caps_new_simple (mimetype,
318 "width", G_TYPE_INT, widths[i],
319 "height", G_TYPE_INT, heights[i],
320 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
322 gst_caps_append (caps, temp);
326 case AV_CODEC_ID_DVVIDEO:
333 gint framerate_n, framerate_d;
336 "Y41B", 720, 480, 8, 9, 30000, 1001}, {
337 "Y41B", 720, 480, 32, 27, 30000, 1001}, {
338 "Y42B", 720, 480, 8, 9, 30000, 1001}, {
339 "Y42B", 720, 480, 32, 27, 30000, 1001}, {
340 "I420", 720, 576, 16, 15, 25, 1}, {
341 "I420", 720, 576, 64, 45, 25, 1}, {
342 "Y41B", 720, 576, 16, 15, 25, 1}, {
343 "Y41B", 720, 576, 64, 45, 25, 1}, {
344 "Y42B", 720, 576, 16, 15, 25, 1}, {
345 "Y42B", 720, 576, 64, 45, 25, 1}, {
346 "Y42B", 1280, 1080, 1, 1, 30000, 1001}, {
347 "Y42B", 1280, 1080, 3, 2, 30000, 1001}, {
348 "Y42B", 1440, 1080, 1, 1, 25, 1}, {
349 "Y42B", 1440, 1080, 4, 3, 25, 1}, {
350 "Y42B", 960, 720, 1, 1, 60000, 1001}, {
351 "Y42B", 960, 720, 4, 3, 60000, 1001}, {
352 "Y42B", 960, 720, 1, 1, 50, 1}, {
353 "Y42B", 960, 720, 4, 3, 50, 1},};
355 gint n_sizes = G_N_ELEMENTS (profiles);
357 if (strcmp (mimetype, "video/x-raw") == 0) {
358 caps = gst_caps_new_empty ();
359 for (i = 0; i < n_sizes; i++) {
360 temp = gst_caps_new_simple (mimetype,
361 "format", G_TYPE_STRING, profiles[i].csp,
362 "width", G_TYPE_INT, profiles[i].width,
363 "height", G_TYPE_INT, profiles[i].height,
364 "framerate", GST_TYPE_FRACTION, profiles[i].framerate_n,
365 profiles[i].framerate_d, "pixel-aspect-ratio",
366 GST_TYPE_FRACTION, profiles[i].par_n, profiles[i].par_d, NULL);
368 gst_caps_append (caps, temp);
371 caps = gst_caps_new_empty ();
372 for (i = 0; i < n_sizes; i++) {
373 temp = gst_caps_new_simple (mimetype,
374 "width", G_TYPE_INT, profiles[i].width,
375 "height", G_TYPE_INT, profiles[i].height,
376 "framerate", GST_TYPE_FRACTION, profiles[i].framerate_n,
377 profiles[i].framerate_d, "pixel-aspect-ratio",
378 GST_TYPE_FRACTION, profiles[i].par_n, profiles[i].par_d, NULL);
380 gst_caps_append (caps, temp);
385 case AV_CODEC_ID_DNXHD:
387 caps = gst_caps_new_simple (mimetype,
388 "width", G_TYPE_INT, 1920,
389 "height", G_TYPE_INT, 1080,
390 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
391 gst_caps_append (caps, gst_caps_new_simple (mimetype,
392 "width", G_TYPE_INT, 1280,
393 "height", G_TYPE_INT, 720,
394 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL));
399 if (codec && codec->supported_framerates
400 && codec->supported_framerates[0].num != 0
401 && codec->supported_framerates[0].den != 0) {
404 const AVRational *rates = codec->supported_framerates;
406 if (rates[1].num == 0 && rates[1].den == 0) {
408 gst_caps_new_simple (mimetype, "framerate", GST_TYPE_FRACTION,
409 rates[0].num, rates[0].den, NULL);
411 g_value_init (&va, GST_TYPE_LIST);
412 g_value_init (&v, GST_TYPE_FRACTION);
414 while (rates->num != 0 && rates->den != 0) {
415 gst_value_set_fraction (&v, rates->num, rates->den);
416 gst_value_list_append_value (&va, &v);
420 caps = gst_caps_new_simple (mimetype, NULL, NULL, NULL);
421 gst_caps_set_value (caps, "framerate", &va);
427 caps = gst_caps_new_empty_simple (mimetype);
435 /* no fixed caps or special restrictions applied;
436 * default unfixed setting */
438 GST_DEBUG ("Creating default caps");
439 caps = gst_caps_new_empty_simple (mimetype);
442 va_start (var_args, fieldname);
443 gst_caps_set_simple_valist (caps, fieldname, var_args);
450 get_nbits_set (guint64 n)
455 for (i = 0; i < 64; i++) {
456 if ((n & (G_GUINT64_CONSTANT (1) << i)))
464 gst_ffmpeg_audio_set_sample_fmts (GstCaps * caps,
465 const enum AVSampleFormat *fmts)
469 GstAudioFormat format;
471 if (!fmts || fmts[0] == -1) {
474 g_value_init (&va, GST_TYPE_LIST);
475 g_value_init (&v, G_TYPE_STRING);
476 for (i = 0; i <= AV_SAMPLE_FMT_DBL; i++) {
477 format = gst_ffmpeg_smpfmt_to_audioformat (i);
478 if (format == GST_AUDIO_FORMAT_UNKNOWN)
480 g_value_set_string (&v, gst_audio_format_to_string (format));
481 gst_value_list_append_value (&va, &v);
483 gst_caps_set_value (caps, "format", &va);
489 g_value_init (&va, GST_TYPE_LIST);
490 g_value_init (&v, G_TYPE_STRING);
491 while (*fmts != -1) {
492 format = gst_ffmpeg_smpfmt_to_audioformat (*fmts);
493 if (format != GST_AUDIO_FORMAT_UNKNOWN) {
494 g_value_set_string (&v, gst_audio_format_to_string (format));
495 /* Only append values we don't have yet */
496 if (!_gst_value_list_contains (&va, &v))
497 gst_value_list_append_value (&va, &v);
501 if (gst_value_list_get_size (&va) == 1) {
502 /* The single value is still in v */
503 gst_caps_set_value (caps, "format", &v);
504 } else if (gst_value_list_get_size (&va) > 1) {
505 gst_caps_set_value (caps, "format", &va);
511 /* same for audio - now with channels/sample rate
514 gst_ff_aud_caps_new (AVCodecContext * context, AVCodec * codec,
515 enum AVCodecID codec_id, gboolean encode, const char *mimetype,
516 const char *fieldname, ...)
518 GstCaps *caps = NULL;
522 /* fixed, non-probing context */
523 if (context != NULL && context->channels != -1) {
524 GstAudioChannelPosition pos[64];
527 caps = gst_caps_new_simple (mimetype,
528 "rate", G_TYPE_INT, context->sample_rate,
529 "channels", G_TYPE_INT, context->channels, NULL);
531 if (context->channels > 1 &&
532 gst_ffmpeg_channel_layout_to_gst (context->channel_layout,
533 context->channels, pos) &&
534 gst_audio_channel_positions_to_mask (pos, context->channels, FALSE,
536 gst_caps_set_simple (caps, "channel-mask", GST_TYPE_BITMASK, mask, NULL);
539 gint maxchannels = 2;
540 const gint *rates = NULL;
543 /* so we must be after restricted caps in this case */
545 case AV_CODEC_ID_AAC:
546 case AV_CODEC_ID_AAC_LATM:
547 case AV_CODEC_ID_DTS:
550 case AV_CODEC_ID_MP2:
552 const static gint l_rates[] =
553 { 48000, 44100, 32000, 24000, 22050, 16000 };
554 n_rates = G_N_ELEMENTS (l_rates);
558 case AV_CODEC_ID_EAC3:
559 case AV_CODEC_ID_AC3:
561 const static gint l_rates[] = { 48000, 44100, 32000 };
563 n_rates = G_N_ELEMENTS (l_rates);
567 case AV_CODEC_ID_ADPCM_G722:
569 const static gint l_rates[] = { 16000 };
570 n_rates = G_N_ELEMENTS (l_rates);
575 case AV_CODEC_ID_ADPCM_G726:
577 const static gint l_rates[] = { 8000 };
578 n_rates = G_N_ELEMENTS (l_rates);
583 case AV_CODEC_ID_ADPCM_SWF:
585 const static gint l_rates[] = { 11025, 22050, 44100 };
586 n_rates = G_N_ELEMENTS (l_rates);
590 case AV_CODEC_ID_ROQ_DPCM:
592 const static gint l_rates[] = { 22050 };
593 n_rates = G_N_ELEMENTS (l_rates);
597 case AV_CODEC_ID_AMR_NB:
599 const static gint l_rates[] = { 8000 };
601 n_rates = G_N_ELEMENTS (l_rates);
605 case AV_CODEC_ID_AMR_WB:
607 const static gint l_rates[] = { 16000 };
609 n_rates = G_N_ELEMENTS (l_rates);
617 /* regardless of encode/decode, open up channels if applicable */
618 /* Until decoders/encoders expose the maximum number of channels
619 * they support, we whitelist them here. */
621 case AV_CODEC_ID_WMAPRO:
622 case AV_CODEC_ID_TRUEHD:
629 if (codec && codec->channel_layouts) {
630 const uint64_t *layouts = codec->channel_layouts;
631 GstAudioChannelPosition pos[64];
633 caps = gst_caps_new_empty ();
635 gint nbits_set = get_nbits_set (*layouts);
637 if (gst_ffmpeg_channel_layout_to_gst (*layouts, nbits_set, pos)) {
640 if (gst_audio_channel_positions_to_mask (pos, nbits_set, FALSE,
643 gst_caps_new_simple (mimetype, "channel-mask", GST_TYPE_BITMASK,
645 "channels", G_TYPE_INT, nbits_set, NULL);
647 gst_caps_append (caps, tmp);
653 if (maxchannels == 1)
654 caps = gst_caps_new_simple (mimetype,
655 "channels", G_TYPE_INT, maxchannels, NULL);
657 caps = gst_caps_new_simple (mimetype,
658 "channels", GST_TYPE_INT_RANGE, 1, maxchannels, NULL);
662 GValue list = { 0, };
664 g_value_init (&list, GST_TYPE_LIST);
665 for (i = 0; i < n_rates; i++) {
668 g_value_init (&v, G_TYPE_INT);
669 g_value_set_int (&v, rates[i]);
670 gst_value_list_append_value (&list, &v);
673 gst_caps_set_value (caps, "rate", &list);
674 g_value_unset (&list);
675 } else if (codec && codec->supported_samplerates
676 && codec->supported_samplerates[0]) {
680 if (!codec->supported_samplerates[1]) {
681 gst_caps_set_simple (caps, "rate", G_TYPE_INT,
682 codec->supported_samplerates[0], NULL);
684 const int *rates = codec->supported_samplerates;
686 g_value_init (&va, GST_TYPE_LIST);
687 g_value_init (&v, G_TYPE_INT);
690 g_value_set_int (&v, *rates);
691 gst_value_list_append_value (&va, &v);
694 gst_caps_set_value (caps, "rate", &va);
699 gst_caps_set_simple (caps, "rate", GST_TYPE_INT_RANGE, 4000, 96000, NULL);
702 caps = gst_caps_new_empty_simple (mimetype);
705 va_start (var_args, fieldname);
706 gst_caps_set_simple_valist (caps, fieldname, var_args);
712 /* Convert a FFMPEG codec ID and optional AVCodecContext
713 * to a GstCaps. If the context is ommitted, no fixed values
714 * for video/audio size will be included in the GstCaps
716 * CodecID is primarily meant for compressed data GstCaps!
718 * encode is a special parameter. gstffmpegdec will say
719 * FALSE, gstffmpegenc will say TRUE. The output caps
720 * depends on this, in such a way that it will be very
721 * specific, defined, fixed and correct caps for encoders,
722 * yet very wide, "forgiving" caps for decoders. Example
723 * for mp3: decode: audio/mpeg,mpegversion=1,layer=[1-3]
724 * but encode: audio/mpeg,mpegversion=1,layer=3,bitrate=x,
729 gst_ffmpeg_codecid_to_caps (enum AVCodecID codec_id,
730 AVCodecContext * context, gboolean encode)
732 GstCaps *caps = NULL;
733 gboolean buildcaps = FALSE;
735 GST_LOG ("codec_id:%d, context:%p, encode:%d", codec_id, context, encode);
738 case AV_CODEC_ID_MPEG1VIDEO:
740 caps = gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
741 "mpegversion", G_TYPE_INT, 1,
742 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
745 case AV_CODEC_ID_MPEG2VIDEO:
749 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
750 "mpegversion", G_TYPE_INT, 2, "systemstream", G_TYPE_BOOLEAN, FALSE,
753 /* decode both MPEG-1 and MPEG-2; width/height/fps are all in
754 * the MPEG video stream headers, so may be omitted from caps. */
755 caps = gst_caps_new_simple ("video/mpeg",
756 "mpegversion", GST_TYPE_INT_RANGE, 1, 2,
757 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
761 case AV_CODEC_ID_MPEG2VIDEO_XVMC:
762 /* this is a special ID - don't need it in GStreamer, I think */
765 case AV_CODEC_ID_H263:
768 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
769 "video/x-h263", "variant", G_TYPE_STRING, "itu", "h263version",
770 G_TYPE_STRING, "h263", NULL);
772 /* don't pass codec_id, we can decode other variants with the H263
773 * decoder that don't have specific size requirements
776 gst_ff_vid_caps_new (context, NULL, AV_CODEC_ID_NONE, encode,
777 "video/x-h263", "variant", G_TYPE_STRING, "itu", NULL);
781 case AV_CODEC_ID_H263P:
783 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h263",
784 "variant", G_TYPE_STRING, "itu", "h263version", G_TYPE_STRING,
786 if (encode && context) {
788 gst_caps_set_simple (caps,
789 "annex-f", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_4MV,
790 "annex-j", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_LOOP_FILTER,
791 "annex-i", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_AC_PRED,
792 "annex-t", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_AC_PRED,
797 case AV_CODEC_ID_H263I:
799 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
800 "video/x-intel-h263", "variant", G_TYPE_STRING, "intel", NULL);
803 case AV_CODEC_ID_H261:
805 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h261",
809 case AV_CODEC_ID_RV10:
810 case AV_CODEC_ID_RV20:
811 case AV_CODEC_ID_RV30:
812 case AV_CODEC_ID_RV40:
817 case AV_CODEC_ID_RV40:
820 case AV_CODEC_ID_RV30:
823 case AV_CODEC_ID_RV20:
832 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
833 "video/x-pn-realvideo", "rmversion", G_TYPE_INT, version, NULL);
835 if (context->extradata_size >= 8) {
836 gst_caps_set_simple (caps,
837 "subformat", G_TYPE_INT, GST_READ_UINT32_BE (context->extradata),
844 case AV_CODEC_ID_MP1:
846 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
847 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 1, NULL);
850 case AV_CODEC_ID_MP2:
852 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
853 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 2, NULL);
856 case AV_CODEC_ID_MP3:
860 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
861 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 3, NULL);
863 /* Decodes MPEG-1 layer 1/2/3. Samplerate, channels et al are
864 * in the MPEG audio header, so may be omitted from caps. */
865 caps = gst_caps_new_simple ("audio/mpeg",
866 "mpegversion", G_TYPE_INT, 1,
867 "layer", GST_TYPE_INT_RANGE, 1, 3, NULL);
871 case AV_CODEC_ID_MUSEPACK7:
873 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
874 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 7,
878 case AV_CODEC_ID_MUSEPACK8:
880 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
881 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 8,
885 case AV_CODEC_ID_AC3:
888 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-ac3",
892 case AV_CODEC_ID_EAC3:
895 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-eac3",
899 case AV_CODEC_ID_TRUEHD:
901 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
902 "audio/x-true-hd", NULL);
905 case AV_CODEC_ID_ATRAC1:
907 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
908 "audio/x-vnd.sony.atrac1", NULL);
911 case AV_CODEC_ID_ATRAC3:
913 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
914 "audio/x-vnd.sony.atrac3", NULL);
917 case AV_CODEC_ID_DTS:
919 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dts",
923 case AV_CODEC_ID_APE:
925 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
926 "audio/x-ffmpeg-parsed-ape", NULL);
928 gst_caps_set_simple (caps,
929 "depth", G_TYPE_INT, context->bits_per_coded_sample, NULL);
933 case AV_CODEC_ID_MLP:
935 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mlp",
939 case AV_CODEC_ID_IMC:
941 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-imc",
945 /* MJPEG is normal JPEG, Motion-JPEG and Quicktime MJPEG-A. MJPEGB
946 * is Quicktime's MJPEG-B. LJPEG is lossless JPEG. I don't know what
947 * sp5x is, but it's apparently something JPEG... We don't separate
948 * between those in GStreamer. Should we (at least between MJPEG,
949 * MJPEG-B and sp5x decoding...)? */
950 case AV_CODEC_ID_MJPEG:
951 case AV_CODEC_ID_LJPEG:
953 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/jpeg",
954 "parsed", G_TYPE_BOOLEAN, TRUE, NULL);
957 case AV_CODEC_ID_SP5X:
959 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/sp5x",
963 case AV_CODEC_ID_MJPEGB:
965 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
966 "video/x-mjpeg-b", NULL);
969 case AV_CODEC_ID_MPEG4:
970 if (encode && context != NULL) {
971 /* I'm not exactly sure what ffmpeg outputs... ffmpeg itself uses
972 * the AVI fourcc 'DIVX', but 'mp4v' for Quicktime... */
973 switch (context->codec_tag) {
974 case GST_MAKE_FOURCC ('D', 'I', 'V', 'X'):
976 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
977 "video/x-divx", "divxversion", G_TYPE_INT, 5, NULL);
979 case GST_MAKE_FOURCC ('m', 'p', '4', 'v'):
983 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
984 "video/mpeg", "systemstream", G_TYPE_BOOLEAN, FALSE,
985 "mpegversion", G_TYPE_INT, 4, NULL);
989 /* The trick here is to separate xvid, divx, mpeg4, 3ivx et al */
991 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
992 "mpegversion", G_TYPE_INT, 4, "systemstream", G_TYPE_BOOLEAN, FALSE,
995 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
996 encode, "video/x-divx", "divxversion", G_TYPE_INT, 5, NULL));
998 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
999 encode, "video/x-divx", "divxversion", GST_TYPE_INT_RANGE, 4,
1001 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
1002 encode, "video/x-xvid", NULL));
1003 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
1004 encode, "video/x-3ivx", NULL));
1009 case AV_CODEC_ID_RAWVIDEO:
1011 gst_ffmpeg_codectype_to_video_caps (context, codec_id, encode, NULL);
1014 case AV_CODEC_ID_MSMPEG4V1:
1015 case AV_CODEC_ID_MSMPEG4V2:
1016 case AV_CODEC_ID_MSMPEG4V3:
1018 gint version = 41 + codec_id - AV_CODEC_ID_MSMPEG4V1;
1020 /* encode-FIXME: bitrate */
1022 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1023 "video/x-msmpeg", "msmpegversion", G_TYPE_INT, version, NULL);
1024 if (!encode && codec_id == AV_CODEC_ID_MSMPEG4V3) {
1025 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
1026 encode, "video/x-divx", "divxversion", G_TYPE_INT, 3, NULL));
1031 case AV_CODEC_ID_WMV1:
1032 case AV_CODEC_ID_WMV2:
1034 gint version = (codec_id == AV_CODEC_ID_WMV1) ? 1 : 2;
1037 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1038 "wmvversion", G_TYPE_INT, version, NULL);
1042 case AV_CODEC_ID_FLV1:
1044 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1045 "video/x-flash-video", "flvversion", G_TYPE_INT, 1, NULL);
1048 case AV_CODEC_ID_SVQ1:
1050 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-svq",
1051 "svqversion", G_TYPE_INT, 1, NULL);
1054 case AV_CODEC_ID_SVQ3:
1056 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-svq",
1057 "svqversion", G_TYPE_INT, 3, NULL);
1060 case AV_CODEC_ID_DVAUDIO:
1062 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dv",
1066 case AV_CODEC_ID_DVVIDEO:
1068 if (encode && context) {
1069 const gchar *format;
1071 switch (context->pix_fmt) {
1072 case PIX_FMT_YUYV422:
1075 case PIX_FMT_YUV420P:
1078 case PIX_FMT_YUVA420P:
1081 case PIX_FMT_YUV411P:
1084 case PIX_FMT_YUV422P:
1087 case PIX_FMT_YUV410P:
1092 ("Couldnt' find format for pixfmt %d, defaulting to I420",
1098 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dv",
1099 "systemstream", G_TYPE_BOOLEAN, FALSE, "format", G_TYPE_STRING,
1103 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dv",
1104 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
1109 case AV_CODEC_ID_WMAV1:
1110 case AV_CODEC_ID_WMAV2:
1112 gint version = (codec_id == AV_CODEC_ID_WMAV1) ? 1 : 2;
1116 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1117 "wmaversion", G_TYPE_INT, version, "block_align", G_TYPE_INT,
1118 context->block_align, "bitrate", G_TYPE_INT, context->bit_rate,
1122 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1123 "wmaversion", G_TYPE_INT, version, "block_align",
1124 GST_TYPE_INT_RANGE, 0, G_MAXINT, "bitrate", GST_TYPE_INT_RANGE, 0,
1129 case AV_CODEC_ID_WMAPRO:
1132 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1133 "wmaversion", G_TYPE_INT, 3, NULL);
1136 case AV_CODEC_ID_WMALOSSLESS:
1138 /* libav only supports a depth of 16 at the moment */
1140 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1141 "wmaversion", G_TYPE_INT, 4, "depth", G_TYPE_INT, 16, NULL);
1144 case AV_CODEC_ID_WMAVOICE:
1147 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wms",
1152 case AV_CODEC_ID_MACE3:
1153 case AV_CODEC_ID_MACE6:
1155 gint version = (codec_id == AV_CODEC_ID_MACE3) ? 3 : 6;
1158 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mace",
1159 "maceversion", G_TYPE_INT, version, NULL);
1163 case AV_CODEC_ID_HUFFYUV:
1165 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1166 "video/x-huffyuv", NULL);
1168 gst_caps_set_simple (caps,
1169 "bpp", G_TYPE_INT, context->bits_per_coded_sample, NULL);
1173 case AV_CODEC_ID_CYUV:
1175 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1176 "video/x-compressed-yuv", NULL);
1179 case AV_CODEC_ID_H264:
1181 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h264",
1182 "alignment", G_TYPE_STRING, "au", NULL);
1184 GValue arr = { 0, };
1185 GValue item = { 0, };
1186 g_value_init (&arr, GST_TYPE_LIST);
1187 g_value_init (&item, G_TYPE_STRING);
1188 g_value_set_string (&item, "avc");
1189 gst_value_list_append_value (&arr, &item);
1190 g_value_set_string (&item, "byte-stream");
1191 gst_value_list_append_value (&arr, &item);
1192 g_value_unset (&item);
1193 gst_caps_set_value (caps, "stream-format", &arr);
1194 g_value_unset (&arr);
1198 case AV_CODEC_ID_HEVC:
1200 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h265",
1201 "alignment", G_TYPE_STRING, "au", NULL);
1203 GValue arr = { 0, };
1204 GValue item = { 0, };
1205 g_value_init (&arr, GST_TYPE_LIST);
1206 g_value_init (&item, G_TYPE_STRING);
1207 g_value_set_string (&item, "hvc1");
1208 gst_value_list_append_value (&arr, &item);
1209 g_value_set_string (&item, "hev1");
1210 gst_value_list_append_value (&arr, &item);
1211 g_value_set_string (&item, "byte-stream");
1212 gst_value_list_append_value (&arr, &item);
1213 g_value_unset (&item);
1214 gst_caps_set_value (caps, "stream-format", &arr);
1215 g_value_unset (&arr);
1219 case AV_CODEC_ID_INDEO5:
1221 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1222 "indeoversion", G_TYPE_INT, 5, NULL);
1225 case AV_CODEC_ID_INDEO4:
1227 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1228 "indeoversion", G_TYPE_INT, 4, NULL);
1231 case AV_CODEC_ID_INDEO3:
1233 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1234 "indeoversion", G_TYPE_INT, 3, NULL);
1237 case AV_CODEC_ID_INDEO2:
1239 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1240 "indeoversion", G_TYPE_INT, 2, NULL);
1243 case AV_CODEC_ID_FLASHSV:
1245 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1246 "video/x-flash-screen", NULL);
1249 case AV_CODEC_ID_VP3:
1251 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp3",
1255 case AV_CODEC_ID_VP5:
1257 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp5",
1261 case AV_CODEC_ID_VP6:
1263 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp6",
1267 case AV_CODEC_ID_VP6F:
1269 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1270 "video/x-vp6-flash", NULL);
1273 case AV_CODEC_ID_VP6A:
1275 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1276 "video/x-vp6-alpha", NULL);
1279 case AV_CODEC_ID_VP8:
1281 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp8",
1285 case AV_CODEC_ID_THEORA:
1287 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1288 "video/x-theora", NULL);
1291 case AV_CODEC_ID_AAC:
1294 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
1298 GValue arr = { 0, };
1299 GValue item = { 0, };
1301 g_value_init (&arr, GST_TYPE_LIST);
1302 g_value_init (&item, G_TYPE_INT);
1303 g_value_set_int (&item, 2);
1304 gst_value_list_append_value (&arr, &item);
1305 g_value_set_int (&item, 4);
1306 gst_value_list_append_value (&arr, &item);
1307 g_value_unset (&item);
1309 gst_caps_set_value (caps, "mpegversion", &arr);
1310 g_value_unset (&arr);
1312 g_value_init (&arr, GST_TYPE_LIST);
1313 g_value_init (&item, G_TYPE_STRING);
1314 g_value_set_string (&item, "raw");
1315 gst_value_list_append_value (&arr, &item);
1316 g_value_set_string (&item, "adts");
1317 gst_value_list_append_value (&arr, &item);
1318 g_value_set_string (&item, "adif");
1319 gst_value_list_append_value (&arr, &item);
1320 g_value_unset (&item);
1322 gst_caps_set_value (caps, "stream-format", &arr);
1323 g_value_unset (&arr);
1325 gst_caps_set_simple (caps, "mpegversion", G_TYPE_INT, 4,
1326 "stream-format", G_TYPE_STRING, "raw",
1327 "base-profile", G_TYPE_STRING, "lc", NULL);
1329 if (context && context->extradata_size > 0)
1330 gst_codec_utils_aac_caps_set_level_and_profile (caps,
1331 context->extradata, context->extradata_size);
1336 case AV_CODEC_ID_AAC_LATM: /* LATM/LOAS AAC syntax */
1337 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
1338 "mpegversion", G_TYPE_INT, 4, "stream-format", G_TYPE_STRING, "loas",
1342 case AV_CODEC_ID_ASV1:
1344 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-asus",
1345 "asusversion", G_TYPE_INT, 1, NULL);
1347 case AV_CODEC_ID_ASV2:
1349 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-asus",
1350 "asusversion", G_TYPE_INT, 2, NULL);
1353 case AV_CODEC_ID_FFV1:
1355 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-ffv",
1356 "ffvversion", G_TYPE_INT, 1, NULL);
1359 case AV_CODEC_ID_4XM:
1361 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-4xm",
1365 case AV_CODEC_ID_XAN_WC3:
1366 case AV_CODEC_ID_XAN_WC4:
1368 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-xan",
1369 "wcversion", G_TYPE_INT, 3 - AV_CODEC_ID_XAN_WC3 + codec_id, NULL);
1372 case AV_CODEC_ID_CLJR:
1374 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1375 "video/x-cirrus-logic-accupak", NULL);
1378 case AV_CODEC_ID_FRAPS:
1380 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-fraps",
1384 case AV_CODEC_ID_MDEC:
1385 case AV_CODEC_ID_ROQ:
1386 case AV_CODEC_ID_INTERPLAY_VIDEO:
1390 case AV_CODEC_ID_VCR1:
1392 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1393 "video/x-ati-vcr", "vcrversion", G_TYPE_INT, 1, NULL);
1396 case AV_CODEC_ID_RPZA:
1398 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1399 "video/x-apple-video", NULL);
1402 case AV_CODEC_ID_CINEPAK:
1404 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1405 "video/x-cinepak", NULL);
1408 /* WS_VQA belogns here (order) */
1410 case AV_CODEC_ID_MSRLE:
1412 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-rle",
1413 "layout", G_TYPE_STRING, "microsoft", NULL);
1415 gst_caps_set_simple (caps,
1416 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1418 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1422 case AV_CODEC_ID_QTRLE:
1424 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-rle",
1425 "layout", G_TYPE_STRING, "quicktime", NULL);
1427 gst_caps_set_simple (caps,
1428 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1430 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1434 case AV_CODEC_ID_MSVIDEO1:
1436 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1437 "video/x-msvideocodec", "msvideoversion", G_TYPE_INT, 1, NULL);
1440 case AV_CODEC_ID_MSS1:
1442 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1443 "wmvversion", G_TYPE_INT, 1, "format", G_TYPE_STRING, "MSS1", NULL);
1446 case AV_CODEC_ID_MSS2:
1448 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1449 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "MSS2", NULL);
1452 case AV_CODEC_ID_WMV3:
1454 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1455 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "WMV3", NULL);
1457 case AV_CODEC_ID_VC1:
1459 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1460 "wmvversion", G_TYPE_INT, 3, NULL);
1461 if (!context && !encode) {
1462 GValue arr = { 0, };
1463 GValue item = { 0, };
1465 g_value_init (&arr, GST_TYPE_LIST);
1466 g_value_init (&item, G_TYPE_STRING);
1467 g_value_set_string (&item, "WVC1");
1468 gst_value_list_append_value (&arr, &item);
1469 g_value_set_string (&item, "WMVA");
1470 gst_value_list_append_and_take_value (&arr, &item);
1471 gst_caps_set_value (caps, "format", &arr);
1472 g_value_unset (&arr);
1474 gst_caps_set_simple (caps, "format", G_TYPE_STRING, "WVC1", NULL);
1477 case AV_CODEC_ID_QDM2:
1479 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-qdm2",
1483 case AV_CODEC_ID_MSZH:
1485 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-mszh",
1489 case AV_CODEC_ID_ZLIB:
1491 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-zlib",
1495 case AV_CODEC_ID_TRUEMOTION1:
1497 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1498 "video/x-truemotion", "trueversion", G_TYPE_INT, 1, NULL);
1500 case AV_CODEC_ID_TRUEMOTION2:
1502 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1503 "video/x-truemotion", "trueversion", G_TYPE_INT, 2, NULL);
1506 case AV_CODEC_ID_ULTI:
1508 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1509 "video/x-ultimotion", NULL);
1512 case AV_CODEC_ID_TSCC:
1514 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1515 "video/x-camtasia", NULL);
1517 gst_caps_set_simple (caps,
1518 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1520 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1524 case AV_CODEC_ID_TSCC2:
1526 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1527 "video/x-tscc", "tsccversion", G_TYPE_INT, 2, NULL);
1530 case AV_CODEC_ID_KMVC:
1532 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-kmvc",
1536 case AV_CODEC_ID_NUV:
1538 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-nuv",
1542 case AV_CODEC_ID_GIF:
1544 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/gif",
1548 case AV_CODEC_ID_PNG:
1550 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/png",
1554 case AV_CODEC_ID_PPM:
1556 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/ppm",
1560 case AV_CODEC_ID_PBM:
1562 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/pbm",
1566 case AV_CODEC_ID_PAM:
1568 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1569 "image/x-portable-anymap", NULL);
1572 case AV_CODEC_ID_PGM:
1574 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1575 "image/x-portable-graymap", NULL);
1578 case AV_CODEC_ID_PCX:
1580 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-pcx",
1584 case AV_CODEC_ID_SGI:
1586 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-sgi",
1590 case AV_CODEC_ID_TARGA:
1592 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-tga",
1596 case AV_CODEC_ID_TIFF:
1598 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/tiff",
1602 case AV_CODEC_ID_SUNRAST:
1604 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1605 "image/x-sun-raster", NULL);
1608 case AV_CODEC_ID_SMC:
1610 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-smc",
1614 case AV_CODEC_ID_QDRAW:
1616 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-qdrw",
1620 case AV_CODEC_ID_DNXHD:
1622 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dnxhd",
1626 case AV_CODEC_ID_PRORES:
1628 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1629 "video/x-prores", NULL);
1632 case AV_CODEC_ID_MIMIC:
1634 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-mimic",
1638 case AV_CODEC_ID_VMNC:
1640 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vmnc",
1644 case AV_CODEC_ID_TRUESPEECH:
1646 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1647 "audio/x-truespeech", NULL);
1650 case AV_CODEC_ID_QCELP:
1652 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/qcelp",
1656 case AV_CODEC_ID_AMV:
1658 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-amv",
1662 case AV_CODEC_ID_AASC:
1664 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-aasc",
1668 case AV_CODEC_ID_LOCO:
1670 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-loco",
1674 case AV_CODEC_ID_ZMBV:
1676 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-zmbv",
1680 case AV_CODEC_ID_LAGARITH:
1682 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1683 "video/x-lagarith", NULL);
1686 case AV_CODEC_ID_CSCD:
1688 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1689 "video/x-camstudio", NULL);
1691 gst_caps_set_simple (caps,
1692 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1694 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1698 case AV_CODEC_ID_AIC:
1700 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1701 "video/x-apple-intermediate-codec", NULL);
1704 case AV_CODEC_ID_WS_VQA:
1705 case AV_CODEC_ID_IDCIN:
1706 case AV_CODEC_ID_8BPS:
1707 case AV_CODEC_ID_FLIC:
1708 case AV_CODEC_ID_VMDVIDEO:
1709 case AV_CODEC_ID_VMDAUDIO:
1710 case AV_CODEC_ID_VIXL:
1711 case AV_CODEC_ID_QPEG:
1712 case AV_CODEC_ID_PGMYUV:
1713 case AV_CODEC_ID_FFVHUFF:
1714 case AV_CODEC_ID_WNV1:
1715 case AV_CODEC_ID_MP3ADU:
1716 case AV_CODEC_ID_MP3ON4:
1717 case AV_CODEC_ID_WESTWOOD_SND1:
1718 case AV_CODEC_ID_MMVIDEO:
1719 case AV_CODEC_ID_AVS:
1720 case AV_CODEC_ID_CAVS:
1724 /* weird quasi-codecs for the demuxers only */
1725 case AV_CODEC_ID_PCM_S16LE:
1726 case AV_CODEC_ID_PCM_S16BE:
1727 case AV_CODEC_ID_PCM_U16LE:
1728 case AV_CODEC_ID_PCM_U16BE:
1729 case AV_CODEC_ID_PCM_S8:
1730 case AV_CODEC_ID_PCM_U8:
1732 GstAudioFormat format;
1735 case AV_CODEC_ID_PCM_S16LE:
1736 format = GST_AUDIO_FORMAT_S16LE;
1738 case AV_CODEC_ID_PCM_S16BE:
1739 format = GST_AUDIO_FORMAT_S16BE;
1741 case AV_CODEC_ID_PCM_U16LE:
1742 format = GST_AUDIO_FORMAT_U16LE;
1744 case AV_CODEC_ID_PCM_U16BE:
1745 format = GST_AUDIO_FORMAT_U16BE;
1747 case AV_CODEC_ID_PCM_S8:
1748 format = GST_AUDIO_FORMAT_S8;
1750 case AV_CODEC_ID_PCM_U8:
1751 format = GST_AUDIO_FORMAT_U8;
1755 g_assert (0); /* don't worry, we never get here */
1760 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-raw",
1761 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
1762 "layout", G_TYPE_STRING, "interleaved", NULL);
1766 case AV_CODEC_ID_PCM_MULAW:
1768 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mulaw",
1772 case AV_CODEC_ID_PCM_ALAW:
1774 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-alaw",
1778 case AV_CODEC_ID_ADPCM_G722:
1780 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/G722",
1783 gst_caps_set_simple (caps,
1784 "block_align", G_TYPE_INT, context->block_align,
1785 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1788 case AV_CODEC_ID_ADPCM_G726:
1790 /* the G726 decoder can also handle G721 */
1792 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-adpcm",
1793 "layout", G_TYPE_STRING, "g726", NULL);
1795 gst_caps_set_simple (caps,
1796 "block_align", G_TYPE_INT, context->block_align,
1797 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1800 gst_caps_append (caps, gst_caps_new_simple ("audio/x-adpcm",
1801 "layout", G_TYPE_STRING, "g721",
1802 "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, 8000, NULL));
1806 case AV_CODEC_ID_ADPCM_IMA_QT:
1807 case AV_CODEC_ID_ADPCM_IMA_WAV:
1808 case AV_CODEC_ID_ADPCM_IMA_DK3:
1809 case AV_CODEC_ID_ADPCM_IMA_DK4:
1810 case AV_CODEC_ID_ADPCM_IMA_WS:
1811 case AV_CODEC_ID_ADPCM_IMA_SMJPEG:
1812 case AV_CODEC_ID_ADPCM_IMA_AMV:
1813 case AV_CODEC_ID_ADPCM_IMA_ISS:
1814 case AV_CODEC_ID_ADPCM_IMA_EA_EACS:
1815 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
1816 case AV_CODEC_ID_ADPCM_MS:
1817 case AV_CODEC_ID_ADPCM_4XM:
1818 case AV_CODEC_ID_ADPCM_XA:
1819 case AV_CODEC_ID_ADPCM_ADX:
1820 case AV_CODEC_ID_ADPCM_EA:
1821 case AV_CODEC_ID_ADPCM_CT:
1822 case AV_CODEC_ID_ADPCM_SWF:
1823 case AV_CODEC_ID_ADPCM_YAMAHA:
1824 case AV_CODEC_ID_ADPCM_SBPRO_2:
1825 case AV_CODEC_ID_ADPCM_SBPRO_3:
1826 case AV_CODEC_ID_ADPCM_SBPRO_4:
1827 case AV_CODEC_ID_ADPCM_EA_R1:
1828 case AV_CODEC_ID_ADPCM_EA_R2:
1829 case AV_CODEC_ID_ADPCM_EA_R3:
1830 case AV_CODEC_ID_ADPCM_EA_MAXIS_XA:
1831 case AV_CODEC_ID_ADPCM_EA_XAS:
1832 case AV_CODEC_ID_ADPCM_THP:
1834 const gchar *layout = NULL;
1837 case AV_CODEC_ID_ADPCM_IMA_QT:
1838 layout = "quicktime";
1840 case AV_CODEC_ID_ADPCM_IMA_WAV:
1843 case AV_CODEC_ID_ADPCM_IMA_DK3:
1846 case AV_CODEC_ID_ADPCM_IMA_DK4:
1849 case AV_CODEC_ID_ADPCM_IMA_WS:
1850 layout = "westwood";
1852 case AV_CODEC_ID_ADPCM_IMA_SMJPEG:
1855 case AV_CODEC_ID_ADPCM_IMA_AMV:
1858 case AV_CODEC_ID_ADPCM_IMA_ISS:
1861 case AV_CODEC_ID_ADPCM_IMA_EA_EACS:
1864 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
1867 case AV_CODEC_ID_ADPCM_MS:
1868 layout = "microsoft";
1870 case AV_CODEC_ID_ADPCM_4XM:
1873 case AV_CODEC_ID_ADPCM_XA:
1876 case AV_CODEC_ID_ADPCM_ADX:
1879 case AV_CODEC_ID_ADPCM_EA:
1882 case AV_CODEC_ID_ADPCM_CT:
1885 case AV_CODEC_ID_ADPCM_SWF:
1888 case AV_CODEC_ID_ADPCM_YAMAHA:
1891 case AV_CODEC_ID_ADPCM_SBPRO_2:
1894 case AV_CODEC_ID_ADPCM_SBPRO_3:
1897 case AV_CODEC_ID_ADPCM_SBPRO_4:
1900 case AV_CODEC_ID_ADPCM_EA_R1:
1903 case AV_CODEC_ID_ADPCM_EA_R2:
1906 case AV_CODEC_ID_ADPCM_EA_R3:
1909 case AV_CODEC_ID_ADPCM_EA_MAXIS_XA:
1910 layout = "ea-maxis-xa";
1912 case AV_CODEC_ID_ADPCM_EA_XAS:
1915 case AV_CODEC_ID_ADPCM_THP:
1919 g_assert (0); /* don't worry, we never get here */
1923 /* FIXME: someone please check whether we need additional properties
1924 * in this caps definition. */
1926 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-adpcm",
1927 "layout", G_TYPE_STRING, layout, NULL);
1929 gst_caps_set_simple (caps,
1930 "block_align", G_TYPE_INT, context->block_align,
1931 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1935 case AV_CODEC_ID_AMR_NB:
1937 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/AMR",
1941 case AV_CODEC_ID_AMR_WB:
1943 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/AMR-WB",
1947 case AV_CODEC_ID_GSM:
1949 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-gsm",
1953 case AV_CODEC_ID_GSM_MS:
1955 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/ms-gsm",
1959 case AV_CODEC_ID_NELLYMOSER:
1961 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1962 "audio/x-nellymoser", NULL);
1965 case AV_CODEC_ID_SIPR:
1968 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-sipro",
1971 gst_caps_set_simple (caps,
1972 "leaf_size", G_TYPE_INT, context->block_align,
1973 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1978 case AV_CODEC_ID_RA_144:
1979 case AV_CODEC_ID_RA_288:
1980 case AV_CODEC_ID_COOK:
1985 case AV_CODEC_ID_RA_144:
1988 case AV_CODEC_ID_RA_288:
1991 case AV_CODEC_ID_COOK:
1998 /* FIXME: properties? */
2000 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
2001 "audio/x-pn-realaudio", "raversion", G_TYPE_INT, version, NULL);
2003 gst_caps_set_simple (caps,
2004 "leaf_size", G_TYPE_INT, context->block_align,
2005 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
2010 case AV_CODEC_ID_ROQ_DPCM:
2011 case AV_CODEC_ID_INTERPLAY_DPCM:
2012 case AV_CODEC_ID_XAN_DPCM:
2013 case AV_CODEC_ID_SOL_DPCM:
2015 const gchar *layout = NULL;
2018 case AV_CODEC_ID_ROQ_DPCM:
2021 case AV_CODEC_ID_INTERPLAY_DPCM:
2022 layout = "interplay";
2024 case AV_CODEC_ID_XAN_DPCM:
2027 case AV_CODEC_ID_SOL_DPCM:
2031 g_assert (0); /* don't worry, we never get here */
2035 /* FIXME: someone please check whether we need additional properties
2036 * in this caps definition. */
2038 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dpcm",
2039 "layout", G_TYPE_STRING, layout, NULL);
2041 gst_caps_set_simple (caps,
2042 "block_align", G_TYPE_INT, context->block_align,
2043 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
2047 case AV_CODEC_ID_SHORTEN:
2048 caps = gst_caps_new_empty_simple ("audio/x-shorten");
2051 case AV_CODEC_ID_ALAC:
2053 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-alac",
2056 gst_caps_set_simple (caps,
2057 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
2061 case AV_CODEC_ID_FLAC:
2062 /* Note that ffmpeg has no encoder yet, but just for safety. In the
2063 * encoder case, we want to add things like samplerate, channels... */
2065 caps = gst_caps_new_empty_simple ("audio/x-flac");
2069 case AV_CODEC_ID_S302M:
2070 caps = gst_caps_new_empty_simple ("audio/x-smpte-302m");
2073 case AV_CODEC_ID_DVD_SUBTITLE:
2074 case AV_CODEC_ID_DVB_SUBTITLE:
2077 case AV_CODEC_ID_BMP:
2078 caps = gst_caps_new_empty_simple ("image/bmp");
2080 case AV_CODEC_ID_TTA:
2082 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-tta",
2085 gst_caps_set_simple (caps,
2086 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
2089 case AV_CODEC_ID_TWINVQ:
2091 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
2092 "audio/x-twin-vq", NULL);
2095 GST_DEBUG ("Unknown codec ID %d, please add mapping here", codec_id);
2102 if ((codec = avcodec_find_decoder (codec_id)) ||
2103 (codec = avcodec_find_encoder (codec_id))) {
2106 GST_LOG ("Could not create stream format caps for %s", codec->name);
2108 switch (codec->type) {
2109 case AVMEDIA_TYPE_VIDEO:
2110 mime = g_strdup_printf ("video/x-gst-av-%s", codec->name);
2112 gst_ff_vid_caps_new (context, NULL, codec_id, encode, mime, NULL);
2115 case AVMEDIA_TYPE_AUDIO:
2116 mime = g_strdup_printf ("audio/x-gst-av-%s", codec->name);
2118 gst_ff_aud_caps_new (context, NULL, codec_id, encode, mime, NULL);
2120 gst_caps_set_simple (caps,
2121 "block_align", G_TYPE_INT, context->block_align,
2122 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
2133 /* set private data */
2134 if (context && context->extradata_size > 0) {
2135 GstBuffer *data = gst_buffer_new_and_alloc (context->extradata_size);
2137 gst_buffer_fill (data, 0, context->extradata, context->extradata_size);
2138 gst_caps_set_simple (caps, "codec_data", GST_TYPE_BUFFER, data, NULL);
2139 gst_buffer_unref (data);
2142 GST_LOG ("caps for codec_id=%d: %" GST_PTR_FORMAT, codec_id, caps);
2145 GST_LOG ("No caps found for codec_id=%d", codec_id);
2151 /* Convert a FFMPEG Pixel Format and optional AVCodecContext
2152 * to a GstCaps. If the context is ommitted, no fixed values
2153 * for video/audio size will be included in the GstCaps
2155 * See below for usefullness
2159 gst_ffmpeg_pixfmt_to_caps (enum PixelFormat pix_fmt, AVCodecContext * context,
2160 enum AVCodecID codec_id)
2162 GstCaps *caps = NULL;
2163 GstVideoFormat format;
2165 format = gst_ffmpeg_pixfmt_to_videoformat (pix_fmt);
2167 if (format != GST_VIDEO_FORMAT_UNKNOWN) {
2168 caps = gst_ff_vid_caps_new (context, NULL, codec_id, TRUE, "video/x-raw",
2169 "format", G_TYPE_STRING, gst_video_format_to_string (format), NULL);
2173 GST_DEBUG ("caps for pix_fmt=%d: %" GST_PTR_FORMAT, pix_fmt, caps);
2175 GST_LOG ("No caps found for pix_fmt=%d", pix_fmt);
2182 gst_ffmpeg_smpfmt_to_audioformat (enum AVSampleFormat sample_fmt)
2184 switch (sample_fmt) {
2185 case AV_SAMPLE_FMT_U8:
2186 case AV_SAMPLE_FMT_U8P:
2187 return GST_AUDIO_FORMAT_U8;
2189 case AV_SAMPLE_FMT_S16:
2190 case AV_SAMPLE_FMT_S16P:
2191 return GST_AUDIO_FORMAT_S16;
2193 case AV_SAMPLE_FMT_S32:
2194 case AV_SAMPLE_FMT_S32P:
2195 return GST_AUDIO_FORMAT_S32;
2197 case AV_SAMPLE_FMT_FLT:
2198 case AV_SAMPLE_FMT_FLTP:
2199 return GST_AUDIO_FORMAT_F32;
2201 case AV_SAMPLE_FMT_DBL:
2202 case AV_SAMPLE_FMT_DBLP:
2203 return GST_AUDIO_FORMAT_F64;
2207 return GST_AUDIO_FORMAT_UNKNOWN;
2212 /* Convert a FFMPEG Sample Format and optional AVCodecContext
2213 * to a GstCaps. If the context is ommitted, no fixed values
2214 * for video/audio size will be included in the GstCaps
2216 * See below for usefullness
2220 gst_ffmpeg_smpfmt_to_caps (enum AVSampleFormat sample_fmt,
2221 AVCodecContext * context, AVCodec * codec, enum AVCodecID codec_id)
2223 GstCaps *caps = NULL;
2224 GstAudioFormat format;
2226 format = gst_ffmpeg_smpfmt_to_audioformat (sample_fmt);
2228 if (format != GST_AUDIO_FORMAT_UNKNOWN) {
2229 caps = gst_ff_aud_caps_new (context, codec, codec_id, TRUE, "audio/x-raw",
2230 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
2231 "layout", G_TYPE_STRING, "interleaved", NULL);
2232 GST_LOG ("caps for sample_fmt=%d: %" GST_PTR_FORMAT, sample_fmt, caps);
2234 GST_LOG ("No caps found for sample_fmt=%d", sample_fmt);
2241 caps_has_field (GstCaps * caps, const gchar * field)
2245 n = gst_caps_get_size (caps);
2246 for (i = 0; i < n; i++) {
2247 GstStructure *s = gst_caps_get_structure (caps, i);
2249 if (gst_structure_has_field (s, field))
2257 gst_ffmpeg_codectype_to_audio_caps (AVCodecContext * context,
2258 enum AVCodecID codec_id, gboolean encode, AVCodec * codec)
2260 GstCaps *caps = NULL;
2262 GST_DEBUG ("context:%p, codec_id:%d, encode:%d, codec:%p",
2263 context, codec_id, encode, codec);
2265 GST_DEBUG ("sample_fmts:%p, samplerates:%p",
2266 codec->sample_fmts, codec->supported_samplerates);
2269 /* Specific codec context */
2271 gst_ffmpeg_smpfmt_to_caps (context->sample_fmt, context, codec,
2274 caps = gst_ff_aud_caps_new (context, codec, codec_id, encode, "audio/x-raw",
2275 "layout", G_TYPE_STRING, "interleaved", NULL);
2276 if (!caps_has_field (caps, "format"))
2277 gst_ffmpeg_audio_set_sample_fmts (caps,
2278 codec ? codec->sample_fmts : NULL);
2285 gst_ffmpeg_codectype_to_video_caps (AVCodecContext * context,
2286 enum AVCodecID codec_id, gboolean encode, AVCodec * codec)
2290 GST_LOG ("context:%p, codec_id:%d, encode:%d, codec:%p",
2291 context, codec_id, encode, codec);
2294 caps = gst_ffmpeg_pixfmt_to_caps (context->pix_fmt, context, codec_id);
2297 gst_ff_vid_caps_new (context, codec, codec_id, encode, "video/x-raw",
2299 if (!caps_has_field (caps, "format"))
2300 gst_ffmpeg_video_set_pix_fmts (caps, codec ? codec->pix_fmts : NULL);
2305 /* Convert a GstCaps (audio/raw) to a FFMPEG SampleFmt
2306 * and other audio properties in a AVCodecContext.
2308 * For usefullness, see below
2312 gst_ffmpeg_caps_to_smpfmt (const GstCaps * caps,
2313 AVCodecContext * context, gboolean raw)
2315 GstStructure *structure;
2317 GstAudioFormat format = GST_AUDIO_FORMAT_UNKNOWN;
2319 g_return_if_fail (gst_caps_get_size (caps) == 1);
2321 structure = gst_caps_get_structure (caps, 0);
2323 gst_structure_get_int (structure, "channels", &context->channels);
2324 gst_structure_get_int (structure, "rate", &context->sample_rate);
2325 gst_structure_get_int (structure, "block_align", &context->block_align);
2326 gst_structure_get_int (structure, "bitrate", &context->bit_rate);
2331 if (gst_structure_has_name (structure, "audio/x-raw")) {
2332 if ((fmt = gst_structure_get_string (structure, "format"))) {
2333 format = gst_audio_format_from_string (fmt);
2338 case GST_AUDIO_FORMAT_F32:
2339 context->sample_fmt = AV_SAMPLE_FMT_FLT;
2341 case GST_AUDIO_FORMAT_F64:
2342 context->sample_fmt = AV_SAMPLE_FMT_DBL;
2344 case GST_AUDIO_FORMAT_S32:
2345 context->sample_fmt = AV_SAMPLE_FMT_S32;
2347 case GST_AUDIO_FORMAT_S16:
2348 context->sample_fmt = AV_SAMPLE_FMT_S16;
2355 /* Convert a GstCaps (video/raw) to a FFMPEG PixFmt
2356 * and other video properties in a AVCodecContext.
2358 * For usefullness, see below
2362 gst_ffmpeg_caps_to_pixfmt (const GstCaps * caps,
2363 AVCodecContext * context, gboolean raw)
2365 GstStructure *structure;
2367 const GValue *par = NULL;
2369 GstVideoFormat format = GST_VIDEO_FORMAT_UNKNOWN;
2371 GST_DEBUG ("converting caps %" GST_PTR_FORMAT, caps);
2372 g_return_if_fail (gst_caps_get_size (caps) == 1);
2373 structure = gst_caps_get_structure (caps, 0);
2375 gst_structure_get_int (structure, "width", &context->width);
2376 gst_structure_get_int (structure, "height", &context->height);
2377 gst_structure_get_int (structure, "bpp", &context->bits_per_coded_sample);
2379 fps = gst_structure_get_value (structure, "framerate");
2380 if (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps)) {
2382 int num = gst_value_get_fraction_numerator (fps);
2383 int den = gst_value_get_fraction_denominator (fps);
2385 if (num > 0 && den > 0) {
2386 /* somehow these seem mixed up.. */
2387 /* they're fine, this is because it does period=1/frequency */
2388 context->time_base.den = gst_value_get_fraction_numerator (fps);
2389 context->time_base.num = gst_value_get_fraction_denominator (fps);
2390 context->ticks_per_frame = 1;
2392 GST_DEBUG ("setting framerate %d/%d = %lf",
2393 context->time_base.den, context->time_base.num,
2394 1. * context->time_base.den / context->time_base.num);
2396 GST_WARNING ("ignoring insane framerate %d/%d",
2397 context->time_base.den, context->time_base.num);
2401 par = gst_structure_get_value (structure, "pixel-aspect-ratio");
2402 if (par && GST_VALUE_HOLDS_FRACTION (par)) {
2404 int num = gst_value_get_fraction_numerator (par);
2405 int den = gst_value_get_fraction_denominator (par);
2407 if (num > 0 && den > 0) {
2408 context->sample_aspect_ratio.num = num;
2409 context->sample_aspect_ratio.den = den;
2411 GST_DEBUG ("setting pixel-aspect-ratio %d/%d = %lf",
2412 context->sample_aspect_ratio.num, context->sample_aspect_ratio.den,
2413 1. * context->sample_aspect_ratio.num /
2414 context->sample_aspect_ratio.den);
2416 GST_WARNING ("ignoring insane pixel-aspect-ratio %d/%d",
2417 context->sample_aspect_ratio.num, context->sample_aspect_ratio.den);
2424 g_return_if_fail (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps));
2426 if (gst_structure_has_name (structure, "video/x-raw")) {
2427 if ((fmt = gst_structure_get_string (structure, "format"))) {
2428 format = gst_video_format_from_string (fmt);
2433 case GST_VIDEO_FORMAT_YUY2:
2434 context->pix_fmt = PIX_FMT_YUYV422;
2436 case GST_VIDEO_FORMAT_I420:
2437 context->pix_fmt = PIX_FMT_YUV420P;
2439 case GST_VIDEO_FORMAT_A420:
2440 context->pix_fmt = PIX_FMT_YUVA420P;
2442 case GST_VIDEO_FORMAT_Y41B:
2443 context->pix_fmt = PIX_FMT_YUV411P;
2445 case GST_VIDEO_FORMAT_Y42B:
2446 context->pix_fmt = PIX_FMT_YUV422P;
2448 case GST_VIDEO_FORMAT_YUV9:
2449 context->pix_fmt = PIX_FMT_YUV410P;
2451 case GST_VIDEO_FORMAT_Y444:
2452 context->pix_fmt = PIX_FMT_YUV444P;
2454 case GST_VIDEO_FORMAT_GRAY8:
2455 context->pix_fmt = PIX_FMT_GRAY8;
2457 case GST_VIDEO_FORMAT_xRGB:
2458 #if (G_BYTE_ORDER == G_BIG_ENDIAN)
2459 context->pix_fmt = PIX_FMT_RGB32;
2462 case GST_VIDEO_FORMAT_BGRx:
2463 #if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
2464 context->pix_fmt = PIX_FMT_RGB32;
2467 case GST_VIDEO_FORMAT_RGB:
2468 context->pix_fmt = PIX_FMT_RGB24;
2470 case GST_VIDEO_FORMAT_BGR:
2471 context->pix_fmt = PIX_FMT_BGR24;
2473 case GST_VIDEO_FORMAT_RGB16:
2474 context->pix_fmt = PIX_FMT_RGB565;
2476 case GST_VIDEO_FORMAT_RGB15:
2477 context->pix_fmt = PIX_FMT_RGB555;
2479 case GST_VIDEO_FORMAT_RGB8P:
2480 context->pix_fmt = PIX_FMT_PAL8;
2489 GstVideoFormat format;
2490 enum PixelFormat pixfmt;
2493 /* FIXME : FILLME */
2494 static const PixToFmt pixtofmttable[] = {
2495 /* GST_VIDEO_FORMAT_I420, */
2496 {GST_VIDEO_FORMAT_I420, PIX_FMT_YUV420P},
2497 /* Note : this should use a different chroma placement */
2498 {GST_VIDEO_FORMAT_I420, PIX_FMT_YUVJ420P},
2500 /* GST_VIDEO_FORMAT_YV12, */
2501 /* GST_VIDEO_FORMAT_YUY2, */
2502 {GST_VIDEO_FORMAT_YUY2, PIX_FMT_YUYV422},
2503 /* GST_VIDEO_FORMAT_UYVY, */
2504 {GST_VIDEO_FORMAT_UYVY, PIX_FMT_UYVY422},
2505 /* GST_VIDEO_FORMAT_AYUV, */
2506 /* GST_VIDEO_FORMAT_RGBx, */
2507 /* GST_VIDEO_FORMAT_BGRx, */
2508 /* GST_VIDEO_FORMAT_xRGB, */
2509 /* GST_VIDEO_FORMAT_xBGR, */
2510 /* GST_VIDEO_FORMAT_RGBA, */
2511 {GST_VIDEO_FORMAT_RGBA, PIX_FMT_RGBA},
2512 /* GST_VIDEO_FORMAT_BGRA, */
2513 {GST_VIDEO_FORMAT_BGRA, PIX_FMT_BGRA},
2514 /* GST_VIDEO_FORMAT_ARGB, */
2515 {GST_VIDEO_FORMAT_ARGB, PIX_FMT_ARGB},
2516 /* GST_VIDEO_FORMAT_ABGR, */
2517 {GST_VIDEO_FORMAT_ABGR, PIX_FMT_ABGR},
2518 /* GST_VIDEO_FORMAT_RGB, */
2519 {GST_VIDEO_FORMAT_RGB, PIX_FMT_RGB24},
2520 /* GST_VIDEO_FORMAT_BGR, */
2521 {GST_VIDEO_FORMAT_BGR, PIX_FMT_BGR24},
2522 /* GST_VIDEO_FORMAT_Y41B, */
2523 {GST_VIDEO_FORMAT_Y41B, PIX_FMT_YUV411P},
2524 /* GST_VIDEO_FORMAT_Y42B, */
2525 {GST_VIDEO_FORMAT_Y42B, PIX_FMT_YUV422P},
2526 {GST_VIDEO_FORMAT_Y42B, PIX_FMT_YUVJ422P},
2527 /* GST_VIDEO_FORMAT_YVYU, */
2528 /* GST_VIDEO_FORMAT_Y444, */
2529 {GST_VIDEO_FORMAT_Y444, PIX_FMT_YUV444P},
2530 {GST_VIDEO_FORMAT_Y444, PIX_FMT_YUVJ444P},
2531 /* GST_VIDEO_FORMAT_v210, */
2532 /* GST_VIDEO_FORMAT_v216, */
2533 /* GST_VIDEO_FORMAT_NV12, */
2534 {GST_VIDEO_FORMAT_NV12, PIX_FMT_NV12},
2535 /* GST_VIDEO_FORMAT_NV21, */
2536 {GST_VIDEO_FORMAT_NV21, PIX_FMT_NV21},
2537 /* GST_VIDEO_FORMAT_GRAY8, */
2538 {GST_VIDEO_FORMAT_GRAY8, PIX_FMT_GRAY8},
2539 /* GST_VIDEO_FORMAT_GRAY16_BE, */
2540 {GST_VIDEO_FORMAT_GRAY16_BE, PIX_FMT_GRAY16BE},
2541 /* GST_VIDEO_FORMAT_GRAY16_LE, */
2542 {GST_VIDEO_FORMAT_GRAY16_LE, PIX_FMT_GRAY16LE},
2543 /* GST_VIDEO_FORMAT_v308, */
2544 /* GST_VIDEO_FORMAT_Y800, */
2545 /* GST_VIDEO_FORMAT_Y16, */
2546 /* GST_VIDEO_FORMAT_RGB16, */
2547 {GST_VIDEO_FORMAT_RGB16, PIX_FMT_RGB565},
2548 /* GST_VIDEO_FORMAT_BGR16, */
2549 /* GST_VIDEO_FORMAT_RGB15, */
2550 {GST_VIDEO_FORMAT_RGB15, PIX_FMT_RGB555},
2551 /* GST_VIDEO_FORMAT_BGR15, */
2552 /* GST_VIDEO_FORMAT_UYVP, */
2553 /* GST_VIDEO_FORMAT_A420, */
2554 {GST_VIDEO_FORMAT_A420, PIX_FMT_YUVA420P},
2555 /* GST_VIDEO_FORMAT_RGB8_PALETTED, */
2556 {GST_VIDEO_FORMAT_RGB8P, PIX_FMT_PAL8},
2557 /* GST_VIDEO_FORMAT_YUV9, */
2558 {GST_VIDEO_FORMAT_YUV9, PIX_FMT_YUV410P},
2559 /* GST_VIDEO_FORMAT_YVU9, */
2560 /* GST_VIDEO_FORMAT_IYU1, */
2561 /* GST_VIDEO_FORMAT_ARGB64, */
2562 /* GST_VIDEO_FORMAT_AYUV64, */
2563 /* GST_VIDEO_FORMAT_r210, */
2564 {GST_VIDEO_FORMAT_I420_10LE, PIX_FMT_YUV420P10LE},
2565 {GST_VIDEO_FORMAT_I420_10BE, PIX_FMT_YUV420P10BE},
2566 {GST_VIDEO_FORMAT_I422_10LE, PIX_FMT_YUV422P10LE},
2567 {GST_VIDEO_FORMAT_I422_10BE, PIX_FMT_YUV422P10BE},
2568 {GST_VIDEO_FORMAT_Y444_10LE, PIX_FMT_YUV444P10LE},
2569 {GST_VIDEO_FORMAT_Y444_10BE, PIX_FMT_YUV444P10BE},
2570 {GST_VIDEO_FORMAT_GBR, PIX_FMT_GBRP},
2571 {GST_VIDEO_FORMAT_GBR_10LE, PIX_FMT_GBRP10LE},
2572 {GST_VIDEO_FORMAT_GBR_10BE, PIX_FMT_GBRP10BE},
2576 gst_ffmpeg_pixfmt_to_videoformat (enum PixelFormat pixfmt)
2580 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2581 if (pixtofmttable[i].pixfmt == pixfmt)
2582 return pixtofmttable[i].format;
2584 GST_DEBUG ("Unknown pixel format %d", pixfmt);
2585 return GST_VIDEO_FORMAT_UNKNOWN;
2589 gst_ffmpeg_videoformat_to_pixfmt (GstVideoFormat format)
2593 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2594 if (pixtofmttable[i].format == format)
2595 return pixtofmttable[i].pixfmt;
2596 return PIX_FMT_NONE;
2600 gst_ffmpeg_videoinfo_to_context (GstVideoInfo * info, AVCodecContext * context)
2604 context->width = GST_VIDEO_INFO_WIDTH (info);
2605 context->height = GST_VIDEO_INFO_HEIGHT (info);
2606 for (i = 0; i < GST_VIDEO_INFO_N_COMPONENTS (info); i++)
2607 bpp += GST_VIDEO_INFO_COMP_DEPTH (info, i);
2608 context->bits_per_coded_sample = bpp;
2610 context->ticks_per_frame = 1;
2611 if (GST_VIDEO_INFO_FPS_N (info) == 0) {
2612 GST_DEBUG ("Using 25/1 framerate");
2613 context->time_base.den = 25;
2614 context->time_base.num = 1;
2616 context->time_base.den = GST_VIDEO_INFO_FPS_N (info);
2617 context->time_base.num = GST_VIDEO_INFO_FPS_D (info);
2620 context->sample_aspect_ratio.num = GST_VIDEO_INFO_PAR_N (info);
2621 context->sample_aspect_ratio.den = GST_VIDEO_INFO_PAR_D (info);
2624 gst_ffmpeg_videoformat_to_pixfmt (GST_VIDEO_INFO_FORMAT (info));
2628 gst_ffmpeg_audioinfo_to_context (GstAudioInfo * info, AVCodecContext * context)
2630 const AVCodec *codec;
2631 const enum AVSampleFormat *smpl_fmts;
2632 enum AVSampleFormat smpl_fmt = -1;
2634 context->channels = info->channels;
2635 context->sample_rate = info->rate;
2636 context->channel_layout =
2637 gst_ffmpeg_channel_positions_to_layout (info->position, info->channels);
2639 codec = context->codec;
2641 smpl_fmts = codec->sample_fmts;
2643 switch (info->finfo->format) {
2644 case GST_AUDIO_FORMAT_F32:
2646 while (*smpl_fmts != -1) {
2647 if (*smpl_fmts == AV_SAMPLE_FMT_FLT) {
2648 smpl_fmt = *smpl_fmts;
2650 } else if (*smpl_fmts == AV_SAMPLE_FMT_FLTP) {
2651 smpl_fmt = *smpl_fmts;
2657 smpl_fmt = AV_SAMPLE_FMT_FLT;
2660 case GST_AUDIO_FORMAT_F64:
2662 while (*smpl_fmts != -1) {
2663 if (*smpl_fmts == AV_SAMPLE_FMT_DBL) {
2664 smpl_fmt = *smpl_fmts;
2666 } else if (*smpl_fmts == AV_SAMPLE_FMT_DBLP) {
2667 smpl_fmt = *smpl_fmts;
2673 smpl_fmt = AV_SAMPLE_FMT_DBL;
2676 case GST_AUDIO_FORMAT_S32:
2678 while (*smpl_fmts != -1) {
2679 if (*smpl_fmts == AV_SAMPLE_FMT_S32) {
2680 smpl_fmt = *smpl_fmts;
2682 } else if (*smpl_fmts == AV_SAMPLE_FMT_S32P) {
2683 smpl_fmt = *smpl_fmts;
2689 smpl_fmt = AV_SAMPLE_FMT_S32;
2692 case GST_AUDIO_FORMAT_S16:
2694 while (*smpl_fmts != -1) {
2695 if (*smpl_fmts == AV_SAMPLE_FMT_S16) {
2696 smpl_fmt = *smpl_fmts;
2698 } else if (*smpl_fmts == AV_SAMPLE_FMT_S16P) {
2699 smpl_fmt = *smpl_fmts;
2705 smpl_fmt = AV_SAMPLE_FMT_S16;
2708 case GST_AUDIO_FORMAT_U8:
2710 while (*smpl_fmts != -1) {
2711 if (*smpl_fmts == AV_SAMPLE_FMT_U8) {
2712 smpl_fmt = *smpl_fmts;
2714 } else if (*smpl_fmts == AV_SAMPLE_FMT_U8P) {
2715 smpl_fmt = *smpl_fmts;
2721 smpl_fmt = AV_SAMPLE_FMT_U8;
2728 g_assert (smpl_fmt != -1);
2730 context->sample_fmt = smpl_fmt;
2733 /* Convert a GstCaps and a FFMPEG codec Type to a
2734 * AVCodecContext. If the context is ommitted, no fixed values
2735 * for video/audio size will be included in the context
2737 * AVMediaType is primarily meant for uncompressed data GstCaps!
2741 gst_ffmpeg_caps_with_codectype (enum AVMediaType type,
2742 const GstCaps * caps, AVCodecContext * context)
2744 if (context == NULL)
2748 case AVMEDIA_TYPE_VIDEO:
2749 gst_ffmpeg_caps_to_pixfmt (caps, context, TRUE);
2752 case AVMEDIA_TYPE_AUDIO:
2753 gst_ffmpeg_caps_to_smpfmt (caps, context, TRUE);
2764 nal_escape (guint8 * dst, guint8 * src, guint size, guint * destsize)
2768 guint8 *end = src + size;
2771 while (srcp < end) {
2772 if (count == 2 && *srcp <= 0x03) {
2773 GST_DEBUG ("added escape code");
2782 GST_DEBUG ("copy %02x, count %d", *srcp, count);
2785 *destsize = dstp - dst;
2788 /* copy the config, escaping NAL units as we iterate them, if something fails we
2789 * copy everything and hope for the best. */
2791 copy_config (guint8 * dst, guint8 * src, guint size, guint * destsize)
2796 guint nalsize, esize;
2806 cnt = *(srcp + 5) & 0x1f; /* Number of sps */
2808 GST_DEBUG ("num SPS %d", cnt);
2810 memcpy (dstp, srcp, 6);
2814 for (i = 0; i < cnt; i++) {
2815 GST_DEBUG ("copy SPS %d", i);
2816 nalsize = (srcp[0] << 8) | srcp[1];
2817 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2818 dstp[0] = esize >> 8;
2819 dstp[1] = esize & 0xff;
2821 srcp += nalsize + 2;
2824 cnt = *(dstp++) = *(srcp++); /* Number of pps */
2826 GST_DEBUG ("num PPS %d", cnt);
2828 for (i = 0; i < cnt; i++) {
2829 GST_DEBUG ("copy PPS %d", i);
2830 nalsize = (srcp[0] << 8) | srcp[1];
2831 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2832 dstp[0] = esize >> 8;
2833 dstp[1] = esize & 0xff;
2835 srcp += nalsize + 2;
2837 *destsize = dstp - dst;
2843 GST_DEBUG ("something unexpected, doing full copy");
2844 memcpy (dst, src, size);
2852 * caps_with_codecid () transforms a GstCaps for a known codec
2853 * ID into a filled-in context.
2854 * codec_data from caps will override possible extradata already in the context
2858 gst_ffmpeg_caps_with_codecid (enum AVCodecID codec_id,
2859 enum AVMediaType codec_type, const GstCaps * caps, AVCodecContext * context)
2862 const GValue *value;
2865 GST_LOG ("codec_id:%d, codec_type:%d, caps:%" GST_PTR_FORMAT " context:%p",
2866 codec_id, codec_type, caps, context);
2868 if (!context || !gst_caps_get_size (caps))
2871 str = gst_caps_get_structure (caps, 0);
2873 /* extradata parsing (esds [mpeg4], wma/wmv, msmpeg4v1/2/3, etc.) */
2874 if ((value = gst_structure_get_value (str, "codec_data"))) {
2877 buf = gst_value_get_buffer (value);
2878 gst_buffer_map (buf, &map, GST_MAP_READ);
2880 /* free the old one if it is there */
2881 if (context->extradata)
2882 av_free (context->extradata);
2885 if (codec_id == AV_CODEC_ID_H264) {
2888 GST_DEBUG ("copy, escaping codec_data %d", size);
2889 /* ffmpeg h264 expects the codec_data to be escaped, there is no real
2890 * reason for this but let's just escape it for now. Start by allocating
2891 * enough space, x2 is more than enough.
2893 * FIXME, we disabled escaping because some file already contain escaped
2894 * codec_data and then we escape twice and fail. It's better to leave it
2895 * as is, as that is what most players do. */
2896 context->extradata =
2897 av_mallocz (GST_ROUND_UP_16 (size * 2 +
2898 FF_INPUT_BUFFER_PADDING_SIZE));
2899 copy_config (context->extradata, data, size, &extrasize);
2900 GST_DEBUG ("escaped size: %d", extrasize);
2901 context->extradata_size = extrasize;
2905 /* allocate with enough padding */
2906 GST_DEBUG ("copy codec_data");
2907 context->extradata =
2908 av_mallocz (GST_ROUND_UP_16 (map.size +
2909 FF_INPUT_BUFFER_PADDING_SIZE));
2910 memcpy (context->extradata, map.data, map.size);
2911 context->extradata_size = map.size;
2914 /* Hack for VC1. Sometimes the first (length) byte is 0 for some files */
2915 if (codec_id == AV_CODEC_ID_VC1 && map.size > 0 && map.data[0] == 0) {
2916 context->extradata[0] = (guint8) map.size;
2919 GST_DEBUG ("have codec data of size %" G_GSIZE_FORMAT, map.size);
2921 gst_buffer_unmap (buf, &map);
2922 } else if (context->extradata == NULL && codec_id != AV_CODEC_ID_AAC_LATM &&
2923 codec_id != AV_CODEC_ID_FLAC) {
2924 /* no extradata, alloc dummy with 0 sized, some codecs insist on reading
2925 * extradata anyway which makes then segfault. */
2926 context->extradata =
2927 av_mallocz (GST_ROUND_UP_16 (FF_INPUT_BUFFER_PADDING_SIZE));
2928 context->extradata_size = 0;
2929 GST_DEBUG ("no codec data");
2933 case AV_CODEC_ID_MPEG4:
2935 const gchar *mime = gst_structure_get_name (str);
2937 if (!strcmp (mime, "video/x-divx"))
2938 context->codec_tag = GST_MAKE_FOURCC ('D', 'I', 'V', 'X');
2939 else if (!strcmp (mime, "video/x-xvid"))
2940 context->codec_tag = GST_MAKE_FOURCC ('X', 'V', 'I', 'D');
2941 else if (!strcmp (mime, "video/x-3ivx"))
2942 context->codec_tag = GST_MAKE_FOURCC ('3', 'I', 'V', '1');
2943 else if (!strcmp (mime, "video/mpeg"))
2944 context->codec_tag = GST_MAKE_FOURCC ('m', 'p', '4', 'v');
2948 case AV_CODEC_ID_SVQ3:
2949 /* FIXME: this is a workaround for older gst-plugins releases
2950 * (<= 0.8.9). This should be removed at some point, because
2951 * it causes wrong decoded frame order. */
2952 if (!context->extradata) {
2953 gint halfpel_flag, thirdpel_flag, low_delay, unknown_svq3_flag;
2956 if (gst_structure_get_int (str, "halfpel_flag", &halfpel_flag) &&
2957 gst_structure_get_int (str, "thirdpel_flag", &thirdpel_flag) &&
2958 gst_structure_get_int (str, "low_delay", &low_delay) &&
2959 gst_structure_get_int (str, "unknown_svq3_flag",
2960 &unknown_svq3_flag)) {
2961 context->extradata = (guint8 *) av_mallocz (0x64);
2962 g_stpcpy ((gchar *) context->extradata, "SVQ3");
2966 flags |= unknown_svq3_flag;
2968 flags |= halfpel_flag;
2970 flags |= thirdpel_flag;
2973 flags = GUINT16_FROM_LE (flags);
2975 memcpy ((gchar *) context->extradata + 0x62, &flags, 2);
2976 context->extradata_size = 0x64;
2981 case AV_CODEC_ID_MSRLE:
2982 case AV_CODEC_ID_QTRLE:
2983 case AV_CODEC_ID_TSCC:
2984 case AV_CODEC_ID_CSCD:
2985 case AV_CODEC_ID_APE:
2989 if (gst_structure_get_int (str, "depth", &depth)) {
2990 context->bits_per_coded_sample = depth;
2992 GST_WARNING ("No depth field in caps %" GST_PTR_FORMAT, caps);
2998 case AV_CODEC_ID_COOK:
2999 case AV_CODEC_ID_RA_288:
3000 case AV_CODEC_ID_RA_144:
3001 case AV_CODEC_ID_SIPR:
3006 if (gst_structure_get_int (str, "leaf_size", &leaf_size))
3007 context->block_align = leaf_size;
3008 if (gst_structure_get_int (str, "bitrate", &bitrate))
3009 context->bit_rate = bitrate;
3012 case AV_CODEC_ID_ALAC:
3013 gst_structure_get_int (str, "samplesize",
3014 &context->bits_per_coded_sample);
3017 case AV_CODEC_ID_DVVIDEO:
3019 const gchar *format;
3021 if ((format = gst_structure_get_string (str, "format"))) {
3023 if (g_str_equal (format, "YUY2"))
3024 context->pix_fmt = PIX_FMT_YUYV422;
3025 else if (g_str_equal (format, "I420"))
3026 context->pix_fmt = PIX_FMT_YUV420P;
3027 else if (g_str_equal (format, "A420"))
3028 context->pix_fmt = PIX_FMT_YUVA420P;
3029 else if (g_str_equal (format, "Y41B"))
3030 context->pix_fmt = PIX_FMT_YUV411P;
3031 else if (g_str_equal (format, "Y42B"))
3032 context->pix_fmt = PIX_FMT_YUV422P;
3033 else if (g_str_equal (format, "YUV9"))
3034 context->pix_fmt = PIX_FMT_YUV410P;
3036 GST_WARNING ("couldn't convert format %s" " to a pixel format",
3040 GST_WARNING ("No specified format");
3043 case AV_CODEC_ID_H263P:
3047 if (!gst_structure_get_boolean (str, "annex-f", &val) || val)
3048 context->flags |= CODEC_FLAG_4MV;
3050 context->flags &= ~CODEC_FLAG_4MV;
3051 if ((!gst_structure_get_boolean (str, "annex-i", &val) || val) &&
3052 (!gst_structure_get_boolean (str, "annex-t", &val) || val))
3053 context->flags |= CODEC_FLAG_AC_PRED;
3055 context->flags &= ~CODEC_FLAG_AC_PRED;
3056 if (!gst_structure_get_boolean (str, "annex-j", &val) || val)
3057 context->flags |= CODEC_FLAG_LOOP_FILTER;
3059 context->flags &= ~CODEC_FLAG_LOOP_FILTER;
3062 case AV_CODEC_ID_ADPCM_G726:
3064 const gchar *layout;
3066 if ((layout = gst_structure_get_string (str, "layout"))) {
3067 if (!strcmp (layout, "g721")) {
3068 context->sample_rate = 8000;
3069 context->channels = 1;
3070 context->bit_rate = 32000;
3079 if (!gst_caps_is_fixed (caps))
3082 /* common properties (width, height, fps) */
3083 switch (codec_type) {
3084 case AVMEDIA_TYPE_VIDEO:
3085 gst_ffmpeg_caps_to_pixfmt (caps, context,
3086 codec_id == AV_CODEC_ID_RAWVIDEO);
3088 case AVMEDIA_TYPE_AUDIO:
3089 gst_ffmpeg_caps_to_smpfmt (caps, context, FALSE);
3095 /* fixup of default settings */
3097 case AV_CODEC_ID_QCELP:
3098 /* QCELP is always mono, no matter what the caps say */
3099 context->channels = 1;
3101 case AV_CODEC_ID_ADPCM_G726:
3102 if (context->sample_rate && context->bit_rate)
3103 context->bits_per_coded_sample =
3104 context->bit_rate / context->sample_rate;
3111 /* _formatid_to_caps () is meant for muxers/demuxers, it
3112 * transforms a name (ffmpeg way of ID'ing these, why don't
3113 * they have unique numerical IDs?) to the corresponding
3114 * caps belonging to that mux-format
3116 * Note: we don't need any additional info because the caps
3117 * isn't supposed to contain any useful info besides the
3122 gst_ffmpeg_formatid_to_caps (const gchar * format_name)
3124 GstCaps *caps = NULL;
3126 if (!strcmp (format_name, "mpeg")) {
3127 caps = gst_caps_new_simple ("video/mpeg",
3128 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3129 } else if (!strcmp (format_name, "mpegts")) {
3130 caps = gst_caps_new_simple ("video/mpegts",
3131 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3132 } else if (!strcmp (format_name, "rm")) {
3133 caps = gst_caps_new_simple ("application/x-pn-realmedia",
3134 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3135 } else if (!strcmp (format_name, "asf")) {
3136 caps = gst_caps_new_empty_simple ("video/x-ms-asf");
3137 } else if (!strcmp (format_name, "avi")) {
3138 caps = gst_caps_new_empty_simple ("video/x-msvideo");
3139 } else if (!strcmp (format_name, "wav")) {
3140 caps = gst_caps_new_empty_simple ("audio/x-wav");
3141 } else if (!strcmp (format_name, "ape")) {
3142 caps = gst_caps_new_empty_simple ("application/x-ape");
3143 } else if (!strcmp (format_name, "swf")) {
3144 caps = gst_caps_new_empty_simple ("application/x-shockwave-flash");
3145 } else if (!strcmp (format_name, "au")) {
3146 caps = gst_caps_new_empty_simple ("audio/x-au");
3147 } else if (!strcmp (format_name, "dv")) {
3148 caps = gst_caps_new_simple ("video/x-dv",
3149 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3150 } else if (!strcmp (format_name, "4xm")) {
3151 caps = gst_caps_new_empty_simple ("video/x-4xm");
3152 } else if (!strcmp (format_name, "matroska")) {
3153 caps = gst_caps_new_empty_simple ("video/x-matroska");
3154 } else if (!strcmp (format_name, "mp3")) {
3155 caps = gst_caps_new_empty_simple ("application/x-id3");
3156 } else if (!strcmp (format_name, "flic")) {
3157 caps = gst_caps_new_empty_simple ("video/x-fli");
3158 } else if (!strcmp (format_name, "flv")) {
3159 caps = gst_caps_new_empty_simple ("video/x-flv");
3160 } else if (!strcmp (format_name, "tta")) {
3161 caps = gst_caps_new_empty_simple ("audio/x-ttafile");
3162 } else if (!strcmp (format_name, "aiff")) {
3163 caps = gst_caps_new_empty_simple ("audio/x-aiff");
3164 } else if (!strcmp (format_name, "mov_mp4_m4a_3gp_3g2")) {
3166 gst_caps_from_string
3167 ("application/x-3gp; video/quicktime; audio/x-m4a");
3168 } else if (!strcmp (format_name, "mov")) {
3169 caps = gst_caps_from_string ("video/quicktime,variant=(string)apple");
3170 } else if (!strcmp (format_name, "mp4")) {
3171 caps = gst_caps_from_string ("video/quicktime,variant=(string)iso");
3172 } else if (!strcmp (format_name, "3gp")) {
3173 caps = gst_caps_from_string ("video/quicktime,variant=(string)3gpp");
3174 } else if (!strcmp (format_name, "3g2")) {
3175 caps = gst_caps_from_string ("video/quicktime,variant=(string)3g2");
3176 } else if (!strcmp (format_name, "psp")) {
3177 caps = gst_caps_from_string ("video/quicktime,variant=(string)psp");
3178 } else if (!strcmp (format_name, "ipod")) {
3179 caps = gst_caps_from_string ("video/quicktime,variant=(string)ipod");
3180 } else if (!strcmp (format_name, "aac")) {
3181 caps = gst_caps_new_simple ("audio/mpeg",
3182 "mpegversion", G_TYPE_INT, 4, NULL);
3183 } else if (!strcmp (format_name, "gif")) {
3184 caps = gst_caps_from_string ("image/gif");
3185 } else if (!strcmp (format_name, "ogg")) {
3186 caps = gst_caps_from_string ("application/ogg");
3187 } else if (!strcmp (format_name, "mxf") || !strcmp (format_name, "mxf_d10")) {
3188 caps = gst_caps_from_string ("application/mxf");
3189 } else if (!strcmp (format_name, "gxf")) {
3190 caps = gst_caps_from_string ("application/gxf");
3191 } else if (!strcmp (format_name, "yuv4mpegpipe")) {
3192 caps = gst_caps_new_simple ("application/x-yuv4mpeg",
3193 "y4mversion", G_TYPE_INT, 2, NULL);
3194 } else if (!strcmp (format_name, "mpc")) {
3195 caps = gst_caps_from_string ("audio/x-musepack, streamversion = (int) 7");
3196 } else if (!strcmp (format_name, "vqf")) {
3197 caps = gst_caps_from_string ("audio/x-vqf");
3198 } else if (!strcmp (format_name, "nsv")) {
3199 caps = gst_caps_from_string ("video/x-nsv");
3200 } else if (!strcmp (format_name, "amr")) {
3201 caps = gst_caps_from_string ("audio/x-amr-nb-sh");
3202 } else if (!strcmp (format_name, "webm")) {
3203 caps = gst_caps_from_string ("video/webm");
3204 } else if (!strcmp (format_name, "voc")) {
3205 caps = gst_caps_from_string ("audio/x-voc");
3206 } else if (!strcmp (format_name, "pva")) {
3207 caps = gst_caps_from_string ("video/x-pva");
3211 GST_LOG ("Could not create stream format caps for %s", format_name);
3212 name = g_strdup_printf ("application/x-gst-av-%s", format_name);
3213 caps = gst_caps_new_empty_simple (name);
3221 gst_ffmpeg_formatid_get_codecids (const gchar * format_name,
3222 enum AVCodecID ** video_codec_list, enum AVCodecID ** audio_codec_list,
3223 AVOutputFormat * plugin)
3225 static enum AVCodecID tmp_vlist[] = {
3229 static enum AVCodecID tmp_alist[] = {
3234 GST_LOG ("format_name : %s", format_name);
3236 if (!strcmp (format_name, "mp4")) {
3237 static enum AVCodecID mp4_video_list[] = {
3238 AV_CODEC_ID_MPEG4, AV_CODEC_ID_H264,
3242 static enum AVCodecID mp4_audio_list[] = {
3243 AV_CODEC_ID_AAC, AV_CODEC_ID_MP3,
3247 *video_codec_list = mp4_video_list;
3248 *audio_codec_list = mp4_audio_list;
3249 } else if (!strcmp (format_name, "mpeg")) {
3250 static enum AVCodecID mpeg_video_list[] = { AV_CODEC_ID_MPEG1VIDEO,
3251 AV_CODEC_ID_MPEG2VIDEO,
3255 static enum AVCodecID mpeg_audio_list[] = { AV_CODEC_ID_MP1,
3261 *video_codec_list = mpeg_video_list;
3262 *audio_codec_list = mpeg_audio_list;
3263 } else if (!strcmp (format_name, "dvd")) {
3264 static enum AVCodecID mpeg_video_list[] = { AV_CODEC_ID_MPEG2VIDEO,
3267 static enum AVCodecID mpeg_audio_list[] = { AV_CODEC_ID_MP2,
3270 AV_CODEC_ID_PCM_S16BE,
3274 *video_codec_list = mpeg_video_list;
3275 *audio_codec_list = mpeg_audio_list;
3276 } else if (!strcmp (format_name, "mpegts")) {
3277 static enum AVCodecID mpegts_video_list[] = { AV_CODEC_ID_MPEG1VIDEO,
3278 AV_CODEC_ID_MPEG2VIDEO,
3282 static enum AVCodecID mpegts_audio_list[] = { AV_CODEC_ID_MP2,
3290 *video_codec_list = mpegts_video_list;
3291 *audio_codec_list = mpegts_audio_list;
3292 } else if (!strcmp (format_name, "vob")) {
3293 static enum AVCodecID vob_video_list[] =
3294 { AV_CODEC_ID_MPEG2VIDEO, AV_CODEC_ID_NONE };
3295 static enum AVCodecID vob_audio_list[] = { AV_CODEC_ID_MP2, AV_CODEC_ID_AC3,
3296 AV_CODEC_ID_DTS, AV_CODEC_ID_NONE
3299 *video_codec_list = vob_video_list;
3300 *audio_codec_list = vob_audio_list;
3301 } else if (!strcmp (format_name, "flv")) {
3302 static enum AVCodecID flv_video_list[] =
3303 { AV_CODEC_ID_FLV1, AV_CODEC_ID_NONE };
3304 static enum AVCodecID flv_audio_list[] =
3305 { AV_CODEC_ID_MP3, AV_CODEC_ID_NONE };
3307 *video_codec_list = flv_video_list;
3308 *audio_codec_list = flv_audio_list;
3309 } else if (!strcmp (format_name, "asf")) {
3310 static enum AVCodecID asf_video_list[] =
3311 { AV_CODEC_ID_WMV1, AV_CODEC_ID_WMV2, AV_CODEC_ID_MSMPEG4V3,
3314 static enum AVCodecID asf_audio_list[] =
3315 { AV_CODEC_ID_WMAV1, AV_CODEC_ID_WMAV2, AV_CODEC_ID_MP3,
3319 *video_codec_list = asf_video_list;
3320 *audio_codec_list = asf_audio_list;
3321 } else if (!strcmp (format_name, "dv")) {
3322 static enum AVCodecID dv_video_list[] =
3323 { AV_CODEC_ID_DVVIDEO, AV_CODEC_ID_NONE };
3324 static enum AVCodecID dv_audio_list[] =
3325 { AV_CODEC_ID_PCM_S16LE, AV_CODEC_ID_NONE };
3327 *video_codec_list = dv_video_list;
3328 *audio_codec_list = dv_audio_list;
3329 } else if (!strcmp (format_name, "mov")) {
3330 static enum AVCodecID mov_video_list[] = {
3331 AV_CODEC_ID_SVQ1, AV_CODEC_ID_SVQ3, AV_CODEC_ID_MPEG4,
3332 AV_CODEC_ID_H263, AV_CODEC_ID_H263P,
3333 AV_CODEC_ID_H264, AV_CODEC_ID_DVVIDEO,
3337 static enum AVCodecID mov_audio_list[] = {
3338 AV_CODEC_ID_PCM_MULAW, AV_CODEC_ID_PCM_ALAW, AV_CODEC_ID_ADPCM_IMA_QT,
3339 AV_CODEC_ID_MACE3, AV_CODEC_ID_MACE6, AV_CODEC_ID_AAC,
3340 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3341 AV_CODEC_ID_PCM_S16BE, AV_CODEC_ID_PCM_S16LE,
3342 AV_CODEC_ID_MP3, AV_CODEC_ID_NONE
3345 *video_codec_list = mov_video_list;
3346 *audio_codec_list = mov_audio_list;
3347 } else if ((!strcmp (format_name, "3gp") || !strcmp (format_name, "3g2"))) {
3348 static enum AVCodecID tgp_video_list[] = {
3349 AV_CODEC_ID_MPEG4, AV_CODEC_ID_H263, AV_CODEC_ID_H263P, AV_CODEC_ID_H264,
3352 static enum AVCodecID tgp_audio_list[] = {
3353 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3358 *video_codec_list = tgp_video_list;
3359 *audio_codec_list = tgp_audio_list;
3360 } else if (!strcmp (format_name, "mmf")) {
3361 static enum AVCodecID mmf_audio_list[] = {
3362 AV_CODEC_ID_ADPCM_YAMAHA, AV_CODEC_ID_NONE
3364 *video_codec_list = NULL;
3365 *audio_codec_list = mmf_audio_list;
3366 } else if (!strcmp (format_name, "amr")) {
3367 static enum AVCodecID amr_audio_list[] = {
3368 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3371 *video_codec_list = NULL;
3372 *audio_codec_list = amr_audio_list;
3373 } else if (!strcmp (format_name, "gif")) {
3374 static enum AVCodecID gif_image_list[] = {
3375 AV_CODEC_ID_RAWVIDEO, AV_CODEC_ID_NONE
3377 *video_codec_list = gif_image_list;
3378 *audio_codec_list = NULL;
3379 } else if ((plugin->audio_codec != AV_CODEC_ID_NONE) ||
3380 (plugin->video_codec != AV_CODEC_ID_NONE)) {
3381 tmp_vlist[0] = plugin->video_codec;
3382 tmp_alist[0] = plugin->audio_codec;
3384 *video_codec_list = tmp_vlist;
3385 *audio_codec_list = tmp_alist;
3386 } else if ((!strcmp (format_name, "pva"))) {
3387 static enum AVCodecID tgp_video_list[] = {
3388 AV_CODEC_ID_MPEG2VIDEO,
3391 static enum AVCodecID tgp_audio_list[] = {
3396 *video_codec_list = tgp_video_list;
3397 *audio_codec_list = tgp_audio_list;
3399 GST_LOG ("Format %s not found", format_name);
3406 /* Convert a GstCaps to a FFMPEG codec ID. Size et all
3407 * are omitted, that can be queried by the user itself,
3408 * we're not eating the GstCaps or anything
3409 * A pointer to an allocated context is also needed for
3410 * optional extra info
3414 gst_ffmpeg_caps_to_codecid (const GstCaps * caps, AVCodecContext * context)
3416 enum AVCodecID id = AV_CODEC_ID_NONE;
3417 const gchar *mimetype;
3418 const GstStructure *structure;
3419 gboolean video = FALSE, audio = FALSE; /* we want to be sure! */
3421 g_return_val_if_fail (caps != NULL, AV_CODEC_ID_NONE);
3422 g_return_val_if_fail (gst_caps_get_size (caps) == 1, AV_CODEC_ID_NONE);
3423 structure = gst_caps_get_structure (caps, 0);
3425 mimetype = gst_structure_get_name (structure);
3427 if (!strcmp (mimetype, "video/x-raw")) {
3428 id = AV_CODEC_ID_RAWVIDEO;
3430 } else if (!strcmp (mimetype, "audio/x-raw")) {
3433 if (gst_audio_info_from_caps (&info, caps)) {
3434 switch (GST_AUDIO_INFO_FORMAT (&info)) {
3435 case GST_AUDIO_FORMAT_S8:
3436 id = AV_CODEC_ID_PCM_S8;
3438 case GST_AUDIO_FORMAT_U8:
3439 id = AV_CODEC_ID_PCM_U8;
3441 case GST_AUDIO_FORMAT_S16LE:
3442 id = AV_CODEC_ID_PCM_S16LE;
3444 case GST_AUDIO_FORMAT_S16BE:
3445 id = AV_CODEC_ID_PCM_S16BE;
3447 case GST_AUDIO_FORMAT_U16LE:
3448 id = AV_CODEC_ID_PCM_U16LE;
3450 case GST_AUDIO_FORMAT_U16BE:
3451 id = AV_CODEC_ID_PCM_U16BE;
3456 if (id != AV_CODEC_ID_NONE)
3459 } else if (!strcmp (mimetype, "audio/x-mulaw")) {
3460 id = AV_CODEC_ID_PCM_MULAW;
3462 } else if (!strcmp (mimetype, "audio/x-alaw")) {
3463 id = AV_CODEC_ID_PCM_ALAW;
3465 } else if (!strcmp (mimetype, "video/x-dv")) {
3468 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3470 id = AV_CODEC_ID_DVVIDEO;
3473 } else if (!strcmp (mimetype, "audio/x-dv")) { /* ??? */
3474 id = AV_CODEC_ID_DVAUDIO;
3476 } else if (!strcmp (mimetype, "video/x-h263")) {
3477 const gchar *h263version =
3478 gst_structure_get_string (structure, "h263version");
3479 if (h263version && !strcmp (h263version, "h263p"))
3480 id = AV_CODEC_ID_H263P;
3482 id = AV_CODEC_ID_H263;
3484 } else if (!strcmp (mimetype, "video/x-intel-h263")) {
3485 id = AV_CODEC_ID_H263I;
3487 } else if (!strcmp (mimetype, "video/x-h261")) {
3488 id = AV_CODEC_ID_H261;
3490 } else if (!strcmp (mimetype, "video/mpeg")) {
3494 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3495 gst_structure_get_int (structure, "mpegversion", &mpegversion) &&
3497 switch (mpegversion) {
3499 id = AV_CODEC_ID_MPEG1VIDEO;
3502 id = AV_CODEC_ID_MPEG2VIDEO;
3505 id = AV_CODEC_ID_MPEG4;
3509 if (id != AV_CODEC_ID_NONE)
3511 } else if (!strcmp (mimetype, "image/jpeg")) {
3512 id = AV_CODEC_ID_MJPEG; /* A... B... */
3514 } else if (!strcmp (mimetype, "video/x-jpeg-b")) {
3515 id = AV_CODEC_ID_MJPEGB;
3517 } else if (!strcmp (mimetype, "video/x-wmv")) {
3518 gint wmvversion = 0;
3520 if (gst_structure_get_int (structure, "wmvversion", &wmvversion)) {
3521 switch (wmvversion) {
3523 id = AV_CODEC_ID_WMV1;
3526 id = AV_CODEC_ID_WMV2;
3530 const gchar *format;
3532 /* WMV3 unless the fourcc exists and says otherwise */
3533 id = AV_CODEC_ID_WMV3;
3535 if ((format = gst_structure_get_string (structure, "format")) &&
3536 (g_str_equal (format, "WVC1") || g_str_equal (format, "WMVA")))
3537 id = AV_CODEC_ID_VC1;
3543 if (id != AV_CODEC_ID_NONE)
3545 } else if (!strcmp (mimetype, "audio/x-vorbis")) {
3546 id = AV_CODEC_ID_VORBIS;
3548 } else if (!strcmp (mimetype, "audio/x-qdm2")) {
3549 id = AV_CODEC_ID_QDM2;
3551 } else if (!strcmp (mimetype, "audio/mpeg")) {
3553 gint mpegversion = 0;
3555 if (gst_structure_get_int (structure, "mpegversion", &mpegversion)) {
3556 switch (mpegversion) {
3557 case 2: /* ffmpeg uses faad for both... */
3559 id = AV_CODEC_ID_AAC;
3562 if (gst_structure_get_int (structure, "layer", &layer)) {
3565 id = AV_CODEC_ID_MP1;
3568 id = AV_CODEC_ID_MP2;
3571 id = AV_CODEC_ID_MP3;
3577 if (id != AV_CODEC_ID_NONE)
3579 } else if (!strcmp (mimetype, "audio/x-musepack")) {
3580 gint streamversion = -1;
3582 if (gst_structure_get_int (structure, "streamversion", &streamversion)) {
3583 if (streamversion == 7)
3584 id = AV_CODEC_ID_MUSEPACK7;
3586 id = AV_CODEC_ID_MUSEPACK7;
3588 } else if (!strcmp (mimetype, "audio/x-wma")) {
3589 gint wmaversion = 0;
3591 if (gst_structure_get_int (structure, "wmaversion", &wmaversion)) {
3592 switch (wmaversion) {
3594 id = AV_CODEC_ID_WMAV1;
3597 id = AV_CODEC_ID_WMAV2;
3600 id = AV_CODEC_ID_WMAPRO;
3604 if (id != AV_CODEC_ID_NONE)
3606 } else if (!strcmp (mimetype, "audio/x-wms")) {
3607 id = AV_CODEC_ID_WMAVOICE;
3609 } else if (!strcmp (mimetype, "audio/x-ac3")) {
3610 id = AV_CODEC_ID_AC3;
3612 } else if (!strcmp (mimetype, "audio/x-eac3")) {
3613 id = AV_CODEC_ID_EAC3;
3615 } else if (!strcmp (mimetype, "audio/x-vnd.sony.atrac3") ||
3616 !strcmp (mimetype, "audio/atrac3")) {
3617 id = AV_CODEC_ID_ATRAC3;
3619 } else if (!strcmp (mimetype, "audio/x-dts")) {
3620 id = AV_CODEC_ID_DTS;
3622 } else if (!strcmp (mimetype, "application/x-ape")) {
3623 id = AV_CODEC_ID_APE;
3625 } else if (!strcmp (mimetype, "video/x-msmpeg")) {
3626 gint msmpegversion = 0;
3628 if (gst_structure_get_int (structure, "msmpegversion", &msmpegversion)) {
3629 switch (msmpegversion) {
3631 id = AV_CODEC_ID_MSMPEG4V1;
3634 id = AV_CODEC_ID_MSMPEG4V2;
3637 id = AV_CODEC_ID_MSMPEG4V3;
3641 if (id != AV_CODEC_ID_NONE)
3643 } else if (!strcmp (mimetype, "video/x-svq")) {
3644 gint svqversion = 0;
3646 if (gst_structure_get_int (structure, "svqversion", &svqversion)) {
3647 switch (svqversion) {
3649 id = AV_CODEC_ID_SVQ1;
3652 id = AV_CODEC_ID_SVQ3;
3656 if (id != AV_CODEC_ID_NONE)
3658 } else if (!strcmp (mimetype, "video/x-huffyuv")) {
3659 id = AV_CODEC_ID_HUFFYUV;
3661 } else if (!strcmp (mimetype, "audio/x-mace")) {
3662 gint maceversion = 0;
3664 if (gst_structure_get_int (structure, "maceversion", &maceversion)) {
3665 switch (maceversion) {
3667 id = AV_CODEC_ID_MACE3;
3670 id = AV_CODEC_ID_MACE6;
3674 if (id != AV_CODEC_ID_NONE)
3676 } else if (!strcmp (mimetype, "video/x-theora")) {
3677 id = AV_CODEC_ID_THEORA;
3679 } else if (!strcmp (mimetype, "video/x-vp3")) {
3680 id = AV_CODEC_ID_VP3;
3682 } else if (!strcmp (mimetype, "video/x-vp5")) {
3683 id = AV_CODEC_ID_VP5;
3685 } else if (!strcmp (mimetype, "video/x-vp6")) {
3686 id = AV_CODEC_ID_VP6;
3688 } else if (!strcmp (mimetype, "video/x-vp6-flash")) {
3689 id = AV_CODEC_ID_VP6F;
3691 } else if (!strcmp (mimetype, "video/x-vp6-alpha")) {
3692 id = AV_CODEC_ID_VP6A;
3694 } else if (!strcmp (mimetype, "video/x-vp8")) {
3695 id = AV_CODEC_ID_VP8;
3697 } else if (!strcmp (mimetype, "video/x-flash-screen")) {
3698 id = AV_CODEC_ID_FLASHSV;
3700 } else if (!strcmp (mimetype, "video/x-indeo")) {
3701 gint indeoversion = 0;
3703 if (gst_structure_get_int (structure, "indeoversion", &indeoversion)) {
3704 switch (indeoversion) {
3706 id = AV_CODEC_ID_INDEO5;
3709 id = AV_CODEC_ID_INDEO4;
3712 id = AV_CODEC_ID_INDEO3;
3715 id = AV_CODEC_ID_INDEO2;
3718 if (id != AV_CODEC_ID_NONE)
3721 } else if (!strcmp (mimetype, "video/x-divx")) {
3722 gint divxversion = 0;
3724 if (gst_structure_get_int (structure, "divxversion", &divxversion)) {
3725 switch (divxversion) {
3727 id = AV_CODEC_ID_MSMPEG4V3;
3731 id = AV_CODEC_ID_MPEG4;
3735 if (id != AV_CODEC_ID_NONE)
3737 } else if (!strcmp (mimetype, "video/x-3ivx")) {
3738 id = AV_CODEC_ID_MPEG4;
3740 } else if (!strcmp (mimetype, "video/x-xvid")) {
3741 id = AV_CODEC_ID_MPEG4;
3743 } else if (!strcmp (mimetype, "video/x-ffv")) {
3744 gint ffvversion = 0;
3746 if (gst_structure_get_int (structure, "ffvversion", &ffvversion) &&
3748 id = AV_CODEC_ID_FFV1;
3751 } else if (!strcmp (mimetype, "video/x-apple-intermediate-codec")) {
3752 id = AV_CODEC_ID_AIC;
3754 } else if (!strcmp (mimetype, "audio/x-adpcm")) {
3755 const gchar *layout;
3757 layout = gst_structure_get_string (structure, "layout");
3758 if (layout == NULL) {
3760 } else if (!strcmp (layout, "quicktime")) {
3761 id = AV_CODEC_ID_ADPCM_IMA_QT;
3762 } else if (!strcmp (layout, "microsoft")) {
3763 id = AV_CODEC_ID_ADPCM_MS;
3764 } else if (!strcmp (layout, "dvi")) {
3765 id = AV_CODEC_ID_ADPCM_IMA_WAV;
3766 } else if (!strcmp (layout, "4xm")) {
3767 id = AV_CODEC_ID_ADPCM_4XM;
3768 } else if (!strcmp (layout, "smjpeg")) {
3769 id = AV_CODEC_ID_ADPCM_IMA_SMJPEG;
3770 } else if (!strcmp (layout, "dk3")) {
3771 id = AV_CODEC_ID_ADPCM_IMA_DK3;
3772 } else if (!strcmp (layout, "dk4")) {
3773 id = AV_CODEC_ID_ADPCM_IMA_DK4;
3774 } else if (!strcmp (layout, "westwood")) {
3775 id = AV_CODEC_ID_ADPCM_IMA_WS;
3776 } else if (!strcmp (layout, "iss")) {
3777 id = AV_CODEC_ID_ADPCM_IMA_ISS;
3778 } else if (!strcmp (layout, "xa")) {
3779 id = AV_CODEC_ID_ADPCM_XA;
3780 } else if (!strcmp (layout, "adx")) {
3781 id = AV_CODEC_ID_ADPCM_ADX;
3782 } else if (!strcmp (layout, "ea")) {
3783 id = AV_CODEC_ID_ADPCM_EA;
3784 } else if (!strcmp (layout, "g726")) {
3785 id = AV_CODEC_ID_ADPCM_G726;
3786 } else if (!strcmp (layout, "g721")) {
3787 id = AV_CODEC_ID_ADPCM_G726;
3788 } else if (!strcmp (layout, "ct")) {
3789 id = AV_CODEC_ID_ADPCM_CT;
3790 } else if (!strcmp (layout, "swf")) {
3791 id = AV_CODEC_ID_ADPCM_SWF;
3792 } else if (!strcmp (layout, "yamaha")) {
3793 id = AV_CODEC_ID_ADPCM_YAMAHA;
3794 } else if (!strcmp (layout, "sbpro2")) {
3795 id = AV_CODEC_ID_ADPCM_SBPRO_2;
3796 } else if (!strcmp (layout, "sbpro3")) {
3797 id = AV_CODEC_ID_ADPCM_SBPRO_3;
3798 } else if (!strcmp (layout, "sbpro4")) {
3799 id = AV_CODEC_ID_ADPCM_SBPRO_4;
3801 if (id != AV_CODEC_ID_NONE)
3803 } else if (!strcmp (mimetype, "video/x-4xm")) {
3804 id = AV_CODEC_ID_4XM;
3806 } else if (!strcmp (mimetype, "audio/x-dpcm")) {
3807 const gchar *layout;
3809 layout = gst_structure_get_string (structure, "layout");
3812 } else if (!strcmp (layout, "roq")) {
3813 id = AV_CODEC_ID_ROQ_DPCM;
3814 } else if (!strcmp (layout, "interplay")) {
3815 id = AV_CODEC_ID_INTERPLAY_DPCM;
3816 } else if (!strcmp (layout, "xan")) {
3817 id = AV_CODEC_ID_XAN_DPCM;
3818 } else if (!strcmp (layout, "sol")) {
3819 id = AV_CODEC_ID_SOL_DPCM;
3821 if (id != AV_CODEC_ID_NONE)
3823 } else if (!strcmp (mimetype, "audio/x-flac")) {
3824 id = AV_CODEC_ID_FLAC;
3826 } else if (!strcmp (mimetype, "audio/x-shorten")) {
3827 id = AV_CODEC_ID_SHORTEN;
3829 } else if (!strcmp (mimetype, "audio/x-alac")) {
3830 id = AV_CODEC_ID_ALAC;
3832 } else if (!strcmp (mimetype, "video/x-cinepak")) {
3833 id = AV_CODEC_ID_CINEPAK;
3835 } else if (!strcmp (mimetype, "video/x-pn-realvideo")) {
3838 if (gst_structure_get_int (structure, "rmversion", &rmversion)) {
3839 switch (rmversion) {
3841 id = AV_CODEC_ID_RV10;
3844 id = AV_CODEC_ID_RV20;
3847 id = AV_CODEC_ID_RV30;
3850 id = AV_CODEC_ID_RV40;
3854 if (id != AV_CODEC_ID_NONE)
3856 } else if (!strcmp (mimetype, "audio/x-sipro")) {
3857 id = AV_CODEC_ID_SIPR;
3859 } else if (!strcmp (mimetype, "audio/x-pn-realaudio")) {
3862 if (gst_structure_get_int (structure, "raversion", &raversion)) {
3863 switch (raversion) {
3865 id = AV_CODEC_ID_RA_144;
3868 id = AV_CODEC_ID_RA_288;
3871 id = AV_CODEC_ID_COOK;
3875 if (id != AV_CODEC_ID_NONE)
3877 } else if (!strcmp (mimetype, "video/x-rle")) {
3878 const gchar *layout;
3880 if ((layout = gst_structure_get_string (structure, "layout"))) {
3881 if (!strcmp (layout, "microsoft")) {
3882 id = AV_CODEC_ID_MSRLE;
3886 } else if (!strcmp (mimetype, "video/x-xan")) {
3889 if ((gst_structure_get_int (structure, "wcversion", &wcversion))) {
3890 switch (wcversion) {
3892 id = AV_CODEC_ID_XAN_WC3;
3896 id = AV_CODEC_ID_XAN_WC4;
3903 } else if (!strcmp (mimetype, "audio/AMR")) {
3905 id = AV_CODEC_ID_AMR_NB;
3906 } else if (!strcmp (mimetype, "audio/AMR-WB")) {
3907 id = AV_CODEC_ID_AMR_WB;
3909 } else if (!strcmp (mimetype, "audio/qcelp")) {
3910 id = AV_CODEC_ID_QCELP;
3912 } else if (!strcmp (mimetype, "video/x-h264")) {
3913 id = AV_CODEC_ID_H264;
3915 } else if (!strcmp (mimetype, "video/x-h265")) {
3916 id = AV_CODEC_ID_HEVC;
3918 } else if (!strcmp (mimetype, "video/x-flash-video")) {
3919 gint flvversion = 0;
3921 if ((gst_structure_get_int (structure, "flvversion", &flvversion))) {
3922 switch (flvversion) {
3924 id = AV_CODEC_ID_FLV1;
3932 } else if (!strcmp (mimetype, "audio/x-nellymoser")) {
3933 id = AV_CODEC_ID_NELLYMOSER;
3935 } else if (!strncmp (mimetype, "audio/x-gst-av-", 15)) {
3939 if (strlen (mimetype) <= 30 &&
3940 sscanf (mimetype, "audio/x-gst-av-%s", ext) == 1) {
3941 if ((codec = avcodec_find_decoder_by_name (ext)) ||
3942 (codec = avcodec_find_encoder_by_name (ext))) {
3947 } else if (!strncmp (mimetype, "video/x-gst-av-", 15)) {
3951 if (strlen (mimetype) <= 30 &&
3952 sscanf (mimetype, "video/x-gst-av-%s", ext) == 1) {
3953 if ((codec = avcodec_find_decoder_by_name (ext)) ||
3954 (codec = avcodec_find_encoder_by_name (ext))) {
3961 if (context != NULL) {
3962 if (video == TRUE) {
3963 context->codec_type = AVMEDIA_TYPE_VIDEO;
3964 } else if (audio == TRUE) {
3965 context->codec_type = AVMEDIA_TYPE_AUDIO;
3967 context->codec_type = AVMEDIA_TYPE_UNKNOWN;
3969 context->codec_id = id;
3970 gst_ffmpeg_caps_with_codecid (id, context->codec_type, caps, context);
3973 if (id != AV_CODEC_ID_NONE) {
3974 GST_DEBUG ("The id=%d belongs to the caps %" GST_PTR_FORMAT, id, caps);
3976 GST_WARNING ("Couldn't figure out the id for caps %" GST_PTR_FORMAT, caps);