comparison movenc.c @ 3456:fb5dd21f7e18 libavformat

factorize psp metadata
author bcoudurier
date Wed, 11 Jun 2008 09:02:01 +0000
parents aefb1cbf9479
children 0bbc97acefde
comparison
equal deleted inserted replaced
3455:aefb1cbf9479 3456:fb5dd21f7e18
1252 static uint16_t language_code(const char *str) 1252 static uint16_t language_code(const char *str)
1253 { 1253 {
1254 return (((str[0]-0x60) & 0x1F) << 10) + (((str[1]-0x60) & 0x1F) << 5) + ((str[2]-0x60) & 0x1F); 1254 return (((str[0]-0x60) & 0x1F) << 10) + (((str[1]-0x60) & 0x1F) << 5) + ((str[2]-0x60) & 0x1F);
1255 } 1255 }
1256 1256
1257 static int mov_write_psp_udta_tag(ByteIOContext *pb,
1258 const char *str, const char *lang, int type)
1259 {
1260 int len = utf8len(str)+1;
1261 if(len<=0)
1262 return 0;
1263 put_be16(pb, len*2+10); /* size */
1264 put_be32(pb, type); /* type */
1265 put_be16(pb, language_code(lang)); /* language */
1266 put_be16(pb, 0x01); /* ? */
1267 ascii_to_wc(pb, str);
1268 return len*2+10;
1269 }
1270
1257 static int mov_write_uuidusmt_tag(ByteIOContext *pb, AVFormatContext *s) 1271 static int mov_write_uuidusmt_tag(ByteIOContext *pb, AVFormatContext *s)
1258 { 1272 {
1259 size_t len, size; 1273 size_t size;
1260 offset_t pos, curpos; 1274 offset_t pos, curpos;
1261 1275
1262 size = 0; 1276 size = 0;
1263 if (s->title[0]) { 1277 if (s->title[0]) {
1264 pos = url_ftell(pb); 1278 pos = url_ftell(pb);
1281 put_be16(pb, language_code("und")); /* language */ 1295 put_be16(pb, language_code("und")); /* language */
1282 put_be16(pb, 0x0); /* ? */ 1296 put_be16(pb, 0x0); /* ? */
1283 put_be16(pb, 0x021C); /* data */ 1297 put_be16(pb, 0x021C); /* data */
1284 size += 12; 1298 size += 12;
1285 1299
1286 // Encoder 1300 size += mov_write_psp_udta_tag(pb, LIBAVCODEC_IDENT, "eng", 0x04);
1287 len = utf8len(LIBAVCODEC_IDENT)+1; 1301 size += mov_write_psp_udta_tag(pb, s->title, "eng", 0x01);
1288 if(len<=0)
1289 goto not_utf8;
1290 put_be16(pb, len*2+10); /* size */
1291 put_be32(pb, 0x04); /* type */
1292 put_be16(pb, language_code("eng")); /* language */
1293 put_be16(pb, 0x01); /* ? */
1294 ascii_to_wc(pb, LIBAVCODEC_IDENT);
1295 size += len*2+10;
1296
1297 // Title
1298 len = utf8len(s->title)+1;
1299 if(len<=0)
1300 goto not_utf8;
1301 put_be16(pb, len*2+10); /* size */
1302 put_be32(pb, 0x01); /* type */
1303 put_be16(pb, language_code("eng")); /* language */
1304 put_be16(pb, 0x01); /* ? */
1305 ascii_to_wc(pb, s->title);
1306 size += len*2+10;
1307
1308 // Date
1309 // snprintf(dt,32,"%04d/%02d/%02d %02d:%02d:%02d",t_st->tm_year+1900,t_st->tm_mon+1,t_st->tm_mday,t_st->tm_hour,t_st->tm_min,t_st->tm_sec); 1302 // snprintf(dt,32,"%04d/%02d/%02d %02d:%02d:%02d",t_st->tm_year+1900,t_st->tm_mon+1,t_st->tm_mday,t_st->tm_hour,t_st->tm_min,t_st->tm_sec);
1310 len = utf8len("2006/04/01 11:11:11")+1; 1303 size += mov_write_psp_udta_tag(pb, "2006/04/01 11:11:11", "und", 0x03);
1311 if(len<=0)
1312 goto not_utf8;
1313 put_be16(pb, len*2+10); /* size */
1314 put_be32(pb, 0x03); /* type */
1315 put_be16(pb, language_code("und")); /* language */
1316 put_be16(pb, 0x01); /* ? */
1317 ascii_to_wc(pb, "2006/04/01 11:11:11");
1318 size += len*2+10;
1319 1304
1320 // size 1305 // size
1321 curpos = url_ftell(pb); 1306 curpos = url_ftell(pb);
1322 url_fseek(pb, pos, SEEK_SET); 1307 url_fseek(pb, pos, SEEK_SET);
1323 put_be32(pb, size); 1308 put_be32(pb, size);
1325 put_be32(pb, size-24); 1310 put_be32(pb, size-24);
1326 url_fseek(pb, curpos, SEEK_SET); 1311 url_fseek(pb, curpos, SEEK_SET);
1327 } 1312 }
1328 1313
1329 return size; 1314 return size;
1330 not_utf8:
1331 av_log(s, AV_LOG_ERROR, "not utf8\n");
1332 return -1;
1333 } 1315 }
1334 1316
1335 static int mov_write_moov_tag(ByteIOContext *pb, MOVContext *mov, 1317 static int mov_write_moov_tag(ByteIOContext *pb, MOVContext *mov,
1336 AVFormatContext *s) 1318 AVFormatContext *s)
1337 { 1319 {