X-Git-Url: http://git.osdn.net/view?p=rec10%2Frec10-git.git;a=blobdiff_plain;f=tstools%2FDtsEdit%2Fsrc%2FEditMain.cpp;fp=tstools%2FDtsEdit%2Fsrc%2FEditMain.cpp;h=0000000000000000000000000000000000000000;hp=3790de8f618d7128b7edc638b92e90b160a4e663;hb=930d3dbdc17ad4179a9b512f4e787a896a544943;hpb=d63ca135202a679bd918561b65e806966f94546e diff --git a/tstools/DtsEdit/src/EditMain.cpp b/tstools/DtsEdit/src/EditMain.cpp deleted file mode 100644 index 3790de8..0000000 --- a/tstools/DtsEdit/src/EditMain.cpp +++ /dev/null @@ -1,281 +0,0 @@ -#include -#include "stdafx.h" -#include "Help.h" -#include "EditMain.h" -#include "debug.h" - - -void EditMain(T_EDIT_PARAM *prm){ - - GF_Err e; - T_MP4_INFO mi; - T_TS_LIST *ts = NULL; - T_TS_LIST *tsSort = NULL; - - // ‰Šú‰» - gf_sys_init(); - - ZeroMemory(&mi, sizeof(T_MP4_INFO)); - - // ƒ^[ƒQƒbƒgƒtƒ@ƒCƒ‹‚̃I[ƒvƒ“ - mi.fp_in = gf_isom_open(prm->p_infile, GF_ISOM_OPEN_READ, NULL); - printf("“ü—̓tƒ@ƒCƒ‹... [%s]\n\n", prm->p_infile); - - mi.i_trackCount = gf_isom_get_track_count(mi.fp_in); - - // Šeƒgƒ‰ƒbƒN‚̃tƒH[ƒ}ƒbƒg‚ðŽæ“¾ - u32 lst4CC[] = {GF_ISOM_BRAND_AVC1, GF_ISOM_BRAND_MP4V, GF_ISOM_BRAND_XVID}; - SearchTrackOf4CC(&mi, lst4CC, 3); - - // –Ú“I‚̃gƒ‰ƒbƒN‚ªŒ©‚‚©‚ç‚È‚©‚Á‚½ê‡B - if (mi.i_trackNo == NULL){ - ErrorMessage(MSG_NO_4CC); - goto _ERROR_RET; - } - - // ƒTƒ“ƒvƒ‹”‚̎擾 - mi.ui_sampleCount = gf_isom_get_sample_count(mi.fp_in, mi.i_trackNo); - if(mi.ui_sampleCount < 3){ - ErrorMessage(MSG_NO_SAMPLE); - goto _ERROR_RET; - } - - ts = new T_TS_LIST[mi.ui_sampleCount + 1]; - ZeroMemory(ts, sizeof(T_TS_LIST) * mi.ui_sampleCount); - - // ƒTƒ“ƒvƒ‹î•ñ‚ðŽæ“¾‚µAƒfƒBƒŒƒCƒtƒŒ[ƒ€”»’èECTS‡‚É•À‚Ñ‘Ö‚¦ - printf("ƒTƒ“ƒvƒ‹î•ñŽæ“¾’†...\n"); - if(readTsFromFile(&mi, ts)) - goto _ERROR_RET; - - // ƒsƒNƒ`ƒƒ•\Ž¦‡‚Ń\[ƒg - tsSort = new T_TS_LIST[mi.ui_sampleCount + 1]; - memcpy(tsSort, ts, sizeof(T_TS_LIST) * mi.ui_sampleCount); - qsort(tsSort, mi.ui_sampleCount, sizeof(T_TS_LIST), (int(*)(const void*, const void*))CompareTS_PTS); - - // ÅIƒtƒŒ[ƒ€‚ÌFPS•âŠ® - u32 i = mi.ui_sampleCount; - tsSort[i].DTS = ts[i-1].DTS + (ts[i-1].DTS - ts[i-2].DTS); - tsSort[i].CTS_Offset = 0; - tsSort[i].CTS = tsSort[i-1].CTS + (tsSort[i-1].CTS - tsSort[i-2].CTS); - tsSort[i].PTS = tsSort[i-1].PTS + (tsSort[i-1].PTS - tsSort[i-2].PTS); - tsSort[i].samples = i+1; - - // ƒ^ƒCƒ€ƒXƒP[ƒ‹‚̎擾 - mi.i_org_timescale = (int)gf_isom_get_media_timescale(mi.fp_in, mi.i_trackNo); - - // ‚±‚̕ӂŃ‚[ƒh•ªŠò - if(prm->i_mode == MODE_IN){ - // ƒ^ƒCƒ€ƒR[ƒh“ü—Í - - // Å¬ƒtƒŒ[ƒ€ƒŒ[ƒgŽæ“¾ - mi.i_org_timerate = getMinimumPTSDiff(&mi, tsSort); - if(prm->i_timerate <= 0) { - int rate = gcd(mi.i_org_timescale, mi.i_org_timerate); - prm->i_timerate = mi.i_org_timerate / rate; - } - - // TimeCode V2 ‚ÌŽæ‚荞‚Ý - if (prm->i_tcv == 1){ - if(readTimeCodeFromFileV1(&mi, tsSort, prm)) - goto _ERROR_RET; - } else if(prm->i_tcv == 2){ - if(readTimeCodeFromFile(&mi, tsSort, prm)) - goto _ERROR_RET; - } else { - goto _ERROR_RET; - } - - // ’x‰„ƒtƒŒ[ƒ€”Žæ“¾ - if(prm->i_delayFrame < 0) { - prm->i_delayFrame = getDelayFlame(&mi, ts); - } - mi.i_delayFrame = prm->i_delayFrame; - mi.i_initDelay = mi.i_delayFrame * (int)(getAveragePTSDiff(&mi, tsSort) / (double)prm->i_timerate + 0.5) * prm->i_timerate; - - // Œ‹‰Ê‚ðƒRƒs[‚µ‚ăsƒNƒ`ƒƒ‡‚Ƀ\[ƒg - memcpy(ts, tsSort, sizeof(T_TS_LIST) * mi.ui_sampleCount); - qsort(ts, mi.ui_sampleCount, sizeof(T_TS_LIST), (int(*)(const void*, const void*))CompareTS_Sample); - - - // î•ñ‚Ì•\Ž¦ - printf("\n"); - printf("--- input ---\n"); - printf("TimeScale F%d\n", mi.i_org_timescale); - printf("TimeRate F%d\n", mi.i_org_timerate); - printf("Sample Count F%d\n", mi.ui_sampleCount); - printf("Delay Frame F%d\n", mi.i_delayFrame); - printf("Delay Time F%d\n", mi.i_initDelay); - printf("\n"); - printf("--- output ---\n"); - printf("TimeScale F%d\n", prm->i_timescale); - printf("TimeRate F%d\n", prm->i_timerate); - printf("Multiple F%lf\n", prm->f_scaleFct); - printf("\n"); - printf("ƒtƒ@ƒCƒ‹o—Í’†... [%s]\n", prm->p_outfile); - - u32 readDscIdx = 0; - u32 destTrack = 0; - mi.fp_out = gf_isom_open(prm->p_outfile, GF_ISOM_OPEN_WRITE, NULL); - - - // o—ÍŠJŽn - for (int trackIdx=1; trackIdx<=mi.i_trackCount; trackIdx++){ - // ƒgƒ‰ƒbƒN‚̃Rƒs[ - gf_isom_clone_track(mi.fp_in, trackIdx, mi.fp_out, true, &destTrack); - // edts‚̍폜 - gf_isom_remove_edit_segments(mi.fp_out, destTrack); - - if (trackIdx != mi.i_trackNo){ - u32 sampleCount = gf_isom_get_sample_count(mi.fp_in, trackIdx); - for(u32 i=1; i<=sampleCount; i++){ - printf("... %5.1f%%\r", (double)i/(double)sampleCount * 100.0); - GF_ISOSample *sample = gf_isom_get_sample(mi.fp_in, trackIdx, i, &readDscIdx); - e = gf_isom_add_sample(mi.fp_out, destTrack, readDscIdx, sample); - gf_isom_sample_del(&sample); - } - - } else { - // ƒ^ƒCƒ€ƒXƒP[ƒ‹Ý’è - e = gf_isom_set_media_timescale(mi.fp_out, destTrack, (u32)prm->i_timescale); - if(e) - printf("!!! ƒ^ƒCƒ€ƒXƒP[ƒ‹Ý’莸”s : %d !!!\n", e); - - // DTS‚ðÝ’肵o—Í - s64 before_dts = -1; - int delta_time = int((prm->i_timerate * prm->f_scaleFct) / (mi.i_delayFrame*2)); - - if(delta_time < 1 && prm->b_dc){ - ErrorMessage(MSG_MORE_SMALL_TIMERATE); - break; - } - - for(u32 i=0; ib_dc){ - dts_delay = 0; - cts_delay = mi.i_initDelay; - } else { - for(u32 k=MAX(0, i - mi.i_delayFrame); kDTS = ts[i].DTS; - sample->CTS_Offset = ts[i].CTS_Offset; - e = gf_isom_add_sample(mi.fp_out, destTrack, readDscIdx, sample); - - if(e) - printf("!!! ƒTƒ“ƒvƒ‹‘‚«ž‚݃Gƒ‰[ / Track:%d Frame:%d DTS:%I64d, CTS_Offset:%d Err:%d !!!\n", destTrack, i+1, sample->DTS, sample->CTS_Offset, e); - gf_isom_sample_del(&sample); - } - - // edts‚Ì‘}“ü - //GF_ISOSample *sample = gf_isom_get_sample_info(mi.fp_out, destTrack, 1, NULL, NULL); - //if(sample->CTS_Offset > 0){ - // u64 trackDur = gf_isom_get_track_duration(mi.fp_out, destTrack); - // gf_isom_remove_edit_segments(mi.fp_out, destTrack); - // gf_isom_append_edit_segment(mi.fp_out, destTrack, trackDur, sample->CTS_Offset, GF_ISOM_EDIT_NORMAL); - //} - //gf_isom_sample_del(&sample); - } - - printf("... %dƒgƒ‰ƒbƒNo—͏I—¹\n", trackIdx); - } - - // o—̓tƒ@ƒCƒ‹‚ð•Â‚¶‚é - gf_isom_clone_pl_indications(mi.fp_in, mi.fp_out); - gf_isom_clone_root_od(mi.fp_in, mi.fp_out); - - u64 duration = gf_isom_get_duration(mi.fp_out); - gf_isom_make_interleave(mi.fp_out, 0.5); - gf_isom_close(mi.fp_out); - - } - else if (prm->i_mode == MODE_OUT){ - // TIMECODE‚̏o—Í - if(prm->i_tcv == 2){ - FILE *fpout; - if((fpout = fopen(prm->p_outfile, "wb")) != NULL){ - fprintf(fpout, "# timecode format v2\r\n"); - for(u32 i=0; ii_tcv == 1){ - FILE *fpout; - if((fpout = fopen(prm->p_outfile, "wb")) != NULL){ - fprintf(fpout, "# timecode format v1\r\n"); - fprintf(fpout, "Assume %.6lf\r\n", getMaximumFps(&mi, tsSort)); - u32 stpos = 0; - double fps = 0.0; - double beforFps = (double)mi.i_org_timescale/(double)(tsSort[1].PTS - tsSort[0].PTS); - for(u32 i=0; i