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
4f8262e3
Commit
4f8262e3
authored
Oct 01, 2016
by
wm4
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ffmpeg: use new encode API
parent
8f6f2322
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
25 deletions
+46
-25
ffmpeg.c
ffmpeg.c
+46
-25
No files found.
ffmpeg.c
View file @
4f8262e3
...
@@ -830,7 +830,7 @@ static void do_audio_out(AVFormatContext *s, OutputStream *ost,
...
@@ -830,7 +830,7 @@ static void do_audio_out(AVFormatContext *s, OutputStream *ost,
{
{
AVCodecContext
*
enc
=
ost
->
enc_ctx
;
AVCodecContext
*
enc
=
ost
->
enc_ctx
;
AVPacket
pkt
;
AVPacket
pkt
;
int
got_packet
=
0
;
int
ret
;
av_init_packet
(
&
pkt
);
av_init_packet
(
&
pkt
);
pkt
.
data
=
NULL
;
pkt
.
data
=
NULL
;
...
@@ -854,13 +854,19 @@ static void do_audio_out(AVFormatContext *s, OutputStream *ost,
...
@@ -854,13 +854,19 @@ static void do_audio_out(AVFormatContext *s, OutputStream *ost,
enc
->
time_base
.
num
,
enc
->
time_base
.
den
);
enc
->
time_base
.
num
,
enc
->
time_base
.
den
);
}
}
if
(
avcodec_encode_audio2
(
enc
,
&
pkt
,
frame
,
&
got_packet
)
<
0
)
{
ret
=
avcodec_send_frame
(
enc
,
frame
);
av_log
(
NULL
,
AV_LOG_FATAL
,
"Audio encoding failed (avcodec_encode_audio2)
\n
"
);
if
(
ret
<
0
)
exit_program
(
1
);
goto
error
;
}
while
(
1
)
{
ret
=
avcodec_receive_packet
(
enc
,
&
pkt
);
if
(
ret
==
AVERROR
(
EAGAIN
))
break
;
if
(
ret
<
0
)
goto
error
;
update_benchmark
(
"encode_audio %d.%d"
,
ost
->
file_index
,
ost
->
index
);
update_benchmark
(
"encode_audio %d.%d"
,
ost
->
file_index
,
ost
->
index
);
if
(
got_packet
)
{
av_packet_rescale_ts
(
&
pkt
,
enc
->
time_base
,
ost
->
st
->
time_base
);
av_packet_rescale_ts
(
&
pkt
,
enc
->
time_base
,
ost
->
st
->
time_base
);
if
(
debug_ts
)
{
if
(
debug_ts
)
{
...
@@ -872,6 +878,11 @@ static void do_audio_out(AVFormatContext *s, OutputStream *ost,
...
@@ -872,6 +878,11 @@ static void do_audio_out(AVFormatContext *s, OutputStream *ost,
output_packet
(
s
,
&
pkt
,
ost
);
output_packet
(
s
,
&
pkt
,
ost
);
}
}
return
;
error:
av_log
(
NULL
,
AV_LOG_FATAL
,
"Audio encoding failed
\n
"
);
exit_program
(
1
);
}
}
static
void
do_subtitle_out
(
AVFormatContext
*
s
,
static
void
do_subtitle_out
(
AVFormatContext
*
s
,
...
@@ -1139,7 +1150,7 @@ static void do_video_out(AVFormatContext *s,
...
@@ -1139,7 +1150,7 @@ static void do_video_out(AVFormatContext *s,
}
else
}
else
#endif
#endif
{
{
int
got_packet
,
forced_keyframe
=
0
;
int
forced_keyframe
=
0
;
double
pts_time
;
double
pts_time
;
if
(
enc
->
flags
&
(
AV_CODEC_FLAG_INTERLACED_DCT
|
AV_CODEC_FLAG_INTERLACED_ME
)
&&
if
(
enc
->
flags
&
(
AV_CODEC_FLAG_INTERLACED_DCT
|
AV_CODEC_FLAG_INTERLACED_ME
)
&&
...
@@ -1206,14 +1217,18 @@ static void do_video_out(AVFormatContext *s,
...
@@ -1206,14 +1217,18 @@ static void do_video_out(AVFormatContext *s,
ost
->
frames_encoded
++
;
ost
->
frames_encoded
++
;
ret
=
avcodec_encode_video2
(
enc
,
&
pkt
,
in_picture
,
&
got_packet
);
ret
=
avcodec_send_frame
(
enc
,
in_picture
);
if
(
ret
<
0
)
goto
error
;
while
(
1
)
{
ret
=
avcodec_receive_packet
(
enc
,
&
pkt
);
update_benchmark
(
"encode_video %d.%d"
,
ost
->
file_index
,
ost
->
index
);
update_benchmark
(
"encode_video %d.%d"
,
ost
->
file_index
,
ost
->
index
);
if
(
ret
<
0
)
{
if
(
ret
==
AVERROR
(
EAGAIN
))
av_log
(
NULL
,
AV_LOG_FATAL
,
"Video encoding failed
\n
"
)
;
break
;
exit_program
(
1
);
if
(
ret
<
0
)
}
goto
error
;
if
(
got_packet
)
{
if
(
debug_ts
)
{
if
(
debug_ts
)
{
av_log
(
NULL
,
AV_LOG_INFO
,
"encoder -> type:video "
av_log
(
NULL
,
AV_LOG_INFO
,
"encoder -> type:video "
"pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s
\n
"
,
"pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s
\n
"
,
...
@@ -1261,6 +1276,11 @@ static void do_video_out(AVFormatContext *s,
...
@@ -1261,6 +1276,11 @@ static void do_video_out(AVFormatContext *s,
av_frame_ref
(
ost
->
last_frame
,
next_picture
);
av_frame_ref
(
ost
->
last_frame
,
next_picture
);
else
else
av_frame_free
(
&
ost
->
last_frame
);
av_frame_free
(
&
ost
->
last_frame
);
return
;
error:
av_log
(
NULL
,
AV_LOG_FATAL
,
"Video encoding failed
\n
"
);
exit_program
(
1
);
}
}
static
double
psnr
(
double
d
)
static
double
psnr
(
double
d
)
...
@@ -1749,35 +1769,36 @@ static void flush_encoders(void)
...
@@ -1749,35 +1769,36 @@ static void flush_encoders(void)
continue
;
continue
;
#endif
#endif
if
(
enc
->
codec_type
!=
AVMEDIA_TYPE_VIDEO
&&
enc
->
codec_type
!=
AVMEDIA_TYPE_AUDIO
)
continue
;
avcodec_send_frame
(
enc
,
NULL
);
for
(;;)
{
for
(;;)
{
int
(
*
encode
)(
AVCodecContext
*
,
AVPacket
*
,
const
AVFrame
*
,
int
*
)
=
NULL
;
const
char
*
desc
=
NULL
;
const
char
*
desc
;
switch
(
enc
->
codec_type
)
{
switch
(
enc
->
codec_type
)
{
case
AVMEDIA_TYPE_AUDIO
:
case
AVMEDIA_TYPE_AUDIO
:
encode
=
avcodec_encode_audio2
;
desc
=
"audio"
;
desc
=
"audio"
;
break
;
break
;
case
AVMEDIA_TYPE_VIDEO
:
case
AVMEDIA_TYPE_VIDEO
:
encode
=
avcodec_encode_video2
;
desc
=
"video"
;
desc
=
"video"
;
break
;
break
;
default:
default:
stop_encoding
=
1
;
av_assert0
(
0
)
;
}
}
if
(
encode
)
{
if
(
1
)
{
AVPacket
pkt
;
AVPacket
pkt
;
int
pkt_size
;
int
pkt_size
;
int
got_packet
;
av_init_packet
(
&
pkt
);
av_init_packet
(
&
pkt
);
pkt
.
data
=
NULL
;
pkt
.
data
=
NULL
;
pkt
.
size
=
0
;
pkt
.
size
=
0
;
update_benchmark
(
NULL
);
update_benchmark
(
NULL
);
ret
=
encode
(
enc
,
&
pkt
,
NULL
,
&
got_packe
t
);
ret
=
avcodec_receive_packet
(
enc
,
&
pk
t
);
update_benchmark
(
"flush_%s %d.%d"
,
desc
,
ost
->
file_index
,
ost
->
index
);
update_benchmark
(
"flush_%s %d.%d"
,
desc
,
ost
->
file_index
,
ost
->
index
);
if
(
ret
<
0
)
{
if
(
ret
<
0
&&
ret
!=
AVERROR_EOF
)
{
av_log
(
NULL
,
AV_LOG_FATAL
,
"%s encoding failed: %s
\n
"
,
av_log
(
NULL
,
AV_LOG_FATAL
,
"%s encoding failed: %s
\n
"
,
desc
,
desc
,
av_err2str
(
ret
));
av_err2str
(
ret
));
...
@@ -1786,7 +1807,7 @@ static void flush_encoders(void)
...
@@ -1786,7 +1807,7 @@ static void flush_encoders(void)
if
(
ost
->
logfile
&&
enc
->
stats_out
)
{
if
(
ost
->
logfile
&&
enc
->
stats_out
)
{
fprintf
(
ost
->
logfile
,
"%s"
,
enc
->
stats_out
);
fprintf
(
ost
->
logfile
,
"%s"
,
enc
->
stats_out
);
}
}
if
(
!
got_packet
)
{
if
(
ret
==
AVERROR_EOF
)
{
stop_encoding
=
1
;
stop_encoding
=
1
;
break
;
break
;
}
}
...
...
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