17 #include <glog/logging.h> 20 #include <libavutil/imgutils.h> 29 bool MapFrameFormat(
bool is_video, AVFrame*
frame,
32 switch (frame->format) {
33 case AV_PIX_FMT_YUV420P:
39 case AV_PIX_FMT_RGB24:
43 case AV_PIX_FMT_VIDEOTOOLBOX:
48 LOG(DFATAL) <<
"Unknown pixel format: " 49 << av_get_pix_fmt_name(
50 static_cast<AVPixelFormat>(frame->format));
54 switch (frame->format) {
55 case AV_SAMPLE_FMT_U8:
58 case AV_SAMPLE_FMT_S16:
61 case AV_SAMPLE_FMT_S32:
64 case AV_SAMPLE_FMT_S64:
67 case AV_SAMPLE_FMT_FLT:
70 case AV_SAMPLE_FMT_DBL:
74 case AV_SAMPLE_FMT_U8P:
77 case AV_SAMPLE_FMT_S16P:
80 case AV_SAMPLE_FMT_S32P:
83 case AV_SAMPLE_FMT_S64P:
86 case AV_SAMPLE_FMT_FLTP:
89 case AV_SAMPLE_FMT_DBLP:
94 LOG(DFATAL) <<
"Unknown sample format: " 95 << av_get_sample_fmt_name(
96 static_cast<AVSampleFormat>(frame->format));
104 FFmpegDecodedFrame::FFmpegDecodedFrame(
105 AVFrame*
frame,
double pts,
double dts,
double duration,
106 std::shared_ptr<const StreamInfo> stream,
108 const std::vector<const uint8_t*>& data,
109 const std::vector<size_t>& linesize)
110 :
DecodedFrame(stream, pts, dts, duration, format, frame->nb_samples, data,
115 av_frame_unref(frame_);
116 av_frame_free(&frame_);
121 std::shared_ptr<const StreamInfo> info, AVFrame* frame,
double time,
124 if (!MapFrameFormat(info->is_video, frame, &format))
127 std::vector<const uint8_t*>
data;
130 data.emplace_back(frame->data[3]);
131 linesize.emplace_back(0);
134 data.assign(frame->extended_data, frame->extended_data + count);
135 if (info->is_video) {
136 DCHECK_LE(count,
sizeof(frame->linesize) /
sizeof(frame->linesize[0]));
137 for (
size_t i = 0; i < count; i++) {
138 if (frame->linesize[i] < 0) {
139 LOG(DFATAL) <<
"Negative linesize not supported";
142 linesize.emplace_back(frame->linesize[i]);
146 linesize.insert(linesize.end(), count, frame->linesize[0]);
151 AVFrame* copy = av_frame_clone(frame);
155 format, data, linesize);
159 size_t size =
sizeof(*this) +
sizeof(*frame_);
160 for (
int i = AV_NUM_DATA_POINTERS; i; i--) {
161 if (frame_->buf[i - 1])
162 size += frame_->buf[i - 1]->size;
164 for (
int i = frame_->nb_extended_buf; i; i--)
165 size += frame_->extended_buf[i - 1]->size;
166 for (
int i = frame_->nb_side_data; i; i--)
167 size += frame_->side_data[i - 1]->size;
std::shared_ptr< shaka::media::DecodedFrame > frame