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
64b55399
Commit
64b55399
authored
7 years ago
by
Matthieu Bouron
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
doc/examples/extract_mvs: switch to codecpar
parent
4a946aca
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
17 deletions
+20
-17
extract_mvs.c
doc/examples/extract_mvs.c
+20
-17
No files found.
doc/examples/extract_mvs.c
View file @
64b55399
...
@@ -69,8 +69,7 @@ static int decode_packet(int *got_frame, int cached)
...
@@ -69,8 +69,7 @@ static int decode_packet(int *got_frame, int cached)
return
decoded
;
return
decoded
;
}
}
static
int
open_codec_context
(
int
*
stream_idx
,
static
int
open_codec_context
(
AVFormatContext
*
fmt_ctx
,
enum
AVMediaType
type
)
AVFormatContext
*
fmt_ctx
,
enum
AVMediaType
type
)
{
{
int
ret
;
int
ret
;
AVStream
*
st
;
AVStream
*
st
;
...
@@ -78,24 +77,27 @@ static int open_codec_context(int *stream_idx,
...
@@ -78,24 +77,27 @@ static int open_codec_context(int *stream_idx,
AVCodec
*
dec
=
NULL
;
AVCodec
*
dec
=
NULL
;
AVDictionary
*
opts
=
NULL
;
AVDictionary
*
opts
=
NULL
;
ret
=
av_find_best_stream
(
fmt_ctx
,
type
,
-
1
,
-
1
,
NULL
,
0
);
ret
=
av_find_best_stream
(
fmt_ctx
,
type
,
-
1
,
-
1
,
&
dec
,
0
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"Could not find %s stream in input file '%s'
\n
"
,
fprintf
(
stderr
,
"Could not find %s stream in input file '%s'
\n
"
,
av_get_media_type_string
(
type
),
src_filename
);
av_get_media_type_string
(
type
),
src_filename
);
return
ret
;
return
ret
;
}
else
{
}
else
{
*
stream_idx
=
ret
;
int
stream_idx
=
ret
;
st
=
fmt_ctx
->
streams
[
*
stream_idx
];
st
=
fmt_ctx
->
streams
[
stream_idx
];
/* find decoder for the stream */
dec_ctx
=
avcodec_alloc_context3
(
dec
);
dec_ctx
=
st
->
codec
;
if
(
!
dec_ctx
)
{
dec
=
avcodec_find_decoder
(
dec_ctx
->
codec_id
);
fprintf
(
stderr
,
"Failed to allocate codec
\n
"
);
if
(
!
dec
)
{
fprintf
(
stderr
,
"Failed to find %s codec
\n
"
,
av_get_media_type_string
(
type
));
return
AVERROR
(
EINVAL
);
return
AVERROR
(
EINVAL
);
}
}
ret
=
avcodec_parameters_to_context
(
dec_ctx
,
st
->
codecpar
);
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"Failed to copy codec parameters to codec context
\n
"
);
return
ret
;
}
/* Init the video decoder */
/* Init the video decoder */
av_dict_set
(
&
opts
,
"flags2"
,
"+export_mvs"
,
0
);
av_dict_set
(
&
opts
,
"flags2"
,
"+export_mvs"
,
0
);
if
((
ret
=
avcodec_open2
(
dec_ctx
,
dec
,
&
opts
))
<
0
)
{
if
((
ret
=
avcodec_open2
(
dec_ctx
,
dec
,
&
opts
))
<
0
)
{
...
@@ -103,6 +105,10 @@ static int open_codec_context(int *stream_idx,
...
@@ -103,6 +105,10 @@ static int open_codec_context(int *stream_idx,
av_get_media_type_string
(
type
));
av_get_media_type_string
(
type
));
return
ret
;
return
ret
;
}
}
video_stream_idx
=
stream_idx
;
video_stream
=
fmt_ctx
->
streams
[
video_stream_idx
];
video_dec_ctx
=
dec_ctx
;
}
}
return
0
;
return
0
;
...
@@ -130,10 +136,7 @@ int main(int argc, char **argv)
...
@@ -130,10 +136,7 @@ int main(int argc, char **argv)
exit
(
1
);
exit
(
1
);
}
}
if
(
open_codec_context
(
&
video_stream_idx
,
fmt_ctx
,
AVMEDIA_TYPE_VIDEO
)
>=
0
)
{
open_codec_context
(
fmt_ctx
,
AVMEDIA_TYPE_VIDEO
);
video_stream
=
fmt_ctx
->
streams
[
video_stream_idx
];
video_dec_ctx
=
video_stream
->
codec
;
}
av_dump_format
(
fmt_ctx
,
0
,
src_filename
,
0
);
av_dump_format
(
fmt_ctx
,
0
,
src_filename
,
0
);
...
@@ -178,7 +181,7 @@ int main(int argc, char **argv)
...
@@ -178,7 +181,7 @@ int main(int argc, char **argv)
}
while
(
got_frame
);
}
while
(
got_frame
);
end:
end:
avcodec_
close
(
video_dec_ctx
);
avcodec_
free_context
(
&
video_dec_ctx
);
avformat_close_input
(
&
fmt_ctx
);
avformat_close_input
(
&
fmt_ctx
);
av_frame_free
(
&
frame
);
av_frame_free
(
&
frame
);
return
ret
<
0
;
return
ret
<
0
;
...
...
This diff is collapsed.
Click to expand it.
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