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
ebf94f43
Commit
ebf94f43
authored
Aug 30, 2011
by
Alex Converse
Committed by
Michael Niedermayer
Aug 30, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ffmpeg: Factorize video resampling.
parent
dadbebbb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
51 deletions
+60
-51
ffmpeg.c
ffmpeg.c
+60
-51
No files found.
ffmpeg.c
View file @
ebf94f43
...
...
@@ -1073,14 +1073,71 @@ static void do_subtitle_out(AVFormatContext *s,
static
int
bit_buffer_size
=
1024
*
256
;
static
uint8_t
*
bit_buffer
=
NULL
;
static
void
do_video_resample
(
OutputStream
*
ost
,
InputStream
*
ist
,
AVFrame
*
in_picture
,
AVFrame
**
out_picture
)
{
int
resample_changed
=
0
;
AVCodecContext
*
dec
=
ist
->
st
->
codec
;
*
out_picture
=
in_picture
;
#if !CONFIG_AVFILTER
resample_changed
=
ost
->
resample_width
!=
dec
->
width
||
ost
->
resample_height
!=
dec
->
height
||
ost
->
resample_pix_fmt
!=
dec
->
pix_fmt
;
if
(
resample_changed
)
{
av_log
(
NULL
,
AV_LOG_INFO
,
"Input stream #%d.%d frame changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s
\n
"
,
ist
->
file_index
,
ist
->
st
->
index
,
ost
->
resample_width
,
ost
->
resample_height
,
av_get_pix_fmt_name
(
ost
->
resample_pix_fmt
),
dec
->
width
,
dec
->
height
,
av_get_pix_fmt_name
(
dec
->
pix_fmt
));
ost
->
resample_width
=
dec
->
width
;
ost
->
resample_height
=
dec
->
height
;
ost
->
resample_pix_fmt
=
dec
->
pix_fmt
;
}
ost
->
video_resample
=
dec
->
width
!=
enc
->
width
||
dec
->
height
!=
enc
->
height
||
dec
->
pix_fmt
!=
enc
->
pix_fmt
;
if
(
ost
->
video_resample
)
{
*
out_picture
=
&
ost
->
resample_frame
;
if
(
!
ost
->
img_resample_ctx
||
resample_changed
)
{
/* initialize the destination picture */
if
(
!
ost
->
resample_frame
.
data
[
0
])
{
avcodec_get_frame_defaults
(
&
ost
->
resample_frame
);
if
(
avpicture_alloc
((
AVPicture
*
)
&
ost
->
resample_frame
,
enc
->
pix_fmt
,
enc
->
width
,
enc
->
height
))
{
fprintf
(
stderr
,
"Cannot allocate temp picture, check pix fmt
\n
"
);
exit_program
(
1
);
}
}
/* initialize a new scaler context */
sws_freeContext
(
ost
->
img_resample_ctx
);
ost
->
img_resample_ctx
=
sws_getContext
(
dec
->
width
,
dec
->
height
,
dec
->
pix_fmt
,
enc
->
width
,
enc
->
height
,
enc
->
pix_fmt
,
ost
->
sws_flags
,
NULL
,
NULL
,
NULL
);
if
(
ost
->
img_resample_ctx
==
NULL
)
{
fprintf
(
stderr
,
"Cannot get resampling context
\n
"
);
exit_program
(
1
);
}
}
sws_scale
(
ost
->
img_resample_ctx
,
in_picture
->
data
,
in_picture
->
linesize
,
0
,
ost
->
resample_height
,
(
*
out_picture
)
->
data
,
(
*
out_picture
)
->
linesize
);
}
#endif
}
static
void
do_video_out
(
AVFormatContext
*
s
,
OutputStream
*
ost
,
InputStream
*
ist
,
AVFrame
*
in_picture
,
int
*
frame_size
,
float
quality
)
{
int
nb_frames
,
i
,
ret
,
av_unused
resample_changed
;
AVFrame
*
final_picture
,
*
formatted_picture
;
int
nb_frames
,
i
,
ret
;
AVFrame
*
final_picture
;
AVCodecContext
*
enc
,
*
dec
;
double
sync_ipts
;
...
...
@@ -1123,55 +1180,7 @@ static void do_video_out(AVFormatContext *s,
if
(
nb_frames
<=
0
)
return
;
formatted_picture
=
in_picture
;
final_picture
=
formatted_picture
;
#if !CONFIG_AVFILTER
resample_changed
=
ost
->
resample_width
!=
dec
->
width
||
ost
->
resample_height
!=
dec
->
height
||
ost
->
resample_pix_fmt
!=
dec
->
pix_fmt
;
if
(
resample_changed
)
{
av_log
(
NULL
,
AV_LOG_INFO
,
"Input stream #%d.%d frame changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s
\n
"
,
ist
->
file_index
,
ist
->
st
->
index
,
ost
->
resample_width
,
ost
->
resample_height
,
av_get_pix_fmt_name
(
ost
->
resample_pix_fmt
),
dec
->
width
,
dec
->
height
,
av_get_pix_fmt_name
(
dec
->
pix_fmt
));
ost
->
resample_width
=
dec
->
width
;
ost
->
resample_height
=
dec
->
height
;
ost
->
resample_pix_fmt
=
dec
->
pix_fmt
;
}
ost
->
video_resample
=
dec
->
width
!=
enc
->
width
||
dec
->
height
!=
enc
->
height
||
dec
->
pix_fmt
!=
enc
->
pix_fmt
;
if
(
ost
->
video_resample
)
{
final_picture
=
&
ost
->
resample_frame
;
if
(
!
ost
->
img_resample_ctx
||
resample_changed
)
{
/* initialize the destination picture */
if
(
!
ost
->
resample_frame
.
data
[
0
])
{
avcodec_get_frame_defaults
(
&
ost
->
resample_frame
);
if
(
avpicture_alloc
((
AVPicture
*
)
&
ost
->
resample_frame
,
enc
->
pix_fmt
,
enc
->
width
,
enc
->
height
))
{
fprintf
(
stderr
,
"Cannot allocate temp picture, check pix fmt
\n
"
);
exit_program
(
1
);
}
}
/* initialize a new scaler context */
sws_freeContext
(
ost
->
img_resample_ctx
);
ost
->
img_resample_ctx
=
sws_getContext
(
dec
->
width
,
dec
->
height
,
dec
->
pix_fmt
,
enc
->
width
,
enc
->
height
,
enc
->
pix_fmt
,
ost
->
sws_flags
,
NULL
,
NULL
,
NULL
);
if
(
ost
->
img_resample_ctx
==
NULL
)
{
fprintf
(
stderr
,
"Cannot get resampling context
\n
"
);
exit_program
(
1
);
}
}
sws_scale
(
ost
->
img_resample_ctx
,
formatted_picture
->
data
,
formatted_picture
->
linesize
,
0
,
ost
->
resample_height
,
final_picture
->
data
,
final_picture
->
linesize
);
}
#endif
do_video_resample
(
ost
,
ist
,
in_picture
,
&
final_picture
);
/* duplicates frame if needed */
for
(
i
=
0
;
i
<
nb_frames
;
i
++
)
{
...
...
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