- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何识别 mpegts 文件?我从 here 复制了以下代码,并且它在很多文件上都运行良好,但他也识别出this file作为 mpegts 视频。下面是有问题的文件的开头。
这是我使用的代码:
#define MPEGTS_MIN_BUF_SIZE 1024 * 4
static __forceinline const uint16_t av_bswap16(uint16_t x)
{
x = (x >> 8) | (x << 8);
return x;
}
#define AV_RB16(x) av_bswap16(x)
#define bswap16(x) ((x)>>8 | ((x)&255)<<8) // https://stackoverflow.com/a/648215/7206675
#define FFMAX(a,b) ((a) > (b) ? (a) : (b))
#define FFMAX3(a,b,c) FFMAX(FFMAX(a,b),c)
#define FFMIN(a,b) ((a) > (b) ? (b) : (a))
#define FFMIN3(a,b,c) FFMIN(FFMIN(a,b),c)
static int analyze2(const uint8_t* buf, int size, int packet_size,
int probe)
{
int stat[TS_MAX_PACKET_SIZE];
int stat_all = 0;
int i;
int best_score = 0;
memset(stat, 0, packet_size * sizeof(*stat));
for (i = 0; i < size - 3; i++)
{
if (buf[i] == 0x47)
{
int pid = AV_RB16(buf + 1) & 0x1FFF;
int asc = buf[i + 3] & 0x30;
if (!probe || pid == 0x1FFF || asc)
{
int x = i % packet_size;
stat[x]++;
stat_all++;
if (stat[x] > best_score)
{
best_score = stat[x];
}
}
}
}
return best_score - FFMAX(stat_all - 10 * best_score, 0) / 10;
}
/**
* This structure contains the data a format has to probe a file.
*/
typedef struct AVProbeData {
const char* filename;
unsigned char* buf; /**< Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero. */
int buf_size; /**< Size of buf except extra allocated bytes */
const char* mime_type; /**< mime_type, when known. */
} AVProbeData;
#define AVPROBE_SCORE_MAX 100 ///< maximum score
static int mpegts_probe(const AVProbeData* p)
{
const int size = p->buf_size;
int maxscore = 0;
int sumscore = 0;
int i;
int check_count = size / TS_FEC_PACKET_SIZE;
#define CHECK_COUNT 10
#define CHECK_BLOCK 100
if (!check_count)
return 0;
for (i = 0; i < check_count; i += CHECK_BLOCK) {
int left = FFMIN(check_count - i, CHECK_BLOCK);
int score = analyze2(p->buf + TS_PACKET_SIZE * i, TS_PACKET_SIZE * left, TS_PACKET_SIZE, 1);
int dvhs_score = analyze2(p->buf + TS_DVHS_PACKET_SIZE * i, TS_DVHS_PACKET_SIZE * left, TS_DVHS_PACKET_SIZE, 1);
int fec_score = analyze2(p->buf + TS_FEC_PACKET_SIZE * i, TS_FEC_PACKET_SIZE * left, TS_FEC_PACKET_SIZE, 1);
score = FFMAX3(score, dvhs_score, fec_score);
sumscore += score;
maxscore = FFMAX(maxscore, score);
}
sumscore = sumscore * CHECK_COUNT / check_count;
maxscore = maxscore * CHECK_COUNT / CHECK_BLOCK;
//ff_dlog(0, "TS score: %d %d\n", sumscore, maxscore);
if (check_count > CHECK_COUNT && sumscore > 6) {
return AVPROBE_SCORE_MAX + sumscore - CHECK_COUNT;
}
else if (check_count >= CHECK_COUNT && sumscore > 6) {
return AVPROBE_SCORE_MAX / 2 + sumscore - CHECK_COUNT;
}
else if (check_count >= CHECK_COUNT && maxscore > 6) {
return AVPROBE_SCORE_MAX / 2 + sumscore - CHECK_COUNT;
}
else if (sumscore > 6) {
return 2;
}
else {
return 0;
}
}
int main()
{
BOOL IsMpegtsVideo = FALSE;
char buf[MPEGTS_MIN_BUF_SIZE];
ReadMyTestFile(buf);
AVProbeData p;
p.buf = buf;
p.buf_size = MPEGTS_MIN_BUF_SIZE;
int score = mpegts_probe(&p);
IsMpegtsVideo = score > 0;
return 0;
}
这是被错误识别为视频的文件的开头:
#ifdef TARGET_ABI32
/*
* Linux N32 syscalls are in the range from 6000 to 6999.
*/
#define TARGET_NR_Linux 6000
#define TARGET_NR_read (TARGET_NR_Linux + 0)
#define TARGET_NR_write (TARGET_NR_Linux + 1)
#define TARGET_NR_open (TARGET_NR_Linux + 2)
#define TARGET_NR_close (TARGET_NR_Linux + 3)
#define TARGET_NR_stat (TARGET_NR_Linux + 4)
#define TARGET_NR_fstat (TARGET_NR_Linux + 5)
#define TARGET_NR_lstat (TARGET_NR_Linux + 6)
#define TARGET_NR_poll (TARGET_NR_Linux + 7)
#define TARGET_NR_lseek (TARGET_NR_Linux + 8)
#define TARGET_NR_mmap (TARGET_NR_Linux + 9)
#define TARGET_NR_mprotect (TARGET_NR_Linux + 10)
#define TARGET_NR_munmap (TARGET_NR_Linux + 11)
#define TARGET_NR_brk (TARGET_NR_Linux + 12)
#define TARGET_NR_rt_sigaction (TARGET_NR_Linux + 13)
#define TARGET_NR_rt_sigprocmask (TARGET_NR_Linux + 14)
#define TARGET_NR_ioctl (TARGET_NR_Linux + 15)
#define TARGET_NR_pread64 (TARGET_NR_Linux + 16)
#define TARGET_NR_pwrite64 (TARGET_NR_Linux + 17)
#define TARGET_NR_readv (TARGET_NR_Linux + 18)
#define TARGET_NR_writev (TARGET_NR_Linux + 19)
#define TARGET_NR_access (TARGET_NR_Linux + 20)
#define TARGET_NR_pipe (TARGET_NR_Linux + 21)
#define TARGET_NR__newselect (TARGET_NR_Linux + 22)
#define TARGET_NR_sched_yield (TARGET_NR_Linux + 23)
#define TARGET_NR_mremap (TARGET_NR_Linux + 24)
#define TARGET_NR_msync (TARGET_NR_Linux + 25)
#define TARGET_NR_mincore (TARGET_NR_Linux + 26)
#define TARGET_NR_madvise (TARGET_NR_Linux + 27)
#define TARGET_NR_shmget (TARGET_NR_Linux + 28)
#define TARGET_NR_shmat (TARGET_NR_Linux + 29)
#define TARGET_NR_shmctl (TARGET_NR_Linux + 30)
#define TARGET_NR_dup (TARGET_NR_Linux + 31)
#define TARGET_NR_dup2 (TARGET_NR_Linux + 32)
如何改进我的代码,使其无法将上述文件识别为视频,而另一方面继续将其识别为实际上是视频的视频文件?
最佳答案
您需要查看 Pid
字段 - Packet identifier flag, used to associate one packet with a set
.它可以有很多有效值,但必须首先带有 PatPid
之类的值, SdtPid
.
如果这些值没有出现在第一个数据包中,则可能不是视频。
public enum PidType
{
PatPid = 0x0,
CatPid = 0x1,
TsDescPid = 0x2,
NitPid = 0x10,
SdtPid = 0x11,
EitPid = 0x12,
NullPid = 0x1FFF
}
关于c - 如何识别 mpegts 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69456626/
谁能解释一下 mpeg-ts 的工作原理。我已经阅读了规范文档,但不明白为什么将多个流组合成一个流。 我还使用媒体信息工具打开了一个 .ts 文件,对于音频,它显示了 2 个音频流。那么在播放内容时将
我使用 ffmpeg 确实读取了一个 udp 流(仅包含视频)并解码帧,然后我想再次编码,但是在解码或从解复用过程中,我得到模糊的图片图片,尤其是下部。 我有一个视频播放器,它也使用 ffmpeg 完
我在几个视频流上使用以下命令将它们传送到我的 TVHeadend 服务器。 pipe:///usr/bin/ffmpeg -i *URL* -c copy -metadata service_prov
我需要一个应用程序,它接受输入 rtp MpegTS 流并将其重新复用,重新映射 PID,然后将其作为 RTP MpegTS 多播发送出去。我了解当前形式的 FFMPEG 无法执行此操作,因为 rtp
如何识别 mpegts 文件?我从 here 复制了以下代码,并且它在很多文件上都运行良好,但他也识别出this file作为 mpegts 视频。下面是有问题的文件的开头。 这是我使用的代码: #d
以下是我使用 ffmpeg 将 MPEG-TS 流式传输到中继的方法: ffmpeg -re -i out.ts -f mpegts -vcodec copy -acodec copy http://
我正在使用 ffmpeg 创建流式音频,如下所示: ffmpeg -i test.mp3 -vn -ac 2 -acodec aac -f segment -segment_format mpegts
我正在尝试查找转码 Assets 的大小,但我发现 .ts 文件的大小总和与 ffmpeg 创建的 mpegts 输出文件的大小总和不匹配。 例如: 使用 5Mb 的源,我得到以下输出 /ffmpeg
据我所知,PCR 以 42 位存储,PTS 以 33 位存储在 mpegts 容器中 所以, Max value for PCR is 2^42 = 4398046511104 Max value
最近我有一个任务,将文件格式转换为 mp4 并进行流式传输。我使用ffmpeg作为转码工具。 MP4 文件不会通过 http 协议(protocol)进行流式传输 [已使用 php cgi 包装器],
这有效: ffmpeg -i test.mp4 -framerate 30 -video_size 1280x720 -c:v libx264 -preset veryfast -maxrate 1
我正在编写一个视频/音频播放器,它使用 libav/ffmpeg 通过 UDP 对 MPEGTS 流进行解复用和解码。我正在处理的一个问题是,有时流在循环,当它循环时,我的播放器会崩溃。 问题在于,一
我正在尝试将 rtsp 流转码为 Android 可以读取的内容。 我需要输入 rtsp:将其转码为 H.264 AVC(基线)MPEGTS + AAC LC 音频。向本地主机套接字广播。 目前我有:
我的服务器通过 ffmpeg 对视频文件(h264/acc,基于 mpegts 的格式)进行编码,然后发送到 iPhone 中的客户端。 ios sdk 的默认 mediaplayer 无法播放这些视
服务器将视频转码为h264/aac,同时将视频数据发送给客户端。为了同时播放和保存视频数据,我使用mpegts作为容器格式,但问题是ios MediaPlayer无法播放mpegts文件。 Googl
我有一个包含单个程序的 mpeg-ts 文件。该程序由一些流组成 - 一个视频流和一些元数据流。 我想将一个特定的流提取到一个单独的文件中。然而,元数据是使用 ffmpeg 不知道的编解码器编码的。我
我想在我的 android 应用程序中通过 udp 接收 mpegts。为此,我正在使用 gstreamer。现在,我正在尝试通过 udp 从同一台计算机的 vlc 播放器发送 mpegts 流。 在
我正在使用 ffmpeg 记录来自 GDI(Windows 屏幕录像机)的视频输入,以便稍后使用 VLC(通过 ActiveX 插件)+ ffmpeg 对其进行解码。 现在在视频中搜索无法通过插件在
我有一个 Python 程序的输出,它作为一个包含 3 个视频流的单个 .AVI 出现,但是,它们似乎都是组合的。视频没有连接,但它们是交错的。生成它的代码非常抽象,我唯一能说的是他们使用 Gstre
我正在开发使用 FFMPEG API 发送 mpeg2ts 流的应用程序。(avio_open、avformat_new_stream 等) 问题是应用程序已经具有 AAC-LC 音频,因此不需要对音
我是一名优秀的程序员,十分优秀!