Skip to content

Commit

Permalink
EHN: build instruction for video streaming improved, travis build for…
Browse files Browse the repository at this point in the history
… Video streaming added
  • Loading branch information
leochan2009 committed Jul 19, 2017
1 parent c9947b3 commit 3ec54f7
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 61 deletions.
19 changes: 8 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,31 @@ install:
if ! brew ls --version cmake &>/dev/null; then brew install cmake; fi
fi
- |
if [ "${TRAVIS_OS_NAME}" == "linux" ] || [ "${TRAVIS_OS_NAME}" == "osx" ]; then
if [ "${TRAVIS_OS_NAME}" == "linux" ] ; then
sudo apt-get -y install yasm;
wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz;
tar xzf yasm-1.3.0.tar.gz;
cd yasm-1.3.0;
./configure;
sudo make;
sudo make install;
cd ..
fi
if [ "${TRAVIS_OS_NAME}" == "osx" ]; then
brew update;
brew install yasm;
fi
before_script:
- mkdir build
- cd build

script:
- cmake -DOpenIGTLink_PROTOCOL_VERSION_3=ON -DLINK_VP9=ON ..
- cmake -DOpenIGTLink_PROTOCOL_VERSION_3=ON -DBUILD_VIDEOSTREAM=ON -DLINK_VP9=ON ..
- make
- cd ..
- mkdir TestBuild
- cd TestBuild
- cmake -DCMAKE_PREFIX_PATH:PATH=../build ../Testing
- cmake -DCMAKE_PREFIX_PATH:PATH=../build -DBUILD_VIDEOSTREAM=ON -DLINK_VP9=ON ../Testing
- make
- make test
#########################
# Test for version2 build
- cd ../build
- cmake -DOpenIGTLink_PROTOCOL_VERSION_3=OFF ..
- cmake -DOpenIGTLink_PROTOCOL_VERSION_3=OFF -DBUILD_VIDEOSTREAM=OFF ..
- make
- cd ../TestBuild
- cmake -DCMAKE_PREFIX_PATH:PATH=../build ../Testing
Expand Down
18 changes: 13 additions & 5 deletions BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,32 +48,36 @@ If all went OK you will have the executable and the library:

VideoStreaming
---------------
You might want to use OpenIGTLink library to perform video streaming. Currently H264 and VP9 are supported in the OpenIGTLink
You might want to use OpenIGTLink library to perform video streaming. Currently OpenH264, H265 and VP9 are supported in the OpenIGTLink.

* Prerequisites

In the case of H264 build, NASM is needed for assembly code: workable version 2.10.06 or above for 32 bit, nasm can downloaded from http://www.nasm.us/

For Mac OSX 64-bit NASM needed to be below version 2.11.08 as nasm 2.11.08
will introduce error when using RIP-relative addresses in Mac OSX 64-bit. If you have another NASM version installed, try to unlink the wrong version of NASM,
and link to the version to below 2.11.08. Afterwards, check the nasm version with comman "which nasm" and "nasm -v".
In the case of VPX build, The Yasm assembler is required to build optimized libraries for x86 platforms.

In the case of VP9 build, The Yasm assembler is required to build optimized libraries for x86 platforms.
Version 0.8.0 or newer is required, except Version 1.0.0.

In the case of H265 build, H265 have many implementations, the encoder used in library is x265 and the decoder is OpenHEVC.
OpenIGTLink library doesn't build H265 libraries, so the users need to download and compile the libraries by themselves.
Afterwards, set the variables-"X265_SOURCE_DIR, X265_LIBRARY_DIR, OPENHEVC_SOURCE_DIR, OPENHEVC_LIBRARY_DIR"-correctly in cmake configuration.

* Linux / Mac OS X

In the case of Linux and Mac, after installing the required program in the Prerequisites section,
the build of openigtlink with codec is very straightforward:

