Commit b5d688da authored by Jan Gerber's avatar Jan Gerber
Browse files

output per stream metadata

parent 65721116
......@@ -301,54 +301,6 @@ void json_codec_info(FILE *output, AVCodecContext *enc, int indent) {
}
}
static void json_stream_format(FILE *output, AVFormatContext *ic, int i, int indent, int first, int type_filter) {
static int _first = 1;
char buf1[32];
AVStream *st = ic->streams[i];
if (first)
_first = 1;
if(st->codec->codec_type == type_filter){
if (!_first)
fprintf(output, ", ");
_first = 0;
fprintf(output, "{\n");
json_codec_info(output, st->codec, indent + 1);
if(st->codec->codec_type == AVMEDIA_TYPE_VIDEO){
if (st->time_base.den && st->time_base.num && av_q2d(st->time_base) > 0.001) {
snprintf(buf1, sizeof(buf1), "%d:%d",
st->time_base.den, st->time_base.num);
json_add_key_value(output, "framerate", buf1, JSON_STRING, 0, indent + 1);
} else {
snprintf(buf1, sizeof(buf1), "%d:%d",
st->r_frame_rate.num, st->r_frame_rate.den);
json_add_key_value(output, "framerate", buf1, JSON_STRING, 0, indent + 1);
}
if (st->sample_aspect_ratio.num && // default
av_cmp_q(st->sample_aspect_ratio, st->codec->sample_aspect_ratio)) {
AVRational display_aspect_ratio;
av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
st->codec->width*st->sample_aspect_ratio.num,
st->codec->height*st->sample_aspect_ratio.den,
1024*1024);
snprintf(buf1, sizeof(buf1), "%d:%d",
st->sample_aspect_ratio.num, st->sample_aspect_ratio.den);
json_add_key_value(output, "pixel_aspect_ratio", buf1, JSON_STRING, 0, indent+1);
snprintf(buf1, sizeof(buf1), "%d:%d",
display_aspect_ratio.num, display_aspect_ratio.den);
json_add_key_value(output, "display_aspect_ratio", buf1, JSON_STRING, 0, indent+1);
}
}
json_add_key_value(output, "id", &i, JSON_INT, 1, indent + 1);
do_indent(output, indent-1);
fprintf(output, "}");
}
}
static int utf8_validate (char *s, int n) {
int i;
int extra_bytes;
......@@ -388,38 +340,79 @@ static int utf8_validate (char *s, int n) {
error:
return i == n;
}
int _json_metadata(FILE *output, AVDictionary *m, int first, int indent)
void json_metadata(FILE *output, AVDictionary *m, int indent)
{
int i = 0;
int first = 1;
AVDictionaryEntry *tag = NULL;
while ((tag = av_dict_get(m, "", tag, AV_DICT_IGNORE_SUFFIX))) {
if (strlen(tag->value) && utf8_validate (tag->value, strlen(tag->value))) {
if (first) {
first = 0;
do_indent(output, 1);
do_indent(output, indent);
fprintf(output, "\"metadata\": {\n");
do_indent(output, indent + 1);
} else {
do_indent(output, 2);
do_indent(output, indent + 1);
fprintf(output, ",");
indent=0;
}
json_add_key_value(output, tag->key, tag->value, JSON_STRING, 1, indent);
json_add_key_value(output, tag->key, tag->value, JSON_STRING, 1, 0);
}
}
return first;
if (!first) {
do_indent(output, indent);
fprintf(output, "},\n");
}
}
void json_metadata(FILE *output, const AVFormatContext *av)
{
int first = 1, indent=2, i=0;
first = _json_metadata(output, av->metadata, first, indent);
for(i=0;i<av->nb_streams;i++) {
first = _json_metadata(output, av->streams[i]->metadata, first, indent);
}
if (!first) {
do_indent(output, 1);
fprintf(output, "},\n");
static void json_stream_format(FILE *output, AVFormatContext *ic, int i, int indent, int first, int type_filter) {
static int _first = 1;
char buf1[32];
AVStream *st = ic->streams[i];
if (first)
_first = 1;
if(st->codec->codec_type == type_filter){
if (!_first)
fprintf(output, ", ");
_first = 0;
fprintf(output, "{\n");
json_codec_info(output, st->codec, indent + 1);
if(st->codec->codec_type == AVMEDIA_TYPE_VIDEO){
if (st->time_base.den && st->time_base.num && av_q2d(st->time_base) > 0.001) {
snprintf(buf1, sizeof(buf1), "%d:%d",
st->time_base.den, st->time_base.num);
json_add_key_value(output, "framerate", buf1, JSON_STRING, 0, indent + 1);
} else {
snprintf(buf1, sizeof(buf1), "%d:%d",
st->r_frame_rate.num, st->r_frame_rate.den);
json_add_key_value(output, "framerate", buf1, JSON_STRING, 0, indent + 1);
}
if (st->sample_aspect_ratio.num && // default
av_cmp_q(st->sample_aspect_ratio, st->codec->sample_aspect_ratio)) {
AVRational display_aspect_ratio;
av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
st->codec->width*st->sample_aspect_ratio.num,
st->codec->height*st->sample_aspect_ratio.den,
1024*1024);
snprintf(buf1, sizeof(buf1), "%d:%d",
st->sample_aspect_ratio.num, st->sample_aspect_ratio.den);
json_add_key_value(output, "pixel_aspect_ratio", buf1, JSON_STRING, 0, indent+1);
snprintf(buf1, sizeof(buf1), "%d:%d",
display_aspect_ratio.num, display_aspect_ratio.den);
json_add_key_value(output, "display_aspect_ratio", buf1, JSON_STRING, 0, indent+1);
}
}
json_metadata(output, st->metadata, indent + 1);
json_add_key_value(output, "id", &i, JSON_INT, 1, indent + 1);
do_indent(output, indent-1);
fprintf(output, "}");
}
}
......@@ -522,7 +515,7 @@ void json_format_info(FILE* output, AVFormatContext *ic, const char *url) {
}
}
fprintf(output, "],\n");
json_metadata(output, ic);
json_metadata(output, ic->metadata, 1);
} else {
json_add_key_value(output, "code", "badfile", JSON_STRING, 0, 1);
json_add_key_value(output, "error", "file does not exist or has unknown format.", JSON_STRING, 0, 1);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment