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
4a946aca
Commit
4a946aca
authored
Mar 28, 2017
by
Matthieu Bouron
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
doc/examples/remuxing: switch to codecpar
Also limits remuxing to audio, video and subtitle streams.
parent
7e3e0f87
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
7 deletions
+35
-7
remuxing.c
doc/examples/remuxing.c
+35
-7
No files found.
doc/examples/remuxing.c
View file @
4a946aca
...
...
@@ -50,6 +50,9 @@ int main(int argc, char **argv)
AVPacket
pkt
;
const
char
*
in_filename
,
*
out_filename
;
int
ret
,
i
;
int
stream_index
=
0
;
int
*
stream_mapping
=
NULL
;
int
stream_mapping_size
=
0
;
if
(
argc
<
3
)
{
printf
(
"usage: %s input output
\n
"
...
...
@@ -83,25 +86,42 @@ int main(int argc, char **argv)
goto
end
;
}
stream_mapping_size
=
ifmt_ctx
->
nb_streams
;
stream_mapping
=
av_mallocz_array
(
stream_mapping_size
,
sizeof
(
*
stream_mapping
));
if
(
!
stream_mapping
)
{
ret
=
AVERROR
(
ENOMEM
);
goto
end
;
}
ofmt
=
ofmt_ctx
->
oformat
;
for
(
i
=
0
;
i
<
ifmt_ctx
->
nb_streams
;
i
++
)
{
AVStream
*
out_stream
;
AVStream
*
in_stream
=
ifmt_ctx
->
streams
[
i
];
AVStream
*
out_stream
=
avformat_new_stream
(
ofmt_ctx
,
in_stream
->
codec
->
codec
);
AVCodecParameters
*
in_codecpar
=
in_stream
->
codecpar
;
if
(
in_codecpar
->
codec_type
!=
AVMEDIA_TYPE_AUDIO
&&
in_codecpar
->
codec_type
!=
AVMEDIA_TYPE_VIDEO
&&
in_codecpar
->
codec_type
!=
AVMEDIA_TYPE_SUBTITLE
)
{
stream_mapping
[
i
]
=
-
1
;
continue
;
}
stream_mapping
[
i
]
=
stream_index
++
;
out_stream
=
avformat_new_stream
(
ofmt_ctx
,
NULL
);
if
(
!
out_stream
)
{
fprintf
(
stderr
,
"Failed allocating output stream
\n
"
);
ret
=
AVERROR_UNKNOWN
;
goto
end
;
}
ret
=
avcodec_
copy_context
(
out_stream
->
codec
,
in_stream
->
codec
);
ret
=
avcodec_
parameters_copy
(
out_stream
->
codecpar
,
in_codecpar
);
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"Failed to copy co
ntext from input to output stream codec context
\n
"
);
fprintf
(
stderr
,
"Failed to copy co
dec parameters
\n
"
);
goto
end
;
}
out_stream
->
codec
->
codec_tag
=
0
;
if
(
ofmt_ctx
->
oformat
->
flags
&
AVFMT_GLOBALHEADER
)
out_stream
->
codec
->
flags
|=
AV_CODEC_FLAG_GLOBAL_HEADER
;
out_stream
->
codecpar
->
codec_tag
=
0
;
}
av_dump_format
(
ofmt_ctx
,
0
,
out_filename
,
1
);
...
...
@@ -127,8 +147,14 @@ int main(int argc, char **argv)
break
;
in_stream
=
ifmt_ctx
->
streams
[
pkt
.
stream_index
];
out_stream
=
ofmt_ctx
->
streams
[
pkt
.
stream_index
];
if
(
pkt
.
stream_index
>=
stream_mapping_size
||
stream_mapping
[
pkt
.
stream_index
]
<
0
)
{
av_packet_unref
(
&
pkt
);
continue
;
}
pkt
.
stream_index
=
stream_mapping
[
pkt
.
stream_index
];
out_stream
=
ofmt_ctx
->
streams
[
pkt
.
stream_index
];
log_packet
(
ifmt_ctx
,
&
pkt
,
"in"
);
/* copy packet */
...
...
@@ -156,6 +182,8 @@ end:
avio_closep
(
&
ofmt_ctx
->
pb
);
avformat_free_context
(
ofmt_ctx
);
av_freep
(
&
stream_mapping
);
if
(
ret
<
0
&&
ret
!=
AVERROR_EOF
)
{
fprintf
(
stderr
,
"Error occurred: %s
\n
"
,
av_err2str
(
ret
));
return
1
;
...
...
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