r7791 - in trunk/libavformat: asf.c asf.h
Author: michael Date: Thu Feb 1 00:32:01 2007 New Revision: 7791 Modified: trunk/libavformat/asf.c trunk/libavformat/asf.h Log: extract aspect ratio Modified: trunk/libavformat/asf.c ============================================================================== --- trunk/libavformat/asf.c (original) +++ trunk/libavformat/asf.c Thu Feb 1 00:32:01 2007 @@ -67,6 +67,7 @@ else PRINT_IF_GUID(g, extended_content_header); else PRINT_IF_GUID(g, ext_stream_embed_stream_header); else PRINT_IF_GUID(g, ext_stream_audio_stream); + else PRINT_IF_GUID(g, metadata_header); else printf("(GUID: unknown) "); for(i=0;i<16;i++) @@ -123,6 +124,16 @@ return 0; } +static int get_value(ByteIOContext *pb, int type){ + switch(type){ + case 2: return get_le32(pb); + case 3: return get_le32(pb); + case 4: return get_le64(pb); + case 5: return get_le16(pb); + default:return INT_MIN; + } +} + static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap) { ASFContext *asf = s->priv_data; @@ -132,6 +143,9 @@ ASFStream *asf_st; int size, i; int64_t gsize; + AVRational dar[128]; + + memset(dar, 0, sizeof(dar)); get_guid(pb, &g); if (memcmp(&g, &asf_header, sizeof(GUID))) @@ -353,14 +367,34 @@ } if ((value_type >= 2) && (value_type <= 5)) // boolean or DWORD or QWORD or WORD { - if (value_type==2) value_num = get_le32(pb); - if (value_type==3) value_num = get_le32(pb); - if (value_type==4) value_num = get_le64(pb); - if (value_type==5) value_num = get_le16(pb); + value_num= get_value(pb, value_type); if (!strcmp(name,"WM/Track" )) s->track = value_num + 1; if (!strcmp(name,"WM/TrackNumber")) s->track = value_num; } } + } else if (!memcmp(&g, &metadata_header, sizeof(GUID))) { + int n, stream_num, name_len, value_len, value_type, value_num; + n = get_le16(pb); + + for(i=0;i<n;i++) { + char name[1024]; + + get_le16(pb); //lang_list_index + stream_num= get_le16(pb); + name_len= get_le16(pb); + value_type= get_le16(pb); + value_len= get_le32(pb); + + get_str16_nolen(pb, name_len, name, sizeof(name)); +//av_log(NULL, AV_LOG_ERROR, "%d %d %d %d %d <%s>\n", i, stream_num, name_len, value_type, value_len, name); + value_num= get_le16(pb);//we should use get_value() here but it doesnt work 2 is le16 here but le32 elsewhere + url_fskip(pb, value_len - 2); + + if(stream_num<128){ + if (!strcmp(name, "AspectRatioX")) dar[stream_num].num= value_num; + else if(!strcmp(name, "AspectRatioY")) dar[stream_num].den= value_num; + } + } } else if (!memcmp(&g, &ext_stream_header, sizeof(GUID))) { int ext_len, payload_ext_ct, stream_ct; uint32_t ext_d; @@ -443,6 +477,20 @@ asf->data_offset = url_ftell(pb); asf->packet_size_left = 0; + + for(i=0; i<128; i++){ + int stream_num= asf->asfid2avid[i]; + if(stream_num>=0 && dar[i].num>0 && dar[i].den>0){ + AVCodecContext *codec= s->streams[stream_num]->codec; + codec->sample_aspect_ratio= + av_div_q( + dar[i], + (AVRational){codec->width, codec->height} + ); +//av_log(NULL, AV_LOG_ERROR, "dar %d:%d sar=%d:%d\n", dar[i].num, dar[i].den, codec->sample_aspect_ratio.num, codec->sample_aspect_ratio.den); + } + } + return 0; fail: Modified: trunk/libavformat/asf.h ============================================================================== --- trunk/libavformat/asf.h (original) +++ trunk/libavformat/asf.h Thu Feb 1 00:32:01 2007 @@ -208,6 +208,10 @@ 0x9d, 0x8c, 0x17, 0x31, 0xE1, 0x03, 0x28, 0x45, 0xb5, 0x82, 0x3d, 0xf9, 0xdb, 0x22, 0xf5, 0x03 }; +static const GUID metadata_header = { + 0xea, 0xcb, 0xf8, 0xc5, 0xaf, 0x5b, 0x77, 0x48, 0x84, 0x67, 0xaa, 0x8c, 0x44, 0xfa, 0x4c, 0xca +}; + /* I am not a number !!! This GUID is the one found on the PC used to generate the stream */ static const GUID my_guid = {
participants (1)
-
subversion@mplayerhq.hu