forked from Apra-Labs/ApraPipes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from SatwikSShanbhag/ss/sample_example
sample example for valve module as well as seek and flush queue features
- Loading branch information
Showing
13 changed files
with
506 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
cmake_minimum_required(VERSION 3.22) | ||
set(TARGET generateThumbnailFromMp4Video) | ||
SET(SAMPLE_FILES | ||
GenerateThumbnailsPipeline.cpp | ||
pipelineMain.cpp | ||
) | ||
SET(SAMPLE_FILES_H | ||
GenerateThumbnailsPipeline.h | ||
) | ||
SET(SOURCE | ||
${SAMPLE_FILES} | ||
${SAMPLE_FILES_H} | ||
) | ||
add_executable(${TARGET} ${SOURCE}) | ||
target_include_directories ( ${TARGET} PRIVATE | ||
${JETSON_MULTIMEDIA_LIB_INCLUDE} | ||
${OpenCV_INCLUDE_DIRS} | ||
${Boost_INCLUDE_DIRS} | ||
${LIBMP4_INC_DIR} | ||
${NVCODEC_INCLUDE_DIR} | ||
) | ||
target_link_libraries( | ||
${TARGET} | ||
aprapipes | ||
${JPEG_LIBRARIES} | ||
${LIBMP4_LIB} | ||
${OPENH264_LIB} | ||
${Boost_LIBRARIES} | ||
${FFMPEG_LIBRARIES} | ||
${OpenCV_LIBRARIES} | ||
${NVCUDAToolkit_LIBS} | ||
${NVCODEC_LIB} | ||
${NVJPEGLIB_L4T} | ||
) |
89 changes: 89 additions & 0 deletions
89
samples/create_thumbnail_from_mp4_video/GenerateThumbnailsPipeline.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
|
||
#include "GenerateThumbnailsPipeline.h" | ||
#include "CudaMemCopy.h" | ||
#include "ExternalSinkModule.h" | ||
#include "FileReaderModule.h" | ||
#include "FileWriterModule.h" | ||
#include "FrameMetadata.h" | ||
#include "H264Decoder.h" | ||
#include "H264Metadata.h" | ||
#include "JPEGEncoderNVJPEG.h" | ||
#include "Logger.h" | ||
#include "Mp4ReaderSource.h" | ||
#include "Mp4VideoMetadata.h" | ||
#include "ValveModule.h" | ||
#include <boost/test/unit_test.hpp> | ||
|
||
GenerateThumbnailsPipeline::GenerateThumbnailsPipeline() | ||
: pipeLine("thumnailSamplePipeline") {} | ||
|
||
bool GenerateThumbnailsPipeline::setUpPipeLine( | ||
const std::string &videoPath, const std::string &outFolderPath) { | ||
// Implementation | ||
|
||
bool parseFS = false; | ||
auto h264ImageMetadata = framemetadata_sp(new H264Metadata(0, 0)); | ||
auto frameType = FrameMetadata::FrameType::H264_DATA; | ||
auto mp4ReaderProps = | ||
Mp4ReaderSourceProps(videoPath, parseFS, 0, true, false, false); | ||
//initializing source Mp4 reader to read Mp4 video | ||
mMp4Reader = | ||
boost::shared_ptr<Mp4ReaderSource>(new Mp4ReaderSource(mp4ReaderProps)); | ||
mMp4Reader->addOutPutPin(h264ImageMetadata); | ||
|
||
auto mp4Metadata = framemetadata_sp(new Mp4VideoMetadata("v_1")); | ||
mMp4Reader->addOutPutPin(mp4Metadata); | ||
|
||
std::vector<std::string> mImagePin; | ||
mImagePin = mMp4Reader->getAllOutputPinsByType(frameType); | ||
|
||
//initializing H264 decoder to decode frame in H264 format | ||
mDecoder = | ||
boost::shared_ptr<H264Decoder>(new H264Decoder(H264DecoderProps())); | ||
//Selecting an image pin of H264 data frame type is necessary because the decoder processes H264 frames for decoding. | ||
mMp4Reader->setNext(mDecoder, mImagePin); | ||
|
||
//Initializing the valve to send only one frame. It is currently set to 0, meaning no frames are captured. | ||
mValve = boost::shared_ptr<ValveModule>(new ValveModule(ValveModuleProps(0))); | ||
mDecoder->setNext(mValve); | ||
|
||
//initialize cuda memory | ||
auto stream = cudastream_sp(new ApraCudaStream); | ||
mCudaCopy = boost::shared_ptr<CudaMemCopy>( | ||
new CudaMemCopy(CudaMemCopyProps(cudaMemcpyHostToDevice, stream))); | ||
mValve->setNext(mCudaCopy); | ||
|
||
//initializing Jpeg encoder to encode the frame in jpeg format | ||
mJpegEncoder = boost::shared_ptr<JPEGEncoderNVJPEG>( | ||
new JPEGEncoderNVJPEG(JPEGEncoderNVJPEGProps(stream))); | ||
mCudaCopy->setNext(mJpegEncoder); | ||
|
||
//initilizing file writer as sink to write frame at given path | ||
mFileWriter = boost::shared_ptr<FileWriterModule>( | ||
new FileWriterModule(FileWriterModuleProps(outFolderPath))); | ||
mJpegEncoder->setNext(mFileWriter); | ||
|
||
return true; | ||
} | ||
|
||
bool GenerateThumbnailsPipeline::startPipeLine() { | ||
pipeLine.appendModule(mMp4Reader); | ||
if (!pipeLine.init()) { | ||
throw AIPException( | ||
AIP_FATAL, | ||
"Engine Pipeline init failed. Check IPEngine Logs for more details."); | ||
return false; | ||
} | ||
pipeLine.run_all_threaded(); | ||
//allowing only one frame to get captured. | ||
mValve->allowFrames(1); | ||
|
||
return true; | ||
} | ||
|
||
bool GenerateThumbnailsPipeline::stopPipeLine() { | ||
pipeLine.stop(); | ||
pipeLine.term(); | ||
pipeLine.wait_for_all(); | ||
return true; | ||
} |
30 changes: 30 additions & 0 deletions
30
samples/create_thumbnail_from_mp4_video/GenerateThumbnailsPipeline.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include <PipeLine.h> | ||
#include <ValveModule.h> | ||
#include "Mp4ReaderSource.h" | ||
#include "H264Decoder.h" | ||
#include "ColorConversionXForm.h" | ||
#include "CudaMemCopy.h" | ||
#include "FileWriterModule.h" | ||
#include "JPEGEncoderNVJPEG.h" | ||
|
||
|
||
|
||
class GenerateThumbnailsPipeline | ||
{ | ||
public: | ||
GenerateThumbnailsPipeline(); | ||
bool setUpPipeLine(const std::string &videoPath,const std::string &outFolderPath); | ||
bool startPipeLine(); | ||
bool stopPipeLine(); | ||
|
||
private: | ||
PipeLine pipeLine; | ||
boost::shared_ptr<ValveModule> mValve; | ||
boost::shared_ptr<Mp4ReaderSource> mMp4Reader; | ||
boost::shared_ptr<H264Decoder> mDecoder; | ||
boost::shared_ptr<ColorConversion> mColorchange; | ||
boost::shared_ptr<CudaMemCopy> mCudaCopy; | ||
boost::shared_ptr<JPEGEncoderNVJPEG> mJpegEncoder; | ||
boost::shared_ptr<FileWriterModule> mFileWriter; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include "GenerateThumbnailsPipeline.h" | ||
#include <chrono> | ||
#include <iostream> | ||
|
||
void main(int argc, char *argv[]) { | ||
if (argc < 3) { | ||
std::cerr << "Usage: " << argv[0] << " <videoPath> <outFolderPath>" | ||
<< std::endl; | ||
} | ||
|
||
std::string videoPath = argv[argc - 2]; | ||
std::string outFolderPath = argv[argc - 1]; | ||
|
||
GenerateThumbnailsPipeline thumbnailPipeline; | ||
if (!thumbnailPipeline.setUpPipeLine(videoPath, outFolderPath)) { | ||
std::cerr << "Failed to setup pipeline." << std::endl; | ||
} | ||
|
||
if (!thumbnailPipeline.startPipeLine()) { | ||
std::cerr << "Failed to start pipeline." << std::endl; | ||
} | ||
|
||
// Wait for the pipeline to run for 10 seconds | ||
boost::this_thread::sleep_for(boost::chrono::seconds(5)); | ||
|
||
// Stop the pipeline | ||
if (!thumbnailPipeline.stopPipeLine()) { | ||
std::cerr << "Failed to stop pipeline." << std::endl; | ||
} else { | ||
std::cerr << "Saved Generated Thumbnail in <" << outFolderPath << ">"; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
samples/create_thumbnail_from_mp4_video/test_generate_thumbnail_from_mp4_video.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include "GenerateThumbnailsPipeline.h" | ||
#include "test_utils.h" | ||
#include <boost/test/unit_test.hpp> | ||
#include <chrono> | ||
|
||
BOOST_AUTO_TEST_SUITE(generateThumbnails) | ||
|
||
BOOST_AUTO_TEST_CASE(generateThumbnails_from_mp4) { | ||
auto generateThumbnailPipeline = | ||
boost::shared_ptr<GenerateThumbnailsPipeline>( | ||
new GenerateThumbnailsPipeline()); | ||
std::string videoPath = "../../data/Mp4_videos/h264_video_metadata/20230514/0011/1686723796848.mp4"; | ||
std::string outFolderPath = "data/generated_thumbnail/thumbnail_????.jpg"; | ||
BOOST_CHECK_NO_THROW(generateThumbnailPipeline->setUpPipeLine(videoPath, outFolderPath)); | ||
BOOST_CHECK_NO_THROW(generateThumbnailPipeline->startPipeLine()); | ||
|
||
boost::this_thread::sleep_for(boost::chrono::seconds(5)); | ||
|
||
const uint8_t *pReadDataTest = nullptr; | ||
unsigned int readDataSizeTest = 0U; | ||
|
||
BOOST_TEST(Test_Utils::readFile("data/test_thumbnail/sample_thumbnail.jpg", | ||
pReadDataTest, readDataSizeTest)); | ||
Test_Utils::saveOrCompare( | ||
"data/generated_thumbnail/thumbnail_0000.jpg", pReadDataTest, | ||
readDataSizeTest, 0); | ||
|
||
generateThumbnailPipeline->stopPipeLine(); | ||
} | ||
|
||
BOOST_AUTO_TEST_SUITE_END() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
cmake_minimum_required(VERSION 3.22) | ||
set(TARGET play_mp4_from_beginning) | ||
SET(SAMPLE_FILES | ||
PlayMp4VideoFromBeginning.cpp | ||
pipelineMain.cpp | ||
) | ||
SET(SAMPLE_FILES_H | ||
PlayMp4VideoFromBeginning.h | ||
) | ||
SET(SOURCE | ||
${SAMPLE_FILES} | ||
${SAMPLE_FILES_H} | ||
) | ||
add_executable(${TARGET} ${SOURCE}) | ||
target_include_directories ( ${TARGET} PRIVATE | ||
${OpenCV_INCLUDE_DIRS} | ||
${Boost_INCLUDE_DIRS} | ||
${LIBMP4_INC_DIR} | ||
) | ||
target_link_libraries( | ||
${TARGET} | ||
aprapipes | ||
${JPEG_LIBRARIES} | ||
${LIBMP4_LIB} | ||
${OPENH264_LIB} | ||
${Boost_LIBRARIES} | ||
${OpenCV_LIBRARIES} | ||
${NVCUDAToolkit_LIBS} | ||
${NVJPEGLIB_L4T} | ||
${NVCODEC_LIB} | ||
${FFMPEG_LIBRARIES} | ||
) | ||
|
Oops, something went wrong.