• 大小: 6.69MB
    文件类型: .7z
    金币: 1
    下载: 0 次
    发布日期: 2023-08-12
  • 语言: 其他
  • 标签: TSDemux  

资源简介

TS流的解复用工程。具体的请参考我的博文<> http://blog.csdn.net/rootusers/article/details/43528261

资源截图

代码片段和文件信息

#include “ts.h“
#include “mpls.h“

namespace ts
{
class ts_file_info
{
public:
std::string filename;
u_int64_t first_dts;
u_int64_t first_pts;
u_int64_t last_pts;

ts_file_info(void) :first_dts(0) first_pts(0) last_pts(0) {}
};
inline int strcasecmp(const char* s1 const char* s2) { return lstrcmpi((LPWSTR)s1 (LPWSTR)s2); }

int scan_dir(const char* path std::list& l);
void load_playlist(const char* path std::list& l std::map& d);
int get_clip_number_by_filename(const std::string& s);

bool is_ts_filename(const std::string& s)
{
if (!s.length())
return false;

if (s[s.length() - 1] == ‘/‘ || s[s.length() - 1] == ‘\\‘)
return false;

std::string::size_type n = s.find_last_of(‘.‘);

if (n == std::string::npos)
return false;

std::string ext = s.substr(n + 1);

if (!strcasecmp(ext.c_str() “ts“) || !strcasecmp(ext.c_str() “m2ts“))
return true;

return false;
}

std::string trim_slash(const std::string& s)
{
const char* p = s.c_str() + s.length();

while (p > s.c_str() && (p[-1] == ‘/‘ || p[-1] == ‘\\‘))
p--;

return s.substr(0 p - s.c_str());
}

const char* timecode_to_time(u_int32_t timecode)
{
static char buf[128];

int msec = timecode % 1000;
timecode /= 1000;

int sec = timecode % 60;
timecode /= 60;

int min = timecode % 60;
timecode /= 60;

sprintf(buf “%.2i:%.2i:%.2i.%.3i“ (int)timecode min sec msec);

return buf;
}
}

int ts::scan_dir(const char* path std::list& l)
{
_finddata_t fileinfo;

intptr_t dir = _findfirst((std::string(path) + “\\*.*“).c_str() &fileinfo);

if (dir == -1)
perror(path);
else
{
while (!_findnext(dir &fileinfo))
if (!(fileinfo.attrib&_A_SUBDIR) && *fileinfo.name != ‘.‘)
{
char p[512];

int n = sprintf(p “%s\\%s“ path fileinfo.name);

l.push_back(std::string(p n));
}
}

_findclose(dir);

return l.size();
}


void ts::load_playlist(const char* path std::list& l std::map& d)
{
FILE* fp = fopen(path “r“);

char buf[512];

while (fgets(buf sizeof(buf) fp))
{
char* p = buf;
while (*p && (*p == ‘ ‘ || *p == ‘\t‘))
p++;

int len = 0;

char* p2 = strpbrk(p “#\r\n“);
if (p2)
len = p2 - p;
else
len = strlen(p);

while (len > 0 && (p[len - 1] == ‘ ‘ || p[len - 1] == ‘\t‘))
len--;

if (len > 0)
{
l.push_back(std::string());

std::string& s = l.back();

std::string ss(p len);
std::string::size_type n = ss.find_first_of(‘;‘);
if (n == std::string::npos)
s.swap(ss);
else
{
s = ss.substr(0 n);
d[get_clip_number_by_filename(s)] = ss.substr(n + 1);
}
}
}
}

int ts::get_clip_number_by_filename(const std::string& s)
{
int ll = s.length();
const char* p = s.c_str();

while (ll > 0)
{
if (p[ll - 1] == 

评论

共有 条评论

相关资源