Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Master nexus 5 #53

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
170 changes: 59 additions & 111 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 =
Expand Down Expand Up @@ -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
Expand All @@ -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 \
Expand All @@ -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
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions atom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ 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);
if(content.size())
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);
}

Expand Down
27 changes: 21 additions & 6 deletions mp4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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++)
Expand All @@ -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);
}

Expand Down Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions mp4.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading