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
5f102a95
Commit
5f102a95
authored
Oct 20, 2016
by
Anton Khirnov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
examples/encode_video: switch to the new encoding API
parent
fee0f1de
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
28 deletions
+31
-28
encode_video.c
doc/examples/encode_video.c
+31
-28
No files found.
doc/examples/encode_video.c
View file @
5f102a95
...
...
@@ -34,12 +34,39 @@
#include "libavutil/frame.h"
#include "libavutil/imgutils.h"
static
void
encode
(
AVCodecContext
*
enc_ctx
,
AVFrame
*
frame
,
AVPacket
*
pkt
,
FILE
*
outfile
)
{
int
ret
;
/* send the frame to the encoder */
ret
=
avcodec_send_frame
(
enc_ctx
,
frame
);
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"error sending a frame for encoding
\n
"
);
exit
(
1
);
}
while
(
ret
>=
0
)
{
ret
=
avcodec_receive_packet
(
enc_ctx
,
pkt
);
if
(
ret
==
AVERROR
(
EAGAIN
)
||
ret
==
AVERROR_EOF
)
return
;
else
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"error during encoding
\n
"
);
exit
(
1
);
}
printf
(
"encoded frame %3"
PRId64
" (size=%5d)
\n
"
,
pkt
->
pts
,
pkt
->
size
);
fwrite
(
pkt
->
data
,
1
,
pkt
->
size
,
outfile
);
av_packet_unref
(
pkt
);
}
}
int
main
(
int
argc
,
char
**
argv
)
{
const
char
*
filename
;
const
AVCodec
*
codec
;
AVCodecContext
*
c
=
NULL
;
int
i
,
ret
,
x
,
y
,
got_output
;
int
i
,
ret
,
x
,
y
;
FILE
*
f
;
AVFrame
*
picture
;
AVPacket
pkt
;
...
...
@@ -130,35 +157,11 @@ int main(int argc, char **argv)
picture
->
pts
=
i
;
/* encode the image */
ret
=
avcodec_encode_video2
(
c
,
&
pkt
,
picture
,
&
got_output
);
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"error encoding frame
\n
"
);
exit
(
1
);
}
if
(
got_output
)
{
printf
(
"encoding frame %3d (size=%5d)
\n
"
,
i
,
pkt
.
size
);
fwrite
(
pkt
.
data
,
1
,
pkt
.
size
,
f
);
av_packet_unref
(
&
pkt
);
}
encode
(
c
,
picture
,
&
pkt
,
f
);
}
/* get the delayed frames */
for
(
got_output
=
1
;
got_output
;
i
++
)
{
fflush
(
stdout
);
ret
=
avcodec_encode_video2
(
c
,
&
pkt
,
NULL
,
&
got_output
);
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"error encoding frame
\n
"
);
exit
(
1
);
}
if
(
got_output
)
{
printf
(
"encoding frame %3d (size=%5d)
\n
"
,
i
,
pkt
.
size
);
fwrite
(
pkt
.
data
,
1
,
pkt
.
size
,
f
);
av_packet_unref
(
&
pkt
);
}
}
/* flush the encoder */
encode
(
c
,
NULL
,
&
pkt
,
f
);
/* add sequence end code to have a real MPEG file */
fwrite
(
endcode
,
1
,
sizeof
(
endcode
),
f
);
...
...
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