2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
4 * Copyright (c) 2002-2004 Ronald Bultje <rbultje@ronald.bitfreak.net>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
29 #include <libavcodec/avcodec.h>
30 #include <libavutil/channel_layout.h>
33 #include "gstavcodecmap.h"
35 #include <gst/video/video.h>
36 #include <gst/audio/audio.h>
37 #include <gst/pbutils/codec-utils.h>
39 /* IMPORTANT: Keep this sorted by the ffmpeg channel masks */
43 GstAudioChannelPosition gst;
44 } _ff_to_gst_layout[] = {
46 AV_CH_FRONT_LEFT, GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT}, {
47 AV_CH_FRONT_RIGHT, GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT}, {
48 AV_CH_FRONT_CENTER, GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER}, {
49 AV_CH_LOW_FREQUENCY, GST_AUDIO_CHANNEL_POSITION_LFE1}, {
50 AV_CH_BACK_LEFT, GST_AUDIO_CHANNEL_POSITION_REAR_LEFT}, {
51 AV_CH_BACK_RIGHT, GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT}, {
52 AV_CH_FRONT_LEFT_OF_CENTER, GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER}, {
53 AV_CH_FRONT_RIGHT_OF_CENTER,
54 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER}, {
55 AV_CH_BACK_CENTER, GST_AUDIO_CHANNEL_POSITION_REAR_CENTER}, {
56 AV_CH_SIDE_LEFT, GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT}, {
57 AV_CH_SIDE_RIGHT, GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT}, {
58 AV_CH_TOP_CENTER, GST_AUDIO_CHANNEL_POSITION_TOP_CENTER}, {
59 AV_CH_TOP_FRONT_LEFT, GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_LEFT}, {
60 AV_CH_TOP_FRONT_CENTER, GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_CENTER}, {
61 AV_CH_TOP_FRONT_RIGHT, GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_RIGHT}, {
62 AV_CH_TOP_BACK_LEFT, GST_AUDIO_CHANNEL_POSITION_TOP_REAR_LEFT}, {
63 AV_CH_TOP_BACK_CENTER, GST_AUDIO_CHANNEL_POSITION_TOP_REAR_CENTER}, {
64 AV_CH_TOP_BACK_RIGHT, GST_AUDIO_CHANNEL_POSITION_TOP_REAR_RIGHT}, {
65 AV_CH_STEREO_LEFT, GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT}, {
66 AV_CH_STEREO_RIGHT, GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT}
70 gst_ffmpeg_compliance_get_type (void)
72 static GType ffmpeg_compliance_type = 0;
73 static const GEnumValue compliance_types[] = {
74 {GST_FFMPEG_VERY_STRICT, "Strictly conform to older spec",
76 {GST_FFMPEG_STRICT, "Strictly conform to current spec", "strict"},
77 {GST_FFMPEG_NORMAL, "Normal behavior", "normal"},
78 {GST_FFMPEG_UNOFFICIAL, "Allow unofficial extensions", "unofficial"},
79 {GST_FFMPEG_EXPERIMENTAL, "Allow nonstandardized experimental things",
84 if (!ffmpeg_compliance_type) {
85 ffmpeg_compliance_type =
86 g_enum_register_static ("GstFFMpegCompliance", compliance_types);
88 return ffmpeg_compliance_type;
92 gst_ffmpeg_channel_positions_to_layout (GstAudioChannelPosition * pos,
97 gint channels_found = 0;
102 for (i = 0; i < channels; i++) {
103 for (j = 0; j < G_N_ELEMENTS (_ff_to_gst_layout); j++) {
104 if (_ff_to_gst_layout[j].gst == pos[i]) {
105 ret |= _ff_to_gst_layout[j].ff;
112 if (channels_found != channels)
118 gst_ffmpeg_channel_layout_to_gst (guint64 channel_layout, gint channels,
119 GstAudioChannelPosition * pos)
122 gboolean none_layout = FALSE;
124 if (channel_layout == 0) {
125 nchannels = channels;
130 for (i = 0; i < 64; i++) {
131 if ((channel_layout & (G_GUINT64_CONSTANT (1) << i)) != 0) {
136 if (nchannels != channels) {
137 GST_ERROR ("Number of channels is different (%u != %u)", channels,
139 nchannels = channels;
143 for (i = 0, j = 0; i < G_N_ELEMENTS (_ff_to_gst_layout); i++) {
144 if ((channel_layout & _ff_to_gst_layout[i].ff) != 0) {
145 pos[j++] = _ff_to_gst_layout[i].gst;
147 if (_ff_to_gst_layout[i].gst == GST_AUDIO_CHANNEL_POSITION_NONE)
152 if (j != nchannels) {
154 ("Unknown channels in channel layout - assuming NONE layout");
161 && !gst_audio_check_valid_channel_positions (pos, nchannels, FALSE)) {
162 GST_ERROR ("Invalid channel layout %" G_GUINT64_FORMAT
163 " - assuming NONE layout", channel_layout);
168 if (nchannels == 1) {
169 pos[0] = GST_AUDIO_CHANNEL_POSITION_MONO;
170 } else if (nchannels == 2) {
171 pos[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT;
172 pos[1] = GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT;
176 for (i = 0; i < nchannels; i++)
177 pos[i] = GST_AUDIO_CHANNEL_POSITION_NONE;
185 _gst_value_list_contains (const GValue * list, const GValue * value)
190 n = gst_value_list_get_size (list);
191 for (i = 0; i < n; i++) {
192 tmp = gst_value_list_get_value (list, i);
193 if (gst_value_compare (value, tmp) == GST_VALUE_EQUAL)
201 gst_ffmpeg_video_set_pix_fmts (GstCaps * caps, const enum AVPixelFormat *fmts)
205 GstVideoFormat format;
207 if (!fmts || fmts[0] == -1) {
210 g_value_init (&va, GST_TYPE_LIST);
211 g_value_init (&v, G_TYPE_STRING);
212 for (i = 0; i <= AV_PIX_FMT_NB; i++) {
213 format = gst_ffmpeg_pixfmt_to_videoformat (i);
214 if (format == GST_VIDEO_FORMAT_UNKNOWN)
216 g_value_set_string (&v, gst_video_format_to_string (format));
217 gst_value_list_append_value (&va, &v);
219 gst_caps_set_value (caps, "format", &va);
225 /* Only a single format */
226 g_value_init (&va, GST_TYPE_LIST);
227 g_value_init (&v, G_TYPE_STRING);
228 while (*fmts != -1) {
229 format = gst_ffmpeg_pixfmt_to_videoformat (*fmts);
230 if (format != GST_VIDEO_FORMAT_UNKNOWN) {
231 g_value_set_string (&v, gst_video_format_to_string (format));
232 /* Only append values we don't have yet */
233 if (!_gst_value_list_contains (&va, &v))
234 gst_value_list_append_value (&va, &v);
238 if (gst_value_list_get_size (&va) == 1) {
239 /* The single value is still in v */
240 gst_caps_set_value (caps, "format", &v);
241 } else if (gst_value_list_get_size (&va) > 1) {
242 gst_caps_set_value (caps, "format", &va);
248 /* this macro makes a caps width fixed or unfixed width/height
249 * properties depending on whether we've got a context.
251 * See below for why we use this.
253 * We should actually do this stuff at the end, like in riff-media.c,
254 * but I'm too lazy today. Maybe later.
257 gst_ff_vid_caps_new (AVCodecContext * context, AVCodec * codec,
258 enum AVCodecID codec_id, gboolean encode, const char *mimetype,
259 const char *fieldname, ...)
261 GstCaps *caps = NULL;
265 GST_LOG ("context:%p, codec_id:%d, mimetype:%s", context, codec_id, mimetype);
267 /* fixed, non probing context */
268 if (context != NULL && context->width != -1) {
271 caps = gst_caps_new_simple (mimetype,
272 "width", G_TYPE_INT, context->width,
273 "height", G_TYPE_INT, context->height, NULL);
275 num = context->time_base.den / context->ticks_per_frame;
276 denom = context->time_base.num;
279 GST_LOG ("invalid framerate: %d/0, -> %d/1", num, num);
282 if (gst_util_fraction_compare (num, denom, 1000, 1) > 0) {
283 GST_LOG ("excessive framerate: %d/%d, -> 0/1", num, denom);
287 GST_LOG ("setting framerate: %d/%d", num, denom);
288 gst_caps_set_simple (caps,
289 "framerate", GST_TYPE_FRACTION, num, denom, NULL);
291 /* so we are after restricted caps in this case */
293 case AV_CODEC_ID_H261:
295 caps = gst_caps_new_simple (mimetype,
296 "width", G_TYPE_INT, 352,
297 "height", G_TYPE_INT, 288,
298 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
299 gst_caps_append (caps, gst_caps_new_simple (mimetype,
300 "width", G_TYPE_INT, 176,
301 "height", G_TYPE_INT, 144,
302 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL));
305 case AV_CODEC_ID_H263:
307 /* 128x96, 176x144, 352x288, 704x576, and 1408x1152. slightly reordered
308 * because we want automatic negotiation to go as close to 320x240 as
310 const static gint widths[] = { 352, 704, 176, 1408, 128 };
311 const static gint heights[] = { 288, 576, 144, 1152, 96 };
313 gint n_sizes = G_N_ELEMENTS (widths);
315 caps = gst_caps_new_empty ();
316 for (i = 0; i < n_sizes; i++) {
317 temp = gst_caps_new_simple (mimetype,
318 "width", G_TYPE_INT, widths[i],
319 "height", G_TYPE_INT, heights[i],
320 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
322 gst_caps_append (caps, temp);
326 case AV_CODEC_ID_DVVIDEO:
333 gint framerate_n, framerate_d;
336 "Y41B", 720, 480, 8, 9, 30000, 1001}, {
337 "Y41B", 720, 480, 32, 27, 30000, 1001}, {
338 "Y42B", 720, 480, 8, 9, 30000, 1001}, {
339 "Y42B", 720, 480, 32, 27, 30000, 1001}, {
340 "I420", 720, 576, 16, 15, 25, 1}, {
341 "I420", 720, 576, 64, 45, 25, 1}, {
342 "Y41B", 720, 576, 16, 15, 25, 1}, {
343 "Y41B", 720, 576, 64, 45, 25, 1}, {
344 "Y42B", 720, 576, 16, 15, 25, 1}, {
345 "Y42B", 720, 576, 64, 45, 25, 1}, {
346 "Y42B", 1280, 1080, 1, 1, 30000, 1001}, {
347 "Y42B", 1280, 1080, 3, 2, 30000, 1001}, {
348 "Y42B", 1440, 1080, 1, 1, 25, 1}, {
349 "Y42B", 1440, 1080, 4, 3, 25, 1}, {
350 "Y42B", 960, 720, 1, 1, 60000, 1001}, {
351 "Y42B", 960, 720, 4, 3, 60000, 1001}, {
352 "Y42B", 960, 720, 1, 1, 50, 1}, {
353 "Y42B", 960, 720, 4, 3, 50, 1},};
355 gint n_sizes = G_N_ELEMENTS (profiles);
357 if (strcmp (mimetype, "video/x-raw") == 0) {
358 caps = gst_caps_new_empty ();
359 for (i = 0; i < n_sizes; i++) {
360 temp = gst_caps_new_simple (mimetype,
361 "format", G_TYPE_STRING, profiles[i].csp,
362 "width", G_TYPE_INT, profiles[i].width,
363 "height", G_TYPE_INT, profiles[i].height,
364 "framerate", GST_TYPE_FRACTION, profiles[i].framerate_n,
365 profiles[i].framerate_d, "pixel-aspect-ratio",
366 GST_TYPE_FRACTION, profiles[i].par_n, profiles[i].par_d, NULL);
368 gst_caps_append (caps, temp);
371 caps = gst_caps_new_empty ();
372 for (i = 0; i < n_sizes; i++) {
373 temp = gst_caps_new_simple (mimetype,
374 "width", G_TYPE_INT, profiles[i].width,
375 "height", G_TYPE_INT, profiles[i].height,
376 "framerate", GST_TYPE_FRACTION, profiles[i].framerate_n,
377 profiles[i].framerate_d, "pixel-aspect-ratio",
378 GST_TYPE_FRACTION, profiles[i].par_n, profiles[i].par_d, NULL);
380 gst_caps_append (caps, temp);
385 case AV_CODEC_ID_DNXHD:
387 caps = gst_caps_new_simple (mimetype,
388 "width", G_TYPE_INT, 1920,
389 "height", G_TYPE_INT, 1080,
390 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
391 gst_caps_append (caps, gst_caps_new_simple (mimetype,
392 "width", G_TYPE_INT, 1280,
393 "height", G_TYPE_INT, 720,
394 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL));
399 if (codec && codec->supported_framerates
400 && codec->supported_framerates[0].num != 0
401 && codec->supported_framerates[0].den != 0) {
404 const AVRational *rates = codec->supported_framerates;
406 if (rates[1].num == 0 && rates[1].den == 0) {
408 gst_caps_new_simple (mimetype, "framerate", GST_TYPE_FRACTION,
409 rates[0].num, rates[0].den, NULL);
411 g_value_init (&va, GST_TYPE_LIST);
412 g_value_init (&v, GST_TYPE_FRACTION);
414 while (rates->num != 0 && rates->den != 0) {
415 gst_value_set_fraction (&v, rates->num, rates->den);
416 gst_value_list_append_value (&va, &v);
420 caps = gst_caps_new_simple (mimetype, NULL, NULL, NULL);
421 gst_caps_set_value (caps, "framerate", &va);
427 caps = gst_caps_new_empty_simple (mimetype);
435 /* no fixed caps or special restrictions applied;
436 * default unfixed setting */
438 GST_DEBUG ("Creating default caps");
439 caps = gst_caps_new_empty_simple (mimetype);
442 va_start (var_args, fieldname);
443 gst_caps_set_simple_valist (caps, fieldname, var_args);
450 get_nbits_set (guint64 n)
455 for (i = 0; i < 64; i++) {
456 if ((n & (G_GUINT64_CONSTANT (1) << i)))
464 gst_ffmpeg_audio_set_sample_fmts (GstCaps * caps,
465 const enum AVSampleFormat *fmts)
469 GstAudioFormat format;
471 if (!fmts || fmts[0] == -1) {
474 g_value_init (&va, GST_TYPE_LIST);
475 g_value_init (&v, G_TYPE_STRING);
476 for (i = 0; i <= AV_SAMPLE_FMT_DBL; i++) {
477 format = gst_ffmpeg_smpfmt_to_audioformat (i);
478 if (format == GST_AUDIO_FORMAT_UNKNOWN)
480 g_value_set_string (&v, gst_audio_format_to_string (format));
481 gst_value_list_append_value (&va, &v);
483 gst_caps_set_value (caps, "format", &va);
489 g_value_init (&va, GST_TYPE_LIST);
490 g_value_init (&v, G_TYPE_STRING);
491 while (*fmts != -1) {
492 format = gst_ffmpeg_smpfmt_to_audioformat (*fmts);
493 if (format != GST_AUDIO_FORMAT_UNKNOWN) {
494 g_value_set_string (&v, gst_audio_format_to_string (format));
495 /* Only append values we don't have yet */
496 if (!_gst_value_list_contains (&va, &v))
497 gst_value_list_append_value (&va, &v);
501 if (gst_value_list_get_size (&va) == 1) {
502 /* The single value is still in v */
503 gst_caps_set_value (caps, "format", &v);
504 } else if (gst_value_list_get_size (&va) > 1) {
505 gst_caps_set_value (caps, "format", &va);
511 /* same for audio - now with channels/sample rate
514 gst_ff_aud_caps_new (AVCodecContext * context, AVCodec * codec,
515 enum AVCodecID codec_id, gboolean encode, const char *mimetype,
516 const char *fieldname, ...)
518 GstCaps *caps = NULL;
522 /* fixed, non-probing context */
523 if (context != NULL && context->channels != -1) {
524 GstAudioChannelPosition pos[64];
527 caps = gst_caps_new_simple (mimetype,
528 "rate", G_TYPE_INT, context->sample_rate,
529 "channels", G_TYPE_INT, context->channels, NULL);
531 if (context->channels > 1 &&
532 gst_ffmpeg_channel_layout_to_gst (context->channel_layout,
533 context->channels, pos) &&
534 gst_audio_channel_positions_to_mask (pos, context->channels, FALSE,
536 gst_caps_set_simple (caps, "channel-mask", GST_TYPE_BITMASK, mask, NULL);
539 gint maxchannels = 2;
540 const gint *rates = NULL;
543 /* so we must be after restricted caps in this case */
545 case AV_CODEC_ID_AAC:
546 case AV_CODEC_ID_AAC_LATM:
547 case AV_CODEC_ID_DTS:
550 case AV_CODEC_ID_MP2:
552 const static gint l_rates[] =
553 { 48000, 44100, 32000, 24000, 22050, 16000 };
554 n_rates = G_N_ELEMENTS (l_rates);
558 case AV_CODEC_ID_EAC3:
559 case AV_CODEC_ID_AC3:
561 const static gint l_rates[] = { 48000, 44100, 32000 };
563 n_rates = G_N_ELEMENTS (l_rates);
567 case AV_CODEC_ID_ADPCM_G722:
569 const static gint l_rates[] = { 16000 };
570 n_rates = G_N_ELEMENTS (l_rates);
575 case AV_CODEC_ID_ADPCM_G726:
577 const static gint l_rates[] = { 8000 };
578 n_rates = G_N_ELEMENTS (l_rates);
583 case AV_CODEC_ID_ADPCM_SWF:
585 const static gint l_rates[] = { 11025, 22050, 44100 };
586 n_rates = G_N_ELEMENTS (l_rates);
590 case AV_CODEC_ID_ROQ_DPCM:
592 const static gint l_rates[] = { 22050 };
593 n_rates = G_N_ELEMENTS (l_rates);
597 case AV_CODEC_ID_AMR_NB:
599 const static gint l_rates[] = { 8000 };
601 n_rates = G_N_ELEMENTS (l_rates);
605 case AV_CODEC_ID_AMR_WB:
607 const static gint l_rates[] = { 16000 };
609 n_rates = G_N_ELEMENTS (l_rates);
617 /* regardless of encode/decode, open up channels if applicable */
618 /* Until decoders/encoders expose the maximum number of channels
619 * they support, we whitelist them here. */
621 case AV_CODEC_ID_WMAPRO:
622 case AV_CODEC_ID_TRUEHD:
629 if (codec && codec->channel_layouts) {
630 const uint64_t *layouts = codec->channel_layouts;
631 GstAudioChannelPosition pos[64];
633 caps = gst_caps_new_empty ();
635 gint nbits_set = get_nbits_set (*layouts);
637 if (gst_ffmpeg_channel_layout_to_gst (*layouts, nbits_set, pos)) {
640 if (gst_audio_channel_positions_to_mask (pos, nbits_set, FALSE,
643 gst_caps_new_simple (mimetype, "channel-mask", GST_TYPE_BITMASK,
645 "channels", G_TYPE_INT, nbits_set, NULL);
647 gst_caps_append (caps, tmp);
653 if (maxchannels == 1)
654 caps = gst_caps_new_simple (mimetype,
655 "channels", G_TYPE_INT, maxchannels, NULL);
657 caps = gst_caps_new_simple (mimetype,
658 "channels", GST_TYPE_INT_RANGE, 1, maxchannels, NULL);
662 GValue list = { 0, };
664 g_value_init (&list, GST_TYPE_LIST);
665 for (i = 0; i < n_rates; i++) {
668 g_value_init (&v, G_TYPE_INT);
669 g_value_set_int (&v, rates[i]);
670 gst_value_list_append_value (&list, &v);
673 gst_caps_set_value (caps, "rate", &list);
674 g_value_unset (&list);
675 } else if (codec && codec->supported_samplerates
676 && codec->supported_samplerates[0]) {
680 if (!codec->supported_samplerates[1]) {
681 gst_caps_set_simple (caps, "rate", G_TYPE_INT,
682 codec->supported_samplerates[0], NULL);
684 const int *rates = codec->supported_samplerates;
686 g_value_init (&va, GST_TYPE_LIST);
687 g_value_init (&v, G_TYPE_INT);
690 g_value_set_int (&v, *rates);
691 gst_value_list_append_value (&va, &v);
694 gst_caps_set_value (caps, "rate", &va);
699 gst_caps_set_simple (caps, "rate", GST_TYPE_INT_RANGE, 4000, 96000, NULL);
702 caps = gst_caps_new_empty_simple (mimetype);
705 va_start (var_args, fieldname);
706 gst_caps_set_simple_valist (caps, fieldname, var_args);
712 /* Convert a FFMPEG codec ID and optional AVCodecContext
713 * to a GstCaps. If the context is ommitted, no fixed values
714 * for video/audio size will be included in the GstCaps
716 * CodecID is primarily meant for compressed data GstCaps!
718 * encode is a special parameter. gstffmpegdec will say
719 * FALSE, gstffmpegenc will say TRUE. The output caps
720 * depends on this, in such a way that it will be very
721 * specific, defined, fixed and correct caps for encoders,
722 * yet very wide, "forgiving" caps for decoders. Example
723 * for mp3: decode: audio/mpeg,mpegversion=1,layer=[1-3]
724 * but encode: audio/mpeg,mpegversion=1,layer=3,bitrate=x,
729 gst_ffmpeg_codecid_to_caps (enum AVCodecID codec_id,
730 AVCodecContext * context, gboolean encode)
732 GstCaps *caps = NULL;
733 gboolean buildcaps = FALSE;
735 GST_LOG ("codec_id:%d, context:%p, encode:%d", codec_id, context, encode);
738 case AV_CODEC_ID_MPEG1VIDEO:
740 caps = gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
741 "mpegversion", G_TYPE_INT, 1,
742 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
745 case AV_CODEC_ID_MPEG2VIDEO:
749 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
750 "mpegversion", G_TYPE_INT, 2, "systemstream", G_TYPE_BOOLEAN, FALSE,
753 /* decode both MPEG-1 and MPEG-2; width/height/fps are all in
754 * the MPEG video stream headers, so may be omitted from caps. */
755 caps = gst_caps_new_simple ("video/mpeg",
756 "mpegversion", GST_TYPE_INT_RANGE, 1, 2,
757 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
761 case AV_CODEC_ID_MPEG2VIDEO_XVMC:
762 /* this is a special ID - don't need it in GStreamer, I think */
765 case AV_CODEC_ID_H263:
768 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
769 "video/x-h263", "variant", G_TYPE_STRING, "itu", "h263version",
770 G_TYPE_STRING, "h263", NULL);
772 /* don't pass codec_id, we can decode other variants with the H263
773 * decoder that don't have specific size requirements
776 gst_ff_vid_caps_new (context, NULL, AV_CODEC_ID_NONE, encode,
777 "video/x-h263", "variant", G_TYPE_STRING, "itu", NULL);
781 case AV_CODEC_ID_H263P:
783 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h263",
784 "variant", G_TYPE_STRING, "itu", "h263version", G_TYPE_STRING,
786 if (encode && context) {
788 gst_caps_set_simple (caps,
789 "annex-f", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_4MV,
790 "annex-j", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_LOOP_FILTER,
791 "annex-i", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_AC_PRED,
792 "annex-t", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_AC_PRED,
797 case AV_CODEC_ID_H263I:
799 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
800 "video/x-intel-h263", "variant", G_TYPE_STRING, "intel", NULL);
803 case AV_CODEC_ID_H261:
805 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h261",
809 case AV_CODEC_ID_RV10:
810 case AV_CODEC_ID_RV20:
811 case AV_CODEC_ID_RV30:
812 case AV_CODEC_ID_RV40:
817 case AV_CODEC_ID_RV40:
820 case AV_CODEC_ID_RV30:
823 case AV_CODEC_ID_RV20:
832 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
833 "video/x-pn-realvideo", "rmversion", G_TYPE_INT, version, NULL);
835 if (context->extradata_size >= 8) {
836 gst_caps_set_simple (caps,
837 "subformat", G_TYPE_INT, GST_READ_UINT32_BE (context->extradata),
844 case AV_CODEC_ID_MP1:
846 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
847 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 1, NULL);
850 case AV_CODEC_ID_MP2:
852 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
853 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 2, NULL);
856 case AV_CODEC_ID_MP3:
860 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
861 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 3, NULL);
863 /* Decodes MPEG-1 layer 1/2/3. Samplerate, channels et al are
864 * in the MPEG audio header, so may be omitted from caps. */
865 caps = gst_caps_new_simple ("audio/mpeg",
866 "mpegversion", G_TYPE_INT, 1,
867 "layer", GST_TYPE_INT_RANGE, 1, 3, NULL);
871 case AV_CODEC_ID_MUSEPACK7:
873 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
874 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 7,
878 case AV_CODEC_ID_MUSEPACK8:
880 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
881 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 8,
885 case AV_CODEC_ID_AC3:
888 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-ac3",
892 case AV_CODEC_ID_EAC3:
895 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-eac3",
899 case AV_CODEC_ID_TRUEHD:
901 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
902 "audio/x-true-hd", NULL);
905 case AV_CODEC_ID_ATRAC1:
907 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
908 "audio/x-vnd.sony.atrac1", NULL);
911 case AV_CODEC_ID_ATRAC3:
913 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
914 "audio/x-vnd.sony.atrac3", NULL);
917 case AV_CODEC_ID_DTS:
919 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dts",
923 case AV_CODEC_ID_APE:
925 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
926 "audio/x-ffmpeg-parsed-ape", NULL);
928 gst_caps_set_simple (caps,
929 "depth", G_TYPE_INT, context->bits_per_coded_sample, NULL);
933 case AV_CODEC_ID_MLP:
935 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mlp",
939 case AV_CODEC_ID_IMC:
941 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-imc",
945 /* MJPEG is normal JPEG, Motion-JPEG and Quicktime MJPEG-A. MJPEGB
946 * is Quicktime's MJPEG-B. LJPEG is lossless JPEG. I don't know what
947 * sp5x is, but it's apparently something JPEG... We don't separate
948 * between those in GStreamer. Should we (at least between MJPEG,
949 * MJPEG-B and sp5x decoding...)? */
950 case AV_CODEC_ID_MJPEG:
951 case AV_CODEC_ID_LJPEG:
953 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/jpeg",
954 "parsed", G_TYPE_BOOLEAN, TRUE, NULL);
957 case AV_CODEC_ID_JPEG2000:
959 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-j2c",
962 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
963 encode, "image/x-jpc", NULL));
964 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
965 encode, "image/jp2", NULL));
969 case AV_CODEC_ID_SP5X:
971 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/sp5x",
975 case AV_CODEC_ID_MJPEGB:
977 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
978 "video/x-mjpeg-b", NULL);
981 case AV_CODEC_ID_MPEG4:
982 if (encode && context != NULL) {
983 /* I'm not exactly sure what ffmpeg outputs... ffmpeg itself uses
984 * the AVI fourcc 'DIVX', but 'mp4v' for Quicktime... */
985 switch (context->codec_tag) {
986 case GST_MAKE_FOURCC ('D', 'I', 'V', 'X'):
988 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
989 "video/x-divx", "divxversion", G_TYPE_INT, 5, NULL);
991 case GST_MAKE_FOURCC ('m', 'p', '4', 'v'):
993 /* FIXME: bitrate. libav doesn't expose the used profile and level */
995 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
996 "video/mpeg", "systemstream", G_TYPE_BOOLEAN, FALSE,
997 "mpegversion", G_TYPE_INT, 4, NULL);
1001 /* The trick here is to separate xvid, divx, mpeg4, 3ivx et al */
1003 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
1004 "mpegversion", G_TYPE_INT, 4, "systemstream", G_TYPE_BOOLEAN, FALSE,
1008 GValue arr = { 0, };
1009 GValue item = { 0, };
1011 g_value_init (&arr, GST_TYPE_LIST);
1012 g_value_init (&item, G_TYPE_STRING);
1013 g_value_set_string (&item, "simple");
1014 gst_value_list_append_value (&arr, &item);
1015 g_value_set_string (&item, "advanced-simple");
1016 gst_value_list_append_value (&arr, &item);
1017 g_value_unset (&item);
1019 gst_caps_set_value (caps, "profile", &arr);
1020 g_value_unset (&arr);
1022 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
1023 encode, "video/x-divx", "divxversion", G_TYPE_INT, 5, NULL));
1025 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
1026 encode, "video/x-divx", "divxversion", GST_TYPE_INT_RANGE, 4,
1032 case AV_CODEC_ID_RAWVIDEO:
1034 gst_ffmpeg_codectype_to_video_caps (context, codec_id, encode, NULL);
1037 case AV_CODEC_ID_MSMPEG4V1:
1038 case AV_CODEC_ID_MSMPEG4V2:
1039 case AV_CODEC_ID_MSMPEG4V3:
1041 gint version = 41 + codec_id - AV_CODEC_ID_MSMPEG4V1;
1043 /* encode-FIXME: bitrate */
1045 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1046 "video/x-msmpeg", "msmpegversion", G_TYPE_INT, version, NULL);
1047 if (!encode && codec_id == AV_CODEC_ID_MSMPEG4V3) {
1048 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
1049 encode, "video/x-divx", "divxversion", G_TYPE_INT, 3, NULL));
1054 case AV_CODEC_ID_WMV1:
1055 case AV_CODEC_ID_WMV2:
1057 gint version = (codec_id == AV_CODEC_ID_WMV1) ? 1 : 2;
1060 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1061 "wmvversion", G_TYPE_INT, version, NULL);
1065 case AV_CODEC_ID_FLV1:
1067 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1068 "video/x-flash-video", "flvversion", G_TYPE_INT, 1, NULL);
1071 case AV_CODEC_ID_SVQ1:
1073 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-svq",
1074 "svqversion", G_TYPE_INT, 1, NULL);
1077 case AV_CODEC_ID_SVQ3:
1079 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-svq",
1080 "svqversion", G_TYPE_INT, 3, NULL);
1083 case AV_CODEC_ID_DVAUDIO:
1085 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dv",
1089 case AV_CODEC_ID_DVVIDEO:
1091 if (encode && context) {
1092 const gchar *format;
1094 switch (context->pix_fmt) {
1095 case AV_PIX_FMT_YUYV422:
1098 case AV_PIX_FMT_YUV420P:
1101 case AV_PIX_FMT_YUVA420P:
1104 case AV_PIX_FMT_YUV411P:
1107 case AV_PIX_FMT_YUV422P:
1110 case AV_PIX_FMT_YUV410P:
1115 ("Couldnt' find format for pixfmt %d, defaulting to I420",
1121 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dv",
1122 "systemstream", G_TYPE_BOOLEAN, FALSE, "format", G_TYPE_STRING,
1126 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dv",
1127 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
1132 case AV_CODEC_ID_WMAV1:
1133 case AV_CODEC_ID_WMAV2:
1135 gint version = (codec_id == AV_CODEC_ID_WMAV1) ? 1 : 2;
1139 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1140 "wmaversion", G_TYPE_INT, version, "block_align", G_TYPE_INT,
1141 context->block_align, "bitrate", G_TYPE_INT, context->bit_rate,
1145 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1146 "wmaversion", G_TYPE_INT, version, "block_align",
1147 GST_TYPE_INT_RANGE, 0, G_MAXINT, "bitrate", GST_TYPE_INT_RANGE, 0,
1152 case AV_CODEC_ID_WMAPRO:
1155 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1156 "wmaversion", G_TYPE_INT, 3, NULL);
1159 case AV_CODEC_ID_WMALOSSLESS:
1161 /* libav only supports a depth of 16 at the moment */
1163 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1164 "wmaversion", G_TYPE_INT, 4, "depth", G_TYPE_INT, 16, NULL);
1167 case AV_CODEC_ID_WMAVOICE:
1170 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wms",
1175 case AV_CODEC_ID_MACE3:
1176 case AV_CODEC_ID_MACE6:
1178 gint version = (codec_id == AV_CODEC_ID_MACE3) ? 3 : 6;
1181 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mace",
1182 "maceversion", G_TYPE_INT, version, NULL);
1186 case AV_CODEC_ID_HUFFYUV:
1188 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1189 "video/x-huffyuv", NULL);
1191 gst_caps_set_simple (caps,
1192 "bpp", G_TYPE_INT, context->bits_per_coded_sample, NULL);
1196 case AV_CODEC_ID_CYUV:
1198 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1199 "video/x-compressed-yuv", NULL);
1202 case AV_CODEC_ID_H264:
1204 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h264",
1205 "alignment", G_TYPE_STRING, "au", NULL);
1207 GValue arr = { 0, };
1208 GValue item = { 0, };
1209 g_value_init (&arr, GST_TYPE_LIST);
1210 g_value_init (&item, G_TYPE_STRING);
1211 g_value_set_string (&item, "avc");
1212 gst_value_list_append_value (&arr, &item);
1213 g_value_set_string (&item, "byte-stream");
1214 gst_value_list_append_value (&arr, &item);
1215 g_value_unset (&item);
1216 gst_caps_set_value (caps, "stream-format", &arr);
1217 g_value_unset (&arr);
1221 case AV_CODEC_ID_HEVC:
1223 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h265",
1224 "alignment", G_TYPE_STRING, "au", NULL);
1226 GValue arr = { 0, };
1227 GValue item = { 0, };
1228 g_value_init (&arr, GST_TYPE_LIST);
1229 g_value_init (&item, G_TYPE_STRING);
1230 g_value_set_string (&item, "hvc1");
1231 gst_value_list_append_value (&arr, &item);
1232 g_value_set_string (&item, "hev1");
1233 gst_value_list_append_value (&arr, &item);
1234 g_value_set_string (&item, "byte-stream");
1235 gst_value_list_append_value (&arr, &item);
1236 g_value_unset (&item);
1237 gst_caps_set_value (caps, "stream-format", &arr);
1238 g_value_unset (&arr);
1242 case AV_CODEC_ID_INDEO5:
1244 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1245 "indeoversion", G_TYPE_INT, 5, NULL);
1248 case AV_CODEC_ID_INDEO4:
1250 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1251 "indeoversion", G_TYPE_INT, 4, NULL);
1254 case AV_CODEC_ID_INDEO3:
1256 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1257 "indeoversion", G_TYPE_INT, 3, NULL);
1260 case AV_CODEC_ID_INDEO2:
1262 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1263 "indeoversion", G_TYPE_INT, 2, NULL);
1266 case AV_CODEC_ID_FLASHSV:
1268 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1269 "video/x-flash-screen", NULL);
1272 case AV_CODEC_ID_VP3:
1274 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp3",
1278 case AV_CODEC_ID_VP5:
1280 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp5",
1284 case AV_CODEC_ID_VP6:
1286 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp6",
1290 case AV_CODEC_ID_VP6F:
1292 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1293 "video/x-vp6-flash", NULL);
1296 case AV_CODEC_ID_VP6A:
1298 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1299 "video/x-vp6-alpha", NULL);
1302 case AV_CODEC_ID_VP8:
1304 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp8",
1308 case AV_CODEC_ID_VP9:
1310 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp9",
1314 case AV_CODEC_ID_THEORA:
1316 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1317 "video/x-theora", NULL);
1320 case AV_CODEC_ID_AAC:
1323 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
1327 GValue arr = { 0, };
1328 GValue item = { 0, };
1330 g_value_init (&arr, GST_TYPE_LIST);
1331 g_value_init (&item, G_TYPE_INT);
1332 g_value_set_int (&item, 2);
1333 gst_value_list_append_value (&arr, &item);
1334 g_value_set_int (&item, 4);
1335 gst_value_list_append_value (&arr, &item);
1336 g_value_unset (&item);
1338 gst_caps_set_value (caps, "mpegversion", &arr);
1339 g_value_unset (&arr);
1341 g_value_init (&arr, GST_TYPE_LIST);
1342 g_value_init (&item, G_TYPE_STRING);
1343 g_value_set_string (&item, "raw");
1344 gst_value_list_append_value (&arr, &item);
1345 g_value_set_string (&item, "adts");
1346 gst_value_list_append_value (&arr, &item);
1347 g_value_set_string (&item, "adif");
1348 gst_value_list_append_value (&arr, &item);
1349 g_value_unset (&item);
1351 gst_caps_set_value (caps, "stream-format", &arr);
1352 g_value_unset (&arr);
1354 gst_caps_set_simple (caps, "mpegversion", G_TYPE_INT, 4,
1355 "stream-format", G_TYPE_STRING, "raw",
1356 "base-profile", G_TYPE_STRING, "lc", NULL);
1358 if (context && context->extradata_size > 0)
1359 gst_codec_utils_aac_caps_set_level_and_profile (caps,
1360 context->extradata, context->extradata_size);
1365 case AV_CODEC_ID_AAC_LATM: /* LATM/LOAS AAC syntax */
1366 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
1367 "mpegversion", G_TYPE_INT, 4, "stream-format", G_TYPE_STRING, "loas",
1371 case AV_CODEC_ID_ASV1:
1373 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-asus",
1374 "asusversion", G_TYPE_INT, 1, NULL);
1376 case AV_CODEC_ID_ASV2:
1378 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-asus",
1379 "asusversion", G_TYPE_INT, 2, NULL);
1382 case AV_CODEC_ID_FFV1:
1384 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-ffv",
1385 "ffvversion", G_TYPE_INT, 1, NULL);
1388 case AV_CODEC_ID_4XM:
1390 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-4xm",
1394 case AV_CODEC_ID_XAN_WC3:
1395 case AV_CODEC_ID_XAN_WC4:
1397 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-xan",
1398 "wcversion", G_TYPE_INT, 3 - AV_CODEC_ID_XAN_WC3 + codec_id, NULL);
1401 case AV_CODEC_ID_CLJR:
1403 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1404 "video/x-cirrus-logic-accupak", NULL);
1407 case AV_CODEC_ID_FRAPS:
1409 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-fraps",
1413 case AV_CODEC_ID_MDEC:
1414 case AV_CODEC_ID_ROQ:
1415 case AV_CODEC_ID_INTERPLAY_VIDEO:
1419 case AV_CODEC_ID_VCR1:
1421 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1422 "video/x-ati-vcr", "vcrversion", G_TYPE_INT, 1, NULL);
1425 case AV_CODEC_ID_RPZA:
1427 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1428 "video/x-apple-video", NULL);
1431 case AV_CODEC_ID_CINEPAK:
1433 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1434 "video/x-cinepak", NULL);
1437 /* WS_VQA belogns here (order) */
1439 case AV_CODEC_ID_MSRLE:
1441 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-rle",
1442 "layout", G_TYPE_STRING, "microsoft", NULL);
1444 gst_caps_set_simple (caps,
1445 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1447 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1451 case AV_CODEC_ID_QTRLE:
1453 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-rle",
1454 "layout", G_TYPE_STRING, "quicktime", NULL);
1456 gst_caps_set_simple (caps,
1457 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1459 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1463 case AV_CODEC_ID_MSVIDEO1:
1465 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1466 "video/x-msvideocodec", "msvideoversion", G_TYPE_INT, 1, NULL);
1469 case AV_CODEC_ID_MSS1:
1471 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1472 "wmvversion", G_TYPE_INT, 1, "format", G_TYPE_STRING, "MSS1", NULL);
1475 case AV_CODEC_ID_MSS2:
1477 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1478 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "MSS2", NULL);
1481 case AV_CODEC_ID_WMV3:
1483 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1484 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "WMV3", NULL);
1486 case AV_CODEC_ID_VC1:
1488 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1489 "wmvversion", G_TYPE_INT, 3, NULL);
1490 if (!context && !encode) {
1491 GValue arr = { 0, };
1492 GValue item = { 0, };
1494 g_value_init (&arr, GST_TYPE_LIST);
1495 g_value_init (&item, G_TYPE_STRING);
1496 g_value_set_string (&item, "WVC1");
1497 gst_value_list_append_value (&arr, &item);
1498 g_value_set_string (&item, "WMVA");
1499 gst_value_list_append_and_take_value (&arr, &item);
1500 gst_caps_set_value (caps, "format", &arr);
1501 g_value_unset (&arr);
1503 gst_caps_set_simple (caps, "format", G_TYPE_STRING, "WVC1", NULL);
1506 case AV_CODEC_ID_QDM2:
1508 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-qdm2",
1512 case AV_CODEC_ID_MSZH:
1514 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-mszh",
1518 case AV_CODEC_ID_ZLIB:
1520 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-zlib",
1524 case AV_CODEC_ID_TRUEMOTION1:
1526 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1527 "video/x-truemotion", "trueversion", G_TYPE_INT, 1, NULL);
1529 case AV_CODEC_ID_TRUEMOTION2:
1531 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1532 "video/x-truemotion", "trueversion", G_TYPE_INT, 2, NULL);
1535 case AV_CODEC_ID_ULTI:
1537 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1538 "video/x-ultimotion", NULL);
1541 case AV_CODEC_ID_TSCC:
1543 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1544 "video/x-camtasia", NULL);
1546 gst_caps_set_simple (caps,
1547 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1549 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1553 case AV_CODEC_ID_TSCC2:
1555 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1556 "video/x-tscc", "tsccversion", G_TYPE_INT, 2, NULL);
1559 case AV_CODEC_ID_KMVC:
1561 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-kmvc",
1565 case AV_CODEC_ID_NUV:
1567 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-nuv",
1571 case AV_CODEC_ID_GIF:
1573 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/gif",
1577 case AV_CODEC_ID_PNG:
1579 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/png",
1583 case AV_CODEC_ID_PPM:
1585 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/ppm",
1589 case AV_CODEC_ID_PBM:
1591 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/pbm",
1595 case AV_CODEC_ID_PAM:
1597 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1598 "image/x-portable-anymap", NULL);
1601 case AV_CODEC_ID_PGM:
1603 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1604 "image/x-portable-graymap", NULL);
1607 case AV_CODEC_ID_PCX:
1609 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-pcx",
1613 case AV_CODEC_ID_SGI:
1615 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-sgi",
1619 case AV_CODEC_ID_TARGA:
1621 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-tga",
1625 case AV_CODEC_ID_TIFF:
1627 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/tiff",
1631 case AV_CODEC_ID_SUNRAST:
1633 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1634 "image/x-sun-raster", NULL);
1637 case AV_CODEC_ID_SMC:
1639 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-smc",
1643 case AV_CODEC_ID_QDRAW:
1645 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-qdrw",
1649 case AV_CODEC_ID_DNXHD:
1651 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dnxhd",
1655 case AV_CODEC_ID_PRORES:
1657 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1658 "video/x-prores", NULL);
1661 case AV_CODEC_ID_MIMIC:
1663 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-mimic",
1667 case AV_CODEC_ID_VMNC:
1669 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vmnc",
1673 case AV_CODEC_ID_TRUESPEECH:
1675 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1676 "audio/x-truespeech", NULL);
1679 case AV_CODEC_ID_QCELP:
1681 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/qcelp",
1685 case AV_CODEC_ID_AMV:
1687 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-amv",
1691 case AV_CODEC_ID_AASC:
1693 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-aasc",
1697 case AV_CODEC_ID_LOCO:
1699 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-loco",
1703 case AV_CODEC_ID_ZMBV:
1705 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-zmbv",
1709 case AV_CODEC_ID_LAGARITH:
1711 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1712 "video/x-lagarith", NULL);
1715 case AV_CODEC_ID_CSCD:
1717 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1718 "video/x-camstudio", NULL);
1720 gst_caps_set_simple (caps,
1721 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1723 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1727 case AV_CODEC_ID_AIC:
1729 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1730 "video/x-apple-intermediate-codec", NULL);
1733 case AV_CODEC_ID_CAVS:
1735 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1736 "video/x-cavs", NULL);
1739 case AV_CODEC_ID_WS_VQA:
1740 case AV_CODEC_ID_IDCIN:
1741 case AV_CODEC_ID_8BPS:
1742 case AV_CODEC_ID_FLIC:
1743 case AV_CODEC_ID_VMDVIDEO:
1744 case AV_CODEC_ID_VMDAUDIO:
1745 case AV_CODEC_ID_VIXL:
1746 case AV_CODEC_ID_QPEG:
1747 case AV_CODEC_ID_PGMYUV:
1748 case AV_CODEC_ID_FFVHUFF:
1749 case AV_CODEC_ID_WNV1:
1750 case AV_CODEC_ID_MP3ADU:
1751 case AV_CODEC_ID_MP3ON4:
1752 case AV_CODEC_ID_WESTWOOD_SND1:
1753 case AV_CODEC_ID_MMVIDEO:
1754 case AV_CODEC_ID_AVS:
1758 /* weird quasi-codecs for the demuxers only */
1759 case AV_CODEC_ID_PCM_S16LE:
1760 case AV_CODEC_ID_PCM_S16BE:
1761 case AV_CODEC_ID_PCM_U16LE:
1762 case AV_CODEC_ID_PCM_U16BE:
1763 case AV_CODEC_ID_PCM_S8:
1764 case AV_CODEC_ID_PCM_U8:
1766 GstAudioFormat format;
1769 case AV_CODEC_ID_PCM_S16LE:
1770 format = GST_AUDIO_FORMAT_S16LE;
1772 case AV_CODEC_ID_PCM_S16BE:
1773 format = GST_AUDIO_FORMAT_S16BE;
1775 case AV_CODEC_ID_PCM_U16LE:
1776 format = GST_AUDIO_FORMAT_U16LE;
1778 case AV_CODEC_ID_PCM_U16BE:
1779 format = GST_AUDIO_FORMAT_U16BE;
1781 case AV_CODEC_ID_PCM_S8:
1782 format = GST_AUDIO_FORMAT_S8;
1784 case AV_CODEC_ID_PCM_U8:
1785 format = GST_AUDIO_FORMAT_U8;
1789 g_assert (0); /* don't worry, we never get here */
1794 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-raw",
1795 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
1796 "layout", G_TYPE_STRING, "interleaved", NULL);
1800 case AV_CODEC_ID_PCM_MULAW:
1802 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mulaw",
1806 case AV_CODEC_ID_PCM_ALAW:
1808 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-alaw",
1812 case AV_CODEC_ID_ADPCM_G722:
1814 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/G722",
1817 gst_caps_set_simple (caps,
1818 "block_align", G_TYPE_INT, context->block_align,
1819 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1822 case AV_CODEC_ID_ADPCM_G726:
1824 /* the G726 decoder can also handle G721 */
1826 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-adpcm",
1827 "layout", G_TYPE_STRING, "g726", NULL);
1829 gst_caps_set_simple (caps,
1830 "block_align", G_TYPE_INT, context->block_align,
1831 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1834 gst_caps_append (caps, gst_caps_new_simple ("audio/x-adpcm",
1835 "layout", G_TYPE_STRING, "g721",
1836 "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, 8000, NULL));
1840 case AV_CODEC_ID_ADPCM_IMA_QT:
1841 case AV_CODEC_ID_ADPCM_IMA_WAV:
1842 case AV_CODEC_ID_ADPCM_IMA_DK3:
1843 case AV_CODEC_ID_ADPCM_IMA_DK4:
1844 case AV_CODEC_ID_ADPCM_IMA_WS:
1845 case AV_CODEC_ID_ADPCM_IMA_SMJPEG:
1846 case AV_CODEC_ID_ADPCM_IMA_AMV:
1847 case AV_CODEC_ID_ADPCM_IMA_ISS:
1848 case AV_CODEC_ID_ADPCM_IMA_EA_EACS:
1849 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
1850 case AV_CODEC_ID_ADPCM_MS:
1851 case AV_CODEC_ID_ADPCM_4XM:
1852 case AV_CODEC_ID_ADPCM_XA:
1853 case AV_CODEC_ID_ADPCM_ADX:
1854 case AV_CODEC_ID_ADPCM_EA:
1855 case AV_CODEC_ID_ADPCM_CT:
1856 case AV_CODEC_ID_ADPCM_SWF:
1857 case AV_CODEC_ID_ADPCM_YAMAHA:
1858 case AV_CODEC_ID_ADPCM_SBPRO_2:
1859 case AV_CODEC_ID_ADPCM_SBPRO_3:
1860 case AV_CODEC_ID_ADPCM_SBPRO_4:
1861 case AV_CODEC_ID_ADPCM_EA_R1:
1862 case AV_CODEC_ID_ADPCM_EA_R2:
1863 case AV_CODEC_ID_ADPCM_EA_R3:
1864 case AV_CODEC_ID_ADPCM_EA_MAXIS_XA:
1865 case AV_CODEC_ID_ADPCM_EA_XAS:
1866 case AV_CODEC_ID_ADPCM_THP:
1868 const gchar *layout = NULL;
1871 case AV_CODEC_ID_ADPCM_IMA_QT:
1872 layout = "quicktime";
1874 case AV_CODEC_ID_ADPCM_IMA_WAV:
1877 case AV_CODEC_ID_ADPCM_IMA_DK3:
1880 case AV_CODEC_ID_ADPCM_IMA_DK4:
1883 case AV_CODEC_ID_ADPCM_IMA_WS:
1884 layout = "westwood";
1886 case AV_CODEC_ID_ADPCM_IMA_SMJPEG:
1889 case AV_CODEC_ID_ADPCM_IMA_AMV:
1892 case AV_CODEC_ID_ADPCM_IMA_ISS:
1895 case AV_CODEC_ID_ADPCM_IMA_EA_EACS:
1898 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
1901 case AV_CODEC_ID_ADPCM_MS:
1902 layout = "microsoft";
1904 case AV_CODEC_ID_ADPCM_4XM:
1907 case AV_CODEC_ID_ADPCM_XA:
1910 case AV_CODEC_ID_ADPCM_ADX:
1913 case AV_CODEC_ID_ADPCM_EA:
1916 case AV_CODEC_ID_ADPCM_CT:
1919 case AV_CODEC_ID_ADPCM_SWF:
1922 case AV_CODEC_ID_ADPCM_YAMAHA:
1925 case AV_CODEC_ID_ADPCM_SBPRO_2:
1928 case AV_CODEC_ID_ADPCM_SBPRO_3:
1931 case AV_CODEC_ID_ADPCM_SBPRO_4:
1934 case AV_CODEC_ID_ADPCM_EA_R1:
1937 case AV_CODEC_ID_ADPCM_EA_R2:
1940 case AV_CODEC_ID_ADPCM_EA_R3:
1943 case AV_CODEC_ID_ADPCM_EA_MAXIS_XA:
1944 layout = "ea-maxis-xa";
1946 case AV_CODEC_ID_ADPCM_EA_XAS:
1949 case AV_CODEC_ID_ADPCM_THP:
1953 g_assert (0); /* don't worry, we never get here */
1957 /* FIXME: someone please check whether we need additional properties
1958 * in this caps definition. */
1960 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-adpcm",
1961 "layout", G_TYPE_STRING, layout, NULL);
1963 gst_caps_set_simple (caps,
1964 "block_align", G_TYPE_INT, context->block_align,
1965 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1969 case AV_CODEC_ID_AMR_NB:
1971 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/AMR",
1975 case AV_CODEC_ID_AMR_WB:
1977 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/AMR-WB",
1981 case AV_CODEC_ID_GSM:
1983 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-gsm",
1987 case AV_CODEC_ID_GSM_MS:
1989 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/ms-gsm",
1993 case AV_CODEC_ID_NELLYMOSER:
1995 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1996 "audio/x-nellymoser", NULL);
1999 case AV_CODEC_ID_SIPR:
2002 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-sipro",
2005 gst_caps_set_simple (caps,
2006 "leaf_size", G_TYPE_INT, context->block_align,
2007 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
2012 case AV_CODEC_ID_RA_144:
2013 case AV_CODEC_ID_RA_288:
2014 case AV_CODEC_ID_COOK:
2019 case AV_CODEC_ID_RA_144:
2022 case AV_CODEC_ID_RA_288:
2025 case AV_CODEC_ID_COOK:
2032 /* FIXME: properties? */
2034 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
2035 "audio/x-pn-realaudio", "raversion", G_TYPE_INT, version, NULL);
2037 gst_caps_set_simple (caps,
2038 "leaf_size", G_TYPE_INT, context->block_align,
2039 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
2044 case AV_CODEC_ID_ROQ_DPCM:
2045 case AV_CODEC_ID_INTERPLAY_DPCM:
2046 case AV_CODEC_ID_XAN_DPCM:
2047 case AV_CODEC_ID_SOL_DPCM:
2049 const gchar *layout = NULL;
2052 case AV_CODEC_ID_ROQ_DPCM:
2055 case AV_CODEC_ID_INTERPLAY_DPCM:
2056 layout = "interplay";
2058 case AV_CODEC_ID_XAN_DPCM:
2061 case AV_CODEC_ID_SOL_DPCM:
2065 g_assert (0); /* don't worry, we never get here */
2069 /* FIXME: someone please check whether we need additional properties
2070 * in this caps definition. */
2072 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dpcm",
2073 "layout", G_TYPE_STRING, layout, NULL);
2075 gst_caps_set_simple (caps,
2076 "block_align", G_TYPE_INT, context->block_align,
2077 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
2081 case AV_CODEC_ID_SHORTEN:
2082 caps = gst_caps_new_empty_simple ("audio/x-shorten");
2085 case AV_CODEC_ID_ALAC:
2087 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-alac",
2090 gst_caps_set_simple (caps,
2091 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
2095 case AV_CODEC_ID_FLAC:
2096 /* Note that ffmpeg has no encoder yet, but just for safety. In the
2097 * encoder case, we want to add things like samplerate, channels... */
2099 caps = gst_caps_new_empty_simple ("audio/x-flac");
2103 case AV_CODEC_ID_S302M:
2104 caps = gst_caps_new_empty_simple ("audio/x-smpte-302m");
2107 case AV_CODEC_ID_DVD_SUBTITLE:
2108 case AV_CODEC_ID_DVB_SUBTITLE:
2111 case AV_CODEC_ID_BMP:
2112 caps = gst_caps_new_empty_simple ("image/bmp");
2114 case AV_CODEC_ID_TTA:
2116 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-tta",
2119 gst_caps_set_simple (caps,
2120 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
2123 case AV_CODEC_ID_TWINVQ:
2125 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
2126 "audio/x-twin-vq", NULL);
2129 GST_DEBUG ("Unknown codec ID %d, please add mapping here", codec_id);
2136 if ((codec = avcodec_find_decoder (codec_id)) ||
2137 (codec = avcodec_find_encoder (codec_id))) {
2140 GST_LOG ("Could not create stream format caps for %s", codec->name);
2142 switch (codec->type) {
2143 case AVMEDIA_TYPE_VIDEO:
2144 mime = g_strdup_printf ("video/x-gst-av-%s", codec->name);
2146 gst_ff_vid_caps_new (context, NULL, codec_id, encode, mime, NULL);
2149 case AVMEDIA_TYPE_AUDIO:
2150 mime = g_strdup_printf ("audio/x-gst-av-%s", codec->name);
2152 gst_ff_aud_caps_new (context, NULL, codec_id, encode, mime, NULL);
2154 gst_caps_set_simple (caps,
2155 "block_align", G_TYPE_INT, context->block_align,
2156 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
2167 /* set private data */
2168 if (context && context->extradata_size > 0) {
2169 GstBuffer *data = gst_buffer_new_and_alloc (context->extradata_size);
2171 gst_buffer_fill (data, 0, context->extradata, context->extradata_size);
2172 gst_caps_set_simple (caps, "codec_data", GST_TYPE_BUFFER, data, NULL);
2173 gst_buffer_unref (data);
2176 GST_LOG ("caps for codec_id=%d: %" GST_PTR_FORMAT, codec_id, caps);
2179 GST_LOG ("No caps found for codec_id=%d", codec_id);
2185 /* Convert a FFMPEG Pixel Format and optional AVCodecContext
2186 * to a GstCaps. If the context is ommitted, no fixed values
2187 * for video/audio size will be included in the GstCaps
2189 * See below for usefullness
2193 gst_ffmpeg_pixfmt_to_caps (enum PixelFormat pix_fmt, AVCodecContext * context,
2194 enum AVCodecID codec_id)
2196 GstCaps *caps = NULL;
2197 GstVideoFormat format;
2199 format = gst_ffmpeg_pixfmt_to_videoformat (pix_fmt);
2201 if (format != GST_VIDEO_FORMAT_UNKNOWN) {
2202 caps = gst_ff_vid_caps_new (context, NULL, codec_id, TRUE, "video/x-raw",
2203 "format", G_TYPE_STRING, gst_video_format_to_string (format), NULL);
2207 GST_DEBUG ("caps for pix_fmt=%d: %" GST_PTR_FORMAT, pix_fmt, caps);
2209 GST_LOG ("No caps found for pix_fmt=%d", pix_fmt);
2216 gst_ffmpeg_smpfmt_to_audioformat (enum AVSampleFormat sample_fmt)
2218 switch (sample_fmt) {
2219 case AV_SAMPLE_FMT_U8:
2220 case AV_SAMPLE_FMT_U8P:
2221 return GST_AUDIO_FORMAT_U8;
2223 case AV_SAMPLE_FMT_S16:
2224 case AV_SAMPLE_FMT_S16P:
2225 return GST_AUDIO_FORMAT_S16;
2227 case AV_SAMPLE_FMT_S32:
2228 case AV_SAMPLE_FMT_S32P:
2229 return GST_AUDIO_FORMAT_S32;
2231 case AV_SAMPLE_FMT_FLT:
2232 case AV_SAMPLE_FMT_FLTP:
2233 return GST_AUDIO_FORMAT_F32;
2235 case AV_SAMPLE_FMT_DBL:
2236 case AV_SAMPLE_FMT_DBLP:
2237 return GST_AUDIO_FORMAT_F64;
2241 return GST_AUDIO_FORMAT_UNKNOWN;
2246 /* Convert a FFMPEG Sample Format and optional AVCodecContext
2247 * to a GstCaps. If the context is ommitted, no fixed values
2248 * for video/audio size will be included in the GstCaps
2250 * See below for usefullness
2254 gst_ffmpeg_smpfmt_to_caps (enum AVSampleFormat sample_fmt,
2255 AVCodecContext * context, AVCodec * codec, enum AVCodecID codec_id)
2257 GstCaps *caps = NULL;
2258 GstAudioFormat format;
2260 format = gst_ffmpeg_smpfmt_to_audioformat (sample_fmt);
2262 if (format != GST_AUDIO_FORMAT_UNKNOWN) {
2263 caps = gst_ff_aud_caps_new (context, codec, codec_id, TRUE, "audio/x-raw",
2264 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
2265 "layout", G_TYPE_STRING, "interleaved", NULL);
2266 GST_LOG ("caps for sample_fmt=%d: %" GST_PTR_FORMAT, sample_fmt, caps);
2268 GST_LOG ("No caps found for sample_fmt=%d", sample_fmt);
2275 caps_has_field (GstCaps * caps, const gchar * field)
2279 n = gst_caps_get_size (caps);
2280 for (i = 0; i < n; i++) {
2281 GstStructure *s = gst_caps_get_structure (caps, i);
2283 if (gst_structure_has_field (s, field))
2291 gst_ffmpeg_codectype_to_audio_caps (AVCodecContext * context,
2292 enum AVCodecID codec_id, gboolean encode, AVCodec * codec)
2294 GstCaps *caps = NULL;
2296 GST_DEBUG ("context:%p, codec_id:%d, encode:%d, codec:%p",
2297 context, codec_id, encode, codec);
2299 GST_DEBUG ("sample_fmts:%p, samplerates:%p",
2300 codec->sample_fmts, codec->supported_samplerates);
2303 /* Specific codec context */
2305 gst_ffmpeg_smpfmt_to_caps (context->sample_fmt, context, codec,
2308 caps = gst_ff_aud_caps_new (context, codec, codec_id, encode, "audio/x-raw",
2309 "layout", G_TYPE_STRING, "interleaved", NULL);
2310 if (!caps_has_field (caps, "format"))
2311 gst_ffmpeg_audio_set_sample_fmts (caps,
2312 codec ? codec->sample_fmts : NULL);
2319 gst_ffmpeg_codectype_to_video_caps (AVCodecContext * context,
2320 enum AVCodecID codec_id, gboolean encode, AVCodec * codec)
2324 GST_LOG ("context:%p, codec_id:%d, encode:%d, codec:%p",
2325 context, codec_id, encode, codec);
2328 caps = gst_ffmpeg_pixfmt_to_caps (context->pix_fmt, context, codec_id);
2331 gst_ff_vid_caps_new (context, codec, codec_id, encode, "video/x-raw",
2333 if (!caps_has_field (caps, "format"))
2334 gst_ffmpeg_video_set_pix_fmts (caps, codec ? codec->pix_fmts : NULL);
2339 /* Convert a GstCaps (audio/raw) to a FFMPEG SampleFmt
2340 * and other audio properties in a AVCodecContext.
2342 * For usefullness, see below
2346 gst_ffmpeg_caps_to_smpfmt (const GstCaps * caps,
2347 AVCodecContext * context, gboolean raw)
2349 GstStructure *structure;
2351 GstAudioFormat format = GST_AUDIO_FORMAT_UNKNOWN;
2353 g_return_if_fail (gst_caps_get_size (caps) == 1);
2355 structure = gst_caps_get_structure (caps, 0);
2357 gst_structure_get_int (structure, "channels", &context->channels);
2358 gst_structure_get_int (structure, "rate", &context->sample_rate);
2359 gst_structure_get_int (structure, "block_align", &context->block_align);
2360 gst_structure_get_int (structure, "bitrate", &context->bit_rate);
2365 if (gst_structure_has_name (structure, "audio/x-raw")) {
2366 if ((fmt = gst_structure_get_string (structure, "format"))) {
2367 format = gst_audio_format_from_string (fmt);
2372 case GST_AUDIO_FORMAT_F32:
2373 context->sample_fmt = AV_SAMPLE_FMT_FLT;
2375 case GST_AUDIO_FORMAT_F64:
2376 context->sample_fmt = AV_SAMPLE_FMT_DBL;
2378 case GST_AUDIO_FORMAT_S32:
2379 context->sample_fmt = AV_SAMPLE_FMT_S32;
2381 case GST_AUDIO_FORMAT_S16:
2382 context->sample_fmt = AV_SAMPLE_FMT_S16;
2389 /* Convert a GstCaps (video/raw) to a FFMPEG PixFmt
2390 * and other video properties in a AVCodecContext.
2392 * For usefullness, see below
2396 gst_ffmpeg_caps_to_pixfmt (const GstCaps * caps,
2397 AVCodecContext * context, gboolean raw)
2399 GstStructure *structure;
2401 const GValue *par = NULL;
2403 GstVideoFormat format = GST_VIDEO_FORMAT_UNKNOWN;
2405 GST_DEBUG ("converting caps %" GST_PTR_FORMAT, caps);
2406 g_return_if_fail (gst_caps_get_size (caps) == 1);
2407 structure = gst_caps_get_structure (caps, 0);
2409 gst_structure_get_int (structure, "width", &context->width);
2410 gst_structure_get_int (structure, "height", &context->height);
2411 gst_structure_get_int (structure, "bpp", &context->bits_per_coded_sample);
2413 fps = gst_structure_get_value (structure, "framerate");
2414 if (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps)) {
2416 int num = gst_value_get_fraction_numerator (fps);
2417 int den = gst_value_get_fraction_denominator (fps);
2419 if (num > 0 && den > 0) {
2420 /* somehow these seem mixed up.. */
2421 /* they're fine, this is because it does period=1/frequency */
2422 context->time_base.den = gst_value_get_fraction_numerator (fps);
2423 context->time_base.num = gst_value_get_fraction_denominator (fps);
2424 context->ticks_per_frame = 1;
2426 GST_DEBUG ("setting framerate %d/%d = %lf",
2427 context->time_base.den, context->time_base.num,
2428 1. * context->time_base.den / context->time_base.num);
2430 GST_WARNING ("ignoring insane framerate %d/%d",
2431 context->time_base.den, context->time_base.num);
2435 par = gst_structure_get_value (structure, "pixel-aspect-ratio");
2436 if (par && GST_VALUE_HOLDS_FRACTION (par)) {
2438 int num = gst_value_get_fraction_numerator (par);
2439 int den = gst_value_get_fraction_denominator (par);
2441 if (num > 0 && den > 0) {
2442 context->sample_aspect_ratio.num = num;
2443 context->sample_aspect_ratio.den = den;
2445 GST_DEBUG ("setting pixel-aspect-ratio %d/%d = %lf",
2446 context->sample_aspect_ratio.num, context->sample_aspect_ratio.den,
2447 1. * context->sample_aspect_ratio.num /
2448 context->sample_aspect_ratio.den);
2450 GST_WARNING ("ignoring insane pixel-aspect-ratio %d/%d",
2451 context->sample_aspect_ratio.num, context->sample_aspect_ratio.den);
2458 g_return_if_fail (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps));
2460 if (gst_structure_has_name (structure, "video/x-raw")) {
2461 if ((fmt = gst_structure_get_string (structure, "format"))) {
2462 format = gst_video_format_from_string (fmt);
2467 case GST_VIDEO_FORMAT_YUY2:
2468 context->pix_fmt = AV_PIX_FMT_YUYV422;
2470 case GST_VIDEO_FORMAT_I420:
2471 context->pix_fmt = AV_PIX_FMT_YUV420P;
2473 case GST_VIDEO_FORMAT_A420:
2474 context->pix_fmt = AV_PIX_FMT_YUVA420P;
2476 case GST_VIDEO_FORMAT_Y41B:
2477 context->pix_fmt = AV_PIX_FMT_YUV411P;
2479 case GST_VIDEO_FORMAT_Y42B:
2480 context->pix_fmt = AV_PIX_FMT_YUV422P;
2482 case GST_VIDEO_FORMAT_YUV9:
2483 context->pix_fmt = AV_PIX_FMT_YUV410P;
2485 case GST_VIDEO_FORMAT_Y444:
2486 context->pix_fmt = AV_PIX_FMT_YUV444P;
2488 case GST_VIDEO_FORMAT_GRAY8:
2489 context->pix_fmt = AV_PIX_FMT_GRAY8;
2491 case GST_VIDEO_FORMAT_xRGB:
2492 #if (G_BYTE_ORDER == G_BIG_ENDIAN)
2493 context->pix_fmt = AV_PIX_FMT_RGB32;
2496 case GST_VIDEO_FORMAT_BGRx:
2497 #if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
2498 context->pix_fmt = AV_PIX_FMT_RGB32;
2501 case GST_VIDEO_FORMAT_RGB:
2502 context->pix_fmt = AV_PIX_FMT_RGB24;
2504 case GST_VIDEO_FORMAT_BGR:
2505 context->pix_fmt = AV_PIX_FMT_BGR24;
2507 case GST_VIDEO_FORMAT_RGB16:
2508 context->pix_fmt = AV_PIX_FMT_RGB565;
2510 case GST_VIDEO_FORMAT_RGB15:
2511 context->pix_fmt = AV_PIX_FMT_RGB555;
2513 case GST_VIDEO_FORMAT_RGB8P:
2514 context->pix_fmt = AV_PIX_FMT_PAL8;
2523 GstVideoFormat format;
2524 enum PixelFormat pixfmt;
2527 /* FIXME : FILLME */
2528 static const PixToFmt pixtofmttable[] = {
2529 /* GST_VIDEO_FORMAT_I420, */
2530 {GST_VIDEO_FORMAT_I420, AV_PIX_FMT_YUV420P},
2531 /* Note : this should use a different chroma placement */
2532 {GST_VIDEO_FORMAT_I420, AV_PIX_FMT_YUVJ420P},
2534 /* GST_VIDEO_FORMAT_YV12, */
2535 /* GST_VIDEO_FORMAT_YUY2, */
2536 {GST_VIDEO_FORMAT_YUY2, AV_PIX_FMT_YUYV422},
2537 /* GST_VIDEO_FORMAT_UYVY, */
2538 {GST_VIDEO_FORMAT_UYVY, AV_PIX_FMT_UYVY422},
2539 /* GST_VIDEO_FORMAT_AYUV, */
2540 /* GST_VIDEO_FORMAT_RGBx, */
2541 /* GST_VIDEO_FORMAT_BGRx, */
2542 /* GST_VIDEO_FORMAT_xRGB, */
2543 /* GST_VIDEO_FORMAT_xBGR, */
2544 /* GST_VIDEO_FORMAT_RGBA, */
2545 {GST_VIDEO_FORMAT_RGBA, AV_PIX_FMT_RGBA},
2546 /* GST_VIDEO_FORMAT_BGRA, */
2547 {GST_VIDEO_FORMAT_BGRA, AV_PIX_FMT_BGRA},
2548 /* GST_VIDEO_FORMAT_ARGB, */
2549 {GST_VIDEO_FORMAT_ARGB, AV_PIX_FMT_ARGB},
2550 /* GST_VIDEO_FORMAT_ABGR, */
2551 {GST_VIDEO_FORMAT_ABGR, AV_PIX_FMT_ABGR},
2552 /* GST_VIDEO_FORMAT_RGB, */
2553 {GST_VIDEO_FORMAT_RGB, AV_PIX_FMT_RGB24},
2554 /* GST_VIDEO_FORMAT_BGR, */
2555 {GST_VIDEO_FORMAT_BGR, AV_PIX_FMT_BGR24},
2556 /* GST_VIDEO_FORMAT_Y41B, */
2557 {GST_VIDEO_FORMAT_Y41B, AV_PIX_FMT_YUV411P},
2558 /* GST_VIDEO_FORMAT_Y42B, */
2559 {GST_VIDEO_FORMAT_Y42B, AV_PIX_FMT_YUV422P},
2560 {GST_VIDEO_FORMAT_Y42B, AV_PIX_FMT_YUVJ422P},
2561 /* GST_VIDEO_FORMAT_YVYU, */
2562 /* GST_VIDEO_FORMAT_Y444, */
2563 {GST_VIDEO_FORMAT_Y444, AV_PIX_FMT_YUV444P},
2564 {GST_VIDEO_FORMAT_Y444, AV_PIX_FMT_YUVJ444P},
2565 /* GST_VIDEO_FORMAT_v210, */
2566 /* GST_VIDEO_FORMAT_v216, */
2567 /* GST_VIDEO_FORMAT_NV12, */
2568 {GST_VIDEO_FORMAT_NV12, AV_PIX_FMT_NV12},
2569 /* GST_VIDEO_FORMAT_NV21, */
2570 {GST_VIDEO_FORMAT_NV21, AV_PIX_FMT_NV21},
2571 /* GST_VIDEO_FORMAT_GRAY8, */
2572 {GST_VIDEO_FORMAT_GRAY8, AV_PIX_FMT_GRAY8},
2573 /* GST_VIDEO_FORMAT_GRAY16_BE, */
2574 {GST_VIDEO_FORMAT_GRAY16_BE, AV_PIX_FMT_GRAY16BE},
2575 /* GST_VIDEO_FORMAT_GRAY16_LE, */
2576 {GST_VIDEO_FORMAT_GRAY16_LE, AV_PIX_FMT_GRAY16LE},
2577 /* GST_VIDEO_FORMAT_v308, */
2578 /* GST_VIDEO_FORMAT_Y800, */
2579 /* GST_VIDEO_FORMAT_Y16, */
2580 /* GST_VIDEO_FORMAT_RGB16, */
2581 {GST_VIDEO_FORMAT_RGB16, AV_PIX_FMT_RGB565},
2582 /* GST_VIDEO_FORMAT_BGR16, */
2583 /* GST_VIDEO_FORMAT_RGB15, */
2584 {GST_VIDEO_FORMAT_RGB15, AV_PIX_FMT_RGB555},
2585 /* GST_VIDEO_FORMAT_BGR15, */
2586 /* GST_VIDEO_FORMAT_UYVP, */
2587 /* GST_VIDEO_FORMAT_A420, */
2588 {GST_VIDEO_FORMAT_A420, AV_PIX_FMT_YUVA420P},
2589 /* GST_VIDEO_FORMAT_RGB8_PALETTED, */
2590 {GST_VIDEO_FORMAT_RGB8P, AV_PIX_FMT_PAL8},
2591 /* GST_VIDEO_FORMAT_YUV9, */
2592 {GST_VIDEO_FORMAT_YUV9, AV_PIX_FMT_YUV410P},
2593 /* GST_VIDEO_FORMAT_YVU9, */
2594 /* GST_VIDEO_FORMAT_IYU1, */
2595 /* GST_VIDEO_FORMAT_ARGB64, */
2596 /* GST_VIDEO_FORMAT_AYUV64, */
2597 /* GST_VIDEO_FORMAT_r210, */
2598 {GST_VIDEO_FORMAT_I420_10LE, AV_PIX_FMT_YUV420P10LE},
2599 {GST_VIDEO_FORMAT_I420_10BE, AV_PIX_FMT_YUV420P10BE},
2600 {GST_VIDEO_FORMAT_I422_10LE, AV_PIX_FMT_YUV422P10LE},
2601 {GST_VIDEO_FORMAT_I422_10BE, AV_PIX_FMT_YUV422P10BE},
2602 {GST_VIDEO_FORMAT_Y444_10LE, AV_PIX_FMT_YUV444P10LE},
2603 {GST_VIDEO_FORMAT_Y444_10BE, AV_PIX_FMT_YUV444P10BE},
2604 {GST_VIDEO_FORMAT_GBR, AV_PIX_FMT_GBRP},
2605 {GST_VIDEO_FORMAT_GBR_10LE, AV_PIX_FMT_GBRP10LE},
2606 {GST_VIDEO_FORMAT_GBR_10BE, AV_PIX_FMT_GBRP10BE},
2607 {GST_VIDEO_FORMAT_A420_10LE, AV_PIX_FMT_YUVA420P10LE},
2608 {GST_VIDEO_FORMAT_A420_10BE, AV_PIX_FMT_YUVA420P10BE},
2609 {GST_VIDEO_FORMAT_A422_10LE, AV_PIX_FMT_YUVA422P10LE},
2610 {GST_VIDEO_FORMAT_A422_10BE, AV_PIX_FMT_YUVA422P10BE},
2611 {GST_VIDEO_FORMAT_A444_10LE, AV_PIX_FMT_YUVA444P10LE},
2612 {GST_VIDEO_FORMAT_A444_10BE, AV_PIX_FMT_YUVA444P10BE},
2616 gst_ffmpeg_pixfmt_to_videoformat (enum PixelFormat pixfmt)
2620 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2621 if (pixtofmttable[i].pixfmt == pixfmt)
2622 return pixtofmttable[i].format;
2624 GST_DEBUG ("Unknown pixel format %d", pixfmt);
2625 return GST_VIDEO_FORMAT_UNKNOWN;
2628 static enum PixelFormat
2629 gst_ffmpeg_videoformat_to_pixfmt_for_codec (GstVideoFormat format,
2630 const AVCodec * codec)
2634 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++) {
2635 if (pixtofmttable[i].format == format) {
2638 if (codec && codec->pix_fmts) {
2639 for (j = 0; codec->pix_fmts[j] != -1; j++) {
2640 if (pixtofmttable[i].pixfmt == codec->pix_fmts[j])
2641 return pixtofmttable[i].pixfmt;
2644 return pixtofmttable[i].pixfmt;
2649 return AV_PIX_FMT_NONE;
2653 gst_ffmpeg_videoformat_to_pixfmt (GstVideoFormat format)
2655 return gst_ffmpeg_videoformat_to_pixfmt_for_codec (format, NULL);
2659 gst_ffmpeg_videoinfo_to_context (GstVideoInfo * info, AVCodecContext * context)
2663 context->width = GST_VIDEO_INFO_WIDTH (info);
2664 context->height = GST_VIDEO_INFO_HEIGHT (info);
2665 for (i = 0; i < GST_VIDEO_INFO_N_COMPONENTS (info); i++)
2666 bpp += GST_VIDEO_INFO_COMP_DEPTH (info, i);
2667 context->bits_per_coded_sample = bpp;
2669 context->ticks_per_frame = 1;
2670 if (GST_VIDEO_INFO_FPS_N (info) == 0) {
2671 GST_DEBUG ("Using 25/1 framerate");
2672 context->time_base.den = 25;
2673 context->time_base.num = 1;
2675 context->time_base.den = GST_VIDEO_INFO_FPS_N (info);
2676 context->time_base.num = GST_VIDEO_INFO_FPS_D (info);
2679 context->sample_aspect_ratio.num = GST_VIDEO_INFO_PAR_N (info);
2680 context->sample_aspect_ratio.den = GST_VIDEO_INFO_PAR_D (info);
2683 gst_ffmpeg_videoformat_to_pixfmt_for_codec (GST_VIDEO_INFO_FORMAT (info),
2688 gst_ffmpeg_audioinfo_to_context (GstAudioInfo * info, AVCodecContext * context)
2690 const AVCodec *codec;
2691 const enum AVSampleFormat *smpl_fmts;
2692 enum AVSampleFormat smpl_fmt = -1;
2694 context->channels = info->channels;
2695 context->sample_rate = info->rate;
2696 context->channel_layout =
2697 gst_ffmpeg_channel_positions_to_layout (info->position, info->channels);
2699 codec = context->codec;
2701 smpl_fmts = codec->sample_fmts;
2703 switch (info->finfo->format) {
2704 case GST_AUDIO_FORMAT_F32:
2706 while (*smpl_fmts != -1) {
2707 if (*smpl_fmts == AV_SAMPLE_FMT_FLT) {
2708 smpl_fmt = *smpl_fmts;
2710 } else if (*smpl_fmts == AV_SAMPLE_FMT_FLTP) {
2711 smpl_fmt = *smpl_fmts;
2717 smpl_fmt = AV_SAMPLE_FMT_FLT;
2720 case GST_AUDIO_FORMAT_F64:
2722 while (*smpl_fmts != -1) {
2723 if (*smpl_fmts == AV_SAMPLE_FMT_DBL) {
2724 smpl_fmt = *smpl_fmts;
2726 } else if (*smpl_fmts == AV_SAMPLE_FMT_DBLP) {
2727 smpl_fmt = *smpl_fmts;
2733 smpl_fmt = AV_SAMPLE_FMT_DBL;
2736 case GST_AUDIO_FORMAT_S32:
2738 while (*smpl_fmts != -1) {
2739 if (*smpl_fmts == AV_SAMPLE_FMT_S32) {
2740 smpl_fmt = *smpl_fmts;
2742 } else if (*smpl_fmts == AV_SAMPLE_FMT_S32P) {
2743 smpl_fmt = *smpl_fmts;
2749 smpl_fmt = AV_SAMPLE_FMT_S32;
2752 case GST_AUDIO_FORMAT_S16:
2754 while (*smpl_fmts != -1) {
2755 if (*smpl_fmts == AV_SAMPLE_FMT_S16) {
2756 smpl_fmt = *smpl_fmts;
2758 } else if (*smpl_fmts == AV_SAMPLE_FMT_S16P) {
2759 smpl_fmt = *smpl_fmts;
2765 smpl_fmt = AV_SAMPLE_FMT_S16;
2768 case GST_AUDIO_FORMAT_U8:
2770 while (*smpl_fmts != -1) {
2771 if (*smpl_fmts == AV_SAMPLE_FMT_U8) {
2772 smpl_fmt = *smpl_fmts;
2774 } else if (*smpl_fmts == AV_SAMPLE_FMT_U8P) {
2775 smpl_fmt = *smpl_fmts;
2781 smpl_fmt = AV_SAMPLE_FMT_U8;
2788 g_assert (smpl_fmt != -1);
2790 context->sample_fmt = smpl_fmt;
2793 /* Convert a GstCaps and a FFMPEG codec Type to a
2794 * AVCodecContext. If the context is ommitted, no fixed values
2795 * for video/audio size will be included in the context
2797 * AVMediaType is primarily meant for uncompressed data GstCaps!
2801 gst_ffmpeg_caps_with_codectype (enum AVMediaType type,
2802 const GstCaps * caps, AVCodecContext * context)
2804 if (context == NULL)
2808 case AVMEDIA_TYPE_VIDEO:
2809 gst_ffmpeg_caps_to_pixfmt (caps, context, TRUE);
2812 case AVMEDIA_TYPE_AUDIO:
2813 gst_ffmpeg_caps_to_smpfmt (caps, context, TRUE);
2824 nal_escape (guint8 * dst, guint8 * src, guint size, guint * destsize)
2828 guint8 *end = src + size;
2831 while (srcp < end) {
2832 if (count == 2 && *srcp <= 0x03) {
2833 GST_DEBUG ("added escape code");
2842 GST_DEBUG ("copy %02x, count %d", *srcp, count);
2845 *destsize = dstp - dst;
2848 /* copy the config, escaping NAL units as we iterate them, if something fails we
2849 * copy everything and hope for the best. */
2851 copy_config (guint8 * dst, guint8 * src, guint size, guint * destsize)
2856 guint nalsize, esize;
2866 cnt = *(srcp + 5) & 0x1f; /* Number of sps */
2868 GST_DEBUG ("num SPS %d", cnt);
2870 memcpy (dstp, srcp, 6);
2874 for (i = 0; i < cnt; i++) {
2875 GST_DEBUG ("copy SPS %d", i);
2876 nalsize = (srcp[0] << 8) | srcp[1];
2877 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2878 dstp[0] = esize >> 8;
2879 dstp[1] = esize & 0xff;
2881 srcp += nalsize + 2;
2884 cnt = *(dstp++) = *(srcp++); /* Number of pps */
2886 GST_DEBUG ("num PPS %d", cnt);
2888 for (i = 0; i < cnt; i++) {
2889 GST_DEBUG ("copy PPS %d", i);
2890 nalsize = (srcp[0] << 8) | srcp[1];
2891 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2892 dstp[0] = esize >> 8;
2893 dstp[1] = esize & 0xff;
2895 srcp += nalsize + 2;
2897 *destsize = dstp - dst;
2903 GST_DEBUG ("something unexpected, doing full copy");
2904 memcpy (dst, src, size);
2912 * caps_with_codecid () transforms a GstCaps for a known codec
2913 * ID into a filled-in context.
2914 * codec_data from caps will override possible extradata already in the context
2918 gst_ffmpeg_caps_with_codecid (enum AVCodecID codec_id,
2919 enum AVMediaType codec_type, const GstCaps * caps, AVCodecContext * context)
2922 const GValue *value;
2925 GST_LOG ("codec_id:%d, codec_type:%d, caps:%" GST_PTR_FORMAT " context:%p",
2926 codec_id, codec_type, caps, context);
2928 if (!context || !gst_caps_get_size (caps))
2931 str = gst_caps_get_structure (caps, 0);
2933 /* extradata parsing (esds [mpeg4], wma/wmv, msmpeg4v1/2/3, etc.) */
2934 if ((value = gst_structure_get_value (str, "codec_data"))) {
2937 buf = gst_value_get_buffer (value);
2938 gst_buffer_map (buf, &map, GST_MAP_READ);
2940 /* free the old one if it is there */
2941 if (context->extradata)
2942 av_free (context->extradata);
2945 if (codec_id == AV_CODEC_ID_H264) {
2948 GST_DEBUG ("copy, escaping codec_data %d", size);
2949 /* ffmpeg h264 expects the codec_data to be escaped, there is no real
2950 * reason for this but let's just escape it for now. Start by allocating
2951 * enough space, x2 is more than enough.
2953 * FIXME, we disabled escaping because some file already contain escaped
2954 * codec_data and then we escape twice and fail. It's better to leave it
2955 * as is, as that is what most players do. */
2956 context->extradata =
2957 av_mallocz (GST_ROUND_UP_16 (size * 2 +
2958 FF_INPUT_BUFFER_PADDING_SIZE));
2959 copy_config (context->extradata, data, size, &extrasize);
2960 GST_DEBUG ("escaped size: %d", extrasize);
2961 context->extradata_size = extrasize;
2965 /* allocate with enough padding */
2966 GST_DEBUG ("copy codec_data");
2967 context->extradata =
2968 av_mallocz (GST_ROUND_UP_16 (map.size +
2969 FF_INPUT_BUFFER_PADDING_SIZE));
2970 memcpy (context->extradata, map.data, map.size);
2971 context->extradata_size = map.size;
2974 /* Hack for VC1. Sometimes the first (length) byte is 0 for some files */
2975 if (codec_id == AV_CODEC_ID_VC1 && map.size > 0 && map.data[0] == 0) {
2976 context->extradata[0] = (guint8) map.size;
2979 GST_DEBUG ("have codec data of size %" G_GSIZE_FORMAT, map.size);
2981 gst_buffer_unmap (buf, &map);
2983 context->extradata = NULL;
2984 context->extradata_size = 0;
2985 GST_DEBUG ("no codec data");
2989 case AV_CODEC_ID_MPEG4:
2991 const gchar *mime = gst_structure_get_name (str);
2993 context->flags |= CODEC_FLAG_4MV;
2995 if (!strcmp (mime, "video/x-divx"))
2996 context->codec_tag = GST_MAKE_FOURCC ('D', 'I', 'V', 'X');
2997 else if (!strcmp (mime, "video/mpeg")) {
2998 const gchar *profile;
3000 context->codec_tag = GST_MAKE_FOURCC ('m', 'p', '4', 'v');
3002 profile = gst_structure_get_string (str, "profile");
3004 if (g_strcmp0 (profile, "advanced-simple") == 0)
3005 context->flags |= CODEC_FLAG_GMC | CODEC_FLAG_QPEL;
3011 case AV_CODEC_ID_SVQ3:
3012 /* FIXME: this is a workaround for older gst-plugins releases
3013 * (<= 0.8.9). This should be removed at some point, because
3014 * it causes wrong decoded frame order. */
3015 if (!context->extradata) {
3016 gint halfpel_flag, thirdpel_flag, low_delay, unknown_svq3_flag;
3019 if (gst_structure_get_int (str, "halfpel_flag", &halfpel_flag) &&
3020 gst_structure_get_int (str, "thirdpel_flag", &thirdpel_flag) &&
3021 gst_structure_get_int (str, "low_delay", &low_delay) &&
3022 gst_structure_get_int (str, "unknown_svq3_flag",
3023 &unknown_svq3_flag)) {
3024 context->extradata = (guint8 *) av_mallocz (0x64);
3025 g_stpcpy ((gchar *) context->extradata, "SVQ3");
3029 flags |= unknown_svq3_flag;
3031 flags |= halfpel_flag;
3033 flags |= thirdpel_flag;
3036 flags = GUINT16_FROM_LE (flags);
3038 memcpy ((gchar *) context->extradata + 0x62, &flags, 2);
3039 context->extradata_size = 0x64;
3044 case AV_CODEC_ID_MSRLE:
3045 case AV_CODEC_ID_QTRLE:
3046 case AV_CODEC_ID_TSCC:
3047 case AV_CODEC_ID_CSCD:
3048 case AV_CODEC_ID_APE:
3052 if (gst_structure_get_int (str, "depth", &depth)) {
3053 context->bits_per_coded_sample = depth;
3055 GST_WARNING ("No depth field in caps %" GST_PTR_FORMAT, caps);
3061 case AV_CODEC_ID_COOK:
3062 case AV_CODEC_ID_RA_288:
3063 case AV_CODEC_ID_RA_144:
3064 case AV_CODEC_ID_SIPR:
3069 if (gst_structure_get_int (str, "leaf_size", &leaf_size))
3070 context->block_align = leaf_size;
3071 if (gst_structure_get_int (str, "bitrate", &bitrate))
3072 context->bit_rate = bitrate;
3075 case AV_CODEC_ID_ALAC:
3076 gst_structure_get_int (str, "samplesize",
3077 &context->bits_per_coded_sample);
3080 case AV_CODEC_ID_DVVIDEO:
3082 const gchar *format;
3084 if ((format = gst_structure_get_string (str, "format"))) {
3086 if (g_str_equal (format, "YUY2"))
3087 context->pix_fmt = AV_PIX_FMT_YUYV422;
3088 else if (g_str_equal (format, "I420"))
3089 context->pix_fmt = AV_PIX_FMT_YUV420P;
3090 else if (g_str_equal (format, "A420"))
3091 context->pix_fmt = AV_PIX_FMT_YUVA420P;
3092 else if (g_str_equal (format, "Y41B"))
3093 context->pix_fmt = AV_PIX_FMT_YUV411P;
3094 else if (g_str_equal (format, "Y42B"))
3095 context->pix_fmt = AV_PIX_FMT_YUV422P;
3096 else if (g_str_equal (format, "YUV9"))
3097 context->pix_fmt = AV_PIX_FMT_YUV410P;
3099 GST_WARNING ("couldn't convert format %s" " to a pixel format",
3103 GST_WARNING ("No specified format");
3106 case AV_CODEC_ID_H263P:
3110 if (!gst_structure_get_boolean (str, "annex-f", &val) || val)
3111 context->flags |= CODEC_FLAG_4MV;
3113 context->flags &= ~CODEC_FLAG_4MV;
3114 if ((!gst_structure_get_boolean (str, "annex-i", &val) || val) &&
3115 (!gst_structure_get_boolean (str, "annex-t", &val) || val))
3116 context->flags |= CODEC_FLAG_AC_PRED;
3118 context->flags &= ~CODEC_FLAG_AC_PRED;
3119 if (!gst_structure_get_boolean (str, "annex-j", &val) || val)
3120 context->flags |= CODEC_FLAG_LOOP_FILTER;
3122 context->flags &= ~CODEC_FLAG_LOOP_FILTER;
3125 case AV_CODEC_ID_ADPCM_G726:
3127 const gchar *layout;
3129 if ((layout = gst_structure_get_string (str, "layout"))) {
3130 if (!strcmp (layout, "g721")) {
3131 context->sample_rate = 8000;
3132 context->channels = 1;
3133 context->bit_rate = 32000;
3142 if (!gst_caps_is_fixed (caps))
3145 /* common properties (width, height, fps) */
3146 switch (codec_type) {
3147 case AVMEDIA_TYPE_VIDEO:
3148 gst_ffmpeg_caps_to_pixfmt (caps, context,
3149 codec_id == AV_CODEC_ID_RAWVIDEO);
3151 case AVMEDIA_TYPE_AUDIO:
3152 gst_ffmpeg_caps_to_smpfmt (caps, context, FALSE);
3158 /* fixup of default settings */
3160 case AV_CODEC_ID_QCELP:
3161 /* QCELP is always mono, no matter what the caps say */
3162 context->channels = 1;
3164 case AV_CODEC_ID_ADPCM_G726:
3165 if (context->sample_rate && context->bit_rate)
3166 context->bits_per_coded_sample =
3167 context->bit_rate / context->sample_rate;
3174 /* _formatid_to_caps () is meant for muxers/demuxers, it
3175 * transforms a name (ffmpeg way of ID'ing these, why don't
3176 * they have unique numerical IDs?) to the corresponding
3177 * caps belonging to that mux-format
3179 * Note: we don't need any additional info because the caps
3180 * isn't supposed to contain any useful info besides the
3185 gst_ffmpeg_formatid_to_caps (const gchar * format_name)
3187 GstCaps *caps = NULL;
3189 if (!strcmp (format_name, "mpeg")) {
3190 caps = gst_caps_new_simple ("video/mpeg",
3191 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3192 } else if (!strcmp (format_name, "mpegts")) {
3193 caps = gst_caps_new_simple ("video/mpegts",
3194 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3195 } else if (!strcmp (format_name, "rm")) {
3196 caps = gst_caps_new_simple ("application/x-pn-realmedia",
3197 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3198 } else if (!strcmp (format_name, "asf")) {
3199 caps = gst_caps_new_empty_simple ("video/x-ms-asf");
3200 } else if (!strcmp (format_name, "avi")) {
3201 caps = gst_caps_new_empty_simple ("video/x-msvideo");
3202 } else if (!strcmp (format_name, "wav")) {
3203 caps = gst_caps_new_empty_simple ("audio/x-wav");
3204 } else if (!strcmp (format_name, "ape")) {
3205 caps = gst_caps_new_empty_simple ("application/x-ape");
3206 } else if (!strcmp (format_name, "swf")) {
3207 caps = gst_caps_new_empty_simple ("application/x-shockwave-flash");
3208 } else if (!strcmp (format_name, "au")) {
3209 caps = gst_caps_new_empty_simple ("audio/x-au");
3210 } else if (!strcmp (format_name, "dv")) {
3211 caps = gst_caps_new_simple ("video/x-dv",
3212 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3213 } else if (!strcmp (format_name, "4xm")) {
3214 caps = gst_caps_new_empty_simple ("video/x-4xm");
3215 } else if (!strcmp (format_name, "matroska")) {
3216 caps = gst_caps_new_empty_simple ("video/x-matroska");
3217 } else if (!strcmp (format_name, "mp3")) {
3218 caps = gst_caps_new_empty_simple ("application/x-id3");
3219 } else if (!strcmp (format_name, "flic")) {
3220 caps = gst_caps_new_empty_simple ("video/x-fli");
3221 } else if (!strcmp (format_name, "flv")) {
3222 caps = gst_caps_new_empty_simple ("video/x-flv");
3223 } else if (!strcmp (format_name, "tta")) {
3224 caps = gst_caps_new_empty_simple ("audio/x-ttafile");
3225 } else if (!strcmp (format_name, "aiff")) {
3226 caps = gst_caps_new_empty_simple ("audio/x-aiff");
3227 } else if (!strcmp (format_name, "mov_mp4_m4a_3gp_3g2")) {
3229 gst_caps_from_string
3230 ("application/x-3gp; video/quicktime; audio/x-m4a");
3231 } else if (!strcmp (format_name, "mov")) {
3232 caps = gst_caps_from_string ("video/quicktime,variant=(string)apple");
3233 } else if (!strcmp (format_name, "mp4")) {
3234 caps = gst_caps_from_string ("video/quicktime,variant=(string)iso");
3235 } else if (!strcmp (format_name, "3gp")) {
3236 caps = gst_caps_from_string ("video/quicktime,variant=(string)3gpp");
3237 } else if (!strcmp (format_name, "3g2")) {
3238 caps = gst_caps_from_string ("video/quicktime,variant=(string)3g2");
3239 } else if (!strcmp (format_name, "psp")) {
3240 caps = gst_caps_from_string ("video/quicktime,variant=(string)psp");
3241 } else if (!strcmp (format_name, "ipod")) {
3242 caps = gst_caps_from_string ("video/quicktime,variant=(string)ipod");
3243 } else if (!strcmp (format_name, "aac")) {
3244 caps = gst_caps_new_simple ("audio/mpeg",
3245 "mpegversion", G_TYPE_INT, 4, NULL);
3246 } else if (!strcmp (format_name, "gif")) {
3247 caps = gst_caps_from_string ("image/gif");
3248 } else if (!strcmp (format_name, "ogg")) {
3249 caps = gst_caps_from_string ("application/ogg");
3250 } else if (!strcmp (format_name, "mxf") || !strcmp (format_name, "mxf_d10")) {
3251 caps = gst_caps_from_string ("application/mxf");
3252 } else if (!strcmp (format_name, "gxf")) {
3253 caps = gst_caps_from_string ("application/gxf");
3254 } else if (!strcmp (format_name, "yuv4mpegpipe")) {
3255 caps = gst_caps_new_simple ("application/x-yuv4mpeg",
3256 "y4mversion", G_TYPE_INT, 2, NULL);
3257 } else if (!strcmp (format_name, "mpc")) {
3258 caps = gst_caps_from_string ("audio/x-musepack, streamversion = (int) 7");
3259 } else if (!strcmp (format_name, "mpc8")) {
3260 caps = gst_caps_from_string ("audio/x-musepack, streamversion = (int) 8");
3261 } else if (!strcmp (format_name, "vqf")) {
3262 caps = gst_caps_from_string ("audio/x-vqf");
3263 } else if (!strcmp (format_name, "nsv")) {
3264 caps = gst_caps_from_string ("video/x-nsv");
3265 } else if (!strcmp (format_name, "amr")) {
3266 caps = gst_caps_from_string ("audio/x-amr-nb-sh");
3267 } else if (!strcmp (format_name, "webm")) {
3268 caps = gst_caps_from_string ("video/webm");
3269 } else if (!strcmp (format_name, "voc")) {
3270 caps = gst_caps_from_string ("audio/x-voc");
3271 } else if (!strcmp (format_name, "pva")) {
3272 caps = gst_caps_from_string ("video/x-pva");
3276 GST_LOG ("Could not create stream format caps for %s", format_name);
3277 name = g_strdup_printf ("application/x-gst-av-%s", format_name);
3278 caps = gst_caps_new_empty_simple (name);
3286 gst_ffmpeg_formatid_get_codecids (const gchar * format_name,
3287 enum AVCodecID ** video_codec_list, enum AVCodecID ** audio_codec_list,
3288 AVOutputFormat * plugin)
3290 static enum AVCodecID tmp_vlist[] = {
3294 static enum AVCodecID tmp_alist[] = {
3299 GST_LOG ("format_name : %s", format_name);
3301 if (!strcmp (format_name, "mp4")) {
3302 static enum AVCodecID mp4_video_list[] = {
3303 AV_CODEC_ID_MPEG4, AV_CODEC_ID_H264,
3307 static enum AVCodecID mp4_audio_list[] = {
3308 AV_CODEC_ID_AAC, AV_CODEC_ID_MP3,
3312 *video_codec_list = mp4_video_list;
3313 *audio_codec_list = mp4_audio_list;
3314 } else if (!strcmp (format_name, "mpeg")) {
3315 static enum AVCodecID mpeg_video_list[] = { AV_CODEC_ID_MPEG1VIDEO,
3316 AV_CODEC_ID_MPEG2VIDEO,
3320 static enum AVCodecID mpeg_audio_list[] = { AV_CODEC_ID_MP1,
3326 *video_codec_list = mpeg_video_list;
3327 *audio_codec_list = mpeg_audio_list;
3328 } else if (!strcmp (format_name, "dvd")) {
3329 static enum AVCodecID mpeg_video_list[] = { AV_CODEC_ID_MPEG2VIDEO,
3332 static enum AVCodecID mpeg_audio_list[] = { AV_CODEC_ID_MP2,
3335 AV_CODEC_ID_PCM_S16BE,
3339 *video_codec_list = mpeg_video_list;
3340 *audio_codec_list = mpeg_audio_list;
3341 } else if (!strcmp (format_name, "mpegts")) {
3342 static enum AVCodecID mpegts_video_list[] = { AV_CODEC_ID_MPEG1VIDEO,
3343 AV_CODEC_ID_MPEG2VIDEO,
3347 static enum AVCodecID mpegts_audio_list[] = { AV_CODEC_ID_MP2,
3355 *video_codec_list = mpegts_video_list;
3356 *audio_codec_list = mpegts_audio_list;
3357 } else if (!strcmp (format_name, "vob")) {
3358 static enum AVCodecID vob_video_list[] =
3359 { AV_CODEC_ID_MPEG2VIDEO, AV_CODEC_ID_NONE };
3360 static enum AVCodecID vob_audio_list[] = { AV_CODEC_ID_MP2, AV_CODEC_ID_AC3,
3361 AV_CODEC_ID_DTS, AV_CODEC_ID_NONE
3364 *video_codec_list = vob_video_list;
3365 *audio_codec_list = vob_audio_list;
3366 } else if (!strcmp (format_name, "flv")) {
3367 static enum AVCodecID flv_video_list[] =
3368 { AV_CODEC_ID_FLV1, AV_CODEC_ID_NONE };
3369 static enum AVCodecID flv_audio_list[] =
3370 { AV_CODEC_ID_MP3, AV_CODEC_ID_NONE };
3372 *video_codec_list = flv_video_list;
3373 *audio_codec_list = flv_audio_list;
3374 } else if (!strcmp (format_name, "asf")) {
3375 static enum AVCodecID asf_video_list[] =
3376 { AV_CODEC_ID_WMV1, AV_CODEC_ID_WMV2, AV_CODEC_ID_MSMPEG4V3,
3379 static enum AVCodecID asf_audio_list[] =
3380 { AV_CODEC_ID_WMAV1, AV_CODEC_ID_WMAV2, AV_CODEC_ID_MP3,
3384 *video_codec_list = asf_video_list;
3385 *audio_codec_list = asf_audio_list;
3386 } else if (!strcmp (format_name, "dv")) {
3387 static enum AVCodecID dv_video_list[] =
3388 { AV_CODEC_ID_DVVIDEO, AV_CODEC_ID_NONE };
3389 static enum AVCodecID dv_audio_list[] =
3390 { AV_CODEC_ID_PCM_S16LE, AV_CODEC_ID_NONE };
3392 *video_codec_list = dv_video_list;
3393 *audio_codec_list = dv_audio_list;
3394 } else if (!strcmp (format_name, "mov")) {
3395 static enum AVCodecID mov_video_list[] = {
3396 AV_CODEC_ID_SVQ1, AV_CODEC_ID_SVQ3, AV_CODEC_ID_MPEG4,
3397 AV_CODEC_ID_H263, AV_CODEC_ID_H263P,
3398 AV_CODEC_ID_H264, AV_CODEC_ID_DVVIDEO,
3402 static enum AVCodecID mov_audio_list[] = {
3403 AV_CODEC_ID_PCM_MULAW, AV_CODEC_ID_PCM_ALAW, AV_CODEC_ID_ADPCM_IMA_QT,
3404 AV_CODEC_ID_MACE3, AV_CODEC_ID_MACE6, AV_CODEC_ID_AAC,
3405 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3406 AV_CODEC_ID_PCM_S16BE, AV_CODEC_ID_PCM_S16LE,
3407 AV_CODEC_ID_MP3, AV_CODEC_ID_NONE
3410 *video_codec_list = mov_video_list;
3411 *audio_codec_list = mov_audio_list;
3412 } else if ((!strcmp (format_name, "3gp") || !strcmp (format_name, "3g2"))) {
3413 static enum AVCodecID tgp_video_list[] = {
3414 AV_CODEC_ID_MPEG4, AV_CODEC_ID_H263, AV_CODEC_ID_H263P, AV_CODEC_ID_H264,
3417 static enum AVCodecID tgp_audio_list[] = {
3418 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3423 *video_codec_list = tgp_video_list;
3424 *audio_codec_list = tgp_audio_list;
3425 } else if (!strcmp (format_name, "mmf")) {
3426 static enum AVCodecID mmf_audio_list[] = {
3427 AV_CODEC_ID_ADPCM_YAMAHA, AV_CODEC_ID_NONE
3429 *video_codec_list = NULL;
3430 *audio_codec_list = mmf_audio_list;
3431 } else if (!strcmp (format_name, "amr")) {
3432 static enum AVCodecID amr_audio_list[] = {
3433 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3436 *video_codec_list = NULL;
3437 *audio_codec_list = amr_audio_list;
3438 } else if (!strcmp (format_name, "gif")) {
3439 static enum AVCodecID gif_image_list[] = {
3440 AV_CODEC_ID_RAWVIDEO, AV_CODEC_ID_NONE
3442 *video_codec_list = gif_image_list;
3443 *audio_codec_list = NULL;
3444 } else if ((plugin->audio_codec != AV_CODEC_ID_NONE) ||
3445 (plugin->video_codec != AV_CODEC_ID_NONE)) {
3446 tmp_vlist[0] = plugin->video_codec;
3447 tmp_alist[0] = plugin->audio_codec;
3449 *video_codec_list = tmp_vlist;
3450 *audio_codec_list = tmp_alist;
3451 } else if ((!strcmp (format_name, "pva"))) {
3452 static enum AVCodecID tgp_video_list[] = {
3453 AV_CODEC_ID_MPEG2VIDEO,
3456 static enum AVCodecID tgp_audio_list[] = {
3461 *video_codec_list = tgp_video_list;
3462 *audio_codec_list = tgp_audio_list;
3464 GST_LOG ("Format %s not found", format_name);
3471 /* Convert a GstCaps to a FFMPEG codec ID. Size et all
3472 * are omitted, that can be queried by the user itself,
3473 * we're not eating the GstCaps or anything
3474 * A pointer to an allocated context is also needed for
3475 * optional extra info
3479 gst_ffmpeg_caps_to_codecid (const GstCaps * caps, AVCodecContext * context)
3481 enum AVCodecID id = AV_CODEC_ID_NONE;
3482 const gchar *mimetype;
3483 const GstStructure *structure;
3484 gboolean video = FALSE, audio = FALSE; /* we want to be sure! */
3486 g_return_val_if_fail (caps != NULL, AV_CODEC_ID_NONE);
3487 g_return_val_if_fail (gst_caps_get_size (caps) == 1, AV_CODEC_ID_NONE);
3488 structure = gst_caps_get_structure (caps, 0);
3490 mimetype = gst_structure_get_name (structure);
3492 if (!strcmp (mimetype, "video/x-raw")) {
3493 id = AV_CODEC_ID_RAWVIDEO;
3495 } else if (!strcmp (mimetype, "audio/x-raw")) {
3498 if (gst_audio_info_from_caps (&info, caps)) {
3499 switch (GST_AUDIO_INFO_FORMAT (&info)) {
3500 case GST_AUDIO_FORMAT_S8:
3501 id = AV_CODEC_ID_PCM_S8;
3503 case GST_AUDIO_FORMAT_U8:
3504 id = AV_CODEC_ID_PCM_U8;
3506 case GST_AUDIO_FORMAT_S16LE:
3507 id = AV_CODEC_ID_PCM_S16LE;
3509 case GST_AUDIO_FORMAT_S16BE:
3510 id = AV_CODEC_ID_PCM_S16BE;
3512 case GST_AUDIO_FORMAT_U16LE:
3513 id = AV_CODEC_ID_PCM_U16LE;
3515 case GST_AUDIO_FORMAT_U16BE:
3516 id = AV_CODEC_ID_PCM_U16BE;
3521 if (id != AV_CODEC_ID_NONE)
3524 } else if (!strcmp (mimetype, "audio/x-mulaw")) {
3525 id = AV_CODEC_ID_PCM_MULAW;
3527 } else if (!strcmp (mimetype, "audio/x-alaw")) {
3528 id = AV_CODEC_ID_PCM_ALAW;
3530 } else if (!strcmp (mimetype, "video/x-dv")) {
3533 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3535 id = AV_CODEC_ID_DVVIDEO;
3538 } else if (!strcmp (mimetype, "audio/x-dv")) { /* ??? */
3539 id = AV_CODEC_ID_DVAUDIO;
3541 } else if (!strcmp (mimetype, "video/x-h263")) {
3542 const gchar *h263version =
3543 gst_structure_get_string (structure, "h263version");
3544 if (h263version && !strcmp (h263version, "h263p"))
3545 id = AV_CODEC_ID_H263P;
3547 id = AV_CODEC_ID_H263;
3549 } else if (!strcmp (mimetype, "video/x-intel-h263")) {
3550 id = AV_CODEC_ID_H263I;
3552 } else if (!strcmp (mimetype, "video/x-h261")) {
3553 id = AV_CODEC_ID_H261;
3555 } else if (!strcmp (mimetype, "video/mpeg")) {
3559 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3560 gst_structure_get_int (structure, "mpegversion", &mpegversion) &&
3562 switch (mpegversion) {
3564 id = AV_CODEC_ID_MPEG1VIDEO;
3567 id = AV_CODEC_ID_MPEG2VIDEO;
3570 id = AV_CODEC_ID_MPEG4;
3574 if (id != AV_CODEC_ID_NONE)
3576 } else if (!strcmp (mimetype, "image/jpeg")) {
3577 id = AV_CODEC_ID_MJPEG; /* A... B... */
3579 } else if (!strcmp (mimetype, "video/x-jpeg-b")) {
3580 id = AV_CODEC_ID_MJPEGB;
3582 } else if (!strcmp (mimetype, "video/x-wmv")) {
3583 gint wmvversion = 0;
3585 if (gst_structure_get_int (structure, "wmvversion", &wmvversion)) {
3586 switch (wmvversion) {
3588 id = AV_CODEC_ID_WMV1;
3591 id = AV_CODEC_ID_WMV2;
3595 const gchar *format;
3597 /* WMV3 unless the fourcc exists and says otherwise */
3598 id = AV_CODEC_ID_WMV3;
3600 if ((format = gst_structure_get_string (structure, "format")) &&
3601 (g_str_equal (format, "WVC1") || g_str_equal (format, "WMVA")))
3602 id = AV_CODEC_ID_VC1;
3608 if (id != AV_CODEC_ID_NONE)
3610 } else if (!strcmp (mimetype, "audio/x-vorbis")) {
3611 id = AV_CODEC_ID_VORBIS;
3613 } else if (!strcmp (mimetype, "audio/x-qdm2")) {
3614 id = AV_CODEC_ID_QDM2;
3616 } else if (!strcmp (mimetype, "audio/mpeg")) {
3618 gint mpegversion = 0;
3620 if (gst_structure_get_int (structure, "mpegversion", &mpegversion)) {
3621 switch (mpegversion) {
3622 case 2: /* ffmpeg uses faad for both... */
3624 id = AV_CODEC_ID_AAC;
3627 if (gst_structure_get_int (structure, "layer", &layer)) {
3630 id = AV_CODEC_ID_MP1;
3633 id = AV_CODEC_ID_MP2;
3636 id = AV_CODEC_ID_MP3;
3642 if (id != AV_CODEC_ID_NONE)
3644 } else if (!strcmp (mimetype, "audio/x-musepack")) {
3645 gint streamversion = -1;
3647 if (gst_structure_get_int (structure, "streamversion", &streamversion)) {
3648 if (streamversion == 7)
3649 id = AV_CODEC_ID_MUSEPACK7;
3651 id = AV_CODEC_ID_MUSEPACK7;
3653 } else if (!strcmp (mimetype, "audio/x-wma")) {
3654 gint wmaversion = 0;
3656 if (gst_structure_get_int (structure, "wmaversion", &wmaversion)) {
3657 switch (wmaversion) {
3659 id = AV_CODEC_ID_WMAV1;
3662 id = AV_CODEC_ID_WMAV2;
3665 id = AV_CODEC_ID_WMAPRO;
3669 if (id != AV_CODEC_ID_NONE)
3671 } else if (!strcmp (mimetype, "audio/x-wms")) {
3672 id = AV_CODEC_ID_WMAVOICE;
3674 } else if (!strcmp (mimetype, "audio/x-ac3")) {
3675 id = AV_CODEC_ID_AC3;
3677 } else if (!strcmp (mimetype, "audio/x-eac3")) {
3678 id = AV_CODEC_ID_EAC3;
3680 } else if (!strcmp (mimetype, "audio/x-vnd.sony.atrac3") ||
3681 !strcmp (mimetype, "audio/atrac3")) {
3682 id = AV_CODEC_ID_ATRAC3;
3684 } else if (!strcmp (mimetype, "audio/x-dts")) {
3685 id = AV_CODEC_ID_DTS;
3687 } else if (!strcmp (mimetype, "application/x-ape")) {
3688 id = AV_CODEC_ID_APE;
3690 } else if (!strcmp (mimetype, "video/x-msmpeg")) {
3691 gint msmpegversion = 0;
3693 if (gst_structure_get_int (structure, "msmpegversion", &msmpegversion)) {
3694 switch (msmpegversion) {
3696 id = AV_CODEC_ID_MSMPEG4V1;
3699 id = AV_CODEC_ID_MSMPEG4V2;
3702 id = AV_CODEC_ID_MSMPEG4V3;
3706 if (id != AV_CODEC_ID_NONE)
3708 } else if (!strcmp (mimetype, "video/x-svq")) {
3709 gint svqversion = 0;
3711 if (gst_structure_get_int (structure, "svqversion", &svqversion)) {
3712 switch (svqversion) {
3714 id = AV_CODEC_ID_SVQ1;
3717 id = AV_CODEC_ID_SVQ3;
3721 if (id != AV_CODEC_ID_NONE)
3723 } else if (!strcmp (mimetype, "video/x-huffyuv")) {
3724 id = AV_CODEC_ID_HUFFYUV;
3726 } else if (!strcmp (mimetype, "audio/x-mace")) {
3727 gint maceversion = 0;
3729 if (gst_structure_get_int (structure, "maceversion", &maceversion)) {
3730 switch (maceversion) {
3732 id = AV_CODEC_ID_MACE3;
3735 id = AV_CODEC_ID_MACE6;
3739 if (id != AV_CODEC_ID_NONE)
3741 } else if (!strcmp (mimetype, "video/x-theora")) {
3742 id = AV_CODEC_ID_THEORA;
3744 } else if (!strcmp (mimetype, "video/x-vp3")) {
3745 id = AV_CODEC_ID_VP3;
3747 } else if (!strcmp (mimetype, "video/x-vp5")) {
3748 id = AV_CODEC_ID_VP5;
3750 } else if (!strcmp (mimetype, "video/x-vp6")) {
3751 id = AV_CODEC_ID_VP6;
3753 } else if (!strcmp (mimetype, "video/x-vp6-flash")) {
3754 id = AV_CODEC_ID_VP6F;
3756 } else if (!strcmp (mimetype, "video/x-vp6-alpha")) {
3757 id = AV_CODEC_ID_VP6A;
3759 } else if (!strcmp (mimetype, "video/x-vp8")) {
3760 id = AV_CODEC_ID_VP8;
3762 } else if (!strcmp (mimetype, "video/x-vp9")) {
3763 id = AV_CODEC_ID_VP9;
3765 } else if (!strcmp (mimetype, "video/x-flash-screen")) {
3766 id = AV_CODEC_ID_FLASHSV;
3768 } else if (!strcmp (mimetype, "video/x-indeo")) {
3769 gint indeoversion = 0;
3771 if (gst_structure_get_int (structure, "indeoversion", &indeoversion)) {
3772 switch (indeoversion) {
3774 id = AV_CODEC_ID_INDEO5;
3777 id = AV_CODEC_ID_INDEO4;
3780 id = AV_CODEC_ID_INDEO3;
3783 id = AV_CODEC_ID_INDEO2;
3786 if (id != AV_CODEC_ID_NONE)
3789 } else if (!strcmp (mimetype, "video/x-divx")) {
3790 gint divxversion = 0;
3792 if (gst_structure_get_int (structure, "divxversion", &divxversion)) {
3793 switch (divxversion) {
3795 id = AV_CODEC_ID_MSMPEG4V3;
3799 id = AV_CODEC_ID_MPEG4;
3803 if (id != AV_CODEC_ID_NONE)
3805 } else if (!strcmp (mimetype, "video/x-ffv")) {
3806 gint ffvversion = 0;
3808 if (gst_structure_get_int (structure, "ffvversion", &ffvversion) &&
3810 id = AV_CODEC_ID_FFV1;
3813 } else if (!strcmp (mimetype, "video/x-apple-intermediate-codec")) {
3814 id = AV_CODEC_ID_AIC;
3816 } else if (!strcmp (mimetype, "audio/x-adpcm")) {
3817 const gchar *layout;
3819 layout = gst_structure_get_string (structure, "layout");
3820 if (layout == NULL) {
3822 } else if (!strcmp (layout, "quicktime")) {
3823 id = AV_CODEC_ID_ADPCM_IMA_QT;
3824 } else if (!strcmp (layout, "microsoft")) {
3825 id = AV_CODEC_ID_ADPCM_MS;
3826 } else if (!strcmp (layout, "dvi")) {
3827 id = AV_CODEC_ID_ADPCM_IMA_WAV;
3828 } else if (!strcmp (layout, "4xm")) {
3829 id = AV_CODEC_ID_ADPCM_4XM;
3830 } else if (!strcmp (layout, "smjpeg")) {
3831 id = AV_CODEC_ID_ADPCM_IMA_SMJPEG;
3832 } else if (!strcmp (layout, "dk3")) {
3833 id = AV_CODEC_ID_ADPCM_IMA_DK3;
3834 } else if (!strcmp (layout, "dk4")) {
3835 id = AV_CODEC_ID_ADPCM_IMA_DK4;
3836 } else if (!strcmp (layout, "westwood")) {
3837 id = AV_CODEC_ID_ADPCM_IMA_WS;
3838 } else if (!strcmp (layout, "iss")) {
3839 id = AV_CODEC_ID_ADPCM_IMA_ISS;
3840 } else if (!strcmp (layout, "xa")) {
3841 id = AV_CODEC_ID_ADPCM_XA;
3842 } else if (!strcmp (layout, "adx")) {
3843 id = AV_CODEC_ID_ADPCM_ADX;
3844 } else if (!strcmp (layout, "ea")) {
3845 id = AV_CODEC_ID_ADPCM_EA;
3846 } else if (!strcmp (layout, "g726")) {
3847 id = AV_CODEC_ID_ADPCM_G726;
3848 } else if (!strcmp (layout, "g721")) {
3849 id = AV_CODEC_ID_ADPCM_G726;
3850 } else if (!strcmp (layout, "ct")) {
3851 id = AV_CODEC_ID_ADPCM_CT;
3852 } else if (!strcmp (layout, "swf")) {
3853 id = AV_CODEC_ID_ADPCM_SWF;
3854 } else if (!strcmp (layout, "yamaha")) {
3855 id = AV_CODEC_ID_ADPCM_YAMAHA;
3856 } else if (!strcmp (layout, "sbpro2")) {
3857 id = AV_CODEC_ID_ADPCM_SBPRO_2;
3858 } else if (!strcmp (layout, "sbpro3")) {
3859 id = AV_CODEC_ID_ADPCM_SBPRO_3;
3860 } else if (!strcmp (layout, "sbpro4")) {
3861 id = AV_CODEC_ID_ADPCM_SBPRO_4;
3863 if (id != AV_CODEC_ID_NONE)
3865 } else if (!strcmp (mimetype, "video/x-4xm")) {
3866 id = AV_CODEC_ID_4XM;
3868 } else if (!strcmp (mimetype, "audio/x-dpcm")) {
3869 const gchar *layout;
3871 layout = gst_structure_get_string (structure, "layout");
3874 } else if (!strcmp (layout, "roq")) {
3875 id = AV_CODEC_ID_ROQ_DPCM;
3876 } else if (!strcmp (layout, "interplay")) {
3877 id = AV_CODEC_ID_INTERPLAY_DPCM;
3878 } else if (!strcmp (layout, "xan")) {
3879 id = AV_CODEC_ID_XAN_DPCM;
3880 } else if (!strcmp (layout, "sol")) {
3881 id = AV_CODEC_ID_SOL_DPCM;
3883 if (id != AV_CODEC_ID_NONE)
3885 } else if (!strcmp (mimetype, "audio/x-flac")) {
3886 id = AV_CODEC_ID_FLAC;
3888 } else if (!strcmp (mimetype, "audio/x-shorten")) {
3889 id = AV_CODEC_ID_SHORTEN;
3891 } else if (!strcmp (mimetype, "audio/x-alac")) {
3892 id = AV_CODEC_ID_ALAC;
3894 } else if (!strcmp (mimetype, "video/x-cinepak")) {
3895 id = AV_CODEC_ID_CINEPAK;
3897 } else if (!strcmp (mimetype, "video/x-pn-realvideo")) {
3900 if (gst_structure_get_int (structure, "rmversion", &rmversion)) {
3901 switch (rmversion) {
3903 id = AV_CODEC_ID_RV10;
3906 id = AV_CODEC_ID_RV20;
3909 id = AV_CODEC_ID_RV30;
3912 id = AV_CODEC_ID_RV40;
3916 if (id != AV_CODEC_ID_NONE)
3918 } else if (!strcmp (mimetype, "audio/x-sipro")) {
3919 id = AV_CODEC_ID_SIPR;
3921 } else if (!strcmp (mimetype, "audio/x-pn-realaudio")) {
3924 if (gst_structure_get_int (structure, "raversion", &raversion)) {
3925 switch (raversion) {
3927 id = AV_CODEC_ID_RA_144;
3930 id = AV_CODEC_ID_RA_288;
3933 id = AV_CODEC_ID_COOK;
3937 if (id != AV_CODEC_ID_NONE)
3939 } else if (!strcmp (mimetype, "video/x-rle")) {
3940 const gchar *layout;
3942 if ((layout = gst_structure_get_string (structure, "layout"))) {
3943 if (!strcmp (layout, "microsoft")) {
3944 id = AV_CODEC_ID_MSRLE;
3948 } else if (!strcmp (mimetype, "video/x-xan")) {
3951 if ((gst_structure_get_int (structure, "wcversion", &wcversion))) {
3952 switch (wcversion) {
3954 id = AV_CODEC_ID_XAN_WC3;
3958 id = AV_CODEC_ID_XAN_WC4;
3965 } else if (!strcmp (mimetype, "audio/AMR")) {
3967 id = AV_CODEC_ID_AMR_NB;
3968 } else if (!strcmp (mimetype, "audio/AMR-WB")) {
3969 id = AV_CODEC_ID_AMR_WB;
3971 } else if (!strcmp (mimetype, "audio/qcelp")) {
3972 id = AV_CODEC_ID_QCELP;
3974 } else if (!strcmp (mimetype, "video/x-h264")) {
3975 id = AV_CODEC_ID_H264;
3977 } else if (!strcmp (mimetype, "video/x-h265")) {
3978 id = AV_CODEC_ID_HEVC;
3980 } else if (!strcmp (mimetype, "video/x-flash-video")) {
3981 gint flvversion = 0;
3983 if ((gst_structure_get_int (structure, "flvversion", &flvversion))) {
3984 switch (flvversion) {
3986 id = AV_CODEC_ID_FLV1;
3994 } else if (!strcmp (mimetype, "audio/x-nellymoser")) {
3995 id = AV_CODEC_ID_NELLYMOSER;
3997 } else if (!strncmp (mimetype, "audio/x-gst-av-", 15)) {
4001 if (strlen (mimetype) <= 30 &&
4002 sscanf (mimetype, "audio/x-gst-av-%s", ext) == 1) {
4003 if ((codec = avcodec_find_decoder_by_name (ext)) ||
4004 (codec = avcodec_find_encoder_by_name (ext))) {
4009 } else if (!strncmp (mimetype, "video/x-gst-av-", 15)) {
4013 if (strlen (mimetype) <= 30 &&
4014 sscanf (mimetype, "video/x-gst-av-%s", ext) == 1) {
4015 if ((codec = avcodec_find_decoder_by_name (ext)) ||
4016 (codec = avcodec_find_encoder_by_name (ext))) {
4023 if (context != NULL) {
4024 if (video == TRUE) {
4025 context->codec_type = AVMEDIA_TYPE_VIDEO;
4026 } else if (audio == TRUE) {
4027 context->codec_type = AVMEDIA_TYPE_AUDIO;
4029 context->codec_type = AVMEDIA_TYPE_UNKNOWN;
4031 context->codec_id = id;
4032 gst_ffmpeg_caps_with_codecid (id, context->codec_type, caps, context);
4035 if (id != AV_CODEC_ID_NONE) {
4036 GST_DEBUG ("The id=%d belongs to the caps %" GST_PTR_FORMAT, id, caps);
4038 GST_WARNING ("Couldn't figure out the id for caps %" GST_PTR_FORMAT, caps);