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
5ff42e31
Commit
5ff42e31
authored
Feb 24, 2012
by
Anton Khirnov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lavf/output-example: use new audio encoding API correctly.
parent
6e9ed7c7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
29 deletions
+15
-29
output-example.c
libavformat/output-example.c
+15
-29
No files found.
libavformat/output-example.c
View file @
5ff42e31
...
...
@@ -53,8 +53,6 @@ static int sws_flags = SWS_BICUBIC;
static
float
t
,
tincr
,
tincr2
;
static
int16_t
*
samples
;
static
uint8_t
*
audio_outbuf
;
static
int
audio_outbuf_size
;
static
int
audio_input_frame_size
;
/*
...
...
@@ -112,27 +110,12 @@ static void open_audio(AVFormatContext *oc, AVStream *st)
/* increment frequency by 110 Hz per second */
tincr2
=
2
*
M_PI
*
110
.
0
/
c
->
sample_rate
/
c
->
sample_rate
;
audio_outbuf_size
=
10000
;
audio_outbuf
=
av_malloc
(
audio_outbuf_size
);
/* ugly hack for PCM codecs (will be removed ASAP with new PCM
support to compute the input frame size in samples */
if
(
c
->
frame_size
<=
1
)
{
audio_input_frame_size
=
audio_outbuf_size
/
c
->
channels
;
switch
(
st
->
codec
->
codec_id
)
{
case
CODEC_ID_PCM_S16LE
:
case
CODEC_ID_PCM_S16BE
:
case
CODEC_ID_PCM_U16LE
:
case
CODEC_ID_PCM_U16BE
:
audio_input_frame_size
>>=
1
;
break
;
default:
break
;
}
}
else
{
if
(
c
->
codec
->
capabilities
&
CODEC_CAP_VARIABLE_FRAME_SIZE
)
audio_input_frame_size
=
10000
;
else
audio_input_frame_size
=
c
->
frame_size
;
}
samples
=
av_malloc
(
audio_input_frame_size
*
2
*
c
->
channels
);
samples
=
av_malloc
(
audio_input_frame_size
*
av_get_bytes_per_sample
(
c
->
sample_fmt
)
*
c
->
channels
);
}
/* prepare a 16 bit dummy audio frame of 'frame_size' samples and
...
...
@@ -156,19 +139,23 @@ static void write_audio_frame(AVFormatContext *oc, AVStream *st)
{
AVCodecContext
*
c
;
AVPacket
pkt
;
av_init_packet
(
&
pkt
);
AVFrame
*
frame
=
avcodec_alloc_frame
();
int
got_packet
;
av_init_packet
(
&
pkt
);
c
=
st
->
codec
;
get_audio_frame
(
samples
,
audio_input_frame_size
,
c
->
channels
);
frame
->
nb_samples
=
audio_input_frame_size
;
avcodec_fill_audio_frame
(
frame
,
c
->
channels
,
c
->
sample_fmt
,
(
uint8_t
*
)
samples
,
audio_input_frame_size
*
av_get_bytes_per_sample
(
c
->
sample_fmt
)
*
c
->
channels
,
1
);
pkt
.
size
=
avcodec_encode_audio2
(
c
,
audio_outbuf
,
audio_outbuf_size
,
samples
);
avcodec_encode_audio2
(
c
,
&
pkt
,
frame
,
&
got_packet
);
if
(
!
got_packet
)
return
;
if
(
c
->
coded_frame
&&
c
->
coded_frame
->
pts
!=
AV_NOPTS_VALUE
)
pkt
.
pts
=
av_rescale_q
(
c
->
coded_frame
->
pts
,
c
->
time_base
,
st
->
time_base
);
pkt
.
flags
|=
AV_PKT_FLAG_KEY
;
pkt
.
stream_index
=
st
->
index
;
pkt
.
data
=
audio_outbuf
;
/* write the compressed frame in the media file */
if
(
av_interleaved_write_frame
(
oc
,
&
pkt
)
!=
0
)
{
...
...
@@ -182,7 +169,6 @@ static void close_audio(AVFormatContext *oc, AVStream *st)
avcodec_close
(
st
->
codec
);
av_free
(
samples
);
av_free
(
audio_outbuf
);
}
/**************************************************************/
...
...
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