Even when the OpenCV and ffmpeg have been successfully installed, you still may meet the error of "undefined reference to main" when building the Dense Trajectory code. Since the author didn't provide a solution, I share my workaround here -- just use command g++ directly:

g++ -o DenseTrack -pipe -D __STDC_CONSTANT_MACROS -D STD=std -Wall -I. -I/opt/include -O3 -DNDEBUG -ggdb -L/opt/lib -lopencv_core -lopencv_highgui -lopencv_video -lopencv_imgproc -lavformat -lavdevice -lavutil -lavcodec -lswscale *.h DenseTrack.cpp

The program Video can be built in similar way, just substitute all DenseTrack into Video.