~~~~
$ cmake -DBUILD_H264:BOOL=ON -DOpenIGTLink_PROTOCOL_VERSION_3:BOOL=ON ../OpenIGTLink
$ cmake -DBUILD_VIDEOSTREAM:BOOL=ON -DLINK_H264:BOOL=ON -DOpenIGTLink_PROTOCOL_VERSION_3:BOOL=ON ../OpenIGTLink
$ make
~~~~

or for VP9 configuration:

~~~~
$ cmake -DBUILD_VPX:BOOL=ON -DOpenIGTLink_PROTOCOL_VERSION_3:BOOL=ON ../OpenIGTLink
$ cmake -DBUILD_VIDEOSTREAM:BOOL=ON -DLINK_VP9:BOOL=ON -DOpenIGTLink_PROTOCOL_VERSION_3:BOOL=ON ../OpenIGTLink
$ make
~~~~

Expand All @@ -94,6 +98,10 @@ Useful X265 build intructions:

https://bitbucket.org/multicoreware/x265/wiki/CrossCompile

Useful OpenHEVC build intructions:

http://openhevc.github.io/openHEVC/

Other Platforms
---------------

Expand Down
98 changes: 53 additions & 45 deletions Examples/VideoStreaming/Evaluation/UltrasonixEval.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@
#include <cstring>
#include <string>

#if OpenIGTLink_BUILD_H264
#if OpenIGTLink_LINK_H264
#include "H264Encoder.h"
#include "H264Decoder.h"
#endif

