@@ -6,6 +6,7 @@ extern "C" {
6
6
#include < libavutil/avutil.h>
7
7
}
8
8
9
+ #include < stdexcept>
9
10
#include < iostream>
10
11
#include < iomanip>
11
12
#include < sstream>
@@ -42,7 +43,6 @@ VideoProperties::VideoProperties( const AVFormatContext* formatContext, const si
42
43
#if LIBAVUTIL_VERSION_MAJOR > 51
43
44
_pixFmt = av_pix_fmt_desc_get ( _codecContext->pix_fmt );
44
45
#else
45
- _pixFmt = NULL ;
46
46
if ( _codecContext->pix_fmt >= 0 && _codecContext->pix_fmt < PIX_FMT_NB )
47
47
_pixFmt = &av_pix_fmt_descriptors[ _codecContext->pix_fmt ];
48
48
#endif
@@ -96,6 +96,9 @@ std::string VideoProperties::getProfileName() const
96
96
97
97
std::string VideoProperties::getColorTransfert () const
98
98
{
99
+ if ( ! _codecContext )
100
+ return " unknown codec context" ;
101
+
99
102
switch ( _codecContext->color_trc )
100
103
{
101
104
case AVCOL_TRC_BT709:
@@ -157,6 +160,9 @@ std::string VideoProperties::getColorTransfert() const
157
160
158
161
std::string VideoProperties::getColorspace () const
159
162
{
163
+ if ( ! _codecContext )
164
+ return " unknown codec context" ;
165
+
160
166
switch ( _codecContext->colorspace )
161
167
{
162
168
case AVCOL_SPC_RGB:
@@ -199,6 +205,9 @@ std::string VideoProperties::getColorspace() const
199
205
200
206
std::string VideoProperties::getColorRange () const
201
207
{
208
+ if ( ! _codecContext )
209
+ return " unknown codec context" ;
210
+
202
211
switch ( _codecContext->color_range )
203
212
{
204
213
case AVCOL_RANGE_UNSPECIFIED:
@@ -216,6 +225,9 @@ std::string VideoProperties::getColorRange() const
216
225
217
226
std::string VideoProperties::getColorPrimaries () const
218
227
{
228
+ if ( ! _codecContext )
229
+ return " unknown codec context" ;
230
+
219
231
switch ( _codecContext->color_primaries )
220
232
{
221
233
case AVCOL_PRI_BT709:
@@ -247,6 +259,9 @@ std::string VideoProperties::getColorPrimaries() const
247
259
248
260
std::string VideoProperties::getChromaSampleLocation () const
249
261
{
262
+ if ( ! _codecContext )
263
+ return " unknown codec context" ;
264
+
250
265
switch ( _codecContext->chroma_sample_location )
251
266
{
252
267
case AVCHROMA_LOC_UNSPECIFIED:
@@ -272,6 +287,9 @@ std::string VideoProperties::getChromaSampleLocation() const
272
287
273
288
std::string VideoProperties::getFieldOrder () const
274
289
{
290
+ if ( ! _codecContext )
291
+ return " unknown codec context" ;
292
+
275
293
switch ( _codecContext->field_order )
276
294
{
277
295
case AV_FIELD_UNKNOWN:
@@ -291,9 +309,27 @@ std::string VideoProperties::getFieldOrder() const
291
309
}
292
310
}
293
311
312
+ std::string VideoProperties::getPixelName () const
313
+ {
314
+ if ( _pixFmt && _pixFmt->name )
315
+ return std::string ( _pixFmt->name );
316
+ return " unknown pixel name" ;
317
+ }
318
+
294
319
std::string VideoProperties::getEndianess () const
295
320
{
296
- return ( _pixFmt->flags & PIX_FMT_BE ) ? " big" : " little" ;
321
+ if ( _pixFmt )
322
+ return ( _pixFmt->flags & PIX_FMT_BE ) ? " big" : " little" ;
323
+ return " unknown pixel format" ;
324
+ }
325
+
326
+
327
+ int64_t VideoProperties::getStartTimecode () const
328
+ {
329
+ if ( ! _codecContext )
330
+ throw std::runtime_error ( " unknown codec context" );
331
+
332
+ return _codecContext->timecode_frame_start ;
297
333
}
298
334
299
335
std::string VideoProperties::getStartTimecodeString () const
@@ -312,6 +348,9 @@ std::string VideoProperties::getStartTimecodeString() const
312
348
313
349
Rational VideoProperties::getTimeBase () const
314
350
{
351
+ if ( ! _codecContext )
352
+ throw std::runtime_error ( " unknown codec context" );
353
+
315
354
Rational timeBase;
316
355
timeBase.num = _codecContext->time_base .num ;
317
356
timeBase.den = _codecContext->time_base .den ;
@@ -320,6 +359,9 @@ Rational VideoProperties::getTimeBase() const
320
359
321
360
Rational VideoProperties::getSar () const
322
361
{
362
+ if ( ! _codecContext )
363
+ throw std::runtime_error ( " unknown codec context" );
364
+
323
365
Rational sar;
324
366
sar.num = _codecContext->sample_aspect_ratio .num ;
325
367
sar.den = _codecContext->sample_aspect_ratio .den ;
@@ -328,6 +370,9 @@ Rational VideoProperties::getSar() const
328
370
329
371
Rational VideoProperties::getDar () const
330
372
{
373
+ if ( ! _codecContext )
374
+ throw std::runtime_error ( " unknown codec context" );
375
+
331
376
int darNum, darDen;
332
377
av_reduce ( &darNum, &darDen,
333
378
_codecContext->width * getSar ().num ,
@@ -340,6 +385,126 @@ Rational VideoProperties::getDar() const
340
385
return dar;
341
386
}
342
387
388
+ size_t VideoProperties::getCodecId () const
389
+ {
390
+ if ( ! _codecContext )
391
+ throw std::runtime_error ( " unknown codec context" );
392
+
393
+ return _codecContext->codec_id ;
394
+ }
395
+
396
+ size_t VideoProperties::getBitRate () const
397
+ {
398
+ if ( ! _codecContext )
399
+ throw std::runtime_error ( " unknown codec context" );
400
+
401
+ return _codecContext->bit_rate ;
402
+ }
403
+
404
+ size_t VideoProperties::getMaxBitRate () const
405
+ {
406
+ if ( ! _codecContext )
407
+ throw std::runtime_error ( " unknown codec context" );
408
+
409
+ return _codecContext->rc_max_rate ;
410
+ }
411
+
412
+ size_t VideoProperties::getMinBitRate () const
413
+ {
414
+ if ( ! _codecContext )
415
+ throw std::runtime_error ( " unknown codec context" );
416
+
417
+ return _codecContext->rc_min_rate ;
418
+ }
419
+
420
+ size_t VideoProperties::getTicksPerFrame () const
421
+ {
422
+ if ( ! _codecContext )
423
+ throw std::runtime_error ( " unknown codec context" );
424
+
425
+ return _codecContext->ticks_per_frame ;
426
+ }
427
+
428
+ size_t VideoProperties::getWidth () const
429
+ {
430
+ if ( ! _codecContext )
431
+ throw std::runtime_error ( " unknown codec context" );
432
+
433
+ return _codecContext->width ;
434
+ }
435
+
436
+ size_t VideoProperties::getHeight () const
437
+ {
438
+ if ( ! _codecContext )
439
+ throw std::runtime_error ( " unknown codec context" );
440
+
441
+ return _codecContext->height ;
442
+ }
443
+
444
+ size_t VideoProperties::getGopSize () const
445
+ {
446
+ if ( ! _codecContext )
447
+ throw std::runtime_error ( " unknown codec context" );
448
+
449
+ return _codecContext->gop_size ;
450
+ }
451
+
452
+ size_t VideoProperties::getDtgActiveFormat () const
453
+ {
454
+ if ( ! _codecContext )
455
+ throw std::runtime_error ( " unknown codec context" );
456
+
457
+ return _codecContext->dtg_active_format ;
458
+ }
459
+
460
+ size_t VideoProperties::getReferencesFrames () const
461
+ {
462
+ if ( ! _codecContext )
463
+ throw std::runtime_error ( " unknown codec context" );
464
+
465
+ return _codecContext->refs ;
466
+ }
467
+
468
+ int VideoProperties::getProfile () const
469
+ {
470
+ if ( ! _codecContext )
471
+ throw std::runtime_error ( " unknown codec context" );
472
+
473
+ return _codecContext->profile ;
474
+ }
475
+
476
+ int VideoProperties::getLevel () const
477
+ {
478
+ if ( ! _codecContext )
479
+ throw std::runtime_error ( " unknown codec context" );
480
+
481
+ return _codecContext->level ;
482
+ }
483
+
484
+ size_t VideoProperties::getComponentsCount () const
485
+ {
486
+ if ( ! _pixFmt )
487
+ throw std::runtime_error ( " unknown pixel format" );
488
+
489
+ return _pixFmt->nb_components ;
490
+ }
491
+
492
+ size_t VideoProperties::getChromaWidth () const
493
+ {
494
+ if ( ! _pixFmt )
495
+ throw std::runtime_error ( " unknown pixel format" );
496
+
497
+ return _pixFmt->log2_chroma_w ;
498
+ }
499
+
500
+ size_t VideoProperties::getChromaHeight () const
501
+ {
502
+ if ( ! _pixFmt )
503
+ throw std::runtime_error ( " unknown pixel format" );
504
+
505
+ return _pixFmt->log2_chroma_h ;
506
+ }
507
+
343
508
double VideoProperties::getFps () const
344
509
{
345
510
Rational timeBase = getTimeBase ();
@@ -349,8 +514,59 @@ double VideoProperties::getFps() const
349
514
return fps;
350
515
}
351
516
517
+ bool VideoProperties::hasBFrames () const
518
+ {
519
+ if ( ! _codecContext )
520
+ throw std::runtime_error ( " unknown codec context" );
521
+
522
+ return (bool ) _codecContext->has_b_frames ;
523
+ }
524
+
525
+ bool VideoProperties::isIndexedColors () const
526
+ {
527
+ if ( ! _pixFmt )
528
+ throw std::runtime_error ( " unknown pixel format" );
529
+
530
+ return (bool ) _pixFmt->flags & PIX_FMT_PAL;
531
+ }
532
+
533
+ bool VideoProperties::isBitWisePacked () const
534
+ {
535
+ if ( ! _pixFmt )
536
+ throw std::runtime_error ( " unknown pixel format" );
537
+
538
+ return (bool ) _pixFmt->flags & PIX_FMT_BITSTREAM;
539
+ }
540
+
541
+ bool VideoProperties::isHardwareAccelerated () const
542
+ {
543
+ if ( ! _pixFmt )
544
+ throw std::runtime_error ( " unknown pixel format" );
545
+
546
+ return (bool ) _pixFmt->flags & PIX_FMT_HWACCEL;
547
+ }
548
+
549
+ bool VideoProperties::isPlanar () const
550
+ {
551
+ if ( ! _pixFmt )
552
+ throw std::runtime_error ( " unknown pixel format" );
553
+
554
+ return (bool ) _pixFmt->flags & PIX_FMT_PLANAR;
555
+ }
556
+
557
+ bool VideoProperties::isRgbPixelData () const
558
+ {
559
+ if ( ! _pixFmt )
560
+ throw std::runtime_error ( " unknown pixel format" );
561
+
562
+ return (bool ) _pixFmt->flags & PIX_FMT_RGB;
563
+ }
564
+
352
565
bool VideoProperties::isPseudoPaletted () const
353
566
{
567
+ if ( ! _pixFmt )
568
+ throw std::runtime_error ( " unknown pixel format" );
569
+
354
570
#if LIBAVCODEC_VERSION_MAJOR > 53
355
571
return (bool ) _pixFmt->flags & PIX_FMT_PSEUDOPAL;
356
572
#else
@@ -360,6 +576,9 @@ bool VideoProperties::isPseudoPaletted() const
360
576
361
577
bool VideoProperties::hasAlpha () const
362
578
{
579
+ if ( ! _pixFmt )
580
+ throw std::runtime_error ( " unknown pixel format" );
581
+
363
582
#if LIBAVCODEC_VERSION_MAJOR > 53
364
583
return (bool ) _pixFmt->flags & PIX_FMT_ALPHA;
365
584
#else
@@ -433,13 +652,16 @@ void VideoProperties::analyseGopStructure( IProgress& progress )
433
652
std::vector<Channel> VideoProperties::getChannels () const
434
653
{
435
654
std::vector<Channel> channels;
436
- for ( size_t channel = 0 ; channel < ( size_t ) _pixFmt-> nb_components ; ++channel )
655
+ if ( _pixFmt )
437
656
{
438
- Channel c;
439
- c.id = channel;
440
- c.chromaHeight = (size_t )_pixFmt->comp [channel].plane ;
441
- c.bitStep = (size_t )_pixFmt->comp [channel].step_minus1 ;
442
- channels.push_back ( c );
657
+ for ( size_t channel = 0 ; channel < (size_t )_pixFmt->nb_components ; ++channel )
658
+ {
659
+ Channel c;
660
+ c.id = channel;
661
+ c.chromaHeight = (size_t )_pixFmt->comp [channel].plane ;
662
+ c.bitStep = (size_t )_pixFmt->comp [channel].step_minus1 ;
663
+ channels.push_back ( c );
664
+ }
443
665
}
444
666
return channels;
445
667
}
0 commit comments