void plex_report_stream_detail(const AVStream *st) { if ((st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO || st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) && st->codec_info_nb_frames == 0) return; // Unparsed stream; will be skipped in output if (plexContext.progress_url && (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO || st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO || st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) && !(st->disposition & AV_DISPOSITION_ATTACHED_PIC)) { char url[4096]; AVBPrint dstbuf; AVDictionaryEntry *lang = av_dict_get(st->metadata, "language", NULL, 0); const char *profile = avcodec_profile_name(st->codecpar->codec_id, st->codecpar->profile); av_bprint_init_for_buffer(&dstbuf, url, sizeof(url)); av_bprintf(&dstbuf, "%s/streamDetail?index=%i&id=%i&codec=%s&type=%s", plexContext.progress_url, st->index, st->id, avcodec_get_name(st->codecpar->codec_id), av_get_media_type_string(st->codecpar->codec_type)); if (st->codecpar->bit_rate) av_bprintf(&dstbuf, "&bitrate=%"PRId64, st->codecpar->bit_rate); if (profile) { av_bprintf(&dstbuf, "&profile="); av_bprint_escape(&dstbuf, profile, NULL, AV_ESCAPE_MODE_URL, 0); } if (lang && lang->value && *lang->value) { av_bprintf(&dstbuf, "&language="); av_bprint_escape(&dstbuf, lang->value, NULL, AV_ESCAPE_MODE_URL, 0); } if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { av_bprintf(&dstbuf, "&width=%i&height=%i", st->codecpar->width, st->codecpar->height); av_bprintf(&dstbuf, "&interlaced=%i", (st->codecpar->field_order != AV_FIELD_PROGRESSIVE && st->codecpar->field_order != AV_FIELD_UNKNOWN)); if (st->codecpar->separate_fields) av_bprintf(&dstbuf, "&separateFields=1"); if (st->codecpar->sample_aspect_ratio.num && st->codecpar->sample_aspect_ratio.den) av_bprintf(&dstbuf, "&sar=%d:%d", st->codecpar->sample_aspect_ratio.num, st->codecpar->sample_aspect_ratio.den); if (st->codecpar->level != FF_LEVEL_UNKNOWN) av_bprintf(&dstbuf, "&level=%d", st->codecpar->level); if (st->avg_frame_rate.num && st->avg_frame_rate.den) av_bprintf(&dstbuf, "&frameRate=%.3f", av_q2d(st->avg_frame_rate)); if (st->internal && st->internal->avctx && st->internal->avctx->properties & FF_CODEC_PROPERTY_CLOSED_CAPTIONS) av_bprintf(&dstbuf, "&closedCaptions=1"); } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { char layout[256]; char *layoutP = layout; char *l, *r; av_bprintf(&dstbuf, "&channels=%i", st->codecpar->channels); av_get_channel_layout_string(layout, sizeof(layout), st->codecpar->channels, st->codecpar->channel_layout); l = strchr(layout, '('); r = strrchr(layout, ')'); if (l && r && l > layoutP + 8) { layoutP = l + 1; *r = 0; } av_bprintf(&dstbuf, "&layout="); av_bprint_escape(&dstbuf, layout, NULL, AV_ESCAPE_MODE_URL, 0); av_bprintf(&dstbuf, "&sampleRate=%i", st->codecpar->sample_rate); if (st->codecpar->bits_per_raw_sample) av_bprintf(&dstbuf, "&bitDepth=%i", st->codecpar->bits_per_raw_sample); } #define SEND_DISPOSITION(flagname, name) if (st->disposition & AV_DISPOSITION_##flagname) \ av_bprintf(&dstbuf, "&disp_" name "=1"); SEND_DISPOSITION(DEFAULT, "default"); SEND_DISPOSITION(DUB, "dub"); SEND_DISPOSITION(ORIGINAL, "original"); SEND_DISPOSITION(COMMENT, "comment"); SEND_DISPOSITION(LYRICS, "lyrics"); SEND_DISPOSITION(KARAOKE, "karaoke"); SEND_DISPOSITION(FORCED, "forced"); SEND_DISPOSITION(HEARING_IMPAIRED, "hearing_impaired"); SEND_DISPOSITION(VISUAL_IMPAIRED, "visual_impaired"); SEND_DISPOSITION(CLEAN_EFFECTS, "clean_effects"); SEND_DISPOSITION(ATTACHED_PIC, "attached_pic"); SEND_DISPOSITION(TIMED_THUMBNAILS, "timed_thumbnails"); av_free(PMS_IssueHttpRequest(url, "PUT")); } }
static void show_stream(InputFile *ifile, InputStream *ist) { AVFormatContext *fmt_ctx = ifile->fmt_ctx; AVStream *stream = ist->st; AVCodecParameters *par; AVCodecContext *dec_ctx; const AVCodecDescriptor *codec_desc; const char *profile; char val_str[128]; AVRational display_aspect_ratio, *sar = NULL; const AVPixFmtDescriptor *desc; probe_object_header("stream"); probe_int("index", stream->index); par = stream->codecpar; dec_ctx = ist->dec_ctx; codec_desc = avcodec_descriptor_get(par->codec_id); if (codec_desc) { probe_str("codec_name", codec_desc->name); probe_str("codec_long_name", codec_desc->long_name); } else { probe_str("codec_name", "unknown"); } probe_str("codec_type", media_type_string(par->codec_type)); /* print AVI/FourCC tag */ av_get_codec_tag_string(val_str, sizeof(val_str), par->codec_tag); probe_str("codec_tag_string", val_str); probe_str("codec_tag", tag_string(val_str, sizeof(val_str), par->codec_tag)); /* print profile, if there is one */ profile = avcodec_profile_name(par->codec_id, par->profile); if (profile) probe_str("profile", profile); switch (par->codec_type) { case AVMEDIA_TYPE_VIDEO: probe_int("width", par->width); probe_int("height", par->height); if (dec_ctx) { probe_int("coded_width", dec_ctx->coded_width); probe_int("coded_height", dec_ctx->coded_height); probe_int("has_b_frames", dec_ctx->has_b_frames); } if (dec_ctx && dec_ctx->sample_aspect_ratio.num) sar = &dec_ctx->sample_aspect_ratio; else if (par->sample_aspect_ratio.num) sar = &par->sample_aspect_ratio; else if (stream->sample_aspect_ratio.num) sar = &stream->sample_aspect_ratio; if (sar) { probe_str("sample_aspect_ratio", rational_string(val_str, sizeof(val_str), ":", sar)); av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den, par->width * sar->num, par->height * sar->den, 1024*1024); probe_str("display_aspect_ratio", rational_string(val_str, sizeof(val_str), ":", &display_aspect_ratio)); } desc = av_pix_fmt_desc_get(par->format); probe_str("pix_fmt", desc ? desc->name : "unknown"); probe_int("level", par->level); probe_str("color_range", av_color_range_name (par->color_range)); probe_str("color_space", av_color_space_name (par->color_space)); probe_str("color_trc", av_color_transfer_name (par->color_trc)); probe_str("color_pri", av_color_primaries_name(par->color_primaries)); probe_str("chroma_loc", av_chroma_location_name (par->chroma_location)); break; case AVMEDIA_TYPE_AUDIO: probe_str("sample_rate", value_string(val_str, sizeof(val_str), par->sample_rate, unit_hertz_str)); probe_int("channels", par->channels); probe_int("bits_per_sample", av_get_bits_per_sample(par->codec_id)); break; } if (fmt_ctx->iformat->flags & AVFMT_SHOW_IDS) probe_int("id", stream->id); probe_str("avg_frame_rate", rational_string(val_str, sizeof(val_str), "/", &stream->avg_frame_rate)); if (par->bit_rate) probe_str("bit_rate", value_string(val_str, sizeof(val_str), par->bit_rate, unit_bit_per_second_str)); probe_str("time_base", rational_string(val_str, sizeof(val_str), "/", &stream->time_base)); probe_str("start_time", time_value_string(val_str, sizeof(val_str), stream->start_time, &stream->time_base)); probe_str("duration", time_value_string(val_str, sizeof(val_str), stream->duration, &stream->time_base)); if (stream->nb_frames) probe_int("nb_frames", stream->nb_frames); probe_dict(stream->metadata, "tags"); if (stream->nb_side_data) { int i, j; probe_object_header("sidedata"); for (i = 0; i < stream->nb_side_data; i++) { const AVPacketSideData* sd = &stream->side_data[i]; AVStereo3D *stereo; switch (sd->type) { case AV_PKT_DATA_DISPLAYMATRIX: probe_object_header("displaymatrix"); probe_array_header("matrix", 1); for (j = 0; j < 9; j++) probe_int(NULL, ((int32_t *)sd->data)[j]); probe_array_footer("matrix", 1); probe_int("rotation", av_display_rotation_get((int32_t *)sd->data)); probe_object_footer("displaymatrix"); break; case AV_PKT_DATA_STEREO3D: stereo = (AVStereo3D *)sd->data; probe_object_header("stereo3d"); probe_str("type", av_stereo3d_type_name(stereo->type)); probe_int("inverted", !!(stereo->flags & AV_STEREO3D_FLAG_INVERT)); probe_object_footer("stereo3d"); break; } } probe_object_footer("sidedata"); } probe_object_footer("stream"); }
std::string get_codec_name(AVCodecContext *pCodecCtx) { AVCodecID id = pCodecCtx->codec_id; // Grab the codec const AVCodec *p = avcodec_find_decoder(id); const AVCodecDescriptor *desc = avcodec_descriptor_get(id); const char *profile = avcodec_profile_name(id, pCodecCtx->profile); std::ostringstream codec_name; const char *nice_name = nullptr; for (int i = 0; i < countof(nice_codec_names); ++i) { if (nice_codec_names[i].id == id) { nice_name = nice_codec_names[i].name; break; } } if (id == AV_CODEC_ID_DTS && pCodecCtx->codec_tag == 0xA2) { profile = "DTS Express"; } if (id == AV_CODEC_ID_H264 && profile) { codec_name << nice_name << " " << tolower(profile); if (pCodecCtx->level && pCodecCtx->level != FF_LEVEL_UNKNOWN && pCodecCtx->level < 1000) { char l_buf[5]; sprintf_s(l_buf, "%.1f", pCodecCtx->level / 10.0); codec_name << " L" << l_buf; } } else if (id == AV_CODEC_ID_VC1 && profile) { codec_name << nice_name << " " << tolower(profile); if (pCodecCtx->level != FF_LEVEL_UNKNOWN) { codec_name << " L" << pCodecCtx->level; } } else if (id == AV_CODEC_ID_DTS && profile) { codec_name << tolower(profile); } else if (id == AV_CODEC_ID_JPEG2000 && profile) { codec_name << tolower(profile); } else if (nice_name) { codec_name << nice_name; if (profile) codec_name << " " << tolower(profile); } else if (desc && desc->name) { codec_name << desc->name; if (profile) codec_name << " " << tolower(profile); } else if (p && p->name) { codec_name << p->name; if (profile) codec_name << " " << tolower(profile); } else { /* output avi tags */ char buf[32]; av_get_codec_tag_string(buf, sizeof(buf), pCodecCtx->codec_tag); codec_name << buf; sprintf_s(buf, "0x%04X", pCodecCtx->codec_tag); codec_name << " / " << buf; } return codec_name.str(); }