Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

Commit

Permalink
Add cpp sample deep-player
Browse files Browse the repository at this point in the history
  • Loading branch information
linxie47 committed Jan 6, 2020
1 parent 3c71ad5 commit 1500f09
Show file tree
Hide file tree
Showing 23 changed files with 2,010 additions and 0 deletions.
33 changes: 33 additions & 0 deletions samples/cpp/deep-player/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Prerequisites
*.d
build/*

# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app
48 changes: 48 additions & 0 deletions samples/cpp/deep-player/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#*******************************************************************************
# Copyright (C) 2018-2019 Intel Corporation
#
# SPDX-License-Identifier: MIT
#*******************************************************************************

cmake_minimum_required (VERSION 3.11)

include(GNUInstallDirs)

if(NOT DEFINED PROJECT_NAME)
set(NOT_SUBPROJECT ON)
endif()

project(DeepPlayer LANGUAGES CXX VERSION 0.0.1)

set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})

set(FFMPEG_PKG_CONFIG_SUFFIX "" CACHE STRING "This suffix uses for FFmpeg component names searches by pkg-config")

SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb")

include_directories(.)

####################################
## to use C++11
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED yes)
####################################

# -pthread sets also some useful compile-time flags
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads)

find_package(FFmpeg
COMPONENTS AVCODEC AVFORMAT AVUTIL AVDEVICE AVFILTER SWSCALE SWRESAMPLE REQUIRED)

#NEW include_directories(${FFMPEG_INCLUDE_DIRS})

# OpenCV
find_package(OpenCV)
include_directories(${OpenCV_INCLUDE_DIRS})
if(OpenCV_FOUND)
add_definitions(-DUSE_OPENCV)
endif()

add_subdirectory(src)
add_subdirectory(sample)
56 changes: 56 additions & 0 deletions samples/cpp/deep-player/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# deep-player
* This is a sample to use ffmpeg API based on the libraries with DNN based analytics plugins.
It can support VAAPI based hardware decoder and Software decoder, 3 filter graphs at most.
The analytics metadata can be overlayed on top of the video.

* To try this sample, please install below dependencies:
- install OpenCV and some other dependencies by script `install_dependencies.sh`
- install ffmpeg with video analytics plugin as shared libraries

* After install dependencies, you can build it:
```sh
mkdir -p build && cd build
cmake .. && make -j`nproc`
```

* Here is one example to use the deep_play sample:
```sh

MODEL1="face-detection-adas-0001.xml"
MODEL2="emotions-recognition-retail-0003.xml"
MODEL3="age-gender-recognition-retail-0013.xml"

MODEL1_PROC="face-detection-adas-0001.json"
MODEL2_PROC="emotions-recognition-retail-0003.json"
MODEL3_PROC="age-gender-recognition-retail-0013.json"

./sample/deep_play -input ~/workspace/tests/0.h264 \
-filter0_desc "detect=model=$MODEL1:model_proc=$MODEL1_PROC:device=CPU:nireq=4" \
-filter1_desc "classify=model=$MODEL2:model_proc=$MODEL2_PROC:device=CPU:nireq=2" \
-filter2_desc "classify=model=$MODEL3:model_proc=$MODEL3_PROC:device=CPU:nireq=2" \
-queue_filter=6 -extra_hw_frames=64\
-decode_dev="vaapi" -debug_log=false -no_show=false
```
Press `ESC` to stop the playback.

* Detailed usage:

```sh
./sample/deep_play -h

deep_play [OPTION]
Options:

-h Print a usage message
-input "<path>" Required. Path to a video file
-decode_dev Optional. Hardware device name of video decoder: e.g vaapi
-extra_hw_frames Optional. Allocate more hw frames for the pipeline
-no_show Optional. Do not show processed video.
-filter0_desc Required. First filter description.
-filter1_desc Optional. Appended filters description.
-filter2_desc Optional. Appended filters description.
-fps Optional. Maximum FPS for playing video
-queue_pkt Required. Set output packet queue size of demuxer
-queue_dec Required. Set queue size of decoer output
-queue_filter Required. Set queue size of filter output
```
204 changes: 204 additions & 0 deletions samples/cpp/deep-player/cmake/FindFFmpeg.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
#.rst:
# FindFFmpeg
# ----------
#
# Try to find the required ffmpeg components (default: AVFORMAT, AVUTIL, AVCODEC)
#
# Next variables can be used to hint FFmpeg libs search:
#
# ::
#
# PC_<component>_LIBRARY_DIRS
# PC_FFMPEG_LIBRARY_DIRS
# PC_<component>_INCLUDE_DIRS
# PC_FFMPEG_INCLUDE_DIRS
#
# Once done this will define
#
# ::
#
# FFMPEG_FOUND - System has the all required components.
# FFMPEG_INCLUDE_DIRS - Include directory necessary for using the required components headers.
# FFMPEG_LIBRARIES - Link these to use the required ffmpeg components.
# FFMPEG_DEFINITIONS - Compiler switches required for using the required ffmpeg components.
#
# For each of the components it will additionally set.
#
# ::
#
# AVCODEC
# AVDEVICE
# AVFORMAT
# AVFILTER
# AVUTIL
# POSTPROC
# SWSCALE
#
# the following variables will be defined
#
# ::
#
# <component>_FOUND - System has <component>
# <component>_INCLUDE_DIRS - Include directory necessary for using the <component> headers
# <component>_LIBRARIES - Link these to use <component>
# <component>_DEFINITIONS - Compiler switches required for using <component>
# <component>_VERSION - The components version
#
# the following import targets is created
#
# ::
#
# FFmpeg::FFmpeg - for all components
# FFmpeg::<component> - where <component> in lower case (FFmpeg::avcodec) for each components
#
# Copyright (c) 2006, Matthias Kretz, <[email protected]>
# Copyright (c) 2008, Alexander Neundorf, <[email protected]>
# Copyright (c) 2011, Michael Jansen, <[email protected]>
# Copyright (c) 2017, Alexander Drozdov, <[email protected]>
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.

include(FindPackageHandleStandardArgs)

# The default components were taken from a survey over other FindFFMPEG.cmake files
if (NOT FFmpeg_FIND_COMPONENTS)
set(FFmpeg_FIND_COMPONENTS AVCODEC AVFORMAT AVUTIL)
endif ()

#
### Macro: set_component_found
#
# Marks the given component as found if both *_LIBRARIES AND *_INCLUDE_DIRS is present.
#
macro(set_component_found _component )
if (${_component}_LIBRARIES AND ${_component}_INCLUDE_DIRS)
# message(STATUS " - ${_component} found.")
set(${_component}_FOUND TRUE)
else ()
# message(STATUS " - ${_component} not found.")
endif ()
endmacro()

#
### Macro: find_component
#
# Checks for the given component by invoking pkgconfig and then looking up the libraries and
# include directories.
#
macro(find_component _component _pkgconfig _library _header)

#if (NOT WIN32)
# use pkg-config to get the directories and then use these values
# in the FIND_PATH() and FIND_LIBRARY() calls
find_package(PkgConfig)
if (PKG_CONFIG_FOUND)
pkg_check_modules(PC_${_component} REQUIRED ${_pkgconfig})
endif ()
#endif (NOT WIN32)

find_path(${_component}_INCLUDE_DIRS ${_header}
HINTS
${PC_${_component}_INCLUDEDIR}
${PC_${_component}_INCLUDE_DIRS}
${PC_FFMPEG_INCLUDE_DIRS}
PATH_SUFFIXES
ffmpeg
)

find_library(${_component}_LIBRARIES NAMES ${PC_${_component}_LIBRARIES} ${_library}
HINTS
${PC_${_component}_LIBDIR}
${PC_${_component}_LIBRARY_DIRS}
${PC_FFMPEG_LIBRARY_DIRS}
)

#message(STATUS ${${_component}_LIBRARIES})
#message(STATUS ${PC_${_component}_LIBRARIES})

set(${_component}_DEFINITIONS ${PC_${_component}_CFLAGS_OTHER} CACHE STRING "The ${_component} CFLAGS.")
set(${_component}_VERSION ${PC_${_component}_VERSION} CACHE STRING "The ${_component} version number.")

set_component_found(${_component})

mark_as_advanced(
${_component}_INCLUDE_DIRS
${_component}_LIBRARIES
${_component}_DEFINITIONS
${_component}_VERSION)

endmacro()


# Check for cached results. If there are skip the costly part.
if (NOT FFMPEG_LIBRARIES)

# Check for all possible component.
find_component(AVCODEC libavcodec avcodec libavcodec/avcodec.h)
find_component(AVFORMAT libavformat avformat libavformat/avformat.h)
find_component(AVDEVICE libavdevice avdevice libavdevice/avdevice.h)
find_component(AVUTIL libavutil avutil libavutil/avutil.h)
find_component(AVFILTER libavfilter avfilter libavfilter/avfilter.h)
find_component(SWSCALE libswscale swscale libswscale/swscale.h)
find_component(POSTPROC libpostproc postproc libpostproc/postprocess.h)
find_component(SWRESAMPLE libswresample swresample libswresample/swresample.h)

# Check if the required components were found and add their stuff to the FFMPEG_* vars.
foreach (_component ${FFmpeg_FIND_COMPONENTS})
if (${_component}_FOUND)
# message(STATUS "Required component ${_component} present.")
set(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} ${${_component}_LIBRARIES})
set(FFMPEG_DEFINITIONS ${FFMPEG_DEFINITIONS} ${${_component}_DEFINITIONS})
list(APPEND FFMPEG_INCLUDE_DIRS ${${_component}_INCLUDE_DIRS})

string(TOLOWER ${_component} _lowerComponent)
if (NOT TARGET FFmpeg::${_lowerComponent})
add_library(FFmpeg::${_lowerComponent} INTERFACE IMPORTED)
set_target_properties(FFmpeg::${_lowerComponent} PROPERTIES
INTERFACE_COMPILE_OPTIONS "${${_component}_DEFINITIONS}"
INTERFACE_INCLUDE_DIRECTORIES ${${_component}_INCLUDE_DIRS}
INTERFACE_LINK_LIBRARIES "${${_component}_LIBRARIES}")
endif()

else ()
# message(STATUS "Required component ${_component} missing.")
endif ()
endforeach ()

# Build the include path with duplicates removed.
if (FFMPEG_INCLUDE_DIRS)
list(REMOVE_DUPLICATES FFMPEG_INCLUDE_DIRS)
endif ()

# cache the vars.
set(FFMPEG_INCLUDE_DIRS ${FFMPEG_INCLUDE_DIRS} CACHE STRING "The FFmpeg include directories." FORCE)
set(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} CACHE STRING "The FFmpeg libraries." FORCE)
set(FFMPEG_DEFINITIONS ${FFMPEG_DEFINITIONS} CACHE STRING "The FFmpeg cflags." FORCE)

mark_as_advanced(FFMPEG_INCLUDE_DIRS
FFMPEG_LIBRARIES
FFMPEG_DEFINITIONS)

endif ()

if (NOT TARGET FFmpeg::FFmpeg)
add_library(FFmpeg::FFmpeg INTERFACE IMPORTED)
set_target_properties(FFmpeg::FFmpeg PROPERTIES
INTERFACE_COMPILE_OPTIONS "${FFMPEG_DEFINITIONS}"
INTERFACE_INCLUDE_DIRECTORIES ${FFMPEG_INCLUDE_DIRS}
INTERFACE_LINK_LIBRARIES "${FFMPEG_LIBRARIES}")
endif()

# Now set the noncached _FOUND vars for the components.
foreach (_component AVCODEC AVDEVICE AVFORMAT AVUTIL POSTPROCESS SWSCALE)
set_component_found(${_component})
endforeach ()

# Compile the list of required vars
set(_FFmpeg_REQUIRED_VARS FFMPEG_LIBRARIES FFMPEG_INCLUDE_DIRS)
foreach (_component ${FFmpeg_FIND_COMPONENTS})
list(APPEND _FFmpeg_REQUIRED_VARS ${_component}_LIBRARIES ${_component}_INCLUDE_DIRS)
endforeach ()

# Give a nice error message if some of the required vars are missing.
find_package_handle_standard_args(FFmpeg DEFAULT_MSG ${_FFmpeg_REQUIRED_VARS})
26 changes: 26 additions & 0 deletions samples/cpp/deep-player/install_dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

sudo apt-get install --no-install-recommends libboost-all-dev

CURDIR=$PWD

GLOG_REPO=https://github.com/google/glog.git
GFLAGS_REPO=https://github.com/gflags/gflags.git

git clone $GLOG_REPO third-party/glog
git clone $GFLAGS_REPO third-party/gflags

cd $CURDIR/third-party/glog && git checkout v0.4.0 && git pull origin v0.4.0
mkdir -p build && cd build
cmake -DBUILD_SHARED_LIBS=ON ..
make -j`nproc`
sudo make install


cd $CURDIR/third-party/gflags && git checkout v2.2.2 && git pull origin v2.2.2
mkdir -p build && cd build
cmake -DBUILD_SHARED_LIBS=ON ..
make -j`nproc`
sudo make install

cd $CURDIR
Loading

0 comments on commit 1500f09

Please sign in to comment.