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_channel_positions_to_layout (GstAudioChannelPosition * pos,
75 gint channels_found = 0;
80 for (i = 0; i < channels; i++) {
81 for (j = 0; j < G_N_ELEMENTS (_ff_to_gst_layout); j++) {
82 if (_ff_to_gst_layout[j].gst == pos[i]) {
83 ret |= _ff_to_gst_layout[j].ff;
90 if (channels_found != channels)
96 gst_ffmpeg_channel_layout_to_gst (guint64 channel_layout, gint channels,
97 GstAudioChannelPosition * pos)
100 gboolean none_layout = FALSE;
102 if (channel_layout == 0) {
103 nchannels = channels;
108 for (i = 0; i < 64; i++) {
109 if ((channel_layout & (G_GUINT64_CONSTANT (1) << i)) != 0) {
114 if (nchannels != channels) {
115 GST_ERROR ("Number of channels is different (%u != %u)", channels,
117 nchannels = channels;
121 for (i = 0, j = 0; i < G_N_ELEMENTS (_ff_to_gst_layout); i++) {
122 if ((channel_layout & _ff_to_gst_layout[i].ff) != 0) {
123 pos[j++] = _ff_to_gst_layout[i].gst;
125 if (_ff_to_gst_layout[i].gst == GST_AUDIO_CHANNEL_POSITION_NONE)
130 if (j != nchannels) {
132 ("Unknown channels in channel layout - assuming NONE layout");
139 && !gst_audio_check_valid_channel_positions (pos, nchannels, FALSE)) {
140 GST_ERROR ("Invalid channel layout %" G_GUINT64_FORMAT
141 " - assuming NONE layout", channel_layout);
146 if (nchannels == 1) {
147 pos[0] = GST_AUDIO_CHANNEL_POSITION_MONO;
148 } else if (nchannels == 2) {
149 pos[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT;
150 pos[1] = GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT;
154 for (i = 0; i < nchannels; i++)
155 pos[i] = GST_AUDIO_CHANNEL_POSITION_NONE;
163 gst_ffmpeg_video_set_pix_fmts (GstCaps * caps, const enum AVPixelFormat *fmts)
167 GstVideoFormat format;
169 if (!fmts || fmts[0] == -1) {
172 g_value_init (&va, GST_TYPE_LIST);
173 g_value_init (&v, G_TYPE_STRING);
174 for (i = 0; i <= PIX_FMT_NB; i++) {
175 format = gst_ffmpeg_pixfmt_to_videoformat (i);
176 if (format == GST_VIDEO_FORMAT_UNKNOWN)
178 g_value_set_string (&v, gst_video_format_to_string (format));
179 gst_value_list_append_value (&va, &v);
181 gst_caps_set_value (caps, "format", &va);
187 /* Only a single format */
188 g_value_init (&va, GST_TYPE_LIST);
189 g_value_init (&v, G_TYPE_STRING);
190 while (*fmts != -1) {
191 format = gst_ffmpeg_pixfmt_to_videoformat (*fmts);
192 if (format != GST_VIDEO_FORMAT_UNKNOWN) {
193 g_value_set_string (&v, gst_video_format_to_string (format));
194 gst_value_list_append_value (&va, &v);
198 if (gst_value_list_get_size (&va) == 1) {
199 /* The single value is still in v */
200 gst_caps_set_value (caps, "format", &v);
201 } else if (gst_value_list_get_size (&va) > 1) {
202 gst_caps_set_value (caps, "format", &va);
208 /* this macro makes a caps width fixed or unfixed width/height
209 * properties depending on whether we've got a context.
211 * See below for why we use this.
213 * We should actually do this stuff at the end, like in riff-media.c,
214 * but I'm too lazy today. Maybe later.
217 gst_ff_vid_caps_new (AVCodecContext * context, AVCodec * codec,
218 enum CodecID codec_id, gboolean encode, const char *mimetype,
219 const char *fieldname, ...)
221 GstCaps *caps = NULL;
225 GST_LOG ("context:%p, codec_id:%d, mimetype:%s", context, codec_id, mimetype);
227 /* fixed, non probing context */
228 if (context != NULL && context->width != -1) {
231 caps = gst_caps_new_simple (mimetype,
232 "width", G_TYPE_INT, context->width,
233 "height", G_TYPE_INT, context->height, NULL);
235 num = context->time_base.den / context->ticks_per_frame;
236 denom = context->time_base.num;
239 GST_LOG ("invalid framerate: %d/0, -> %d/1", num, num);
242 if (gst_util_fraction_compare (num, denom, 1000, 1) > 0) {
243 GST_LOG ("excessive framerate: %d/%d, -> 0/1", num, denom);
247 GST_LOG ("setting framerate: %d/%d", num, denom);
248 gst_caps_set_simple (caps,
249 "framerate", GST_TYPE_FRACTION, num, denom, NULL);
251 /* so we are after restricted caps in this case */
253 case AV_CODEC_ID_H261:
255 caps = gst_caps_new_simple (mimetype,
256 "width", G_TYPE_INT, 352,
257 "height", G_TYPE_INT, 288,
258 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
259 gst_caps_append (caps, gst_caps_new_simple (mimetype,
260 "width", G_TYPE_INT, 176,
261 "height", G_TYPE_INT, 144,
262 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL));
265 case AV_CODEC_ID_H263:
267 /* 128x96, 176x144, 352x288, 704x576, and 1408x1152. slightly reordered
268 * because we want automatic negotiation to go as close to 320x240 as
270 const static gint widths[] = { 352, 704, 176, 1408, 128 };
271 const static gint heights[] = { 288, 576, 144, 1152, 96 };
273 gint n_sizes = G_N_ELEMENTS (widths);
275 caps = gst_caps_new_empty ();
276 for (i = 0; i < n_sizes; i++) {
277 temp = gst_caps_new_simple (mimetype,
278 "width", G_TYPE_INT, widths[i],
279 "height", G_TYPE_INT, heights[i],
280 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
282 gst_caps_append (caps, temp);
286 case AV_CODEC_ID_DVVIDEO:
293 gint framerate_n, framerate_d;
296 "Y41B", 720, 480, 8, 9, 30000, 1001}, {
297 "Y41B", 720, 480, 32, 27, 30000, 1001}, {
298 "Y42B", 720, 480, 8, 9, 30000, 1001}, {
299 "Y42B", 720, 480, 32, 27, 30000, 1001}, {
300 "I420", 720, 576, 16, 15, 25, 1}, {
301 "I420", 720, 576, 64, 45, 25, 1}, {
302 "Y41B", 720, 576, 16, 15, 25, 1}, {
303 "Y41B", 720, 576, 64, 45, 25, 1}, {
304 "Y42B", 720, 576, 16, 15, 25, 1}, {
305 "Y42B", 720, 576, 64, 45, 25, 1}, {
306 "Y42B", 1280, 1080, 1, 1, 30000, 1001}, {
307 "Y42B", 1280, 1080, 3, 2, 30000, 1001}, {
308 "Y42B", 1440, 1080, 1, 1, 25, 1}, {
309 "Y42B", 1440, 1080, 4, 3, 25, 1}, {
310 "Y42B", 960, 720, 1, 1, 60000, 1001}, {
311 "Y42B", 960, 720, 4, 3, 60000, 1001}, {
312 "Y42B", 960, 720, 1, 1, 50, 1}, {
313 "Y42B", 960, 720, 4, 3, 50, 1},};
315 gint n_sizes = G_N_ELEMENTS (profiles);
317 if (strcmp (mimetype, "video/x-raw") == 0) {
318 caps = gst_caps_new_empty ();
319 for (i = 0; i < n_sizes; i++) {
320 temp = gst_caps_new_simple (mimetype,
321 "format", G_TYPE_STRING, profiles[i].csp,
322 "width", G_TYPE_INT, profiles[i].width,
323 "height", G_TYPE_INT, profiles[i].height,
324 "framerate", GST_TYPE_FRACTION, profiles[i].framerate_n,
325 profiles[i].framerate_d, "pixel-aspect-ratio",
326 GST_TYPE_FRACTION, profiles[i].par_n, profiles[i].par_d, NULL);
328 gst_caps_append (caps, temp);
331 caps = gst_caps_new_empty ();
332 for (i = 0; i < n_sizes; i++) {
333 temp = gst_caps_new_simple (mimetype,
334 "width", G_TYPE_INT, profiles[i].width,
335 "height", G_TYPE_INT, profiles[i].height,
336 "framerate", GST_TYPE_FRACTION, profiles[i].framerate_n,
337 profiles[i].framerate_d, "pixel-aspect-ratio",
338 GST_TYPE_FRACTION, profiles[i].par_n, profiles[i].par_d, NULL);
340 gst_caps_append (caps, temp);
345 case AV_CODEC_ID_DNXHD:
347 caps = gst_caps_new_simple (mimetype,
348 "width", G_TYPE_INT, 1920,
349 "height", G_TYPE_INT, 1080,
350 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
351 gst_caps_append (caps, gst_caps_new_simple (mimetype,
352 "width", G_TYPE_INT, 1280,
353 "height", G_TYPE_INT, 720,
354 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL));
359 if (codec && codec->supported_framerates
360 && codec->supported_framerates[0].num != 0
361 && codec->supported_framerates[0].den != 0) {
364 const AVRational *rates = codec->supported_framerates;
366 if (rates[1].num == 0 && rates[1].den == 0) {
368 gst_caps_new_simple (mimetype, "framerate", GST_TYPE_FRACTION,
369 rates[0].num, rates[0].den, NULL);
371 g_value_init (&va, GST_TYPE_LIST);
372 g_value_init (&v, GST_TYPE_FRACTION);
374 while (rates->num != 0 && rates->den != 0) {
375 gst_value_set_fraction (&v, rates->num, rates->den);
376 gst_value_list_append_value (&va, &v);
380 caps = gst_caps_new_simple (mimetype, NULL, NULL, NULL);
381 gst_caps_set_value (caps, "framerate", &va);
387 caps = gst_caps_new_empty_simple (mimetype);
395 /* no fixed caps or special restrictions applied;
396 * default unfixed setting */
398 GST_DEBUG ("Creating default caps");
399 caps = gst_caps_new_empty_simple (mimetype);
402 va_start (var_args, fieldname);
403 gst_caps_set_simple_valist (caps, fieldname, var_args);
410 get_nbits_set (guint64 n)
415 for (i = 0; i < 64; i++) {
416 if ((n & (G_GUINT64_CONSTANT (1) << i)))
424 gst_ffmpeg_audio_set_sample_fmts (GstCaps * caps,
425 const enum AVSampleFormat *fmts)
429 GstAudioFormat format;
431 if (!fmts || fmts[0] == -1) {
434 g_value_init (&va, GST_TYPE_LIST);
435 g_value_init (&v, G_TYPE_STRING);
436 for (i = 0; i <= AV_SAMPLE_FMT_DBL; i++) {
437 format = gst_ffmpeg_smpfmt_to_audioformat (i);
438 if (format == GST_AUDIO_FORMAT_UNKNOWN)
440 g_value_set_string (&v, gst_audio_format_to_string (format));
441 gst_value_list_append_value (&va, &v);
443 gst_caps_set_value (caps, "format", &va);
449 g_value_init (&va, GST_TYPE_LIST);
450 g_value_init (&v, G_TYPE_STRING);
451 while (*fmts != -1) {
452 format = gst_ffmpeg_smpfmt_to_audioformat (*fmts);
453 if (format != GST_AUDIO_FORMAT_UNKNOWN) {
454 g_value_set_string (&v, gst_audio_format_to_string (format));
455 gst_value_list_append_value (&va, &v);
459 if (gst_value_list_get_size (&va) == 1) {
460 /* The single value is still in v */
461 gst_caps_set_value (caps, "format", &v);
462 } else if (gst_value_list_get_size (&va) > 1) {
463 gst_caps_set_value (caps, "format", &va);
469 /* same for audio - now with channels/sample rate
472 gst_ff_aud_caps_new (AVCodecContext * context, AVCodec * codec,
473 enum CodecID codec_id, gboolean encode, const char *mimetype,
474 const char *fieldname, ...)
476 GstCaps *caps = NULL;
480 /* fixed, non-probing context */
481 if (context != NULL && context->channels != -1) {
482 GstAudioChannelPosition pos[64];
484 caps = gst_caps_new_simple (mimetype,
485 "rate", G_TYPE_INT, context->sample_rate,
486 "channels", G_TYPE_INT, context->channels, NULL);
488 if (gst_ffmpeg_channel_layout_to_gst (context->channel_layout,
489 context->channels, pos)) {
492 if (gst_audio_channel_positions_to_mask (pos, context->channels, FALSE,
494 gst_caps_set_simple (caps, "channel-mask", GST_TYPE_BITMASK, mask,
499 gint maxchannels = 2;
500 const gint *rates = NULL;
503 /* so we must be after restricted caps in this case */
505 case AV_CODEC_ID_AAC:
506 case AV_CODEC_ID_AAC_LATM:
507 case AV_CODEC_ID_DTS:
510 case AV_CODEC_ID_MP2:
512 const static gint l_rates[] =
513 { 48000, 44100, 32000, 24000, 22050, 16000 };
514 n_rates = G_N_ELEMENTS (l_rates);
518 case AV_CODEC_ID_EAC3:
519 case AV_CODEC_ID_AC3:
521 const static gint l_rates[] = { 48000, 44100, 32000 };
523 n_rates = G_N_ELEMENTS (l_rates);
527 case AV_CODEC_ID_ADPCM_G722:
529 const static gint l_rates[] = { 16000 };
530 n_rates = G_N_ELEMENTS (l_rates);
535 case AV_CODEC_ID_ADPCM_G726:
537 const static gint l_rates[] = { 8000 };
538 n_rates = G_N_ELEMENTS (l_rates);
543 case AV_CODEC_ID_ADPCM_SWF:
545 const static gint l_rates[] = { 11025, 22050, 44100 };
546 n_rates = G_N_ELEMENTS (l_rates);
550 case AV_CODEC_ID_ROQ_DPCM:
552 const static gint l_rates[] = { 22050 };
553 n_rates = G_N_ELEMENTS (l_rates);
557 case AV_CODEC_ID_AMR_NB:
559 const static gint l_rates[] = { 8000 };
561 n_rates = G_N_ELEMENTS (l_rates);
565 case AV_CODEC_ID_AMR_WB:
567 const static gint l_rates[] = { 16000 };
569 n_rates = G_N_ELEMENTS (l_rates);
577 /* regardless of encode/decode, open up channels if applicable */
578 /* Until decoders/encoders expose the maximum number of channels
579 * they support, we whitelist them here. */
581 case AV_CODEC_ID_WMAPRO:
582 case AV_CODEC_ID_TRUEHD:
589 if (codec && codec->channel_layouts) {
590 const uint64_t *layouts = codec->channel_layouts;
591 GstAudioChannelPosition pos[64];
593 caps = gst_caps_new_empty ();
595 gint nbits_set = get_nbits_set (*layouts);
597 if (gst_ffmpeg_channel_layout_to_gst (*layouts, nbits_set, pos)) {
600 if (gst_audio_channel_positions_to_mask (pos, nbits_set, FALSE,
603 gst_caps_new_simple (mimetype, "channel-mask", GST_TYPE_BITMASK,
605 "channels", G_TYPE_INT, nbits_set, NULL);
607 gst_caps_append (caps, tmp);
613 if (maxchannels == 1)
614 caps = gst_caps_new_simple (mimetype,
615 "channels", G_TYPE_INT, maxchannels, NULL);
617 caps = gst_caps_new_simple (mimetype,
618 "channels", GST_TYPE_INT_RANGE, 1, maxchannels, NULL);
622 GValue list = { 0, };
624 g_value_init (&list, GST_TYPE_LIST);
625 for (i = 0; i < n_rates; i++) {
628 g_value_init (&v, G_TYPE_INT);
629 g_value_set_int (&v, rates[i]);
630 gst_value_list_append_value (&list, &v);
633 gst_caps_set_value (caps, "rate", &list);
634 g_value_unset (&list);
635 } else if (codec && codec->supported_samplerates
636 && codec->supported_samplerates[0]) {
640 if (!codec->supported_samplerates[1]) {
641 gst_caps_set_simple (caps, "rate", G_TYPE_INT,
642 codec->supported_samplerates[0], NULL);
644 const int *rates = codec->supported_samplerates;
646 g_value_init (&va, GST_TYPE_LIST);
647 g_value_init (&v, G_TYPE_INT);
650 g_value_set_int (&v, *rates);
651 gst_value_list_append_value (&va, &v);
654 gst_caps_set_value (caps, "rate", &va);
659 gst_caps_set_simple (caps, "rate", GST_TYPE_INT_RANGE, 4000, 96000, NULL);
662 caps = gst_caps_new_empty_simple (mimetype);
665 va_start (var_args, fieldname);
666 gst_caps_set_simple_valist (caps, fieldname, var_args);
672 /* Convert a FFMPEG codec ID and optional AVCodecContext
673 * to a GstCaps. If the context is ommitted, no fixed values
674 * for video/audio size will be included in the GstCaps
676 * CodecID is primarily meant for compressed data GstCaps!
678 * encode is a special parameter. gstffmpegdec will say
679 * FALSE, gstffmpegenc will say TRUE. The output caps
680 * depends on this, in such a way that it will be very
681 * specific, defined, fixed and correct caps for encoders,
682 * yet very wide, "forgiving" caps for decoders. Example
683 * for mp3: decode: audio/mpeg,mpegversion=1,layer=[1-3]
684 * but encode: audio/mpeg,mpegversion=1,layer=3,bitrate=x,
689 gst_ffmpeg_codecid_to_caps (enum CodecID codec_id,
690 AVCodecContext * context, gboolean encode)
692 GstCaps *caps = NULL;
693 gboolean buildcaps = FALSE;
695 GST_LOG ("codec_id:%d, context:%p, encode:%d", codec_id, context, encode);
698 case AV_CODEC_ID_MPEG1VIDEO:
700 caps = gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
701 "mpegversion", G_TYPE_INT, 1,
702 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
705 case AV_CODEC_ID_MPEG2VIDEO:
709 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
710 "mpegversion", G_TYPE_INT, 2, "systemstream", G_TYPE_BOOLEAN, FALSE,
713 /* decode both MPEG-1 and MPEG-2; width/height/fps are all in
714 * the MPEG video stream headers, so may be omitted from caps. */
715 caps = gst_caps_new_simple ("video/mpeg",
716 "mpegversion", GST_TYPE_INT_RANGE, 1, 2,
717 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
721 case AV_CODEC_ID_MPEG2VIDEO_XVMC:
722 /* this is a special ID - don't need it in GStreamer, I think */
725 case AV_CODEC_ID_H263:
728 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
729 "video/x-h263", "variant", G_TYPE_STRING, "itu", "h263version",
730 G_TYPE_STRING, "h263", NULL);
732 /* don't pass codec_id, we can decode other variants with the H263
733 * decoder that don't have specific size requirements
736 gst_ff_vid_caps_new (context, NULL, AV_CODEC_ID_NONE, encode,
737 "video/x-h263", "variant", G_TYPE_STRING, "itu", NULL);
741 case AV_CODEC_ID_H263P:
743 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h263",
744 "variant", G_TYPE_STRING, "itu", "h263version", G_TYPE_STRING,
746 if (encode && context) {
748 gst_caps_set_simple (caps,
749 "annex-f", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_4MV,
750 "annex-j", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_LOOP_FILTER,
751 "annex-i", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_AC_PRED,
752 "annex-t", G_TYPE_BOOLEAN, context->flags & CODEC_FLAG_AC_PRED,
757 case AV_CODEC_ID_H263I:
759 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
760 "video/x-intel-h263", "variant", G_TYPE_STRING, "intel", NULL);
763 case AV_CODEC_ID_H261:
765 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h261",
769 case AV_CODEC_ID_RV10:
770 case AV_CODEC_ID_RV20:
771 case AV_CODEC_ID_RV30:
772 case AV_CODEC_ID_RV40:
777 case AV_CODEC_ID_RV40:
780 case AV_CODEC_ID_RV30:
783 case AV_CODEC_ID_RV20:
791 /* FIXME: context->sub_id must be filled in during decoding */
793 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
794 "video/x-pn-realvideo", "systemstream", G_TYPE_BOOLEAN, FALSE,
795 "rmversion", G_TYPE_INT, version, NULL);
797 gst_caps_set_simple (caps, "format", G_TYPE_INT, context->sub_id, NULL);
798 if (context->extradata_size >= 8) {
799 gst_caps_set_simple (caps,
800 "subformat", G_TYPE_INT, GST_READ_UINT32_BE (context->extradata),
807 case AV_CODEC_ID_MP1:
809 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
810 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 1, NULL);
813 case AV_CODEC_ID_MP2:
815 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
816 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 2, NULL);
819 case AV_CODEC_ID_MP3:
823 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
824 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 3, NULL);
826 /* Decodes MPEG-1 layer 1/2/3. Samplerate, channels et al are
827 * in the MPEG audio header, so may be omitted from caps. */
828 caps = gst_caps_new_simple ("audio/mpeg",
829 "mpegversion", G_TYPE_INT, 1,
830 "layer", GST_TYPE_INT_RANGE, 1, 3, NULL);
834 case AV_CODEC_ID_MUSEPACK7:
836 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
837 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 7,
841 case AV_CODEC_ID_MUSEPACK8:
843 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
844 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 8,
848 case AV_CODEC_ID_AC3:
851 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-ac3",
855 case AV_CODEC_ID_EAC3:
858 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-eac3",
862 case AV_CODEC_ID_TRUEHD:
864 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
865 "audio/x-true-hd", NULL);
868 case AV_CODEC_ID_ATRAC1:
870 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
871 "audio/x-vnd.sony.atrac1", NULL);
874 case AV_CODEC_ID_ATRAC3:
876 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
877 "audio/x-vnd.sony.atrac3", NULL);
880 case AV_CODEC_ID_DTS:
882 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dts",
886 case AV_CODEC_ID_APE:
888 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
889 "audio/x-ffmpeg-parsed-ape", NULL);
891 gst_caps_set_simple (caps,
892 "depth", G_TYPE_INT, context->bits_per_coded_sample, NULL);
896 case AV_CODEC_ID_MLP:
898 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mlp",
902 case AV_CODEC_ID_IMC:
904 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-imc",
908 /* MJPEG is normal JPEG, Motion-JPEG and Quicktime MJPEG-A. MJPEGB
909 * is Quicktime's MJPEG-B. LJPEG is lossless JPEG. I don't know what
910 * sp5x is, but it's apparently something JPEG... We don't separate
911 * between those in GStreamer. Should we (at least between MJPEG,
912 * MJPEG-B and sp5x decoding...)? */
913 case AV_CODEC_ID_MJPEG:
914 case AV_CODEC_ID_LJPEG:
916 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/jpeg",
920 case AV_CODEC_ID_SP5X:
922 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/sp5x",
926 case AV_CODEC_ID_MJPEGB:
928 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
929 "video/x-mjpeg-b", NULL);
932 case AV_CODEC_ID_MPEG4:
933 if (encode && context != NULL) {
934 /* I'm not exactly sure what ffmpeg outputs... ffmpeg itself uses
935 * the AVI fourcc 'DIVX', but 'mp4v' for Quicktime... */
936 switch (context->codec_tag) {
937 case GST_MAKE_FOURCC ('D', 'I', 'V', 'X'):
939 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
940 "video/x-divx", "divxversion", G_TYPE_INT, 5, NULL);
942 case GST_MAKE_FOURCC ('m', 'p', '4', 'v'):
946 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
947 "video/mpeg", "systemstream", G_TYPE_BOOLEAN, FALSE,
948 "mpegversion", G_TYPE_INT, 4, NULL);
952 /* The trick here is to separate xvid, divx, mpeg4, 3ivx et al */
954 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
955 "mpegversion", G_TYPE_INT, 4, "systemstream", G_TYPE_BOOLEAN, FALSE,
958 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
959 encode, "video/x-divx", "divxversion", G_TYPE_INT, 5, NULL));
961 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
962 encode, "video/x-divx", "divxversion", GST_TYPE_INT_RANGE, 4,
964 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
965 encode, "video/x-xvid", NULL));
966 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
967 encode, "video/x-3ivx", NULL));
972 case AV_CODEC_ID_RAWVIDEO:
974 gst_ffmpeg_codectype_to_video_caps (context, codec_id, encode, NULL);
977 case AV_CODEC_ID_MSMPEG4V1:
978 case AV_CODEC_ID_MSMPEG4V2:
979 case AV_CODEC_ID_MSMPEG4V3:
981 gint version = 41 + codec_id - AV_CODEC_ID_MSMPEG4V1;
983 /* encode-FIXME: bitrate */
985 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
986 "video/x-msmpeg", "msmpegversion", G_TYPE_INT, version, NULL);
987 if (!encode && codec_id == AV_CODEC_ID_MSMPEG4V3) {
988 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
989 encode, "video/x-divx", "divxversion", G_TYPE_INT, 3, NULL));
994 case AV_CODEC_ID_WMV1:
995 case AV_CODEC_ID_WMV2:
997 gint version = (codec_id == AV_CODEC_ID_WMV1) ? 1 : 2;
1000 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1001 "wmvversion", G_TYPE_INT, version, NULL);
1005 case AV_CODEC_ID_FLV1:
1007 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1008 "video/x-flash-video", "flvversion", G_TYPE_INT, 1, NULL);
1011 case AV_CODEC_ID_SVQ1:
1013 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-svq",
1014 "svqversion", G_TYPE_INT, 1, NULL);
1017 case AV_CODEC_ID_SVQ3:
1019 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-svq",
1020 "svqversion", G_TYPE_INT, 3, NULL);
1023 case AV_CODEC_ID_DVAUDIO:
1025 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dv",
1029 case AV_CODEC_ID_DVVIDEO:
1031 if (encode && context) {
1032 const gchar *format;
1034 switch (context->pix_fmt) {
1035 case PIX_FMT_YUYV422:
1038 case PIX_FMT_YUV420P:
1041 case PIX_FMT_YUVA420P:
1044 case PIX_FMT_YUV411P:
1047 case PIX_FMT_YUV422P:
1050 case PIX_FMT_YUV410P:
1055 ("Couldnt' find format for pixfmt %d, defaulting to I420",
1061 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dv",
1062 "systemstream", G_TYPE_BOOLEAN, FALSE, "format", G_TYPE_STRING,
1066 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dv",
1067 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
1072 case AV_CODEC_ID_WMAV1:
1073 case AV_CODEC_ID_WMAV2:
1075 gint version = (codec_id == AV_CODEC_ID_WMAV1) ? 1 : 2;
1079 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1080 "wmaversion", G_TYPE_INT, version, "block_align", G_TYPE_INT,
1081 context->block_align, "bitrate", G_TYPE_INT, context->bit_rate,
1085 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1086 "wmaversion", G_TYPE_INT, version, "block_align",
1087 GST_TYPE_INT_RANGE, 0, G_MAXINT, "bitrate", GST_TYPE_INT_RANGE, 0,
1092 case AV_CODEC_ID_WMAPRO:
1095 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1096 "wmaversion", G_TYPE_INT, 3, NULL);
1099 case AV_CODEC_ID_WMALOSSLESS:
1101 /* libav only supports a depth of 16 at the moment */
1103 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1104 "wmaversion", G_TYPE_INT, 4, "depth", G_TYPE_INT, 16, NULL);
1107 case AV_CODEC_ID_WMAVOICE:
1110 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wms",
1115 case AV_CODEC_ID_MACE3:
1116 case AV_CODEC_ID_MACE6:
1118 gint version = (codec_id == AV_CODEC_ID_MACE3) ? 3 : 6;
1121 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mace",
1122 "maceversion", G_TYPE_INT, version, NULL);
1126 case AV_CODEC_ID_HUFFYUV:
1128 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1129 "video/x-huffyuv", NULL);
1131 gst_caps_set_simple (caps,
1132 "bpp", G_TYPE_INT, context->bits_per_coded_sample, NULL);
1136 case AV_CODEC_ID_CYUV:
1138 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1139 "video/x-compressed-yuv", NULL);
1142 case AV_CODEC_ID_H264:
1144 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h264",
1145 "alignment", G_TYPE_STRING, "au", NULL);
1148 case AV_CODEC_ID_INDEO5:
1150 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1151 "indeoversion", G_TYPE_INT, 5, NULL);
1154 case AV_CODEC_ID_INDEO4:
1156 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1157 "indeoversion", G_TYPE_INT, 4, NULL);
1160 case AV_CODEC_ID_INDEO3:
1162 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1163 "indeoversion", G_TYPE_INT, 3, NULL);
1166 case AV_CODEC_ID_INDEO2:
1168 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1169 "indeoversion", G_TYPE_INT, 2, NULL);
1172 case AV_CODEC_ID_FLASHSV:
1174 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1175 "video/x-flash-screen", NULL);
1178 case AV_CODEC_ID_VP3:
1180 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp3",
1184 case AV_CODEC_ID_VP5:
1186 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp5",
1190 case AV_CODEC_ID_VP6:
1192 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp6",
1196 case AV_CODEC_ID_VP6F:
1198 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1199 "video/x-vp6-flash", NULL);
1202 case AV_CODEC_ID_VP6A:
1204 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1205 "video/x-vp6-alpha", NULL);
1208 case AV_CODEC_ID_VP8:
1210 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp8",
1214 case AV_CODEC_ID_THEORA:
1216 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1217 "video/x-theora", NULL);
1220 case AV_CODEC_ID_AAC:
1223 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
1227 GValue arr = { 0, };
1228 GValue item = { 0, };
1230 g_value_init (&arr, GST_TYPE_LIST);
1231 g_value_init (&item, G_TYPE_INT);
1232 g_value_set_int (&item, 2);
1233 gst_value_list_append_value (&arr, &item);
1234 g_value_set_int (&item, 4);
1235 gst_value_list_append_value (&arr, &item);
1236 g_value_unset (&item);
1238 gst_caps_set_value (caps, "mpegversion", &arr);
1239 g_value_unset (&arr);
1241 g_value_init (&arr, GST_TYPE_LIST);
1242 g_value_init (&item, G_TYPE_STRING);
1243 g_value_set_string (&item, "raw");
1244 gst_value_list_append_value (&arr, &item);
1245 g_value_set_string (&item, "adts");
1246 gst_value_list_append_value (&arr, &item);
1247 g_value_set_string (&item, "adif");
1248 gst_value_list_append_value (&arr, &item);
1249 g_value_unset (&item);
1251 gst_caps_set_value (caps, "stream-format", &arr);
1252 g_value_unset (&arr);
1254 gst_caps_set_simple (caps, "mpegversion", G_TYPE_INT, 4,
1255 "stream-format", G_TYPE_STRING, "raw",
1256 "base-profile", G_TYPE_STRING, "lc", NULL);
1258 if (context && context->extradata_size > 0)
1259 gst_codec_utils_aac_caps_set_level_and_profile (caps,
1260 context->extradata, context->extradata_size);
1265 case AV_CODEC_ID_AAC_LATM: /* LATM/LOAS AAC syntax */
1266 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
1267 "mpegversion", G_TYPE_INT, 4, "stream-format", G_TYPE_STRING, "loas",
1271 case AV_CODEC_ID_ASV1:
1273 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-asus",
1274 "asusversion", G_TYPE_INT, 1, NULL);
1276 case AV_CODEC_ID_ASV2:
1278 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-asus",
1279 "asusversion", G_TYPE_INT, 2, NULL);
1282 case AV_CODEC_ID_FFV1:
1284 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-ffv",
1285 "ffvversion", G_TYPE_INT, 1, NULL);
1288 case AV_CODEC_ID_4XM:
1290 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-4xm",
1294 case AV_CODEC_ID_XAN_WC3:
1295 case AV_CODEC_ID_XAN_WC4:
1297 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-xan",
1298 "wcversion", G_TYPE_INT, 3 - AV_CODEC_ID_XAN_WC3 + codec_id, NULL);
1301 case AV_CODEC_ID_CLJR:
1303 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1304 "video/x-cirrus-logic-accupak", NULL);
1307 case AV_CODEC_ID_FRAPS:
1309 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-fraps",
1313 case AV_CODEC_ID_MDEC:
1314 case AV_CODEC_ID_ROQ:
1315 case AV_CODEC_ID_INTERPLAY_VIDEO:
1319 case AV_CODEC_ID_VCR1:
1321 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1322 "video/x-ati-vcr", "vcrversion", G_TYPE_INT, 1, NULL);
1325 case AV_CODEC_ID_RPZA:
1327 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1328 "video/x-apple-video", NULL);
1331 case AV_CODEC_ID_CINEPAK:
1333 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1334 "video/x-cinepak", NULL);
1337 /* WS_VQA belogns here (order) */
1339 case AV_CODEC_ID_MSRLE:
1341 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-rle",
1342 "layout", G_TYPE_STRING, "microsoft", NULL);
1344 gst_caps_set_simple (caps,
1345 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1347 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1351 case AV_CODEC_ID_QTRLE:
1353 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-rle",
1354 "layout", G_TYPE_STRING, "quicktime", NULL);
1356 gst_caps_set_simple (caps,
1357 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1359 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1363 case AV_CODEC_ID_MSVIDEO1:
1365 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1366 "video/x-msvideocodec", "msvideoversion", G_TYPE_INT, 1, NULL);
1369 case AV_CODEC_ID_WMV3:
1371 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1372 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "WMV3", NULL);
1374 case AV_CODEC_ID_VC1:
1376 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1377 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "WVC1", NULL);
1379 case AV_CODEC_ID_QDM2:
1381 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-qdm2",
1385 case AV_CODEC_ID_MSZH:
1387 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-mszh",
1391 case AV_CODEC_ID_ZLIB:
1393 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-zlib",
1397 case AV_CODEC_ID_TRUEMOTION1:
1399 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1400 "video/x-truemotion", "trueversion", G_TYPE_INT, 1, NULL);
1402 case AV_CODEC_ID_TRUEMOTION2:
1404 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1405 "video/x-truemotion", "trueversion", G_TYPE_INT, 2, NULL);
1408 case AV_CODEC_ID_ULTI:
1410 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1411 "video/x-ultimotion", NULL);
1414 case AV_CODEC_ID_TSCC:
1416 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1417 "video/x-camtasia", NULL);
1419 gst_caps_set_simple (caps,
1420 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1422 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1426 case AV_CODEC_ID_KMVC:
1428 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-kmvc",
1432 case AV_CODEC_ID_NUV:
1434 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-nuv",
1438 case AV_CODEC_ID_GIF:
1440 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/gif",
1444 case AV_CODEC_ID_PNG:
1446 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/png",
1450 case AV_CODEC_ID_PPM:
1452 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/ppm",
1456 case AV_CODEC_ID_PBM:
1458 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/pbm",
1462 case AV_CODEC_ID_PAM:
1464 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1465 "image/x-portable-anymap", NULL);
1468 case AV_CODEC_ID_PGM:
1470 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1471 "image/x-portable-graymap", NULL);
1474 case AV_CODEC_ID_PCX:
1476 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-pcx",
1480 case AV_CODEC_ID_SGI:
1482 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-sgi",
1486 case AV_CODEC_ID_TARGA:
1488 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-tga",
1492 case AV_CODEC_ID_TIFF:
1494 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/tiff",
1498 case AV_CODEC_ID_SUNRAST:
1500 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1501 "image/x-sun-raster", NULL);
1504 case AV_CODEC_ID_SMC:
1506 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-smc",
1510 case AV_CODEC_ID_QDRAW:
1512 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-qdrw",
1516 case AV_CODEC_ID_DNXHD:
1518 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dnxhd",
1522 case AV_CODEC_ID_PRORES:
1524 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1525 "video/x-prores", NULL);
1528 case AV_CODEC_ID_MIMIC:
1530 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-mimic",
1534 case AV_CODEC_ID_VMNC:
1536 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vmnc",
1540 case AV_CODEC_ID_TRUESPEECH:
1542 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1543 "audio/x-truespeech", NULL);
1546 case AV_CODEC_ID_QCELP:
1548 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/qcelp",
1552 case AV_CODEC_ID_AMV:
1554 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-amv",
1558 case AV_CODEC_ID_AASC:
1560 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-aasc",
1564 case AV_CODEC_ID_LOCO:
1566 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-loco",
1570 case AV_CODEC_ID_ZMBV:
1572 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-zmbv",
1576 case AV_CODEC_ID_LAGARITH:
1578 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1579 "video/x-lagarith", NULL);
1582 case AV_CODEC_ID_CSCD:
1584 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1585 "video/x-camstudio", NULL);
1587 gst_caps_set_simple (caps,
1588 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1590 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1594 case AV_CODEC_ID_WS_VQA:
1595 case AV_CODEC_ID_IDCIN:
1596 case AV_CODEC_ID_8BPS:
1597 case AV_CODEC_ID_FLIC:
1598 case AV_CODEC_ID_VMDVIDEO:
1599 case AV_CODEC_ID_VMDAUDIO:
1600 case AV_CODEC_ID_SNOW:
1601 case AV_CODEC_ID_VIXL:
1602 case AV_CODEC_ID_QPEG:
1603 case AV_CODEC_ID_PGMYUV:
1604 case AV_CODEC_ID_FFVHUFF:
1605 case AV_CODEC_ID_WNV1:
1606 case AV_CODEC_ID_MP3ADU:
1607 case AV_CODEC_ID_MP3ON4:
1608 case AV_CODEC_ID_WESTWOOD_SND1:
1609 case AV_CODEC_ID_MMVIDEO:
1610 case AV_CODEC_ID_AVS:
1611 case AV_CODEC_ID_CAVS:
1615 /* weird quasi-codecs for the demuxers only */
1616 case AV_CODEC_ID_PCM_S16LE:
1617 case AV_CODEC_ID_PCM_S16BE:
1618 case AV_CODEC_ID_PCM_U16LE:
1619 case AV_CODEC_ID_PCM_U16BE:
1620 case AV_CODEC_ID_PCM_S8:
1621 case AV_CODEC_ID_PCM_U8:
1623 GstAudioFormat format;
1626 case AV_CODEC_ID_PCM_S16LE:
1627 format = GST_AUDIO_FORMAT_S16LE;
1629 case AV_CODEC_ID_PCM_S16BE:
1630 format = GST_AUDIO_FORMAT_S16BE;
1632 case AV_CODEC_ID_PCM_U16LE:
1633 format = GST_AUDIO_FORMAT_U16LE;
1635 case AV_CODEC_ID_PCM_U16BE:
1636 format = GST_AUDIO_FORMAT_U16BE;
1638 case AV_CODEC_ID_PCM_S8:
1639 format = GST_AUDIO_FORMAT_S8;
1641 case AV_CODEC_ID_PCM_U8:
1642 format = GST_AUDIO_FORMAT_U8;
1645 g_assert (0); /* don't worry, we never get here */
1650 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-raw",
1651 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
1652 "layout", G_TYPE_STRING, "interleaved", NULL);
1656 case AV_CODEC_ID_PCM_MULAW:
1658 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mulaw",
1662 case AV_CODEC_ID_PCM_ALAW:
1664 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-alaw",
1668 case AV_CODEC_ID_ADPCM_G722:
1670 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/G722",
1673 gst_caps_set_simple (caps,
1674 "block_align", G_TYPE_INT, context->block_align,
1675 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1678 case AV_CODEC_ID_ADPCM_G726:
1680 /* the G726 decoder can also handle G721 */
1682 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-adpcm",
1683 "layout", G_TYPE_STRING, "g726", NULL);
1685 gst_caps_set_simple (caps,
1686 "block_align", G_TYPE_INT, context->block_align,
1687 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1690 gst_caps_append (caps, gst_caps_new_simple ("audio/x-adpcm",
1691 "layout", G_TYPE_STRING, "g721",
1692 "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, 8000, NULL));
1696 case AV_CODEC_ID_ADPCM_IMA_QT:
1697 case AV_CODEC_ID_ADPCM_IMA_WAV:
1698 case AV_CODEC_ID_ADPCM_IMA_DK3:
1699 case AV_CODEC_ID_ADPCM_IMA_DK4:
1700 case AV_CODEC_ID_ADPCM_IMA_WS:
1701 case AV_CODEC_ID_ADPCM_IMA_SMJPEG:
1702 case AV_CODEC_ID_ADPCM_IMA_AMV:
1703 case AV_CODEC_ID_ADPCM_IMA_ISS:
1704 case AV_CODEC_ID_ADPCM_IMA_EA_EACS:
1705 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
1706 case AV_CODEC_ID_ADPCM_MS:
1707 case AV_CODEC_ID_ADPCM_4XM:
1708 case AV_CODEC_ID_ADPCM_XA:
1709 case AV_CODEC_ID_ADPCM_ADX:
1710 case AV_CODEC_ID_ADPCM_EA:
1711 case AV_CODEC_ID_ADPCM_CT:
1712 case AV_CODEC_ID_ADPCM_SWF:
1713 case AV_CODEC_ID_ADPCM_YAMAHA:
1714 case AV_CODEC_ID_ADPCM_SBPRO_2:
1715 case AV_CODEC_ID_ADPCM_SBPRO_3:
1716 case AV_CODEC_ID_ADPCM_SBPRO_4:
1717 case AV_CODEC_ID_ADPCM_EA_R1:
1718 case AV_CODEC_ID_ADPCM_EA_R2:
1719 case AV_CODEC_ID_ADPCM_EA_R3:
1720 case AV_CODEC_ID_ADPCM_EA_MAXIS_XA:
1721 case AV_CODEC_ID_ADPCM_EA_XAS:
1722 case AV_CODEC_ID_ADPCM_THP:
1724 const gchar *layout = NULL;
1727 case AV_CODEC_ID_ADPCM_IMA_QT:
1728 layout = "quicktime";
1730 case AV_CODEC_ID_ADPCM_IMA_WAV:
1733 case AV_CODEC_ID_ADPCM_IMA_DK3:
1736 case AV_CODEC_ID_ADPCM_IMA_DK4:
1739 case AV_CODEC_ID_ADPCM_IMA_WS:
1740 layout = "westwood";
1742 case AV_CODEC_ID_ADPCM_IMA_SMJPEG:
1745 case AV_CODEC_ID_ADPCM_IMA_AMV:
1748 case AV_CODEC_ID_ADPCM_IMA_ISS:
1751 case AV_CODEC_ID_ADPCM_IMA_EA_EACS:
1754 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
1757 case AV_CODEC_ID_ADPCM_MS:
1758 layout = "microsoft";
1760 case AV_CODEC_ID_ADPCM_4XM:
1763 case AV_CODEC_ID_ADPCM_XA:
1766 case AV_CODEC_ID_ADPCM_ADX:
1769 case AV_CODEC_ID_ADPCM_EA:
1772 case AV_CODEC_ID_ADPCM_CT:
1775 case AV_CODEC_ID_ADPCM_SWF:
1778 case AV_CODEC_ID_ADPCM_YAMAHA:
1781 case AV_CODEC_ID_ADPCM_SBPRO_2:
1784 case AV_CODEC_ID_ADPCM_SBPRO_3:
1787 case AV_CODEC_ID_ADPCM_SBPRO_4:
1790 case AV_CODEC_ID_ADPCM_EA_R1:
1793 case AV_CODEC_ID_ADPCM_EA_R2:
1796 case AV_CODEC_ID_ADPCM_EA_R3:
1799 case AV_CODEC_ID_ADPCM_EA_MAXIS_XA:
1800 layout = "ea-maxis-xa";
1802 case AV_CODEC_ID_ADPCM_EA_XAS:
1805 case AV_CODEC_ID_ADPCM_THP:
1809 g_assert (0); /* don't worry, we never get here */
1813 /* FIXME: someone please check whether we need additional properties
1814 * in this caps definition. */
1816 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-adpcm",
1817 "layout", G_TYPE_STRING, layout, NULL);
1819 gst_caps_set_simple (caps,
1820 "block_align", G_TYPE_INT, context->block_align,
1821 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1825 case AV_CODEC_ID_AMR_NB:
1827 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/AMR",
1831 case AV_CODEC_ID_AMR_WB:
1833 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/AMR-WB",
1837 case AV_CODEC_ID_GSM:
1839 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-gsm",
1843 case AV_CODEC_ID_GSM_MS:
1845 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/ms-gsm",
1849 case AV_CODEC_ID_NELLYMOSER:
1851 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1852 "audio/x-nellymoser", NULL);
1855 case AV_CODEC_ID_SIPR:
1858 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-sipro",
1861 gst_caps_set_simple (caps,
1862 "leaf_size", G_TYPE_INT, context->block_align,
1863 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1868 case AV_CODEC_ID_RA_144:
1869 case AV_CODEC_ID_RA_288:
1870 case AV_CODEC_ID_COOK:
1875 case AV_CODEC_ID_RA_144:
1878 case AV_CODEC_ID_RA_288:
1881 case AV_CODEC_ID_COOK:
1888 /* FIXME: properties? */
1890 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1891 "audio/x-pn-realaudio", "raversion", G_TYPE_INT, version, NULL);
1893 gst_caps_set_simple (caps,
1894 "leaf_size", G_TYPE_INT, context->block_align,
1895 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1900 case AV_CODEC_ID_ROQ_DPCM:
1901 case AV_CODEC_ID_INTERPLAY_DPCM:
1902 case AV_CODEC_ID_XAN_DPCM:
1903 case AV_CODEC_ID_SOL_DPCM:
1905 const gchar *layout = NULL;
1908 case AV_CODEC_ID_ROQ_DPCM:
1911 case AV_CODEC_ID_INTERPLAY_DPCM:
1912 layout = "interplay";
1914 case AV_CODEC_ID_XAN_DPCM:
1917 case AV_CODEC_ID_SOL_DPCM:
1921 g_assert (0); /* don't worry, we never get here */
1925 /* FIXME: someone please check whether we need additional properties
1926 * in this caps definition. */
1928 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dpcm",
1929 "layout", G_TYPE_STRING, layout, NULL);
1931 gst_caps_set_simple (caps,
1932 "block_align", G_TYPE_INT, context->block_align,
1933 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
1937 case AV_CODEC_ID_SHORTEN:
1938 caps = gst_caps_new_empty_simple ("audio/x-shorten");
1941 case AV_CODEC_ID_ALAC:
1943 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-alac",
1946 gst_caps_set_simple (caps,
1947 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
1951 case AV_CODEC_ID_FLAC:
1952 /* Note that ffmpeg has no encoder yet, but just for safety. In the
1953 * encoder case, we want to add things like samplerate, channels... */
1955 caps = gst_caps_new_empty_simple ("audio/x-flac");
1959 case AV_CODEC_ID_S302M:
1960 caps = gst_caps_new_empty_simple ("audio/x-smpte-302m");
1963 case AV_CODEC_ID_DVD_SUBTITLE:
1964 case AV_CODEC_ID_DVB_SUBTITLE:
1967 case AV_CODEC_ID_BMP:
1968 caps = gst_caps_new_empty_simple ("image/bmp");
1970 case AV_CODEC_ID_TTA:
1972 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-tta",
1975 gst_caps_set_simple (caps,
1976 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
1979 case AV_CODEC_ID_TWINVQ:
1981 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1982 "audio/x-twin-vq", NULL);
1985 GST_DEBUG ("Unknown codec ID %d, please add mapping here", codec_id);
1992 if ((codec = avcodec_find_decoder (codec_id)) ||
1993 (codec = avcodec_find_encoder (codec_id))) {
1996 GST_LOG ("Could not create stream format caps for %s", codec->name);
1998 switch (codec->type) {
1999 case AVMEDIA_TYPE_VIDEO:
2000 mime = g_strdup_printf ("video/x-gst-av-%s", codec->name);
2002 gst_ff_vid_caps_new (context, NULL, codec_id, encode, mime, NULL);
2005 case AVMEDIA_TYPE_AUDIO:
2006 mime = g_strdup_printf ("audio/x-gst-av-%s", codec->name);
2008 gst_ff_aud_caps_new (context, NULL, codec_id, encode, mime, NULL);
2010 gst_caps_set_simple (caps,
2011 "block_align", G_TYPE_INT, context->block_align,
2012 "bitrate", G_TYPE_INT, context->bit_rate, NULL);
2023 /* set private data */
2024 if (context && context->extradata_size > 0) {
2025 GstBuffer *data = gst_buffer_new_and_alloc (context->extradata_size);
2027 gst_buffer_fill (data, 0, context->extradata, context->extradata_size);
2028 gst_caps_set_simple (caps, "codec_data", GST_TYPE_BUFFER, data, NULL);
2029 gst_buffer_unref (data);
2032 GST_LOG ("caps for codec_id=%d: %" GST_PTR_FORMAT, codec_id, caps);
2035 GST_LOG ("No caps found for codec_id=%d", codec_id);
2041 /* Convert a FFMPEG Pixel Format and optional AVCodecContext
2042 * to a GstCaps. If the context is ommitted, no fixed values
2043 * for video/audio size will be included in the GstCaps
2045 * See below for usefullness
2049 gst_ffmpeg_pixfmt_to_caps (enum PixelFormat pix_fmt, AVCodecContext * context,
2050 enum CodecID codec_id)
2052 GstCaps *caps = NULL;
2053 GstVideoFormat format;
2055 format = gst_ffmpeg_pixfmt_to_videoformat (pix_fmt);
2057 if (format != GST_VIDEO_FORMAT_UNKNOWN) {
2058 caps = gst_ff_vid_caps_new (context, NULL, codec_id, TRUE, "video/x-raw",
2059 "format", G_TYPE_STRING, gst_video_format_to_string (format), NULL);
2063 GST_DEBUG ("caps for pix_fmt=%d: %" GST_PTR_FORMAT, pix_fmt, caps);
2065 GST_LOG ("No caps found for pix_fmt=%d", pix_fmt);
2072 gst_ffmpeg_smpfmt_to_audioformat (enum AVSampleFormat sample_fmt)
2074 switch (sample_fmt) {
2075 case AV_SAMPLE_FMT_U8:
2076 case AV_SAMPLE_FMT_U8P:
2077 return GST_AUDIO_FORMAT_U8;
2079 case AV_SAMPLE_FMT_S16:
2080 case AV_SAMPLE_FMT_S16P:
2081 return GST_AUDIO_FORMAT_S16;
2083 case AV_SAMPLE_FMT_S32:
2084 case AV_SAMPLE_FMT_S32P:
2085 return GST_AUDIO_FORMAT_S32;
2087 case AV_SAMPLE_FMT_FLT:
2088 case AV_SAMPLE_FMT_FLTP:
2089 return GST_AUDIO_FORMAT_F32;
2091 case AV_SAMPLE_FMT_DBL:
2092 case AV_SAMPLE_FMT_DBLP:
2093 return GST_AUDIO_FORMAT_F64;
2097 return GST_AUDIO_FORMAT_UNKNOWN;
2102 /* Convert a FFMPEG Sample Format and optional AVCodecContext
2103 * to a GstCaps. If the context is ommitted, no fixed values
2104 * for video/audio size will be included in the GstCaps
2106 * See below for usefullness
2110 gst_ffmpeg_smpfmt_to_caps (enum AVSampleFormat sample_fmt,
2111 AVCodecContext * context, AVCodec * codec, enum CodecID codec_id)
2113 GstCaps *caps = NULL;
2114 GstAudioFormat format;
2116 format = gst_ffmpeg_smpfmt_to_audioformat (sample_fmt);
2118 if (format != GST_AUDIO_FORMAT_UNKNOWN) {
2119 caps = gst_ff_aud_caps_new (context, codec, codec_id, TRUE, "audio/x-raw",
2120 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
2121 "layout", G_TYPE_STRING, "interleaved", NULL);
2122 GST_LOG ("caps for sample_fmt=%d: %" GST_PTR_FORMAT, sample_fmt, caps);
2124 GST_LOG ("No caps found for sample_fmt=%d", sample_fmt);
2131 caps_has_field (GstCaps * caps, const gchar * field)
2135 n = gst_caps_get_size (caps);
2136 for (i = 0; i < n; i++) {
2137 GstStructure *s = gst_caps_get_structure (caps, i);
2139 if (gst_structure_has_field (s, field))
2147 gst_ffmpeg_codectype_to_audio_caps (AVCodecContext * context,
2148 enum CodecID codec_id, gboolean encode, AVCodec * codec)
2150 GstCaps *caps = NULL;
2152 GST_DEBUG ("context:%p, codec_id:%d, encode:%d, codec:%p",
2153 context, codec_id, encode, codec);
2155 GST_DEBUG ("sample_fmts:%p, samplerates:%p",
2156 codec->sample_fmts, codec->supported_samplerates);
2159 /* Specific codec context */
2161 gst_ffmpeg_smpfmt_to_caps (context->sample_fmt, context, codec,
2164 caps = gst_ff_aud_caps_new (context, codec, codec_id, encode, "audio/x-raw",
2165 "layout", G_TYPE_STRING, "interleaved", NULL);
2166 if (!caps_has_field (caps, "format"))
2167 gst_ffmpeg_audio_set_sample_fmts (caps,
2168 codec ? codec->sample_fmts : NULL);
2175 gst_ffmpeg_codectype_to_video_caps (AVCodecContext * context,
2176 enum CodecID codec_id, gboolean encode, AVCodec * codec)
2180 GST_LOG ("context:%p, codec_id:%d, encode:%d, codec:%p",
2181 context, codec_id, encode, codec);
2184 caps = gst_ffmpeg_pixfmt_to_caps (context->pix_fmt, context, codec_id);
2187 gst_ff_vid_caps_new (context, codec, codec_id, encode, "video/x-raw",
2189 if (!caps_has_field (caps, "format"))
2190 gst_ffmpeg_video_set_pix_fmts (caps, codec ? codec->pix_fmts : NULL);
2195 /* Convert a GstCaps (audio/raw) to a FFMPEG SampleFmt
2196 * and other audio properties in a AVCodecContext.
2198 * For usefullness, see below
2202 gst_ffmpeg_caps_to_smpfmt (const GstCaps * caps,
2203 AVCodecContext * context, gboolean raw)
2205 GstStructure *structure;
2207 GstAudioFormat format = GST_AUDIO_FORMAT_UNKNOWN;
2209 g_return_if_fail (gst_caps_get_size (caps) == 1);
2211 structure = gst_caps_get_structure (caps, 0);
2213 gst_structure_get_int (structure, "channels", &context->channels);
2214 gst_structure_get_int (structure, "rate", &context->sample_rate);
2215 gst_structure_get_int (structure, "block_align", &context->block_align);
2216 gst_structure_get_int (structure, "bitrate", &context->bit_rate);
2221 if (gst_structure_has_name (structure, "audio/x-raw")) {
2222 if ((fmt = gst_structure_get_string (structure, "format"))) {
2223 format = gst_audio_format_from_string (fmt);
2228 case GST_AUDIO_FORMAT_F32:
2229 context->sample_fmt = AV_SAMPLE_FMT_FLT;
2231 case GST_AUDIO_FORMAT_F64:
2232 context->sample_fmt = AV_SAMPLE_FMT_DBL;
2234 case GST_AUDIO_FORMAT_S32:
2235 context->sample_fmt = AV_SAMPLE_FMT_S32;
2237 case GST_AUDIO_FORMAT_S16:
2238 context->sample_fmt = AV_SAMPLE_FMT_S16;
2245 /* Convert a GstCaps (video/raw) to a FFMPEG PixFmt
2246 * and other video properties in a AVCodecContext.
2248 * For usefullness, see below
2252 gst_ffmpeg_caps_to_pixfmt (const GstCaps * caps,
2253 AVCodecContext * context, gboolean raw)
2255 GstStructure *structure;
2257 const GValue *par = NULL;
2259 GstVideoFormat format = GST_VIDEO_FORMAT_UNKNOWN;
2261 GST_DEBUG ("converting caps %" GST_PTR_FORMAT, caps);
2262 g_return_if_fail (gst_caps_get_size (caps) == 1);
2263 structure = gst_caps_get_structure (caps, 0);
2265 gst_structure_get_int (structure, "width", &context->width);
2266 gst_structure_get_int (structure, "height", &context->height);
2267 gst_structure_get_int (structure, "bpp", &context->bits_per_coded_sample);
2269 fps = gst_structure_get_value (structure, "framerate");
2270 if (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps)) {
2272 /* somehow these seem mixed up.. */
2273 context->time_base.den = gst_value_get_fraction_numerator (fps);
2274 context->time_base.num = gst_value_get_fraction_denominator (fps);
2275 context->ticks_per_frame = 1;
2277 GST_DEBUG ("setting framerate %d/%d = %lf",
2278 context->time_base.den, context->time_base.num,
2279 1. * context->time_base.den / context->time_base.num);
2282 par = gst_structure_get_value (structure, "pixel-aspect-ratio");
2283 if (par && GST_VALUE_HOLDS_FRACTION (par)) {
2285 context->sample_aspect_ratio.num = gst_value_get_fraction_numerator (par);
2286 context->sample_aspect_ratio.den = gst_value_get_fraction_denominator (par);
2288 GST_DEBUG ("setting pixel-aspect-ratio %d/%d = %lf",
2289 context->sample_aspect_ratio.den, context->sample_aspect_ratio.num,
2290 1. * context->sample_aspect_ratio.den /
2291 context->sample_aspect_ratio.num);
2297 g_return_if_fail (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps));
2299 if (gst_structure_has_name (structure, "video/x-raw")) {
2300 if ((fmt = gst_structure_get_string (structure, "format"))) {
2301 format = gst_video_format_from_string (fmt);
2306 case GST_VIDEO_FORMAT_YUY2:
2307 context->pix_fmt = PIX_FMT_YUYV422;
2309 case GST_VIDEO_FORMAT_I420:
2310 context->pix_fmt = PIX_FMT_YUV420P;
2312 case GST_VIDEO_FORMAT_A420:
2313 context->pix_fmt = PIX_FMT_YUVA420P;
2315 case GST_VIDEO_FORMAT_Y41B:
2316 context->pix_fmt = PIX_FMT_YUV411P;
2318 case GST_VIDEO_FORMAT_Y42B:
2319 context->pix_fmt = PIX_FMT_YUV422P;
2321 case GST_VIDEO_FORMAT_YUV9:
2322 context->pix_fmt = PIX_FMT_YUV410P;
2324 case GST_VIDEO_FORMAT_Y444:
2325 context->pix_fmt = PIX_FMT_YUV444P;
2327 case GST_VIDEO_FORMAT_GRAY8:
2328 context->pix_fmt = PIX_FMT_GRAY8;
2330 case GST_VIDEO_FORMAT_xRGB:
2331 #if (G_BYTE_ORDER == G_BIG_ENDIAN)
2332 context->pix_fmt = PIX_FMT_RGB32;
2335 case GST_VIDEO_FORMAT_BGRx:
2336 #if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
2337 context->pix_fmt = PIX_FMT_RGB32;
2340 case GST_VIDEO_FORMAT_RGB:
2341 context->pix_fmt = PIX_FMT_RGB24;
2343 case GST_VIDEO_FORMAT_BGR:
2344 context->pix_fmt = PIX_FMT_BGR24;
2346 case GST_VIDEO_FORMAT_RGB16:
2347 context->pix_fmt = PIX_FMT_RGB565;
2349 case GST_VIDEO_FORMAT_RGB15:
2350 context->pix_fmt = PIX_FMT_RGB555;
2352 case GST_VIDEO_FORMAT_RGB8P:
2353 context->pix_fmt = PIX_FMT_PAL8;
2362 GstVideoFormat format;
2363 enum PixelFormat pixfmt;
2366 /* FIXME : FILLME */
2367 static const PixToFmt pixtofmttable[] = {
2368 /* GST_VIDEO_FORMAT_I420, */
2369 {GST_VIDEO_FORMAT_I420, PIX_FMT_YUV420P},
2370 /* Note : this should use a different chroma placement */
2371 {GST_VIDEO_FORMAT_I420, PIX_FMT_YUVJ420P},
2373 /* GST_VIDEO_FORMAT_YV12, */
2374 /* GST_VIDEO_FORMAT_YUY2, */
2375 {GST_VIDEO_FORMAT_YUY2, PIX_FMT_YUYV422},
2376 /* GST_VIDEO_FORMAT_UYVY, */
2377 {GST_VIDEO_FORMAT_UYVY, PIX_FMT_UYVY422},
2378 /* GST_VIDEO_FORMAT_AYUV, */
2379 /* GST_VIDEO_FORMAT_RGBx, */
2380 /* GST_VIDEO_FORMAT_BGRx, */
2381 /* GST_VIDEO_FORMAT_xRGB, */
2382 /* GST_VIDEO_FORMAT_xBGR, */
2383 /* GST_VIDEO_FORMAT_RGBA, */
2384 {GST_VIDEO_FORMAT_RGBA, PIX_FMT_RGBA},
2385 /* GST_VIDEO_FORMAT_BGRA, */
2386 {GST_VIDEO_FORMAT_BGRA, PIX_FMT_BGRA},
2387 /* GST_VIDEO_FORMAT_ARGB, */
2388 {GST_VIDEO_FORMAT_ARGB, PIX_FMT_ARGB},
2389 /* GST_VIDEO_FORMAT_ABGR, */
2390 {GST_VIDEO_FORMAT_ABGR, PIX_FMT_ABGR},
2391 /* GST_VIDEO_FORMAT_RGB, */
2392 {GST_VIDEO_FORMAT_RGB, PIX_FMT_RGB24},
2393 /* GST_VIDEO_FORMAT_BGR, */
2394 {GST_VIDEO_FORMAT_BGR, PIX_FMT_BGR24},
2395 /* GST_VIDEO_FORMAT_Y41B, */
2396 {GST_VIDEO_FORMAT_Y41B, PIX_FMT_YUV411P},
2397 /* GST_VIDEO_FORMAT_Y42B, */
2398 {GST_VIDEO_FORMAT_Y42B, PIX_FMT_YUV422P},
2399 {GST_VIDEO_FORMAT_Y42B, PIX_FMT_YUVJ422P},
2400 /* GST_VIDEO_FORMAT_YVYU, */
2401 /* GST_VIDEO_FORMAT_Y444, */
2402 {GST_VIDEO_FORMAT_Y444, PIX_FMT_YUV444P},
2403 {GST_VIDEO_FORMAT_Y444, PIX_FMT_YUVJ444P},
2404 /* GST_VIDEO_FORMAT_v210, */
2405 /* GST_VIDEO_FORMAT_v216, */
2406 /* GST_VIDEO_FORMAT_NV12, */
2407 {GST_VIDEO_FORMAT_NV12, PIX_FMT_NV12},
2408 /* GST_VIDEO_FORMAT_NV21, */
2409 {GST_VIDEO_FORMAT_NV21, PIX_FMT_NV21},
2410 /* GST_VIDEO_FORMAT_GRAY8, */
2411 {GST_VIDEO_FORMAT_GRAY8, PIX_FMT_GRAY8},
2412 /* GST_VIDEO_FORMAT_GRAY16_BE, */
2413 {GST_VIDEO_FORMAT_GRAY16_BE, PIX_FMT_GRAY16BE},
2414 /* GST_VIDEO_FORMAT_GRAY16_LE, */
2415 {GST_VIDEO_FORMAT_GRAY16_LE, PIX_FMT_GRAY16LE},
2416 /* GST_VIDEO_FORMAT_v308, */
2417 /* GST_VIDEO_FORMAT_Y800, */
2418 /* GST_VIDEO_FORMAT_Y16, */
2419 /* GST_VIDEO_FORMAT_RGB16, */
2420 {GST_VIDEO_FORMAT_RGB16, PIX_FMT_RGB565},
2421 /* GST_VIDEO_FORMAT_BGR16, */
2422 /* GST_VIDEO_FORMAT_RGB15, */
2423 {GST_VIDEO_FORMAT_RGB15, PIX_FMT_RGB555},
2424 /* GST_VIDEO_FORMAT_BGR15, */
2425 /* GST_VIDEO_FORMAT_UYVP, */
2426 /* GST_VIDEO_FORMAT_A420, */
2427 {GST_VIDEO_FORMAT_A420, PIX_FMT_YUVA420P},
2428 /* GST_VIDEO_FORMAT_RGB8_PALETTED, */
2429 {GST_VIDEO_FORMAT_RGB8P, PIX_FMT_PAL8},
2430 /* GST_VIDEO_FORMAT_YUV9, */
2431 {GST_VIDEO_FORMAT_YUV9, PIX_FMT_YUV410P},
2432 /* GST_VIDEO_FORMAT_YVU9, */
2433 /* GST_VIDEO_FORMAT_IYU1, */
2434 /* GST_VIDEO_FORMAT_ARGB64, */
2435 /* GST_VIDEO_FORMAT_AYUV64, */
2436 /* GST_VIDEO_FORMAT_r210, */
2437 {GST_VIDEO_FORMAT_I420_10LE, PIX_FMT_YUV420P10LE},
2438 {GST_VIDEO_FORMAT_I420_10BE, PIX_FMT_YUV420P10BE},
2439 {GST_VIDEO_FORMAT_I422_10LE, PIX_FMT_YUV422P10LE},
2440 {GST_VIDEO_FORMAT_I422_10BE, PIX_FMT_YUV422P10BE},
2441 {GST_VIDEO_FORMAT_Y444_10LE, PIX_FMT_YUV444P10LE},
2442 {GST_VIDEO_FORMAT_Y444_10BE, PIX_FMT_YUV444P10BE},
2443 {GST_VIDEO_FORMAT_GBR, PIX_FMT_GBRP},
2444 {GST_VIDEO_FORMAT_GBR_10LE, PIX_FMT_GBRP10LE},
2445 {GST_VIDEO_FORMAT_GBR_10BE, PIX_FMT_GBRP10BE},
2449 gst_ffmpeg_pixfmt_to_videoformat (enum PixelFormat pixfmt)
2453 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2454 if (pixtofmttable[i].pixfmt == pixfmt)
2455 return pixtofmttable[i].format;
2457 GST_WARNING ("Unknown pixel format %d", pixfmt);
2458 return GST_VIDEO_FORMAT_UNKNOWN;
2462 gst_ffmpeg_videoformat_to_pixfmt (GstVideoFormat format)
2466 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2467 if (pixtofmttable[i].format == format)
2468 return pixtofmttable[i].pixfmt;
2469 return PIX_FMT_NONE;
2473 gst_ffmpeg_videoinfo_to_context (GstVideoInfo * info, AVCodecContext * context)
2477 context->width = GST_VIDEO_INFO_WIDTH (info);
2478 context->height = GST_VIDEO_INFO_HEIGHT (info);
2479 for (i = 0; i < GST_VIDEO_INFO_N_COMPONENTS (info); i++)
2480 bpp += GST_VIDEO_INFO_COMP_DEPTH (info, i);
2481 context->bits_per_coded_sample = bpp;
2483 context->ticks_per_frame = 1;
2484 context->time_base.den = GST_VIDEO_INFO_FPS_N (info);
2485 context->time_base.num = GST_VIDEO_INFO_FPS_D (info);
2487 context->sample_aspect_ratio.num = GST_VIDEO_INFO_PAR_N (info);
2488 context->sample_aspect_ratio.den = GST_VIDEO_INFO_PAR_D (info);
2491 gst_ffmpeg_videoformat_to_pixfmt (GST_VIDEO_INFO_FORMAT (info));
2495 gst_ffmpeg_audioinfo_to_context (GstAudioInfo * info, AVCodecContext * context)
2497 const AVCodec *codec;
2498 const enum AVSampleFormat *smpl_fmts;
2499 enum AVSampleFormat smpl_fmt = -1;
2501 context->channels = info->channels;
2502 context->sample_rate = info->rate;
2503 context->channel_layout =
2504 gst_ffmpeg_channel_positions_to_layout (info->position, info->channels);
2506 codec = context->codec;
2508 smpl_fmts = codec->sample_fmts;
2510 switch (info->finfo->format) {
2511 case GST_AUDIO_FORMAT_F32:
2513 while (*smpl_fmts != -1) {
2514 if (*smpl_fmts == AV_SAMPLE_FMT_FLT) {
2515 smpl_fmt = *smpl_fmts;
2517 } else if (*smpl_fmts == AV_SAMPLE_FMT_FLTP) {
2518 smpl_fmt = *smpl_fmts;
2524 smpl_fmt = AV_SAMPLE_FMT_FLT;
2527 case GST_AUDIO_FORMAT_F64:
2529 while (*smpl_fmts != -1) {
2530 if (*smpl_fmts == AV_SAMPLE_FMT_DBL) {
2531 smpl_fmt = *smpl_fmts;
2533 } else if (*smpl_fmts == AV_SAMPLE_FMT_DBLP) {
2534 smpl_fmt = *smpl_fmts;
2540 smpl_fmt = AV_SAMPLE_FMT_DBL;
2543 case GST_AUDIO_FORMAT_S32:
2545 while (*smpl_fmts != -1) {
2546 if (*smpl_fmts == AV_SAMPLE_FMT_S32) {
2547 smpl_fmt = *smpl_fmts;
2549 } else if (*smpl_fmts == AV_SAMPLE_FMT_S32P) {
2550 smpl_fmt = *smpl_fmts;
2556 smpl_fmt = AV_SAMPLE_FMT_S32;
2559 case GST_AUDIO_FORMAT_S16:
2561 while (*smpl_fmts != -1) {
2562 if (*smpl_fmts == AV_SAMPLE_FMT_S16) {
2563 smpl_fmt = *smpl_fmts;
2565 } else if (*smpl_fmts == AV_SAMPLE_FMT_S16P) {
2566 smpl_fmt = *smpl_fmts;
2572 smpl_fmt = AV_SAMPLE_FMT_S16;
2575 case GST_AUDIO_FORMAT_U8:
2577 while (*smpl_fmts != -1) {
2578 if (*smpl_fmts == AV_SAMPLE_FMT_U8) {
2579 smpl_fmt = *smpl_fmts;
2581 } else if (*smpl_fmts == AV_SAMPLE_FMT_U8P) {
2582 smpl_fmt = *smpl_fmts;
2588 smpl_fmt = AV_SAMPLE_FMT_U8;
2595 g_assert (smpl_fmt != -1);
2597 context->sample_fmt = smpl_fmt;
2600 /* Convert a GstCaps and a FFMPEG codec Type to a
2601 * AVCodecContext. If the context is ommitted, no fixed values
2602 * for video/audio size will be included in the context
2604 * AVMediaType is primarily meant for uncompressed data GstCaps!
2608 gst_ffmpeg_caps_with_codectype (enum AVMediaType type,
2609 const GstCaps * caps, AVCodecContext * context)
2611 if (context == NULL)
2615 case AVMEDIA_TYPE_VIDEO:
2616 gst_ffmpeg_caps_to_pixfmt (caps, context, TRUE);
2619 case AVMEDIA_TYPE_AUDIO:
2620 gst_ffmpeg_caps_to_smpfmt (caps, context, TRUE);
2631 nal_escape (guint8 * dst, guint8 * src, guint size, guint * destsize)
2635 guint8 *end = src + size;
2638 while (srcp < end) {
2639 if (count == 2 && *srcp <= 0x03) {
2640 GST_DEBUG ("added escape code");
2649 GST_DEBUG ("copy %02x, count %d", *srcp, count);
2652 *destsize = dstp - dst;
2655 /* copy the config, escaping NAL units as we iterate them, if something fails we
2656 * copy everything and hope for the best. */
2658 copy_config (guint8 * dst, guint8 * src, guint size, guint * destsize)
2663 guint nalsize, esize;
2673 cnt = *(srcp + 5) & 0x1f; /* Number of sps */
2675 GST_DEBUG ("num SPS %d", cnt);
2677 memcpy (dstp, srcp, 6);
2681 for (i = 0; i < cnt; i++) {
2682 GST_DEBUG ("copy SPS %d", i);
2683 nalsize = (srcp[0] << 8) | srcp[1];
2684 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2685 dstp[0] = esize >> 8;
2686 dstp[1] = esize & 0xff;
2688 srcp += nalsize + 2;
2691 cnt = *(dstp++) = *(srcp++); /* Number of pps */
2693 GST_DEBUG ("num PPS %d", cnt);
2695 for (i = 0; i < cnt; i++) {
2696 GST_DEBUG ("copy PPS %d", i);
2697 nalsize = (srcp[0] << 8) | srcp[1];
2698 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
2699 dstp[0] = esize >> 8;
2700 dstp[1] = esize & 0xff;
2702 srcp += nalsize + 2;
2704 *destsize = dstp - dst;
2710 GST_DEBUG ("something unexpected, doing full copy");
2711 memcpy (dst, src, size);
2719 * caps_with_codecid () transforms a GstCaps for a known codec
2720 * ID into a filled-in context.
2721 * codec_data from caps will override possible extradata already in the context
2725 gst_ffmpeg_caps_with_codecid (enum CodecID codec_id,
2726 enum AVMediaType codec_type, const GstCaps * caps, AVCodecContext * context)
2729 const GValue *value;
2732 GST_LOG ("codec_id:%d, codec_type:%d, caps:%" GST_PTR_FORMAT " context:%p",
2733 codec_id, codec_type, caps, context);
2735 if (!context || !gst_caps_get_size (caps))
2738 str = gst_caps_get_structure (caps, 0);
2740 /* extradata parsing (esds [mpeg4], wma/wmv, msmpeg4v1/2/3, etc.) */
2741 if ((value = gst_structure_get_value (str, "codec_data"))) {
2744 buf = gst_value_get_buffer (value);
2745 gst_buffer_map (buf, &map, GST_MAP_READ);
2747 /* free the old one if it is there */
2748 if (context->extradata)
2749 av_free (context->extradata);
2752 if (codec_id == AV_CODEC_ID_H264) {
2755 GST_DEBUG ("copy, escaping codec_data %d", size);
2756 /* ffmpeg h264 expects the codec_data to be escaped, there is no real
2757 * reason for this but let's just escape it for now. Start by allocating
2758 * enough space, x2 is more than enough.
2760 * FIXME, we disabled escaping because some file already contain escaped
2761 * codec_data and then we escape twice and fail. It's better to leave it
2762 * as is, as that is what most players do. */
2763 context->extradata =
2764 av_mallocz (GST_ROUND_UP_16 (size * 2 +
2765 FF_INPUT_BUFFER_PADDING_SIZE));
2766 copy_config (context->extradata, data, size, &extrasize);
2767 GST_DEBUG ("escaped size: %d", extrasize);
2768 context->extradata_size = extrasize;
2772 /* allocate with enough padding */
2773 GST_DEBUG ("copy codec_data");
2774 context->extradata =
2775 av_mallocz (GST_ROUND_UP_16 (map.size +
2776 FF_INPUT_BUFFER_PADDING_SIZE));
2777 memcpy (context->extradata, map.data, map.size);
2778 context->extradata_size = map.size;
2781 /* Hack for VC1. Sometimes the first (length) byte is 0 for some files */
2782 if (codec_id == AV_CODEC_ID_VC1 && map.size > 0 && map.data[0] == 0) {
2783 context->extradata[0] = (guint8) map.size;
2786 GST_DEBUG ("have codec data of size %" G_GSIZE_FORMAT, map.size);
2788 gst_buffer_unmap (buf, &map);
2789 } else if (context->extradata == NULL && codec_id != AV_CODEC_ID_AAC_LATM &&
2790 codec_id != AV_CODEC_ID_FLAC) {
2791 /* no extradata, alloc dummy with 0 sized, some codecs insist on reading
2792 * extradata anyway which makes then segfault. */
2793 context->extradata =
2794 av_mallocz (GST_ROUND_UP_16 (FF_INPUT_BUFFER_PADDING_SIZE));
2795 context->extradata_size = 0;
2796 GST_DEBUG ("no codec data");
2800 case AV_CODEC_ID_MPEG4:
2802 const gchar *mime = gst_structure_get_name (str);
2804 if (!strcmp (mime, "video/x-divx"))
2805 context->codec_tag = GST_MAKE_FOURCC ('D', 'I', 'V', 'X');
2806 else if (!strcmp (mime, "video/x-xvid"))
2807 context->codec_tag = GST_MAKE_FOURCC ('X', 'V', 'I', 'D');
2808 else if (!strcmp (mime, "video/x-3ivx"))
2809 context->codec_tag = GST_MAKE_FOURCC ('3', 'I', 'V', '1');
2810 else if (!strcmp (mime, "video/mpeg"))
2811 context->codec_tag = GST_MAKE_FOURCC ('m', 'p', '4', 'v');
2815 case AV_CODEC_ID_SVQ3:
2816 /* FIXME: this is a workaround for older gst-plugins releases
2817 * (<= 0.8.9). This should be removed at some point, because
2818 * it causes wrong decoded frame order. */
2819 if (!context->extradata) {
2820 gint halfpel_flag, thirdpel_flag, low_delay, unknown_svq3_flag;
2823 if (gst_structure_get_int (str, "halfpel_flag", &halfpel_flag) ||
2824 gst_structure_get_int (str, "thirdpel_flag", &thirdpel_flag) ||
2825 gst_structure_get_int (str, "low_delay", &low_delay) ||
2826 gst_structure_get_int (str, "unknown_svq3_flag",
2827 &unknown_svq3_flag)) {
2828 context->extradata = (guint8 *) av_mallocz (0x64);
2829 g_stpcpy ((gchar *) context->extradata, "SVQ3");
2833 flags |= unknown_svq3_flag;
2835 flags |= halfpel_flag;
2837 flags |= thirdpel_flag;
2840 flags = GUINT16_FROM_LE (flags);
2842 memcpy ((gchar *) context->extradata + 0x62, &flags, 2);
2843 context->extradata_size = 0x64;
2848 case AV_CODEC_ID_MSRLE:
2849 case AV_CODEC_ID_QTRLE:
2850 case AV_CODEC_ID_TSCC:
2851 case AV_CODEC_ID_CSCD:
2852 case AV_CODEC_ID_APE:
2856 if (gst_structure_get_int (str, "depth", &depth)) {
2857 context->bits_per_coded_sample = depth;
2859 GST_WARNING ("No depth field in caps %" GST_PTR_FORMAT, caps);
2865 case AV_CODEC_ID_RV10:
2866 case AV_CODEC_ID_RV20:
2867 case AV_CODEC_ID_RV30:
2868 case AV_CODEC_ID_RV40:
2872 if (gst_structure_get_int (str, "format", &format))
2873 context->sub_id = format;
2877 case AV_CODEC_ID_COOK:
2878 case AV_CODEC_ID_RA_288:
2879 case AV_CODEC_ID_RA_144:
2880 case AV_CODEC_ID_SIPR:
2885 if (gst_structure_get_int (str, "leaf_size", &leaf_size))
2886 context->block_align = leaf_size;
2887 if (gst_structure_get_int (str, "bitrate", &bitrate))
2888 context->bit_rate = bitrate;
2890 case AV_CODEC_ID_ALAC:
2891 gst_structure_get_int (str, "samplesize",
2892 &context->bits_per_coded_sample);
2895 case AV_CODEC_ID_DVVIDEO:
2897 const gchar *format;
2899 if ((format = gst_structure_get_string (str, "format"))) {
2901 if (g_str_equal (format, "YUY2"))
2902 context->pix_fmt = PIX_FMT_YUYV422;
2903 else if (g_str_equal (format, "I420"))
2904 context->pix_fmt = PIX_FMT_YUV420P;
2905 else if (g_str_equal (format, "A420"))
2906 context->pix_fmt = PIX_FMT_YUVA420P;
2907 else if (g_str_equal (format, "Y41B"))
2908 context->pix_fmt = PIX_FMT_YUV411P;
2909 else if (g_str_equal (format, "Y42B"))
2910 context->pix_fmt = PIX_FMT_YUV422P;
2911 else if (g_str_equal (format, "YUV9"))
2912 context->pix_fmt = PIX_FMT_YUV410P;
2914 GST_WARNING ("couldn't convert format %s" " to a pixel format",
2918 GST_WARNING ("No specified format");
2921 case AV_CODEC_ID_H263P:
2925 if (!gst_structure_get_boolean (str, "annex-f", &val) || val)
2926 context->flags |= CODEC_FLAG_4MV;
2928 context->flags &= ~CODEC_FLAG_4MV;
2929 if ((!gst_structure_get_boolean (str, "annex-i", &val) || val) &&
2930 (!gst_structure_get_boolean (str, "annex-t", &val) || val))
2931 context->flags |= CODEC_FLAG_AC_PRED;
2933 context->flags &= ~CODEC_FLAG_AC_PRED;
2934 if (!gst_structure_get_boolean (str, "annex-j", &val) || val)
2935 context->flags |= CODEC_FLAG_LOOP_FILTER;
2937 context->flags &= ~CODEC_FLAG_LOOP_FILTER;
2940 case AV_CODEC_ID_ADPCM_G726:
2942 const gchar *layout;
2944 if ((layout = gst_structure_get_string (str, "layout"))) {
2945 if (!strcmp (layout, "g721")) {
2946 context->sample_rate = 8000;
2947 context->channels = 1;
2948 context->bit_rate = 32000;
2957 if (!gst_caps_is_fixed (caps))
2960 /* common properties (width, height, fps) */
2961 switch (codec_type) {
2962 case AVMEDIA_TYPE_VIDEO:
2963 gst_ffmpeg_caps_to_pixfmt (caps, context,
2964 codec_id == AV_CODEC_ID_RAWVIDEO);
2966 case AVMEDIA_TYPE_AUDIO:
2967 gst_ffmpeg_caps_to_smpfmt (caps, context, FALSE);
2973 /* fixup of default settings */
2975 case AV_CODEC_ID_QCELP:
2976 /* QCELP is always mono, no matter what the caps say */
2977 context->channels = 1;
2979 case AV_CODEC_ID_ADPCM_G726:
2980 if (context->sample_rate && context->bit_rate)
2981 context->bits_per_coded_sample =
2982 context->bit_rate / context->sample_rate;
2989 /* _formatid_to_caps () is meant for muxers/demuxers, it
2990 * transforms a name (ffmpeg way of ID'ing these, why don't
2991 * they have unique numerical IDs?) to the corresponding
2992 * caps belonging to that mux-format
2994 * Note: we don't need any additional info because the caps
2995 * isn't supposed to contain any useful info besides the
3000 gst_ffmpeg_formatid_to_caps (const gchar * format_name)
3002 GstCaps *caps = NULL;
3004 if (!strcmp (format_name, "mpeg")) {
3005 caps = gst_caps_new_simple ("video/mpeg",
3006 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3007 } else if (!strcmp (format_name, "mpegts")) {
3008 caps = gst_caps_new_simple ("video/mpegts",
3009 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3010 } else if (!strcmp (format_name, "rm")) {
3011 caps = gst_caps_new_simple ("application/x-pn-realmedia",
3012 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3013 } else if (!strcmp (format_name, "asf")) {
3014 caps = gst_caps_new_empty_simple ("video/x-ms-asf");
3015 } else if (!strcmp (format_name, "avi")) {
3016 caps = gst_caps_new_empty_simple ("video/x-msvideo");
3017 } else if (!strcmp (format_name, "wav")) {
3018 caps = gst_caps_new_empty_simple ("audio/x-wav");
3019 } else if (!strcmp (format_name, "ape")) {
3020 caps = gst_caps_new_empty_simple ("application/x-ape");
3021 } else if (!strcmp (format_name, "swf")) {
3022 caps = gst_caps_new_empty_simple ("application/x-shockwave-flash");
3023 } else if (!strcmp (format_name, "au")) {
3024 caps = gst_caps_new_empty_simple ("audio/x-au");
3025 } else if (!strcmp (format_name, "dv")) {
3026 caps = gst_caps_new_simple ("video/x-dv",
3027 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3028 } else if (!strcmp (format_name, "4xm")) {
3029 caps = gst_caps_new_empty_simple ("video/x-4xm");
3030 } else if (!strcmp (format_name, "matroska")) {
3031 caps = gst_caps_new_empty_simple ("video/x-matroska");
3032 } else if (!strcmp (format_name, "mp3")) {
3033 caps = gst_caps_new_empty_simple ("application/x-id3");
3034 } else if (!strcmp (format_name, "flic")) {
3035 caps = gst_caps_new_empty_simple ("video/x-fli");
3036 } else if (!strcmp (format_name, "flv")) {
3037 caps = gst_caps_new_empty_simple ("video/x-flv");
3038 } else if (!strcmp (format_name, "tta")) {
3039 caps = gst_caps_new_empty_simple ("audio/x-ttafile");
3040 } else if (!strcmp (format_name, "aiff")) {
3041 caps = gst_caps_new_empty_simple ("audio/x-aiff");
3042 } else if (!strcmp (format_name, "mov_mp4_m4a_3gp_3g2")) {
3044 gst_caps_from_string
3045 ("application/x-3gp; video/quicktime; audio/x-m4a");
3046 } else if (!strcmp (format_name, "mov")) {
3047 caps = gst_caps_from_string ("video/quicktime,variant=(string)apple");
3048 } else if (!strcmp (format_name, "mp4")) {
3049 caps = gst_caps_from_string ("video/quicktime,variant=(string)iso");
3050 } else if (!strcmp (format_name, "3gp")) {
3051 caps = gst_caps_from_string ("video/quicktime,variant=(string)3gpp");
3052 } else if (!strcmp (format_name, "3g2")) {
3053 caps = gst_caps_from_string ("video/quicktime,variant=(string)3g2");
3054 } else if (!strcmp (format_name, "psp")) {
3055 caps = gst_caps_from_string ("video/quicktime,variant=(string)psp");
3056 } else if (!strcmp (format_name, "ipod")) {
3057 caps = gst_caps_from_string ("video/quicktime,variant=(string)ipod");
3058 } else if (!strcmp (format_name, "aac")) {
3059 caps = gst_caps_new_simple ("audio/mpeg",
3060 "mpegversion", G_TYPE_INT, 4, NULL);
3061 } else if (!strcmp (format_name, "gif")) {
3062 caps = gst_caps_from_string ("image/gif");
3063 } else if (!strcmp (format_name, "ogg")) {
3064 caps = gst_caps_from_string ("application/ogg");
3065 } else if (!strcmp (format_name, "mxf") || !strcmp (format_name, "mxf_d10")) {
3066 caps = gst_caps_from_string ("application/mxf");
3067 } else if (!strcmp (format_name, "gxf")) {
3068 caps = gst_caps_from_string ("application/gxf");
3069 } else if (!strcmp (format_name, "yuv4mpegpipe")) {
3070 caps = gst_caps_new_simple ("application/x-yuv4mpeg",
3071 "y4mversion", G_TYPE_INT, 2, NULL);
3072 } else if (!strcmp (format_name, "mpc")) {
3073 caps = gst_caps_from_string ("audio/x-musepack, streamversion = (int) 7");
3074 } else if (!strcmp (format_name, "vqf")) {
3075 caps = gst_caps_from_string ("audio/x-vqf");
3076 } else if (!strcmp (format_name, "nsv")) {
3077 caps = gst_caps_from_string ("video/x-nsv");
3078 } else if (!strcmp (format_name, "amr")) {
3079 caps = gst_caps_from_string ("audio/x-amr-nb-sh");
3080 } else if (!strcmp (format_name, "webm")) {
3081 caps = gst_caps_from_string ("video/webm");
3082 } else if (!strcmp (format_name, "voc")) {
3083 caps = gst_caps_from_string ("audio/x-voc");
3087 GST_LOG ("Could not create stream format caps for %s", format_name);
3088 name = g_strdup_printf ("application/x-gst-av-%s", format_name);
3089 caps = gst_caps_new_empty_simple (name);
3097 gst_ffmpeg_formatid_get_codecids (const gchar * format_name,
3098 enum CodecID ** video_codec_list, enum CodecID ** audio_codec_list,
3099 AVOutputFormat * plugin)
3101 static enum CodecID tmp_vlist[] = {
3105 static enum CodecID tmp_alist[] = {
3110 GST_LOG ("format_name : %s", format_name);
3112 if (!strcmp (format_name, "mp4")) {
3113 static enum CodecID mp4_video_list[] = {
3114 AV_CODEC_ID_MPEG4, AV_CODEC_ID_H264,
3118 static enum CodecID mp4_audio_list[] = {
3119 AV_CODEC_ID_AAC, AV_CODEC_ID_MP3,
3123 *video_codec_list = mp4_video_list;
3124 *audio_codec_list = mp4_audio_list;
3125 } else if (!strcmp (format_name, "mpeg")) {
3126 static enum CodecID mpeg_video_list[] = { AV_CODEC_ID_MPEG1VIDEO,
3127 AV_CODEC_ID_MPEG2VIDEO,
3131 static enum CodecID mpeg_audio_list[] = { AV_CODEC_ID_MP1,
3137 *video_codec_list = mpeg_video_list;
3138 *audio_codec_list = mpeg_audio_list;
3139 } else if (!strcmp (format_name, "dvd")) {
3140 static enum CodecID mpeg_video_list[] = { AV_CODEC_ID_MPEG2VIDEO,
3143 static enum CodecID mpeg_audio_list[] = { AV_CODEC_ID_MP2,
3146 AV_CODEC_ID_PCM_S16BE,
3150 *video_codec_list = mpeg_video_list;
3151 *audio_codec_list = mpeg_audio_list;
3152 } else if (!strcmp (format_name, "mpegts")) {
3153 static enum CodecID mpegts_video_list[] = { AV_CODEC_ID_MPEG1VIDEO,
3154 AV_CODEC_ID_MPEG2VIDEO,
3158 static enum CodecID mpegts_audio_list[] = { AV_CODEC_ID_MP2,
3166 *video_codec_list = mpegts_video_list;
3167 *audio_codec_list = mpegts_audio_list;
3168 } else if (!strcmp (format_name, "vob")) {
3169 static enum CodecID vob_video_list[] =
3170 { AV_CODEC_ID_MPEG2VIDEO, AV_CODEC_ID_NONE };
3171 static enum CodecID vob_audio_list[] = { AV_CODEC_ID_MP2, AV_CODEC_ID_AC3,
3172 AV_CODEC_ID_DTS, AV_CODEC_ID_NONE
3175 *video_codec_list = vob_video_list;
3176 *audio_codec_list = vob_audio_list;
3177 } else if (!strcmp (format_name, "flv")) {
3178 static enum CodecID flv_video_list[] =
3179 { AV_CODEC_ID_FLV1, AV_CODEC_ID_NONE };
3180 static enum CodecID flv_audio_list[] =
3181 { AV_CODEC_ID_MP3, AV_CODEC_ID_NONE };
3183 *video_codec_list = flv_video_list;
3184 *audio_codec_list = flv_audio_list;
3185 } else if (!strcmp (format_name, "asf")) {
3186 static enum CodecID asf_video_list[] =
3187 { AV_CODEC_ID_WMV1, AV_CODEC_ID_WMV2, AV_CODEC_ID_MSMPEG4V3,
3190 static enum CodecID asf_audio_list[] =
3191 { AV_CODEC_ID_WMAV1, AV_CODEC_ID_WMAV2, AV_CODEC_ID_MP3,
3195 *video_codec_list = asf_video_list;
3196 *audio_codec_list = asf_audio_list;
3197 } else if (!strcmp (format_name, "dv")) {
3198 static enum CodecID dv_video_list[] =
3199 { AV_CODEC_ID_DVVIDEO, AV_CODEC_ID_NONE };
3200 static enum CodecID dv_audio_list[] =
3201 { AV_CODEC_ID_PCM_S16LE, AV_CODEC_ID_NONE };
3203 *video_codec_list = dv_video_list;
3204 *audio_codec_list = dv_audio_list;
3205 } else if (!strcmp (format_name, "mov")) {
3206 static enum CodecID mov_video_list[] = {
3207 AV_CODEC_ID_SVQ1, AV_CODEC_ID_SVQ3, AV_CODEC_ID_MPEG4,
3208 AV_CODEC_ID_H263, AV_CODEC_ID_H263P,
3209 AV_CODEC_ID_H264, AV_CODEC_ID_DVVIDEO,
3213 static enum CodecID mov_audio_list[] = {
3214 AV_CODEC_ID_PCM_MULAW, AV_CODEC_ID_PCM_ALAW, AV_CODEC_ID_ADPCM_IMA_QT,
3215 AV_CODEC_ID_MACE3, AV_CODEC_ID_MACE6, AV_CODEC_ID_AAC,
3216 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3217 AV_CODEC_ID_PCM_S16BE, AV_CODEC_ID_PCM_S16LE,
3218 AV_CODEC_ID_MP3, AV_CODEC_ID_NONE
3221 *video_codec_list = mov_video_list;
3222 *audio_codec_list = mov_audio_list;
3223 } else if ((!strcmp (format_name, "3gp") || !strcmp (format_name, "3g2"))) {
3224 static enum CodecID tgp_video_list[] = {
3225 AV_CODEC_ID_MPEG4, AV_CODEC_ID_H263, AV_CODEC_ID_H263P, AV_CODEC_ID_H264,
3228 static enum CodecID tgp_audio_list[] = {
3229 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3234 *video_codec_list = tgp_video_list;
3235 *audio_codec_list = tgp_audio_list;
3236 } else if (!strcmp (format_name, "mmf")) {
3237 static enum CodecID mmf_audio_list[] = {
3238 AV_CODEC_ID_ADPCM_YAMAHA, AV_CODEC_ID_NONE
3240 *video_codec_list = NULL;
3241 *audio_codec_list = mmf_audio_list;
3242 } else if (!strcmp (format_name, "amr")) {
3243 static enum CodecID amr_audio_list[] = {
3244 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3247 *video_codec_list = NULL;
3248 *audio_codec_list = amr_audio_list;
3249 } else if (!strcmp (format_name, "gif")) {
3250 static enum CodecID gif_image_list[] = {
3251 AV_CODEC_ID_RAWVIDEO, AV_CODEC_ID_NONE
3253 *video_codec_list = gif_image_list;
3254 *audio_codec_list = NULL;
3255 } else if ((plugin->audio_codec != AV_CODEC_ID_NONE) ||
3256 (plugin->video_codec != AV_CODEC_ID_NONE)) {
3257 tmp_vlist[0] = plugin->video_codec;
3258 tmp_alist[0] = plugin->audio_codec;
3260 *video_codec_list = tmp_vlist;
3261 *audio_codec_list = tmp_alist;
3263 GST_LOG ("Format %s not found", format_name);
3270 /* Convert a GstCaps to a FFMPEG codec ID. Size et all
3271 * are omitted, that can be queried by the user itself,
3272 * we're not eating the GstCaps or anything
3273 * A pointer to an allocated context is also needed for
3274 * optional extra info
3278 gst_ffmpeg_caps_to_codecid (const GstCaps * caps, AVCodecContext * context)
3280 enum CodecID id = AV_CODEC_ID_NONE;
3281 const gchar *mimetype;
3282 const GstStructure *structure;
3283 gboolean video = FALSE, audio = FALSE; /* we want to be sure! */
3285 g_return_val_if_fail (caps != NULL, AV_CODEC_ID_NONE);
3286 g_return_val_if_fail (gst_caps_get_size (caps) == 1, AV_CODEC_ID_NONE);
3287 structure = gst_caps_get_structure (caps, 0);
3289 mimetype = gst_structure_get_name (structure);
3291 if (!strcmp (mimetype, "video/x-raw")) {
3292 id = AV_CODEC_ID_RAWVIDEO;
3294 } else if (!strcmp (mimetype, "audio/x-raw")) {
3297 if (gst_audio_info_from_caps (&info, caps)) {
3298 switch (GST_AUDIO_INFO_FORMAT (&info)) {
3299 case GST_AUDIO_FORMAT_S8:
3300 id = AV_CODEC_ID_PCM_S8;
3302 case GST_AUDIO_FORMAT_U8:
3303 id = AV_CODEC_ID_PCM_U8;
3305 case GST_AUDIO_FORMAT_S16LE:
3306 id = AV_CODEC_ID_PCM_S16LE;
3308 case GST_AUDIO_FORMAT_S16BE:
3309 id = AV_CODEC_ID_PCM_S16BE;
3311 case GST_AUDIO_FORMAT_U16LE:
3312 id = AV_CODEC_ID_PCM_U16LE;
3314 case GST_AUDIO_FORMAT_U16BE:
3315 id = AV_CODEC_ID_PCM_U16BE;
3320 if (id != AV_CODEC_ID_NONE)
3323 } else if (!strcmp (mimetype, "audio/x-mulaw")) {
3324 id = AV_CODEC_ID_PCM_MULAW;
3326 } else if (!strcmp (mimetype, "audio/x-alaw")) {
3327 id = AV_CODEC_ID_PCM_ALAW;
3329 } else if (!strcmp (mimetype, "video/x-dv")) {
3332 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3334 id = AV_CODEC_ID_DVVIDEO;
3337 } else if (!strcmp (mimetype, "audio/x-dv")) { /* ??? */
3338 id = AV_CODEC_ID_DVAUDIO;
3340 } else if (!strcmp (mimetype, "video/x-h263")) {
3341 const gchar *h263version =
3342 gst_structure_get_string (structure, "h263version");
3343 if (h263version && !strcmp (h263version, "h263p"))
3344 id = AV_CODEC_ID_H263P;
3346 id = AV_CODEC_ID_H263;
3348 } else if (!strcmp (mimetype, "video/x-intel-h263")) {
3349 id = AV_CODEC_ID_H263I;
3351 } else if (!strcmp (mimetype, "video/x-h261")) {
3352 id = AV_CODEC_ID_H261;
3354 } else if (!strcmp (mimetype, "video/mpeg")) {
3358 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3359 gst_structure_get_int (structure, "mpegversion", &mpegversion) &&
3361 switch (mpegversion) {
3363 id = AV_CODEC_ID_MPEG1VIDEO;
3366 id = AV_CODEC_ID_MPEG2VIDEO;
3369 id = AV_CODEC_ID_MPEG4;
3373 if (id != AV_CODEC_ID_NONE)
3375 } else if (!strcmp (mimetype, "image/jpeg")) {
3376 id = AV_CODEC_ID_MJPEG; /* A... B... */
3378 } else if (!strcmp (mimetype, "video/x-jpeg-b")) {
3379 id = AV_CODEC_ID_MJPEGB;
3381 } else if (!strcmp (mimetype, "video/x-wmv")) {
3382 gint wmvversion = 0;
3384 if (gst_structure_get_int (structure, "wmvversion", &wmvversion)) {
3385 switch (wmvversion) {
3387 id = AV_CODEC_ID_WMV1;
3390 id = AV_CODEC_ID_WMV2;
3394 const gchar *format;
3396 /* WMV3 unless the fourcc exists and says otherwise */
3397 id = AV_CODEC_ID_WMV3;
3399 if ((format = gst_structure_get_string (structure, "format")) &&
3400 (g_str_equal (format, "WVC1") || g_str_equal (format, "WMVA")))
3401 id = AV_CODEC_ID_VC1;
3407 if (id != AV_CODEC_ID_NONE)
3409 } else if (!strcmp (mimetype, "audio/x-vorbis")) {
3410 id = AV_CODEC_ID_VORBIS;
3412 } else if (!strcmp (mimetype, "audio/x-qdm2")) {
3413 id = AV_CODEC_ID_QDM2;
3415 } else if (!strcmp (mimetype, "audio/mpeg")) {
3417 gint mpegversion = 0;
3419 if (gst_structure_get_int (structure, "mpegversion", &mpegversion)) {
3420 switch (mpegversion) {
3421 case 2: /* ffmpeg uses faad for both... */
3423 id = AV_CODEC_ID_AAC;
3426 if (gst_structure_get_int (structure, "layer", &layer)) {
3429 id = AV_CODEC_ID_MP1;
3432 id = AV_CODEC_ID_MP2;
3435 id = AV_CODEC_ID_MP3;
3441 if (id != AV_CODEC_ID_NONE)
3443 } else if (!strcmp (mimetype, "audio/x-musepack")) {
3444 gint streamversion = -1;
3446 if (gst_structure_get_int (structure, "streamversion", &streamversion)) {
3447 if (streamversion == 7)
3448 id = AV_CODEC_ID_MUSEPACK7;
3450 id = AV_CODEC_ID_MUSEPACK7;
3452 } else if (!strcmp (mimetype, "audio/x-wma")) {
3453 gint wmaversion = 0;
3455 if (gst_structure_get_int (structure, "wmaversion", &wmaversion)) {
3456 switch (wmaversion) {
3458 id = AV_CODEC_ID_WMAV1;
3461 id = AV_CODEC_ID_WMAV2;
3464 id = AV_CODEC_ID_WMAPRO;
3468 if (id != AV_CODEC_ID_NONE)
3470 } else if (!strcmp (mimetype, "audio/x-wms")) {
3471 id = AV_CODEC_ID_WMAVOICE;
3473 } else if (!strcmp (mimetype, "audio/x-ac3")) {
3474 id = AV_CODEC_ID_AC3;
3476 } else if (!strcmp (mimetype, "audio/x-eac3")) {
3477 id = AV_CODEC_ID_EAC3;
3479 } else if (!strcmp (mimetype, "audio/x-vnd.sony.atrac3") ||
3480 !strcmp (mimetype, "audio/atrac3")) {
3481 id = AV_CODEC_ID_ATRAC3;
3483 } else if (!strcmp (mimetype, "audio/x-dts")) {
3484 id = AV_CODEC_ID_DTS;
3486 } else if (!strcmp (mimetype, "application/x-ape")) {
3487 id = AV_CODEC_ID_APE;
3489 } else if (!strcmp (mimetype, "video/x-msmpeg")) {
3490 gint msmpegversion = 0;
3492 if (gst_structure_get_int (structure, "msmpegversion", &msmpegversion)) {
3493 switch (msmpegversion) {
3495 id = AV_CODEC_ID_MSMPEG4V1;
3498 id = AV_CODEC_ID_MSMPEG4V2;
3501 id = AV_CODEC_ID_MSMPEG4V3;
3505 if (id != AV_CODEC_ID_NONE)
3507 } else if (!strcmp (mimetype, "video/x-svq")) {
3508 gint svqversion = 0;
3510 if (gst_structure_get_int (structure, "svqversion", &svqversion)) {
3511 switch (svqversion) {
3513 id = AV_CODEC_ID_SVQ1;
3516 id = AV_CODEC_ID_SVQ3;
3520 if (id != AV_CODEC_ID_NONE)
3522 } else if (!strcmp (mimetype, "video/x-huffyuv")) {
3523 id = AV_CODEC_ID_HUFFYUV;
3525 } else if (!strcmp (mimetype, "audio/x-mace")) {
3526 gint maceversion = 0;
3528 if (gst_structure_get_int (structure, "maceversion", &maceversion)) {
3529 switch (maceversion) {
3531 id = AV_CODEC_ID_MACE3;
3534 id = AV_CODEC_ID_MACE6;
3538 if (id != AV_CODEC_ID_NONE)
3540 } else if (!strcmp (mimetype, "video/x-theora")) {
3541 id = AV_CODEC_ID_THEORA;
3543 } else if (!strcmp (mimetype, "video/x-vp3")) {
3544 id = AV_CODEC_ID_VP3;
3546 } else if (!strcmp (mimetype, "video/x-vp5")) {
3547 id = AV_CODEC_ID_VP5;
3549 } else if (!strcmp (mimetype, "video/x-vp6")) {
3550 id = AV_CODEC_ID_VP6;
3552 } else if (!strcmp (mimetype, "video/x-vp6-flash")) {
3553 id = AV_CODEC_ID_VP6F;
3555 } else if (!strcmp (mimetype, "video/x-vp6-alpha")) {
3556 id = AV_CODEC_ID_VP6A;
3558 } else if (!strcmp (mimetype, "video/x-vp8")) {
3559 id = AV_CODEC_ID_VP8;
3561 } else if (!strcmp (mimetype, "video/x-flash-screen")) {
3562 id = AV_CODEC_ID_FLASHSV;
3564 } else if (!strcmp (mimetype, "video/x-indeo")) {
3565 gint indeoversion = 0;
3567 if (gst_structure_get_int (structure, "indeoversion", &indeoversion)) {
3568 switch (indeoversion) {
3570 id = AV_CODEC_ID_INDEO5;
3573 id = AV_CODEC_ID_INDEO4;
3576 id = AV_CODEC_ID_INDEO3;
3579 id = AV_CODEC_ID_INDEO2;
3582 if (id != AV_CODEC_ID_NONE)
3585 } else if (!strcmp (mimetype, "video/x-divx")) {
3586 gint divxversion = 0;
3588 if (gst_structure_get_int (structure, "divxversion", &divxversion)) {
3589 switch (divxversion) {
3591 id = AV_CODEC_ID_MSMPEG4V3;
3595 id = AV_CODEC_ID_MPEG4;
3599 if (id != AV_CODEC_ID_NONE)
3601 } else if (!strcmp (mimetype, "video/x-3ivx")) {
3602 id = AV_CODEC_ID_MPEG4;
3604 } else if (!strcmp (mimetype, "video/x-xvid")) {
3605 id = AV_CODEC_ID_MPEG4;
3607 } else if (!strcmp (mimetype, "video/x-ffv")) {
3608 gint ffvversion = 0;
3610 if (gst_structure_get_int (structure, "ffvversion", &ffvversion) &&
3612 id = AV_CODEC_ID_FFV1;
3615 } else if (!strcmp (mimetype, "audio/x-adpcm")) {
3616 const gchar *layout;
3618 layout = gst_structure_get_string (structure, "layout");
3619 if (layout == NULL) {
3621 } else if (!strcmp (layout, "quicktime")) {
3622 id = AV_CODEC_ID_ADPCM_IMA_QT;
3623 } else if (!strcmp (layout, "microsoft")) {
3624 id = AV_CODEC_ID_ADPCM_MS;
3625 } else if (!strcmp (layout, "dvi")) {
3626 id = AV_CODEC_ID_ADPCM_IMA_WAV;
3627 } else if (!strcmp (layout, "4xm")) {
3628 id = AV_CODEC_ID_ADPCM_4XM;
3629 } else if (!strcmp (layout, "smjpeg")) {
3630 id = AV_CODEC_ID_ADPCM_IMA_SMJPEG;
3631 } else if (!strcmp (layout, "dk3")) {
3632 id = AV_CODEC_ID_ADPCM_IMA_DK3;
3633 } else if (!strcmp (layout, "dk4")) {
3634 id = AV_CODEC_ID_ADPCM_IMA_DK4;
3635 } else if (!strcmp (layout, "westwood")) {
3636 id = AV_CODEC_ID_ADPCM_IMA_WS;
3637 } else if (!strcmp (layout, "iss")) {
3638 id = AV_CODEC_ID_ADPCM_IMA_ISS;
3639 } else if (!strcmp (layout, "xa")) {
3640 id = AV_CODEC_ID_ADPCM_XA;
3641 } else if (!strcmp (layout, "adx")) {
3642 id = AV_CODEC_ID_ADPCM_ADX;
3643 } else if (!strcmp (layout, "ea")) {
3644 id = AV_CODEC_ID_ADPCM_EA;
3645 } else if (!strcmp (layout, "g726")) {
3646 id = AV_CODEC_ID_ADPCM_G726;
3647 } else if (!strcmp (layout, "g721")) {
3648 id = AV_CODEC_ID_ADPCM_G726;
3649 } else if (!strcmp (layout, "ct")) {
3650 id = AV_CODEC_ID_ADPCM_CT;
3651 } else if (!strcmp (layout, "swf")) {
3652 id = AV_CODEC_ID_ADPCM_SWF;
3653 } else if (!strcmp (layout, "yamaha")) {
3654 id = AV_CODEC_ID_ADPCM_YAMAHA;
3655 } else if (!strcmp (layout, "sbpro2")) {
3656 id = AV_CODEC_ID_ADPCM_SBPRO_2;
3657 } else if (!strcmp (layout, "sbpro3")) {
3658 id = AV_CODEC_ID_ADPCM_SBPRO_3;
3659 } else if (!strcmp (layout, "sbpro4")) {
3660 id = AV_CODEC_ID_ADPCM_SBPRO_4;
3662 if (id != AV_CODEC_ID_NONE)
3664 } else if (!strcmp (mimetype, "video/x-4xm")) {
3665 id = AV_CODEC_ID_4XM;
3667 } else if (!strcmp (mimetype, "audio/x-dpcm")) {
3668 const gchar *layout;
3670 layout = gst_structure_get_string (structure, "layout");
3673 } else if (!strcmp (layout, "roq")) {
3674 id = AV_CODEC_ID_ROQ_DPCM;
3675 } else if (!strcmp (layout, "interplay")) {
3676 id = AV_CODEC_ID_INTERPLAY_DPCM;
3677 } else if (!strcmp (layout, "xan")) {
3678 id = AV_CODEC_ID_XAN_DPCM;
3679 } else if (!strcmp (layout, "sol")) {
3680 id = AV_CODEC_ID_SOL_DPCM;
3682 if (id != AV_CODEC_ID_NONE)
3684 } else if (!strcmp (mimetype, "audio/x-flac")) {
3685 id = AV_CODEC_ID_FLAC;
3687 } else if (!strcmp (mimetype, "audio/x-shorten")) {
3688 id = AV_CODEC_ID_SHORTEN;
3690 } else if (!strcmp (mimetype, "audio/x-alac")) {
3691 id = AV_CODEC_ID_ALAC;
3693 } else if (!strcmp (mimetype, "video/x-cinepak")) {
3694 id = AV_CODEC_ID_CINEPAK;
3696 } else if (!strcmp (mimetype, "video/x-pn-realvideo")) {
3699 if (gst_structure_get_int (structure, "rmversion", &rmversion)) {
3700 switch (rmversion) {
3702 id = AV_CODEC_ID_RV10;
3705 id = AV_CODEC_ID_RV20;
3708 id = AV_CODEC_ID_RV30;
3711 id = AV_CODEC_ID_RV40;
3715 if (id != AV_CODEC_ID_NONE)
3717 } else if (!strcmp (mimetype, "audio/x-sipro")) {
3718 id = AV_CODEC_ID_SIPR;
3720 } else if (!strcmp (mimetype, "audio/x-pn-realaudio")) {
3723 if (gst_structure_get_int (structure, "raversion", &raversion)) {
3724 switch (raversion) {
3726 id = AV_CODEC_ID_RA_144;
3729 id = AV_CODEC_ID_RA_288;
3732 id = AV_CODEC_ID_COOK;
3736 if (id != AV_CODEC_ID_NONE)
3738 } else if (!strcmp (mimetype, "video/x-rle")) {
3739 const gchar *layout;
3741 if ((layout = gst_structure_get_string (structure, "layout"))) {
3742 if (!strcmp (layout, "microsoft")) {
3743 id = AV_CODEC_ID_MSRLE;
3747 } else if (!strcmp (mimetype, "video/x-xan")) {
3750 if ((gst_structure_get_int (structure, "wcversion", &wcversion))) {
3751 switch (wcversion) {
3753 id = AV_CODEC_ID_XAN_WC3;
3757 id = AV_CODEC_ID_XAN_WC4;
3764 } else if (!strcmp (mimetype, "audio/AMR")) {
3766 id = AV_CODEC_ID_AMR_NB;
3767 } else if (!strcmp (mimetype, "audio/AMR-WB")) {
3768 id = AV_CODEC_ID_AMR_WB;
3770 } else if (!strcmp (mimetype, "audio/qcelp")) {
3771 id = AV_CODEC_ID_QCELP;
3773 } else if (!strcmp (mimetype, "video/x-h264")) {
3774 id = AV_CODEC_ID_H264;
3776 } else if (!strcmp (mimetype, "video/x-flash-video")) {
3777 gint flvversion = 0;
3779 if ((gst_structure_get_int (structure, "flvversion", &flvversion))) {
3780 switch (flvversion) {
3782 id = AV_CODEC_ID_FLV1;
3790 } else if (!strcmp (mimetype, "audio/x-nellymoser")) {
3791 id = AV_CODEC_ID_NELLYMOSER;
3793 } else if (!strncmp (mimetype, "audio/x-gst-av-", 15)) {
3797 if (strlen (mimetype) <= 30 &&
3798 sscanf (mimetype, "audio/x-gst-av-%s", ext) == 1) {
3799 if ((codec = avcodec_find_decoder_by_name (ext)) ||
3800 (codec = avcodec_find_encoder_by_name (ext))) {
3805 } else if (!strncmp (mimetype, "video/x-gst-av-", 15)) {
3809 if (strlen (mimetype) <= 30 &&
3810 sscanf (mimetype, "video/x-gst-av-%s", ext) == 1) {
3811 if ((codec = avcodec_find_decoder_by_name (ext)) ||
3812 (codec = avcodec_find_encoder_by_name (ext))) {
3819 if (context != NULL) {
3820 if (video == TRUE) {
3821 context->codec_type = AVMEDIA_TYPE_VIDEO;
3822 } else if (audio == TRUE) {
3823 context->codec_type = AVMEDIA_TYPE_AUDIO;
3825 context->codec_type = AVMEDIA_TYPE_UNKNOWN;
3827 context->codec_id = id;
3828 gst_ffmpeg_caps_with_codecid (id, context->codec_type, caps, context);
3831 if (id != AV_CODEC_ID_NONE) {
3832 GST_DEBUG ("The id=%d belongs to the caps %" GST_PTR_FORMAT, id, caps);
3834 GST_WARNING ("Couldn't figure out the id for caps %" GST_PTR_FORMAT, caps);