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 if (channels == 1 && pos[0] == GST_AUDIO_CHANNEL_POSITION_MONO)
81 return AV_CH_LAYOUT_MONO;
83 for (i = 0; i < channels; i++) {
84 for (j = 0; j < G_N_ELEMENTS (_ff_to_gst_layout); j++) {
85 if (_ff_to_gst_layout[j].gst == pos[i]) {
86 ret |= _ff_to_gst_layout[j].ff;
93 if (channels_found != channels)
99 gst_ffmpeg_channel_layout_to_gst (guint64 channel_layout, gint channels,
100 GstAudioChannelPosition * pos)
103 gboolean none_layout = FALSE;
105 if (channel_layout == 0 || channels > 64) {
106 nchannels = channels;
111 /* Special path for mono, as AV_CH_LAYOUT_MONO is the same
112 * as FRONT_CENTER but we distinguish between the two in
115 if (channels == 1 && channel_layout == AV_CH_LAYOUT_MONO) {
116 pos[0] = GST_AUDIO_CHANNEL_POSITION_MONO;
120 for (i = 0; i < 64; i++) {
121 if ((channel_layout & (G_GUINT64_CONSTANT (1) << i)) != 0) {
126 if (nchannels != channels) {
127 GST_ERROR ("Number of channels is different (%u != %u)", channels,
129 nchannels = channels;
133 for (i = 0, j = 0; i < G_N_ELEMENTS (_ff_to_gst_layout); i++) {
134 if ((channel_layout & _ff_to_gst_layout[i].ff) != 0) {
135 pos[j++] = _ff_to_gst_layout[i].gst;
137 if (_ff_to_gst_layout[i].gst == GST_AUDIO_CHANNEL_POSITION_NONE)
142 if (j != nchannels) {
144 ("Unknown channels in channel layout - assuming NONE layout");
151 && !gst_audio_check_valid_channel_positions (pos, nchannels, FALSE)) {
152 GST_ERROR ("Invalid channel layout %" G_GUINT64_FORMAT
153 " - assuming NONE layout", channel_layout);
158 if (nchannels == 1) {
159 pos[0] = GST_AUDIO_CHANNEL_POSITION_MONO;
160 } else if (nchannels == 2) {
161 pos[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT;
162 pos[1] = GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT;
166 for (i = 0; i < nchannels && i < 64; i++)
167 pos[i] = GST_AUDIO_CHANNEL_POSITION_NONE;
175 _gst_value_list_contains (const GValue * list, const GValue * value)
180 n = gst_value_list_get_size (list);
181 for (i = 0; i < n; i++) {
182 tmp = gst_value_list_get_value (list, i);
183 if (gst_value_compare (value, tmp) == GST_VALUE_EQUAL)
191 gst_ffmpeg_video_set_pix_fmts (GstCaps * caps, const enum AVPixelFormat *fmts)
195 GstVideoFormat format;
197 if (!fmts || fmts[0] == -1) {
200 g_value_init (&va, GST_TYPE_LIST);
201 g_value_init (&v, G_TYPE_STRING);
202 for (i = 0; i <= AV_PIX_FMT_NB; i++) {
203 format = gst_ffmpeg_pixfmt_to_videoformat (i);
204 if (format == GST_VIDEO_FORMAT_UNKNOWN)
206 g_value_set_string (&v, gst_video_format_to_string (format));
207 gst_value_list_append_value (&va, &v);
209 gst_caps_set_value (caps, "format", &va);
215 /* Only a single format */
216 g_value_init (&va, GST_TYPE_LIST);
217 g_value_init (&v, G_TYPE_STRING);
218 while (*fmts != -1) {
219 format = gst_ffmpeg_pixfmt_to_videoformat (*fmts);
220 if (format != GST_VIDEO_FORMAT_UNKNOWN) {
221 g_value_set_string (&v, gst_video_format_to_string (format));
222 /* Only append values we don't have yet */
223 if (!_gst_value_list_contains (&va, &v))
224 gst_value_list_append_value (&va, &v);
228 if (gst_value_list_get_size (&va) == 1) {
229 /* The single value is still in v */
230 gst_caps_set_value (caps, "format", &v);
231 } else if (gst_value_list_get_size (&va) > 1) {
232 gst_caps_set_value (caps, "format", &va);
238 /* this macro makes a caps width fixed or unfixed width/height
239 * properties depending on whether we've got a context.
241 * See below for why we use this.
243 * We should actually do this stuff at the end, like in riff-media.c,
244 * but I'm too lazy today. Maybe later.
247 gst_ff_vid_caps_new (AVCodecContext * context, const AVCodec * codec,
248 enum AVCodecID codec_id, gboolean encode, const char *mimetype,
249 const char *fieldname, ...)
251 GstCaps *caps = NULL;
255 GST_LOG ("context:%p, codec_id:%d, mimetype:%s", context, codec_id, mimetype);
257 /* fixed, non probing context */
258 if (context != NULL && context->width != -1) {
261 caps = gst_caps_new_simple (mimetype,
262 "width", G_TYPE_INT, context->width,
263 "height", G_TYPE_INT, context->height, NULL);
265 num = context->framerate.num;
266 denom = context->framerate.den;
269 GST_LOG ("invalid framerate: %d/0, -> %d/1", num, num);
272 if (gst_util_fraction_compare (num, denom, 1000, 1) > 0) {
273 GST_LOG ("excessive framerate: %d/%d, -> 0/1", num, denom);
277 GST_LOG ("setting framerate: %d/%d", num, denom);
278 gst_caps_set_simple (caps,
279 "framerate", GST_TYPE_FRACTION, num, denom, NULL);
281 /* so we are after restricted caps in this case */
283 case AV_CODEC_ID_H261:
285 caps = gst_caps_new_simple (mimetype,
286 "width", G_TYPE_INT, 352,
287 "height", G_TYPE_INT, 288,
288 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
289 gst_caps_append (caps, gst_caps_new_simple (mimetype,
290 "width", G_TYPE_INT, 176,
291 "height", G_TYPE_INT, 144,
292 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL));
295 case AV_CODEC_ID_H263:
297 /* 128x96, 176x144, 352x288, 704x576, and 1408x1152. slightly reordered
298 * because we want automatic negotiation to go as close to 320x240 as
300 const static gint widths[] = { 352, 704, 176, 1408, 128 };
301 const static gint heights[] = { 288, 576, 144, 1152, 96 };
303 gint n_sizes = G_N_ELEMENTS (widths);
305 caps = gst_caps_new_empty ();
306 for (i = 0; i < n_sizes; i++) {
307 temp = gst_caps_new_simple (mimetype,
308 "width", G_TYPE_INT, widths[i],
309 "height", G_TYPE_INT, heights[i],
310 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
312 gst_caps_append (caps, temp);
316 case AV_CODEC_ID_DVVIDEO:
323 gint framerate_n, framerate_d;
326 "Y41B", 720, 480, 8, 9, 30000, 1001}, {
327 "Y41B", 720, 480, 32, 27, 30000, 1001}, {
328 "Y42B", 720, 480, 8, 9, 30000, 1001}, {
329 "Y42B", 720, 480, 32, 27, 30000, 1001}, {
330 "I420", 720, 576, 16, 15, 25, 1}, {
331 "I420", 720, 576, 64, 45, 25, 1}, {
332 "Y41B", 720, 576, 16, 15, 25, 1}, {
333 "Y41B", 720, 576, 64, 45, 25, 1}, {
334 "Y42B", 720, 576, 16, 15, 25, 1}, {
335 "Y42B", 720, 576, 64, 45, 25, 1}, {
336 "Y42B", 1280, 1080, 1, 1, 30000, 1001}, {
337 "Y42B", 1280, 1080, 3, 2, 30000, 1001}, {
338 "Y42B", 1440, 1080, 1, 1, 25, 1}, {
339 "Y42B", 1440, 1080, 4, 3, 25, 1}, {
340 "Y42B", 960, 720, 1, 1, 60000, 1001}, {
341 "Y42B", 960, 720, 4, 3, 60000, 1001}, {
342 "Y42B", 960, 720, 1, 1, 50, 1}, {
343 "Y42B", 960, 720, 4, 3, 50, 1},};
345 gint n_sizes = G_N_ELEMENTS (profiles);
347 if (strcmp (mimetype, "video/x-raw") == 0) {
348 caps = gst_caps_new_empty ();
349 for (i = 0; i < n_sizes; i++) {
350 temp = gst_caps_new_simple (mimetype,
351 "format", G_TYPE_STRING, profiles[i].csp,
352 "width", G_TYPE_INT, profiles[i].width,
353 "height", G_TYPE_INT, profiles[i].height,
354 "framerate", GST_TYPE_FRACTION, profiles[i].framerate_n,
355 profiles[i].framerate_d, "pixel-aspect-ratio",
356 GST_TYPE_FRACTION, profiles[i].par_n, profiles[i].par_d, NULL);
358 gst_caps_append (caps, temp);
361 caps = gst_caps_new_empty ();
362 for (i = 0; i < n_sizes; i++) {
363 temp = gst_caps_new_simple (mimetype,
364 "width", G_TYPE_INT, profiles[i].width,
365 "height", G_TYPE_INT, profiles[i].height,
366 "framerate", GST_TYPE_FRACTION, profiles[i].framerate_n,
367 profiles[i].framerate_d, "pixel-aspect-ratio",
368 GST_TYPE_FRACTION, profiles[i].par_n, profiles[i].par_d, NULL);
370 gst_caps_append (caps, temp);
375 case AV_CODEC_ID_DNXHD:
377 caps = gst_caps_new_simple (mimetype,
378 "width", G_TYPE_INT, 1920,
379 "height", G_TYPE_INT, 1080,
380 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
381 gst_caps_append (caps, gst_caps_new_simple (mimetype,
382 "width", G_TYPE_INT, 1280,
383 "height", G_TYPE_INT, 720,
384 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL));
389 if (codec && codec->supported_framerates
390 && codec->supported_framerates[0].num != 0
391 && codec->supported_framerates[0].den != 0) {
394 const AVRational *rates = codec->supported_framerates;
396 if (rates[1].num == 0 && rates[1].den == 0) {
398 gst_caps_new_simple (mimetype, "framerate", GST_TYPE_FRACTION,
399 rates[0].num, rates[0].den, NULL);
401 g_value_init (&va, GST_TYPE_LIST);
402 g_value_init (&v, GST_TYPE_FRACTION);
404 while (rates->num != 0 && rates->den != 0) {
405 gst_value_set_fraction (&v, rates->num, rates->den);
406 gst_value_list_append_value (&va, &v);
410 caps = gst_caps_new_simple (mimetype, NULL, NULL, NULL);
411 gst_caps_set_value (caps, "framerate", &va);
417 caps = gst_caps_new_empty_simple (mimetype);
425 /* no fixed caps or special restrictions applied;
426 * default unfixed setting */
428 GST_DEBUG ("Creating default caps");
429 caps = gst_caps_new_empty_simple (mimetype);
432 va_start (var_args, fieldname);
433 gst_caps_set_simple_valist (caps, fieldname, var_args);
440 get_nbits_set (guint64 n)
445 for (i = 0; i < 64; i++) {
446 if ((n & (G_GUINT64_CONSTANT (1) << i)))
454 gst_ffmpeg_audio_set_sample_fmts (GstCaps * caps,
455 const enum AVSampleFormat *fmts, gboolean always_interleaved)
460 GstAudioFormat format;
461 GstAudioLayout layout;
462 GstCaps *caps_copy = NULL;
464 if (!fmts || fmts[0] == -1) {
467 g_value_init (&va, GST_TYPE_LIST);
468 g_value_init (&v, G_TYPE_STRING);
469 for (i = 0; i <= AV_SAMPLE_FMT_DBL; i++) {
470 format = gst_ffmpeg_smpfmt_to_audioformat (i, NULL);
471 if (format == GST_AUDIO_FORMAT_UNKNOWN)
473 g_value_set_string (&v, gst_audio_format_to_string (format));
474 gst_value_list_append_value (&va, &v);
476 gst_caps_set_value (caps, "format", &va);
477 if (!always_interleaved) {
478 g_value_init (&vap, GST_TYPE_LIST);
479 g_value_set_string (&v, "interleaved");
480 gst_value_list_append_value (&vap, &v);
481 g_value_set_string (&v, "non-interleaved");
482 gst_value_list_append_value (&vap, &v);
483 gst_caps_set_value (caps, "layout", &vap);
484 g_value_unset (&vap);
486 gst_caps_set_simple (caps, "layout", G_TYPE_STRING, "interleaved", NULL);
493 g_value_init (&va, GST_TYPE_LIST);
494 g_value_init (&vap, GST_TYPE_LIST);
495 g_value_init (&v, G_TYPE_STRING);
496 while (*fmts != -1) {
497 format = gst_ffmpeg_smpfmt_to_audioformat (*fmts, &layout);
498 if (format != GST_AUDIO_FORMAT_UNKNOWN) {
499 g_value_set_string (&v, gst_audio_format_to_string (format));
500 /* Only append values we don't have yet */
501 if (layout == GST_AUDIO_LAYOUT_INTERLEAVED || always_interleaved) {
502 if (!_gst_value_list_contains (&va, &v))
503 gst_value_list_append_value (&va, &v);
505 if (!_gst_value_list_contains (&vap, &v))
506 gst_value_list_append_value (&vap, &v);
511 if (gst_value_list_get_size (&va) >= 1 && gst_value_list_get_size (&vap) >= 1) {
512 caps_copy = gst_caps_copy (caps);
514 if (gst_value_list_get_size (&va) == 1) {
515 gst_caps_set_value (caps, "format", gst_value_list_get_value (&va, 0));
516 gst_caps_set_simple (caps, "layout", G_TYPE_STRING, "interleaved", NULL);
517 } else if (gst_value_list_get_size (&va) > 1) {
518 gst_caps_set_value (caps, "format", &va);
519 gst_caps_set_simple (caps, "layout", G_TYPE_STRING, "interleaved", NULL);
521 if (gst_value_list_get_size (&vap) == 1) {
522 gst_caps_set_value (caps_copy ? caps_copy : caps, "format",
523 gst_value_list_get_value (&vap, 0));
524 gst_caps_set_simple (caps_copy ? caps_copy : caps, "layout", G_TYPE_STRING,
525 "non-interleaved", NULL);
526 } else if (gst_value_list_get_size (&vap) > 1) {
527 gst_caps_set_value (caps_copy ? caps_copy : caps, "format", &vap);
528 gst_caps_set_simple (caps_copy ? caps_copy : caps, "layout", G_TYPE_STRING,
529 "non-interleaved", NULL);
532 gst_caps_append (caps, caps_copy);
536 g_value_unset (&vap);
539 /* same for audio - now with channels/sample rate
542 gst_ff_aud_caps_new (AVCodecContext * context, AVCodec * codec,
543 enum AVCodecID codec_id, gboolean encode, const char *mimetype,
544 const char *fieldname, ...)
546 GstCaps *caps = NULL;
550 /* fixed, non-probing context */
551 if (context != NULL && context->channels != -1) {
552 GstAudioChannelPosition pos[64];
555 caps = gst_caps_new_simple (mimetype,
556 "rate", G_TYPE_INT, context->sample_rate,
557 "channels", G_TYPE_INT, context->channels, NULL);
559 if (context->channels > 1 &&
560 gst_ffmpeg_channel_layout_to_gst (context->channel_layout,
561 context->channels, pos) &&
562 gst_audio_channel_positions_to_mask (pos, context->channels, FALSE,
564 gst_caps_set_simple (caps, "channel-mask", GST_TYPE_BITMASK, mask, NULL);
567 gint maxchannels = 2;
568 const gint *rates = NULL;
571 /* so we must be after restricted caps in this case */
573 case AV_CODEC_ID_AAC:
574 case AV_CODEC_ID_AAC_LATM:
575 case AV_CODEC_ID_DTS:
578 case AV_CODEC_ID_MP2:
580 const static gint l_rates[] =
581 { 48000, 44100, 32000, 24000, 22050, 16000 };
582 n_rates = G_N_ELEMENTS (l_rates);
586 case AV_CODEC_ID_EAC3:
587 case AV_CODEC_ID_AC3:
589 const static gint l_rates[] = { 48000, 44100, 32000 };
591 n_rates = G_N_ELEMENTS (l_rates);
595 case AV_CODEC_ID_ADPCM_G722:
597 const static gint l_rates[] = { 16000 };
598 n_rates = G_N_ELEMENTS (l_rates);
603 case AV_CODEC_ID_ADPCM_G726:
605 const static gint l_rates[] = { 8000 };
606 n_rates = G_N_ELEMENTS (l_rates);
611 case AV_CODEC_ID_ADPCM_SWF:
613 const static gint l_rates[] = { 11025, 22050, 44100 };
614 n_rates = G_N_ELEMENTS (l_rates);
618 case AV_CODEC_ID_ROQ_DPCM:
620 const static gint l_rates[] = { 22050 };
621 n_rates = G_N_ELEMENTS (l_rates);
625 case AV_CODEC_ID_AMR_NB:
627 const static gint l_rates[] = { 8000 };
629 n_rates = G_N_ELEMENTS (l_rates);
633 case AV_CODEC_ID_AMR_WB:
635 const static gint l_rates[] = { 16000 };
637 n_rates = G_N_ELEMENTS (l_rates);
645 /* regardless of encode/decode, open up channels if applicable */
646 /* Until decoders/encoders expose the maximum number of channels
647 * they support, we whitelist them here. */
649 case AV_CODEC_ID_WMAPRO:
650 case AV_CODEC_ID_TRUEHD:
657 if (codec && codec->channel_layouts) {
658 const uint64_t *layouts = codec->channel_layouts;
659 GstAudioChannelPosition pos[64];
661 caps = gst_caps_new_empty ();
663 gint nbits_set = get_nbits_set (*layouts);
665 if (gst_ffmpeg_channel_layout_to_gst (*layouts, nbits_set, pos)) {
668 if (gst_audio_channel_positions_to_mask (pos, nbits_set, FALSE,
671 gst_structure_new (mimetype, "channels", G_TYPE_INT, nbits_set,
674 /* No need to require a channel mask for mono or stereo */
675 if (!(nbits_set == 1 && pos[0] == GST_AUDIO_CHANNEL_POSITION_MONO)
677 && pos[0] == GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT
678 && pos[1] == GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT))
679 gst_structure_set (s, "channel-mask", GST_TYPE_BITMASK, mask,
682 gst_caps_append_structure (caps, s);
688 if (maxchannels == 1)
689 caps = gst_caps_new_simple (mimetype,
690 "channels", G_TYPE_INT, maxchannels, NULL);
692 caps = gst_caps_new_simple (mimetype,
693 "channels", GST_TYPE_INT_RANGE, 1, maxchannels, NULL);
697 GValue list = { 0, };
699 g_value_init (&list, GST_TYPE_LIST);
700 for (i = 0; i < n_rates; i++) {
703 g_value_init (&v, G_TYPE_INT);
704 g_value_set_int (&v, rates[i]);
705 gst_value_list_append_value (&list, &v);
708 gst_caps_set_value (caps, "rate", &list);
709 g_value_unset (&list);
710 } else if (codec && codec->supported_samplerates
711 && codec->supported_samplerates[0]) {
715 if (!codec->supported_samplerates[1]) {
716 gst_caps_set_simple (caps, "rate", G_TYPE_INT,
717 codec->supported_samplerates[0], NULL);
719 const int *rates = codec->supported_samplerates;
721 g_value_init (&va, GST_TYPE_LIST);
722 g_value_init (&v, G_TYPE_INT);
725 g_value_set_int (&v, *rates);
726 gst_value_list_append_value (&va, &v);
729 gst_caps_set_value (caps, "rate", &va);
734 gst_caps_set_simple (caps, "rate", GST_TYPE_INT_RANGE, 4000, 96000, NULL);
737 caps = gst_caps_new_empty_simple (mimetype);
740 va_start (var_args, fieldname);
741 gst_caps_set_simple_valist (caps, fieldname, var_args);
747 /* Check if the given codec ID is an image format -- for now this is just
748 * anything whose caps is image/... */
750 gst_ffmpeg_codecid_is_image (enum AVCodecID codec_id)
753 case AV_CODEC_ID_MJPEG:
754 case AV_CODEC_ID_LJPEG:
755 case AV_CODEC_ID_GIF:
756 case AV_CODEC_ID_PPM:
757 case AV_CODEC_ID_PBM:
758 case AV_CODEC_ID_PCX:
759 case AV_CODEC_ID_SGI:
760 case AV_CODEC_ID_TARGA:
761 case AV_CODEC_ID_TIFF:
762 case AV_CODEC_ID_SUNRAST:
763 case AV_CODEC_ID_BMP:
771 /* Convert a FFMPEG codec ID and optional AVCodecContext
772 * to a GstCaps. If the context is ommitted, no fixed values
773 * for video/audio size will be included in the GstCaps
775 * CodecID is primarily meant for compressed data GstCaps!
777 * encode is a special parameter. gstffmpegdec will say
778 * FALSE, gstffmpegenc will say TRUE. The output caps
779 * depends on this, in such a way that it will be very
780 * specific, defined, fixed and correct caps for encoders,
781 * yet very wide, "forgiving" caps for decoders. Example
782 * for mp3: decode: audio/mpeg,mpegversion=1,layer=[1-3]
783 * but encode: audio/mpeg,mpegversion=1,layer=3,bitrate=x,
788 gst_ffmpeg_codecid_to_caps (enum AVCodecID codec_id,
789 AVCodecContext * context, gboolean encode)
791 GstCaps *caps = NULL;
792 gboolean buildcaps = FALSE;
794 GST_LOG ("codec_id:%d, context:%p, encode:%d", codec_id, context, encode);
797 case AV_CODEC_ID_MPEG1VIDEO:
799 caps = gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
800 "mpegversion", G_TYPE_INT, 1,
801 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
804 case AV_CODEC_ID_MPEG2VIDEO:
808 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
809 "mpegversion", G_TYPE_INT, 2, "systemstream", G_TYPE_BOOLEAN, FALSE,
812 /* decode both MPEG-1 and MPEG-2; width/height/fps are all in
813 * the MPEG video stream headers, so may be omitted from caps. */
814 caps = gst_caps_new_simple ("video/mpeg",
815 "mpegversion", GST_TYPE_INT_RANGE, 1, 2,
816 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
820 case AV_CODEC_ID_H263:
823 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
824 "video/x-h263", "variant", G_TYPE_STRING, "itu", "h263version",
825 G_TYPE_STRING, "h263", NULL);
827 /* don't pass codec_id, we can decode other variants with the H263
828 * decoder that don't have specific size requirements
831 gst_ff_vid_caps_new (context, NULL, AV_CODEC_ID_NONE, encode,
832 "video/x-h263", "variant", G_TYPE_STRING, "itu", NULL);
836 case AV_CODEC_ID_H263P:
838 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h263",
839 "variant", G_TYPE_STRING, "itu", "h263version", G_TYPE_STRING,
841 if (encode && context) {
843 gst_caps_set_simple (caps,
844 "annex-f", G_TYPE_BOOLEAN, context->flags & AV_CODEC_FLAG_4MV,
845 "annex-j", G_TYPE_BOOLEAN,
846 context->flags & AV_CODEC_FLAG_LOOP_FILTER,
847 "annex-i", G_TYPE_BOOLEAN, context->flags & AV_CODEC_FLAG_AC_PRED,
848 "annex-t", G_TYPE_BOOLEAN, context->flags & AV_CODEC_FLAG_AC_PRED,
853 case AV_CODEC_ID_H263I:
855 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
856 "video/x-intel-h263", "variant", G_TYPE_STRING, "intel", NULL);
859 case AV_CODEC_ID_H261:
861 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h261",
865 case AV_CODEC_ID_RV10:
866 case AV_CODEC_ID_RV20:
867 case AV_CODEC_ID_RV30:
868 case AV_CODEC_ID_RV40:
873 case AV_CODEC_ID_RV40:
876 case AV_CODEC_ID_RV30:
879 case AV_CODEC_ID_RV20:
888 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
889 "video/x-pn-realvideo", "rmversion", G_TYPE_INT, version, NULL);
891 if (context->extradata_size >= 8) {
892 gst_caps_set_simple (caps,
893 "subformat", G_TYPE_INT, GST_READ_UINT32_BE (context->extradata),
900 case AV_CODEC_ID_MP1:
902 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
903 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 1, NULL);
906 case AV_CODEC_ID_MP2:
908 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
909 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 2, NULL);
912 case AV_CODEC_ID_MP3:
916 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
917 "mpegversion", G_TYPE_INT, 1, "layer", G_TYPE_INT, 3, NULL);
919 /* Decodes MPEG-1 layer 1/2/3. Samplerate, channels et al are
920 * in the MPEG audio header, so may be omitted from caps. */
921 caps = gst_caps_new_simple ("audio/mpeg",
922 "mpegversion", G_TYPE_INT, 1,
923 "layer", GST_TYPE_INT_RANGE, 1, 3, NULL);
927 case AV_CODEC_ID_MUSEPACK7:
929 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
930 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 7,
934 case AV_CODEC_ID_MUSEPACK8:
936 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
937 "audio/x-ffmpeg-parsed-musepack", "streamversion", G_TYPE_INT, 8,
941 case AV_CODEC_ID_AC3:
944 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-ac3",
948 case AV_CODEC_ID_EAC3:
951 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-eac3",
955 case AV_CODEC_ID_TRUEHD:
957 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
958 "audio/x-true-hd", NULL);
961 case AV_CODEC_ID_ATRAC1:
963 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
964 "audio/x-vnd.sony.atrac1", NULL);
967 case AV_CODEC_ID_ATRAC3:
969 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
970 "audio/x-vnd.sony.atrac3", NULL);
973 case AV_CODEC_ID_DTS:
975 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dts",
979 case AV_CODEC_ID_APE:
981 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
982 "audio/x-ffmpeg-parsed-ape", NULL);
984 gst_caps_set_simple (caps,
985 "depth", G_TYPE_INT, context->bits_per_coded_sample, NULL);
989 case AV_CODEC_ID_MLP:
991 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mlp",
995 case AV_CODEC_ID_METASOUND:
997 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
998 "audio/x-voxware", NULL);
1001 case AV_CODEC_ID_IMC:
1003 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-imc",
1007 /* MJPEG is normal JPEG, Motion-JPEG and Quicktime MJPEG-A. MJPEGB
1008 * is Quicktime's MJPEG-B. LJPEG is lossless JPEG. I don't know what
1009 * sp5x is, but it's apparently something JPEG... We don't separate
1010 * between those in GStreamer. Should we (at least between MJPEG,
1011 * MJPEG-B and sp5x decoding...)? */
1012 case AV_CODEC_ID_MJPEG:
1013 case AV_CODEC_ID_LJPEG:
1015 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/jpeg",
1016 "parsed", G_TYPE_BOOLEAN, TRUE, NULL);
1019 case AV_CODEC_ID_JPEG2000:
1021 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-j2c",
1024 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
1025 encode, "image/x-jpc", NULL));
1026 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
1027 encode, "image/jp2", NULL));
1031 case AV_CODEC_ID_SP5X:
1033 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/sp5x",
1037 case AV_CODEC_ID_MJPEGB:
1039 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1040 "video/x-mjpeg-b", NULL);
1043 case AV_CODEC_ID_MPEG4:
1044 if (encode && context != NULL) {
1045 /* I'm not exactly sure what ffmpeg outputs... ffmpeg itself uses
1046 * the AVI fourcc 'DIVX', but 'mp4v' for Quicktime... */
1047 switch (context->codec_tag) {
1048 case GST_MAKE_FOURCC ('D', 'I', 'V', 'X'):
1050 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1051 "video/x-divx", "divxversion", G_TYPE_INT, 5, NULL);
1053 case GST_MAKE_FOURCC ('m', 'p', '4', 'v'):
1055 /* FIXME: bitrate. libav doesn't expose the used profile and level */
1057 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1058 "video/mpeg", "systemstream", G_TYPE_BOOLEAN, FALSE,
1059 "mpegversion", G_TYPE_INT, 4, NULL);
1063 /* The trick here is to separate xvid, divx, mpeg4, 3ivx et al */
1065 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/mpeg",
1066 "mpegversion", G_TYPE_INT, 4, "systemstream", G_TYPE_BOOLEAN, FALSE,
1070 GValue arr = { 0, };
1071 GValue item = { 0, };
1073 g_value_init (&arr, GST_TYPE_LIST);
1074 g_value_init (&item, G_TYPE_STRING);
1075 g_value_set_string (&item, "simple");
1076 gst_value_list_append_value (&arr, &item);
1077 g_value_set_string (&item, "advanced-simple");
1078 gst_value_list_append_value (&arr, &item);
1079 g_value_unset (&item);
1081 gst_caps_set_value (caps, "profile", &arr);
1082 g_value_unset (&arr);
1084 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
1085 encode, "video/x-divx", "divxversion", G_TYPE_INT, 5, NULL));
1087 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
1088 encode, "video/x-divx", "divxversion", GST_TYPE_INT_RANGE, 4,
1094 case AV_CODEC_ID_RAWVIDEO:
1096 gst_ffmpeg_codectype_to_video_caps (context, codec_id, encode, NULL);
1099 case AV_CODEC_ID_MSMPEG4V1:
1100 case AV_CODEC_ID_MSMPEG4V2:
1101 case AV_CODEC_ID_MSMPEG4V3:
1103 gint version = 41 + codec_id - AV_CODEC_ID_MSMPEG4V1;
1105 /* encode-FIXME: bitrate */
1107 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1108 "video/x-msmpeg", "msmpegversion", G_TYPE_INT, version, NULL);
1109 if (!encode && codec_id == AV_CODEC_ID_MSMPEG4V3) {
1110 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
1111 encode, "video/x-divx", "divxversion", G_TYPE_INT, 3, NULL));
1116 case AV_CODEC_ID_WMV1:
1117 case AV_CODEC_ID_WMV2:
1119 gint version = (codec_id == AV_CODEC_ID_WMV1) ? 1 : 2;
1122 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1123 "wmvversion", G_TYPE_INT, version, NULL);
1127 case AV_CODEC_ID_FLV1:
1129 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1130 "video/x-flash-video", "flvversion", G_TYPE_INT, 1, NULL);
1133 case AV_CODEC_ID_SVQ1:
1135 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-svq",
1136 "svqversion", G_TYPE_INT, 1, NULL);
1139 case AV_CODEC_ID_SVQ3:
1141 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-svq",
1142 "svqversion", G_TYPE_INT, 3, NULL);
1145 case AV_CODEC_ID_DVAUDIO:
1147 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dv",
1151 case AV_CODEC_ID_DVVIDEO:
1153 if (encode && context) {
1154 const gchar *format;
1156 switch (context->pix_fmt) {
1157 case AV_PIX_FMT_YUYV422:
1160 case AV_PIX_FMT_YUV420P:
1163 case AV_PIX_FMT_YUVA420P:
1166 case AV_PIX_FMT_YUV411P:
1169 case AV_PIX_FMT_YUV422P:
1172 case AV_PIX_FMT_YUV410P:
1177 ("Couldnt' find format for pixfmt %d, defaulting to I420",
1183 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dv",
1184 "systemstream", G_TYPE_BOOLEAN, FALSE, "format", G_TYPE_STRING,
1188 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dv",
1189 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
1194 case AV_CODEC_ID_WMAV1:
1195 case AV_CODEC_ID_WMAV2:
1197 gint version = (codec_id == AV_CODEC_ID_WMAV1) ? 1 : 2;
1201 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1202 "wmaversion", G_TYPE_INT, version, "block_align", G_TYPE_INT,
1203 context->block_align, "bitrate", G_TYPE_INT,
1204 (guint) context->bit_rate, NULL);
1207 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1208 "wmaversion", G_TYPE_INT, version, "block_align",
1209 GST_TYPE_INT_RANGE, 0, G_MAXINT, "bitrate", GST_TYPE_INT_RANGE, 0,
1214 case AV_CODEC_ID_WMAPRO:
1217 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1218 "wmaversion", G_TYPE_INT, 3, NULL);
1221 case AV_CODEC_ID_WMALOSSLESS:
1224 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wma",
1225 "wmaversion", G_TYPE_INT, 4, NULL);
1228 case AV_CODEC_ID_WMAVOICE:
1231 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-wms",
1236 case AV_CODEC_ID_XMA1:
1239 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-xma",
1240 "xmaversion", G_TYPE_INT, 1, NULL);
1243 case AV_CODEC_ID_XMA2:
1246 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-xma",
1247 "xmaversion", G_TYPE_INT, 2, NULL);
1251 case AV_CODEC_ID_MACE3:
1252 case AV_CODEC_ID_MACE6:
1254 gint version = (codec_id == AV_CODEC_ID_MACE3) ? 3 : 6;
1257 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mace",
1258 "maceversion", G_TYPE_INT, version, NULL);
1262 case AV_CODEC_ID_HUFFYUV:
1264 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1265 "video/x-huffyuv", NULL);
1267 gst_caps_set_simple (caps,
1268 "bpp", G_TYPE_INT, context->bits_per_coded_sample, NULL);
1272 case AV_CODEC_ID_CYUV:
1274 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1275 "video/x-compressed-yuv", NULL);
1278 case AV_CODEC_ID_H264:
1280 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h264",
1281 "alignment", G_TYPE_STRING, "au", NULL);
1283 GValue arr = { 0, };
1284 GValue item = { 0, };
1285 g_value_init (&arr, GST_TYPE_LIST);
1286 g_value_init (&item, G_TYPE_STRING);
1287 g_value_set_string (&item, "avc");
1288 gst_value_list_append_value (&arr, &item);
1289 g_value_set_string (&item, "byte-stream");
1290 gst_value_list_append_value (&arr, &item);
1291 g_value_unset (&item);
1292 gst_caps_set_value (caps, "stream-format", &arr);
1293 g_value_unset (&arr);
1295 gst_caps_append (caps, gst_ff_vid_caps_new (context, NULL, codec_id,
1296 encode, "video/x-h264", "alignment", G_TYPE_STRING, "nal",
1297 "stream-format", G_TYPE_STRING, "byte-stream", NULL));
1299 } else if (context) {
1300 /* FIXME: ffmpeg currently assumes AVC if there is extradata and
1301 * byte-stream otherwise. See for example the MOV or MPEG-TS code.
1302 * ffmpeg does not distinguish the different types of AVC. */
1303 if (context->extradata_size > 0) {
1304 gst_caps_set_simple (caps, "stream-format", G_TYPE_STRING, "avc",
1307 gst_caps_set_simple (caps, "stream-format", G_TYPE_STRING,
1308 "byte-stream", NULL);
1313 case AV_CODEC_ID_HEVC:
1315 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-h265",
1316 "alignment", G_TYPE_STRING, "au", NULL);
1318 GValue arr = { 0, };
1319 GValue item = { 0, };
1320 g_value_init (&arr, GST_TYPE_LIST);
1321 g_value_init (&item, G_TYPE_STRING);
1322 g_value_set_string (&item, "hvc1");
1323 gst_value_list_append_value (&arr, &item);
1324 g_value_set_string (&item, "hev1");
1325 gst_value_list_append_value (&arr, &item);
1326 g_value_set_string (&item, "byte-stream");
1327 gst_value_list_append_value (&arr, &item);
1328 g_value_unset (&item);
1329 gst_caps_set_value (caps, "stream-format", &arr);
1330 g_value_unset (&arr);
1331 } else if (context) {
1332 /* FIXME: ffmpeg currently assumes HVC1 if there is extradata and
1333 * byte-stream otherwise. See for example the MOV or MPEG-TS code.
1334 * ffmpeg does not distinguish the different types: HVC1/HEV1/etc. */
1335 if (context->extradata_size > 0) {
1336 gst_caps_set_simple (caps, "stream-format", G_TYPE_STRING, "hvc1",
1339 gst_caps_set_simple (caps, "stream-format", G_TYPE_STRING,
1340 "byte-stream", NULL);
1345 case AV_CODEC_ID_INDEO5:
1347 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1348 "indeoversion", G_TYPE_INT, 5, NULL);
1351 case AV_CODEC_ID_INDEO4:
1353 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1354 "indeoversion", G_TYPE_INT, 4, NULL);
1357 case AV_CODEC_ID_INDEO3:
1359 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1360 "indeoversion", G_TYPE_INT, 3, NULL);
1363 case AV_CODEC_ID_INDEO2:
1365 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-indeo",
1366 "indeoversion", G_TYPE_INT, 2, NULL);
1369 case AV_CODEC_ID_FLASHSV:
1371 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1372 "video/x-flash-screen", NULL);
1375 case AV_CODEC_ID_FLASHSV2:
1377 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1378 "video/x-flash-screen2", NULL);
1381 case AV_CODEC_ID_VP3:
1383 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp3",
1387 case AV_CODEC_ID_VP5:
1389 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp5",
1393 case AV_CODEC_ID_VP6:
1395 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp6",
1399 case AV_CODEC_ID_VP6F:
1401 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1402 "video/x-vp6-flash", NULL);
1405 case AV_CODEC_ID_VP6A:
1407 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1408 "video/x-vp6-alpha", NULL);
1411 case AV_CODEC_ID_VP8:
1413 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp8",
1417 case AV_CODEC_ID_VP9:
1419 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vp9",
1423 case AV_CODEC_ID_THEORA:
1425 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1426 "video/x-theora", NULL);
1429 case AV_CODEC_ID_CFHD:
1431 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1432 "video/x-cineform", NULL);
1435 case AV_CODEC_ID_SPEEDHQ:
1436 if (context && context->codec_tag) {
1437 gchar *variant = g_strdup_printf ("%" GST_FOURCC_FORMAT,
1438 GST_FOURCC_ARGS (context->codec_tag));
1440 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1441 "video/x-speedhq", "variant", G_TYPE_STRING, variant, NULL);
1445 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1446 "video/x-speedhq", NULL);
1450 case AV_CODEC_ID_AAC:
1453 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
1457 GValue arr = { 0, };
1458 GValue item = { 0, };
1460 g_value_init (&arr, GST_TYPE_LIST);
1461 g_value_init (&item, G_TYPE_INT);
1462 g_value_set_int (&item, 2);
1463 gst_value_list_append_value (&arr, &item);
1464 g_value_set_int (&item, 4);
1465 gst_value_list_append_value (&arr, &item);
1466 g_value_unset (&item);
1468 gst_caps_set_value (caps, "mpegversion", &arr);
1469 g_value_unset (&arr);
1471 g_value_init (&arr, GST_TYPE_LIST);
1472 g_value_init (&item, G_TYPE_STRING);
1473 g_value_set_string (&item, "raw");
1474 gst_value_list_append_value (&arr, &item);
1475 g_value_set_string (&item, "adts");
1476 gst_value_list_append_value (&arr, &item);
1477 g_value_set_string (&item, "adif");
1478 gst_value_list_append_value (&arr, &item);
1479 g_value_unset (&item);
1481 gst_caps_set_value (caps, "stream-format", &arr);
1482 g_value_unset (&arr);
1484 gst_caps_set_simple (caps, "mpegversion", G_TYPE_INT, 4,
1485 "base-profile", G_TYPE_STRING, "lc", NULL);
1487 /* FIXME: ffmpeg currently assumes raw if there is extradata and
1488 * ADTS otherwise. See for example the FDK AAC encoder. */
1489 if (context && context->extradata_size > 0) {
1490 gst_caps_set_simple (caps, "stream-format", G_TYPE_STRING, "raw",
1492 gst_codec_utils_aac_caps_set_level_and_profile (caps,
1493 context->extradata, context->extradata_size);
1494 } else if (context) {
1495 gst_caps_set_simple (caps, "stream-format", G_TYPE_STRING, "adts",
1502 case AV_CODEC_ID_AAC_LATM: /* LATM/LOAS AAC syntax */
1503 caps = gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/mpeg",
1504 "mpegversion", G_TYPE_INT, 4, "stream-format", G_TYPE_STRING, "loas",
1508 case AV_CODEC_ID_ASV1:
1510 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-asus",
1511 "asusversion", G_TYPE_INT, 1, NULL);
1513 case AV_CODEC_ID_ASV2:
1515 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-asus",
1516 "asusversion", G_TYPE_INT, 2, NULL);
1519 case AV_CODEC_ID_FFV1:
1521 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-ffv",
1522 "ffvversion", G_TYPE_INT, 1, NULL);
1525 case AV_CODEC_ID_4XM:
1527 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-4xm",
1531 case AV_CODEC_ID_XAN_WC3:
1532 case AV_CODEC_ID_XAN_WC4:
1534 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-xan",
1535 "wcversion", G_TYPE_INT, 3 - AV_CODEC_ID_XAN_WC3 + codec_id, NULL);
1538 case AV_CODEC_ID_CLJR:
1540 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1541 "video/x-cirrus-logic-accupak", NULL);
1544 case AV_CODEC_ID_FRAPS:
1546 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-fraps",
1550 case AV_CODEC_ID_MDEC:
1551 case AV_CODEC_ID_ROQ:
1552 case AV_CODEC_ID_INTERPLAY_VIDEO:
1556 case AV_CODEC_ID_VCR1:
1558 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1559 "video/x-ati-vcr", "vcrversion", G_TYPE_INT, 1, NULL);
1562 case AV_CODEC_ID_RPZA:
1564 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1565 "video/x-apple-video", NULL);
1568 case AV_CODEC_ID_CINEPAK:
1570 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1571 "video/x-cinepak", NULL);
1574 /* WS_VQA belogns here (order) */
1576 case AV_CODEC_ID_MSRLE:
1578 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-rle",
1579 "layout", G_TYPE_STRING, "microsoft", NULL);
1581 gst_caps_set_simple (caps,
1582 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1584 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1588 case AV_CODEC_ID_QTRLE:
1590 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-rle",
1591 "layout", G_TYPE_STRING, "quicktime", NULL);
1593 gst_caps_set_simple (caps,
1594 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1596 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 1, 64, NULL);
1600 case AV_CODEC_ID_MSVIDEO1:
1602 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1603 "video/x-msvideocodec", "msvideoversion", G_TYPE_INT, 1, NULL);
1606 case AV_CODEC_ID_MSS1:
1608 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1609 "wmvversion", G_TYPE_INT, 1, "format", G_TYPE_STRING, "MSS1", NULL);
1612 case AV_CODEC_ID_MSS2:
1614 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1615 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "MSS2", NULL);
1618 case AV_CODEC_ID_WMV3:
1620 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1621 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "WMV3", NULL);
1623 case AV_CODEC_ID_VC1:
1625 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-wmv",
1626 "wmvversion", G_TYPE_INT, 3, NULL);
1627 if (!context && !encode) {
1628 GValue arr = { 0, };
1629 GValue item = { 0, };
1631 g_value_init (&arr, GST_TYPE_LIST);
1632 g_value_init (&item, G_TYPE_STRING);
1633 g_value_set_string (&item, "WVC1");
1634 gst_value_list_append_value (&arr, &item);
1635 g_value_set_string (&item, "WMVA");
1636 gst_value_list_append_and_take_value (&arr, &item);
1637 gst_caps_set_value (caps, "format", &arr);
1638 g_value_unset (&arr);
1640 gst_caps_set_simple (caps, "format", G_TYPE_STRING, "WVC1", NULL);
1643 case AV_CODEC_ID_QDM2:
1645 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-qdm2",
1649 case AV_CODEC_ID_MSZH:
1651 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-mszh",
1655 case AV_CODEC_ID_ZLIB:
1657 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-zlib",
1661 case AV_CODEC_ID_TRUEMOTION1:
1663 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1664 "video/x-truemotion", "trueversion", G_TYPE_INT, 1, NULL);
1666 case AV_CODEC_ID_TRUEMOTION2:
1668 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1669 "video/x-truemotion", "trueversion", G_TYPE_INT, 2, NULL);
1672 case AV_CODEC_ID_ULTI:
1674 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1675 "video/x-ultimotion", NULL);
1678 case AV_CODEC_ID_TSCC:
1680 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1681 "video/x-camtasia", NULL);
1683 gst_caps_set_simple (caps,
1684 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1686 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1690 case AV_CODEC_ID_TSCC2:
1692 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1693 "video/x-tscc", "tsccversion", G_TYPE_INT, 2, NULL);
1696 case AV_CODEC_ID_KMVC:
1698 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-kmvc",
1702 case AV_CODEC_ID_NUV:
1704 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-nuv",
1708 case AV_CODEC_ID_GIF:
1710 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1711 "image/gst-libav-gif", "parsed", G_TYPE_BOOLEAN, TRUE, NULL);
1714 case AV_CODEC_ID_PNG:
1716 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/png",
1720 case AV_CODEC_ID_PPM:
1722 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/ppm",
1726 case AV_CODEC_ID_PBM:
1728 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/pbm",
1732 case AV_CODEC_ID_PAM:
1734 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1735 "image/x-portable-anymap", NULL);
1738 case AV_CODEC_ID_PGM:
1740 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1741 "image/x-portable-graymap", NULL);
1744 case AV_CODEC_ID_PCX:
1746 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-pcx",
1750 case AV_CODEC_ID_SGI:
1752 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-sgi",
1756 case AV_CODEC_ID_TARGA:
1758 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/x-tga",
1762 case AV_CODEC_ID_TIFF:
1764 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "image/tiff",
1768 case AV_CODEC_ID_SUNRAST:
1770 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1771 "image/x-sun-raster", NULL);
1774 case AV_CODEC_ID_SMC:
1776 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-smc",
1780 case AV_CODEC_ID_QDRAW:
1782 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-qdrw",
1786 case AV_CODEC_ID_DNXHD:
1788 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-dnxhd",
1792 case AV_CODEC_ID_PRORES:
1794 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1795 "video/x-prores", NULL);
1797 switch (context->codec_tag) {
1798 case GST_MAKE_FOURCC ('a', 'p', 'c', 'o'):
1799 gst_caps_set_simple (caps, "variant", G_TYPE_STRING, "proxy", NULL);
1801 case GST_MAKE_FOURCC ('a', 'p', 'c', 's'):
1802 gst_caps_set_simple (caps, "variant", G_TYPE_STRING, "lt", NULL);
1805 case GST_MAKE_FOURCC ('a', 'p', 'c', 'n'):
1806 gst_caps_set_simple (caps, "variant", G_TYPE_STRING, "standard",
1809 case GST_MAKE_FOURCC ('a', 'p', 'c', 'h'):
1810 gst_caps_set_simple (caps, "variant", G_TYPE_STRING, "hq", NULL);
1812 case GST_MAKE_FOURCC ('a', 'p', '4', 'h'):
1813 gst_caps_set_simple (caps, "variant", G_TYPE_STRING, "4444", NULL);
1815 case GST_MAKE_FOURCC ('a', 'p', '4', 'x'):
1816 gst_caps_set_simple (caps, "variant", G_TYPE_STRING, "4444xq",
1823 case AV_CODEC_ID_MIMIC:
1825 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-mimic",
1829 case AV_CODEC_ID_VMNC:
1831 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-vmnc",
1835 case AV_CODEC_ID_TRUESPEECH:
1837 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
1838 "audio/x-truespeech", NULL);
1841 case AV_CODEC_ID_QCELP:
1843 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/qcelp",
1847 case AV_CODEC_ID_AMV:
1849 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-amv",
1853 case AV_CODEC_ID_AASC:
1855 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-aasc",
1859 case AV_CODEC_ID_LOCO:
1861 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-loco",
1865 case AV_CODEC_ID_ZMBV:
1867 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-zmbv",
1871 case AV_CODEC_ID_LAGARITH:
1873 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1874 "video/x-lagarith", NULL);
1877 case AV_CODEC_ID_CSCD:
1879 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1880 "video/x-camstudio", NULL);
1882 gst_caps_set_simple (caps,
1883 "depth", G_TYPE_INT, (gint) context->bits_per_coded_sample, NULL);
1885 gst_caps_set_simple (caps, "depth", GST_TYPE_INT_RANGE, 8, 32, NULL);
1889 case AV_CODEC_ID_AIC:
1891 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1892 "video/x-apple-intermediate-codec", NULL);
1895 case AV_CODEC_ID_CAVS:
1897 gst_ff_vid_caps_new (context, NULL, codec_id, encode,
1898 "video/x-cavs", NULL);
1901 case AV_CODEC_ID_WS_VQA:
1902 case AV_CODEC_ID_IDCIN:
1903 case AV_CODEC_ID_8BPS:
1904 case AV_CODEC_ID_FLIC:
1905 case AV_CODEC_ID_VMDVIDEO:
1906 case AV_CODEC_ID_VMDAUDIO:
1907 case AV_CODEC_ID_VIXL:
1908 case AV_CODEC_ID_QPEG:
1909 case AV_CODEC_ID_PGMYUV:
1910 case AV_CODEC_ID_FFVHUFF:
1911 case AV_CODEC_ID_WNV1:
1912 case AV_CODEC_ID_MP3ADU:
1913 case AV_CODEC_ID_MP3ON4:
1914 case AV_CODEC_ID_WESTWOOD_SND1:
1915 case AV_CODEC_ID_MMVIDEO:
1916 case AV_CODEC_ID_AVS:
1920 /* weird quasi-codecs for the demuxers only */
1921 case AV_CODEC_ID_PCM_S16LE:
1922 case AV_CODEC_ID_PCM_S16BE:
1923 case AV_CODEC_ID_PCM_U16LE:
1924 case AV_CODEC_ID_PCM_U16BE:
1925 case AV_CODEC_ID_PCM_S8:
1926 case AV_CODEC_ID_PCM_U8:
1928 GstAudioFormat format;
1931 case AV_CODEC_ID_PCM_S16LE:
1932 format = GST_AUDIO_FORMAT_S16LE;
1934 case AV_CODEC_ID_PCM_S16BE:
1935 format = GST_AUDIO_FORMAT_S16BE;
1937 case AV_CODEC_ID_PCM_U16LE:
1938 format = GST_AUDIO_FORMAT_U16LE;
1940 case AV_CODEC_ID_PCM_U16BE:
1941 format = GST_AUDIO_FORMAT_U16BE;
1943 case AV_CODEC_ID_PCM_S8:
1944 format = GST_AUDIO_FORMAT_S8;
1946 case AV_CODEC_ID_PCM_U8:
1947 format = GST_AUDIO_FORMAT_U8;
1951 g_assert (0); /* don't worry, we never get here */
1956 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-raw",
1957 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
1958 "layout", G_TYPE_STRING, "interleaved", NULL);
1962 case AV_CODEC_ID_PCM_MULAW:
1964 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-mulaw",
1968 case AV_CODEC_ID_PCM_ALAW:
1970 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-alaw",
1974 case AV_CODEC_ID_ADPCM_G722:
1976 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/G722",
1979 gst_caps_set_simple (caps,
1980 "block_align", G_TYPE_INT, context->block_align,
1981 "bitrate", G_TYPE_INT, (guint) context->bit_rate, NULL);
1984 case AV_CODEC_ID_ADPCM_G726:
1986 /* the G726 decoder can also handle G721 */
1988 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-adpcm",
1989 "layout", G_TYPE_STRING, "g726", NULL);
1991 gst_caps_set_simple (caps,
1992 "block_align", G_TYPE_INT, context->block_align,
1993 "bitrate", G_TYPE_INT, (guint) context->bit_rate, NULL);
1996 gst_caps_append (caps, gst_caps_new_simple ("audio/x-adpcm",
1997 "layout", G_TYPE_STRING, "g721",
1998 "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, 8000, NULL));
2002 case AV_CODEC_ID_ADPCM_IMA_QT:
2003 case AV_CODEC_ID_ADPCM_IMA_WAV:
2004 case AV_CODEC_ID_ADPCM_IMA_DK3:
2005 case AV_CODEC_ID_ADPCM_IMA_DK4:
2006 case AV_CODEC_ID_ADPCM_IMA_OKI:
2007 case AV_CODEC_ID_ADPCM_IMA_WS:
2008 case AV_CODEC_ID_ADPCM_IMA_SMJPEG:
2009 case AV_CODEC_ID_ADPCM_IMA_AMV:
2010 case AV_CODEC_ID_ADPCM_IMA_ISS:
2011 case AV_CODEC_ID_ADPCM_IMA_EA_EACS:
2012 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
2013 case AV_CODEC_ID_ADPCM_MS:
2014 case AV_CODEC_ID_ADPCM_4XM:
2015 case AV_CODEC_ID_ADPCM_XA:
2016 case AV_CODEC_ID_ADPCM_ADX:
2017 case AV_CODEC_ID_ADPCM_EA:
2018 case AV_CODEC_ID_ADPCM_CT:
2019 case AV_CODEC_ID_ADPCM_SWF:
2020 case AV_CODEC_ID_ADPCM_YAMAHA:
2021 case AV_CODEC_ID_ADPCM_SBPRO_2:
2022 case AV_CODEC_ID_ADPCM_SBPRO_3:
2023 case AV_CODEC_ID_ADPCM_SBPRO_4:
2024 case AV_CODEC_ID_ADPCM_EA_R1:
2025 case AV_CODEC_ID_ADPCM_EA_R2:
2026 case AV_CODEC_ID_ADPCM_EA_R3:
2027 case AV_CODEC_ID_ADPCM_EA_MAXIS_XA:
2028 case AV_CODEC_ID_ADPCM_EA_XAS:
2029 case AV_CODEC_ID_ADPCM_THP:
2031 const gchar *layout = NULL;
2034 case AV_CODEC_ID_ADPCM_IMA_QT:
2035 layout = "quicktime";
2037 case AV_CODEC_ID_ADPCM_IMA_WAV:
2040 case AV_CODEC_ID_ADPCM_IMA_DK3:
2043 case AV_CODEC_ID_ADPCM_IMA_DK4:
2046 case AV_CODEC_ID_ADPCM_IMA_OKI:
2049 case AV_CODEC_ID_ADPCM_IMA_WS:
2050 layout = "westwood";
2052 case AV_CODEC_ID_ADPCM_IMA_SMJPEG:
2055 case AV_CODEC_ID_ADPCM_IMA_AMV:
2058 case AV_CODEC_ID_ADPCM_IMA_ISS:
2061 case AV_CODEC_ID_ADPCM_IMA_EA_EACS:
2064 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
2067 case AV_CODEC_ID_ADPCM_MS:
2068 layout = "microsoft";
2070 case AV_CODEC_ID_ADPCM_4XM:
2073 case AV_CODEC_ID_ADPCM_XA:
2076 case AV_CODEC_ID_ADPCM_ADX:
2079 case AV_CODEC_ID_ADPCM_EA:
2082 case AV_CODEC_ID_ADPCM_CT:
2085 case AV_CODEC_ID_ADPCM_SWF:
2088 case AV_CODEC_ID_ADPCM_YAMAHA:
2091 case AV_CODEC_ID_ADPCM_SBPRO_2:
2094 case AV_CODEC_ID_ADPCM_SBPRO_3:
2097 case AV_CODEC_ID_ADPCM_SBPRO_4:
2100 case AV_CODEC_ID_ADPCM_EA_R1:
2103 case AV_CODEC_ID_ADPCM_EA_R2:
2106 case AV_CODEC_ID_ADPCM_EA_R3:
2109 case AV_CODEC_ID_ADPCM_EA_MAXIS_XA:
2110 layout = "ea-maxis-xa";
2112 case AV_CODEC_ID_ADPCM_EA_XAS:
2115 case AV_CODEC_ID_ADPCM_THP:
2119 g_assert (0); /* don't worry, we never get here */
2123 /* FIXME: someone please check whether we need additional properties
2124 * in this caps definition. */
2126 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-adpcm",
2127 "layout", G_TYPE_STRING, layout, NULL);
2129 gst_caps_set_simple (caps,
2130 "block_align", G_TYPE_INT, context->block_align,
2131 "bitrate", G_TYPE_INT, (guint) context->bit_rate, NULL);
2135 case AV_CODEC_ID_AMR_NB:
2137 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/AMR",
2141 case AV_CODEC_ID_AMR_WB:
2143 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/AMR-WB",
2147 case AV_CODEC_ID_GSM:
2149 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-gsm",
2153 case AV_CODEC_ID_GSM_MS:
2155 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/ms-gsm",
2159 case AV_CODEC_ID_NELLYMOSER:
2161 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
2162 "audio/x-nellymoser", NULL);
2165 case AV_CODEC_ID_SIPR:
2168 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-sipro",
2171 gst_caps_set_simple (caps,
2172 "leaf_size", G_TYPE_INT, context->block_align,
2173 "bitrate", G_TYPE_INT, (guint) context->bit_rate, NULL);
2178 case AV_CODEC_ID_RA_144:
2179 case AV_CODEC_ID_RA_288:
2180 case AV_CODEC_ID_COOK:
2185 case AV_CODEC_ID_RA_144:
2188 case AV_CODEC_ID_RA_288:
2191 case AV_CODEC_ID_COOK:
2198 /* FIXME: properties? */
2200 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
2201 "audio/x-pn-realaudio", "raversion", G_TYPE_INT, version, NULL);
2203 gst_caps_set_simple (caps,
2204 "leaf_size", G_TYPE_INT, context->block_align,
2205 "bitrate", G_TYPE_INT, (guint) context->bit_rate, NULL);
2210 case AV_CODEC_ID_ROQ_DPCM:
2211 case AV_CODEC_ID_INTERPLAY_DPCM:
2212 case AV_CODEC_ID_XAN_DPCM:
2213 case AV_CODEC_ID_SOL_DPCM:
2215 const gchar *layout = NULL;
2218 case AV_CODEC_ID_ROQ_DPCM:
2221 case AV_CODEC_ID_INTERPLAY_DPCM:
2222 layout = "interplay";
2224 case AV_CODEC_ID_XAN_DPCM:
2227 case AV_CODEC_ID_SOL_DPCM:
2231 g_assert (0); /* don't worry, we never get here */
2235 /* FIXME: someone please check whether we need additional properties
2236 * in this caps definition. */
2238 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dpcm",
2239 "layout", G_TYPE_STRING, layout, NULL);
2241 gst_caps_set_simple (caps,
2242 "block_align", G_TYPE_INT, context->block_align,
2243 "bitrate", G_TYPE_INT, (guint) context->bit_rate, NULL);
2247 case AV_CODEC_ID_SHORTEN:
2248 caps = gst_caps_new_empty_simple ("audio/x-shorten");
2251 case AV_CODEC_ID_ALAC:
2253 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-alac",
2256 gst_caps_set_simple (caps,
2257 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
2261 case AV_CODEC_ID_FLAC:
2262 /* Note that ffmpeg has no encoder yet, but just for safety. In the
2263 * encoder case, we want to add things like samplerate, channels... */
2265 caps = gst_caps_new_empty_simple ("audio/x-flac");
2269 case AV_CODEC_ID_OPUS:
2270 /* Note that ffmpeg has no encoder yet, but just for safety. In the
2271 * encoder case, we want to add things like samplerate, channels... */
2273 /* FIXME: can ffmpeg handle multichannel Opus? */
2274 caps = gst_caps_new_simple ("audio/x-opus",
2275 "channel-mapping-family", G_TYPE_INT, 0, NULL);
2279 case AV_CODEC_ID_S302M:
2280 caps = gst_caps_new_empty_simple ("audio/x-smpte-302m");
2283 case AV_CODEC_ID_DVD_SUBTITLE:
2284 case AV_CODEC_ID_DVB_SUBTITLE:
2287 case AV_CODEC_ID_BMP:
2288 caps = gst_caps_new_empty_simple ("image/bmp");
2290 case AV_CODEC_ID_TTA:
2292 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-tta",
2295 gst_caps_set_simple (caps,
2296 "samplesize", G_TYPE_INT, context->bits_per_coded_sample, NULL);
2299 case AV_CODEC_ID_TWINVQ:
2301 gst_ff_aud_caps_new (context, NULL, codec_id, encode,
2302 "audio/x-twin-vq", NULL);
2304 case AV_CODEC_ID_G729:
2306 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/G729",
2309 case AV_CODEC_ID_DSD_LSBF:
2311 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dsd",
2313 gst_caps_set_simple (caps, "lsbf", G_TYPE_BOOLEAN,
2314 TRUE, "planar", G_TYPE_BOOLEAN, FALSE, NULL);
2316 case AV_CODEC_ID_DSD_MSBF:
2318 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dsd",
2320 gst_caps_set_simple (caps, "lsbf", G_TYPE_BOOLEAN,
2321 FALSE, "planar", G_TYPE_BOOLEAN, FALSE, NULL);
2323 case AV_CODEC_ID_DSD_LSBF_PLANAR:
2325 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dsd",
2327 gst_caps_set_simple (caps, "lsbf", G_TYPE_BOOLEAN,
2328 TRUE, "planar", G_TYPE_BOOLEAN, TRUE, NULL);
2330 case AV_CODEC_ID_DSD_MSBF_PLANAR:
2332 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/x-dsd",
2334 gst_caps_set_simple (caps, "lsbf", G_TYPE_BOOLEAN,
2335 FALSE, "planar", G_TYPE_BOOLEAN, TRUE, NULL);
2337 case AV_CODEC_ID_APTX:
2339 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/aptx",
2342 case AV_CODEC_ID_APTX_HD:
2344 gst_ff_aud_caps_new (context, NULL, codec_id, encode, "audio/aptx-hd",
2347 case AV_CODEC_ID_AV1:
2349 gst_ff_vid_caps_new (context, NULL, codec_id, encode, "video/x-av1",
2353 GST_DEBUG ("Unknown codec ID %d, please add mapping here", codec_id);
2358 const AVCodec *codec;
2360 if ((codec = avcodec_find_decoder (codec_id)) ||
2361 (codec = avcodec_find_encoder (codec_id))) {
2364 GST_LOG ("Could not create stream format caps for %s", codec->name);
2366 switch (codec->type) {
2367 case AVMEDIA_TYPE_VIDEO:
2368 mime = g_strdup_printf ("video/x-gst-av-%s", codec->name);
2370 gst_ff_vid_caps_new (context, NULL, codec_id, encode, mime, NULL);
2373 case AVMEDIA_TYPE_AUDIO:
2374 mime = g_strdup_printf ("audio/x-gst-av-%s", codec->name);
2376 gst_ff_aud_caps_new (context, NULL, codec_id, encode, mime, NULL);
2378 gst_caps_set_simple (caps,
2379 "block_align", G_TYPE_INT, context->block_align,
2380 "bitrate", G_TYPE_INT, (guint) context->bit_rate, NULL);
2391 /* set private data */
2392 if (context && context->extradata_size > 0) {
2393 GstBuffer *data = gst_buffer_new_and_alloc (context->extradata_size);
2395 gst_buffer_fill (data, 0, context->extradata, context->extradata_size);
2396 gst_caps_set_simple (caps, "codec_data", GST_TYPE_BUFFER, data, NULL);
2397 gst_buffer_unref (data);
2400 GST_LOG ("caps for codec_id=%d: %" GST_PTR_FORMAT, codec_id, caps);
2403 GST_LOG ("No caps found for codec_id=%d", codec_id);
2409 /* Convert a FFMPEG Pixel Format and optional AVCodecContext
2410 * to a GstCaps. If the context is ommitted, no fixed values
2411 * for video/audio size will be included in the GstCaps
2413 * See below for usefullness
2417 gst_ffmpeg_pixfmt_to_caps (enum AVPixelFormat pix_fmt, AVCodecContext * context,
2418 enum AVCodecID codec_id)
2420 GstCaps *caps = NULL;
2421 GstVideoFormat format;
2423 format = gst_ffmpeg_pixfmt_to_videoformat (pix_fmt);
2425 if (format != GST_VIDEO_FORMAT_UNKNOWN) {
2426 caps = gst_ff_vid_caps_new (context, NULL, codec_id, TRUE, "video/x-raw",
2427 "format", G_TYPE_STRING, gst_video_format_to_string (format), NULL);
2431 GST_DEBUG ("caps for pix_fmt=%d: %" GST_PTR_FORMAT, pix_fmt, caps);
2433 GST_LOG ("No caps found for pix_fmt=%d", pix_fmt);
2440 gst_ffmpeg_smpfmt_to_audioformat (enum AVSampleFormat sample_fmt,
2441 GstAudioLayout * layout)
2444 *layout = GST_AUDIO_LAYOUT_NON_INTERLEAVED;
2446 switch (sample_fmt) {
2447 case AV_SAMPLE_FMT_U8:
2449 *layout = GST_AUDIO_LAYOUT_INTERLEAVED;
2450 case AV_SAMPLE_FMT_U8P:
2451 return GST_AUDIO_FORMAT_U8;
2454 case AV_SAMPLE_FMT_S16:
2456 *layout = GST_AUDIO_LAYOUT_INTERLEAVED;
2457 case AV_SAMPLE_FMT_S16P:
2458 return GST_AUDIO_FORMAT_S16;
2461 case AV_SAMPLE_FMT_S32:
2463 *layout = GST_AUDIO_LAYOUT_INTERLEAVED;
2464 case AV_SAMPLE_FMT_S32P:
2465 return GST_AUDIO_FORMAT_S32;
2467 case AV_SAMPLE_FMT_FLT:
2469 *layout = GST_AUDIO_LAYOUT_INTERLEAVED;
2470 case AV_SAMPLE_FMT_FLTP:
2471 return GST_AUDIO_FORMAT_F32;
2474 case AV_SAMPLE_FMT_DBL:
2476 *layout = GST_AUDIO_LAYOUT_INTERLEAVED;
2477 case AV_SAMPLE_FMT_DBLP:
2478 return GST_AUDIO_FORMAT_F64;
2483 return GST_AUDIO_FORMAT_UNKNOWN;
2488 /* Convert a FFMPEG Sample Format and optional AVCodecContext
2489 * to a GstCaps. If the context is ommitted, no fixed values
2490 * for video/audio size will be included in the GstCaps
2492 * See below for usefullness
2496 gst_ffmpeg_smpfmt_to_caps (enum AVSampleFormat sample_fmt,
2497 AVCodecContext * context, AVCodec * codec, enum AVCodecID codec_id)
2499 GstCaps *caps = NULL;
2500 GstAudioFormat format;
2501 GstAudioLayout layout;
2503 format = gst_ffmpeg_smpfmt_to_audioformat (sample_fmt, &layout);
2505 if (format != GST_AUDIO_FORMAT_UNKNOWN) {
2506 caps = gst_ff_aud_caps_new (context, codec, codec_id, TRUE, "audio/x-raw",
2507 "format", G_TYPE_STRING, gst_audio_format_to_string (format),
2508 "layout", G_TYPE_STRING,
2509 (layout == GST_AUDIO_LAYOUT_INTERLEAVED) ?
2510 "interleaved" : "non-interleaved", NULL);
2511 GST_LOG ("caps for sample_fmt=%d: %" GST_PTR_FORMAT, sample_fmt, caps);
2513 GST_LOG ("No caps found for sample_fmt=%d", sample_fmt);
2520 caps_has_field (GstCaps * caps, const gchar * field)
2524 n = gst_caps_get_size (caps);
2525 for (i = 0; i < n; i++) {
2526 GstStructure *s = gst_caps_get_structure (caps, i);
2528 if (gst_structure_has_field (s, field))
2536 gst_ffmpeg_codectype_to_audio_caps (AVCodecContext * context,
2537 enum AVCodecID codec_id, gboolean encode, AVCodec * codec)
2539 GstCaps *caps = NULL;
2541 GST_DEBUG ("context:%p, codec_id:%d, encode:%d, codec:%p",
2542 context, codec_id, encode, codec);
2544 GST_DEBUG ("sample_fmts:%p, samplerates:%p",
2545 codec->sample_fmts, codec->supported_samplerates);
2548 /* Specific codec context */
2550 gst_ffmpeg_smpfmt_to_caps (context->sample_fmt, context, codec,
2553 caps = gst_ff_aud_caps_new (context, codec, codec_id, encode, "audio/x-raw",
2555 if (!caps_has_field (caps, "format"))
2556 gst_ffmpeg_audio_set_sample_fmts (caps,
2557 codec ? codec->sample_fmts : NULL, encode);
2564 gst_ffmpeg_codectype_to_video_caps (AVCodecContext * context,
2565 enum AVCodecID codec_id, gboolean encode, const AVCodec * codec)
2569 GST_LOG ("context:%p, codec_id:%d, encode:%d, codec:%p",
2570 context, codec_id, encode, codec);
2573 caps = gst_ffmpeg_pixfmt_to_caps (context->pix_fmt, context, codec_id);
2576 gst_ff_vid_caps_new (context, codec, codec_id, encode, "video/x-raw",
2578 if (!caps_has_field (caps, "format"))
2579 gst_ffmpeg_video_set_pix_fmts (caps, codec ? codec->pix_fmts : NULL);
2584 /* Convert a GstCaps (audio/raw) to a FFMPEG SampleFmt
2585 * and other audio properties in a AVCodecContext.
2587 * For usefullness, see below
2591 gst_ffmpeg_caps_to_smpfmt (const GstCaps * caps,
2592 AVCodecContext * context, gboolean raw)
2594 GstStructure *structure;
2596 GstAudioFormat format = GST_AUDIO_FORMAT_UNKNOWN;
2598 const gchar *layout;
2599 gboolean interleaved;
2601 g_return_if_fail (gst_caps_get_size (caps) == 1);
2603 structure = gst_caps_get_structure (caps, 0);
2605 gst_structure_get_int (structure, "channels", &context->channels);
2606 gst_structure_get_int (structure, "rate", &context->sample_rate);
2607 gst_structure_get_int (structure, "block_align", &context->block_align);
2608 if (gst_structure_get_int (structure, "bitrate", &bitrate))
2609 context->bit_rate = bitrate;
2614 if (gst_structure_has_name (structure, "audio/x-raw")) {
2615 if ((fmt = gst_structure_get_string (structure, "format"))) {
2616 format = gst_audio_format_from_string (fmt);
2620 layout = gst_structure_get_string (structure, "layout");
2621 interleaved = ! !g_strcmp0 (layout, "non-interleaved");
2624 case GST_AUDIO_FORMAT_F32:
2625 context->sample_fmt =
2626 interleaved ? AV_SAMPLE_FMT_FLT : AV_SAMPLE_FMT_FLTP;
2628 case GST_AUDIO_FORMAT_F64:
2629 context->sample_fmt =
2630 interleaved ? AV_SAMPLE_FMT_DBL : AV_SAMPLE_FMT_DBLP;
2632 case GST_AUDIO_FORMAT_S32:
2633 context->sample_fmt =
2634 interleaved ? AV_SAMPLE_FMT_S32 : AV_SAMPLE_FMT_S32P;
2636 case GST_AUDIO_FORMAT_S16:
2637 context->sample_fmt =
2638 interleaved ? AV_SAMPLE_FMT_S16 : AV_SAMPLE_FMT_S16P;
2645 /* Convert a GstCaps (video/raw) to a FFMPEG PixFmt
2646 * and other video properties in a AVCodecContext.
2648 * For usefullness, see below
2652 gst_ffmpeg_caps_to_pixfmt (const GstCaps * caps,
2653 AVCodecContext * context, gboolean raw)
2655 GstStructure *structure;
2657 const GValue *par = NULL;
2659 GstVideoFormat format = GST_VIDEO_FORMAT_UNKNOWN;
2662 GST_DEBUG ("converting caps %" GST_PTR_FORMAT, caps);
2663 g_return_if_fail (gst_caps_get_size (caps) == 1);
2664 structure = gst_caps_get_structure (caps, 0);
2666 gst_structure_get_int (structure, "width", &context->width);
2667 gst_structure_get_int (structure, "height", &context->height);
2668 gst_structure_get_int (structure, "bpp", &context->bits_per_coded_sample);
2670 fps = gst_structure_get_value (structure, "framerate");
2671 if (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps)) {
2673 int num = gst_value_get_fraction_numerator (fps);
2674 int den = gst_value_get_fraction_denominator (fps);
2676 if (num > 0 && den > 0) {
2677 /* somehow these seem mixed up.. */
2678 /* they're fine, this is because it does period=1/frequency */
2679 context->time_base.den = gst_value_get_fraction_numerator (fps);
2680 context->time_base.num = gst_value_get_fraction_denominator (fps);
2681 context->ticks_per_frame = 1;
2683 GST_DEBUG ("setting framerate %d/%d = %lf",
2684 context->time_base.den, context->time_base.num,
2685 1. * context->time_base.den / context->time_base.num);
2687 GST_INFO ("ignoring framerate %d/%d (probably variable framerate)",
2688 context->time_base.num, context->time_base.den);
2692 par = gst_structure_get_value (structure, "pixel-aspect-ratio");
2693 if (par && GST_VALUE_HOLDS_FRACTION (par)) {
2695 int num = gst_value_get_fraction_numerator (par);
2696 int den = gst_value_get_fraction_denominator (par);
2698 if (num > 0 && den > 0) {
2699 context->sample_aspect_ratio.num = num;
2700 context->sample_aspect_ratio.den = den;
2702 GST_DEBUG ("setting pixel-aspect-ratio %d/%d = %lf",
2703 context->sample_aspect_ratio.num, context->sample_aspect_ratio.den,
2704 1. * context->sample_aspect_ratio.num /
2705 context->sample_aspect_ratio.den);
2707 GST_WARNING ("ignoring insane pixel-aspect-ratio %d/%d",
2708 context->sample_aspect_ratio.num, context->sample_aspect_ratio.den);
2715 g_return_if_fail (fps != NULL && GST_VALUE_HOLDS_FRACTION (fps));
2717 if (gst_structure_has_name (structure, "video/x-raw")) {
2718 if ((fmt = gst_structure_get_string (structure, "format"))) {
2719 format = gst_video_format_from_string (fmt);
2724 case GST_VIDEO_FORMAT_YUY2:
2725 context->pix_fmt = AV_PIX_FMT_YUYV422;
2727 case GST_VIDEO_FORMAT_I420:
2728 context->pix_fmt = AV_PIX_FMT_YUV420P;
2730 case GST_VIDEO_FORMAT_A420:
2731 context->pix_fmt = AV_PIX_FMT_YUVA420P;
2733 case GST_VIDEO_FORMAT_Y41B:
2734 context->pix_fmt = AV_PIX_FMT_YUV411P;
2736 case GST_VIDEO_FORMAT_Y42B:
2737 context->pix_fmt = AV_PIX_FMT_YUV422P;
2739 case GST_VIDEO_FORMAT_YUV9:
2740 context->pix_fmt = AV_PIX_FMT_YUV410P;
2742 case GST_VIDEO_FORMAT_Y444:
2743 context->pix_fmt = AV_PIX_FMT_YUV444P;
2745 case GST_VIDEO_FORMAT_GRAY8:
2746 context->pix_fmt = AV_PIX_FMT_GRAY8;
2748 case GST_VIDEO_FORMAT_xRGB:
2749 #if (G_BYTE_ORDER == G_BIG_ENDIAN)
2750 context->pix_fmt = AV_PIX_FMT_RGB32;
2753 case GST_VIDEO_FORMAT_BGRx:
2754 #if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
2755 context->pix_fmt = AV_PIX_FMT_RGB32;
2758 case GST_VIDEO_FORMAT_RGB:
2759 context->pix_fmt = AV_PIX_FMT_RGB24;
2761 case GST_VIDEO_FORMAT_BGR:
2762 context->pix_fmt = AV_PIX_FMT_BGR24;
2764 case GST_VIDEO_FORMAT_RGB16:
2765 context->pix_fmt = AV_PIX_FMT_RGB565;
2767 case GST_VIDEO_FORMAT_RGB15:
2768 context->pix_fmt = AV_PIX_FMT_RGB555;
2770 case GST_VIDEO_FORMAT_RGB8P:
2771 context->pix_fmt = AV_PIX_FMT_PAL8;
2777 s = gst_structure_get_string (structure, "interlace-mode");
2779 if (strcmp (s, "progressive") == 0) {
2780 context->field_order = AV_FIELD_PROGRESSIVE;
2781 } else if (strcmp (s, "interleaved") == 0) {
2782 s = gst_structure_get_string (structure, "field-order");
2784 if (strcmp (s, "top-field-first") == 0) {
2785 context->field_order = AV_FIELD_TT;
2786 } else if (strcmp (s, "bottom-field-first") == 0) {
2787 context->field_order = AV_FIELD_TB;
2796 GstVideoFormat format;
2797 enum AVPixelFormat pixfmt;
2800 /* FIXME : FILLME */
2801 static const PixToFmt pixtofmttable[] = {
2802 /* GST_VIDEO_FORMAT_I420, */
2803 {GST_VIDEO_FORMAT_I420, AV_PIX_FMT_YUV420P},
2804 /* Note : this should use a different chroma placement */
2805 {GST_VIDEO_FORMAT_I420, AV_PIX_FMT_YUVJ420P},
2807 /* GST_VIDEO_FORMAT_YV12, */
2808 /* GST_VIDEO_FORMAT_YUY2, */
2809 {GST_VIDEO_FORMAT_YUY2, AV_PIX_FMT_YUYV422},
2810 /* GST_VIDEO_FORMAT_UYVY, */
2811 {GST_VIDEO_FORMAT_UYVY, AV_PIX_FMT_UYVY422},
2812 /* GST_VIDEO_FORMAT_AYUV, */
2813 /* GST_VIDEO_FORMAT_RGBx, */
2814 {GST_VIDEO_FORMAT_RGBx, AV_PIX_FMT_RGB0},
2815 /* GST_VIDEO_FORMAT_BGRx, */
2816 {GST_VIDEO_FORMAT_BGRx, AV_PIX_FMT_BGR0},
2817 /* GST_VIDEO_FORMAT_xRGB, */
2818 {GST_VIDEO_FORMAT_xRGB, AV_PIX_FMT_0RGB},
2819 /* GST_VIDEO_FORMAT_xBGR, */
2820 {GST_VIDEO_FORMAT_xBGR, AV_PIX_FMT_0BGR},
2821 /* GST_VIDEO_FORMAT_RGBA, */
2822 {GST_VIDEO_FORMAT_RGBA, AV_PIX_FMT_RGBA},
2823 /* GST_VIDEO_FORMAT_BGRA, */
2824 {GST_VIDEO_FORMAT_BGRA, AV_PIX_FMT_BGRA},
2825 /* GST_VIDEO_FORMAT_ARGB, */
2826 {GST_VIDEO_FORMAT_ARGB, AV_PIX_FMT_ARGB},
2827 /* GST_VIDEO_FORMAT_ABGR, */
2828 {GST_VIDEO_FORMAT_ABGR, AV_PIX_FMT_ABGR},
2829 /* GST_VIDEO_FORMAT_RGB, */
2830 {GST_VIDEO_FORMAT_RGB, AV_PIX_FMT_RGB24},
2831 /* GST_VIDEO_FORMAT_BGR, */
2832 {GST_VIDEO_FORMAT_BGR, AV_PIX_FMT_BGR24},
2833 /* GST_VIDEO_FORMAT_Y41B, */
2834 {GST_VIDEO_FORMAT_Y41B, AV_PIX_FMT_YUV411P},
2835 /* GST_VIDEO_FORMAT_Y42B, */
2836 {GST_VIDEO_FORMAT_Y42B, AV_PIX_FMT_YUV422P},
2837 {GST_VIDEO_FORMAT_Y42B, AV_PIX_FMT_YUVJ422P},
2838 /* GST_VIDEO_FORMAT_YVYU, */
2839 /* GST_VIDEO_FORMAT_Y444, */
2840 {GST_VIDEO_FORMAT_Y444, AV_PIX_FMT_YUV444P},
2841 {GST_VIDEO_FORMAT_Y444, AV_PIX_FMT_YUVJ444P},
2842 /* GST_VIDEO_FORMAT_v210, */
2843 /* GST_VIDEO_FORMAT_v216, */
2844 /* GST_VIDEO_FORMAT_NV12, */
2845 {GST_VIDEO_FORMAT_NV12, AV_PIX_FMT_NV12},
2846 /* GST_VIDEO_FORMAT_NV21, */
2847 {GST_VIDEO_FORMAT_NV21, AV_PIX_FMT_NV21},
2848 /* GST_VIDEO_FORMAT_GRAY8, */
2849 {GST_VIDEO_FORMAT_GRAY8, AV_PIX_FMT_GRAY8},
2850 /* GST_VIDEO_FORMAT_GRAY16_BE, */
2851 {GST_VIDEO_FORMAT_GRAY16_BE, AV_PIX_FMT_GRAY16BE},
2852 /* GST_VIDEO_FORMAT_GRAY16_LE, */
2853 {GST_VIDEO_FORMAT_GRAY16_LE, AV_PIX_FMT_GRAY16LE},
2854 /* GST_VIDEO_FORMAT_v308, */
2855 /* GST_VIDEO_FORMAT_Y800, */
2856 /* GST_VIDEO_FORMAT_Y16, */
2857 /* GST_VIDEO_FORMAT_RGB16, */
2858 {GST_VIDEO_FORMAT_RGB16, AV_PIX_FMT_RGB565},
2859 /* GST_VIDEO_FORMAT_BGR16, */
2860 /* GST_VIDEO_FORMAT_RGB15, */
2861 {GST_VIDEO_FORMAT_RGB15, AV_PIX_FMT_RGB555},
2862 /* GST_VIDEO_FORMAT_BGR15, */
2863 /* GST_VIDEO_FORMAT_UYVP, */
2864 /* GST_VIDEO_FORMAT_A420, */
2865 {GST_VIDEO_FORMAT_A420, AV_PIX_FMT_YUVA420P},
2866 /* GST_VIDEO_FORMAT_RGB8_PALETTED, */
2867 {GST_VIDEO_FORMAT_RGB8P, AV_PIX_FMT_PAL8},
2868 /* GST_VIDEO_FORMAT_YUV9, */
2869 {GST_VIDEO_FORMAT_YUV9, AV_PIX_FMT_YUV410P},
2870 /* GST_VIDEO_FORMAT_YVU9, */
2871 /* GST_VIDEO_FORMAT_IYU1, */
2872 /* GST_VIDEO_FORMAT_ARGB64, */
2873 /* GST_VIDEO_FORMAT_AYUV64, */
2874 /* GST_VIDEO_FORMAT_r210, */
2875 {GST_VIDEO_FORMAT_I420_10LE, AV_PIX_FMT_YUV420P10LE},
2876 {GST_VIDEO_FORMAT_I420_10BE, AV_PIX_FMT_YUV420P10BE},
2877 {GST_VIDEO_FORMAT_I422_10LE, AV_PIX_FMT_YUV422P10LE},
2878 {GST_VIDEO_FORMAT_I422_10BE, AV_PIX_FMT_YUV422P10BE},
2879 {GST_VIDEO_FORMAT_Y444_10LE, AV_PIX_FMT_YUV444P10LE},
2880 {GST_VIDEO_FORMAT_Y444_10BE, AV_PIX_FMT_YUV444P10BE},
2881 {GST_VIDEO_FORMAT_GBR, AV_PIX_FMT_GBRP},
2882 {GST_VIDEO_FORMAT_GBRA, AV_PIX_FMT_GBRAP},
2883 {GST_VIDEO_FORMAT_GBR_10LE, AV_PIX_FMT_GBRP10LE},
2884 {GST_VIDEO_FORMAT_GBR_10BE, AV_PIX_FMT_GBRP10BE},
2885 {GST_VIDEO_FORMAT_GBRA_10LE, AV_PIX_FMT_GBRAP10LE},
2886 {GST_VIDEO_FORMAT_GBRA_10BE, AV_PIX_FMT_GBRAP10BE},
2887 {GST_VIDEO_FORMAT_GBR_12LE, AV_PIX_FMT_GBRP12LE},
2888 {GST_VIDEO_FORMAT_GBR_12BE, AV_PIX_FMT_GBRP12BE},
2889 {GST_VIDEO_FORMAT_GBRA_12LE, AV_PIX_FMT_GBRAP12LE},
2890 {GST_VIDEO_FORMAT_GBRA_12BE, AV_PIX_FMT_GBRAP12BE},
2891 {GST_VIDEO_FORMAT_A420_10LE, AV_PIX_FMT_YUVA420P10LE},
2892 {GST_VIDEO_FORMAT_A420_10BE, AV_PIX_FMT_YUVA420P10BE},
2893 {GST_VIDEO_FORMAT_A422_10LE, AV_PIX_FMT_YUVA422P10LE},
2894 {GST_VIDEO_FORMAT_A422_10BE, AV_PIX_FMT_YUVA422P10BE},
2895 {GST_VIDEO_FORMAT_A444_10LE, AV_PIX_FMT_YUVA444P10LE},
2896 {GST_VIDEO_FORMAT_A444_10BE, AV_PIX_FMT_YUVA444P10BE},
2897 {GST_VIDEO_FORMAT_I420_12LE, AV_PIX_FMT_YUV420P12LE},
2898 {GST_VIDEO_FORMAT_I420_12BE, AV_PIX_FMT_YUV420P12BE},
2899 {GST_VIDEO_FORMAT_I422_12LE, AV_PIX_FMT_YUV422P12LE},
2900 {GST_VIDEO_FORMAT_I422_12BE, AV_PIX_FMT_YUV422P12BE},
2901 {GST_VIDEO_FORMAT_Y444_12LE, AV_PIX_FMT_YUV444P12LE},
2902 {GST_VIDEO_FORMAT_Y444_12BE, AV_PIX_FMT_YUV444P12BE},
2906 gst_ffmpeg_pixfmt_to_videoformat (enum AVPixelFormat pixfmt)
2910 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++)
2911 if (pixtofmttable[i].pixfmt == pixfmt)
2912 return pixtofmttable[i].format;
2914 GST_DEBUG ("Unknown pixel format %d", pixfmt);
2915 return GST_VIDEO_FORMAT_UNKNOWN;
2918 static enum AVPixelFormat
2919 gst_ffmpeg_videoformat_to_pixfmt_for_codec (GstVideoFormat format,
2920 const AVCodec * codec)
2924 for (i = 0; i < G_N_ELEMENTS (pixtofmttable); i++) {
2925 if (pixtofmttable[i].format == format) {
2928 if (codec && codec->pix_fmts) {
2929 for (j = 0; codec->pix_fmts[j] != -1; j++) {
2930 if (pixtofmttable[i].pixfmt == codec->pix_fmts[j])
2931 return pixtofmttable[i].pixfmt;
2934 return pixtofmttable[i].pixfmt;
2939 return AV_PIX_FMT_NONE;
2943 gst_ffmpeg_videoformat_to_pixfmt (GstVideoFormat format)
2945 return gst_ffmpeg_videoformat_to_pixfmt_for_codec (format, NULL);
2949 gst_ffmpeg_videoinfo_to_context (GstVideoInfo * info, AVCodecContext * context)
2953 context->width = GST_VIDEO_INFO_WIDTH (info);
2954 context->height = GST_VIDEO_INFO_HEIGHT (info);
2955 for (i = 0; i < GST_VIDEO_INFO_N_COMPONENTS (info); i++)
2956 bpp += GST_VIDEO_INFO_COMP_DEPTH (info, i);
2957 context->bits_per_coded_sample = bpp;
2959 context->ticks_per_frame = 1;
2960 if (GST_VIDEO_INFO_FPS_N (info) == 0) {
2961 GST_DEBUG ("Using 25/1 framerate");
2962 context->time_base.den = 25;
2963 context->time_base.num = 1;
2965 context->time_base.den = GST_VIDEO_INFO_FPS_N (info);
2966 context->time_base.num = GST_VIDEO_INFO_FPS_D (info);
2969 context->sample_aspect_ratio.num = GST_VIDEO_INFO_PAR_N (info);
2970 context->sample_aspect_ratio.den = GST_VIDEO_INFO_PAR_D (info);
2973 gst_ffmpeg_videoformat_to_pixfmt_for_codec (GST_VIDEO_INFO_FORMAT (info),
2976 switch (info->chroma_site) {
2977 case GST_VIDEO_CHROMA_SITE_MPEG2:
2978 context->chroma_sample_location = AVCHROMA_LOC_LEFT;
2980 case GST_VIDEO_CHROMA_SITE_JPEG:
2981 context->chroma_sample_location = AVCHROMA_LOC_CENTER;
2983 case GST_VIDEO_CHROMA_SITE_DV:
2984 context->chroma_sample_location = AVCHROMA_LOC_TOPLEFT;
2986 case GST_VIDEO_CHROMA_SITE_V_COSITED:
2987 context->chroma_sample_location = AVCHROMA_LOC_TOP;
2993 context->color_primaries =
2994 gst_video_color_primaries_to_iso (info->colorimetry.primaries);
2995 context->color_trc =
2996 gst_video_transfer_function_to_iso (info->colorimetry.transfer);
2997 context->colorspace =
2998 gst_video_color_matrix_to_iso (info->colorimetry.matrix);
3000 if (info->colorimetry.range == GST_VIDEO_COLOR_RANGE_0_255) {
3001 context->color_range = AVCOL_RANGE_JPEG;
3003 context->color_range = AVCOL_RANGE_MPEG;
3004 context->strict_std_compliance = FF_COMPLIANCE_UNOFFICIAL;
3009 gst_ffmpeg_audioinfo_to_context (GstAudioInfo * info, AVCodecContext * context)
3011 const AVCodec *codec;
3012 const enum AVSampleFormat *smpl_fmts;
3013 enum AVSampleFormat smpl_fmt = -1;
3015 context->channels = info->channels;
3016 context->sample_rate = info->rate;
3017 context->channel_layout =
3018 gst_ffmpeg_channel_positions_to_layout (info->position, info->channels);
3020 codec = context->codec;
3022 smpl_fmts = codec->sample_fmts;
3024 switch (info->finfo->format) {
3025 case GST_AUDIO_FORMAT_F32:
3027 while (*smpl_fmts != -1) {
3028 if (*smpl_fmts == AV_SAMPLE_FMT_FLT) {
3029 smpl_fmt = *smpl_fmts;
3031 } else if (*smpl_fmts == AV_SAMPLE_FMT_FLTP) {
3032 smpl_fmt = *smpl_fmts;
3038 smpl_fmt = AV_SAMPLE_FMT_FLT;
3041 case GST_AUDIO_FORMAT_F64:
3043 while (*smpl_fmts != -1) {
3044 if (*smpl_fmts == AV_SAMPLE_FMT_DBL) {
3045 smpl_fmt = *smpl_fmts;
3047 } else if (*smpl_fmts == AV_SAMPLE_FMT_DBLP) {
3048 smpl_fmt = *smpl_fmts;
3054 smpl_fmt = AV_SAMPLE_FMT_DBL;
3057 case GST_AUDIO_FORMAT_S32:
3059 while (*smpl_fmts != -1) {
3060 if (*smpl_fmts == AV_SAMPLE_FMT_S32) {
3061 smpl_fmt = *smpl_fmts;
3063 } else if (*smpl_fmts == AV_SAMPLE_FMT_S32P) {
3064 smpl_fmt = *smpl_fmts;
3070 smpl_fmt = AV_SAMPLE_FMT_S32;
3073 case GST_AUDIO_FORMAT_S16:
3075 while (*smpl_fmts != -1) {
3076 if (*smpl_fmts == AV_SAMPLE_FMT_S16) {
3077 smpl_fmt = *smpl_fmts;
3079 } else if (*smpl_fmts == AV_SAMPLE_FMT_S16P) {
3080 smpl_fmt = *smpl_fmts;
3086 smpl_fmt = AV_SAMPLE_FMT_S16;
3089 case GST_AUDIO_FORMAT_U8:
3091 while (*smpl_fmts != -1) {
3092 if (*smpl_fmts == AV_SAMPLE_FMT_U8) {
3093 smpl_fmt = *smpl_fmts;
3095 } else if (*smpl_fmts == AV_SAMPLE_FMT_U8P) {
3096 smpl_fmt = *smpl_fmts;
3102 smpl_fmt = AV_SAMPLE_FMT_U8;
3109 g_assert (smpl_fmt != -1);
3111 context->sample_fmt = smpl_fmt;
3114 /* Convert a GstCaps and a FFMPEG codec Type to a
3115 * AVCodecContext. If the context is ommitted, no fixed values
3116 * for video/audio size will be included in the context
3118 * AVMediaType is primarily meant for uncompressed data GstCaps!
3122 gst_ffmpeg_caps_with_codectype (enum AVMediaType type,
3123 const GstCaps * caps, AVCodecContext * context)
3125 if (context == NULL)
3129 case AVMEDIA_TYPE_VIDEO:
3130 gst_ffmpeg_caps_to_pixfmt (caps, context, TRUE);
3133 case AVMEDIA_TYPE_AUDIO:
3134 gst_ffmpeg_caps_to_smpfmt (caps, context, TRUE);
3145 nal_escape (guint8 * dst, guint8 * src, guint size, guint * destsize)
3149 guint8 *end = src + size;
3152 while (srcp < end) {
3153 if (count == 2 && *srcp <= 0x03) {
3154 GST_DEBUG ("added escape code");
3163 GST_DEBUG ("copy %02x, count %d", *srcp, count);
3166 *destsize = dstp - dst;
3169 /* copy the config, escaping NAL units as we iterate them, if something fails we
3170 * copy everything and hope for the best. */
3172 copy_config (guint8 * dst, guint8 * src, guint size, guint * destsize)
3177 guint nalsize, esize;
3187 cnt = *(srcp + 5) & 0x1f; /* Number of sps */
3189 GST_DEBUG ("num SPS %d", cnt);
3191 memcpy (dstp, srcp, 6);
3195 for (i = 0; i < cnt; i++) {
3196 GST_DEBUG ("copy SPS %d", i);
3197 nalsize = (srcp[0] << 8) | srcp[1];
3198 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
3199 dstp[0] = esize >> 8;
3200 dstp[1] = esize & 0xff;
3202 srcp += nalsize + 2;
3205 cnt = *(dstp++) = *(srcp++); /* Number of pps */
3207 GST_DEBUG ("num PPS %d", cnt);
3209 for (i = 0; i < cnt; i++) {
3210 GST_DEBUG ("copy PPS %d", i);
3211 nalsize = (srcp[0] << 8) | srcp[1];
3212 nal_escape (dstp + 2, srcp + 2, nalsize, &esize);
3213 dstp[0] = esize >> 8;
3214 dstp[1] = esize & 0xff;
3216 srcp += nalsize + 2;
3218 *destsize = dstp - dst;
3224 GST_DEBUG ("something unexpected, doing full copy");
3225 memcpy (dst, src, size);
3233 * caps_with_codecid () transforms a GstCaps for a known codec
3234 * ID into a filled-in context.
3235 * codec_data from caps will override possible extradata already in the context
3239 gst_ffmpeg_caps_with_codecid (enum AVCodecID codec_id,
3240 enum AVMediaType codec_type, const GstCaps * caps, AVCodecContext * context)
3243 const GValue *value;
3246 GST_LOG ("codec_id:%d, codec_type:%d, caps:%" GST_PTR_FORMAT " context:%p",
3247 codec_id, codec_type, caps, context);
3249 if (!context || !gst_caps_get_size (caps))
3252 str = gst_caps_get_structure (caps, 0);
3254 /* extradata parsing (esds [mpeg4], wma/wmv, msmpeg4v1/2/3, etc.) */
3255 if ((value = gst_structure_get_value (str, "codec_data"))) {
3258 buf = gst_value_get_buffer (value);
3259 gst_buffer_map (buf, &map, GST_MAP_READ);
3261 /* free the old one if it is there */
3262 if (context->extradata)
3263 av_free (context->extradata);
3266 if (codec_id == AV_CODEC_ID_H264) {
3269 GST_DEBUG ("copy, escaping codec_data %d", size);
3270 /* ffmpeg h264 expects the codec_data to be escaped, there is no real
3271 * reason for this but let's just escape it for now. Start by allocating
3272 * enough space, x2 is more than enough.
3274 * FIXME, we disabled escaping because some file already contain escaped
3275 * codec_data and then we escape twice and fail. It's better to leave it
3276 * as is, as that is what most players do. */
3277 context->extradata =
3278 av_mallocz (GST_ROUND_UP_16 (size * 2 +
3279 AV_INPUT_BUFFER_PADDING_SIZE));
3280 copy_config (context->extradata, data, size, &extrasize);
3281 GST_DEBUG ("escaped size: %d", extrasize);
3282 context->extradata_size = extrasize;
3286 /* allocate with enough padding */
3287 GST_DEBUG ("copy codec_data");
3288 context->extradata =
3289 av_mallocz (GST_ROUND_UP_16 (map.size +
3290 AV_INPUT_BUFFER_PADDING_SIZE));
3291 memcpy (context->extradata, map.data, map.size);
3292 context->extradata_size = map.size;
3295 /* Hack for VC1. Sometimes the first (length) byte is 0 for some files */
3296 if (codec_id == AV_CODEC_ID_VC1 && map.size > 0 && map.data[0] == 0) {
3297 context->extradata[0] = (guint8) map.size;
3300 GST_DEBUG ("have codec data of size %" G_GSIZE_FORMAT, map.size);
3302 gst_buffer_unmap (buf, &map);
3304 context->extradata = NULL;
3305 context->extradata_size = 0;
3306 GST_DEBUG ("no codec data");
3310 case AV_CODEC_ID_MPEG4:
3312 const gchar *mime = gst_structure_get_name (str);
3314 context->flags |= AV_CODEC_FLAG_4MV;
3316 if (!strcmp (mime, "video/x-divx"))
3317 context->codec_tag = GST_MAKE_FOURCC ('D', 'I', 'V', 'X');
3318 else if (!strcmp (mime, "video/mpeg")) {
3319 const gchar *profile;
3321 context->codec_tag = GST_MAKE_FOURCC ('m', 'p', '4', 'v');
3323 profile = gst_structure_get_string (str, "profile");
3325 if (g_strcmp0 (profile, "advanced-simple") == 0)
3326 context->flags |= AV_CODEC_FLAG_QPEL;
3332 case AV_CODEC_ID_SVQ3:
3333 /* FIXME: this is a workaround for older gst-plugins releases
3334 * (<= 0.8.9). This should be removed at some point, because
3335 * it causes wrong decoded frame order. */
3336 if (!context->extradata) {
3337 gint halfpel_flag, thirdpel_flag, low_delay, unknown_svq3_flag;
3340 if (gst_structure_get_int (str, "halfpel_flag", &halfpel_flag) &&
3341 gst_structure_get_int (str, "thirdpel_flag", &thirdpel_flag) &&
3342 gst_structure_get_int (str, "low_delay", &low_delay) &&
3343 gst_structure_get_int (str, "unknown_svq3_flag",
3344 &unknown_svq3_flag)) {
3345 context->extradata = (guint8 *) av_mallocz (0x64);
3346 g_stpcpy ((gchar *) context->extradata, "SVQ3");
3350 flags |= unknown_svq3_flag;
3352 flags |= halfpel_flag;
3354 flags |= thirdpel_flag;
3357 flags = GUINT16_FROM_LE (flags);
3359 memcpy ((gchar *) context->extradata + 0x62, &flags, 2);
3360 context->extradata_size = 0x64;
3365 case AV_CODEC_ID_MSRLE:
3366 case AV_CODEC_ID_QTRLE:
3367 case AV_CODEC_ID_TSCC:
3368 case AV_CODEC_ID_CSCD:
3369 case AV_CODEC_ID_APE:
3373 if (gst_structure_get_int (str, "depth", &depth)) {
3374 context->bits_per_coded_sample = depth;
3376 GST_WARNING ("No depth field in caps %" GST_PTR_FORMAT, caps);
3382 case AV_CODEC_ID_COOK:
3383 case AV_CODEC_ID_RA_288:
3384 case AV_CODEC_ID_RA_144:
3385 case AV_CODEC_ID_SIPR:
3390 if (gst_structure_get_int (str, "leaf_size", &leaf_size))
3391 context->block_align = leaf_size;
3392 if (gst_structure_get_int (str, "bitrate", &bitrate))
3393 context->bit_rate = bitrate;
3396 case AV_CODEC_ID_ALAC:
3397 gst_structure_get_int (str, "samplesize",
3398 &context->bits_per_coded_sample);
3401 case AV_CODEC_ID_DVVIDEO:
3403 const gchar *format;
3405 if ((format = gst_structure_get_string (str, "format"))) {
3407 if (g_str_equal (format, "YUY2"))
3408 context->pix_fmt = AV_PIX_FMT_YUYV422;
3409 else if (g_str_equal (format, "I420"))
3410 context->pix_fmt = AV_PIX_FMT_YUV420P;
3411 else if (g_str_equal (format, "A420"))
3412 context->pix_fmt = AV_PIX_FMT_YUVA420P;
3413 else if (g_str_equal (format, "Y41B"))
3414 context->pix_fmt = AV_PIX_FMT_YUV411P;
3415 else if (g_str_equal (format, "Y42B"))
3416 context->pix_fmt = AV_PIX_FMT_YUV422P;
3417 else if (g_str_equal (format, "YUV9"))
3418 context->pix_fmt = AV_PIX_FMT_YUV410P;
3420 GST_WARNING ("couldn't convert format %s" " to a pixel format",
3424 GST_WARNING ("No specified format");
3427 case AV_CODEC_ID_H263P:
3431 if (!gst_structure_get_boolean (str, "annex-f", &val) || val)
3432 context->flags |= AV_CODEC_FLAG_4MV;
3434 context->flags &= ~AV_CODEC_FLAG_4MV;
3435 if ((!gst_structure_get_boolean (str, "annex-i", &val) || val) &&
3436 (!gst_structure_get_boolean (str, "annex-t", &val) || val))
3437 context->flags |= AV_CODEC_FLAG_AC_PRED;
3439 context->flags &= ~AV_CODEC_FLAG_AC_PRED;
3440 if (!gst_structure_get_boolean (str, "annex-j", &val) || val)
3441 context->flags |= AV_CODEC_FLAG_LOOP_FILTER;
3443 context->flags &= ~AV_CODEC_FLAG_LOOP_FILTER;
3446 case AV_CODEC_ID_ADPCM_G726:
3448 const gchar *layout;
3450 if ((layout = gst_structure_get_string (str, "layout"))) {
3451 if (!strcmp (layout, "g721")) {
3452 context->sample_rate = 8000;
3453 context->channels = 1;
3454 context->bit_rate = 32000;
3459 case AV_CODEC_ID_SPEEDHQ:
3461 const gchar *variant;
3463 if (context && (variant = gst_structure_get_string (str, "variant"))
3464 && strlen (variant) == 4) {
3466 context->codec_tag =
3467 GST_MAKE_FOURCC (variant[0], variant[1], variant[2], variant[3]);
3475 if (!gst_caps_is_fixed (caps))
3478 /* common properties (width, height, fps) */
3479 switch (codec_type) {
3480 case AVMEDIA_TYPE_VIDEO:
3481 gst_ffmpeg_caps_to_pixfmt (caps, context,
3482 codec_id == AV_CODEC_ID_RAWVIDEO);
3484 case AVMEDIA_TYPE_AUDIO:
3485 gst_ffmpeg_caps_to_smpfmt (caps, context, FALSE);
3491 /* fixup of default settings */
3493 case AV_CODEC_ID_QCELP:
3494 /* QCELP is always mono, no matter what the caps say */
3495 context->channels = 1;
3497 case AV_CODEC_ID_ADPCM_G726:
3498 if (context->sample_rate && context->bit_rate)
3499 context->bits_per_coded_sample =
3500 context->bit_rate / context->sample_rate;
3507 /* _formatid_to_caps () is meant for muxers/demuxers, it
3508 * transforms a name (ffmpeg way of ID'ing these, why don't
3509 * they have unique numerical IDs?) to the corresponding
3510 * caps belonging to that mux-format
3512 * Note: we don't need any additional info because the caps
3513 * isn't supposed to contain any useful info besides the
3518 gst_ffmpeg_formatid_to_caps (const gchar * format_name)
3520 GstCaps *caps = NULL;
3522 if (!strcmp (format_name, "mpeg")) {
3523 caps = gst_caps_new_simple ("video/mpeg",
3524 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3525 } else if (!strcmp (format_name, "mpegts")) {
3526 caps = gst_caps_new_simple ("video/mpegts",
3527 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3528 } else if (!strcmp (format_name, "rm")) {
3529 caps = gst_caps_new_simple ("application/x-pn-realmedia",
3530 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3531 } else if (!strcmp (format_name, "asf")) {
3532 caps = gst_caps_new_empty_simple ("video/x-ms-asf");
3533 } else if (!strcmp (format_name, "avi")) {
3534 caps = gst_caps_new_empty_simple ("video/x-msvideo");
3535 } else if (!strcmp (format_name, "wav")) {
3536 caps = gst_caps_new_empty_simple ("audio/x-wav");
3537 } else if (!strcmp (format_name, "ape")) {
3538 caps = gst_caps_new_empty_simple ("application/x-ape");
3539 } else if (!strcmp (format_name, "swf")) {
3540 caps = gst_caps_new_empty_simple ("application/x-shockwave-flash");
3541 } else if (!strcmp (format_name, "au")) {
3542 caps = gst_caps_new_empty_simple ("audio/x-au");
3543 } else if (!strcmp (format_name, "dv")) {
3544 caps = gst_caps_new_simple ("video/x-dv",
3545 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
3546 } else if (!strcmp (format_name, "4xm")) {
3547 caps = gst_caps_new_empty_simple ("video/x-4xm");
3548 } else if (!strcmp (format_name, "matroska")) {
3549 caps = gst_caps_new_empty_simple ("video/x-matroska");
3550 } else if (!strcmp (format_name, "ivf")) {
3551 caps = gst_caps_new_empty_simple ("video/x-ivf");
3552 } else if (!strcmp (format_name, "mp3")) {
3553 caps = gst_caps_new_empty_simple ("application/x-id3");
3554 } else if (!strcmp (format_name, "flic")) {
3555 caps = gst_caps_new_empty_simple ("video/x-fli");
3556 } else if (!strcmp (format_name, "flv")) {
3557 caps = gst_caps_new_empty_simple ("video/x-flv");
3558 } else if (!strcmp (format_name, "tta")) {
3559 caps = gst_caps_new_empty_simple ("audio/x-ttafile");
3560 } else if (!strcmp (format_name, "aiff")) {
3561 caps = gst_caps_new_empty_simple ("audio/x-aiff");
3562 } else if (!strcmp (format_name, "mov_mp4_m4a_3gp_3g2")) {
3564 gst_caps_from_string
3565 ("application/x-3gp; video/quicktime; audio/x-m4a");
3566 } else if (!strcmp (format_name, "mov")) {
3567 caps = gst_caps_from_string ("video/quicktime,variant=(string)apple");
3568 } else if (!strcmp (format_name, "mp4")) {
3569 caps = gst_caps_from_string ("video/quicktime,variant=(string)iso");
3570 } else if (!strcmp (format_name, "3gp")) {
3571 caps = gst_caps_from_string ("video/quicktime,variant=(string)3gpp");
3572 } else if (!strcmp (format_name, "3g2")) {
3573 caps = gst_caps_from_string ("video/quicktime,variant=(string)3g2");
3574 } else if (!strcmp (format_name, "psp")) {
3575 caps = gst_caps_from_string ("video/quicktime,variant=(string)psp");
3576 } else if (!strcmp (format_name, "ipod")) {
3577 caps = gst_caps_from_string ("video/quicktime,variant=(string)ipod");
3578 } else if (!strcmp (format_name, "aac")) {
3579 caps = gst_caps_new_simple ("audio/mpeg",
3580 "mpegversion", G_TYPE_INT, 4, NULL);
3581 } else if (!strcmp (format_name, "gif")) {
3582 caps = gst_caps_from_string ("image/gif");
3583 } else if (!strcmp (format_name, "ogg")) {
3584 caps = gst_caps_from_string ("application/ogg");
3585 } else if (!strcmp (format_name, "mxf") || !strcmp (format_name, "mxf_d10")) {
3586 caps = gst_caps_from_string ("application/mxf");
3587 } else if (!strcmp (format_name, "gxf")) {
3588 caps = gst_caps_from_string ("application/gxf");
3589 } else if (!strcmp (format_name, "yuv4mpegpipe")) {
3590 caps = gst_caps_new_simple ("application/x-yuv4mpeg",
3591 "y4mversion", G_TYPE_INT, 2, NULL);
3592 } else if (!strcmp (format_name, "mpc")) {
3593 caps = gst_caps_from_string ("audio/x-musepack, streamversion = (int) 7");
3594 } else if (!strcmp (format_name, "mpc8")) {
3595 caps = gst_caps_from_string ("audio/x-musepack, streamversion = (int) 8");
3596 } else if (!strcmp (format_name, "vqf")) {
3597 caps = gst_caps_from_string ("audio/x-vqf");
3598 } else if (!strcmp (format_name, "nsv")) {
3599 caps = gst_caps_from_string ("video/x-nsv");
3600 } else if (!strcmp (format_name, "amr")) {
3601 caps = gst_caps_from_string ("audio/x-amr-nb-sh");
3602 } else if (!strcmp (format_name, "webm")) {
3603 caps = gst_caps_from_string ("video/webm");
3604 } else if (!strcmp (format_name, "voc")) {
3605 caps = gst_caps_from_string ("audio/x-voc");
3606 } else if (!strcmp (format_name, "pva")) {
3607 caps = gst_caps_from_string ("video/x-pva");
3608 } else if (!strcmp (format_name, "brstm")) {
3609 caps = gst_caps_from_string ("audio/x-brstm");
3610 } else if (!strcmp (format_name, "bfstm")) {
3611 caps = gst_caps_from_string ("audio/x-bfstm");
3615 GST_LOG ("Could not create stream format caps for %s", format_name);
3616 name = g_strdup_printf ("application/x-gst-av-%s", format_name);
3617 caps = gst_caps_new_empty_simple (name);
3625 gst_ffmpeg_formatid_get_codecids (const gchar * format_name,
3626 enum AVCodecID ** video_codec_list, enum AVCodecID ** audio_codec_list,
3627 AVOutputFormat * plugin)
3629 static enum AVCodecID tmp_vlist[] = {
3633 static enum AVCodecID tmp_alist[] = {
3638 GST_LOG ("format_name : %s", format_name);
3640 if (!strcmp (format_name, "mp4")) {
3641 static enum AVCodecID mp4_video_list[] = {
3642 AV_CODEC_ID_MPEG4, AV_CODEC_ID_H264,
3646 static enum AVCodecID mp4_audio_list[] = {
3647 AV_CODEC_ID_AAC, AV_CODEC_ID_MP3,
3651 *video_codec_list = mp4_video_list;
3652 *audio_codec_list = mp4_audio_list;
3653 } else if (!strcmp (format_name, "mpeg")) {
3654 static enum AVCodecID mpeg_video_list[] = { AV_CODEC_ID_MPEG1VIDEO,
3655 AV_CODEC_ID_MPEG2VIDEO,
3659 static enum AVCodecID mpeg_audio_list[] = { AV_CODEC_ID_MP1,
3665 *video_codec_list = mpeg_video_list;
3666 *audio_codec_list = mpeg_audio_list;
3667 } else if (!strcmp (format_name, "dvd")) {
3668 static enum AVCodecID mpeg_video_list[] = { AV_CODEC_ID_MPEG2VIDEO,
3671 static enum AVCodecID mpeg_audio_list[] = { AV_CODEC_ID_MP2,
3674 AV_CODEC_ID_PCM_S16BE,
3678 *video_codec_list = mpeg_video_list;
3679 *audio_codec_list = mpeg_audio_list;
3680 } else if (!strcmp (format_name, "mpegts")) {
3681 static enum AVCodecID mpegts_video_list[] = { AV_CODEC_ID_MPEG1VIDEO,
3682 AV_CODEC_ID_MPEG2VIDEO,
3686 static enum AVCodecID mpegts_audio_list[] = { AV_CODEC_ID_MP2,
3694 *video_codec_list = mpegts_video_list;
3695 *audio_codec_list = mpegts_audio_list;
3696 } else if (!strcmp (format_name, "vob")) {
3697 static enum AVCodecID vob_video_list[] =
3698 { AV_CODEC_ID_MPEG2VIDEO, AV_CODEC_ID_NONE };
3699 static enum AVCodecID vob_audio_list[] = { AV_CODEC_ID_MP2, AV_CODEC_ID_AC3,
3700 AV_CODEC_ID_DTS, AV_CODEC_ID_NONE
3703 *video_codec_list = vob_video_list;
3704 *audio_codec_list = vob_audio_list;
3705 } else if (!strcmp (format_name, "flv")) {
3706 static enum AVCodecID flv_video_list[] =
3707 { AV_CODEC_ID_FLV1, AV_CODEC_ID_NONE };
3708 static enum AVCodecID flv_audio_list[] =
3709 { AV_CODEC_ID_MP3, AV_CODEC_ID_NONE };
3711 *video_codec_list = flv_video_list;
3712 *audio_codec_list = flv_audio_list;
3713 } else if (!strcmp (format_name, "asf")) {
3714 static enum AVCodecID asf_video_list[] =
3715 { AV_CODEC_ID_WMV1, AV_CODEC_ID_WMV2, AV_CODEC_ID_MSMPEG4V3,
3718 static enum AVCodecID asf_audio_list[] =
3719 { AV_CODEC_ID_WMAV1, AV_CODEC_ID_WMAV2, AV_CODEC_ID_MP3,
3723 *video_codec_list = asf_video_list;
3724 *audio_codec_list = asf_audio_list;
3725 } else if (!strcmp (format_name, "dv")) {
3726 static enum AVCodecID dv_video_list[] =
3727 { AV_CODEC_ID_DVVIDEO, AV_CODEC_ID_NONE };
3728 static enum AVCodecID dv_audio_list[] =
3729 { AV_CODEC_ID_PCM_S16LE, AV_CODEC_ID_NONE };
3731 *video_codec_list = dv_video_list;
3732 *audio_codec_list = dv_audio_list;
3733 } else if (!strcmp (format_name, "mov")) {
3734 static enum AVCodecID mov_video_list[] = {
3735 AV_CODEC_ID_SVQ1, AV_CODEC_ID_SVQ3, AV_CODEC_ID_MPEG4,
3736 AV_CODEC_ID_H263, AV_CODEC_ID_H263P,
3737 AV_CODEC_ID_H264, AV_CODEC_ID_DVVIDEO,
3741 static enum AVCodecID mov_audio_list[] = {
3742 AV_CODEC_ID_PCM_MULAW, AV_CODEC_ID_PCM_ALAW, AV_CODEC_ID_ADPCM_IMA_QT,
3743 AV_CODEC_ID_MACE3, AV_CODEC_ID_MACE6, AV_CODEC_ID_AAC,
3744 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3745 AV_CODEC_ID_PCM_S16BE, AV_CODEC_ID_PCM_S16LE,
3746 AV_CODEC_ID_MP3, AV_CODEC_ID_NONE
3749 *video_codec_list = mov_video_list;
3750 *audio_codec_list = mov_audio_list;
3751 } else if ((!strcmp (format_name, "3gp") || !strcmp (format_name, "3g2"))) {
3752 static enum AVCodecID tgp_video_list[] = {
3753 AV_CODEC_ID_MPEG4, AV_CODEC_ID_H263, AV_CODEC_ID_H263P, AV_CODEC_ID_H264,
3756 static enum AVCodecID tgp_audio_list[] = {
3757 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3762 *video_codec_list = tgp_video_list;
3763 *audio_codec_list = tgp_audio_list;
3764 } else if (!strcmp (format_name, "mmf")) {
3765 static enum AVCodecID mmf_audio_list[] = {
3766 AV_CODEC_ID_ADPCM_YAMAHA, AV_CODEC_ID_NONE
3768 *video_codec_list = NULL;
3769 *audio_codec_list = mmf_audio_list;
3770 } else if (!strcmp (format_name, "amr")) {
3771 static enum AVCodecID amr_audio_list[] = {
3772 AV_CODEC_ID_AMR_NB, AV_CODEC_ID_AMR_WB,
3775 *video_codec_list = NULL;
3776 *audio_codec_list = amr_audio_list;
3777 } else if (!strcmp (format_name, "gif")) {
3778 static enum AVCodecID gif_image_list[] = {
3779 AV_CODEC_ID_RAWVIDEO, AV_CODEC_ID_NONE
3781 *video_codec_list = gif_image_list;
3782 *audio_codec_list = NULL;
3783 } else if ((!strcmp (format_name, "pva"))) {
3784 static enum AVCodecID pga_video_list[] = {
3785 AV_CODEC_ID_MPEG2VIDEO,
3788 static enum AVCodecID pga_audio_list[] = {
3793 *video_codec_list = pga_video_list;
3794 *audio_codec_list = pga_audio_list;
3795 } else if ((!strcmp (format_name, "ivf"))) {
3796 static enum AVCodecID ivf_video_list[] = {
3802 static enum AVCodecID ivf_audio_list[] = {
3806 *video_codec_list = ivf_video_list;
3807 *audio_codec_list = ivf_audio_list;
3808 } else if ((plugin->audio_codec != AV_CODEC_ID_NONE) ||
3809 (plugin->video_codec != AV_CODEC_ID_NONE)) {
3810 tmp_vlist[0] = plugin->video_codec;
3811 tmp_alist[0] = plugin->audio_codec;
3813 *video_codec_list = tmp_vlist;
3814 *audio_codec_list = tmp_alist;
3816 GST_LOG ("Format %s not found", format_name);
3823 /* Convert a GstCaps to a FFMPEG codec ID. Size et all
3824 * are omitted, that can be queried by the user itself,
3825 * we're not eating the GstCaps or anything
3826 * A pointer to an allocated context is also needed for
3827 * optional extra info
3831 gst_ffmpeg_caps_to_codecid (const GstCaps * caps, AVCodecContext * context)
3833 enum AVCodecID id = AV_CODEC_ID_NONE;
3834 const gchar *mimetype;
3835 const GstStructure *structure;
3836 gboolean video = FALSE, audio = FALSE; /* we want to be sure! */
3838 g_return_val_if_fail (caps != NULL, AV_CODEC_ID_NONE);
3839 g_return_val_if_fail (gst_caps_get_size (caps) == 1, AV_CODEC_ID_NONE);
3840 structure = gst_caps_get_structure (caps, 0);
3842 mimetype = gst_structure_get_name (structure);
3844 if (!strcmp (mimetype, "video/x-raw")) {
3845 id = AV_CODEC_ID_RAWVIDEO;
3847 } else if (!strcmp (mimetype, "audio/x-raw")) {
3850 if (gst_audio_info_from_caps (&info, caps)) {
3851 switch (GST_AUDIO_INFO_FORMAT (&info)) {
3852 case GST_AUDIO_FORMAT_S8:
3853 id = AV_CODEC_ID_PCM_S8;
3855 case GST_AUDIO_FORMAT_U8:
3856 id = AV_CODEC_ID_PCM_U8;
3858 case GST_AUDIO_FORMAT_S16LE:
3859 id = AV_CODEC_ID_PCM_S16LE;
3861 case GST_AUDIO_FORMAT_S16BE:
3862 id = AV_CODEC_ID_PCM_S16BE;
3864 case GST_AUDIO_FORMAT_U16LE:
3865 id = AV_CODEC_ID_PCM_U16LE;
3867 case GST_AUDIO_FORMAT_U16BE:
3868 id = AV_CODEC_ID_PCM_U16BE;
3873 if (id != AV_CODEC_ID_NONE)
3876 } else if (!strcmp (mimetype, "audio/x-mulaw")) {
3877 id = AV_CODEC_ID_PCM_MULAW;
3879 } else if (!strcmp (mimetype, "audio/x-alaw")) {
3880 id = AV_CODEC_ID_PCM_ALAW;
3882 } else if (!strcmp (mimetype, "video/x-dv")) {
3885 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3887 id = AV_CODEC_ID_DVVIDEO;
3890 } else if (!strcmp (mimetype, "audio/x-dv")) { /* ??? */
3891 id = AV_CODEC_ID_DVAUDIO;
3893 } else if (!strcmp (mimetype, "video/x-h263")) {
3894 const gchar *h263version =
3895 gst_structure_get_string (structure, "h263version");
3896 if (h263version && !strcmp (h263version, "h263p"))
3897 id = AV_CODEC_ID_H263P;
3899 id = AV_CODEC_ID_H263;
3901 } else if (!strcmp (mimetype, "video/x-intel-h263")) {
3902 id = AV_CODEC_ID_H263I;
3904 } else if (!strcmp (mimetype, "video/x-h261")) {
3905 id = AV_CODEC_ID_H261;
3907 } else if (!strcmp (mimetype, "video/mpeg")) {
3911 if (gst_structure_get_boolean (structure, "systemstream", &sys_strm) &&
3912 gst_structure_get_int (structure, "mpegversion", &mpegversion) &&
3914 switch (mpegversion) {
3916 id = AV_CODEC_ID_MPEG1VIDEO;
3919 id = AV_CODEC_ID_MPEG2VIDEO;
3922 id = AV_CODEC_ID_MPEG4;
3926 if (id != AV_CODEC_ID_NONE)
3928 } else if (!strcmp (mimetype, "image/jpeg")) {
3929 id = AV_CODEC_ID_MJPEG; /* A... B... */
3931 } else if (!strcmp (mimetype, "video/x-jpeg-b")) {
3932 id = AV_CODEC_ID_MJPEGB;
3934 } else if (!strcmp (mimetype, "video/x-wmv")) {
3935 gint wmvversion = 0;
3937 if (gst_structure_get_int (structure, "wmvversion", &wmvversion)) {
3938 switch (wmvversion) {
3940 id = AV_CODEC_ID_WMV1;
3943 id = AV_CODEC_ID_WMV2;
3947 const gchar *format;
3949 /* WMV3 unless the fourcc exists and says otherwise */
3950 id = AV_CODEC_ID_WMV3;
3952 if ((format = gst_structure_get_string (structure, "format")) &&
3953 (g_str_equal (format, "WVC1") || g_str_equal (format, "WMVA")))
3954 id = AV_CODEC_ID_VC1;
3960 if (id != AV_CODEC_ID_NONE)
3962 } else if (!strcmp (mimetype, "audio/x-vorbis")) {
3963 id = AV_CODEC_ID_VORBIS;
3965 } else if (!strcmp (mimetype, "audio/x-qdm2")) {
3966 id = AV_CODEC_ID_QDM2;
3968 } else if (!strcmp (mimetype, "audio/mpeg")) {
3970 gint mpegversion = 0;
3972 if (gst_structure_get_int (structure, "mpegversion", &mpegversion)) {
3973 switch (mpegversion) {
3974 case 2: /* ffmpeg uses faad for both... */
3976 id = AV_CODEC_ID_AAC;
3979 if (gst_structure_get_int (structure, "layer", &layer)) {
3982 id = AV_CODEC_ID_MP1;
3985 id = AV_CODEC_ID_MP2;
3988 id = AV_CODEC_ID_MP3;
3994 if (id != AV_CODEC_ID_NONE)
3996 } else if (!strcmp (mimetype, "audio/x-musepack")) {
3997 gint streamversion = -1;
3999 if (gst_structure_get_int (structure, "streamversion", &streamversion)) {
4000 if (streamversion == 7)
4001 id = AV_CODEC_ID_MUSEPACK7;
4003 id = AV_CODEC_ID_MUSEPACK7;
4005 } else if (!strcmp (mimetype, "audio/x-wma")) {
4006 gint wmaversion = 0;
4008 if (gst_structure_get_int (structure, "wmaversion", &wmaversion)) {
4009 switch (wmaversion) {
4011 id = AV_CODEC_ID_WMAV1;
4014 id = AV_CODEC_ID_WMAV2;
4017 id = AV_CODEC_ID_WMAPRO;
4021 if (id != AV_CODEC_ID_NONE)
4023 } else if (!strcmp (mimetype, "audio/x-xma")) {
4024 gint xmaversion = 0;
4026 if (gst_structure_get_int (structure, "xmaversion", &xmaversion)) {
4027 switch (xmaversion) {
4029 id = AV_CODEC_ID_XMA1;
4032 id = AV_CODEC_ID_XMA2;
4036 if (id != AV_CODEC_ID_NONE)
4038 } else if (!strcmp (mimetype, "audio/x-wms")) {
4039 id = AV_CODEC_ID_WMAVOICE;
4041 } else if (!strcmp (mimetype, "audio/x-ac3")) {
4042 id = AV_CODEC_ID_AC3;
4044 } else if (!strcmp (mimetype, "audio/x-eac3")) {
4045 id = AV_CODEC_ID_EAC3;
4047 } else if (!strcmp (mimetype, "audio/x-vnd.sony.atrac3") ||
4048 !strcmp (mimetype, "audio/atrac3")) {
4049 id = AV_CODEC_ID_ATRAC3;
4051 } else if (!strcmp (mimetype, "audio/x-dts")) {
4052 id = AV_CODEC_ID_DTS;
4054 } else if (!strcmp (mimetype, "application/x-ape")) {
4055 id = AV_CODEC_ID_APE;
4057 } else if (!strcmp (mimetype, "video/x-msmpeg")) {
4058 gint msmpegversion = 0;
4060 if (gst_structure_get_int (structure, "msmpegversion", &msmpegversion)) {
4061 switch (msmpegversion) {
4063 id = AV_CODEC_ID_MSMPEG4V1;
4066 id = AV_CODEC_ID_MSMPEG4V2;
4069 id = AV_CODEC_ID_MSMPEG4V3;
4073 if (id != AV_CODEC_ID_NONE)
4075 } else if (!strcmp (mimetype, "video/x-svq")) {
4076 gint svqversion = 0;
4078 if (gst_structure_get_int (structure, "svqversion", &svqversion)) {
4079 switch (svqversion) {
4081 id = AV_CODEC_ID_SVQ1;
4084 id = AV_CODEC_ID_SVQ3;
4088 if (id != AV_CODEC_ID_NONE)
4090 } else if (!strcmp (mimetype, "video/x-huffyuv")) {
4091 id = AV_CODEC_ID_HUFFYUV;
4093 } else if (!strcmp (mimetype, "audio/x-mace")) {
4094 gint maceversion = 0;
4096 if (gst_structure_get_int (structure, "maceversion", &maceversion)) {
4097 switch (maceversion) {
4099 id = AV_CODEC_ID_MACE3;
4102 id = AV_CODEC_ID_MACE6;
4106 if (id != AV_CODEC_ID_NONE)
4108 } else if (!strcmp (mimetype, "video/x-theora")) {
4109 id = AV_CODEC_ID_THEORA;
4111 } else if (!strcmp (mimetype, "video/x-vp3")) {
4112 id = AV_CODEC_ID_VP3;
4114 } else if (!strcmp (mimetype, "video/x-vp5")) {
4115 id = AV_CODEC_ID_VP5;
4117 } else if (!strcmp (mimetype, "video/x-vp6")) {
4118 id = AV_CODEC_ID_VP6;
4120 } else if (!strcmp (mimetype, "video/x-vp6-flash")) {
4121 id = AV_CODEC_ID_VP6F;
4123 } else if (!strcmp (mimetype, "video/x-vp6-alpha")) {
4124 id = AV_CODEC_ID_VP6A;
4126 } else if (!strcmp (mimetype, "video/x-vp8")) {
4127 id = AV_CODEC_ID_VP8;
4129 } else if (!strcmp (mimetype, "video/x-vp9")) {
4130 id = AV_CODEC_ID_VP9;
4132 } else if (!strcmp (mimetype, "video/x-flash-screen")) {
4133 id = AV_CODEC_ID_FLASHSV;
4135 } else if (!strcmp (mimetype, "video/x-flash-screen2")) {
4136 id = AV_CODEC_ID_FLASHSV2;
4138 } else if (!strcmp (mimetype, "video/x-cineform")) {
4139 id = AV_CODEC_ID_CFHD;
4141 } else if (!strcmp (mimetype, "video/x-speedhq")) {
4142 id = AV_CODEC_ID_SPEEDHQ;
4144 } else if (!strcmp (mimetype, "video/x-indeo")) {
4145 gint indeoversion = 0;
4147 if (gst_structure_get_int (structure, "indeoversion", &indeoversion)) {
4148 switch (indeoversion) {
4150 id = AV_CODEC_ID_INDEO5;
4153 id = AV_CODEC_ID_INDEO4;
4156 id = AV_CODEC_ID_INDEO3;
4159 id = AV_CODEC_ID_INDEO2;
4162 if (id != AV_CODEC_ID_NONE)
4165 } else if (!strcmp (mimetype, "video/x-divx")) {
4166 gint divxversion = 0;
4168 if (gst_structure_get_int (structure, "divxversion", &divxversion)) {
4169 switch (divxversion) {
4171 id = AV_CODEC_ID_MSMPEG4V3;
4175 id = AV_CODEC_ID_MPEG4;
4179 if (id != AV_CODEC_ID_NONE)
4181 } else if (!strcmp (mimetype, "video/x-ffv")) {
4182 gint ffvversion = 0;
4184 if (gst_structure_get_int (structure, "ffvversion", &ffvversion) &&
4186 id = AV_CODEC_ID_FFV1;
4189 } else if (!strcmp (mimetype, "video/x-apple-intermediate-codec")) {
4190 id = AV_CODEC_ID_AIC;
4192 } else if (!strcmp (mimetype, "audio/x-adpcm")) {
4193 const gchar *layout;
4195 layout = gst_structure_get_string (structure, "layout");
4196 if (layout == NULL) {
4198 } else if (!strcmp (layout, "quicktime")) {
4199 id = AV_CODEC_ID_ADPCM_IMA_QT;
4200 } else if (!strcmp (layout, "microsoft")) {
4201 id = AV_CODEC_ID_ADPCM_MS;
4202 } else if (!strcmp (layout, "dvi")) {
4203 id = AV_CODEC_ID_ADPCM_IMA_WAV;
4204 } else if (!strcmp (layout, "4xm")) {
4205 id = AV_CODEC_ID_ADPCM_4XM;
4206 } else if (!strcmp (layout, "smjpeg")) {
4207 id = AV_CODEC_ID_ADPCM_IMA_SMJPEG;
4208 } else if (!strcmp (layout, "dk3")) {
4209 id = AV_CODEC_ID_ADPCM_IMA_DK3;
4210 } else if (!strcmp (layout, "dk4")) {
4211 id = AV_CODEC_ID_ADPCM_IMA_DK4;
4212 } else if (!strcmp (layout, "oki")) {
4213 id = AV_CODEC_ID_ADPCM_IMA_OKI;
4214 } else if (!strcmp (layout, "westwood")) {
4215 id = AV_CODEC_ID_ADPCM_IMA_WS;
4216 } else if (!strcmp (layout, "iss")) {
4217 id = AV_CODEC_ID_ADPCM_IMA_ISS;
4218 } else if (!strcmp (layout, "xa")) {
4219 id = AV_CODEC_ID_ADPCM_XA;
4220 } else if (!strcmp (layout, "adx")) {
4221 id = AV_CODEC_ID_ADPCM_ADX;
4222 } else if (!strcmp (layout, "ea")) {
4223 id = AV_CODEC_ID_ADPCM_EA;
4224 } else if (!strcmp (layout, "g726")) {
4225 id = AV_CODEC_ID_ADPCM_G726;
4226 } else if (!strcmp (layout, "g721")) {
4227 id = AV_CODEC_ID_ADPCM_G726;
4228 } else if (!strcmp (layout, "ct")) {
4229 id = AV_CODEC_ID_ADPCM_CT;
4230 } else if (!strcmp (layout, "swf")) {
4231 id = AV_CODEC_ID_ADPCM_SWF;
4232 } else if (!strcmp (layout, "yamaha")) {
4233 id = AV_CODEC_ID_ADPCM_YAMAHA;
4234 } else if (!strcmp (layout, "sbpro2")) {
4235 id = AV_CODEC_ID_ADPCM_SBPRO_2;
4236 } else if (!strcmp (layout, "sbpro3")) {
4237 id = AV_CODEC_ID_ADPCM_SBPRO_3;
4238 } else if (!strcmp (layout, "sbpro4")) {
4239 id = AV_CODEC_ID_ADPCM_SBPRO_4;
4241 if (id != AV_CODEC_ID_NONE)
4243 } else if (!strcmp (mimetype, "video/x-4xm")) {
4244 id = AV_CODEC_ID_4XM;
4246 } else if (!strcmp (mimetype, "audio/x-dpcm")) {
4247 const gchar *layout;
4249 layout = gst_structure_get_string (structure, "layout");
4252 } else if (!strcmp (layout, "roq")) {
4253 id = AV_CODEC_ID_ROQ_DPCM;
4254 } else if (!strcmp (layout, "interplay")) {
4255 id = AV_CODEC_ID_INTERPLAY_DPCM;
4256 } else if (!strcmp (layout, "xan")) {
4257 id = AV_CODEC_ID_XAN_DPCM;
4258 } else if (!strcmp (layout, "sol")) {
4259 id = AV_CODEC_ID_SOL_DPCM;
4261 if (id != AV_CODEC_ID_NONE)
4263 } else if (!strcmp (mimetype, "audio/x-flac")) {
4264 id = AV_CODEC_ID_FLAC;
4266 } else if (!strcmp (mimetype, "audio/x-shorten")) {
4267 id = AV_CODEC_ID_SHORTEN;
4269 } else if (!strcmp (mimetype, "audio/x-alac")) {
4270 id = AV_CODEC_ID_ALAC;
4272 } else if (!strcmp (mimetype, "video/x-cinepak")) {
4273 id = AV_CODEC_ID_CINEPAK;
4275 } else if (!strcmp (mimetype, "video/x-pn-realvideo")) {
4278 if (gst_structure_get_int (structure, "rmversion", &rmversion)) {
4279 switch (rmversion) {
4281 id = AV_CODEC_ID_RV10;
4284 id = AV_CODEC_ID_RV20;
4287 id = AV_CODEC_ID_RV30;
4290 id = AV_CODEC_ID_RV40;
4294 if (id != AV_CODEC_ID_NONE)
4296 } else if (!strcmp (mimetype, "audio/x-sipro")) {
4297 id = AV_CODEC_ID_SIPR;
4299 } else if (!strcmp (mimetype, "audio/x-pn-realaudio")) {
4302 if (gst_structure_get_int (structure, "raversion", &raversion)) {
4303 switch (raversion) {
4305 id = AV_CODEC_ID_RA_144;
4308 id = AV_CODEC_ID_RA_288;
4311 id = AV_CODEC_ID_COOK;
4315 if (id != AV_CODEC_ID_NONE)
4317 } else if (!strcmp (mimetype, "video/x-rle")) {
4318 const gchar *layout;
4320 if ((layout = gst_structure_get_string (structure, "layout"))) {
4321 if (!strcmp (layout, "microsoft")) {
4322 id = AV_CODEC_ID_MSRLE;
4326 } else if (!strcmp (mimetype, "video/x-xan")) {
4329 if ((gst_structure_get_int (structure, "wcversion", &wcversion))) {
4330 switch (wcversion) {
4332 id = AV_CODEC_ID_XAN_WC3;
4336 id = AV_CODEC_ID_XAN_WC4;
4343 } else if (!strcmp (mimetype, "audio/AMR")) {
4345 id = AV_CODEC_ID_AMR_NB;
4346 } else if (!strcmp (mimetype, "audio/AMR-WB")) {
4347 id = AV_CODEC_ID_AMR_WB;
4349 } else if (!strcmp (mimetype, "audio/qcelp")) {
4350 id = AV_CODEC_ID_QCELP;
4352 } else if (!strcmp (mimetype, "video/x-h264")) {
4353 id = AV_CODEC_ID_H264;
4355 } else if (!strcmp (mimetype, "video/x-h265")) {
4356 id = AV_CODEC_ID_HEVC;
4358 } else if (!strcmp (mimetype, "video/x-flash-video")) {
4359 gint flvversion = 0;
4361 if ((gst_structure_get_int (structure, "flvversion", &flvversion))) {
4362 switch (flvversion) {
4364 id = AV_CODEC_ID_FLV1;
4372 } else if (!strcmp (mimetype, "audio/x-nellymoser")) {
4373 id = AV_CODEC_ID_NELLYMOSER;
4375 } else if (!strncmp (mimetype, "audio/x-gst-av-", 15)) {
4377 const AVCodec *codec;
4379 if (strlen (mimetype) <= 30 &&
4380 sscanf (mimetype, "audio/x-gst-av-%s", ext) == 1) {
4381 if ((codec = avcodec_find_decoder_by_name (ext)) ||
4382 (codec = avcodec_find_encoder_by_name (ext))) {
4387 } else if (!strncmp (mimetype, "video/x-gst-av-", 15)) {
4389 const AVCodec *codec;
4391 if (strlen (mimetype) <= 30 &&
4392 sscanf (mimetype, "video/x-gst-av-%s", ext) == 1) {
4393 if ((codec = avcodec_find_decoder_by_name (ext)) ||
4394 (codec = avcodec_find_encoder_by_name (ext))) {
4401 if (context != NULL) {
4402 if (video == TRUE) {
4403 context->codec_type = AVMEDIA_TYPE_VIDEO;
4404 } else if (audio == TRUE) {
4405 context->codec_type = AVMEDIA_TYPE_AUDIO;
4407 context->codec_type = AVMEDIA_TYPE_UNKNOWN;
4409 context->codec_id = id;
4410 gst_ffmpeg_caps_with_codecid (id, context->codec_type, caps, context);
4413 if (id != AV_CODEC_ID_NONE) {
4414 GST_DEBUG ("The id=%d belongs to the caps %" GST_PTR_FORMAT, id, caps);
4416 GST_WARNING ("Couldn't figure out the id for caps %" GST_PTR_FORMAT, caps);