// This class extends VideoSource to allow parsing of raw YUV // formats of various color sampling and bit-depths so that we can // do actual file encodes. class YUVVideoSource : public VideoSource { public:
YUVVideoSource(const std::string &file_name, vpx_img_fmt format, unsigned int width, unsigned int height, int rate_numerator,
int rate_denominator, unsigned int start, int limit)
: file_name_(file_name), input_file_(nullptr), img_(nullptr),
start_(start), limit_(limit), frame_(0), width_(0), height_(0),
format_(VPX_IMG_FMT_NONE), framerate_numerator_(rate_numerator),
framerate_denominator_(rate_denominator) { // This initializes format_, raw_size_, width_, height_ and allocates img.
SetSize(width, height, format);
}
~YUVVideoSource() override {
vpx_img_free(img_);
if (input_file_) fclose(input_file_);
}
void Begin() override {
if (input_file_) fclose(input_file_);
input_file_ = OpenTestDataFile(file_name_);
ASSERT_NE(input_file_, nullptr)
<< "Input file open failed. Filename: " << file_name_;
if (start_) {
fseek(input_file_, static_cast<unsigned>(raw_size_) * start_, SEEK_SET);
}
// If vpx_img_alloc() pads the row -- for example, to a power of 2 when // width is odd -- the YUV data needs to be read row-wise to ensure the // planes refer to the correct data. const int width_in_bytes = static_cast<int>(width_ * (img_->bit_depth >> 3));
if (img_->stride[VPX_PLANE_Y] != width_in_bytes) {
uint8_t *row = img_->planes[VPX_PLANE_Y]; const int y_stride = img_->stride[VPX_PLANE_Y];
for (unsigned int y = 0; y < height_; ++y) {
if (fread(row, width_in_bytes, 1, input_file_) == 0) {
limit_ = frame_; return;
}
row += y_stride;
} const int uv_width =
(width_in_bytes + img_->x_chroma_shift) >> img_->x_chroma_shift; const int uv_height =
(height_ + img_->y_chroma_shift) >> img_->y_chroma_shift; const int last_uv_plane =
(format_ == VPX_IMG_FMT_NV12) ? VPX_PLANE_U : VPX_PLANE_V;
for (int i = VPX_PLANE_U; i <= last_uv_plane; ++i) {
row = img_->planes[i]; const int stride = img_->stride[i];
for (int y = 0; y < uv_height; ++y) {
if (fread(row, uv_width, 1, input_file_) == 0) {
limit_ = frame_; return;
}
row += stride;
}
}
} else { // Read a frame from input_file.
if (fread(img_->img_data, raw_size_, 1, input_file_) == 0) {
limit_ = frame_;
}
}
}
protected:
std::string file_name_;
FILE *input_file_;
vpx_image_t *img_;
size_t raw_size_; unsigned int start_; unsigned int limit_; unsigned int frame_; unsigned int width_; unsigned int height_;
vpx_img_fmt format_;
int framerate_numerator_;
int framerate_denominator_;
};
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.