-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmediafile.h
More file actions
94 lines (74 loc) · 2.5 KB
/
Copy pathmediafile.h
File metadata and controls
94 lines (74 loc) · 2.5 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* SPDX-FileCopyrightText: 2023-2026 Minei3oat
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#ifndef MEDIAFILE_H
#define MEDIAFILE_H
#include <string>
extern "C" {
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavutil/imgutils.h>
#include <libswscale/swscale.h>
}
typedef struct {
unsigned long offset;
long pts;
long dts;
unsigned int duration;
bool is_keyframe;
bool is_corrupt;
char frame_type;
} packet_info_t;
typedef struct {
ssize_t num_infos;
packet_info_t* infos;
packet_info_t* infos_end;
} stream_info_t;
class MediaFile
{
public:
MediaFile(const std::string& filename);
~MediaFile();
int seek(ssize_t frame_index);
AVFrame* get_frame(ssize_t frame_index);
ssize_t find_iframe_before(ssize_t search) const;
ssize_t find_pframe_before(ssize_t search) const;
ssize_t find_iframe_after(ssize_t search) const;
ssize_t find_pframe_after(ssize_t search) const;
ssize_t offset_before_pts(int64_t pts) const;
ssize_t offset_after_pts(int64_t pts) const;
ssize_t get_frame_count() const { return stream_infos[video_stream->index].num_infos; }
ssize_t get_stream_count() const { return format_context->nb_streams; }
int get_reorder_length() const { return reorder_length; }
int get_max_bframes() const { return max_bframes; }
int get_gop_size() const { return gop_size; }
int get_max_difference() const { return max_difference; }
const std::string& get_filename() const { return filename; }
const packet_info_t* get_frame_info(ssize_t frame_index) const;
const packet_info_t* get_packet_info(int stream_index, int64_t pts) const;
const AVStream* get_video_stream() const { return video_stream; }
AVCodecContext* get_video_decode_context(bool hw_accel = false);
const AVStream* get_stream(size_t index) const;
int next_packet(AVPacket* packet);
bool is_audio_stream(int stream_index) const;
ssize_t current_frame = 0;
private:
void build_cache();
void detect_hardware_decoding();
AVFrame* get_raw_frame(ssize_t frame_index);
std::string filename;
AVFormatContext *format_context = NULL;
AVCodecContext *codec_context = NULL;
const AVCodecHWConfig *hw_config = NULL;
int reorder_length = 0;
int max_bframes = 0;
int gop_size = 0;
ssize_t filesize = 0;
int64_t max_difference = 0;
stream_info_t* stream_infos = NULL;
// temporary
AVStream *video_stream = NULL;
};
#endif // MEDIAFILE_H