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
67d28f4a
Commit
67d28f4a
authored
Sep 22, 2016
by
Anton Khirnov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
examples/output: switch to the new encoding API
parent
7bf8db4d
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
27 deletions
+44
-27
output.c
doc/examples/output.c
+44
-27
No files found.
doc/examples/output.c
View file @
67d28f4a
...
@@ -233,25 +233,37 @@ static AVFrame *get_audio_frame(OutputStream *ost)
...
@@ -233,25 +233,37 @@ static AVFrame *get_audio_frame(OutputStream *ost)
static
int
encode_audio_frame
(
AVFormatContext
*
oc
,
OutputStream
*
ost
,
static
int
encode_audio_frame
(
AVFormatContext
*
oc
,
OutputStream
*
ost
,
AVFrame
*
frame
)
AVFrame
*
frame
)
{
{
int
ret
;
ret
=
avcodec_send_frame
(
ost
->
enc
,
frame
);
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"Error submitting a frame for encoding
\n
"
);
exit
(
1
);
}
while
(
ret
>=
0
)
{
AVPacket
pkt
=
{
0
};
// data and size must be 0;
AVPacket
pkt
=
{
0
};
// data and size must be 0;
int
got_packet
;
av_init_packet
(
&
pkt
);
av_init_packet
(
&
pkt
);
avcodec_encode_audio2
(
ost
->
enc
,
&
pkt
,
frame
,
&
got_packet
);
if
(
got_packet
)
{
pkt
.
stream_index
=
ost
->
st
->
index
;
ret
=
avcodec_receive_packet
(
ost
->
enc
,
&
pkt
);
if
(
ret
<
0
&&
ret
!=
AVERROR
(
EAGAIN
)
&&
ret
!=
AVERROR_EOF
)
{
fprintf
(
stderr
,
"Error encoding a video frame
\n
"
);
exit
(
1
);
}
else
if
(
ret
>=
0
)
{
av_packet_rescale_ts
(
&
pkt
,
ost
->
enc
->
time_base
,
ost
->
st
->
time_base
);
av_packet_rescale_ts
(
&
pkt
,
ost
->
enc
->
time_base
,
ost
->
st
->
time_base
);
pkt
.
stream_index
=
ost
->
st
->
index
;
/* Write the compressed frame to the media file. */
/* Write the compressed frame to the media file. */
if
(
av_interleaved_write_frame
(
oc
,
&
pkt
)
!=
0
)
{
ret
=
av_interleaved_write_frame
(
oc
,
&
pkt
);
fprintf
(
stderr
,
"Error while writing audio frame
\n
"
);
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"Error while writing video frame
\n
"
);
exit
(
1
);
exit
(
1
);
}
}
}
}
}
return
(
frame
||
got_packet
)
?
0
:
1
;
return
ret
==
AVERROR_EOF
;
}
}
/*
/*
...
@@ -517,36 +529,41 @@ static int write_video_frame(AVFormatContext *oc, OutputStream *ost)
...
@@ -517,36 +529,41 @@ static int write_video_frame(AVFormatContext *oc, OutputStream *ost)
int
ret
;
int
ret
;
AVCodecContext
*
c
;
AVCodecContext
*
c
;
AVFrame
*
frame
;
AVFrame
*
frame
;
AVPacket
pkt
=
{
0
};
int
got_packet
=
0
;
c
=
ost
->
enc
;
c
=
ost
->
enc
;
frame
=
get_video_frame
(
ost
);
frame
=
get_video_frame
(
ost
);
av_init_packet
(
&
pkt
);
/* encode the image */
/* encode the image */
ret
=
avcodec_
encode_video2
(
c
,
&
pkt
,
frame
,
&
got_packet
);
ret
=
avcodec_
send_frame
(
c
,
frame
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"Error
encoding a video frame
\n
"
);
fprintf
(
stderr
,
"Error
submitting a frame for encoding
\n
"
);
exit
(
1
);
exit
(
1
);
}
}
if
(
got_packet
)
{
while
(
ret
>=
0
)
{
AVPacket
pkt
=
{
0
};
av_init_packet
(
&
pkt
);
ret
=
avcodec_receive_packet
(
c
,
&
pkt
);
if
(
ret
<
0
&&
ret
!=
AVERROR
(
EAGAIN
)
&&
ret
!=
AVERROR_EOF
)
{
fprintf
(
stderr
,
"Error encoding a video frame
\n
"
);
exit
(
1
);
}
else
if
(
ret
>=
0
)
{
av_packet_rescale_ts
(
&
pkt
,
c
->
time_base
,
ost
->
st
->
time_base
);
av_packet_rescale_ts
(
&
pkt
,
c
->
time_base
,
ost
->
st
->
time_base
);
pkt
.
stream_index
=
ost
->
st
->
index
;
pkt
.
stream_index
=
ost
->
st
->
index
;
/* Write the compressed frame to the media file. */
/* Write the compressed frame to the media file. */
ret
=
av_interleaved_write_frame
(
oc
,
&
pkt
);
ret
=
av_interleaved_write_frame
(
oc
,
&
pkt
);
}
if
(
ret
<
0
)
{
if
(
ret
!=
0
)
{
fprintf
(
stderr
,
"Error while writing video frame
\n
"
);
fprintf
(
stderr
,
"Error while writing video frame
\n
"
);
exit
(
1
);
exit
(
1
);
}
}
}
}
return
(
frame
||
got_packet
)
?
0
:
1
;
return
ret
==
AVERROR_EOF
;
}
}
static
void
close_stream
(
AVFormatContext
*
oc
,
OutputStream
*
ost
)
static
void
close_stream
(
AVFormatContext
*
oc
,
OutputStream
*
ost
)
...
...
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