Skip to content

Commit 5c74696

Browse files
committed
generalize CineStat tool to VideoStat to get info on video files
1 parent 05df177 commit 5c74696

File tree

2 files changed

+28
-17
lines changed

2 files changed

+28
-17
lines changed

tools/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ install(TARGETS DICe_CineToTiff
4848
DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
4949
)
5050

51-
add_executable(DICe_CineStat DICe_CineStat.cpp)
52-
target_link_libraries(DICe_CineStat ${DICE_LIBRARIES} ${DICE_TEST_LIBRARIES})
51+
add_executable(DICe_VideoStat DICe_VideoStat.cpp)
52+
target_link_libraries(DICe_VideoStat ${DICE_LIBRARIES} ${DICE_TEST_LIBRARIES})
5353

54-
install(TARGETS DICe_CineStat
54+
install(TARGETS DICe_VideoStat
5555
DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
5656
)
5757

@@ -83,7 +83,7 @@ target_link_libraries(DICe_Cal ${DICE_LIBRARIES} ${DICE_TEST_LIBRARIES})
8383
add_executable(DICe_Epiline DICe_Epiline.cpp)
8484
target_link_libraries(DICe_Epiline ${DICE_LIBRARIES} ${DICE_TEST_LIBRARIES})
8585

86-
set_target_properties(DICe_CineToTiff DICe_CineStat DICe_Diff DICe_DiffAvg DICe_CrossInit DICe_Cal DICe_Epiline
86+
set_target_properties(DICe_CineToTiff DICe_VideoStat DICe_Diff DICe_DiffAvg DICe_CrossInit DICe_Cal DICe_Epiline
8787
PROPERTIES
8888
LIBRARY_OUTPUT_DIRECTORY "${DICE_OUTPUT_PREFIX}/lib"
8989
ARCHIVE_OUTPUT_DIRECTORY "${DICE_OUTPUT_PREFIX}/lib"
Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
// ************************************************************************
4040
// @HEADER
4141

42-
/*! \file DICe_CineToTiff.cpp
43-
\brief Utility for exporting cine files to tiff files
42+
/*! \file DICe_VideoStat.cpp
43+
\brief Utility for exporting video files to tiff files
4444
*/
4545

4646
#include <DICe.h>
@@ -69,8 +69,8 @@ int main(int argc, char *argv[]) {
6969
if(argc>=2){
7070
std::string help = argv[1];
7171
if(help=="-h"||argc>2){
72-
std::cout << " DICe_CineStat (writes a file with the cine index range) " << std::endl;
73-
std::cout << " Syntax: DICe_CineStat <cine_file_name>" << std::endl;
72+
std::cout << " DICe_VideoStat (writes a file with the valid video index range) " << std::endl;
73+
std::cout << " Syntax: DICe_VideoStat <video_file_name>" << std::endl;
7474
exit(0);
7575
}
7676
}
@@ -81,14 +81,25 @@ int main(int argc, char *argv[]) {
8181
DEBUG_MSG(argv[i]);
8282
}
8383
std::string fileName = argv[1];
84-
*outStream << "Cine file name: " << fileName << std::endl;
85-
Teuchos::RCP<hypercine::HyperCine> hc = DICe::utils::Video_Singleton::instance().hypercine(fileName,hypercine::HyperCine::TO_8_BIT);
86-
*outStream << "\nCine read successfully\n" << std::endl;
87-
88-
const int_t num_images = hc->file_frame_count();
89-
const int_t first_frame = hc->file_first_frame_id();
90-
const int_t last_frame = first_frame + num_images - 1;
91-
const int_t frame_rate = hc->frame_rate();
84+
*outStream << "Video file name: " << fileName << std::endl;
85+
86+
int_t num_images, first_frame, last_frame, frame_rate;
87+
88+
if(DICe::utils::is_cine_file(fileName)){
89+
Teuchos::RCP<hypercine::HyperCine> hc = DICe::utils::Video_Singleton::instance().hypercine(fileName,hypercine::HyperCine::TO_8_BIT);
90+
*outStream << "\nCine read successfully\n" << std::endl;
91+
num_images = hc->file_frame_count();
92+
first_frame = hc->file_first_frame_id();
93+
last_frame = first_frame + num_images - 1;
94+
frame_rate = hc->frame_rate();
95+
}else{
96+
Teuchos::RCP<cv::VideoCapture> vc = DICe::utils::Video_Singleton::instance().video_capture(fileName);
97+
*outStream << "\nVideo read successfully\n" << std::endl;
98+
num_images = vc->get(cv::CAP_PROP_FRAME_COUNT);
99+
first_frame = 0;
100+
last_frame = first_frame + num_images - 1;
101+
frame_rate = vc->get(cv::CAP_PROP_FPS);
102+
}
92103

93104
*outStream << "Num frames: " << num_images << std::endl;
94105
*outStream << "First frame: " << first_frame << std::endl;
@@ -97,7 +108,7 @@ int main(int argc, char *argv[]) {
97108

98109
// write stats to file
99110
create_directory(".dice");
100-
std::FILE * filePtr = fopen(".dice/.cine_stats.dat","w");
111+
std::FILE * filePtr = fopen(".dice/.video_stats.dat","w");
101112
fprintf(filePtr,"%i %i %i %i\n",num_images,first_frame,last_frame,frame_rate);
102113
fclose(filePtr);
103114

0 commit comments

Comments
 (0)