Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
F
ffmpeg.wasm-core
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Linshizhi
ffmpeg.wasm-core
Commits
d28cb849
Commit
d28cb849
authored
Feb 25, 2013
by
Anton Khirnov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
buffersrc: switch to an AVOptions-based system.
parent
4fa1f52e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
53 deletions
+55
-53
filters.texi
doc/filters.texi
+13
-24
buffersrc.c
libavfilter/buffersrc.c
+42
-29
No files found.
doc/filters.texi
View file @
d28cb849
...
@@ -2195,46 +2195,35 @@ Buffer video frames, and make them available to the filter chain.
...
@@ -2195,46 +2195,35 @@ Buffer video frames, and make them available to the filter chain.
This source is mainly intended for a programmatic use, in particular
This source is mainly intended for a programmatic use, in particular
through the interface defined in @file{libavfilter/vsrc_buffer.h}.
through the interface defined in @file{libavfilter/vsrc_buffer.h}.
It accepts the following parameters:
This filter accepts the following parameters:
@var{width}:@var{height}:@var{pix_fmt_string}:@var{timebase_num}:@var{timebase_den}:@var{sample_aspect_ratio_num}:@var{sample_aspect_ratio.den}
All the parameters need to be explicitly defined.
@table @option
Follows the list of the accepted parameters.
@item width
Input video width.
@table @option
@item height
Input video height.
@item
width, heigh
t
@item
pix_fm
t
Specify the width and height of the buffered video frames
.
Name of the input video pixel format
.
@item pix_fmt_string
@item time_base
A string representing the pixel format of the buffered video frames.
The time base used for input timestamps.
It may be a number corresponding to a pixel format, or a pixel format
name.
@item timebase_num, timebase_den
@item sar
Specify numerator and denomitor of the timebase assumed by the
Sample (pixel) aspect ratio of the input video.
timestamps of the buffered frames.
@item sample_aspect_ratio.num, sample_aspect_ratio.den
Specify numerator and denominator of the sample aspect ratio assumed
by the video frames.
@end table
@end table
For example:
For example:
@example
@example
buffer=
320:240:yuv410p:1:24:1:
1
buffer=
width=320:height=240:pix_fmt=yuv410p:time_base=1/24:sar=
1
@end example
@end example
will instruct the source to accept video frames with size 320x240 and
will instruct the source to accept video frames with size 320x240 and
with format "yuv410p", assuming 1/24 as the timestamps timebase and
with format "yuv410p", assuming 1/24 as the timestamps timebase and
square pixels (1:1 sample aspect ratio).
square pixels (1:1 sample aspect ratio).
Since the pixel format with name "yuv410p" corresponds to the number 6
(check the enum AVPixelFormat definition in @file{libavutil/pixfmt.h}),
this example corresponds to:
@example
buffer=320:240:6:1:24
@end example
@section color
@section color
...
...
libavfilter/buffersrc.c
View file @
d28cb849
...
@@ -23,6 +23,8 @@
...
@@ -23,6 +23,8 @@
* memory buffer source filter
* memory buffer source filter
*/
*/
#include <float.h>
#include "libavutil/channel_layout.h"
#include "libavutil/channel_layout.h"
#include "libavutil/common.h"
#include "libavutil/common.h"
#include "libavutil/fifo.h"
#include "libavutil/fifo.h"
...
@@ -45,6 +47,7 @@ typedef struct {
...
@@ -45,6 +47,7 @@ typedef struct {
/* video only */
/* video only */
int
h
,
w
;
int
h
,
w
;
enum
AVPixelFormat
pix_fmt
;
enum
AVPixelFormat
pix_fmt
;
char
*
pix_fmt_str
;
AVRational
pixel_aspect
;
AVRational
pixel_aspect
;
/* audio only */
/* audio only */
...
@@ -236,21 +239,17 @@ fail:
...
@@ -236,21 +239,17 @@ fail:
static
av_cold
int
init_video
(
AVFilterContext
*
ctx
,
const
char
*
args
)
static
av_cold
int
init_video
(
AVFilterContext
*
ctx
,
const
char
*
args
)
{
{
BufferSourceContext
*
c
=
ctx
->
priv
;
BufferSourceContext
*
c
=
ctx
->
priv
;
char
pix_fmt_str
[
128
];
int
n
=
0
;
if
(
!
c
->
pix_fmt_str
||
!
c
->
w
||
!
c
->
h
||
av_q2d
(
c
->
time_base
)
<=
0
)
{
av_log
(
ctx
,
AV_LOG_ERROR
,
"Invalid parameters provided.
\n
"
);
if
(
!
args
||
(
n
=
sscanf
(
args
,
"%d:%d:%127[^:]:%d:%d:%d:%d"
,
&
c
->
w
,
&
c
->
h
,
pix_fmt_str
,
&
c
->
time_base
.
num
,
&
c
->
time_base
.
den
,
&
c
->
pixel_aspect
.
num
,
&
c
->
pixel_aspect
.
den
))
!=
7
)
{
av_log
(
ctx
,
AV_LOG_ERROR
,
"Expected 7 arguments, but %d found in '%s'
\n
"
,
n
,
args
);
return
AVERROR
(
EINVAL
);
return
AVERROR
(
EINVAL
);
}
}
if
((
c
->
pix_fmt
=
av_get_pix_fmt
(
pix_fmt_str
))
==
AV_PIX_FMT_NONE
)
{
if
((
c
->
pix_fmt
=
av_get_pix_fmt
(
c
->
pix_fmt_str
))
==
AV_PIX_FMT_NONE
)
{
char
*
tail
;
char
*
tail
;
c
->
pix_fmt
=
strtol
(
pix_fmt_str
,
&
tail
,
10
);
c
->
pix_fmt
=
strtol
(
c
->
pix_fmt_str
,
&
tail
,
10
);
if
(
*
tail
||
c
->
pix_fmt
<
0
||
c
->
pix_fmt
>=
AV_PIX_FMT_NB
)
{
if
(
*
tail
||
c
->
pix_fmt
<
0
||
c
->
pix_fmt
>=
AV_PIX_FMT_NB
)
{
av_log
(
ctx
,
AV_LOG_ERROR
,
"Invalid pixel format string '%s'
\n
"
,
pix_fmt_str
);
av_log
(
ctx
,
AV_LOG_ERROR
,
"Invalid pixel format string '%s'
\n
"
,
c
->
pix_fmt_str
);
return
AVERROR
(
EINVAL
);
return
AVERROR
(
EINVAL
);
}
}
}
}
...
@@ -264,6 +263,32 @@ static av_cold int init_video(AVFilterContext *ctx, const char *args)
...
@@ -264,6 +263,32 @@ static av_cold int init_video(AVFilterContext *ctx, const char *args)
#define OFFSET(x) offsetof(BufferSourceContext, x)
#define OFFSET(x) offsetof(BufferSourceContext, x)
#define A AV_OPT_FLAG_AUDIO_PARAM
#define A AV_OPT_FLAG_AUDIO_PARAM
#define V AV_OPT_FLAG_VIDEO_PARAM
static
const
AVOption
video_options
[]
=
{
{
"width"
,
NULL
,
OFFSET
(
w
),
AV_OPT_TYPE_INT
,
{
.
i64
=
0
},
0
,
INT_MAX
,
V
},
{
"height"
,
NULL
,
OFFSET
(
h
),
AV_OPT_TYPE_INT
,
{
.
i64
=
0
},
0
,
INT_MAX
,
V
},
{
"pix_fmt"
,
NULL
,
OFFSET
(
pix_fmt_str
),
AV_OPT_TYPE_STRING
,
.
flags
=
V
},
#if FF_API_OLD_FILTER_OPTS
/* those 4 are for compatibility with the old option passing system where each filter
* did its own parsing */
{
"time_base_num"
,
"deprecated, do not use"
,
OFFSET
(
time_base
.
num
),
AV_OPT_TYPE_INT
,
{
.
i64
=
0
},
0
,
INT_MAX
,
V
},
{
"time_base_den"
,
"deprecated, do not use"
,
OFFSET
(
time_base
.
den
),
AV_OPT_TYPE_INT
,
{
.
i64
=
0
},
0
,
INT_MAX
,
V
},
{
"sar_num"
,
"deprecated, do not use"
,
OFFSET
(
pixel_aspect
.
num
),
AV_OPT_TYPE_INT
,
{
.
i64
=
0
},
0
,
INT_MAX
,
V
},
{
"sar_den"
,
"deprecated, do not use"
,
OFFSET
(
pixel_aspect
.
den
),
AV_OPT_TYPE_INT
,
{
.
i64
=
0
},
0
,
INT_MAX
,
V
},
#endif
{
"sar"
,
"sample aspect ratio"
,
OFFSET
(
pixel_aspect
),
AV_OPT_TYPE_RATIONAL
,
{
.
dbl
=
1
},
0
,
DBL_MAX
,
V
},
{
"time_base"
,
NULL
,
OFFSET
(
time_base
),
AV_OPT_TYPE_RATIONAL
,
{
.
dbl
=
0
},
0
,
DBL_MAX
,
V
},
{
NULL
},
};
static
const
AVClass
buffer_class
=
{
.
class_name
=
"buffer source"
,
.
item_name
=
av_default_item_name
,
.
option
=
video_options
,
.
version
=
LIBAVUTIL_VERSION_INT
,
};
static
const
AVOption
audio_options
[]
=
{
static
const
AVOption
audio_options
[]
=
{
{
"time_base"
,
NULL
,
OFFSET
(
time_base
),
AV_OPT_TYPE_RATIONAL
,
{
.
dbl
=
0
},
0
,
INT_MAX
,
A
},
{
"time_base"
,
NULL
,
OFFSET
(
time_base
),
AV_OPT_TYPE_RATIONAL
,
{
.
dbl
=
0
},
0
,
INT_MAX
,
A
},
{
"sample_rate"
,
NULL
,
OFFSET
(
sample_rate
),
AV_OPT_TYPE_INT
,
{
.
i64
=
0
},
0
,
INT_MAX
,
A
},
{
"sample_rate"
,
NULL
,
OFFSET
(
sample_rate
),
AV_OPT_TYPE_INT
,
{
.
i64
=
0
},
0
,
INT_MAX
,
A
},
...
@@ -284,34 +309,22 @@ static av_cold int init_audio(AVFilterContext *ctx, const char *args)
...
@@ -284,34 +309,22 @@ static av_cold int init_audio(AVFilterContext *ctx, const char *args)
BufferSourceContext
*
s
=
ctx
->
priv
;
BufferSourceContext
*
s
=
ctx
->
priv
;
int
ret
=
0
;
int
ret
=
0
;
s
->
class
=
&
abuffer_class
;
av_opt_set_defaults
(
s
);
if
((
ret
=
av_set_options_string
(
s
,
args
,
"="
,
":"
))
<
0
)
{
av_log
(
ctx
,
AV_LOG_ERROR
,
"Error parsing options string: %s.
\n
"
,
args
);
goto
fail
;
}
s
->
sample_fmt
=
av_get_sample_fmt
(
s
->
sample_fmt_str
);
s
->
sample_fmt
=
av_get_sample_fmt
(
s
->
sample_fmt_str
);
if
(
s
->
sample_fmt
==
AV_SAMPLE_FMT_NONE
)
{
if
(
s
->
sample_fmt
==
AV_SAMPLE_FMT_NONE
)
{
av_log
(
ctx
,
AV_LOG_ERROR
,
"Invalid sample format %s.
\n
"
,
av_log
(
ctx
,
AV_LOG_ERROR
,
"Invalid sample format %s.
\n
"
,
s
->
sample_fmt_str
);
s
->
sample_fmt_str
);
ret
=
AVERROR
(
EINVAL
);
return
AVERROR
(
EINVAL
);
goto
fail
;
}
}
s
->
channel_layout
=
av_get_channel_layout
(
s
->
channel_layout_str
);
s
->
channel_layout
=
av_get_channel_layout
(
s
->
channel_layout_str
);
if
(
!
s
->
channel_layout
)
{
if
(
!
s
->
channel_layout
)
{
av_log
(
ctx
,
AV_LOG_ERROR
,
"Invalid channel layout %s.
\n
"
,
av_log
(
ctx
,
AV_LOG_ERROR
,
"Invalid channel layout %s.
\n
"
,
s
->
channel_layout_str
);
s
->
channel_layout_str
);
ret
=
AVERROR
(
EINVAL
);
return
AVERROR
(
EINVAL
);
goto
fail
;
}
}
if
(
!
(
s
->
fifo
=
av_fifo_alloc
(
sizeof
(
AVFrame
*
))))
{
if
(
!
(
s
->
fifo
=
av_fifo_alloc
(
sizeof
(
AVFrame
*
))))
ret
=
AVERROR
(
ENOMEM
);
return
AVERROR
(
ENOMEM
);
goto
fail
;
}
if
(
!
s
->
time_base
.
num
)
if
(
!
s
->
time_base
.
num
)
s
->
time_base
=
(
AVRational
){
1
,
s
->
sample_rate
};
s
->
time_base
=
(
AVRational
){
1
,
s
->
sample_rate
};
...
@@ -320,8 +333,6 @@ static av_cold int init_audio(AVFilterContext *ctx, const char *args)
...
@@ -320,8 +333,6 @@ static av_cold int init_audio(AVFilterContext *ctx, const char *args)
"ch layout:%s
\n
"
,
s
->
time_base
.
num
,
s
->
time_base
.
den
,
s
->
sample_fmt_str
,
"ch layout:%s
\n
"
,
s
->
time_base
.
num
,
s
->
time_base
.
den
,
s
->
sample_fmt_str
,
s
->
sample_rate
,
s
->
channel_layout_str
);
s
->
sample_rate
,
s
->
channel_layout_str
);
fail:
av_opt_free
(
s
);
return
ret
;
return
ret
;
}
}
...
@@ -430,6 +441,7 @@ AVFilter avfilter_vsrc_buffer = {
...
@@ -430,6 +441,7 @@ AVFilter avfilter_vsrc_buffer = {
.
name
=
"buffer"
,
.
name
=
"buffer"
,
.
description
=
NULL_IF_CONFIG_SMALL
(
"Buffer video frames, and make them accessible to the filterchain."
),
.
description
=
NULL_IF_CONFIG_SMALL
(
"Buffer video frames, and make them accessible to the filterchain."
),
.
priv_size
=
sizeof
(
BufferSourceContext
),
.
priv_size
=
sizeof
(
BufferSourceContext
),
.
priv_class
=
&
buffer_class
,
.
query_formats
=
query_formats
,
.
query_formats
=
query_formats
,
.
init
=
init_video
,
.
init
=
init_video
,
...
@@ -454,6 +466,7 @@ AVFilter avfilter_asrc_abuffer = {
...
@@ -454,6 +466,7 @@ AVFilter avfilter_asrc_abuffer = {
.
name
=
"abuffer"
,
.
name
=
"abuffer"
,
.
description
=
NULL_IF_CONFIG_SMALL
(
"Buffer audio frames, and make them accessible to the filterchain."
),
.
description
=
NULL_IF_CONFIG_SMALL
(
"Buffer audio frames, and make them accessible to the filterchain."
),
.
priv_size
=
sizeof
(
BufferSourceContext
),
.
priv_size
=
sizeof
(
BufferSourceContext
),
.
priv_class
=
&
abuffer_class
,
.
query_formats
=
query_formats
,
.
query_formats
=
query_formats
,
.
init
=
init_audio
,
.
init
=
init_audio
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment