1 Star 0 Fork 0

wangzhankun/untrunc

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
moovfirst
.gitignore
.gitmodules
.travis.yml
AP_AtomDefinitions.h
COPYING
Dockerfile
README.md
atom.cpp
atom.h
avlog.h
codec.cpp
codec.h
codec_alac.cpp
codec_apch.cpp
codec_avc1.cpp
codec_camm.cpp
codec_fdsc.cpp
codec_gpmd.cpp
codec_hev1.cpp
codec_mbex.cpp
codec_mijd.cpp
codec_mp4a.cpp
codec_mp4v.cpp
codec_pcm.cpp
codec_rtp.cpp
codec_text.cpp
codec_tmcd.cpp
codec_unknown.cpp
codecstats.cpp
codecstats.h
file.cpp
file.h
log.cpp
log.h
main.cpp
mp4.cpp
mp4.h
osx_endian.h
track.cpp
track.h
untrunc.pro
克隆/下载
codecstats.cpp 2.20 KB
一键复制 编辑 原始数据 按行查看 历史
#include "codecstats.h"
#include "track.h"
#include "atom.h"
#include <map>
#include <iomanip>
#include <iostream>
#include "log.h"
using namespace std;
int GCD(int a, int b) {
if (a == 0)
return b;
if(b == 0)
return a;
if (a > b)
return GCD(a-b, b);
return GCD(a, b-a);
}
void CodecStats::init(Track &track, BufferedAtom *mdat) {
std::vector<Track::Chunk> &chunks = track.chunks;
if(!chunks.size())
return;
fixed_size = chunks[0].size;
//last chunk is skipped as in pcm could be a bit smaller.
for(size_t i = 0; i < chunks.size()-1; i++) {
auto &c = chunks[i];
if(c.size != fixed_size) {
fixed_size = 0;
break;
}
}
//it might happens that chunks get just grouped, find GCD
if(!fixed_size && track.codec.pcm) {
int gcd = 0;
for(size_t i = 0; i < chunks.size()-1; i++) {
gcd = GCD(gcd, chunks[i].size);
}
if(gcd >= 128)
fixed_size = gcd;
}
float step = (1<<20)/track.chunks.size();
int current_sample = 0;
for(Track::Chunk &chunk: track.chunks) {
int64_t offset = chunk.offset - mdat->content_start;
for(int s = 0; s < chunk.nsamples; s++) {
int size = track.getSize(s);
largestSample = std::max(size, largestSample);
smallestSample = std::min(size, smallestSample);
unsigned char *start = mdat->getFragment(offset, 8);// &(mdat->content[offset]);
int64_t begin64 = readBE<int64_t>(start);
int32_t begin32 = readBE<int32_t>(start);
if(track.codec.name == "avc1") {
begin64 = readBE<int32_t>(start + 4);
begin32 = readBE<int32_t>(start + 4) && 0x0000ffff;
}
if(!beginnings64.count(begin64)) {
beginnings64[begin64] = 1;
} else {
beginnings64[begin64]+= step;
}
if(!beginnings32.count(begin32)) {
beginnings32[begin32] = step;
} else {
beginnings32[begin32]+= step;
}
if(!track.default_size) { //pcm codecs with small samples.
offset += track.sample_sizes[current_sample];
current_sample++;
} else if(track.default_size > 80) {
offset += track.default_size;
current_sample++;
} else
break;
}
}
Log::debug << "Beginnings: \n";
int maxcount = 20;
for(auto &c: beginnings64) {
if(!maxcount--) break;
Log::debug << hex << setw(116) << c.first << ": " << c.second << dec << endl;
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wangzhankun/untrunc.git
git@gitee.com:wangzhankun/untrunc.git
wangzhankun
untrunc
untrunc
master

搜索帮助