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
d72c742d
Commit
d72c742d
authored
Jan 19, 2014
by
Stefano Sabatini
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
examples/muxing: factorize write_interleave code
Also log output packet information.
parent
5e2b8e49
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
17 deletions
+28
-17
muxing.c
doc/examples/muxing.c
+28
-17
No files found.
doc/examples/muxing.c
View file @
d72c742d
...
...
@@ -36,6 +36,7 @@
#include <libavutil/opt.h>
#include <libavutil/mathematics.h>
#include <libavutil/timestamp.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
#include <libswresample/swresample.h>
...
...
@@ -48,6 +49,30 @@
static
int
sws_flags
=
SWS_BICUBIC
;
static
void
log_packet
(
const
AVFormatContext
*
fmt_ctx
,
const
AVPacket
*
pkt
)
{
AVRational
*
time_base
=
&
fmt_ctx
->
streams
[
pkt
->
stream_index
]
->
time_base
;
printf
(
"pts:%s pts_time:%s dts:%s dts_time:%s duration:%s duration_time:%s stream_index:%d
\n
"
,
av_ts2str
(
pkt
->
pts
),
av_ts2timestr
(
pkt
->
pts
,
time_base
),
av_ts2str
(
pkt
->
dts
),
av_ts2timestr
(
pkt
->
dts
,
time_base
),
av_ts2str
(
pkt
->
duration
),
av_ts2timestr
(
pkt
->
duration
,
time_base
),
pkt
->
stream_index
);
}
static
int
write_frame
(
AVFormatContext
*
fmt_ctx
,
const
AVRational
*
time_base
,
AVStream
*
st
,
AVPacket
*
pkt
)
{
/* rescale output packet timestamp values from codec to stream timebase */
pkt
->
pts
=
av_rescale_q_rnd
(
pkt
->
pts
,
*
time_base
,
st
->
time_base
,
AV_ROUND_NEAR_INF
|
AV_ROUND_PASS_MINMAX
);
pkt
->
dts
=
av_rescale_q_rnd
(
pkt
->
dts
,
*
time_base
,
st
->
time_base
,
AV_ROUND_NEAR_INF
|
AV_ROUND_PASS_MINMAX
);
pkt
->
duration
=
av_rescale_q
(
pkt
->
duration
,
*
time_base
,
st
->
time_base
);
pkt
->
stream_index
=
st
->
index
;
/* Write the compressed frame to the media file. */
log_packet
(
fmt_ctx
,
pkt
);
return
av_interleaved_write_frame
(
fmt_ctx
,
pkt
);
}
/* Add an output stream. */
static
AVStream
*
add_stream
(
AVFormatContext
*
oc
,
AVCodec
**
codec
,
enum
AVCodecID
codec_id
)
...
...
@@ -284,14 +309,7 @@ static void write_audio_frame(AVFormatContext *oc, AVStream *st)
if
(
!
got_packet
)
return
;
/* rescale output packet timestamp values from codec to stream timebase */
pkt
.
pts
=
av_rescale_q_rnd
(
pkt
.
pts
,
c
->
time_base
,
st
->
time_base
,
AV_ROUND_NEAR_INF
|
AV_ROUND_PASS_MINMAX
);
pkt
.
dts
=
av_rescale_q_rnd
(
pkt
.
dts
,
c
->
time_base
,
st
->
time_base
,
AV_ROUND_NEAR_INF
|
AV_ROUND_PASS_MINMAX
);
pkt
.
duration
=
av_rescale_q
(
pkt
.
duration
,
c
->
time_base
,
st
->
time_base
);
pkt
.
stream_index
=
st
->
index
;
/* Write the compressed frame to the media file. */
ret
=
av_interleaved_write_frame
(
oc
,
&
pkt
);
ret
=
write_frame
(
oc
,
&
c
->
time_base
,
st
,
&
pkt
);
if
(
ret
!=
0
)
{
fprintf
(
stderr
,
"Error while writing audio frame: %s
\n
"
,
av_err2str
(
ret
));
...
...
@@ -443,15 +461,8 @@ static void write_video_frame(AVFormatContext *oc, AVStream *st)
}
/* If size is zero, it means the image was buffered. */
if
(
!
ret
&&
got_packet
&&
pkt
.
size
)
{
/* rescale output packet timestamp values from codec to stream timebase */
pkt
.
pts
=
av_rescale_q_rnd
(
pkt
.
pts
,
c
->
time_base
,
st
->
time_base
,
AV_ROUND_NEAR_INF
|
AV_ROUND_PASS_MINMAX
);
pkt
.
dts
=
av_rescale_q_rnd
(
pkt
.
dts
,
c
->
time_base
,
st
->
time_base
,
AV_ROUND_NEAR_INF
|
AV_ROUND_PASS_MINMAX
);
pkt
.
duration
=
av_rescale_q
(
pkt
.
duration
,
c
->
time_base
,
st
->
time_base
);
pkt
.
stream_index
=
st
->
index
;
/* Write the compressed frame to the media file. */
ret
=
av_interleaved_write_frame
(
oc
,
&
pkt
);
if
(
got_packet
)
{
ret
=
write_frame
(
oc
,
&
c
->
time_base
,
st
,
&
pkt
);
}
else
{
ret
=
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