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

Commit 1500f09

Browse files
committed
Add cpp sample deep-player
1 parent 3c71ad5 commit 1500f09

23 files changed

+2010
-0
lines changed

samples/cpp/deep-player/.gitignore

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Prerequisites
2+
*.d
3+
build/*
4+
5+
# Compiled Object files
6+
*.slo
7+
*.lo
8+
*.o
9+
*.obj
10+
11+
# Precompiled Headers
12+
*.gch
13+
*.pch
14+
15+
# Compiled Dynamic libraries
16+
*.so
17+
*.dylib
18+
*.dll
19+
20+
# Fortran module files
21+
*.mod
22+
*.smod
23+
24+
# Compiled Static libraries
25+
*.lai
26+
*.la
27+
*.a
28+
*.lib
29+
30+
# Executables
31+
*.exe
32+
*.out
33+
*.app
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#*******************************************************************************
2+
# Copyright (C) 2018-2019 Intel Corporation
3+
#
4+
# SPDX-License-Identifier: MIT
5+
#*******************************************************************************
6+
7+
cmake_minimum_required (VERSION 3.11)
8+
9+
include(GNUInstallDirs)
10+
11+
if(NOT DEFINED PROJECT_NAME)
12+
set(NOT_SUBPROJECT ON)
13+
endif()
14+
15+
project(DeepPlayer LANGUAGES CXX VERSION 0.0.1)
16+
17+
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
18+
19+
set(FFMPEG_PKG_CONFIG_SUFFIX "" CACHE STRING "This suffix uses for FFmpeg component names searches by pkg-config")
20+
21+
SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb")
22+
23+
include_directories(.)
24+
25+
####################################
26+
## to use C++11
27+
set(CMAKE_CXX_STANDARD 11)
28+
set(CMAKE_CXX_STANDARD_REQUIRED yes)
29+
####################################
30+
31+
# -pthread sets also some useful compile-time flags
32+
set(THREADS_PREFER_PTHREAD_FLAG ON)
33+
find_package(Threads)
34+
35+
find_package(FFmpeg
36+
COMPONENTS AVCODEC AVFORMAT AVUTIL AVDEVICE AVFILTER SWSCALE SWRESAMPLE REQUIRED)
37+
38+
#NEW include_directories(${FFMPEG_INCLUDE_DIRS})
39+
40+
# OpenCV
41+
find_package(OpenCV)
42+
include_directories(${OpenCV_INCLUDE_DIRS})
43+
if(OpenCV_FOUND)
44+
add_definitions(-DUSE_OPENCV)
45+
endif()
46+
47+
add_subdirectory(src)
48+
add_subdirectory(sample)

samples/cpp/deep-player/README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# deep-player
2+
* This is a sample to use ffmpeg API based on the libraries with DNN based analytics plugins.
3+
It can support VAAPI based hardware decoder and Software decoder, 3 filter graphs at most.
4+
The analytics metadata can be overlayed on top of the video.
5+
6+
* To try this sample, please install below dependencies:
7+
- install OpenCV and some other dependencies by script `install_dependencies.sh`
8+
- install ffmpeg with video analytics plugin as shared libraries
9+
10+
* After install dependencies, you can build it:
11+
```sh
12+
mkdir -p build && cd build
13+
cmake .. && make -j`nproc`
14+
```
15+
16+
* Here is one example to use the deep_play sample:
17+
```sh
18+
19+
MODEL1="face-detection-adas-0001.xml"
20+
MODEL2="emotions-recognition-retail-0003.xml"
21+
MODEL3="age-gender-recognition-retail-0013.xml"
22+
23+
MODEL1_PROC="face-detection-adas-0001.json"
24+
MODEL2_PROC="emotions-recognition-retail-0003.json"
25+
MODEL3_PROC="age-gender-recognition-retail-0013.json"
26+
27+
./sample/deep_play -input ~/workspace/tests/0.h264 \
28+
-filter0_desc "detect=model=$MODEL1:model_proc=$MODEL1_PROC:device=CPU:nireq=4" \
29+
-filter1_desc "classify=model=$MODEL2:model_proc=$MODEL2_PROC:device=CPU:nireq=2" \
30+
-filter2_desc "classify=model=$MODEL3:model_proc=$MODEL3_PROC:device=CPU:nireq=2" \
31+
-queue_filter=6 -extra_hw_frames=64\
32+
-decode_dev="vaapi" -debug_log=false -no_show=false
33+
```
34+
Press `ESC` to stop the playback.
35+
36+
* Detailed usage:
37+
38+
```sh
39+
./sample/deep_play -h
40+
41+
deep_play [OPTION]
42+
Options:
43+
44+
-h Print a usage message
45+
-input "<path>" Required. Path to a video file
46+
-decode_dev Optional. Hardware device name of video decoder: e.g vaapi
47+
-extra_hw_frames Optional. Allocate more hw frames for the pipeline
48+
-no_show Optional. Do not show processed video.
49+
-filter0_desc Required. First filter description.
50+
-filter1_desc Optional. Appended filters description.
51+
-filter2_desc Optional. Appended filters description.
52+
-fps Optional. Maximum FPS for playing video
53+
-queue_pkt Required. Set output packet queue size of demuxer
54+
-queue_dec Required. Set queue size of decoer output
55+
-queue_filter Required. Set queue size of filter output
56+
```
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
#.rst:
2+
# FindFFmpeg
3+
# ----------
4+
#
5+
# Try to find the required ffmpeg components (default: AVFORMAT, AVUTIL, AVCODEC)
6+
#
7+
# Next variables can be used to hint FFmpeg libs search:
8+
#
9+
# ::
10+
#
11+
# PC_<component>_LIBRARY_DIRS
12+
# PC_FFMPEG_LIBRARY_DIRS
13+
# PC_<component>_INCLUDE_DIRS
14+
# PC_FFMPEG_INCLUDE_DIRS
15+
#
16+
# Once done this will define
17+
#
18+
# ::
19+
#
20+
# FFMPEG_FOUND - System has the all required components.
21+
# FFMPEG_INCLUDE_DIRS - Include directory necessary for using the required components headers.
22+
# FFMPEG_LIBRARIES - Link these to use the required ffmpeg components.
23+
# FFMPEG_DEFINITIONS - Compiler switches required for using the required ffmpeg components.
24+
#
25+
# For each of the components it will additionally set.
26+
#
27+
# ::
28+
#
29+
# AVCODEC
30+
# AVDEVICE
31+
# AVFORMAT
32+
# AVFILTER
33+
# AVUTIL
34+
# POSTPROC
35+
# SWSCALE
36+
#
37+
# the following variables will be defined
38+
#
39+
# ::
40+
#
41+
# <component>_FOUND - System has <component>
42+
# <component>_INCLUDE_DIRS - Include directory necessary for using the <component> headers
43+
# <component>_LIBRARIES - Link these to use <component>
44+
# <component>_DEFINITIONS - Compiler switches required for using <component>
45+
# <component>_VERSION - The components version
46+
#
47+
# the following import targets is created
48+
#
49+
# ::
50+
#
51+
# FFmpeg::FFmpeg - for all components
52+
# FFmpeg::<component> - where <component> in lower case (FFmpeg::avcodec) for each components
53+
#
54+
# Copyright (c) 2006, Matthias Kretz, <[email protected]>
55+
# Copyright (c) 2008, Alexander Neundorf, <[email protected]>
56+
# Copyright (c) 2011, Michael Jansen, <[email protected]>
57+
# Copyright (c) 2017, Alexander Drozdov, <[email protected]>
58+
#
59+
# Redistribution and use is allowed according to the terms of the BSD license.
60+
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
61+
62+
include(FindPackageHandleStandardArgs)
63+
64+
# The default components were taken from a survey over other FindFFMPEG.cmake files
65+
if (NOT FFmpeg_FIND_COMPONENTS)
66+
set(FFmpeg_FIND_COMPONENTS AVCODEC AVFORMAT AVUTIL)
67+
endif ()
68+
69+
#
70+
### Macro: set_component_found
71+
#
72+
# Marks the given component as found if both *_LIBRARIES AND *_INCLUDE_DIRS is present.
73+
#
74+
macro(set_component_found _component )
75+
if (${_component}_LIBRARIES AND ${_component}_INCLUDE_DIRS)
76+
# message(STATUS " - ${_component} found.")
77+
set(${_component}_FOUND TRUE)
78+
else ()
79+
# message(STATUS " - ${_component} not found.")
80+
endif ()
81+
endmacro()
82+
83+
#
84+
### Macro: find_component
85+
#
86+
# Checks for the given component by invoking pkgconfig and then looking up the libraries and
87+
# include directories.
88+
#
89+
macro(find_component _component _pkgconfig _library _header)
90+
91+
#if (NOT WIN32)
92+
# use pkg-config to get the directories and then use these values
93+
# in the FIND_PATH() and FIND_LIBRARY() calls
94+
find_package(PkgConfig)
95+
if (PKG_CONFIG_FOUND)
96+
pkg_check_modules(PC_${_component} REQUIRED ${_pkgconfig})
97+
endif ()
98+
#endif (NOT WIN32)
99+
100+
find_path(${_component}_INCLUDE_DIRS ${_header}
101+
HINTS
102+
${PC_${_component}_INCLUDEDIR}
103+
${PC_${_component}_INCLUDE_DIRS}
104+
${PC_FFMPEG_INCLUDE_DIRS}
105+
PATH_SUFFIXES
106+
ffmpeg
107+
)
108+
109+
find_library(${_component}_LIBRARIES NAMES ${PC_${_component}_LIBRARIES} ${_library}
110+
HINTS
111+
${PC_${_component}_LIBDIR}
112+
${PC_${_component}_LIBRARY_DIRS}
113+
${PC_FFMPEG_LIBRARY_DIRS}
114+
)
115+
116+
#message(STATUS ${${_component}_LIBRARIES})
117+
#message(STATUS ${PC_${_component}_LIBRARIES})
118+
119+
set(${_component}_DEFINITIONS ${PC_${_component}_CFLAGS_OTHER} CACHE STRING "The ${_component} CFLAGS.")
120+
set(${_component}_VERSION ${PC_${_component}_VERSION} CACHE STRING "The ${_component} version number.")
121+
122+
set_component_found(${_component})
123+
124+
mark_as_advanced(
125+
${_component}_INCLUDE_DIRS
126+
${_component}_LIBRARIES
127+
${_component}_DEFINITIONS
128+
${_component}_VERSION)
129+
130+
endmacro()
131+
132+
133+
# Check for cached results. If there are skip the costly part.
134+
if (NOT FFMPEG_LIBRARIES)
135+
136+
# Check for all possible component.
137+
find_component(AVCODEC libavcodec avcodec libavcodec/avcodec.h)
138+
find_component(AVFORMAT libavformat avformat libavformat/avformat.h)
139+
find_component(AVDEVICE libavdevice avdevice libavdevice/avdevice.h)
140+
find_component(AVUTIL libavutil avutil libavutil/avutil.h)
141+
find_component(AVFILTER libavfilter avfilter libavfilter/avfilter.h)
142+
find_component(SWSCALE libswscale swscale libswscale/swscale.h)
143+
find_component(POSTPROC libpostproc postproc libpostproc/postprocess.h)
144+
find_component(SWRESAMPLE libswresample swresample libswresample/swresample.h)
145+
146+
# Check if the required components were found and add their stuff to the FFMPEG_* vars.
147+
foreach (_component ${FFmpeg_FIND_COMPONENTS})
148+
if (${_component}_FOUND)
149+
# message(STATUS "Required component ${_component} present.")
150+
set(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} ${${_component}_LIBRARIES})
151+
set(FFMPEG_DEFINITIONS ${FFMPEG_DEFINITIONS} ${${_component}_DEFINITIONS})
152+
list(APPEND FFMPEG_INCLUDE_DIRS ${${_component}_INCLUDE_DIRS})
153+
154+
string(TOLOWER ${_component} _lowerComponent)
155+
if (NOT TARGET FFmpeg::${_lowerComponent})
156+
add_library(FFmpeg::${_lowerComponent} INTERFACE IMPORTED)
157+
set_target_properties(FFmpeg::${_lowerComponent} PROPERTIES
158+
INTERFACE_COMPILE_OPTIONS "${${_component}_DEFINITIONS}"
159+
INTERFACE_INCLUDE_DIRECTORIES ${${_component}_INCLUDE_DIRS}
160+
INTERFACE_LINK_LIBRARIES "${${_component}_LIBRARIES}")
161+
endif()
162+
163+
else ()
164+
# message(STATUS "Required component ${_component} missing.")
165+
endif ()
166+
endforeach ()
167+
168+
# Build the include path with duplicates removed.
169+
if (FFMPEG_INCLUDE_DIRS)
170+
list(REMOVE_DUPLICATES FFMPEG_INCLUDE_DIRS)
171+
endif ()
172+
173+
# cache the vars.
174+
set(FFMPEG_INCLUDE_DIRS ${FFMPEG_INCLUDE_DIRS} CACHE STRING "The FFmpeg include directories." FORCE)
175+
set(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} CACHE STRING "The FFmpeg libraries." FORCE)
176+
set(FFMPEG_DEFINITIONS ${FFMPEG_DEFINITIONS} CACHE STRING "The FFmpeg cflags." FORCE)
177+
178+
mark_as_advanced(FFMPEG_INCLUDE_DIRS
179+
FFMPEG_LIBRARIES
180+
FFMPEG_DEFINITIONS)
181+
182+
endif ()
183+
184+
if (NOT TARGET FFmpeg::FFmpeg)
185+
add_library(FFmpeg::FFmpeg INTERFACE IMPORTED)
186+
set_target_properties(FFmpeg::FFmpeg PROPERTIES
187+
INTERFACE_COMPILE_OPTIONS "${FFMPEG_DEFINITIONS}"
188+
INTERFACE_INCLUDE_DIRECTORIES ${FFMPEG_INCLUDE_DIRS}
189+
INTERFACE_LINK_LIBRARIES "${FFMPEG_LIBRARIES}")
190+
endif()
191+
192+
# Now set the noncached _FOUND vars for the components.
193+
foreach (_component AVCODEC AVDEVICE AVFORMAT AVUTIL POSTPROCESS SWSCALE)
194+
set_component_found(${_component})
195+
endforeach ()
196+
197+
# Compile the list of required vars
198+
set(_FFmpeg_REQUIRED_VARS FFMPEG_LIBRARIES FFMPEG_INCLUDE_DIRS)
199+
foreach (_component ${FFmpeg_FIND_COMPONENTS})
200+
list(APPEND _FFmpeg_REQUIRED_VARS ${_component}_LIBRARIES ${_component}_INCLUDE_DIRS)
201+
endforeach ()
202+
203+
# Give a nice error message if some of the required vars are missing.
204+
find_package_handle_standard_args(FFmpeg DEFAULT_MSG ${_FFmpeg_REQUIRED_VARS})
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
3+
sudo apt-get install --no-install-recommends libboost-all-dev
4+
5+
CURDIR=$PWD
6+
7+
GLOG_REPO=https://github.com/google/glog.git
8+
GFLAGS_REPO=https://github.com/gflags/gflags.git
9+
10+
git clone $GLOG_REPO third-party/glog
11+
git clone $GFLAGS_REPO third-party/gflags
12+
13+
cd $CURDIR/third-party/glog && git checkout v0.4.0 && git pull origin v0.4.0
14+
mkdir -p build && cd build
15+
cmake -DBUILD_SHARED_LIBS=ON ..
16+
make -j`nproc`
17+
sudo make install
18+
19+
20+
cd $CURDIR/third-party/gflags && git checkout v2.2.2 && git pull origin v2.2.2
21+
mkdir -p build && cd build
22+
cmake -DBUILD_SHARED_LIBS=ON ..
23+
make -j`nproc`
24+
sudo make install
25+
26+
cd $CURDIR

0 commit comments

Comments
 (0)