⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 multplex.cpp

📁 传输流分析
💻 CPP
📖 第 1 页 / 共 5 页
字号:
                                for (j = 0; j < i - 1; j++)                                        *(index++) = (unsigned char) STUFFING_BYTE;                        } else                                for (j = 0; j < i; j++)                                        *(index++) = (unsigned char) STUFFING_BYTE;                        i = sector_size;                } else                        i = 4;                *(index++) = (unsigned char)((PROGRAM_END)>>24);                *(index++) = (unsigned char)((PROGRAM_END & 0x00ff0000)>>16);                *(index++) = (unsigned char)((PROGRAM_END & 0x0000ff00)>>8);                *(index) = (unsigned char)(PROGRAM_END & 0x000000ff);                if ( write(programFile, sector.buf, i) <= 0) {                        sprintf(tmpStr, "Unable to write to program file %s: %s.",                                programFilename, strerrno());                        DisplayError(tmpStr);                        return 0;                }                bytes_output += i;        }        if (OutputStats) {                /* status info*/                status_info(nsec_a, nsec_a1, nsec_v, nsec_p, bytes_output,                            buffer_space(video_buffer), buffer_space(audio_buffer),                            buffer_space(audio1_buffer));                status_footer ();        }        if (video_underflows || audio_underflows || audio1_underflows) {                if (video_underflows) {                        sprintf(tmpStr, "    %u video underflows (SCR >= PTS or DTS)", video_underflows);                        DisplayInfo(tmpStr);                }                if (audio_underflows) {                        sprintf(tmpStr, "    %u audio 1 underflows (SCR >= PTS)", audio_underflows);                        DisplayInfo(tmpStr);                }                if (audio1_underflows) {                        sprintf(tmpStr, "    %u audio 2 underflows (SCR >= PTS)", audio1_underflows);                        DisplayInfo(tmpStr);                }        }        if (video_underflows || audio_underflows || audio1_underflows) {                DisplayInfo(" ");                DisplayInfo("    NOTE: The resulting file may not play back correctly.");                if ((mplex_type == MPEG_VCD) || (mplex_type == MPEG_SVCD)) {                        DisplayInfo("    Try reducing the video bitrate or increasing the video and");                        DisplayInfo("    audio startup delays.");                } else                        DisplayInfo("    Try increasing the mux rate.");        }        DisplayProgress("", 0);        sprintf(tmpStr, "  Finished multiplexing %s                                 ", programFilename);        DisplayInfo(tmpStr);        if (mux_SVCD_scan_offsets) {                if (!embed_svcd_scan_info(video_info))                        return 0;                if (svcd_info) {                        fclose(svcd_info);                        svcd_info = NULL;                }        }        /* close the output */        if (!outputFile || fileCount > 1)                if (programFile) {                        close(programFile);                        programFile = 0;                }        return 1;}static int sector_to_timecode(unsigned char *ptr, unsigned int frame){        unsigned int i, j;        char tmpStr[MAXPATH];        if (fseeko(svcd_info, frame << 2, SEEK_SET)) {                sprintf(tmpStr, "Unable to seek position in SVCD temporary file %s: %s.",                        svcd_name, strerrno());                DisplayError(tmpStr);                return FALSE;        }        if (fread(&j, 1, 4, svcd_info) != 4) {                struct stat statbuf;                if (stat(svcd_name, &statbuf))                        sprintf(tmpStr, "Unable to get size of SVCD temporary file %s: %s.",                                svcd_name, strerrno());                else                        sprintf(tmpStr, "Unable to read from SVCD temporary file %s, offset = %u, size = %u: %s.",                                svcd_name, (uint)(frame << 2),(uint)statbuf.st_size, strerrno());                DisplayError(tmpStr);                return FALSE;        }        i = j / 4500;        if (i) {                ptr[0] = (unsigned char) (((i / 10) << 4) | (i % 10));                j %= 4500;        } else                ptr[0] = 0;        i = j / 75;        if (i) {                ptr[1] = (unsigned char) (0x80 | ((i / 10) << 4) | (i % 10));                j %= 75;        } else                ptr[1] = 0x80;        ptr[2] = (unsigned char) (0x80 | ((j / 10) << 4) | (j % 10));        return TRUE;}static int embed_svcd_scan_info(Video_struc *video_info){        char tmpStr[MAXPATH];        int percent, oldPercent;        int i, totIFrames, iFrames5s, errorexit, gop_size;        unsigned int j;        unsigned char info_data[12];        bitstream bs;        off_t ret;        long hiLong;        struct stat statbuf;        if ((video_info->picture_rate < 1) || (video_info->picture_rate > 8)) {                DisplayInfo("  SVCD scan offsets aborted, invalid frame rate");                return TRUE;        }        if (!video_info->num_groups) {                DisplayInfo("  SVCD scan offsets aborted, no GOP headers found");                return TRUE;        }        errorexit = TRUE;        fclose(svcd_info);        svcd_info = NULL;        if (stat(svcd_name, &statbuf)) {                sprintf("Unable to get the size of the SVCD temporary file %s: %s.",                        svcd_name, strerrno());                DisplayError(tmpStr);                return FALSE;        }        svcd_info = fopen(svcd_name, "rb");        if (!svcd_info) {                sprintf("Unable to open SVCD temporary file %s: %s.",                        svcd_name, strerrno());                DisplayError(tmpStr);                return FALSE;        }        totIFrames = statbuf.st_size >> 2;        sprintf(tmpStr, "  Calculating %d SVCD user data scan offsets for file %s", totIFrames, programFilename);        DisplayInfo(tmpStr);        if (!init_getbits(&bs, programFilename))                return FALSE;        i = 0;        oldPercent = -1;        gop_size = (int)floor((double)video_info->num_pictures / (double)video_info->num_groups + 0.5);        if (video_info->pulldown)                iFrames5s = (int)ceil(120.0 / (double)gop_size);        else                iFrames5s = (int)ceil((5.0 * picture_rates[video_info->picture_rate]) / gop_size);        while ((i < totIFrames) && !end_bs(&bs)) {                if (AbortMPEG)                        goto exit2;                percent = (int)floor(((double) (i)) / ((double) totIFrames) * 100.0);                if (percent != oldPercent) {                        sprintf(tmpStr, "SVCD Scan Offsets: %d%% - %d of %d  I-Frames.", percent, i, totIFrames);                        DisplayProgress(tmpStr, percent);                        oldPercent = percent;                }                if (seek_sync(&bs, USER_DATA_START, 32)) {                        if (!getbits(&bs, &j, 8)) {                                sprintf(tmpStr, "Unable to read from program file %s.", programFilename);                                DisplayError(tmpStr);                                goto exit2;                        }                        if (j == 0x10) {                                if (!getbits(&bs, &j, 8)) {                                        sprintf(tmpStr, "Unable to read from program file %s.", programFilename);                                        DisplayError(tmpStr);                                        goto exit2;                                }                                if (j == 0x0E) {                                        hiLong = 0;                                        ret = lseek(programFile, (off_t) (bitcount(&bs) / 8.0), SEEK_SET);                                        if ((ret == (off_t)-1)) {                                                sprintf(tmpStr, "Unable to seek position in program file %s: %s.",                                                        programFilename, strerrno());                                                DisplayError(tmpStr);                                                goto exit2;                                        }                                        /* fill in previous_I_offset */                                        if (i) {                                                if (!sector_to_timecode(&info_data[0], i - 1))                                                        goto exit2;                                        } else                                                info_data[0] = info_data[1] = info_data[2] = 0xFF;                                        /* fill in next_I_offset */                                        if (i < totIFrames - 1) {                                                if (!sector_to_timecode(&info_data[3], i + 1))                                                        goto exit2;                                        } else                                                info_data[3] = info_data[4] = info_data[5] = 0xFF;                                        /* fill in backward_offset */                                        if (i > iFrames5s - 1)                                                j = i - iFrames5s;                                        else                                                j = 0;                                        if (!sector_to_timecode(&info_data[6], j))                                                goto exit2;                                        /* fill in forward_offset */                                        if (i < (totIFrames - iFrames5s - 1))                                                j = i + iFrames5s;                                        else                                                j = totIFrames - 1;                                        if (!sector_to_timecode(&info_data[9], j))                                                goto exit2;                                        if (verbose) {                                                sprintf(tmpStr, "  i frame: %d", i);                                                DisplayInfo(tmpStr);                                                sprintf(tmpStr, "    Prev I Offset: %02X:%02X:%02X", info_data[0], info_data[1] & 0x7f, info_data[2] & 0x7f);                                                DisplayInfo(tmpStr);                                                sprintf(tmpStr, "    Next I Offset: %02X:%02X:%02X", info_data[3], info_data[4] & 0x7f, info_data[5] & 0x7f);                                                DisplayInfo(tmpStr);                                                sprintf(tmpStr, "    Back I Offset: %02X:%02X:%02X", info_data[6], info_data[7] & 0x7f, info_data[8] & 0x7f);                                                DisplayInfo(tmpStr);                                                sprintf(tmpStr, "    Forw I Offset: %02X:%02X:%02X", info_data[9], info_data[10] & 0x7f, info_data[11] & 0x7f);                                                DisplayInfo(tmpStr);                                        }                                        if ( write(programFile, &info_data[0], 12L) <= 0) {                                                sprintf(tmpStr, "Unable to write to program file %s: %s.",                                                        programFilename, strerrno());                                                DisplayError(tmpStr);                                                goto exit2;                                        }                                        i++;           

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -