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
ef74e397
Commit
ef74e397
authored
Oct 20, 2011
by
Justin Ruggles
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
flvenc: store delay and last_ts per-stream.
parent
b034c95c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
12 deletions
+22
-12
flvenc.c
libavformat/flvenc.c
+22
-12
No files found.
libavformat/flvenc.c
View file @
ef74e397
...
...
@@ -57,10 +57,13 @@ typedef struct FLVContext {
int64_t
duration_offset
;
int64_t
filesize_offset
;
int64_t
duration
;
int
delay
;
///< first dts delay for AVC
int64_t
last_ts
;
}
FLVContext
;
typedef
struct
FLVStreamContext
{
int
delay
;
///< first dts delay for each stream (needed for AVC & Speex)
int64_t
last_ts
;
///< last timestamp for each stream
}
FLVStreamContext
;
static
int
get_audio_flags
(
AVCodecContext
*
enc
){
int
flags
=
(
enc
->
bits_per_coded_sample
==
16
)
?
FLV_SAMPLESSIZE_16BIT
:
FLV_SAMPLESSIZE_8BIT
;
...
...
@@ -179,6 +182,7 @@ static int flv_write_header(AVFormatContext *s)
for
(
i
=
0
;
i
<
s
->
nb_streams
;
i
++
){
AVCodecContext
*
enc
=
s
->
streams
[
i
]
->
codec
;
FLVStreamContext
*
sc
;
if
(
enc
->
codec_type
==
AVMEDIA_TYPE_VIDEO
)
{
if
(
s
->
streams
[
i
]
->
r_frame_rate
.
den
&&
s
->
streams
[
i
]
->
r_frame_rate
.
num
)
{
framerate
=
av_q2d
(
s
->
streams
[
i
]
->
r_frame_rate
);
...
...
@@ -196,6 +200,12 @@ static int flv_write_header(AVFormatContext *s)
return
-
1
;
}
av_set_pts_info
(
s
->
streams
[
i
],
32
,
1
,
1000
);
/* 32 bit pts in ms */
sc
=
av_mallocz
(
sizeof
(
FLVStreamContext
));
if
(
!
sc
)
return
AVERROR
(
ENOMEM
);
s
->
streams
[
i
]
->
priv_data
=
sc
;
sc
->
last_ts
=
-
1
;
}
avio_write
(
pb
,
"FLV"
,
3
);
avio_w8
(
pb
,
1
);
...
...
@@ -215,8 +225,6 @@ static int flv_write_header(AVFormatContext *s)
}
}
flv
->
last_ts
=
-
1
;
/* write meta_tag */
avio_w8
(
pb
,
18
);
// tag type META
metadata_size_pos
=
avio_tell
(
pb
);
...
...
@@ -342,9 +350,10 @@ static int flv_write_trailer(AVFormatContext *s)
/* Add EOS tag */
for
(
i
=
0
;
i
<
s
->
nb_streams
;
i
++
)
{
AVCodecContext
*
enc
=
s
->
streams
[
i
]
->
codec
;
FLVStreamContext
*
sc
=
s
->
streams
[
i
]
->
priv_data
;
if
(
enc
->
codec_type
==
AVMEDIA_TYPE_VIDEO
&&
enc
->
codec_id
==
CODEC_ID_H264
)
{
put_avc_eos_tag
(
pb
,
flv
->
last_ts
);
put_avc_eos_tag
(
pb
,
sc
->
last_ts
);
}
}
...
...
@@ -365,6 +374,7 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt)
AVIOContext
*
pb
=
s
->
pb
;
AVCodecContext
*
enc
=
s
->
streams
[
pkt
->
stream_index
]
->
codec
;
FLVContext
*
flv
=
s
->
priv_data
;
FLVStreamContext
*
sc
=
s
->
streams
[
pkt
->
stream_index
]
->
priv_data
;
unsigned
ts
;
int
size
=
pkt
->
size
;
uint8_t
*
data
=
NULL
;
...
...
@@ -406,20 +416,20 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt)
return
-
1
;
}
}
if
(
!
flv
->
delay
&&
pkt
->
dts
<
0
)
flv
->
delay
=
-
pkt
->
dts
;
if
(
!
sc
->
delay
&&
pkt
->
dts
<
0
)
sc
->
delay
=
-
pkt
->
dts
;
ts
=
pkt
->
dts
+
flv
->
delay
;
// add delay to force positive dts
ts
=
pkt
->
dts
+
sc
->
delay
;
// add delay to force positive dts
/* check Speex packet duration */
if
(
enc
->
codec_id
==
CODEC_ID_SPEEX
&&
ts
-
flv
->
last_ts
>
160
)
{
if
(
enc
->
codec_id
==
CODEC_ID_SPEEX
&&
ts
-
sc
->
last_ts
>
160
)
{
av_log
(
s
,
AV_LOG_WARNING
,
"Warning: Speex stream has more than "
"8 frames per packet. Adobe Flash "
"Player cannot handle this!
\n
"
);
}
if
(
flv
->
last_ts
<
ts
)
flv
->
last_ts
=
ts
;
if
(
sc
->
last_ts
<
ts
)
sc
->
last_ts
=
ts
;
avio_wb24
(
pb
,
size
+
flags_size
);
avio_wb24
(
pb
,
ts
);
...
...
@@ -440,7 +450,7 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt)
avio_write
(
pb
,
data
?
data
:
pkt
->
data
,
size
);
avio_wb32
(
pb
,
size
+
flags_size
+
11
);
// previous tag size
flv
->
duration
=
FFMAX
(
flv
->
duration
,
pkt
->
pts
+
flv
->
delay
+
pkt
->
duration
);
flv
->
duration
=
FFMAX
(
flv
->
duration
,
pkt
->
pts
+
sc
->
delay
+
pkt
->
duration
);
avio_flush
(
pb
);
...
...
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