Example #1
0
void
mp_set_mq_meta(media_queue_t *mq, const AVCodec *codec, 
	       const AVCodecContext *avctx)
{
  char buf[128];
  metadata_from_libav(buf, sizeof(buf), codec, avctx);
  prop_set_string(mq->mq_prop_codec, buf);
}
Example #2
0
static void
fa_lavf_load_meta(metadata_t *md, AVFormatContext *fctx,
		  const char *filename)
{
  int i;
  char tmp1[1024];
  int has_video = 0;
  int has_audio = 0;

  md->md_artist = ffmpeg_metadata_rstr(fctx->metadata, "artist") ?:
    ffmpeg_metadata_rstr(fctx->metadata, "author");

  md->md_album = ffmpeg_metadata_rstr(fctx->metadata, "album");

  md->md_format = rstr_alloc(fctx->iformat->long_name);

  if(fctx->duration != AV_NOPTS_VALUE)
    md->md_duration = (float)fctx->duration / 1000000;

  for(i = 0; i < fctx->nb_streams; i++) {
    AVStream *stream = fctx->streams[i];
    AVCodecContext *avctx = stream->codec;

    if(avctx->codec_type == AVMEDIA_TYPE_AUDIO)
      has_audio = 1;

    if(avctx->codec_type == AVMEDIA_TYPE_VIDEO &&
       !(stream->disposition & AV_DISPOSITION_ATTACHED_PIC))
      has_video = 1;
  }

  if(has_audio && !has_video) {
    md->md_contenttype = CONTENT_AUDIO;

    md->md_title = ffmpeg_metadata_rstr(fctx->metadata, "title");
    md->md_track = ffmpeg_metadata_int(fctx->metadata, "track",
				       filename ? atoi(filename) : 0);

    return;
  }

  has_audio = 0;
  has_video = 0;

  if(1) {

    int atrack = 0;
    int strack = 0;
    int vtrack = 0;

    /* Check each stream */

    for(i = 0; i < fctx->nb_streams; i++) {
      AVStream *stream = fctx->streams[i];
      AVCodecContext *avctx = stream->codec;
      AVCodec *codec = avcodec_find_decoder(avctx->codec_id);
      AVDictionaryEntry *lang, *title;
      int tn;
      char str[256];

      avcodec_string(str, sizeof(str), avctx, 0);
      TRACE(TRACE_DEBUG, "Probe", " Stream #%d: %s", i, str);

      switch(avctx->codec_type) {
      case AVMEDIA_TYPE_VIDEO:
	has_video = !!codec;
	tn = ++vtrack;
	break;
      case AVMEDIA_TYPE_AUDIO:
	has_audio = !!codec;
	tn = ++atrack;
	break;
      case AVMEDIA_TYPE_SUBTITLE:
	tn = ++strack;
	break;

      default:
	continue;
      }

      if(codec == NULL) {
	snprintf(tmp1, sizeof(tmp1), "%s", codecname(avctx->codec_id));
      } else {
	metadata_from_libav(tmp1, sizeof(tmp1), codec, avctx);
      }

      lang = av_dict_get(stream->metadata, "language", NULL,
                         AV_DICT_IGNORE_SUFFIX);

      title = av_dict_get(stream->metadata, "title", NULL,
                          AV_DICT_IGNORE_SUFFIX);

      metadata_add_stream(md, codecname(avctx->codec_id),
			  avctx->codec_type, i,
			  title ? title->value : NULL,
			  tmp1,
			  lang ? lang->value : NULL,
			  stream->disposition,
			  tn);
    }
  
    md->md_contenttype = CONTENT_FILE;
    if(has_video) {
      md->md_contenttype = CONTENT_VIDEO;
    } else if(has_audio) {
      md->md_contenttype = CONTENT_AUDIO;
    }
  }
}