-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathVideoCodec.cpp
More file actions
45 lines (37 loc) · 1.25 KB
/
VideoCodec.cpp
File metadata and controls
45 lines (37 loc) · 1.25 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
#include "VideoCodec.hpp"
#include <AvTranscoder/util.hpp>
#include <cmath>
#include <cassert>
namespace avtranscoder
{
VideoCodec::VideoCodec(const ECodecType type, const std::string& codecName)
: ICodec(type, codecName)
{
}
VideoCodec::VideoCodec(const ECodecType type, const AVCodecID codecId)
: ICodec(type, codecId)
{
}
VideoCodec::VideoCodec(const ECodecType type, AVCodecContext& avCodecContext)
: ICodec(type, avCodecContext)
{
}
VideoFrameDesc VideoCodec::getVideoFrameDesc() const
{
assert(_avCodecContext != NULL);
VideoFrameDesc videoFrameDesc(_avCodecContext->width, _avCodecContext->height, getPixelFormatName(_avCodecContext->pix_fmt));
double fps = 1.0 * _avCodecContext->time_base.den / (_avCodecContext->time_base.num * _avCodecContext->ticks_per_frame);
if(!std::isinf(fps))
videoFrameDesc._fps = fps;
return videoFrameDesc;
}
void VideoCodec::setImageParameters(const VideoFrameDesc& videoFrameDesc)
{
_avCodecContext->width = videoFrameDesc._width;
_avCodecContext->height = videoFrameDesc._height;
_avCodecContext->pix_fmt = videoFrameDesc._pixelFormat;
_avCodecContext->time_base.num = 1;
_avCodecContext->time_base.den = videoFrameDesc._fps;
_avCodecContext->ticks_per_frame = 1;
}
}