#if OpenIGTLink_BUILD_VPX
#include "VPXEncoder.h"
#include "VPXDecoder.h"
#if OpenIGTLink_LINK_VP9
#include "VP9Encoder.h"
#include "VP9Decoder.h"
#include "../video_reader.h"
#include "./vpx_config.h"
#include "vpx_dsp_rtcd.h"
Expand Down Expand Up @@ -193,16 +193,11 @@ void TestWithVersion(int version, GenericEncoder* videoStreamEncoder, GenericDec
totalDecodeTime = 0;
pEval = fopen (evalFileName.c_str(), "a");
totolFrameNumber=0;
for(int i = 2341; i <inputFrameNum; i++)
for(int i = startIndex; i <inputFrameNum; i++)
{ std::string sep = "/";
#if defined(_WIN32) || defined(_WIN64)
sep = "\\";
#endif
//std::cerr<<i<<std::endl;
if (i >= 2343 && i<=2350)
{
continue;
}
std::string stringTemp = testFileDir;
std::string testIndexedFileName = stringTemp.append(sep).append(std::to_string(i)).append(".yuv");
FILE* pFileYUV = NULL;
Expand Down Expand Up @@ -268,6 +263,10 @@ void TestWithVersion(int version, GenericEncoder* videoStreamEncoder, GenericDec
} else {
fprintf (stderr, "Unable to open image file, check corresponding path!\n");
}
if(totolFrameNumber>=100)
{
break;
}
}
delete pDecodedPic;
delete pSrcPic;
Expand All @@ -277,7 +276,7 @@ void TestWithVersion(int version, GenericEncoder* videoStreamEncoder, GenericDec
float framePerSecondDecode = 1e6/((float)totalDecodeTime)*totolFrameNumber;
ssim/=static_cast<float>(totolFrameNumber);
std::cerr<<"SSIM Value: "<<ssim<<" Total Encoding Time: "<<totalEncodeTime/1e6<<std::endl;
compressionRate = (float)(Width*Height*1951*3/2)/bitstreamTotalLength;
compressionRate = (float)(Width*Height*totolFrameNumber*3/2)/bitstreamTotalLength;
std::cerr<<"Compression Ratio: "<<compressionRate<< std::endl;
std::string localline = std::string("");
localline.append(ToString(ssim));
Expand Down Expand Up @@ -391,9 +390,9 @@ void H264CodecSpeedAndRateEval()

void VP9CodecSpeedAndRateEval()
{
#if OpenIGTLink_BUILD_VPX
VPXEncoder* videoStreamEncoder = new VPXEncoder();
VPXDecoder* videoStreamDecoder = new VPXDecoder();
#if OpenIGTLink_LINK_VP9
VP9Encoder* videoStreamEncoder = new VP9Encoder();
VP9Decoder* videoStreamDecoder = new VP9Decoder();
videoStreamEncoder->SetPicWidthAndHeight(Width, Height);
videoStreamEncoder->SetLosslessLink(true);
videoStreamEncoder->SetRCMode(1); // 1 is VPX_CBR
Expand Down Expand Up @@ -425,8 +424,8 @@ void VP9CodecSpeedAndRateEval()
{
std::cerr<<it->first<<" "<<it->second<<" "<<it2->first<<" "<<it2->second<<std::endl;
}
videoStreamDecoder->~VPXDecoder();
videoStreamEncoder->~VPXEncoder();
videoStreamDecoder->~VP9Decoder();
videoStreamEncoder->~VP9Encoder();
#endif
}

Expand Down Expand Up @@ -459,38 +458,43 @@ void VP9SpeedEvaluation()
{
for (int speed = 0; speed<=8;speed=speed+2)
{
#if OpenIGTLink_BUILD_VPX
pEval = fopen (evalFileName.c_str(), "a");
std::string title = "VP9CodecSpeedAndRateEvalWithSpeed-";
title.append(ToString(speed)).append("\r\n");
fwrite(title.c_str(),1, title.size(),pEval);
fclose(pEval);
#if OpenIGTLink_LINK_VP9
std::map<std::string, std::string> values, times;
VPXEncoder* videoStreamEncoder = new VPXEncoder();
VPXDecoder* videoStreamDecoder = new VPXDecoder();
VP9Encoder* videoStreamEncoder = new VP9Encoder();
VP9Decoder* videoStreamDecoder = new VP9Decoder();
videoStreamEncoder->SetPicWidthAndHeight(Width, Height);
videoStreamEncoder->SetLosslessLink(false);
videoStreamEncoder->SetRCMode(1); // 1 is VPX_CBR
float percents[5] ={0.01, 0.02, 0.04, 0.06, 0.09};;
for (int j = 0; j<5; j=j+1) // The original frame bits per second is 256*256*20*8, the compression ratio is set from 0.5% to 8%
float percents[5] ={0.01, 0.02, 0.04, 0.06, 0.09};
for(int k = 0; k<19; k++)
{
videoStreamEncoder->SetRCTaregetBitRate((int)(Width*Height*8*20*percents[j]));
videoStreamEncoder->InitializeEncoder();
videoStreamEncoder->SetSpeed(speed);
TestWithVersion(IGTL_HEADER_VERSION_1, videoStreamEncoder, videoStreamDecoder, false);
float framePerSecondEncode = 1e6/((float)totalEncodeTime)*totolFrameNumber;
float framePerSecondDecode = 1e6/((float)totalDecodeTime)*totolFrameNumber;
std::cerr<<"Total encode and decode frequency for target bitrate="<<j<<": "<<framePerSecondEncode<<", "<<framePerSecondDecode<<std::endl;
values.insert(std::pair<std::string, std::string>(ToString(ssim), ToString(compressionRate)));
times.insert(std::pair<std::string, std::string>(ToString(framePerSecondEncode), ToString(framePerSecondDecode)));
startIndex = 2351 + k*100;
pEval = fopen (evalFileName.c_str(), "a");
std::string title = "VP9CodecSpeedAndRateEvalWithSpeed-";
title.append(ToString(speed)).append("\r\n");
fwrite(title.c_str(),1, title.size(),pEval);
fclose(pEval);
for (int j = 0; j<5; j=j+1) // The original frame bits per second is 256*256*20*8, the compression ratio is set from 0.5% to 8%
{
videoStreamEncoder->SetRCTaregetBitRate((int)(Width*Height*8*20*percents[j]));
videoStreamEncoder->InitializeEncoder();
videoStreamEncoder->SetSpeed(speed);

TestWithVersion(IGTL_HEADER_VERSION_1, videoStreamEncoder, videoStreamDecoder, false);
float framePerSecondEncode = 1e6/((float)totalEncodeTime)*totolFrameNumber;
float framePerSecondDecode = 1e6/((float)totalDecodeTime)*totolFrameNumber;
std::cerr<<"Total encode and decode frequency for target bitrate="<<j<<": "<<framePerSecondEncode<<", "<<framePerSecondDecode<<std::endl;
values.insert(std::pair<std::string, std::string>(ToString(ssim), ToString(compressionRate)));
times.insert(std::pair<std::string, std::string>(ToString(framePerSecondEncode), ToString(framePerSecondDecode)));
}
}
std::map<std::string, std::string>::const_iterator it2 = times.begin();
for( std::map<std::string, std::string>::const_iterator it = values.begin(); it != values.end(); ++it, ++it2)
{
std::cerr<<it->first<<" "<<it->second<<" "<<it2->first<<" "<<it2->second<<std::endl;
}
videoStreamDecoder->~VPXDecoder();
videoStreamEncoder->~VPXEncoder();
videoStreamDecoder->~VP9Decoder();
videoStreamEncoder->~VP9Encoder();
#endif
}
}
Expand All @@ -500,17 +504,20 @@ void H265SpeedEvaluation()
{
for (int speed = 1; speed<=9;speed=speed+2)
{
#if OpenIGTLink_BUILD_VPX
pEval = fopen (evalFileName.c_str(), "a");
std::string title = "H265CodecSpeedAndRateEvalWithSpeed-";
title.append(ToString(speed)).append("\r\n");
fwrite(title.c_str(),1, title.size(),pEval);
fclose(pEval);
#if OpenIGTLink_LINK_X265
float percents[5] ={0.01, 0.02, 0.04, 0.06, 0.09};
std::map<std::string, std::string> values, times;
int BitRateFactor = 7;
for (int j = 0; j<5; j=j+1) // The original frame bits per second is 256*256*20*8, the compression ratio is set from 0.5% to 8%
for(int k = 0; k<19; k++)
{
startIndex = 2351 + k*100;
pEval = fopen (evalFileName.c_str(), "a");
std::string title = "H265CodecSpeedAndRateEvalWithSpeed-";
title.append(ToString(speed)).append("\r\n");
fwrite(title.c_str(),1, title.size(),pEval);
fclose(pEval);
for (int j = 0; j<5; j=j+1) // The original frame bits per second is 256*256*20*8, the compression ratio is set from 0.5% to 8%
{
H265Encoder* videoStreamEncoder = new H265Encoder();
H265Decoder* videoStreamDecoder = new H265Decoder();
videoStreamEncoder->SetPicWidthAndHeight(Width, Height);
Expand All @@ -527,6 +534,7 @@ void H265SpeedEvaluation()
times.insert(std::pair<std::string, std::string>(ToString(framePerSecondEncode), ToString(framePerSecondDecode)));
videoStreamDecoder->~H265Decoder();
videoStreamEncoder->~H265Encoder();
}
}
std::map<std::string, std::string>::const_iterator it2 = times.begin();
for( std::map<std::string, std::string>::const_iterator it = values.begin(); it != values.end(); ++it, ++it2)
Expand All @@ -545,7 +553,7 @@ void H264SpeedEvaluation()
{
for (int i = 0; i<22; i=i+2)
{
#if OpenIGTLink_BUILD_H264
#if OpenIGTLink_LINK_H264
startIndex = i*100;
pEval = fopen (evalFileName.c_str(), "a");
std::string title = "H264CodecSpeedAndRateEvalWithSpeed-";
Expand Down

0 comments on commit 3ec54f7

Please sign in to comment.