📄 inptstrm.cpp
字号:
#include "main.h"#include "consts1.h"void DisplayInfo(char *info){ fprintf(stderr,"%s\n",info);}void DisplayError(char *err){ fprintf(stderr,"%s\n",err);}void DisplayProgress(char *st, int per){ fprintf(stderr,"%s \r",st);}/************************************************************************* File found?*************************************************************************/int open_file(char *name, unsigned int *bytes){ FILE* datei; char tmpStr[MAXPATH]; datei = fopen(name, "rb"); if (datei == NULL) { sprintf(tmpStr, "Unable to open file %s: %s.", name, strerrno()); DisplayError(tmpStr); return TRUE; } if (fseeko(datei, 0, 2)) { sprintf(tmpStr, "Error searching input file %s: %s.", name, strerrno()); fclose(datei); DisplayError(tmpStr); return TRUE; } if ((*bytes = ftello(datei)) == (uint)-1L) { sprintf(tmpStr, "Error getting size of input file %s: %s.", name, strerrno()); fclose(datei); DisplayError(tmpStr); return TRUE; } fclose(datei); return FALSE;}/************************************************************************* Basic Checks on MPEG Streams*************************************************************************/int marker_bit (bitstream *bs, unsigned int what){ unsigned int retval; char tmpStr[132]; if (!get1bit(bs, &retval)) return FALSE; if (what != retval) { sprintf(tmpStr, "Error in MPEG stream at offset (bits) %.0f: supposed marker bit not found.", bitcount(bs)); DisplayError(tmpStr); return FALSE; } return TRUE;}/************************************************************************* Check if files are valid MPEG streams*************************************************************************/int check_files ( unsigned int *audio_bytes, unsigned int *audio1_bytes, unsigned int *video_bytes, unsigned int which_streams){ unsigned int bytes_1, bytes_2, bytes_3, retval; int exiterror; char tmpStr[80]; bitstream bs; exiterror = TRUE; if (which_streams & STREAMS_VIDEO) { if (open_file(VideoFilename, &bytes_1)) return FALSE; if (!init_getbits(&bs, VideoFilename)) goto exit1; if (!getbits(&bs, &retval, 32)) goto exit1; if (retval != 0x1b3) { sprintf(tmpStr, "File %s is not a 11172-2 or 13818-2 Video stream.", VideoFilename); DisplayError(tmpStr); goto exit1; } else *video_bytes = bytes_1; finish_getbits(&bs); } if (which_streams & STREAMS_AUDIO) { if (open_file(AudioFilename, &bytes_2)) goto exit1; if (!init_getbits(&bs, AudioFilename)) goto exit1; if (!getbits(&bs, &retval, 12)) goto exit1; if (retval != 0xfff) { finish_getbits(&bs); if (!init_getbits(&bs, AudioFilename)) goto exit1; if (seek_sync(&bs, AC3_SYNCWORD, 16)) *audio_bytes = bytes_2; else { sprintf(tmpStr, "File %s is not an AC3 or MPEG Audio stream.", AudioFilename); DisplayError(tmpStr); goto exit1; } } else *audio_bytes = bytes_2; } if (which_streams & STREAMS_AUDIO1) { if (open_file(Audio1Filename, &bytes_3)) goto exit1; if (!init_getbits(&bs, Audio1Filename)) goto exit1; if (!getbits(&bs, &retval, 12)) goto exit1; if (retval != 0xfff) { finish_getbits(&bs); if (!init_getbits(&bs, Audio1Filename)) goto exit1; if (seek_sync(&bs, AC3_SYNCWORD, 16)) *audio1_bytes = bytes_3; else { sprintf(tmpStr, "File %s is not an AC3 or MPEG Audio stream.", Audio1Filename); DisplayError(tmpStr); goto exit1; } } else *audio1_bytes = bytes_3; } exiterror = FALSE;exit1: finish_getbits(&bs); return !exiterror;}static int scan_video(char *video_file, Video_struc *video_info){ bitstream bs; unsigned int retval, i, j, mpeg2flag, exiterror; unsigned int pulldown = 0, first_pulldown = 0; unsigned int syncword, temporal_reference; exiterror = TRUE; mpeg2flag = 0; video_info->pulldown = PULLDOWN_NONE; video_info->sh_length = 0; DisplayInfo(" "); if (mplex_pulldown_flag == PULLDOWN_AUTO) DisplayInfo(" Scanning video stream for a sequence header and pulldown type ..."); else DisplayInfo(" Scanning video stream for a sequence header ..."); if (!init_getbits(&bs, video_file)) goto scanexit; if (!getbits(&bs, &retval, 32)) goto scanexit; if (retval == SEQUENCE_HEADER) { j = 0; video_info->seq_hdr[j++] = 0; video_info->seq_hdr[j++] = 0; video_info->seq_hdr[j++] = 1; retval = 0xFFFFFFB3; while ((retval != GROUP_START) && (j < 256)) { video_info->seq_hdr[j++] = (unsigned char)(retval & 0xff); if (!getbits(&bs, &i, 8)) goto scanexit; retval = (retval << 8) | i; if (retval == EXT_START_CODE) mpeg2flag = 1; } if (retval == GROUP_START) video_info->sh_length = j - 3; /* see if the repeat first flag is set in any frame in the first GOP */ if (mpeg2flag) { j = 0; while (!j) { if (!seek_sync(&bs, SYNCWORD_START, 24)) j = 1; else { if (!getbits(&bs, &retval, 8)) j = 1; else { syncword = (SYNCWORD_START << 8) + retval; switch (syncword) { case SEQUENCE_HEADER: case GROUP_START: j = 1; break; case PICTURE_START: j = 1; if (!getbits(&bs, &retval, 10)) break; temporal_reference = retval; if (!seek_sync(&bs, EXT_START_CODE, 32)) break; if (!getbits(&bs, &retval, 4)) break; if (retval != CODING_ID) break; if (!getbits(&bs, &retval, 18)) break; if (!getbits(&bs, &retval, 2)) /* picture structure type */ break; if (retval != FRAME_PICTURE) break; /* see if repeat flag is set for auto pulldown detection */ if (!getbits(&bs, &retval, 7)) break; if (retval & 0x01) { pulldown = 1; if (!temporal_reference) first_pulldown = 1; } j = 0; break; } } } } if (pulldown) { if (first_pulldown) video_info->pulldown = PULLDOWN_32; else video_info->pulldown = PULLDOWN_23; } } if (mplex_pulldown_flag == PULLDOWN_AUTO) { switch (video_info->pulldown) { case PULLDOWN_32: DisplayInfo(" 3:2 pulldown detected ..."); break; case PULLDOWN_23: DisplayInfo(" 2:3 pulldown detected ..."); break; default: DisplayInfo(" no pulldown detected ..."); } } exiterror = FALSE; } else { DisplayError("Invalid MPEG Video stream header."); goto scanexit; }scanexit: finish_getbits(&bs); return !exiterror;}/************************************************************************* Get_Info_Video holt Informationen zu den einzelnen Access-Units (Frames) des Videofiles ein und speichert sie in einer temporaeren Datei ab. Wird spaeter zum Aufbau der gemultiplexten Datei gebraucht. Gets informations on the single access units (frames) of the video stream and saves them in a tmp file for further processing. We need it for building the multiplex file.*************************************************************************/int get_info_video (
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -