+ /* write meta_tag */
+ put_byte(pb, 18); // tag type META
+ metadata_size_pos= url_ftell(pb);
+ put_be24(pb, 0); // size of data part (sum of all parts below)
+ put_be24(pb, 0); // time stamp
+ put_be32(pb, 0); // reserved
+
+ /* now data of data_size size */
+
+ /* first event name as a string */
+ put_byte(pb, AMF_DATA_TYPE_STRING);
+ put_amf_string(pb, "onMetaData"); // 12 bytes
+
+ /* mixed array (hash) with size and string/type/data tuples */
+ put_byte(pb, AMF_DATA_TYPE_MIXEDARRAY);
+ put_be32(pb, 5*flv->hasVideo + 4*flv->hasAudio + 2); // +2 for duration and file size
+
+ put_amf_string(pb, "duration");
+ flv->duration_offset= url_ftell(pb);
+ put_amf_double(pb, 0); // delayed write
+
+ if(flv->hasVideo){
+ put_amf_string(pb, "width");
+ put_amf_double(pb, width);
+
+ put_amf_string(pb, "height");
+ put_amf_double(pb, height);
+
+ put_amf_string(pb, "videodatarate");
+ put_amf_double(pb, s->bit_rate / 1024.0);
+
+ put_amf_string(pb, "framerate");
+ put_amf_double(pb, framerate);
+
+ put_amf_string(pb, "videocodecid");
+ put_amf_double(pb, videocodecid);
+ }
+
+ if(flv->hasAudio){
+ put_amf_string(pb, "audiosamplerate");
+ put_amf_double(pb, samplerate);
+
+ put_amf_string(pb, "audiosamplesize");
+ put_amf_double(pb, samplesize);
+
+ put_amf_string(pb, "stereo");
+ put_amf_bool(pb, (channels == 2));
+
+ put_amf_string(pb, "audiocodecid");
+ put_amf_double(pb, audiocodecid);
+ }
+
+ put_amf_string(pb, "filesize");
+ flv->filesize_offset= url_ftell(pb);
+ put_amf_double(pb, 0); // delayed write
+
+ put_amf_string(pb, "");
+ put_byte(pb, AMF_END_OF_OBJECT);
+
+ /* write total size of tag */
+ data_size= url_ftell(pb) - metadata_size_pos - 10;
+ url_fseek(pb, metadata_size_pos, SEEK_SET);
+ put_be24(pb, data_size);
+ url_fseek(pb, data_size + 10 - 3, SEEK_CUR);
+ put_be32(pb, data_size + 11);
+