Second Project Post

To Skip to Profiling Section click here

In my previous project post, I talked about the ffmpeg, the test cases I will be using, and the optimization levels. In this post, I will be discussion profiling and how we are going to find out which function has the biggest impact in the amount of resources running. I want to revise my bechmarking, so I will be quickly discussing the changes I made from my previous post.

Picking Software – FFMPEG

When looking for software, it was recommended to pick something that I was interested in. The software I picked had many libraries and frameworks that work with video. On my own free time, I would stream live sessions of game play from games such as League of Legends and Overwatch. When I looked into OBS, the software I used, they had an encoder in their library called x264. x264 is a video encoding technique that is used by mass open software that handle video and audio. OBS was too big of a file, which led me to decide to pick FFMPEG.

Downloading – FFMPEG

The first thing I did after deciding on my software was to download it. There were many different ways to download it, such as using git clone or wget. I decided to use wget. The first download technique is git clone, this allows you to download and have the files ready to build. wget would download the archive file, which you would then have to unzip before building. I decided to use wget, but both methods worked fine for me. Before moving onto the next part, we also need to install dependencies. These files are required in order for the software to work properly. A challenge I faced in this part was knowing the difference between dependencies and enabled features. dependencies are necessary and enabled features are not required. Once I understood this part, the next step became quite simple.

Configure – FFMPEG

Configuring FFMPEG is different then most software. It took me awhile to understand the modifications they had made to their configure script. The configure script checks to see what is needed before the package can be installed. This includes system information, optimizations levels, install path, and features you want to enable. For example,

./configure --prefix="~/FFMPEG-test" CLAGS="-O3"

The script above runs the configurations for FFMPEG with the installation path set to FFMPEG-test directory in my home directory. Most configure sctipts have optimization levels options similar to the above where we would specify CFLAGS and then the optimization level. For FFMPEG, it was a bit different. The developers had provided configure options for CFLAGS. Below is how I ran my configure script using FFMPEG’s Makefile:

./configure --prefix="~/FFMPEG-test" --optflags="O3" --extra-cflags="-g"

After I figured out how to properly set up the configure script to run with the optimization level I wanted, to verify this, I ran:

grep -R "O3"

This displayed to console all matching patterns for “O3” in files of current directory and sub directories.

Building – FFMPEG

Once configuration and verifying is done, I then proceeded to build a working copy of FFMPEG. When we ran our configure script, it had created a Makefile. This file helps connect things such as shared libraries to have the same optimization levels. At first, running make took awhile to build because FFMPEG was a pretty big package. By using make -j16, this helped speed up the building process by utilizing multiple cores that our machine had to offer. This cut down the build time by more then 50%, from 10 minutes to 3 minutes. Once the it was done building, I had to set a path from which the machine would call the executable file. This is needed because ffmpeg is automatically installed on the machine. A simple command:

PATH="~/FFMPEG-test:$PATH"

The path is set to the executable file’s directory, so if the ffmpeg executable file is in your FFMPEG-test directory, then append the remaining path after FFMPEG-test.

Benchmark – FFMPEG

The only changes for benchmark was the encoding part. The new script is below:

for((x=0; x<5; x++)) ; do
    time ~/FFMPEG-test/ffmpeg -i testsrc2.mp4 testsrc$x.avi ; 
done |& tee test.log

This script utilizes the x264, instead of the libx264, which is what I wanted to begin with.

Conclusion

In conclusion in building it in different optimization level would normally increase the file size if we built it with an O3 optimization level. For FFMPEG, it seems that the file size decreased with a higher optimization level. This could be due to many reasons such as removing unused variables. I would like to finish it off with a complete script that starts off with the configuration all the way to creating a benchmark.

cd ~ && \
wget https://launchpad.net/ubuntu/+archive/primary/+sourcefiles/ffmpeg/7:4.1.1-1/ffmpeg_4.1.1.orig.tar.xz && \
mkdir ~/FFMPEG-test && \
cd ~/ffmpeg && \
./configure --optflags="O3" --extracflags="-g" && \
make -j16 && \
ffmpeg -f lavfi -i testsrc=duration=32400:size=qcif:rate=9 ~/FFMPEG-test/testsrc2.mp4 && \
for((x=0; x<5; x++)) ; do echo ============ Run $x; time ffmpeg -i ~/FFMPEG-test/testsrc2.mp4 ~/FFMPEG-test/testsrc$x.avi ; done |& tee ~/FFMPEG-test/test.log && \
egrep user ~/FFMPEG-test/test.log | sed 's\user[[:space:]]*\\' > ~/FFMPEG-test/test.txt

Published by Danny Nguyen

I am a curious person. I find interest in all aspects of software development cycle, software stacks, and how the same software is used in different industries in different ways

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create your website with WordPress.com
Get started
<span>%d</span> bloggers like this: