1
1
#include < torchaudio/csrc/ffmpeg/filter_graph.h>
2
- #include < torchaudio/csrc/ffmpeg/stub.h>
3
2
#include < stdexcept>
4
3
5
4
namespace torchaudio ::io {
6
5
7
6
namespace {
8
7
AVFilterGraph* get_filter_graph () {
9
- AVFilterGraph* ptr = FFMPEG avfilter_graph_alloc ();
8
+ AVFilterGraph* ptr = avfilter_graph_alloc ();
10
9
TORCH_CHECK (ptr, " Failed to allocate resouce." );
11
10
ptr->nb_threads = 1 ;
12
11
return ptr;
@@ -32,7 +31,7 @@ std::string get_audio_src_args(
32
31
time_base.num ,
33
32
time_base.den ,
34
33
sample_rate,
35
- FFMPEG av_get_sample_fmt_name (format),
34
+ av_get_sample_fmt_name (format),
36
35
channel_layout);
37
36
return std::string (args);
38
37
}
@@ -51,7 +50,7 @@ std::string get_video_src_args(
51
50
" video_size=%dx%d:pix_fmt=%s:time_base=%d/%d:frame_rate=%d/%d:pixel_aspect=%d/%d" ,
52
51
width,
53
52
height,
54
- FFMPEG av_get_pix_fmt_name (format),
53
+ av_get_pix_fmt_name (format),
55
54
time_base.num ,
56
55
time_base.den ,
57
56
frame_rate.num ,
@@ -69,7 +68,7 @@ void FilterGraph::add_audio_src(
69
68
int sample_rate,
70
69
uint64_t channel_layout) {
71
70
add_src (
72
- FFMPEG avfilter_get_by_name (" abuffer" ),
71
+ avfilter_get_by_name (" abuffer" ),
73
72
get_audio_src_args (format, time_base, sample_rate, channel_layout));
74
73
}
75
74
@@ -81,13 +80,13 @@ void FilterGraph::add_video_src(
81
80
int height,
82
81
AVRational sample_aspect_ratio) {
83
82
add_src (
84
- FFMPEG avfilter_get_by_name (" buffer" ),
83
+ avfilter_get_by_name (" buffer" ),
85
84
get_video_src_args (
86
85
format, time_base, frame_rate, width, height, sample_aspect_ratio));
87
86
}
88
87
89
88
void FilterGraph::add_src (const AVFilter* buffersrc, const std::string& args) {
90
- int ret = FFMPEG avfilter_graph_create_filter (
89
+ int ret = avfilter_graph_create_filter (
91
90
&buffersrc_ctx, buffersrc, " in" , args.c_str (), nullptr , graph);
92
91
TORCH_CHECK (
93
92
ret >= 0 ,
@@ -96,11 +95,11 @@ void FilterGraph::add_src(const AVFilter* buffersrc, const std::string& args) {
96
95
}
97
96
98
97
void FilterGraph::add_audio_sink () {
99
- add_sink (FFMPEG avfilter_get_by_name (" abuffersink" ));
98
+ add_sink (avfilter_get_by_name (" abuffersink" ));
100
99
}
101
100
102
101
void FilterGraph::add_video_sink () {
103
- add_sink (FFMPEG avfilter_get_by_name (" buffersink" ));
102
+ add_sink (avfilter_get_by_name (" buffersink" ));
104
103
}
105
104
106
105
void FilterGraph::add_sink (const AVFilter* buffersink) {
@@ -114,7 +113,7 @@ void FilterGraph::add_sink(const AVFilter* buffersink) {
114
113
// According to the other example
115
114
// https://ffmpeg.org/doxygen/4.1/filter_audio_8c-example.html
116
115
// `abuffersink` should not take options, and this resolved issue.
117
- int ret = FFMPEG avfilter_graph_create_filter (
116
+ int ret = avfilter_graph_create_filter (
118
117
&buffersink_ctx, buffersink, " out" , nullptr , nullptr , graph);
119
118
TORCH_CHECK (ret >= 0 , " Failed to create output filter." );
120
119
}
@@ -131,15 +130,15 @@ class InOuts {
131
130
132
131
public:
133
132
InOuts (const char * name, AVFilterContext* pCtx) {
134
- p = FFMPEG avfilter_inout_alloc ();
133
+ p = avfilter_inout_alloc ();
135
134
TORCH_CHECK (p, " Failed to allocate AVFilterInOut." );
136
- p->name = FFMPEG av_strdup (name);
135
+ p->name = av_strdup (name);
137
136
p->filter_ctx = pCtx;
138
137
p->pad_idx = 0 ;
139
138
p->next = nullptr ;
140
139
}
141
140
~InOuts () {
142
- FFMPEG avfilter_inout_free (&p);
141
+ avfilter_inout_free (&p);
143
142
}
144
143
operator AVFilterInOut**() {
145
144
return &p;
@@ -156,7 +155,7 @@ void FilterGraph::add_process(const std::string& filter_description) {
156
155
// If you are debugging this part of the code, you might get confused.
157
156
InOuts in{" in" , buffersrc_ctx}, out{" out" , buffersink_ctx};
158
157
159
- int ret = FFMPEG avfilter_graph_parse_ptr (
158
+ int ret = avfilter_graph_parse_ptr (
160
159
graph, filter_description.c_str (), out, in, nullptr );
161
160
162
161
TORCH_CHECK (
@@ -167,11 +166,11 @@ void FilterGraph::add_process(const std::string& filter_description) {
167
166
168
167
void FilterGraph::create_filter (AVBufferRef* hw_frames_ctx) {
169
168
buffersrc_ctx->outputs [0 ]->hw_frames_ctx = hw_frames_ctx;
170
- int ret = FFMPEG avfilter_graph_config (graph, nullptr );
169
+ int ret = avfilter_graph_config (graph, nullptr );
171
170
TORCH_CHECK (ret >= 0 , " Failed to configure the graph: " + av_err2string (ret));
172
- // char* desc = FFMPEG avfilter_graph_dump(graph, NULL);
171
+ // char* desc = avfilter_graph_dump(graph, NULL);
173
172
// std::cerr << "Filter created:\n" << desc << std::endl;
174
- // FFMPEG av_free(static_cast<void*>(desc));
173
+ // av_free(static_cast<void*>(desc));
175
174
}
176
175
177
176
// ////////////////////////////////////////////////////////////////////////////
@@ -191,8 +190,7 @@ FilterGraphOutputInfo FilterGraph::get_output_info() const {
191
190
ret.num_channels = l->ch_layout .nb_channels ;
192
191
#else
193
192
// Before FFmpeg 5.1
194
- ret.num_channels =
195
- FFMPEG av_get_channel_layout_nb_channels (l->channel_layout );
193
+ ret.num_channels = av_get_channel_layout_nb_channels (l->channel_layout );
196
194
#endif
197
195
break ;
198
196
}
@@ -215,12 +213,12 @@ FilterGraphOutputInfo FilterGraph::get_output_info() const {
215
213
// Streaming process
216
214
// ////////////////////////////////////////////////////////////////////////////
217
215
int FilterGraph::add_frame (AVFrame* pInputFrame) {
218
- return FFMPEG av_buffersrc_add_frame_flags (
216
+ return av_buffersrc_add_frame_flags (
219
217
buffersrc_ctx, pInputFrame, AV_BUFFERSRC_FLAG_KEEP_REF);
220
218
}
221
219
222
220
int FilterGraph::get_frame (AVFrame* pOutputFrame) {
223
- return FFMPEG av_buffersink_get_frame (buffersink_ctx, pOutputFrame);
221
+ return av_buffersink_get_frame (buffersink_ctx, pOutputFrame);
224
222
}
225
223
226
224
} // namespace torchaudio::io
0 commit comments