diff --git a/.travis.yml b/.travis.yml index e459e6f3..8171f822 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,15 +25,12 @@ 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: @@ -41,18 +38,18 @@ before_script: - 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 diff --git a/BUILD.md b/BUILD.md index 6bb224fe..ee9d8f7c 100644 --- a/BUILD.md +++ b/BUILD.md @@ -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 ~~~~ @@ -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 --------------- diff --git a/Examples/VideoStreaming/Evaluation/UltrasonixEval.cxx b/Examples/VideoStreaming/Evaluation/UltrasonixEval.cxx index 6bdf38b1..e0cf0897 100644 --- a/Examples/VideoStreaming/Evaluation/UltrasonixEval.cxx +++ b/Examples/VideoStreaming/Evaluation/UltrasonixEval.cxx @@ -43,14 +43,14 @@ #include #include -#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" @@ -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 = 2343 && i<=2350) - { - continue; - } std::string stringTemp = testFileDir; std::string testIndexedFileName = stringTemp.append(sep).append(std::to_string(i)).append(".yuv"); FILE* pFileYUV = NULL; @@ -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; @@ -277,7 +276,7 @@ void TestWithVersion(int version, GenericEncoder* videoStreamEncoder, GenericDec float framePerSecondDecode = 1e6/((float)totalDecodeTime)*totolFrameNumber; ssim/=static_cast(totolFrameNumber); std::cerr<<"SSIM Value: "<SetPicWidthAndHeight(Width, Height); videoStreamEncoder->SetLosslessLink(true); videoStreamEncoder->SetRCMode(1); // 1 is VPX_CBR @@ -425,8 +424,8 @@ void VP9CodecSpeedAndRateEval() { std::cerr<first<<" "<second<<" "<first<<" "<second<~VPXDecoder(); - videoStreamEncoder->~VPXEncoder(); + videoStreamDecoder->~VP9Decoder(); + videoStreamEncoder->~VP9Encoder(); #endif } @@ -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 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="<(ToString(ssim), ToString(compressionRate))); - times.insert(std::pair(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="<(ToString(ssim), ToString(compressionRate))); + times.insert(std::pair(ToString(framePerSecondEncode), ToString(framePerSecondDecode))); + } } std::map::const_iterator it2 = times.begin(); for( std::map::const_iterator it = values.begin(); it != values.end(); ++it, ++it2) { std::cerr<first<<" "<second<<" "<first<<" "<second<~VPXDecoder(); - videoStreamEncoder->~VPXEncoder(); + videoStreamDecoder->~VP9Decoder(); + videoStreamEncoder->~VP9Encoder(); #endif } } @@ -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 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); @@ -527,6 +534,7 @@ void H265SpeedEvaluation() times.insert(std::pair(ToString(framePerSecondEncode), ToString(framePerSecondDecode))); videoStreamDecoder->~H265Decoder(); videoStreamEncoder->~H265Encoder(); + } } std::map::const_iterator it2 = times.begin(); for( std::map::const_iterator it = values.begin(); it != values.end(); ++it, ++it2) @@ -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-";