comparison libmpdemux/muxer_mpeg.c @ 18161:516d7874450b

changed timebase from 1024 to 300 (no rounding errors with any of the allowed framerates); write scr_extension accordingly. This is the first of a long series of patches to rewrite the muxer
author nicodvb
date Thu, 20 Apr 2006 20:32:36 +0000
parents b693d92e6210
children 1b4bf0c9ecb3
comparison
equal deleted inserted replaced
18160:03bc3385a845 18161:516d7874450b
375 s->muxer=muxer; 375 s->muxer=muxer;
376 376
377 if (type == MUXER_TYPE_VIDEO) { 377 if (type == MUXER_TYPE_VIDEO) {
378 spriv->type = 1; 378 spriv->type = 1;
379 spriv->init_dts = 0; 379 spriv->init_dts = 0;
380 spriv->init_pts = conf_init_vpts * 90 * 1024; 380 spriv->init_pts = conf_init_vpts * 90 * 300;
381 spriv->last_pts = spriv->init_pts; 381 spriv->last_pts = spriv->init_pts;
382 spriv->last_saved_pts = 0; 382 spriv->last_saved_pts = 0;
383 spriv->init_dts = spriv->last_dts = spriv->init_pts; 383 spriv->init_dts = spriv->last_dts = spriv->init_pts;
384 spriv->pts = spriv->dts = 0; 384 spriv->pts = spriv->dts = 0;
385 spriv->last_dpts = spriv->timer; 385 spriv->last_dpts = spriv->timer;
415 } else { // MUXER_TYPE_AUDIO 415 } else { // MUXER_TYPE_AUDIO
416 spriv->type = 0; 416 spriv->type = 0;
417 spriv->pts = 1; 417 spriv->pts = 1;
418 spriv->dts = 0; 418 spriv->dts = 0;
419 spriv->max_pl_size = priv->packet_size - calc_pack_hlen(priv, spriv); 419 spriv->max_pl_size = priv->packet_size - calc_pack_hlen(priv, spriv);
420 spriv->init_pts = conf_init_apts * 90 * 1024; 420 spriv->init_pts = conf_init_apts * 90 * 300;
421 spriv->pts = spriv->init_pts; 421 spriv->pts = spriv->init_pts;
422 spriv->last_pts = spriv->init_pts; 422 spriv->last_pts = spriv->init_pts;
423 spriv->dts = 0; 423 spriv->dts = 0;
424 spriv->id = 0xc0 + muxer->num_audios; 424 spriv->id = 0xc0 + muxer->num_audios;
425 s->ckid = be2me_32 (0x100 + spriv->id); 425 s->ckid = be2me_32 (0x100 + spriv->id);
453 muxer->avih.dwStreams++; 453 muxer->avih.dwStreams++;
454 return s; 454 return s;
455 } 455 }
456 456
457 static void write_mpeg_ts(unsigned char *b, uint64_t ts, uint8_t mod) { 457 static void write_mpeg_ts(unsigned char *b, uint64_t ts, uint8_t mod) {
458 ts >>= 10; 458 ts /= 300;
459 b[0] = mod | ((ts >> 29) & 0xf) | 1; 459 b[0] = mod | ((ts >> 29) & 0xf) | 1;
460 b[1] = (ts >> 22) & 0xff; 460 b[1] = (ts >> 22) & 0xff;
461 b[2] = ((ts >> 14) & 0xff) | 1; 461 b[2] = ((ts >> 14) & 0xff) | 1;
462 b[3] = (ts >> 7) & 0xff; 462 b[3] = (ts >> 7) & 0xff;
463 b[4] = ((ts << 1) & 0xff) | 1; 463 b[4] = ((ts << 1) & 0xff) | 1;
498 b[1] = size & 0xff; 498 b[1] = size & 0xff;
499 } 499 }
500 500
501 static void write_mpeg2_scr(unsigned char *b, uint64_t ts) 501 static void write_mpeg2_scr(unsigned char *b, uint64_t ts)
502 { 502 {
503 uint16_t t1, t2, t3; 503 uint16_t t1, t2, t3, scr_ext;
504 ts >>= 10; 504 scr_ext = ts % 300ULL;
505 ts &= 0x1FFFFFFFFULL; //33 bits, no extension; input must be * 92160000 505 ts /= 300ULL;
506 ts &= 0x1FFFFFFFFULL; //33 bits
506 t1 = (ts >> 30) & 0x7;; 507 t1 = (ts >> 30) & 0x7;;
507 t2 = (ts >> 15) & 0x7fff; 508 t2 = (ts >> 15) & 0x7fff;
508 t3 = ts & 0x7fff; 509 t3 = ts & 0x7fff;
509 510
510 b[0] = (t1 << 3 ) | 0x44 | ((t2 >> 13) & 0x3); 511 b[0] = (t1 << 3 ) | 0x44 | ((t2 >> 13) & 0x3);
511 b[1] = (t2 >> 5); 512 b[1] = (t2 >> 5);
512 b[2] = (t2 & 0x1f) << 3 | 0x4 | ((t3 >> 13) & 0x3); 513 b[2] = (t2 & 0x1f) << 3 | 0x4 | ((t3 >> 13) & 0x3);
513 b[3] = (t3 >> 5); 514 b[3] = (t3 >> 5);
514 b[4] = (t3 & 0x1f) << 3 | 0x4; 515 b[4] = (t3 & 0x1f) << 3 | ((scr_ext >> 7) & 0x03) | 0x4;
515 b[5] = 1; 516 b[5] = ((scr_ext << 1) & 0xFF) | 1;
516 } 517 }
517 518
518 519
519 static int write_mpeg_pack_header(muxer_t *muxer, char *buff) 520 static int write_mpeg_pack_header(muxer_t *muxer, char *buff)
520 { 521 {
1072 if(!next_pts && force) 1073 if(!next_pts && force)
1073 next_pts = apriv->last_pts; 1074 next_pts = apriv->last_pts;
1074 apriv->last_dts = apriv->pts; 1075 apriv->last_dts = apriv->pts;
1075 apriv->pts = next_pts; 1076 apriv->pts = next_pts;
1076 mp_msg(MSGT_MUXER, MSGL_DBG2, "\nAUDIO: tot=%"PRIu64", sz=%u bytes, FRAMES: %"PRIu64" * %u, REST: %u, DELTA_PTS: %u\n", 1077 mp_msg(MSGT_MUXER, MSGL_DBG2, "\nAUDIO: tot=%"PRIu64", sz=%u bytes, FRAMES: %"PRIu64" * %u, REST: %u, DELTA_PTS: %u\n",
1077 apriv->size, sz, num_frames, (uint32_t) apriv->frame_size, (uint32_t) rest, (uint32_t) ((num_frames * apriv->delta_pts) >> 10)); 1078 apriv->size, sz, num_frames, (uint32_t) apriv->frame_size, (uint32_t) rest, (uint32_t) ((num_frames * apriv->delta_pts) / 300));
1078 1079
1079 if(((priv->scr + (63000*1024)) < next_pts) && (priv->scr < apriv->pts) && (! force)) 1080 if(((priv->scr + (63000*300)) < next_pts) && (priv->scr < apriv->pts) && (! force))
1080 { 1081 {
1081 apriv->is_late = 1; 1082 apriv->is_late = 1;
1082 return 0; 1083 return 0;
1083 } 1084 }
1084 1085
1142 apriv->buffer_size = 0; 1143 apriv->buffer_size = 0;
1143 1144
1144 apriv->size += len; 1145 apriv->size += len;
1145 1146
1146 tmp = apriv->pts - priv->scr; 1147 tmp = apriv->pts - priv->scr;
1147 if((abs(tmp) > (63000*1024)) || (apriv->pts <= priv->scr)) 1148 if((abs(tmp) > (63000*300)) || (apriv->pts <= priv->scr))
1148 { 1149 {
1149 double d; 1150 double d;
1150 1151
1151 if(tmp > 0) 1152 if(tmp > 0)
1152 tmp = tmp - (63000*1024); 1153 tmp = tmp - (63000*300);
1153 1154
1154 d = -tmp / 92160000.0; 1155 d = -tmp / 27000000.0;
1155 d *= apriv->bitrate; 1156 d *= apriv->bitrate;
1156 apriv->compensate = (int32_t) d; 1157 apriv->compensate = (int32_t) d;
1157 1158
1158 if((tmp) > 92160000) //usually up to 1 second it still acceptable 1159 if((tmp) > 27000000) //usually up to 1 second it still acceptable
1159 mp_msg(MSGT_MUXER, MSGL_ERR, "\nWARNING: SCR: << APTS, DELTA=%.3lf secs, COMPENSATE=%d, BR: %d\n", 1160 mp_msg(MSGT_MUXER, MSGL_ERR, "\nWARNING: SCR: << APTS, DELTA=%.3lf secs, COMPENSATE=%d, BR: %d\n",
1160 (((double) tmp)/92160000.0), apriv->compensate, apriv->bitrate); 1161 (((double) tmp)/27000000.0), apriv->compensate, apriv->bitrate);
1161 else if(apriv->pts < priv->scr) 1162 else if(apriv->pts < priv->scr)
1162 mp_msg(MSGT_MUXER, MSGL_ERR, "\nERROR: SCR: %"PRIu64", APTS: %"PRIu64", DELTA=-%.3lf secs, COMPENSATE=%d, BR: %d, lens: %d/%d, frames: %d\n", 1163 mp_msg(MSGT_MUXER, MSGL_ERR, "\nERROR: SCR: %"PRIu64", APTS: %"PRIu64", DELTA=-%.3lf secs, COMPENSATE=%d, BR: %d, lens: %d/%d, frames: %d\n",
1163 priv->scr, apriv->pts, (double) ((priv->scr - apriv->pts)/92160000.0), apriv->compensate, apriv->bitrate, tlen, len, n); 1164 priv->scr, apriv->pts, (double) ((priv->scr - apriv->pts)/27000000.0), apriv->compensate, apriv->bitrate, tlen, len, n);
1164 } 1165 }
1165 1166
1166 mp_msg(MSGT_MUXER, MSGL_DBG2, "\nWRITTEN AUDIO: %u bytes, TIMER: %.3lf, FRAMES: %"PRIu64" * %u, DELTA_PTS: %.3lf\n", 1167 mp_msg(MSGT_MUXER, MSGL_DBG2, "\nWRITTEN AUDIO: %u bytes, TIMER: %.3lf, FRAMES: %"PRIu64" * %u, DELTA_PTS: %.3lf\n",
1167 len, (double) (apriv->pts/92160000), num_frames, (uint32_t) apriv->frame_size, delta_pts); 1168 len, (double) (apriv->pts/27000000), num_frames, (uint32_t) apriv->frame_size, delta_pts);
1168 1169
1169 return len; 1170 return len;
1170 } 1171 }
1171 1172
1172 static void drop_delayed_audio(muxer_t *muxer, muxer_stream_t *as, int64_t size) 1173 static void drop_delayed_audio(muxer_t *muxer, muxer_stream_t *as, int64_t size)
1188 memmove(as->b_buffer, &(as->b_buffer[size]), as->b_buffer_len - size1); 1189 memmove(as->b_buffer, &(as->b_buffer[size]), as->b_buffer_len - size1);
1189 as->b_buffer_len -= size1; 1190 as->b_buffer_len -= size1;
1190 1191
1191 rest = size1 - size; 1192 rest = size1 - size;
1192 rest_pts = (double) rest / (double) apriv->bitrate; 1193 rest_pts = (double) rest / (double) apriv->bitrate;
1193 apriv->pts += (int64_t) (92160000.0 * rest_pts); 1194 apriv->pts += (int64_t) (27000000.0 * rest_pts);
1194 apriv->last_pts += (int64_t) (92160000.0 * rest_pts); 1195 apriv->last_pts += (int64_t) (27000000.0 * rest_pts);
1195 mp_msg(MSGT_MUXER, MSGL_DBG2, "DROPPED: %"PRId64" bytes, REST= %"PRId64", REST_PTS: %.3lf, AUDIO_PTS%.3lf\n", size1, rest, rest_pts, (double) (apriv->pts/92160000.0)); 1196 mp_msg(MSGT_MUXER, MSGL_DBG2, "DROPPED: %"PRId64" bytes, REST= %"PRId64", REST_PTS: %.3lf, AUDIO_PTS%.3lf\n", size1, rest, rest_pts, (double) (apriv->pts/27000000.0));
1196 } 1197 }
1197 1198
1198 1199
1199 static void save_delayed_audio(muxer_t *muxer, muxer_stream_t *as, uint64_t dur) 1200 static void save_delayed_audio(muxer_t *muxer, muxer_stream_t *as, uint64_t dur)
1200 { 1201 {
1204 1205
1205 init_pts = apriv->pts; 1206 init_pts = apriv->pts;
1206 mp_msg(MSGT_MUXER, MSGL_DBG2, "DUR: %"PRIu64", DIFF: %"PRIu64"\n", dur, apriv->pts - init_pts); 1207 mp_msg(MSGT_MUXER, MSGL_DBG2, "DUR: %"PRIu64", DIFF: %"PRIu64"\n", dur, apriv->pts - init_pts);
1207 while(dur > apriv->pts - init_pts) 1208 while(dur > apriv->pts - init_pts)
1208 { 1209 {
1209 priv->scr = (92160000 * apriv->size) / apriv->bitrate; 1210 priv->scr = (27000000 * apriv->size) / apriv->bitrate;
1210 last_pts = apriv->pts; 1211 last_pts = apriv->pts;
1211 dump_audio(muxer, as, as->b_buffer_len, 0); 1212 dump_audio(muxer, as, as->b_buffer_len, 0);
1212 mp_msg(MSGT_MUXER, MSGL_DBG2, "DUR: %"PRIu64", DIFF: %"PRIu64", SCR: %"PRIu64"\n", dur, apriv->pts - init_pts, priv->scr); 1213 mp_msg(MSGT_MUXER, MSGL_DBG2, "DUR: %"PRIu64", DIFF: %"PRIu64", SCR: %"PRIu64"\n", dur, apriv->pts - init_pts, priv->scr);
1213 } 1214 }
1214 1215
1215 //priv->init_delay_pts = last_pts; 1216 //priv->init_delay_pts = last_pts;
1216 priv->init_delay_pts = (90 * 1024 * abs(conf_init_adelay)) + apriv->init_pts - (90 * 1024 * abs(conf_init_vpts)); 1217 priv->init_delay_pts = (90 * 300 * abs(conf_init_adelay)) + apriv->init_pts - (90 * 300 * abs(conf_init_vpts));
1217 if(priv->init_delay_pts <= priv->scr) 1218 if(priv->init_delay_pts <= priv->scr)
1218 priv->init_delay_pts = last_pts; 1219 priv->init_delay_pts = last_pts;
1219 mp_msg(MSGT_MUXER, MSGL_INFO, "INIT_VPTS: %"PRIu64" (%.3lf)\n", priv->init_delay_pts, (double) (priv->init_delay_pts/92160000.0)); 1220 mp_msg(MSGT_MUXER, MSGL_INFO, "INIT_VPTS: %"PRIu64" (%.3lf)\n", priv->init_delay_pts, (double) (priv->init_delay_pts/27000000.0));
1220 } 1221 }
1221 1222
1222 1223
1223 static inline void update_scr(muxer_priv_t *priv, uint32_t len, uint32_t totlen, double mult) 1224 static inline void update_scr(muxer_priv_t *priv, uint32_t len, uint32_t totlen, double mult)
1224 { 1225 {
1229 1230
1230 delta_scr = (uint64_t) (mult * perc); 1231 delta_scr = (uint64_t) (mult * perc);
1231 priv->scr += delta_scr; 1232 priv->scr += delta_scr;
1232 1233
1233 mp_msg(MSGT_MUXER, MSGL_DBG2, "UPDATE SCR TO %"PRIu64" (%.3lf): mult is %.3lf, perc: %.3lf, %u/%u, delta: %"PRIu64"\n", 1234 mp_msg(MSGT_MUXER, MSGL_DBG2, "UPDATE SCR TO %"PRIu64" (%.3lf): mult is %.3lf, perc: %.3lf, %u/%u, delta: %"PRIu64"\n",
1234 priv->scr, (double) (priv->scr/92160000.0), mult, perc, len, totlen, delta_scr); 1235 priv->scr, (double) (priv->scr/27000000.0), mult, perc, len, totlen, delta_scr);
1235 } 1236 }
1236 1237
1237 1238
1238 static int calc_frames_to_flush(muxer_headers_t *vpriv) 1239 static int calc_frames_to_flush(muxer_headers_t *vpriv)
1239 { 1240 {
1352 { 1353 {
1353 vpriv->framebuf[i].dts = last_dts + last_idur; 1354 vpriv->framebuf[i].dts = last_dts + last_idur;
1354 last_idur = vpriv->framebuf[i].idur; 1355 last_idur = vpriv->framebuf[i].idur;
1355 last_dts = vpriv->framebuf[i].dts; 1356 last_dts = vpriv->framebuf[i].dts;
1356 mp_msg(MSGT_MUXER, MSGL_DBG2, "I=%d, type: %c, TR: %u, pts=%.3lf, dts=%.3lf, size=%u\n", 1357 mp_msg(MSGT_MUXER, MSGL_DBG2, "I=%d, type: %c, TR: %u, pts=%.3lf, dts=%.3lf, size=%u\n",
1357 i, FTYPE(vpriv->framebuf[i].type), vpriv->framebuf[i].temp_ref, (double) (vpriv->framebuf[i].pts/92160000.0), 1358 i, FTYPE(vpriv->framebuf[i].type), vpriv->framebuf[i].temp_ref, (double) (vpriv->framebuf[i].pts/27000000.0),
1358 (double) (vpriv->framebuf[i].dts/92160000.0), vpriv->framebuf[i].size); 1359 (double) (vpriv->framebuf[i].dts/27000000.0), vpriv->framebuf[i].size);
1359 } 1360 }
1360 1361
1361 if((vpriv->size == 0) && (priv->init_delay_pts > 0)) 1362 if((vpriv->size == 0) && (priv->init_delay_pts > 0))
1362 { 1363 {
1363 uint64_t diff; 1364 uint64_t diff;
1379 vpriv->init_pts = 0; 1380 vpriv->init_pts = 0;
1380 vpriv->last_pts += priv->init_delay_pts; 1381 vpriv->last_pts += priv->init_delay_pts;
1381 1382
1382 priv->init_delay_pts = 0; 1383 priv->init_delay_pts = 0;
1383 mp_msg(MSGT_MUXER, MSGL_INFO, "INIT delayed video timestamps: PTS=%.3lf, DTS=%.3lf, DUR=%.3lf\n", 1384 mp_msg(MSGT_MUXER, MSGL_INFO, "INIT delayed video timestamps: PTS=%.3lf, DTS=%.3lf, DUR=%.3lf\n",
1384 (double) (vpriv->last_pts/92160000.0), (double) (vpriv->last_dts/92160000.0), (double) (vpriv->framebuf[0].idur/92160000.0)); 1385 (double) (vpriv->last_pts/27000000.0), (double) (vpriv->last_dts/27000000.0), (double) (vpriv->framebuf[0].idur/27000000.0));
1385 } 1386 }
1386 1387
1387 return ret; 1388 return ret;
1388 } 1389 }
1389 1390
1395 dpts = max(vpriv->last_saved_pts, vpriv->pts) - min(vpriv->last_saved_pts, vpriv->pts); 1396 dpts = max(vpriv->last_saved_pts, vpriv->pts) - min(vpriv->last_saved_pts, vpriv->pts);
1396 dpts += vpriv->framebuf[i].idur; 1397 dpts += vpriv->framebuf[i].idur;
1397 1398
1398 if((!priv->ts_allframes) && ( 1399 if((!priv->ts_allframes) && (
1399 (priv->is_dvd && (vpriv->framebuf[i].type != I_FRAME)) || 1400 (priv->is_dvd && (vpriv->framebuf[i].type != I_FRAME)) ||
1400 ((priv->is_genmpeg1 || priv->is_genmpeg2) && (vpriv->framebuf[i].type != I_FRAME) && (dpts < 64512000))) //0.7 seconds 1401 ((priv->is_genmpeg1 || priv->is_genmpeg2) && (vpriv->framebuf[i].type != I_FRAME) && (dpts < 63000*300))) //0.7 seconds
1401 ) 1402 )
1402 vpriv->pts = vpriv->dts = 0; 1403 vpriv->pts = vpriv->dts = 0;
1403 1404
1404 if(vpriv->dts && ((vpriv->dts < priv->scr) || (vpriv->pts <= vpriv->dts))) 1405 if(vpriv->dts && ((vpriv->dts < priv->scr) || (vpriv->pts <= vpriv->dts)))
1405 { 1406 {
1406 mp_msg(MSGT_MUXER, MSGL_V, "\nWARNING, SCR: %.3lf, DTS: %.3lf, PTS: %.3lf\n", 1407 mp_msg(MSGT_MUXER, MSGL_V, "\nWARNING, SCR: %.3lf, DTS: %.3lf, PTS: %.3lf\n",
1407 (double) priv->scr/92160000.0,(double) vpriv->dts/92160000.0, (double) vpriv->pts/92160000.0); 1408 (double) priv->scr/27000000.0,(double) vpriv->dts/27000000.0, (double) vpriv->pts/27000000.0);
1408 vpriv->dts = 0; 1409 vpriv->dts = 0;
1409 } 1410 }
1410 1411
1411 if(vpriv->pts && (vpriv->pts <= priv->scr)) 1412 if(vpriv->pts && (vpriv->pts <= priv->scr))
1412 { 1413 {
1413 mp_msg(MSGT_MUXER, MSGL_ERR, "ERROR: SCR: %.3lf, VPTS: %.3lf, DELTA=-%.3lf secs\n", 1414 mp_msg(MSGT_MUXER, MSGL_ERR, "ERROR: SCR: %.3lf, VPTS: %.3lf, DELTA=-%.3lf secs\n",
1414 (double) (priv->scr/92160000.0), (double)(vpriv->pts/92160000.0), (double) ((priv->scr - vpriv->pts)/92160000.0)); 1415 (double) (priv->scr/27000000.0), (double)(vpriv->pts/27000000.0), (double) ((priv->scr - vpriv->pts)/27000000.0));
1415 vpriv->pts = vpriv->dts = 0; 1416 vpriv->pts = vpriv->dts = 0;
1416 } 1417 }
1417 1418
1418 if(vpriv->pts) 1419 if(vpriv->pts)
1419 vpriv->last_saved_pts = vpriv->pts; 1420 vpriv->last_saved_pts = vpriv->pts;
1434 available = abytes = 0; 1435 available = abytes = 0;
1435 for(i = 0; i < apriv->framebuf_used; i++) 1436 for(i = 0; i < apriv->framebuf_used; i++)
1436 { 1437 {
1437 if(adur < duration) 1438 if(adur < duration)
1438 abytes += apriv->framebuf[i].size - apriv->framebuf[i].pos; 1439 abytes += apriv->framebuf[i].size - apriv->framebuf[i].pos;
1439 adur += (double)(apriv->framebuf[i].idur/92160000.0); 1440 adur += (double)(apriv->framebuf[i].idur/27000000.0);
1440 available += apriv->framebuf[i].size - apriv->framebuf[i].pos; 1441 available += apriv->framebuf[i].size - apriv->framebuf[i].pos;
1441 } 1442 }
1442 1443
1443 1444
1444 if(adur < duration && !finalize) 1445 if(adur < duration && !finalize)
1521 for(i = 0; i < n; i++) 1522 for(i = 0; i < n; i++)
1522 { 1523 {
1523 vbytes += vpriv->framebuf[i].size; 1524 vbytes += vpriv->framebuf[i].size;
1524 iduration += vpriv->framebuf[i].idur; 1525 iduration += vpriv->framebuf[i].idur;
1525 } 1526 }
1526 duration = (double) (iduration / 92160000.0); 1527 duration = (double) (iduration / 27000000.0);
1527 1528
1528 if(vpriv->is_mpeg12) 1529 if(vpriv->is_mpeg12)
1529 init_delay = fix_pts(priv, vpriv, n); 1530 init_delay = fix_pts(priv, vpriv, n);
1530 else 1531 else
1531 init_delay = 0; 1532 init_delay = 0;
1760 muxer->file_end = priv->scr; 1761 muxer->file_end = priv->scr;
1761 return found; 1762 return found;
1762 } 1763 }
1763 1764
1764 1765
1765 static uint64_t parse_fps(float fps) 1766 static inline uint64_t parse_fps(float fps)
1766 { 1767 {
1767 // 90000 * 1024 / fps 1768 // 90000 * 300 * 1001 / d , there's no rounding error with any of the admitted framerates
1768 switch((int)(fps*1001+0.5)) 1769 int d = (int)(fps*1001+0.5);
1769 { 1770
1770 case 24000: 1771 return 27027000000ULL / d;
1771 return 3843844;
1772 case 24024:
1773 return 3840000;
1774 case 25025:
1775 return 3686400;
1776 case 30000:
1777 return 3075075;
1778 case 30030:
1779 return 3072000;
1780 case 50050:
1781 return 1843200;
1782 case 60000:
1783 return 1537538;
1784 case 60060:
1785 return 1536000;
1786 default:
1787 mp_msg(MSGT_MUXER, MSGL_ERR, "ERROR! unknown fps code: %d", (int)(fps*1001+0.5));
1788 return 0;
1789 }
1790 } 1772 }
1791 1773
1792 1774
1793 static int soft_telecine(muxer_headers_t *vpriv, uint8_t *fps_ptr, uint8_t *se_ptr, uint8_t *pce_ptr, int n) 1775 static int soft_telecine(muxer_headers_t *vpriv, uint8_t *fps_ptr, uint8_t *se_ptr, uint8_t *pce_ptr, int n)
1794 { 1776 {
1931 spriv->delta_pts = spriv->nom_delta_pts = parse_fps(spriv->picture.fps); 1913 spriv->delta_pts = spriv->nom_delta_pts = parse_fps(spriv->picture.fps);
1932 1914
1933 spriv->delta_clock = (double) 1/fps; 1915 spriv->delta_clock = (double) 1/fps;
1934 //the 2 lines below are needed to handle non-standard frame rates (such as 18) 1916 //the 2 lines below are needed to handle non-standard frame rates (such as 18)
1935 if(! spriv->delta_pts) 1917 if(! spriv->delta_pts)
1936 spriv->delta_pts = spriv->nom_delta_pts = (uint64_t) ((double)92160000.0 * spriv->delta_clock ); 1918 spriv->delta_pts = spriv->nom_delta_pts = (uint64_t) ((double)27000000.0 * spriv->delta_clock );
1937 mp_msg(MSGT_MUXER, MSGL_DBG2, "\nFPS: %.3f, FRAMETIME: %.3lf\n", fps, (double)1/fps); 1919 mp_msg(MSGT_MUXER, MSGL_DBG2, "\nFPS: %.3f, FRAMETIME: %.3lf\n", fps, (double)1/fps);
1938 if(priv->patch_seq) 1920 if(priv->patch_seq)
1939 patch_seq(priv, s->buffer); 1921 patch_seq(priv, s->buffer);
1940 1922
1941 tmp = 12; 1923 tmp = 12;
2109 for(i=0; i<3; i++) 2091 for(i=0; i<3; i++)
2110 { 2092 {
2111 vpriv->framebuf[i].pts += diff; 2093 vpriv->framebuf[i].pts += diff;
2112 vpriv->framebuf[i].dts += i * diff; 2094 vpriv->framebuf[i].dts += i * diff;
2113 mp_msg(MSGT_MUXER, MSGL_DBG2, "FIXED_PTS: %.3lf, FIXED_DTS: %.3lf\n", 2095 mp_msg(MSGT_MUXER, MSGL_DBG2, "FIXED_PTS: %.3lf, FIXED_DTS: %.3lf\n",
2114 (double) (vpriv->framebuf[i].pts/92160000.0), (double) (vpriv->framebuf[i].dts/92160000.0)); 2096 (double) (vpriv->framebuf[i].pts/27000000.0), (double) (vpriv->framebuf[i].dts/27000000.0));
2115 } 2097 }
2116 return diff; 2098 return diff;
2117 } 2099 }
2118 else 2100 else
2119 return 0; 2101 return 0;
2158 if((delta > 0) && (delta > (vpriv->picture.timeinc_resolution/2))) 2140 if((delta > 0) && (delta > (vpriv->picture.timeinc_resolution/2)))
2159 delta -= vpriv->picture.timeinc_resolution; 2141 delta -= vpriv->picture.timeinc_resolution;
2160 else if((delta < 0) && (delta < (-vpriv->picture.timeinc_resolution/2))) 2142 else if((delta < 0) && (delta < (-vpriv->picture.timeinc_resolution/2)))
2161 delta += vpriv->picture.timeinc_resolution; 2143 delta += vpriv->picture.timeinc_resolution;
2162 2144
2163 delta_pts = (92160000 * (int64_t) delta) / vpriv->picture.timeinc_resolution; 2145 delta_pts = (27000000 * (int64_t) delta) / vpriv->picture.timeinc_resolution;
2164 2146
2165 pt = vpriv->picture.picture_type + 1; 2147 pt = vpriv->picture.picture_type + 1;
2166 mp_msg(MSGT_MUXER, MSGL_DBG2, "\nTYPE: %c, RESOLUTION: %d, TEMP: %d, delta: %d, delta_pts: %"PRId64" = %.3lf, delta2: %.3lf\n", 2148 mp_msg(MSGT_MUXER, MSGL_DBG2, "\nTYPE: %c, RESOLUTION: %d, TEMP: %d, delta: %d, delta_pts: %"PRId64" = %.3lf, delta2: %.3lf\n",
2167 FTYPE(pt), vpriv->picture.timeinc_resolution, vpriv->picture.timeinc_unit, delta, delta_pts, (double) (delta_pts/92160000.0), 2149 FTYPE(pt), vpriv->picture.timeinc_resolution, vpriv->picture.timeinc_unit, delta, delta_pts, (double) (delta_pts/27000000.0),
2168 (double) delta / (double) vpriv->picture.timeinc_resolution); 2150 (double) delta / (double) vpriv->picture.timeinc_resolution);
2169 2151
2170 vpriv->last_tr = vpriv->picture.timeinc_unit; 2152 vpriv->last_tr = vpriv->picture.timeinc_unit;
2171 2153
2172 break; 2154 break;
2182 vpriv->framebuf[vpriv->framebuf_used-1].pts = vpriv->last_pts; 2164 vpriv->framebuf[vpriv->framebuf_used-1].pts = vpriv->last_pts;
2183 vpriv->framebuf[vpriv->framebuf_used-1].dts = vpriv->last_dts; 2165 vpriv->framebuf[vpriv->framebuf_used-1].dts = vpriv->last_dts;
2184 vpriv->framebuf[vpriv->framebuf_used-1].idur = vpriv->frame_duration; 2166 vpriv->framebuf[vpriv->framebuf_used-1].idur = vpriv->frame_duration;
2185 2167
2186 /*mp_msg(MSGT_MUXER, MSGL_DBG2, "\nMPEG4V, PT: %c, LEN=%u, DELTA_PTS: %.3lf, PTS: %.3lf, DTS: %.3lf\n", 2168 /*mp_msg(MSGT_MUXER, MSGL_DBG2, "\nMPEG4V, PT: %c, LEN=%u, DELTA_PTS: %.3lf, PTS: %.3lf, DTS: %.3lf\n",
2187 FTYPE(pt), len, (delta_pts/92160000.0), 2169 FTYPE(pt), len, (delta_pts/27000000.0),
2188 (double) (vpriv->framebuf[vpriv->framebuf_used-1].pts/92160000.0), 2170 (double) (vpriv->framebuf[vpriv->framebuf_used-1].pts/27000000.0),
2189 (double) (vpriv->framebuf[vpriv->framebuf_used-1].dts/92160000.0), len);*/ 2171 (double) (vpriv->framebuf[vpriv->framebuf_used-1].dts/27000000.0), len);*/
2190 2172
2191 if(!vpriv->frame_duration && vpriv->framebuf_used == 3) 2173 if(!vpriv->frame_duration && vpriv->framebuf_used == 3)
2192 { 2174 {
2193 vpriv->frame_duration = fix_mp4_frame_duration(vpriv); 2175 vpriv->frame_duration = fix_mp4_frame_duration(vpriv);
2194 if(vpriv->frame_duration) 2176 if(vpriv->frame_duration)
2195 { 2177 {
2196 vpriv->last_pts += vpriv->frame_duration; 2178 vpriv->last_pts += vpriv->frame_duration;
2197 vpriv->last_dts = vpriv->framebuf[vpriv->framebuf_used-1].dts; 2179 vpriv->last_dts = vpriv->framebuf[vpriv->framebuf_used-1].dts;
2198 vpriv->delta_clock = ((double) vpriv->frame_duration)/92160000.0; 2180 vpriv->delta_clock = ((double) vpriv->frame_duration)/27000000.0;
2199 mp_msg(MSGT_MUXER, MSGL_INFO, "FRAME DURATION: %"PRIu64" %.3lf\n", 2181 mp_msg(MSGT_MUXER, MSGL_INFO, "FRAME DURATION: %"PRIu64" %.3lf\n",
2200 vpriv->frame_duration, (double) (vpriv->frame_duration/92160000.0)); 2182 vpriv->frame_duration, (double) (vpriv->frame_duration/27000000.0));
2201 } 2183 }
2202 } 2184 }
2203 2185
2204 mp_msg(MSGT_MUXER, MSGL_DBG2, "LAST_PTS: %.3lf, LAST_DTS: %.3lf\n", 2186 mp_msg(MSGT_MUXER, MSGL_DBG2, "LAST_PTS: %.3lf, LAST_DTS: %.3lf\n",
2205 (double) (vpriv->last_pts/92160000.0), (double) (vpriv->last_dts/92160000.0)); 2187 (double) (vpriv->last_pts/27000000.0), (double) (vpriv->last_dts/27000000.0));
2206 2188
2207 return len; 2189 return len;
2208 } 2190 }
2209 2191
2210 2192
2308 if(len > 0 && (srate == s->wf->nSamplesPerSec) && (i + len <= s->b_buffer_len)) 2290 if(len > 0 && (srate == s->wf->nSamplesPerSec) && (i + len <= s->b_buffer_len))
2309 { 2291 {
2310 frames++; 2292 frames++;
2311 fill_last_frame(spriv, &(s->b_buffer[tot]), i - tot); 2293 fill_last_frame(spriv, &(s->b_buffer[tot]), i - tot);
2312 2294
2313 idur = (92160000ULL * spf) / srate; 2295 idur = (27000000ULL * spf) / srate;
2314 frm_idx = add_frame(spriv, idur, &(s->b_buffer[i]), len, 0, 0); 2296 frm_idx = add_frame(spriv, idur, &(s->b_buffer[i]), len, 0, 0);
2315 if(frm_idx < 0) 2297 if(frm_idx < 0)
2316 continue; 2298 continue;
2317 for(j = frm_idx; j < spriv->framebuf_cnt; j++) 2299 for(j = frm_idx; j < spriv->framebuf_cnt; j++)
2318 spriv->framebuf[j].pts = spriv->last_pts; 2300 spriv->framebuf[j].pts = spriv->last_pts;
2343 if((len > 0) && (srate == s->wf->nSamplesPerSec) && (i + len <= s->b_buffer_len)) 2325 if((len > 0) && (srate == s->wf->nSamplesPerSec) && (i + len <= s->b_buffer_len))
2344 { 2326 {
2345 frames++; 2327 frames++;
2346 fill_last_frame(spriv, &(s->b_buffer[tot]), i - tot); 2328 fill_last_frame(spriv, &(s->b_buffer[tot]), i - tot);
2347 2329
2348 idur = (92160000ULL * 1536) / srate; 2330 idur = (27000000ULL * 1536) / srate;
2349 frm_idx = add_frame(spriv, idur, &(s->b_buffer[i]), len, 0, 0); 2331 frm_idx = add_frame(spriv, idur, &(s->b_buffer[i]), len, 0, 0);
2350 if(frm_idx < 0) 2332 if(frm_idx < 0)
2351 continue; 2333 continue;
2352 for(j = frm_idx; j < spriv->framebuf_cnt; j++) 2334 for(j = frm_idx; j < spriv->framebuf_cnt; j++)
2353 spriv->framebuf[j].pts = spriv->last_pts; 2335 spriv->framebuf[j].pts = spriv->last_pts;
2374 if((len > 0) && (srate == s->wf->nSamplesPerSec) && (i + len <= s->b_buffer_len)) 2356 if((len > 0) && (srate == s->wf->nSamplesPerSec) && (i + len <= s->b_buffer_len))
2375 { 2357 {
2376 frames++; 2358 frames++;
2377 fill_last_frame(spriv, &(s->b_buffer[tot]), i - tot); 2359 fill_last_frame(spriv, &(s->b_buffer[tot]), i - tot);
2378 2360
2379 idur = (92160000ULL * 1024 * num) / srate; 2361 idur = (27000000ULL * 1024 * num) / srate;
2380 frm_idx = add_frame(spriv, idur, &(s->b_buffer[i]), len, 0, 0); 2362 frm_idx = add_frame(spriv, idur, &(s->b_buffer[i]), len, 0, 0);
2381 if(frm_idx < 0) 2363 if(frm_idx < 0)
2382 continue; 2364 continue;
2383 for(j = frm_idx; j < spriv->framebuf_cnt; j++) 2365 for(j = frm_idx; j < spriv->framebuf_cnt; j++)
2384 spriv->framebuf[j].pts = spriv->last_pts; 2366 spriv->framebuf[j].pts = spriv->last_pts;
2413 spriv->framebuf[j].pts = spriv->last_pts; 2395 spriv->framebuf[j].pts = spriv->last_pts;
2414 } 2396 }
2415 } 2397 }
2416 2398
2417 *nf = frames; 2399 *nf = frames;
2418 *timer = (double) (spriv->last_pts - spriv->init_pts)/92160000.0; 2400 *timer = (double) (spriv->last_pts - spriv->init_pts)/27000000.0;
2419 2401
2420 return tot; 2402 return tot;
2421 } 2403 }
2422 2404
2423 2405
2450 { 2432 {
2451 spriv->is_mpeg12 = 1; 2433 spriv->is_mpeg12 = 1;
2452 if(len) 2434 if(len)
2453 sz = parse_mpeg12_video(s, priv, spriv, fps, len); 2435 sz = parse_mpeg12_video(s, priv, spriv, fps, len);
2454 else { 2436 else {
2455 tmp = (uint64_t) (92160000 / fps); 2437 tmp = (uint64_t) (27000000 / fps);
2456 spriv->last_pts += tmp; 2438 spriv->last_pts += tmp;
2457 spriv->last_dts += tmp; 2439 spriv->last_dts += tmp;
2458 } 2440 }
2459 } 2441 }
2460 else if(is_mpeg4(stream_format)) 2442 else if(is_mpeg4(stream_format))
2464 if(spriv->size == 0) 2446 if(spriv->size == 0)
2465 priv->use_psm = 1; 2447 priv->use_psm = 1;
2466 if(len) 2448 if(len)
2467 sz = parse_mpeg4_video(s, priv, spriv, fps, len); 2449 sz = parse_mpeg4_video(s, priv, spriv, fps, len);
2468 else { 2450 else {
2469 tmp = (uint64_t) (92160000 / fps); 2451 tmp = (uint64_t) (27000000 / fps);
2470 spriv->last_pts += tmp; 2452 spriv->last_pts += tmp;
2471 spriv->last_dts += tmp; 2453 spriv->last_dts += tmp;
2472 } 2454 }
2473 } 2455 }
2474 2456
2534 drop_delayed_audio(muxer, s, (int64_t) delay_len); 2516 drop_delayed_audio(muxer, s, (int64_t) delay_len);
2535 } 2517 }
2536 else 2518 else
2537 { 2519 {
2538 mp_msg(MSGT_MUXER, MSGL_V, "\nWRITING %"PRIu64" EARLY AUDIO BYTES, DELAY: %.3lf, BR: %u\n", delay_len, priv->init_adelay, spriv->bitrate); 2520 mp_msg(MSGT_MUXER, MSGL_V, "\nWRITING %"PRIu64" EARLY AUDIO BYTES, DELAY: %.3lf, BR: %u\n", delay_len, priv->init_adelay, spriv->bitrate);
2539 save_delayed_audio(muxer, s, (uint64_t) (92160000 * (-priv->init_adelay))); 2521 save_delayed_audio(muxer, s, (uint64_t) (27000000 * (-priv->init_adelay)));
2540 } 2522 }
2541 priv->init_adelay = 0.0; 2523 priv->init_adelay = 0.0;
2542 conf_init_adelay = 0; 2524 conf_init_adelay = 0;
2543 priv->drop = 0; 2525 priv->drop = 0;
2544 } 2526 }