-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathVideoReader.cpp
More file actions
71 lines (61 loc) · 2.21 KB
/
VideoReader.cpp
File metadata and controls
71 lines (61 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "VideoReader.hpp"
#include <AvTranscoder/util.hpp>
#include <AvTranscoder/decoder/VideoDecoder.hpp>
#include <AvTranscoder/decoder/VideoGenerator.hpp>
#include <AvTranscoder/data/decoded/VideoFrame.hpp>
#include <AvTranscoder/transform/VideoTransform.hpp>
#include <AvTranscoder/progress/NoDisplayProgress.hpp>
namespace avtranscoder
{
VideoReader::VideoReader(const InputStreamDesc& inputDesc)
: IReader(inputDesc)
, _videoStreamProperties(NULL)
, _outputWidth(0)
, _outputHeight(0)
, _outputPixelProperties("rgb24")
{
init();
}
void VideoReader::init()
{
// analyse InputFile
avtranscoder::NoDisplayProgress p;
_inputFile->analyse(p);
_streamProperties = &_inputFile->getProperties().getStreamPropertiesWithIndex(_inputDesc._streamIndex);
_videoStreamProperties = static_cast<const VideoProperties*>(_streamProperties);
_inputFile->activateStream(_inputDesc._streamIndex);
// setup decoder
_decoder = new VideoDecoder(_inputFile->getStream(_inputDesc._streamIndex));
_decoder->setupDecoder();
_currentDecoder = _decoder;
// create src frame
const VideoFrameDesc srcFrameDesc = _inputFile->getStream(_inputDesc._streamIndex).getVideoCodec().getVideoFrameDesc();
_srcFrame = new VideoFrame(srcFrameDesc, false);
VideoFrame* srcFrame = static_cast<VideoFrame*>(_srcFrame);
// create dst frame
_outputWidth = srcFrame->getWidth();
_outputHeight = srcFrame->getHeight();
_dstFrame = new VideoFrame(VideoFrameDesc(_outputWidth, _outputHeight, getPixelFormatName(getOutputPixelFormat())));
// generator
_generator = new VideoGenerator(srcFrameDesc);
// create transform
_transform = new VideoTransform();
}
VideoReader::~VideoReader()
{
delete _decoder;
delete _generator;
delete _srcFrame;
delete _dstFrame;
delete _transform;
}
void VideoReader::updateOutput(const size_t width, const size_t height, const std::string& pixelFormat)
{
_outputWidth = width;
_outputHeight = height;
_outputPixelProperties = PixelProperties(pixelFormat);
// update dst frame
delete _dstFrame;
_dstFrame = new VideoFrame(VideoFrameDesc(_outputWidth, _outputHeight, getPixelFormatName(getOutputPixelFormat())));
}
}