-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathyuv4mpeg.hpp
More file actions
57 lines (48 loc) · 1.28 KB
/
Copy pathyuv4mpeg.hpp
File metadata and controls
57 lines (48 loc) · 1.28 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
// Copyright (c) 2025 Hans-Kristian Arntzen
// SPDX-License-Identifier: MIT
#pragma once
#include <memory>
#include <string>
#include <stdio.h>
#include <stddef.h>
class YUV4MPEGFile
{
public:
bool open_read(const std::string &path);
bool rewind();
bool open_write(const std::string &path, const std::string ¶ms);
const std::string &get_params() const;
int get_width() const;
int get_height() const;
bool begin_frame();
bool write(const void *pixels, size_t size);
bool read(void *pixels, size_t size);
enum class Format
{
YUV420P,
YUV444P,
YUV420P16,
YUV444P16
};
Format get_format() const;
bool is_full_range() const;
bool is_center_chroma() const;
static int format_to_bytes_per_component(Format format);
static bool format_has_subsampling(Format format);
int get_frame_rate_num() const;
int get_frame_rate_den() const;
private:
enum class Mode { Read, Write };
bool open(const std::string &path, Mode mode);
struct FileDeleter { void operator()(FILE *f) { if (f) fclose(f); } };
std::unique_ptr<FILE, FileDeleter> file;
int width = 0, height = 0;
int frame_rate_num = 60, frame_rate_den = 1;
std::string params;
Mode mode = {};
Format format = {};
bool full_range = false;
bool center_chroma = false;
float unorm_scale = 1.0f;
long initial_position = -1;
};