2009-04-24 19:42:21 +02:00
|
|
|
// Copyright (c) 2009 Fredrik Mellbin
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
|
|
// in the Software without restriction, including without limitation the rights
|
|
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
|
|
// furnished to do so, subject to the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
// THE SOFTWARE.
|
|
|
|
|
|
|
|
extern "C" {
|
2009-05-12 22:50:40 +02:00
|
|
|
#include <libavutil/log.h>
|
2009-04-24 19:42:21 +02:00
|
|
|
#include <libavutil/md5.h>
|
|
|
|
}
|
|
|
|
|
2009-05-22 23:28:02 +02:00
|
|
|
#include <cassert>
|
2009-04-24 19:42:21 +02:00
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
#include "ffms.h"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2009-05-22 23:28:02 +02:00
|
|
|
#define VERBOSE
|
2009-04-24 19:42:21 +02:00
|
|
|
|
2009-05-18 00:02:43 +02:00
|
|
|
static int FFMS_CC UpdateProgress(int64_t Current, int64_t Total, void *Private) {
|
2009-04-24 19:42:21 +02:00
|
|
|
|
2009-05-23 01:28:08 +02:00
|
|
|
int *LastPercentage = (int *)Private;
|
2009-04-24 19:42:21 +02:00
|
|
|
int Percentage = int((double(Current)/double(Total)) * 100);
|
|
|
|
|
2009-05-23 01:28:08 +02:00
|
|
|
if (Percentage <= *LastPercentage)
|
2009-04-24 19:42:21 +02:00
|
|
|
return 0;
|
|
|
|
|
2009-05-23 01:28:08 +02:00
|
|
|
*LastPercentage = Percentage;
|
2009-04-24 19:42:21 +02:00
|
|
|
|
|
|
|
#ifdef VERBOSE
|
2009-05-22 23:28:02 +02:00
|
|
|
cout << "Indexing, please wait... " << Percentage << "% \r" << flush;
|
2009-04-24 19:42:21 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-05-22 23:28:02 +02:00
|
|
|
void TestFullDump1(char *SrcFile, bool WithAudio) {
|
2009-05-23 01:28:08 +02:00
|
|
|
int Private;
|
2009-04-24 19:42:21 +02:00
|
|
|
char ErrorMsg[2000];
|
2009-05-22 23:28:02 +02:00
|
|
|
int ret = FFMS_Init();
|
|
|
|
assert(!ret);
|
|
|
|
|
|
|
|
FFIndexer *FIdx = FFMS_CreateIndexer(SrcFile, ErrorMsg, sizeof(ErrorMsg));
|
|
|
|
assert(FIdx);
|
|
|
|
FFMS_CancelIndexing(FIdx);
|
|
|
|
FIdx = FFMS_CreateIndexer(SrcFile, ErrorMsg, sizeof(ErrorMsg));
|
|
|
|
assert(FIdx);
|
|
|
|
|
2009-05-23 01:28:08 +02:00
|
|
|
FFIndex *FI = FFMS_DoIndexing(FIdx, -1, -1, FFMS_DefaultAudioFilename, NULL, false, UpdateProgress, &Private, ErrorMsg, sizeof(ErrorMsg));
|
2009-05-22 23:28:02 +02:00
|
|
|
assert(FI);
|
|
|
|
|
|
|
|
int vtrack = FFMS_GetFirstTrackOfType(FI, FFMS_TYPE_VIDEO, ErrorMsg, sizeof(ErrorMsg));
|
|
|
|
assert(vtrack >= 0);
|
|
|
|
int atrack = FFMS_GetFirstTrackOfType(FI, FFMS_TYPE_AUDIO, ErrorMsg, sizeof(ErrorMsg));
|
|
|
|
assert(atrack >= 0);
|
|
|
|
|
2009-05-23 01:28:08 +02:00
|
|
|
FFVideo *V = FFMS_CreateVideoSource(SrcFile, vtrack, FI, "", 2, 1, ErrorMsg, sizeof(ErrorMsg));
|
2009-05-22 23:28:02 +02:00
|
|
|
assert(V);
|
|
|
|
|
|
|
|
if (WithAudio) {
|
|
|
|
uint8_t *DB = new uint8_t[100000];
|
|
|
|
FFAudio *A = FFMS_CreateAudioSource(SrcFile, atrack, FI, ErrorMsg, sizeof(ErrorMsg));
|
|
|
|
assert(A);
|
|
|
|
|
|
|
|
const TAudioProperties *AP = FFMS_GetAudioProperties(A);
|
|
|
|
for (int i = 0; i < AP->NumSamples / 1000; i++) {
|
|
|
|
ret = FFMS_GetAudio(A, DB, i * 1000, 1000, ErrorMsg, sizeof(ErrorMsg));
|
|
|
|
assert(!ret);
|
|
|
|
}
|
2009-04-24 19:42:21 +02:00
|
|
|
|
2009-05-22 23:28:02 +02:00
|
|
|
FFMS_DestroyAudioSource(A);
|
|
|
|
delete[] DB;
|
2009-04-24 19:42:21 +02:00
|
|
|
}
|
|
|
|
|
2009-05-18 00:02:43 +02:00
|
|
|
const TVideoProperties *VP = FFMS_GetVideoProperties(V);
|
2009-04-24 19:42:21 +02:00
|
|
|
for (int i = 0; i < VP->NumFrames; i++) {
|
2009-05-16 01:11:18 +02:00
|
|
|
const TAVFrameLite *AVF = FFMS_GetFrame(V, i, ErrorMsg, sizeof(ErrorMsg));
|
2009-05-22 23:28:02 +02:00
|
|
|
assert(AVF);
|
2009-04-24 19:42:21 +02:00
|
|
|
}
|
|
|
|
|
2009-05-22 23:28:02 +02:00
|
|
|
FFMS_DestroyFFIndex(FI);
|
2009-05-16 01:11:18 +02:00
|
|
|
FFMS_DestroyVideoSource(V);
|
2009-05-22 23:28:02 +02:00
|
|
|
FFMS_DeInit();
|
|
|
|
}
|
2009-04-29 23:06:07 +02:00
|
|
|
|
2009-05-22 23:28:02 +02:00
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
char *TestFiles1[10];
|
|
|
|
TestFiles1[0] = "[FLV1]_The_Melancholy_of_Haruhi_Suzumiya_-_Full_Clean_Ending.flv";
|
|
|
|
TestFiles1[1] = "jra_jupiter.avi";
|
2009-05-23 01:28:08 +02:00
|
|
|
TestFiles1[2] = "Zero1_ITV2_TS_Test.ts";
|
|
|
|
TestFiles1[3] = "zx.starship.operators.01.h264.mkv";
|
2009-05-22 23:28:02 +02:00
|
|
|
TestFiles1[4] = "negative-timecodes.avi";
|
2009-05-23 01:28:08 +02:00
|
|
|
TestFiles1[5] = "h264_16-bframes_16-references_pyramid_crash-indexing.mkv";
|
|
|
|
TestFiles1[6] = "pyramid-adaptive-10-bframes.mkv";
|
2009-05-22 23:28:02 +02:00
|
|
|
|
2009-05-23 01:28:08 +02:00
|
|
|
for (int i = 0; i < 5; i++)
|
2009-05-23 00:12:31 +02:00
|
|
|
TestFullDump1(TestFiles1[i], true);
|
2009-05-22 23:28:02 +02:00
|
|
|
/*
|
|
|
|
TestFullDump1(TestFiles1[5], false);
|
|
|
|
|
|
|
|
for (int i = 0; i < 5; i++)
|
|
|
|
TestFullDump1(TestFiles1[i], true);
|
|
|
|
TestFullDump1(TestFiles1[5], false);
|
|
|
|
*/
|
2009-04-24 19:42:21 +02:00
|
|
|
return 0;
|
2009-05-22 23:28:02 +02:00
|
|
|
}
|