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
7497c894
Commit
7497c894
authored
Nov 27, 2013
by
Michael Niedermayer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
doc/examples/transcode_aac: switch to swresample
Signed-off-by:
Michael Niedermayer
<
michaelni@gmx.at
>
parent
60b099c3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
45 deletions
+35
-45
configure
configure
+1
-1
transcode_aac.c
doc/examples/transcode_aac.c
+34
-44
No files found.
configure
View file @
7497c894
...
@@ -2277,7 +2277,7 @@ zmq_filter_deps="libzmq"
...
@@ -2277,7 +2277,7 @@ zmq_filter_deps="libzmq"
# examples
# examples
muxing_example_deps
=
"avcodec avformat avutil swscale"
muxing_example_deps
=
"avcodec avformat avutil swscale"
transcode_aac_example_deps
=
"avcodec avformat
av
resample"
transcode_aac_example_deps
=
"avcodec avformat
sw
resample"
# libraries
# libraries
avcodec_deps
=
"avutil"
avcodec_deps
=
"avutil"
...
...
doc/examples/transcode_aac.c
View file @
7497c894
...
@@ -30,11 +30,12 @@
...
@@ -30,11 +30,12 @@
#include "libavcodec/avcodec.h"
#include "libavcodec/avcodec.h"
#include "libavutil/audio_fifo.h"
#include "libavutil/audio_fifo.h"
#include "libavutil/avassert.h"
#include "libavutil/avstring.h"
#include "libavutil/avstring.h"
#include "libavutil/frame.h"
#include "libavutil/frame.h"
#include "libavutil/opt.h"
#include "libavutil/opt.h"
#include "lib
avresample/av
resample.h"
#include "lib
swresample/sw
resample.h"
/** The output bit rate in kbit/s */
/** The output bit rate in kbit/s */
#define OUTPUT_BIT_RATE 48000
#define OUTPUT_BIT_RATE 48000
...
@@ -223,11 +224,11 @@ static int init_input_frame(AVFrame **frame)
...
@@ -223,11 +224,11 @@ static int init_input_frame(AVFrame **frame)
/**
/**
* Initialize the audio resampler based on the input and output codec settings.
* Initialize the audio resampler based on the input and output codec settings.
* If the input and output sample formats differ, a conversion is required
* If the input and output sample formats differ, a conversion is required
* lib
av
resample takes care of this, but requires initialization.
* lib
sw
resample takes care of this, but requires initialization.
*/
*/
static
int
init_resampler
(
AVCodecContext
*
input_codec_context
,
static
int
init_resampler
(
AVCodecContext
*
input_codec_context
,
AVCodecContext
*
output_codec_context
,
AVCodecContext
*
output_codec_context
,
AVAudioResample
Context
**
resample_context
)
Swr
Context
**
resample_context
)
{
{
/**
/**
* Only initialize the resampler if it is necessary, i.e.,
* Only initialize the resampler if it is necessary, i.e.,
...
@@ -237,35 +238,36 @@ static int init_resampler(AVCodecContext *input_codec_context,
...
@@ -237,35 +238,36 @@ static int init_resampler(AVCodecContext *input_codec_context,
input_codec_context
->
channels
!=
output_codec_context
->
channels
)
{
input_codec_context
->
channels
!=
output_codec_context
->
channels
)
{
int
error
;
int
error
;
/** Create a resampler context for the conversion. */
if
(
!
(
*
resample_context
=
avresample_alloc_context
()))
{
fprintf
(
stderr
,
"Could not allocate resample context
\n
"
);
return
AVERROR
(
ENOMEM
);
}
/**
/**
* Create a resampler context for the conversion.
* Set the conversion parameters.
* Set the conversion parameters.
* Default channel layouts based on the number of channels
* Default channel layouts based on the number of channels
* are assumed for simplicity (they are sometimes not detected
* are assumed for simplicity (they are sometimes not detected
* properly by the demuxer and/or decoder).
* properly by the demuxer and/or decoder).
*/
*/
av_opt_set_int
(
*
resample_context
,
"in_channel_layout"
,
*
resample_context
=
swr_alloc_set_opts
(
NULL
,
av_get_default_channel_layout
(
input_codec_context
->
channels
),
0
);
av_get_default_channel_layout
(
output_codec_context
->
channels
),
av_opt_set_int
(
*
resample_context
,
"out_channel_layout"
,
output_codec_context
->
sample_fmt
,
av_get_default_channel_layout
(
output_codec_context
->
channels
),
0
);
output_codec_context
->
sample_rate
,
av_opt_set_int
(
*
resample_context
,
"in_sample_rate"
,
av_get_default_channel_layout
(
input_codec_context
->
channels
),
input_codec_context
->
sample_rate
,
0
);
input_codec_context
->
sample_fmt
,
av_opt_set_int
(
*
resample_context
,
"out_sample_rate"
,
input_codec_context
->
sample_rate
,
output_codec_context
->
sample_rate
,
0
);
0
,
NULL
);
av_opt_set_int
(
*
resample_context
,
"in_sample_fmt"
,
if
(
!*
resample_context
)
{
input_codec_context
->
sample_fmt
,
0
);
fprintf
(
stderr
,
"Could not allocate resample context
\n
"
);
av_opt_set_int
(
*
resample_context
,
"out_sample_fmt"
,
return
AVERROR
(
ENOMEM
);
output_codec_context
->
sample_fmt
,
0
);
}
/**
* Perform a sanity check so that the number of converted samples is
* not greater than the number of samples to be converted.
* If the sample rates differ, this case has to be handled differently
*/
av_assert0
(
output_codec_context
->
sample_rate
==
input_codec_context
->
sample_rate
);
/** Open the resampler with the specified parameters. */
/** Open the resampler with the specified parameters. */
if
((
error
=
avresample_open
(
*
resample_context
))
<
0
)
{
if
((
error
=
swr_init
(
*
resample_context
))
<
0
)
{
fprintf
(
stderr
,
"Could not open resample context
\n
"
);
fprintf
(
stderr
,
"Could not open resample context
\n
"
);
avresample
_free
(
resample_context
);
swr
_free
(
resample_context
);
return
error
;
return
error
;
}
}
}
}
...
@@ -387,30 +389,21 @@ static int init_converted_samples(uint8_t ***converted_input_samples,
...
@@ -387,30 +389,21 @@ static int init_converted_samples(uint8_t ***converted_input_samples,
* The conversion happens on a per-frame basis, the size of which is specified
* The conversion happens on a per-frame basis, the size of which is specified
* by frame_size.
* by frame_size.
*/
*/
static
int
convert_samples
(
uint8_t
**
input_data
,
static
int
convert_samples
(
const
uint8_t
**
input_data
,
uint8_t
**
converted_data
,
const
int
frame_size
,
uint8_t
**
converted_data
,
const
int
frame_size
,
AVAudioResample
Context
*
resample_context
)
Swr
Context
*
resample_context
)
{
{
int
error
;
int
error
;
/** Convert the samples using the resampler. */
/** Convert the samples using the resampler. */
if
((
error
=
avresample_convert
(
resample_context
,
converted_data
,
0
,
if
((
error
=
swr_convert
(
resample_context
,
frame_size
,
input_data
,
0
,
frame_size
))
<
0
)
{
converted_data
,
frame_size
,
input_data
,
frame_size
))
<
0
)
{
fprintf
(
stderr
,
"Could not convert input samples (error '%s')
\n
"
,
fprintf
(
stderr
,
"Could not convert input samples (error '%s')
\n
"
,
get_error_text
(
error
));
get_error_text
(
error
));
return
error
;
return
error
;
}
}
/**
* Perform a sanity check so that the number of converted samples is
* not greater than the number of samples to be converted.
* If the sample rates differ, this case has to be handled differently
*/
if
(
avresample_available
(
resample_context
))
{
fprintf
(
stderr
,
"Converted samples left over
\n
"
);
return
AVERROR_EXIT
;
}
return
0
;
return
0
;
}
}
...
@@ -447,7 +440,7 @@ static int read_decode_convert_and_store(AVAudioFifo *fifo,
...
@@ -447,7 +440,7 @@ static int read_decode_convert_and_store(AVAudioFifo *fifo,
AVFormatContext
*
input_format_context
,
AVFormatContext
*
input_format_context
,
AVCodecContext
*
input_codec_context
,
AVCodecContext
*
input_codec_context
,
AVCodecContext
*
output_codec_context
,
AVCodecContext
*
output_codec_context
,
AVAudioResample
Context
*
resampler_context
,
Swr
Context
*
resampler_context
,
int
*
finished
)
int
*
finished
)
{
{
/** Temporary storage of the input samples of the frame read from the file. */
/** Temporary storage of the input samples of the frame read from the file. */
...
@@ -484,7 +477,7 @@ static int read_decode_convert_and_store(AVAudioFifo *fifo,
...
@@ -484,7 +477,7 @@ static int read_decode_convert_and_store(AVAudioFifo *fifo,
* Convert the input samples to the desired output sample format.
* Convert the input samples to the desired output sample format.
* This requires a temporary storage provided by converted_input_samples.
* This requires a temporary storage provided by converted_input_samples.
*/
*/
if
(
convert_samples
(
input_frame
->
extended_data
,
converted_input_samples
,
if
(
convert_samples
(
(
const
uint8_t
**
)
input_frame
->
extended_data
,
converted_input_samples
,
input_frame
->
nb_samples
,
resampler_context
))
input_frame
->
nb_samples
,
resampler_context
))
goto
cleanup
;
goto
cleanup
;
...
@@ -646,7 +639,7 @@ int main(int argc, char **argv)
...
@@ -646,7 +639,7 @@ int main(int argc, char **argv)
{
{
AVFormatContext
*
input_format_context
=
NULL
,
*
output_format_context
=
NULL
;
AVFormatContext
*
input_format_context
=
NULL
,
*
output_format_context
=
NULL
;
AVCodecContext
*
input_codec_context
=
NULL
,
*
output_codec_context
=
NULL
;
AVCodecContext
*
input_codec_context
=
NULL
,
*
output_codec_context
=
NULL
;
AVAudioResample
Context
*
resample_context
=
NULL
;
Swr
Context
*
resample_context
=
NULL
;
AVAudioFifo
*
fifo
=
NULL
;
AVAudioFifo
*
fifo
=
NULL
;
int
ret
=
AVERROR_EXIT
;
int
ret
=
AVERROR_EXIT
;
...
@@ -750,10 +743,7 @@ int main(int argc, char **argv)
...
@@ -750,10 +743,7 @@ int main(int argc, char **argv)
cleanup:
cleanup:
if
(
fifo
)
if
(
fifo
)
av_audio_fifo_free
(
fifo
);
av_audio_fifo_free
(
fifo
);
if
(
resample_context
)
{
swr_free
(
&
resample_context
);
avresample_close
(
resample_context
);
avresample_free
(
&
resample_context
);
}
if
(
output_codec_context
)
if
(
output_codec_context
)
avcodec_close
(
output_codec_context
);
avcodec_close
(
output_codec_context
);
if
(
output_format_context
)
{
if
(
output_format_context
)
{
...
...
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