void ijkmeta_set_avformat_context_l(IjkMediaMeta *meta, AVFormatContext *ic) { if (!meta || !ic) return; if (ic->iformat && ic->iformat->name) ijkmeta_set_string_l(meta, IJKM_KEY_FORMAT, ic->iformat->name); if (ic->duration != AV_NOPTS_VALUE) ijkmeta_set_int64_l(meta, IJKM_KEY_DURATION_US, ic->duration); if (ic->start_time != AV_NOPTS_VALUE) ijkmeta_set_int64_l(meta, IJKM_KEY_START_US, ic->start_time); if (ic->bit_rate) ijkmeta_set_int64_l(meta, IJKM_KEY_BITRATE, ic->bit_rate); IjkMediaMeta *stream_meta = NULL; for (int i = 0; i < ic->nb_streams; i++) { if (!stream_meta) ijkmeta_destroy_p(&stream_meta); AVStream *st = ic->streams[i]; if (!st || !st->codec) continue; stream_meta = ijkmeta_create(); if (!stream_meta) continue; AVCodecContext *avctx = st->codec; const char *codec_name = avcodec_get_name(avctx->codec_id); if (codec_name) ijkmeta_set_string_l(stream_meta, IJKM_KEY_CODEC_NAME, codec_name); if (avctx->profile != FF_PROFILE_UNKNOWN) { const AVCodec *codec = avctx->codec ? avctx->codec : avcodec_find_decoder(avctx->codec_id); if (codec) { const char *profile = av_get_profile_name(codec, avctx->profile); if (profile) ijkmeta_set_string_l(stream_meta, IJKM_KEY_CODEC_PROFILE, profile); if (codec->long_name) ijkmeta_set_string_l(stream_meta, IJKM_KEY_CODEC_LONG_NAME, codec->long_name); ijkmeta_set_int64_l(stream_meta, IJKM_KEY_CODEC_LEVEL, avctx->level); if (avctx->pix_fmt != AV_PIX_FMT_NONE) ijkmeta_set_string_l(stream_meta, IJKM_KEY_CODEC_PIXEL_FORMAT, av_get_pix_fmt_name(avctx->pix_fmt)); } } int64_t bitrate = get_bit_rate(avctx); if (bitrate > 0) { ijkmeta_set_int64_l(stream_meta, IJKM_KEY_BITRATE, bitrate); } switch (avctx->codec_type) { case AVMEDIA_TYPE_VIDEO: { ijkmeta_set_string_l(stream_meta, IJKM_KEY_TYPE, IJKM_VAL_TYPE__VIDEO); if (avctx->width > 0) ijkmeta_set_int64_l(stream_meta, IJKM_KEY_WIDTH, avctx->width); if (avctx->height > 0) ijkmeta_set_int64_l(stream_meta, IJKM_KEY_HEIGHT, avctx->height); if (st->sample_aspect_ratio.num > 0 && st->sample_aspect_ratio.den > 0) { ijkmeta_set_int64_l(stream_meta, IJKM_KEY_SAR_NUM, avctx->sample_aspect_ratio.num); ijkmeta_set_int64_l(stream_meta, IJKM_KEY_SAR_DEN, avctx->sample_aspect_ratio.den); } if (st->avg_frame_rate.num > 0 && st->avg_frame_rate.den > 0) { ijkmeta_set_int64_l(stream_meta, IJKM_KEY_FPS_NUM, st->avg_frame_rate.num); ijkmeta_set_int64_l(stream_meta, IJKM_KEY_FPS_DEN, st->avg_frame_rate.den); } if (st->r_frame_rate.num > 0 && st->r_frame_rate.den > 0) { ijkmeta_set_int64_l(stream_meta, IJKM_KEY_TBR_NUM, st->avg_frame_rate.num); ijkmeta_set_int64_l(stream_meta, IJKM_KEY_TBR_DEN, st->avg_frame_rate.den); } break; } case AVMEDIA_TYPE_AUDIO: { ijkmeta_set_string_l(stream_meta, IJKM_KEY_TYPE, IJKM_VAL_TYPE__AUDIO); if (avctx->sample_rate) ijkmeta_set_int64_l(stream_meta, IJKM_KEY_SAMPLE_RATE, avctx->sample_rate); if (avctx->channel_layout) ijkmeta_set_int64_l(stream_meta, IJKM_KEY_CHANNEL_LAYOUT, avctx->channel_layout); break; } default: { ijkmeta_set_string_l(stream_meta, IJKM_KEY_TYPE, IJKM_VAL_TYPE__UNKNOWN); break; } } AVDictionaryEntry *lang = av_dict_get(st->metadata, "language", NULL, 0); if (lang && lang->value) ijkmeta_set_string_l(stream_meta, IJKM_KEY_LANGUAGE, lang->value); ijkmeta_append_child_l(meta, stream_meta); stream_meta = NULL; } if (!stream_meta) ijkmeta_destroy_p(&stream_meta); }
audio_encoder_settings_ptr audio_encoder_settings::duplicate() const { return audio_encoder_settings_ptr( new audio_encoder_settings( new audio_encoder_settings::Impl( get_mode(), get_bit_rate(), get_quality() ) ) ); }
std::string lavf_get_stream_description(AVStream *pStream) { AVCodecContext *enc = pStream->codec; std::string codec_name = get_codec_name(enc); const char *lang = get_stream_language(pStream); std::string sLanguage; if(lang) { sLanguage = ProbeLangForLanguage(lang); if (sLanguage.empty()) { sLanguage = lang; } } char *title = nullptr; if (AVDictionaryEntry *dictEntry = av_dict_get(pStream->metadata, "title", nullptr, 0)) { title = dictEntry->value; } else if (AVDictionaryEntry *dictEntry = av_dict_get(pStream->metadata, "handler_name", nullptr, 0)) { title = dictEntry->value; if (strcmp(title, "GPAC ISO Video Handler") == 0 || strcmp(title, "VideoHandler") == 0|| strcmp(title, "GPAC ISO Audio Handler") == 0 || strcmp(title, "GPAC Streaming Text Handler") == 0) title = nullptr; } // Empty titles are rather useless if (title && strlen(title) == 0) title = nullptr; int bitrate = get_bit_rate(enc); std::ostringstream buf; switch(enc->codec_type) { case AVMEDIA_TYPE_VIDEO: buf << "V: "; // Title/Language if (title && lang) { buf << title << " [" << lang << "] ("; } else if (title) { // Print either title or lang buf << title << " ("; } else if (lang) { buf << sLanguage << " [" << lang << "] ("; } // Codec buf << codec_name; // Pixel Format if (enc->pix_fmt != AV_PIX_FMT_NONE) { buf << ", " << av_get_pix_fmt_name(enc->pix_fmt); } // Dimensions if (enc->width) { buf << ", " << enc->width << "x" << enc->height; } // Bitrate if (bitrate > 0) { buf << ", " << (bitrate / 1000) << " kb/s"; } // Closing tag if (title || lang) { buf << ")"; } buf << format_flags(pStream->disposition); break; case AVMEDIA_TYPE_AUDIO: buf << "A: "; // Title/Language if (title && lang) { buf << title << " [" << lang << "] ("; } else if (title) { // Print either title or lang buf << title << " ("; } else if (lang) { buf << sLanguage << " [" << lang << "] ("; } // Codec buf << codec_name; // Sample Rate if (enc->sample_rate) { buf << ", " << enc->sample_rate << " Hz"; } if (enc->channels) { // Get channel layout char channel[32]; av_get_channel_layout_string(channel, 32, enc->channels, enc->channel_layout); buf << ", " << channel; } // Sample Format if (show_sample_fmt(enc->codec_id) && get_bits_per_sample(enc, true)) { if (enc->sample_fmt == AV_SAMPLE_FMT_FLT || enc->sample_fmt == AV_SAMPLE_FMT_DBL) { buf << ", fp"; } else { buf << ", s"; } buf << get_bits_per_sample(enc, true); } // Bitrate if (bitrate > 0) { buf << ", " << (bitrate / 1000) << " kb/s"; } // Closing tag if (title || lang) { buf << ")"; } // Flags buf << format_flags(pStream->disposition); break; case AVMEDIA_TYPE_SUBTITLE: buf << "S: "; // Title/Language if (title && lang) { buf << title << " [" << lang << "] ("; } else if (title) { // Print either title or lang buf << title << " ("; } else if (lang) { buf << sLanguage << " [" << lang << "] ("; } // Codec buf << codec_name; if (title || lang) { buf << ")"; } // Subtitle flags buf << format_flags(pStream->disposition); break; default: buf << "Unknown: Stream #" << pStream->index; break; } return buf.str(); }
std::string lavf_get_stream_description(const AVStream *pStream) { AVCodecParameters *par = pStream->codecpar; std::string codec_name = get_codec_name(par); const char *lang = get_stream_language(pStream); std::string sLanguage; if(lang) { sLanguage = ProbeLangForLanguage(lang); if (sLanguage.empty()) { sLanguage = lang; } } const char * title = lavf_get_stream_title(pStream); // Empty titles are rather useless if (title && strlen(title) == 0) title = nullptr; int64_t bitrate = get_bit_rate(par); std::ostringstream buf; switch(par->codec_type) { case AVMEDIA_TYPE_VIDEO: buf << "V: "; // Title/Language if (title && lang) { buf << title << " [" << lang << "] ("; } else if (title) { // Print either title or lang buf << title << " ("; } else if (lang) { buf << sLanguage << " [" << lang << "] ("; } // Codec buf << codec_name; // Pixel Format if (const char *pix_fmt = av_get_pix_fmt_name((AVPixelFormat)par->format)) { buf << ", " << pix_fmt; } // Dimensions if (par->width) { buf << ", " << par->width << "x" << par->height; } // Bitrate if (bitrate > 0) { buf << ", " << (bitrate / 1000) << " kb/s"; } if (par->codec_id == AV_CODEC_ID_H264 && par->profile == FF_PROFILE_H264_STEREO_HIGH) { AVDictionaryEntry *entry = av_dict_get(pStream->metadata, "stereo_mode", nullptr, 0); if (entry && strcmp(entry->value, "mvc_lr") == 0) buf << ", lr"; else if (entry && strcmp(entry->value, "mvc_rl") == 0) buf << ", rl"; } // Closing tag if (title || lang) { buf << ")"; } buf << format_flags(pStream->disposition); break; case AVMEDIA_TYPE_AUDIO: buf << "A: "; // Title/Language if (title && lang) { buf << title << " [" << lang << "] ("; } else if (title) { // Print either title or lang buf << title << " ("; } else if (lang) { buf << sLanguage << " [" << lang << "] ("; } // Codec buf << codec_name; // Sample Rate if (par->sample_rate) { buf << ", " << par->sample_rate << " Hz"; } if (par->channels) { // Get channel layout char channel[32]; av_get_channel_layout_string(channel, 32, par->channels, par->channel_layout); buf << ", " << channel; } // Sample Format if (show_sample_fmt(par) && get_bits_per_sample(par, true)) { if (par->format == AV_SAMPLE_FMT_FLT || par->format == AV_SAMPLE_FMT_DBL) { buf << ", fp"; } else { buf << ", s"; } buf << get_bits_per_sample(par, true); } // Bitrate if (bitrate > 0) { buf << ", " << (bitrate / 1000) << " kb/s"; } // Closing tag if (title || lang) { buf << ")"; } // Flags buf << format_flags(pStream->disposition); break; case AVMEDIA_TYPE_SUBTITLE: buf << "S: "; // Title/Language if (title && lang) { buf << title << " [" << lang << "] ("; } else if (title) { // Print either title or lang buf << title << " ("; } else if (lang) { buf << sLanguage << " [" << lang << "] ("; } // Codec buf << codec_name; if (title || lang) { buf << ")"; } // Subtitle flags buf << format_flags(pStream->disposition); break; default: buf << "Unknown: Stream #" << pStream->index; break; } return buf.str(); }