AJA NTV2 SDK  18.0.0.2122
NTV2 SDK 18.0.0.2122
main.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MIT */
8 // Includes
9 #include "ntv2utils.h"
10 #include "ajatypes.h"
11 #include "ntv2m31publicinterface.h"
14 #include "ntv2encodehevcfile.h"
15 #include <signal.h>
16 #include <iostream>
17 #include <iomanip>
18 
19 using namespace std;
20 
21 
22 // Globals
27 
31 
42 
53 
62 
71 
80 
84 
88 
97 };
98 
104 };
105 
106 static const size_t gNumCodecPresets (sizeof(kCodecPreset)/sizeof(M31VideoPreset));
107 static const size_t gNumCodecFormats (sizeof(kCodecFormat)/sizeof(NTV2FrameBufferFormat));
108 const int kNoSelection (1000000000);
109 static bool gGlobalQuit (false); // Set this "true" to exit gracefully
110 
111 
112 static int printPresets (void)
113 {
114  cout << "M31 Presets" << endl;
115  for (size_t ndx(0); ndx < gNumCodecPresets; ndx++)
116  {
117  const string presetStr (::NTV2M31VideoPresetToString(kCodecPreset[ndx], true));
118  if (!presetStr.empty())
119  cout << ndx << ": " << presetStr << endl;
120  }
121  return 0;
122 }
123 
124 static int printFormats (void)
125 {
126  cout << "M31 Formats" << endl;
127  for (size_t ndx(0); ndx < gNumCodecFormats; ndx++)
128  {
129  const string pixFormatStr (::NTV2FrameBufferFormatToString(kCodecFormat[ndx], true));
130  if (!pixFormatStr.empty())
131  cout << ndx << ": " << pixFormatStr << endl;
132  }
133  return 0;
134 }
135 
136 static void SignalHandler (int inSignal)
137 { (void) inSignal;
138  gGlobalQuit = true;
139 }
140 
141 
142 int main (int argc, const char ** argv)
143 {
144  M31VideoPreset m31Preset (M31_NUMVIDEOPRESETS); // Codec preset
145  char * pWhatToList (AJA_NULL); // Value of --list argument
146  char * pDeviceSpec (AJA_NULL); // Device specifier string, if any
147  int codecFormat (kNoSelection); // Codec format index
148  int codecPreset (kNoSelection); // Codec preset index
149  uint32_t channelNumber (1); // Number of the input channel to use
150  int infoData (0); // Picture and encoded information
151  poptContext optionsContext; // Context for parsing command line arguments
152 
153  (void)m31Preset; // stops unused warning
154 
155  AJADebug::Open();
156 
157  // Command line option descriptions:
158  const struct poptOption userOptionsTable [] =
159  {
160  {"device", 'd', POPT_ARG_STRING, &pDeviceSpec, 0, "device to use", "index#, serial#, or model"},
161  {"channel", 'c', POPT_ARG_INT, &channelNumber, 0, "channel to use", "1-4"},
162  {"format", 'f', POPT_ARG_INT, &codecFormat, 0, "format to use", "use '-lf' for list"},
163  {"preset", 'p', POPT_ARG_INT, &codecPreset, 0, "codec preset to use", "use '-lp' for list"},
164  {"list", 'l', POPT_ARG_STRING, &pWhatToList, 0, "list options", "p or f (presets or formats)"},
165  {"info", 'i', POPT_ARG_NONE, &infoData, 0, "write encoded info file", ""},
168  };
169 
170  // Read command line arguments...
171  optionsContext = ::poptGetContext (AJA_NULL, argc, argv, userOptionsTable, 0);
172  ::poptGetNextOpt(optionsContext);
173  optionsContext = ::poptFreeContext(optionsContext);
174 
175  if (pWhatToList && string(pWhatToList) == "p")
176  return printPresets();
177  else if (pWhatToList && string(pWhatToList) == "f")
178  return printFormats();
179  else if (pWhatToList)
180  {cerr << "## ERROR: Invalid argument to --list option, expected 'p' or 'f'" << endl; return 2;}
181 
182  if ((codecFormat != kNoSelection) && (codecFormat >= int(gNumCodecFormats)))
183  {cerr << "## ERROR: Invalid M31 format " << codecFormat << " -- expected 0 thru " << (gNumCodecFormats) << endl; return 2;}
184 
185  if ((codecPreset != kNoSelection) && (codecPreset >= int(gNumCodecPresets)))
186  {cerr << "## ERROR: Invalid M31 preset " << codecPreset << " -- expected 0 thru " << (gNumCodecPresets) << endl; return 2;}
187 
188  if (codecPreset < int(gNumCodecPresets))
189  m31Preset = kCodecPreset[codecPreset];
190 
191  const NTV2Channel inputChannel (::GetNTV2ChannelForIndex(channelNumber - 1));
192  if (!NTV2_IS_VALID_CHANNEL(inputChannel) || inputChannel > NTV2_CHANNEL4)
193  {cerr << "## ERROR: Invalid channel number " << channelNumber << " -- expected 1 thru 4" << endl; return 2;}
194 
195  ::signal (SIGINT, SignalHandler);
196  #if defined (AJAMac)
197  ::signal (SIGHUP, SignalHandler);
198  ::signal (SIGQUIT, SignalHandler);
199  #endif
200 
201  // Instantiate the NTV2EncodeHEVCFile object, using the specified AJA device (note we don't do audio in file to file or timecode burn)
202  NTV2EncodeHEVCFile hevcFileEncoder (pDeviceSpec ? string (pDeviceSpec) : "0", inputChannel,
204 
205  // Initialize the NTV2EncodeHEVCFile instance
206  if (AJA_FAILURE(hevcFileEncoder.Init()))
207  {cerr << "## ERROR: Initialization failed" << endl; return 1;}
208 
209  cout << endl
210  << "Capture: " << ::NTV2M31VideoPresetToString (hevcFileEncoder.GetCodecPreset(), false) << endl
211  << endl;
212 
213  // Run the capturer
214  hevcFileEncoder.Run();
215 
216  cout << " Capture Capture" << endl
217  << " Frames Frames Buffer" << endl
218  << "Processed Dropped Level" << endl;
219 
220  // Loop until someone tells us to stop
221  do
222  {
223  AVHevcStatus inputStatus;
224  hevcFileEncoder.GetStatus(inputStatus);
225  cout << setw (9) << inputStatus.framesProcessed
226  << setw (9) << inputStatus.framesDropped
227  << setw (9) << inputStatus.bufferLevel
228  << "\r" << flush;
229  AJATime::Sleep(1000);
230  } while (!gGlobalQuit);
231  cout << endl;
232 
233  // Quit the capturer
234  hevcFileEncoder.Quit();
235 
236  return 0;
237 
238 } // main
int main(int argc, const char **argv)
Definition: main.cpp:30
NTV2Channel GetNTV2ChannelForIndex(const ULWord inIndex0)
Definition: ntv2utils.cpp:4697
NTV2FrameBufferFormat
Identifies a particular video frame buffer pixel format. See Device Frame Buffer Formats for details...
Definition: ntv2enums.h:219
10-Bit 4:2:2 2-Plane YCbCr
Definition: ntv2enums.h:252
static AJAStatus Open(bool incrementRefCount=false)
Definition: debug.cpp:44
Declares the NTV2EncodeHEVCFile class.
#define AJA_FAILURE(_status_)
Definition: types.h:373
Instances of me capture frames in real time from a video signal provided to an input of an AJA device...
static const size_t gNumCodecFormats(sizeof(kCodecFormat)/sizeof(NTV2FrameBufferFormat))
Declares the AJATime class.
virtual void Quit(void)
Gracefully stops me from running.
Definition: json.hpp:5362
virtual AJAStatus Run(void)
Runs me.
#define POPT_ARG_INT
Definition: options_popt.h:58
void SignalHandler(int inSignal)
Definition: main.cpp:26
NTV2Channel
These enum values are mostly used to identify a specific widget_framestore. They&#39;re also commonly use...
Definition: ntv2enums.h:1357
virtual M31VideoPreset GetCodecPreset(void)
Get the codec preset.
#define POPT_AUTOHELP
Definition: options_popt.h:227
poptContext poptGetContext(const char *name, int argc, const char **argv, const struct poptOption *options, unsigned int flags)
static const size_t gNumCodecPresets(sizeof(kCodecPreset)/sizeof(M31VideoPreset))
const int kNoSelection(1000000000)
M31VideoPreset
Definition: ntv2m31enums.h:13
#define RAWFILEPATH
8-Bit 4:2:2 2-Plane YCbCr
Definition: ntv2enums.h:254
#define RAWFILEHEIGHT
#define AJA_NULL
Definition: ajatypes.h:167
Declares the most fundamental data types used by NTV2. Since Windows NT was the first principal devel...
static void Sleep(const int32_t inMilliseconds)
Suspends execution of the current thread for a given number of milliseconds.
Definition: systemtime.cpp:284
#define RAWFILEWIDTH
#define NTV2_IS_VALID_CHANNEL(__x__)
Definition: ntv2enums.h:1371
10-Bit 4:2:0 2-Plane YCbCr
Definition: ntv2enums.h:251
virtual void GetStatus(AVHevcStatus &outStatus)
Provides status information about my input (capture) process.
const M31VideoPreset kCodecPreset[]
Definition: main.cpp:23
std::string NTV2M31VideoPresetToString(const M31VideoPreset val, const bool retailDisplay=false)
Definition: ntv2utils.cpp:7144
Declares numerous NTV2 utility functions.
#define POPT_TABLEEND
Definition: options_popt.h:222
std::string NTV2FrameBufferFormatToString(const NTV2FrameBufferFormat inValue, const bool inForRetailDisplay=false)
Definition: ntv2utils.cpp:6936
const NTV2FrameBufferFormat kCodecFormat[]
Definition: main.cpp:99
Specifies channel or FrameStore 4 (or the 4th item).
Definition: ntv2enums.h:1362
virtual AJAStatus Init(void)
Initializes me and prepares me to Run.
poptContext poptFreeContext(poptContext con)
static int printPresets(void)
Definition: main.cpp:112
#define M31PRESET
int poptGetNextOpt(poptContext con)
static int printFormats(void)
Definition: main.cpp:124
#define POPT_ARG_STRING
Definition: options_popt.h:57
8-Bit 4:2:0 2-Plane YCbCr
Definition: ntv2enums.h:253
#define POPT_ARG_NONE
Definition: options_popt.h:56
static bool gGlobalQuit((0))