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
bba6a03b
Commit
bba6a03b
authored
Aug 10, 2016
by
James Almer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
examples/demuxing_decoding: convert to codecpar
Signed-off-by:
James Almer
<
jamrial@gmail.com
>
parent
b72a7b96
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
11 deletions
+22
-11
demuxing_decoding.c
doc/examples/demuxing_decoding.c
+22
-11
No files found.
doc/examples/demuxing_decoding.c
View file @
bba6a03b
...
@@ -148,11 +148,10 @@ static int decode_packet(int *got_frame, int cached)
...
@@ -148,11 +148,10 @@ static int decode_packet(int *got_frame, int cached)
}
}
static
int
open_codec_context
(
int
*
stream_idx
,
static
int
open_codec_context
(
int
*
stream_idx
,
AVFormatContext
*
fmt_ctx
,
enum
AVMediaType
type
)
AV
CodecContext
**
dec_ctx
,
AV
FormatContext
*
fmt_ctx
,
enum
AVMediaType
type
)
{
{
int
ret
,
stream_index
;
int
ret
,
stream_index
;
AVStream
*
st
;
AVStream
*
st
;
AVCodecContext
*
dec_ctx
=
NULL
;
AVCodec
*
dec
=
NULL
;
AVCodec
*
dec
=
NULL
;
AVDictionary
*
opts
=
NULL
;
AVDictionary
*
opts
=
NULL
;
...
@@ -166,17 +165,31 @@ static int open_codec_context(int *stream_idx,
...
@@ -166,17 +165,31 @@ static int open_codec_context(int *stream_idx,
st
=
fmt_ctx
->
streams
[
stream_index
];
st
=
fmt_ctx
->
streams
[
stream_index
];
/* find decoder for the stream */
/* find decoder for the stream */
dec_ctx
=
st
->
codec
;
dec
=
avcodec_find_decoder
(
st
->
codecpar
->
codec_id
);
dec
=
avcodec_find_decoder
(
dec_ctx
->
codec_id
);
if
(
!
dec
)
{
if
(
!
dec
)
{
fprintf
(
stderr
,
"Failed to find %s codec
\n
"
,
fprintf
(
stderr
,
"Failed to find %s codec
\n
"
,
av_get_media_type_string
(
type
));
av_get_media_type_string
(
type
));
return
AVERROR
(
EINVAL
);
return
AVERROR
(
EINVAL
);
}
}
/* Allocate a codec context for the decoder */
*
dec_ctx
=
avcodec_alloc_context3
(
dec
);
if
(
!*
dec_ctx
)
{
fprintf
(
stderr
,
"Failed to allocate the %s codec context
\n
"
,
av_get_media_type_string
(
type
));
return
AVERROR
(
ENOMEM
);
}
/* Copy codec parameters from input stream to output codec context */
if
((
ret
=
avcodec_parameters_to_context
(
*
dec_ctx
,
st
->
codecpar
))
<
0
)
{
fprintf
(
stderr
,
"Failed to copy %s codec parameters to decoder context
\n
"
,
av_get_media_type_string
(
type
));
return
ret
;
}
/* Init the decoders, with or without reference counting */
/* Init the decoders, with or without reference counting */
av_dict_set
(
&
opts
,
"refcounted_frames"
,
refcount
?
"1"
:
"0"
,
0
);
av_dict_set
(
&
opts
,
"refcounted_frames"
,
refcount
?
"1"
:
"0"
,
0
);
if
((
ret
=
avcodec_open2
(
dec_ctx
,
dec
,
&
opts
))
<
0
)
{
if
((
ret
=
avcodec_open2
(
*
dec_ctx
,
dec
,
&
opts
))
<
0
)
{
fprintf
(
stderr
,
"Failed to open %s codec
\n
"
,
fprintf
(
stderr
,
"Failed to open %s codec
\n
"
,
av_get_media_type_string
(
type
));
av_get_media_type_string
(
type
));
return
ret
;
return
ret
;
...
@@ -255,9 +268,8 @@ int main (int argc, char **argv)
...
@@ -255,9 +268,8 @@ int main (int argc, char **argv)
exit
(
1
);
exit
(
1
);
}
}
if
(
open_codec_context
(
&
video_stream_idx
,
fmt_ctx
,
AVMEDIA_TYPE_VIDEO
)
>=
0
)
{
if
(
open_codec_context
(
&
video_stream_idx
,
&
video_dec_ctx
,
fmt_ctx
,
AVMEDIA_TYPE_VIDEO
)
>=
0
)
{
video_stream
=
fmt_ctx
->
streams
[
video_stream_idx
];
video_stream
=
fmt_ctx
->
streams
[
video_stream_idx
];
video_dec_ctx
=
video_stream
->
codec
;
video_dst_file
=
fopen
(
video_dst_filename
,
"wb"
);
video_dst_file
=
fopen
(
video_dst_filename
,
"wb"
);
if
(
!
video_dst_file
)
{
if
(
!
video_dst_file
)
{
...
@@ -279,9 +291,8 @@ int main (int argc, char **argv)
...
@@ -279,9 +291,8 @@ int main (int argc, char **argv)
video_dst_bufsize
=
ret
;
video_dst_bufsize
=
ret
;
}
}
if
(
open_codec_context
(
&
audio_stream_idx
,
fmt_ctx
,
AVMEDIA_TYPE_AUDIO
)
>=
0
)
{
if
(
open_codec_context
(
&
audio_stream_idx
,
&
audio_dec_ctx
,
fmt_ctx
,
AVMEDIA_TYPE_AUDIO
)
>=
0
)
{
audio_stream
=
fmt_ctx
->
streams
[
audio_stream_idx
];
audio_stream
=
fmt_ctx
->
streams
[
audio_stream_idx
];
audio_dec_ctx
=
audio_stream
->
codec
;
audio_dst_file
=
fopen
(
audio_dst_filename
,
"wb"
);
audio_dst_file
=
fopen
(
audio_dst_filename
,
"wb"
);
if
(
!
audio_dst_file
)
{
if
(
!
audio_dst_file
)
{
fprintf
(
stderr
,
"Could not open destination file %s
\n
"
,
audio_dst_filename
);
fprintf
(
stderr
,
"Could not open destination file %s
\n
"
,
audio_dst_filename
);
...
@@ -369,8 +380,8 @@ int main (int argc, char **argv)
...
@@ -369,8 +380,8 @@ int main (int argc, char **argv)
}
}
end:
end:
avcodec_
close
(
video_dec_ctx
);
avcodec_
free_context
(
&
video_dec_ctx
);
avcodec_
close
(
audio_dec_ctx
);
avcodec_
free_context
(
&
audio_dec_ctx
);
avformat_close_input
(
&
fmt_ctx
);
avformat_close_input
(
&
fmt_ctx
);
if
(
video_dst_file
)
if
(
video_dst_file
)
fclose
(
video_dst_file
);
fclose
(
video_dst_file
);
...
...
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