mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-01-29 22:00:58 +02:00
mpegts_probe: detect files with garbage at the begin.
Fixes Ticket1811 Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
parent
84e7d368d6
commit
304ebed586
@ -1880,24 +1880,34 @@ static int handle_packets(MpegTSContext *ts, int nb_packets)
|
||||
static int mpegts_probe(AVProbeData *p)
|
||||
{
|
||||
const int size= p->buf_size;
|
||||
int score, fec_score, dvhs_score;
|
||||
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 < CHECK_COUNT)
|
||||
return -1;
|
||||
|
||||
score = analyze(p->buf, TS_PACKET_SIZE *check_count, TS_PACKET_SIZE , NULL)*CHECK_COUNT/check_count;
|
||||
dvhs_score= analyze(p->buf, TS_DVHS_PACKET_SIZE*check_count, TS_DVHS_PACKET_SIZE, NULL)*CHECK_COUNT/check_count;
|
||||
fec_score = analyze(p->buf, TS_FEC_PACKET_SIZE *check_count, TS_FEC_PACKET_SIZE , NULL)*CHECK_COUNT/check_count;
|
||||
av_dlog(NULL, "score: %d, dvhs_score: %d, fec_score: %d \n",
|
||||
score, dvhs_score, fec_score);
|
||||
for (i=0; i<check_count; i+=CHECK_BLOCK){
|
||||
int left = FFMIN(check_count - i, CHECK_BLOCK);
|
||||
int score = analyze(p->buf + TS_PACKET_SIZE *i, TS_PACKET_SIZE *left, TS_PACKET_SIZE , NULL);
|
||||
int dvhs_score= analyze(p->buf + TS_DVHS_PACKET_SIZE*i, TS_DVHS_PACKET_SIZE*left, TS_DVHS_PACKET_SIZE, NULL);
|
||||
int fec_score = analyze(p->buf + TS_FEC_PACKET_SIZE *i, TS_FEC_PACKET_SIZE *left, TS_FEC_PACKET_SIZE , NULL);
|
||||
score = FFMAX3(score, dvhs_score, fec_score);
|
||||
sumscore += score;
|
||||
maxscore = FFMAX(maxscore, score);
|
||||
}
|
||||
|
||||
// we need a clear definition for the returned score otherwise things will become messy sooner or later
|
||||
if (score > fec_score && score > dvhs_score && score > 6) return AVPROBE_SCORE_MAX + score - CHECK_COUNT;
|
||||
else if(dvhs_score > score && dvhs_score > fec_score && dvhs_score > 6) return AVPROBE_SCORE_MAX + dvhs_score - CHECK_COUNT;
|
||||
else if( fec_score > 6) return AVPROBE_SCORE_MAX + fec_score - CHECK_COUNT;
|
||||
else return -1;
|
||||
sumscore = sumscore*CHECK_COUNT/check_count;
|
||||
maxscore = maxscore*CHECK_COUNT/CHECK_BLOCK;
|
||||
|
||||
av_dlog(0, "TS score: %d %d\n", sumscore, maxscore);
|
||||
|
||||
if (sumscore > 6) return AVPROBE_SCORE_MAX + sumscore - CHECK_COUNT;
|
||||
else if (maxscore > 6) return AVPROBE_SCORE_MAX/2 + sumscore - CHECK_COUNT;
|
||||
else return -1;
|
||||
}
|
||||
|
||||
/* return the 90kHz PCR and the extension for the 27MHz PCR. return
|
||||
|
Loading…
x
Reference in New Issue
Block a user