Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
FFmpeg
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
libremedia
Tethys
FFmpeg
Commits
03372d0a
Commit
03372d0a
authored
8 years ago
by
Matthieu Bouron
Browse files
Options
Downloads
Patches
Plain Diff
doc/examples/filtering_audio: switch to new decoding API
parent
afd257b4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
doc/examples/filtering_audio.c
+30
-33
30 additions, 33 deletions
doc/examples/filtering_audio.c
with
30 additions
and
33 deletions
doc/examples/filtering_audio.c
+
30
−
33
View file @
03372d0a
...
...
@@ -216,10 +216,9 @@ static void print_frame(const AVFrame *frame)
int
main
(
int
argc
,
char
**
argv
)
{
int
ret
;
AVPacket
packet0
,
packet
;
AVPacket
packet
;
AVFrame
*
frame
=
av_frame_alloc
();
AVFrame
*
filt_frame
=
av_frame_alloc
();
int
got_frame
;
if
(
!
frame
||
!
filt_frame
)
{
perror
(
"Could not allocate frame"
);
...
...
@@ -239,50 +238,48 @@ int main(int argc, char **argv)
goto
end
;
/* read all packets */
packet0
.
data
=
NULL
;
packet
.
data
=
NULL
;
while
(
1
)
{
if
(
!
packet0
.
data
)
{
if
((
ret
=
av_read_frame
(
fmt_ctx
,
&
packet
))
<
0
)
break
;
packet0
=
packet
;
}
if
((
ret
=
av_read_frame
(
fmt_ctx
,
&
packet
))
<
0
)
break
;
if
(
packet
.
stream_index
==
audio_stream_index
)
{
got_frame
=
0
;
ret
=
avcodec_decode_audio4
(
dec_ctx
,
frame
,
&
got_frame
,
&
packet
);
ret
=
avcodec_send_packet
(
dec_ctx
,
&
packet
);
if
(
ret
<
0
)
{
av_log
(
NULL
,
AV_LOG_ERROR
,
"Error
decoding audio
\n
"
);
continue
;
av_log
(
NULL
,
AV_LOG_ERROR
,
"Error
while sending a packet to the decoder
\n
"
);
break
;
}
packet
.
size
-=
ret
;
packet
.
data
+=
ret
;
if
(
got_frame
)
{
/* push the audio data from decoded frame into the filtergraph */
if
(
av_buffersrc_add_frame_flags
(
buffersrc_ctx
,
frame
,
0
)
<
0
)
{
av_log
(
NULL
,
AV_LOG_ERROR
,
"Error while feeding the audio filtergraph
\n
"
);
while
(
ret
>=
0
)
{
ret
=
avcodec_receive_frame
(
dec_ctx
,
frame
);
if
(
ret
==
AVERROR
(
EAGAIN
)
||
ret
==
AVERROR_EOF
)
{
break
;
}
else
if
(
ret
<
0
)
{
av_log
(
NULL
,
AV_LOG_ERROR
,
"Error while receiving a frame from the decoder
\n
"
);
goto
end
;
}
/* pull filtered audio from the filtergraph */
while
(
1
)
{
ret
=
av_buffers
ink_get_frame
(
buffers
ink
_ctx
,
f
ilt_frame
);
if
(
ret
==
AVERROR
(
EAGAIN
)
||
ret
==
AVERROR_EOF
)
if
(
ret
>=
0
)
{
/* push the audio data from decoded frame into the filtergraph */
if
(
av_buffers
rc_add_frame_flags
(
buffers
rc
_ctx
,
f
rame
,
AV_BUFFERSRC_FLAG_KEEP_REF
)
<
0
)
{
av_log
(
NULL
,
AV_LOG_ERROR
,
"Error while feeding the audio filtergraph
\n
"
);
break
;
if
(
ret
<
0
)
goto
end
;
print_frame
(
filt_frame
);
av_frame_unref
(
filt_frame
);
}
/* pull filtered audio from the filtergraph */
while
(
1
)
{
ret
=
av_buffersink_get_frame
(
buffersink_ctx
,
filt_frame
);
if
(
ret
==
AVERROR
(
EAGAIN
)
||
ret
==
AVERROR_EOF
)
break
;
if
(
ret
<
0
)
goto
end
;
print_frame
(
filt_frame
);
av_frame_unref
(
filt_frame
);
}
av_frame_unref
(
frame
);
}
}
if
(
packet
.
size
<=
0
)
av_packet_unref
(
&
packet0
);
}
else
{
/* discard non-wanted packets */
av_packet_unref
(
&
packet0
);
}
av_packet_unref
(
&
packet
);
}
end:
avfilter_graph_free
(
&
filter_graph
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment