diff --git a/Makefile b/Makefile index 1da9ea0e..071165f2 100644 --- a/Makefile +++ b/Makefile @@ -1,32 +1,32 @@ ############################################################################# # Makefile for building: untrunc -# Generated by qmake (2.01a) (Qt 4.8.1) on: Fri Jun 28 10:25:17 2013 +# Generated by qmake (2.01a) (Qt 4.8.7) on: Sun May 15 23:31:05 2016 # Project: untrunc.pro # Template: app -# Command: /usr/bin/qmake -o Makefile untrunc.pro +# Command: /usr/bin/qmake-qt4 CONFIG=system_libav -o Makefile untrunc.pro ############################################################################# ####### Compiler, tools and options CC = gcc CXX = g++ -DEFINES = -DQT_WEBKIT -DQT_NO_DEBUG -CFLAGS = -m64 -pipe -O2 -Wall -W -D_REENTRANT $(DEFINES) -CXXFLAGS = -m64 -pipe -O2 -Wall -W -D_REENTRANT $(DEFINES) -INCPATH = -I/usr/share/qt4/mkspecs/linux-g++-64 -I. -I/usr/include/qt4 -I-I../libav-0.8.7/libavformat -I-I../libav-0.8.7/libavcodec -I-I../libav-0.8.7/libavutil -I. +DEFINES = -D_FILE_OFFSET_BITS=64 -DVERBOSE -DVERBOSE1 +CFLAGS = -pipe -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic -std=gnu++98 -Wno-deprecated -O2 $(DEFINES) +CXXFLAGS = -pipe -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic -std=gnu++98 -Wno-deprecated -O2 $(DEFINES) +INCPATH = -I/usr/lib64/qt4/mkspecs/linux-g++ -I. -I/usr/include/ffmpeg LINK = g++ -LFLAGS = -m64 -Wl,-O1 -LIBS = $(SUBLIBS) -L/usr/lib/x86_64-linux-gnu ../libav-0.8.7/libavformat/libavformat.a ../libav-0.8.7/libavcodec/libavcodec.a ../libav-0.8.7/libavutil/libavutil.a -lz -lpthread +LFLAGS = -Wl,-O1 -Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld +LIBS = $(SUBLIBS) -lz -lavformat -lavcodec -lavutil AR = ar cqs RANLIB = -QMAKE = /usr/bin/qmake +QMAKE = /usr/bin/qmake-qt4 TAR = tar -cf COMPRESS = gzip -9f COPY = cp -f SED = sed COPY_FILE = $(COPY) COPY_DIR = $(COPY) -r -STRIP = strip +STRIP = INSTALL_FILE = install -m 644 -p INSTALL_DIR = $(COPY_DIR) INSTALL_PROGRAM = install -m 755 -p @@ -53,31 +53,20 @@ OBJECTS = main.o \ mp4.o \ file.o \ track.o -DIST = /usr/share/qt4/mkspecs/common/unix.conf \ - /usr/share/qt4/mkspecs/common/linux.conf \ - /usr/share/qt4/mkspecs/common/gcc-base.conf \ - /usr/share/qt4/mkspecs/common/gcc-base-unix.conf \ - /usr/share/qt4/mkspecs/common/g++-base.conf \ - /usr/share/qt4/mkspecs/common/g++-unix.conf \ - /usr/share/qt4/mkspecs/qconfig.pri \ - /usr/share/qt4/mkspecs/modules/qt_phonon.pri \ - /usr/share/qt4/mkspecs/modules/qt_webkit_version.pri \ - /usr/share/qt4/mkspecs/features/qt_functions.prf \ - /usr/share/qt4/mkspecs/features/qt_config.prf \ - /usr/share/qt4/mkspecs/features/exclusive_builds.prf \ - /usr/share/qt4/mkspecs/features/default_pre.prf \ - /usr/share/qt4/mkspecs/features/release.prf \ - /usr/share/qt4/mkspecs/features/default_post.prf \ - /usr/share/qt4/mkspecs/features/unix/gdb_dwarf_index.prf \ - /usr/share/qt4/mkspecs/features/warn_on.prf \ - /usr/share/qt4/mkspecs/features/qt.prf \ - /usr/share/qt4/mkspecs/features/unix/thread.prf \ - /usr/share/qt4/mkspecs/features/moc.prf \ - /usr/share/qt4/mkspecs/features/resources.prf \ - /usr/share/qt4/mkspecs/features/uic.prf \ - /usr/share/qt4/mkspecs/features/yacc.prf \ - /usr/share/qt4/mkspecs/features/lex.prf \ - /usr/share/qt4/mkspecs/features/include_source_dir.prf \ +DIST = /usr/lib64/qt4/mkspecs/common/unix.conf \ + /usr/lib64/qt4/mkspecs/common/linux.conf \ + /usr/lib64/qt4/mkspecs/common/gcc-base.conf \ + /usr/lib64/qt4/mkspecs/common/gcc-base-unix.conf \ + /usr/lib64/qt4/mkspecs/common/g++-base.conf \ + /usr/lib64/qt4/mkspecs/common/g++-unix.conf \ + /usr/lib64/qt4/mkspecs/qconfig.pri \ + /usr/lib64/qt4/mkspecs/features/qt_functions.prf \ + /usr/lib64/qt4/mkspecs/features/qt_config.prf \ + /usr/lib64/qt4/mkspecs/features/exclusive_builds.prf \ + /usr/lib64/qt4/mkspecs/features/default_pre.prf \ + /usr/lib64/qt4/mkspecs/features/release.prf \ + /usr/lib64/qt4/mkspecs/features/default_post.prf \ + /usr/lib64/qt4/mkspecs/features/link_pkgconfig.prf \ untrunc.pro QMAKE_TARGET = untrunc DESTDIR = @@ -110,63 +99,41 @@ all: Makefile $(TARGET) $(TARGET): $(OBJECTS) $(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS) -Makefile: untrunc.pro /usr/share/qt4/mkspecs/linux-g++-64/qmake.conf /usr/share/qt4/mkspecs/common/unix.conf \ - /usr/share/qt4/mkspecs/common/linux.conf \ - /usr/share/qt4/mkspecs/common/gcc-base.conf \ - /usr/share/qt4/mkspecs/common/gcc-base-unix.conf \ - /usr/share/qt4/mkspecs/common/g++-base.conf \ - /usr/share/qt4/mkspecs/common/g++-unix.conf \ - /usr/share/qt4/mkspecs/qconfig.pri \ - /usr/share/qt4/mkspecs/modules/qt_phonon.pri \ - /usr/share/qt4/mkspecs/modules/qt_webkit_version.pri \ - /usr/share/qt4/mkspecs/features/qt_functions.prf \ - /usr/share/qt4/mkspecs/features/qt_config.prf \ - /usr/share/qt4/mkspecs/features/exclusive_builds.prf \ - /usr/share/qt4/mkspecs/features/default_pre.prf \ - /usr/share/qt4/mkspecs/features/release.prf \ - /usr/share/qt4/mkspecs/features/default_post.prf \ - /usr/share/qt4/mkspecs/features/unix/gdb_dwarf_index.prf \ - /usr/share/qt4/mkspecs/features/warn_on.prf \ - /usr/share/qt4/mkspecs/features/qt.prf \ - /usr/share/qt4/mkspecs/features/unix/thread.prf \ - /usr/share/qt4/mkspecs/features/moc.prf \ - /usr/share/qt4/mkspecs/features/resources.prf \ - /usr/share/qt4/mkspecs/features/uic.prf \ - /usr/share/qt4/mkspecs/features/yacc.prf \ - /usr/share/qt4/mkspecs/features/lex.prf \ - /usr/share/qt4/mkspecs/features/include_source_dir.prf - $(QMAKE) -o Makefile untrunc.pro -/usr/share/qt4/mkspecs/common/unix.conf: -/usr/share/qt4/mkspecs/common/linux.conf: -/usr/share/qt4/mkspecs/common/gcc-base.conf: -/usr/share/qt4/mkspecs/common/gcc-base-unix.conf: -/usr/share/qt4/mkspecs/common/g++-base.conf: -/usr/share/qt4/mkspecs/common/g++-unix.conf: -/usr/share/qt4/mkspecs/qconfig.pri: -/usr/share/qt4/mkspecs/modules/qt_phonon.pri: -/usr/share/qt4/mkspecs/modules/qt_webkit_version.pri: -/usr/share/qt4/mkspecs/features/qt_functions.prf: -/usr/share/qt4/mkspecs/features/qt_config.prf: -/usr/share/qt4/mkspecs/features/exclusive_builds.prf: -/usr/share/qt4/mkspecs/features/default_pre.prf: -/usr/share/qt4/mkspecs/features/release.prf: -/usr/share/qt4/mkspecs/features/default_post.prf: -/usr/share/qt4/mkspecs/features/unix/gdb_dwarf_index.prf: -/usr/share/qt4/mkspecs/features/warn_on.prf: -/usr/share/qt4/mkspecs/features/qt.prf: -/usr/share/qt4/mkspecs/features/unix/thread.prf: -/usr/share/qt4/mkspecs/features/moc.prf: -/usr/share/qt4/mkspecs/features/resources.prf: -/usr/share/qt4/mkspecs/features/uic.prf: -/usr/share/qt4/mkspecs/features/yacc.prf: -/usr/share/qt4/mkspecs/features/lex.prf: -/usr/share/qt4/mkspecs/features/include_source_dir.prf: +Makefile: untrunc.pro /usr/lib64/qt4/mkspecs/linux-g++/qmake.conf /usr/lib64/qt4/mkspecs/common/unix.conf \ + /usr/lib64/qt4/mkspecs/common/linux.conf \ + /usr/lib64/qt4/mkspecs/common/gcc-base.conf \ + /usr/lib64/qt4/mkspecs/common/gcc-base-unix.conf \ + /usr/lib64/qt4/mkspecs/common/g++-base.conf \ + /usr/lib64/qt4/mkspecs/common/g++-unix.conf \ + /usr/lib64/qt4/mkspecs/qconfig.pri \ + /usr/lib64/qt4/mkspecs/features/qt_functions.prf \ + /usr/lib64/qt4/mkspecs/features/qt_config.prf \ + /usr/lib64/qt4/mkspecs/features/exclusive_builds.prf \ + /usr/lib64/qt4/mkspecs/features/default_pre.prf \ + /usr/lib64/qt4/mkspecs/features/release.prf \ + /usr/lib64/qt4/mkspecs/features/default_post.prf \ + /usr/lib64/qt4/mkspecs/features/link_pkgconfig.prf + $(QMAKE) CONFIG=system_libav -o Makefile untrunc.pro +/usr/lib64/qt4/mkspecs/common/unix.conf: +/usr/lib64/qt4/mkspecs/common/linux.conf: +/usr/lib64/qt4/mkspecs/common/gcc-base.conf: +/usr/lib64/qt4/mkspecs/common/gcc-base-unix.conf: +/usr/lib64/qt4/mkspecs/common/g++-base.conf: +/usr/lib64/qt4/mkspecs/common/g++-unix.conf: +/usr/lib64/qt4/mkspecs/qconfig.pri: +/usr/lib64/qt4/mkspecs/features/qt_functions.prf: +/usr/lib64/qt4/mkspecs/features/qt_config.prf: +/usr/lib64/qt4/mkspecs/features/exclusive_builds.prf: +/usr/lib64/qt4/mkspecs/features/default_pre.prf: +/usr/lib64/qt4/mkspecs/features/release.prf: +/usr/lib64/qt4/mkspecs/features/default_post.prf: +/usr/lib64/qt4/mkspecs/features/link_pkgconfig.prf: qmake: FORCE - @$(QMAKE) -o Makefile untrunc.pro + @$(QMAKE) CONFIG=system_libav -o Makefile untrunc.pro dist: @$(CHK_DIR_EXISTS) .tmp/untrunc1.0.0 || $(MKDIR) .tmp/untrunc1.0.0 - $(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/untrunc1.0.0/ && $(COPY_FILE) --parents atom.h mp4.h file.h track.h .tmp/untrunc1.0.0/ && $(COPY_FILE) --parents main.cpp atom.cpp mp4.cpp file.cpp track.cpp .tmp/untrunc1.0.0/ && (cd `dirname .tmp/untrunc1.0.0` && $(TAR) untrunc1.0.0.tar untrunc1.0.0 && $(COMPRESS) untrunc1.0.0.tar) && $(MOVE) `dirname .tmp/untrunc1.0.0`/untrunc1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/untrunc1.0.0 + $(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/untrunc1.0.0/ && (cd `dirname .tmp/untrunc1.0.0` && $(TAR) untrunc1.0.0.tar untrunc1.0.0 && $(COMPRESS) untrunc1.0.0.tar) && $(MOVE) `dirname .tmp/untrunc1.0.0`/untrunc1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/untrunc1.0.0 clean:compiler_clean @@ -183,34 +150,14 @@ distclean: clean check: first -mocclean: compiler_moc_header_clean compiler_moc_source_clean - -mocables: compiler_moc_header_make_all compiler_moc_source_make_all - -compiler_moc_header_make_all: -compiler_moc_header_clean: -compiler_rcc_make_all: -compiler_rcc_clean: -compiler_image_collection_make_all: qmake_image_collection.cpp -compiler_image_collection_clean: - -$(DEL_FILE) qmake_image_collection.cpp -compiler_moc_source_make_all: -compiler_moc_source_clean: -compiler_uic_make_all: -compiler_uic_clean: -compiler_yacc_decl_make_all: -compiler_yacc_decl_clean: -compiler_yacc_impl_make_all: -compiler_yacc_impl_clean: -compiler_lex_make_all: -compiler_lex_clean: compiler_clean: ####### Compile main.o: main.cpp mp4.h \ track.h \ - atom.h + atom.h \ + file.h $(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o main.cpp atom.o: atom.cpp AP_AtomDefinitions.h \ @@ -228,7 +175,8 @@ file.o: file.cpp file.h $(CXX) -c $(CXXFLAGS) $(INCPATH) -o file.o file.cpp track.o: track.cpp track.h \ - atom.h + atom.h \ + file.h $(CXX) -c $(CXXFLAGS) $(INCPATH) -o track.o track.cpp ####### Install diff --git a/README.md b/README.md index 400c4d7a..232a3ff3 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,15 @@ Go into the directory where it's been unzipped: cd untrunc-master -Compile the source code using this command (all one line): +Reconfigure to link with Ubuntu's libav: + + qmake CONFIG="system_libav" + +Compile the source code with the generated Makefile: + + make + +Or compile the source code using this command (all one line): g++ -o untrunc file.cpp main.cpp track.cpp atom.cpp mp4.cpp -L/usr/local/lib -lavformat -lavcodec -lavutil diff --git a/atom.cpp b/atom.cpp index 49acb055..00c27b81 100644 --- a/atom.cpp +++ b/atom.cpp @@ -50,7 +50,7 @@ void Atom::parse(File &file) { void Atom::write(File &file) { //1 write length - int start = file.pos(); + off64_t start = file.pos(); file.writeInt(length); file.writeChar(name, 4); @@ -58,7 +58,7 @@ void Atom::write(File &file) { file.write(content); for(unsigned int i = 0; i < children.size(); i++) children[i]->write(file); - int end = file.pos(); + off64_t end = file.pos(); assert(end - start == length); } diff --git a/mp4.cpp b/mp4.cpp index 804ceccc..f962948f 100644 --- a/mp4.cpp +++ b/mp4.cpp @@ -160,7 +160,7 @@ void Mp4::makeStreamable(string filename, string output) { } } -void Mp4::saveVideo(string filename) { +void Mp4::saveVideo(string filename, int mdat_offset) { /* we save all atom except: ctts: composition offset ( we use sample to time) cslg: because it is used only when ctts is present @@ -195,11 +195,14 @@ void Mp4::saveVideo(string filename) { root->updateLength(); + if (mdat_offset == 0) { + mdat_offset = ftyp->length + moov->length; + } else if (ftyp->length + moov->length > mdat_offset) { + throw "Bad fixed offset"; + exit(1); + } //fix offsets - int offset = 8 + moov->length; - if(ftyp) - offset += ftyp->length; //not all mov have a ftyp. - + int offset = mdat_offset - mdat->start; for(unsigned int t = 0; t < tracks.size(); t++) { Track &track = tracks[t]; for(unsigned int i = 0; i < track.offsets.size(); i++) @@ -216,6 +219,18 @@ void Mp4::saveVideo(string filename) { if(ftyp) ftyp->write(file); moov->write(file); + if (mdat_offset > ftyp->length + moov->length + 8) { // would need 8 for atom header... + Atom free; + + free.start = ftyp->length + moov->length; + free.length = mdat_offset - free.start; + strcpy(free.name, "free"); + memset(free.head, 0, sizeof(free.head)); + memset(free.version, 0, sizeof(free.version)); + free.content.resize(free.length - 8); + free.write(file); + } + mdat->write(file); } @@ -363,7 +378,7 @@ void Mp4::repair(string filename) { if(length == -1 || length == 0) { continue; } - if(length >= maxlength) + if(length > maxlength) continue; #ifdef VERBOSE1 if(length > 8) diff --git a/mp4.h b/mp4.h index 0c9ee1a6..8726e668 100644 --- a/mp4.h +++ b/mp4.h @@ -43,10 +43,9 @@ class Mp4 { void printMediaInfo(); void printAtoms(); - void saveVideo(std::string filename); + void saveVideo(std::string filename, int mdat_offset = 0); void makeStreamable(std::string filename, std::string output); - void analyze(); void writeTracksToAtoms(); void repair(std::string filename); diff --git a/track.cpp b/track.cpp index 041c7e91..86d83602 100644 --- a/track.cpp +++ b/track.cpp @@ -75,7 +75,6 @@ void Codec::parse(Atom *trak, vector &offsets, Atom *mdat) { } } -#define VERBOSE 1 bool Codec::matchSample(unsigned char *start, int maxlength) { int s = be32toh(*(int *)start); @@ -257,7 +256,9 @@ int Codec::getLength(unsigned char *start, int maxlength) { }; */ int first_nal_type = (start[4] & 0x1f); +#ifdef VERBOSE cout << "Nal type: " << first_nal_type << endl; +#endif if(first_nal_type > 21) { cout << "Unrecognized nal type: " << first_nal_type << endl; return -1; @@ -278,8 +279,7 @@ int Codec::getLength(unsigned char *start, int maxlength) { //consume all nal units where type is != 1, 3, 5 unsigned char *pos = start; - bool found = false; - while(!found) { + while(1) { pos = start + length; assert(pos - start < maxlength - 4); int l = be32toh(*(int *)pos); @@ -288,8 +288,8 @@ int Codec::getLength(unsigned char *start, int maxlength) { int nal_type = (pos[4] & 0x1f); cout << "Intermediate nal type: " << nal_type << endl; - if(nal_type <= 5) found = true; + if(nal_type <= 5) break; //if(nal_type <= 5 || nal_type >= 18) break;//wrong nal or not video if(nal_type > 21) break; //unknown nal type if(l + length + 8 >= maxlength) break; //out of boundary @@ -410,8 +410,8 @@ void Track::writeToAtoms() { saveSampleTimes(); saveKeyframes(); saveSampleSizes(); - saveSampleToChunk(); saveChunkOffsets(); + saveSampleToChunk(); Atom *mdhd = trak->atomByName("mdhd"); mdhd->writeInt(duration, 16); @@ -466,9 +466,10 @@ void Track::fixTimes() { times.resize(offsets.size(), 160); return; } + uint32_t stdTime = times[1]; + times.reserve(offsets.size()); while(times.size() < offsets.size()) - times.insert(times.end(), times.begin(), times.end()); - times.resize(offsets.size()); + times.push_back(stdTime); duration = 0; for(unsigned int i = 0; i < times.size(); i++) @@ -577,13 +578,39 @@ vector Track::getSampleToChunk(Atom *t, int nchunks){ void Track::saveSampleTimes() { Atom *stts = trak->atomByName("stts"); assert(stts); + + unsigned int c = 0; + unsigned int it_time = times[0]; + unsigned int it_i; + + // first compute size of stts array + // we only have an entry in stts if a frame duration is different than the previous one + for(unsigned int i = 1; i < times.size(); i++) { + if ((i==1) || (times[i] != it_time) || (i == times.size() - 1)) { + c++; + it_time = times[i]; + } + } + stts->content.resize(4 + //version 4 + //entries - 8*times.size()); //time table - stts->writeInt(times.size(), 4); - for(unsigned int i = 0; i < times.size(); i++) { - stts->writeInt(1, 8 + 8*i); - stts->writeInt(times[i], 12 + 8*i); + 8*c); //time table + stts->writeInt(c, 4); + + // then write data + it_time = times[0]; + it_i = 0; + c = 0; + for(unsigned int i = 1; i <= times.size(); i++) { + if ((i==1) || ( i == times.size()) || (times[i] != it_time)) { + stts->writeInt(i - it_i, 8 + 8*c); + stts->writeInt(it_time, 12 + 8*c); + c++; + if (i != times.size()) { + it_time = times[i]; + it_i = i; + } + } } } @@ -618,13 +645,47 @@ void Track::saveSampleSizes() { void Track::saveSampleToChunk() { Atom *stsc = trak->atomByName("stsc"); assert(stsc); + + Atom *stco = trak->atomByName("stco"); + int stco_len = (stco->content.size() - 8 ) / 4; + stsc->content.resize(4 + // version 4 + //number of entries - 12); //one sample per chunk. - stsc->writeInt(1, 4); - stsc->writeInt(1, 8); //first chunk (1 based) - stsc->writeInt(1, 12); //one sample per chunk - stsc->writeInt(1, 16); //id 1 (WHAT IS THIS!) + 12 * stco_len); //one sample per chunk. + + unsigned int c = 1, cc = 0; + int i = 0; + int ss = 0; + int ss_acc = 0, acc = 1; + for(unsigned int i = 1; i < offsets.size(); i++) { + if (offsets[i-1] + sizes[i-1] == offsets[i]) { + acc++; + } else { + if (ss_acc != acc) { + stsc->writeInt(c, 8 + 12*cc); // + stsc->writeInt(acc, 12 + 12*cc); // + stsc->writeInt(1, 16 + 12*cc); //1 + cc++; + ss_acc = acc; + } + c++; + acc = 1; + } + } + + if (ss_acc != acc) { + stsc->writeInt(c, 8 + 12*cc); // + stsc->writeInt(acc, 12 + 12*cc); // + stsc->writeInt(1, 16 + 12*cc); //1 + cc++; + ss_acc = acc; + } + + stsc->writeInt(cc, 4); + + stsc->content.resize(4 + // version + 4 + //number of entries + 12 * cc); //one sample per chunk. } void Track::saveChunkOffsets() { @@ -638,12 +699,27 @@ void Track::saveChunkOffsets() { } Atom *stco = trak->atomByName("stco"); assert(stco); + + unsigned int c = 1; + unsigned int it_time = times[0]; + unsigned int it_i; + for(unsigned int i = 1; i < offsets.size(); i++) { + if (offsets[i-1] + sizes[i-1] != offsets[i]) { + c++; + } + } + stco->content.resize(4 + //version 4 + //number of entries - 4*offsets.size()); - stco->writeInt(offsets.size(), 4); - for(unsigned int i = 0; i < offsets.size(); i++) - stco->writeInt(offsets[i], 8 + 4*i); + 4*c); + stco->writeInt(c, 4); + c = 0; + for(unsigned int i = 0; i < offsets.size(); i++) { + if (i == 0 || (offsets[i-1] + sizes[i-1] != offsets[i])) { + stco->writeInt(offsets[i], 8 + 4*c); + c++; + } + } } diff --git a/untrunc.pro b/untrunc.pro index 581e44cf..37e8bc5f 100644 --- a/untrunc.pro +++ b/untrunc.pro @@ -27,12 +27,25 @@ HEADERS += \ file.h \ track.h -INCLUDEPATH += -I/usr/local/lib -LIBS += -L/usr/local/lib -lavformat -lavcodec -lavutil -DEFINES += _FILE_OFFSET_BITS=64 VERBOSE VERBOSE1 +CONFIG(system_libav) { + message(Building with system libav.) + #PKG_CONFIG = PKG_CONFIG_PATH=/usr/lib64/ffmpeg-compat/pkgconfig pkg-config + CONFIG += link_pkgconfig + PKGCONFIG += libavformat libavcodec libavutil + + # without pkg-config + #INCLUDEPATH += -I/usr/local/lib + #LIBS += -L/usr/local/lib -lavformat -lavcodec -lavutil +} else { + message(Building with static libav.) + LIBAV_SOURCE_PATH = ../libav-0.8.7 + LIBAV_BUILD_PATH = $$LIBAV_SOURCE_PATH + LIBAV_HEADER_PATH = $$LIBAV_SOURCE_PATH + INCLUDEPATH += -I$$LIBAV_HEADER_PATH/libavformat -I$$LIBAV_HEADER_PATH/libavcodec -I$$LIBAV_HEADER_PATH/libavutil + LIBS += $$LIBAV_BUILD_PATH/libavformat/libavformat.a $$LIBAV_BUILD_PATH/libavcodec/libavcodec.a $$LIBAV_BUILD_PATH/libavutil/libavutil.a +} -#INCLUDEPATH += -I../libav-0.8.7/libavformat -I../libav-0.8.7/libavcodec -I../libav-0.8.7/libavutil -#LIBS += ../libav-0.8.7/libavformat/libavformat.a ../libav-0.8.7/libavcodec/libavcodec.a ../libav-0.8.7/libavutil/libavutil.a +DEFINES += _FILE_OFFSET_BITS=64 VERBOSE VERBOSE1 LIBS += -lz #QMAKE_LFLAGS += -static