Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
F
ffmpeg
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
ffmpeg
Commits
59ab9e8b
Commit
59ab9e8b
authored
Oct 20, 2016
by
Anton Khirnov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
examples/encode_video: allocate the packet dynamically
AVPackets on stack are discouraged.
parent
5f102a95
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
7 deletions
+8
-7
encode_video.c
doc/examples/encode_video.c
+8
-7
No files found.
doc/examples/encode_video.c
View file @
59ab9e8b
...
@@ -69,7 +69,7 @@ int main(int argc, char **argv)
...
@@ -69,7 +69,7 @@ int main(int argc, char **argv)
int
i
,
ret
,
x
,
y
;
int
i
,
ret
,
x
,
y
;
FILE
*
f
;
FILE
*
f
;
AVFrame
*
picture
;
AVFrame
*
picture
;
AVPacket
pkt
;
AVPacket
*
pkt
;
uint8_t
endcode
[]
=
{
0
,
0
,
1
,
0xb7
};
uint8_t
endcode
[]
=
{
0
,
0
,
1
,
0xb7
};
if
(
argc
<=
1
)
{
if
(
argc
<=
1
)
{
...
@@ -90,6 +90,10 @@ int main(int argc, char **argv)
...
@@ -90,6 +90,10 @@ int main(int argc, char **argv)
c
=
avcodec_alloc_context3
(
codec
);
c
=
avcodec_alloc_context3
(
codec
);
picture
=
av_frame_alloc
();
picture
=
av_frame_alloc
();
pkt
=
av_packet_alloc
();
if
(
!
pkt
)
exit
(
1
);
/* put sample parameters */
/* put sample parameters */
c
->
bit_rate
=
400000
;
c
->
bit_rate
=
400000
;
/* resolution must be a multiple of two */
/* resolution must be a multiple of two */
...
@@ -127,10 +131,6 @@ int main(int argc, char **argv)
...
@@ -127,10 +131,6 @@ int main(int argc, char **argv)
/* encode 1 second of video */
/* encode 1 second of video */
for
(
i
=
0
;
i
<
25
;
i
++
)
{
for
(
i
=
0
;
i
<
25
;
i
++
)
{
av_init_packet
(
&
pkt
);
pkt
.
data
=
NULL
;
// packet data will be allocated by the encoder
pkt
.
size
=
0
;
fflush
(
stdout
);
fflush
(
stdout
);
/* make sure the frame data is writable */
/* make sure the frame data is writable */
...
@@ -157,11 +157,11 @@ int main(int argc, char **argv)
...
@@ -157,11 +157,11 @@ int main(int argc, char **argv)
picture
->
pts
=
i
;
picture
->
pts
=
i
;
/* encode the image */
/* encode the image */
encode
(
c
,
picture
,
&
pkt
,
f
);
encode
(
c
,
picture
,
pkt
,
f
);
}
}
/* flush the encoder */
/* flush the encoder */
encode
(
c
,
NULL
,
&
pkt
,
f
);
encode
(
c
,
NULL
,
pkt
,
f
);
/* add sequence end code to have a real MPEG file */
/* add sequence end code to have a real MPEG file */
fwrite
(
endcode
,
1
,
sizeof
(
endcode
),
f
);
fwrite
(
endcode
,
1
,
sizeof
(
endcode
),
f
);
...
@@ -169,6 +169,7 @@ int main(int argc, char **argv)
...
@@ -169,6 +169,7 @@ int main(int argc, char **argv)
avcodec_free_context
(
&
c
);
avcodec_free_context
(
&
c
);
av_frame_free
(
&
picture
);
av_frame_free
(
&
picture
);
av_packet_free
(
&
pkt
);
return
0
;
return
0
;
}
}
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