Skip to content

Commit 9d475b8

Browse files
author
Clement Champetier
committed
transcoder: add ProcessStat class, returned by Transcoder::process method
1 parent e35d620 commit 9d475b8

File tree

4 files changed

+114
-5
lines changed

4 files changed

+114
-5
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include "ProcessStat.hpp"
2+
3+
#include <utility>
4+
5+
namespace avtranscoder
6+
{
7+
8+
void ProcessStat::addVideoStat( const size_t streamIndex, const VideoStat& videoStat )
9+
{
10+
_videoStats.insert( std::make_pair( streamIndex, videoStat ) );
11+
}
12+
13+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#ifndef _AV_TRANSCODER_PROCESSSTAT_HPP
2+
#define _AV_TRANSCODER_PROCESSSTAT_HPP
3+
4+
#include <AvTranscoder/common.hpp>
5+
6+
#include <map>
7+
8+
namespace avtranscoder
9+
{
10+
11+
/**
12+
* @brief Statistic related to a video stream.
13+
*/
14+
class VideoStat
15+
{
16+
public:
17+
VideoStat( const double duration, const size_t nbFrames )
18+
: _duration( duration )
19+
, _nbFrames( nbFrames )
20+
, _quality( 0 )
21+
, _psnr( 0 )
22+
{}
23+
24+
public:
25+
static double psnr( double d )
26+
{
27+
return -10.0 * log(d) / log(10.0);
28+
}
29+
30+
public:
31+
double _duration;
32+
size_t _nbFrames;
33+
size_t _quality; ///< Between 1 (good) and FF_LAMBDA_MAX (bad). 0 if unknown.
34+
double _psnr; ///< 0 if unknown.
35+
};
36+
37+
/**
38+
* @brief ProcessStat contains statistic results given after the process.
39+
* @see Transcoder::process methods
40+
*/
41+
class ProcessStat
42+
{
43+
public:
44+
ProcessStat()
45+
: _videoStats()
46+
{}
47+
48+
void addVideoStat( const size_t streamIndex, const VideoStat& videoStat );
49+
50+
VideoStat& getVideoStat( const size_t streamIndex ) { return _videoStats.at(streamIndex); }
51+
52+
private:
53+
std::map<size_t, VideoStat> _videoStats; ///< Key: streamIndex, Value: statistic video results
54+
};
55+
56+
}
57+
58+
#endif

src/AvTranscoder/transcoder/Transcoder.cpp

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,13 @@ bool Transcoder::processFrame()
221221
return true;
222222
}
223223

224-
void Transcoder::process()
224+
ProcessStat Transcoder::process()
225225
{
226226
NoDisplayProgress progress;
227-
process( progress );
227+
return process( progress );
228228
}
229229

230-
void Transcoder::process( IProgress& progress )
230+
ProcessStat Transcoder::process( IProgress& progress )
231231
{
232232
if( _streamTranscoders.size() == 0 )
233233
throw std::runtime_error( "missing input streams in transcoder" );
@@ -266,6 +266,12 @@ void Transcoder::process( IProgress& progress )
266266
_outputFile.endWrap();
267267

268268
LOG_INFO( "End of process" )
269+
270+
LOG_INFO( "Get process statistics" )
271+
ProcessStat processStat;
272+
fillProcessStat( processStat );
273+
274+
return processStat;
269275
}
270276

271277
void Transcoder::setProcessMethod( const EProcessMethod eProcessMethod, const size_t indexBasedStream, const double outputDuration )
@@ -511,4 +517,29 @@ void Transcoder::manageSwitchToGenerator()
511517
}
512518
}
513519

520+
void Transcoder::fillProcessStat( ProcessStat& processStat )
521+
{
522+
for( size_t streamIndex = 0; streamIndex < _streamTranscoders.size(); ++streamIndex )
523+
{
524+
IOutputStream& stream = _streamTranscoders.at( streamIndex )->getOutputStream();
525+
AVCodecContext& encoderContext = _streamTranscoders.at( streamIndex )->getEncoder().getCodec().getAVCodecContext();
526+
switch( encoderContext.codec_type )
527+
{
528+
case AVMEDIA_TYPE_VIDEO:
529+
{
530+
VideoStat videoStat( stream.getStreamDuration(), stream.getNbFrames() );
531+
if( encoderContext.coded_frame && ( encoderContext.flags & CODEC_FLAG_PSNR) )
532+
{
533+
videoStat._quality = encoderContext.coded_frame->quality;
534+
videoStat._psnr = VideoStat::psnr(encoderContext.coded_frame->error[0] / (encoderContext.width * encoderContext.height * 255.0 * 255.0));
535+
}
536+
processStat.addVideoStat( streamIndex, videoStat );
537+
break;
538+
}
539+
default:
540+
break;
541+
}
542+
}
543+
}
544+
514545
}

src/AvTranscoder/transcoder/Transcoder.hpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <AvTranscoder/file/IOutputFile.hpp>
77
#include <AvTranscoder/stream/IInputStream.hpp>
88
#include <AvTranscoder/profile/ProfileLoader.hpp>
9+
#include <AvTranscoder/transcoder/ProcessStat.hpp>
910

1011
#include "StreamTranscoder.hpp"
1112

@@ -119,10 +120,11 @@ class AvExport Transcoder
119120
* @brief Process all the streams, and ended the process depending on the transcode politic.
120121
* @note The function manages all process: init(), beginWrap(), processFrame()s, and endWrap().
121122
* @param progress: choose a progress, or create your own in C++ or in bindings by inherit IProgress class.
123+
* @return ProcessStat: object with statistics of the process for each stream.
122124
* @see IProgress
123125
*/
124-
void process( IProgress& progress );
125-
void process(); ///< Call process with no display of progression
126+
ProcessStat process( IProgress& progress );
127+
ProcessStat process(); ///< Call process with no display of progression
126128

127129
/**
128130
* @brief Return the list of streams added to the transcoder.
@@ -188,6 +190,11 @@ class AvExport Transcoder
188190
*/
189191
void manageSwitchToGenerator();
190192

193+
/**
194+
* @brief Fill the given ProcessStat to summarize the process.
195+
*/
196+
void fillProcessStat( ProcessStat& processStat );
197+
191198
private:
192199
IOutputFile& _outputFile; ///< The output media file after process (has link)
193200
std::vector< InputFile* > _inputFiles; ///< The list of input files which contain added streams (has ownership)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy