Sai*_*tla -4 c c++ multimedia ffmpeg
我需要从示例 MPEG-TS 文件中获取 PIDS,我尝试使用读取文件fopen()并以十六进制格式获取数据。现在我一直在寻找整个数据中的 PID 字节。谁能帮我吗?
我使用了以下代码:
#include <stdio.h>
#include <string.h>
void main()
{
FILE *myfile;
FILE *output;
int i=0,j;
unsigned int buffer;
int o;
myfile=fopen("screen.ts","rb");
output = fopen("output2.txt","w");
do{
o=fread(&buffer, 2, 1, myfile);
if(o!=1)
break;
printf("%d: ",i);
printf("%x\n",buffer);
fprintf(output,"%x ",buffer);
i++;
}while(1);
}
Run Code Online (Sandbox Code Playgroud)
我从文件中获取了数据,现在我需要找到数据中的“PID”字节。
考虑一个指向pTS 包开始的指针。检查同步字节p[0] == 0x47。
PID 是一个 13 位无符号整数,您可以将其存储在 a 中uint16_t并且等于((p[1] & 0x1f) << 8) | p[2]。
将指针增加 TS 数据包的大小,通常为 188 字节。
重复。