Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Xiph.Org
aom-rav1e
Commits
6adaec4f
Commit
6adaec4f
authored
Feb 06, 2014
by
Dmitry Kovalev
Committed by
Gerrit Code Review
Feb 06, 2014
Browse files
Merge "Adding video reader/writer APIs."
parents
f91a099f
37e6fd3d
Changes
13
Hide whitespace changes
Inline
Side-by-side
examples.mk
View file @
6adaec4f
...
...
@@ -79,20 +79,29 @@ EXAMPLES-$(CONFIG_VP8_DECODER) += simple_decoder.c
simple_decoder.GUID
=
D3BBF1E9-2427-450D-BBFF-B2843C1D44CC
simple_decoder.SRCS
+=
ivfdec.h ivfdec.c
simple_decoder.SRCS
+=
tools_common.h tools_common.c
simple_decoder.SRCS
+=
video_common.h
simple_decoder.SRCS
+=
video_reader.h video_reader.c
simple_decoder.DESCRIPTION
=
Simplified decoder loop
EXAMPLES-$(CONFIG_VP8_DECODER)
+=
postproc.c
postproc.SRCS
+=
ivfdec.h ivfdec.c
postproc.SRCS
+=
tools_common.h tools_common.c
postproc.SRCS
+=
video_common.h
postproc.SRCS
+=
video_reader.h video_reader.c
postproc.GUID
=
65E33355-F35E-4088-884D-3FD4905881D7
postproc.DESCRIPTION
=
Decoder postprocessor control
EXAMPLES-$(CONFIG_VP8_DECODER)
+=
decode_to_md5.c
decode_to_md5.SRCS
+=
md5_utils.h md5_utils.c
decode_to_md5.SRCS
+=
ivfdec.h ivfdec.c
decode_to_md5.SRCS
+=
tools_common.h tools_common.c
decode_to_md5.SRCS
+=
video_common.h
decode_to_md5.SRCS
+=
video_reader.h video_reader.c
decode_to_md5.GUID
=
59120B9B-2735-4BFE-B022-146CA340FE42
decode_to_md5.DESCRIPTION
=
Frame by frame MD5 checksum
EXAMPLES-$(CONFIG_VP8_ENCODER)
+=
simple_encoder.c
simple_encoder.SRCS
+=
ivfenc.h ivfenc.c
simple_encoder.SRCS
+=
tools_common.h tools_common.c
simple_encoder.SRCS
+=
video_common.h
simple_encoder.SRCS
+=
video_writer.h video_writer.c
simple_encoder.GUID
=
4607D299-8A71-4D2C-9B1D-071899B6FBFD
simple_encoder.DESCRIPTION
=
Simplified encoder loop
EXAMPLES-$(CONFIG_VP8_ENCODER)
+=
twopass_encoder.c
...
...
@@ -105,6 +114,8 @@ ifeq ($(CONFIG_DECODERS),yes)
EXAMPLES-$(CONFIG_VP8_ENCODER)
+=
decode_with_drops.c
decode_with_drops.SRCS
+=
ivfdec.h ivfdec.c
decode_with_drops.SRCS
+=
tools_common.h tools_common.c
decode_with_drops.SRCS
+=
video_common.h
decode_with_drops.SRCS
+=
video_reader.h video_reader.c
endif
decode_with_drops.GUID
=
CE5C53C4-8DDA-438A-86ED-0DDD3CDB8D26
decode_with_drops.DESCRIPTION
=
Drops frames
while
decoding
...
...
examples/decode_to_md5.c
View file @
6adaec4f
...
...
@@ -38,9 +38,9 @@
#include
"vpx/vp8dx.h"
#include
"vpx/vpx_decoder.h"
#include
"./ivfdec.h"
#include
"./md5_utils.h"
#include
"./tools_common.h"
#include
"./video_reader.h"
#include
"./vpx_config.h"
static
void
get_image_md5
(
const
vpx_image_t
*
img
,
unsigned
char
digest
[
16
])
{
...
...
@@ -79,41 +79,42 @@ void usage_exit() {
}
int
main
(
int
argc
,
char
**
argv
)
{
FILE
*
infile
,
*
outfile
;
int
frame_cnt
=
0
;
FILE
*
outfile
=
NULL
;
vpx_codec_ctx_t
codec
;
vpx_codec_iface_t
*
iface
;
int
flags
=
0
,
frame_cnt
=
0
;
vpx_video_t
*
video
;
vpx_codec_iface_t
*
iface
=
NULL
;
VpxVideoReader
*
reader
=
NULL
;
const
VpxVideoInfo
*
info
=
NULL
;
exec_name
=
argv
[
0
];
if
(
argc
!=
3
)
die
(
"Invalid number of arguments"
);
die
(
"Invalid number of arguments
.
"
);
if
(
!
(
infile
=
fopen
(
argv
[
1
],
"rb"
)))
die
(
"Failed to open %s for reading"
,
argv
[
1
]);
reader
=
vpx_video_reader_open
(
argv
[
1
]);
if
(
!
reader
)
die
(
"Failed to open %s for reading."
,
argv
[
1
]);
if
(
!
(
outfile
=
fopen
(
argv
[
2
],
"wb"
)))
die
(
"Failed to open %s for writing"
,
argv
[
2
]);
die
(
"Failed to open %s for writing
.
"
,
argv
[
2
]);
video
=
vpx_video_open_file
(
infile
);
if
(
!
video
)
die
(
"%s is not an IVF file."
,
argv
[
1
]);
info
=
vpx_video_reader_get_info
(
reader
);
iface
=
get_codec_interface
(
vpx_video_get_fourcc
(
video
)
);
iface
=
get_codec_interface
(
info
->
codec_fourcc
);
if
(
!
iface
)
die
(
"Unknown
FOURCC
code."
);
die
(
"Unknown
input
code
c
."
);
printf
(
"Using %s
\n
"
,
vpx_codec_iface_name
(
iface
));
if
(
vpx_codec_dec_init
(
&
codec
,
iface
,
NULL
,
flags
))
if
(
vpx_codec_dec_init
(
&
codec
,
iface
,
NULL
,
0
))
die_codec
(
&
codec
,
"Failed to initialize decoder"
);
while
(
vpx_video_read_frame
(
vi
de
o
))
{
while
(
vpx_video_
reader_
read_frame
(
rea
de
r
))
{
vpx_codec_iter_t
iter
=
NULL
;
vpx_image_t
*
img
=
NULL
;
size_t
frame_size
=
0
;
const
unsigned
char
*
frame
=
vpx_video_get_frame
(
video
,
&
frame_size
);
const
unsigned
char
*
frame
=
vpx_video_reader_get_frame
(
reader
,
&
frame_size
);
if
(
vpx_codec_decode
(
&
codec
,
frame
,
frame_size
,
NULL
,
0
))
die_codec
(
&
codec
,
"Failed to decode frame"
);
...
...
@@ -129,11 +130,10 @@ int main(int argc, char **argv) {
printf
(
"Processed %d frames.
\n
"
,
frame_cnt
);
if
(
vpx_codec_destroy
(
&
codec
))
die_codec
(
&
codec
,
"Failed to destroy codec"
);
die_codec
(
&
codec
,
"Failed to destroy codec
.
"
);
vpx_video_close
(
vi
de
o
);
vpx_video_
reader_
close
(
rea
de
r
);
fclose
(
outfile
);
fclose
(
infile
);
return
EXIT_SUCCESS
;
}
examples/decode_with_drops.c
View file @
6adaec4f
...
...
@@ -56,14 +56,13 @@
#include
<stdlib.h>
#include
<string.h>
#include
"./ivfdec.h"
#define VPX_CODEC_DISABLE_COMPAT 1
#include
"vpx/vp8dx.h"
#include
"vpx/vpx_decoder.h"
#include
"./tools_common.h"
#include
"./video_reader.h"
#include
"./vpx_config.h"
static
const
char
*
exec_name
;
...
...
@@ -74,52 +73,55 @@ void usage_exit() {
}
int
main
(
int
argc
,
char
**
argv
)
{
FILE
*
infile
,
*
outfile
;
int
frame_cnt
=
0
;
FILE
*
outfile
=
NULL
;
vpx_codec_ctx_t
codec
;
vpx_codec_iface_t
*
iface
;
int
flags
=
0
,
frame_cnt
=
0
;
vpx_video_t
*
video
;
int
n
,
m
,
is_range
;
char
*
nptr
;
vpx_codec_iface_t
*
iface
=
NULL
;
VpxVideoReader
*
reader
=
NULL
;
const
VpxVideoInfo
*
info
=
NULL
;
int
n
=
0
;
int
m
=
0
;
int
is_range
=
0
;
char
*
nptr
=
NULL
;
exec_name
=
argv
[
0
];
if
(
argc
!=
4
)
die
(
"Invalid number of arguments"
);
die
(
"Invalid number of arguments
.
"
);
if
(
!
(
infile
=
fopen
(
argv
[
1
],
"rb"
)))
die
(
"Failed to open %s for reading"
,
argv
[
1
]);
reader
=
vpx_video_reader_open
(
argv
[
1
]);
if
(
!
reader
)
die
(
"Failed to open %s for reading."
,
argv
[
1
]);
if
(
!
(
outfile
=
fopen
(
argv
[
2
],
"wb"
)))
die
(
"Failed to open %s for writing"
,
argv
[
2
]);
die
(
"Failed to open %s for writing
.
"
,
argv
[
2
]);
n
=
strtol
(
argv
[
3
],
&
nptr
,
0
);
m
=
strtol
(
nptr
+
1
,
NULL
,
0
);
is_range
=
(
*
nptr
==
'-'
);
if
(
!
n
||
!
m
||
(
*
nptr
!=
'-'
&&
*
nptr
!=
'/'
))
die
(
"Couldn't parse pattern %s
\n
"
,
argv
[
3
]);
die
(
"Couldn't parse pattern %s
.
\n
"
,
argv
[
3
]);
video
=
vpx_video_open_file
(
infile
);
if
(
!
video
)
die
(
"%s is not a supported input file."
,
argv
[
1
]);
info
=
vpx_video_reader_get_info
(
reader
);
iface
=
get_codec_interface
(
vpx_video_get_fourcc
(
video
)
);
iface
=
get_codec_interface
(
info
->
codec_fourcc
);
if
(
!
iface
)
die
(
"Unknown
FOURCC
code."
);
die
(
"Unknown
input
code
c
."
);
printf
(
"Using %s
\n
"
,
vpx_codec_iface_name
(
iface
));
if
(
vpx_codec_dec_init
(
&
codec
,
iface
,
NULL
,
flags
))
die_codec
(
&
codec
,
"Failed to initialize decoder"
);
if
(
vpx_codec_dec_init
(
&
codec
,
iface
,
NULL
,
0
))
die_codec
(
&
codec
,
"Failed to initialize decoder
.
"
);
while
(
vpx_video_read_frame
(
vi
de
o
))
{
while
(
vpx_video_
reader_
read_frame
(
rea
de
r
))
{
vpx_codec_iter_t
iter
=
NULL
;
vpx_image_t
*
img
=
NULL
;
size_t
frame_size
=
0
;
int
skip
;
const
unsigned
char
*
frame
=
vpx_video_get_frame
(
video
,
&
frame_size
);
const
unsigned
char
*
frame
=
vpx_video_reader_get_frame
(
reader
,
&
frame_size
);
if
(
vpx_codec_decode
(
&
codec
,
frame
,
frame_size
,
NULL
,
0
))
die_codec
(
&
codec
,
"Failed to decode frame"
);
die_codec
(
&
codec
,
"Failed to decode frame
.
"
);
++
frame_cnt
;
...
...
@@ -140,15 +142,13 @@ int main(int argc, char **argv) {
printf
(
"Processed %d frames.
\n
"
,
frame_cnt
);
if
(
vpx_codec_destroy
(
&
codec
))
die_codec
(
&
codec
,
"Failed to destroy codec"
);
die_codec
(
&
codec
,
"Failed to destroy codec
.
"
);
printf
(
"Play: ffplay -f rawvideo -pix_fmt yuv420p -s %dx%d %s
\n
"
,
vpx_video_get_width
(
video
),
vpx_video_get_height
(
video
),
argv
[
2
]);
vpx_video_close
(
video
);
info
->
frame_width
,
info
->
frame_height
,
argv
[
2
]);
vpx_video_reader_close
(
reader
);
fclose
(
outfile
);
fclose
(
infile
);
return
EXIT_SUCCESS
;
}
examples/postproc.c
View file @
6adaec4f
...
...
@@ -43,14 +43,13 @@
#include
<stdlib.h>
#include
<string.h>
#include
"./ivfdec.h"
#define VPX_CODEC_DISABLE_COMPAT 1
#include
"vpx/vp8dx.h"
#include
"vpx/vpx_decoder.h"
#include
"./tools_common.h"
#include
"./video_reader.h"
#include
"./vpx_config.h"
static
const
char
*
exec_name
;
...
...
@@ -61,35 +60,34 @@ void usage_exit() {
}
int
main
(
int
argc
,
char
**
argv
)
{
FILE
*
infile
,
*
outfile
;
vpx_codec_ctx_t
codec
;
vpx_codec_iface_t
*
iface
;
int
frame_cnt
=
0
;
vpx_video_t
*
video
;
FILE
*
outfile
=
NULL
;
vpx_codec_ctx_t
codec
;
vpx_codec_err_t
res
;
vpx_codec_iface_t
*
iface
=
NULL
;
VpxVideoReader
*
reader
=
NULL
;
const
VpxVideoInfo
*
info
=
NULL
;
exec_name
=
argv
[
0
];
if
(
argc
!=
3
)
die
(
"Invalid number of arguments"
);
die
(
"Invalid number of arguments
.
"
);
if
(
!
(
infile
=
fopen
(
argv
[
1
],
"rb"
)))
die
(
"Failed to open %s for reading"
,
argv
[
1
]);
reader
=
vpx_video_reader_open
(
argv
[
1
]);
if
(
!
reader
)
die
(
"Failed to open %s for reading."
,
argv
[
1
]);
if
(
!
(
outfile
=
fopen
(
argv
[
2
],
"wb"
)))
die
(
"Failed to open %s for writing"
,
argv
[
2
]);
video
=
vpx_video_open_file
(
infile
);
if
(
!
video
)
die
(
"%s is not a supported input file."
,
argv
[
1
]);
info
=
vpx_video_reader_get_info
(
reader
);
iface
=
get_codec_interface
(
vpx_video_get_fourcc
(
video
)
);
iface
=
get_codec_interface
(
info
->
codec_fourcc
);
if
(
!
iface
)
die
(
"Unknown
FOURCC
code."
);
die
(
"Unknown
input
code
c
."
);
printf
(
"Using %s
\n
"
,
vpx_codec_iface_name
(
iface
));
res
=
vpx_codec_dec_init
(
&
codec
,
iface
,
NULL
,
VPX_CODEC_USE_POSTPROC
);
if
(
res
==
VPX_CODEC_INCAPABLE
)
{
printf
(
"NOTICE: Postproc not supported.
\n
"
);
...
...
@@ -97,13 +95,14 @@ int main(int argc, char **argv) {
}
if
(
res
)
die_codec
(
&
codec
,
"Failed to initialize decoder"
);
die_codec
(
&
codec
,
"Failed to initialize decoder
.
"
);
while
(
vpx_video_read_frame
(
vi
de
o
))
{
while
(
vpx_video_
reader_
read_frame
(
rea
de
r
))
{
vpx_codec_iter_t
iter
=
NULL
;
vpx_image_t
*
img
=
NULL
;
size_t
frame_size
=
0
;
const
unsigned
char
*
frame
=
vpx_video_get_frame
(
video
,
&
frame_size
);
const
unsigned
char
*
frame
=
vpx_video_reader_get_frame
(
reader
,
&
frame_size
);
++
frame_cnt
;
...
...
@@ -111,12 +110,12 @@ int main(int argc, char **argv) {
vp8_postproc_cfg_t
pp
=
{
0
,
0
,
0
};
if
(
vpx_codec_control
(
&
codec
,
VP8_SET_POSTPROC
,
&
pp
))
die_codec
(
&
codec
,
"Failed to turn off postproc"
);
die_codec
(
&
codec
,
"Failed to turn off postproc
.
"
);
}
else
if
(
frame_cnt
%
30
==
16
)
{
vp8_postproc_cfg_t
pp
=
{
VP8_DEBLOCK
|
VP8_DEMACROBLOCK
|
VP8_MFQE
,
4
,
0
};
if
(
vpx_codec_control
(
&
codec
,
VP8_SET_POSTPROC
,
&
pp
))
die_codec
(
&
codec
,
"Failed to turn on postproc"
);
die_codec
(
&
codec
,
"Failed to turn on postproc
.
"
);
};
// Decode the frame with 15ms deadline
...
...
@@ -133,11 +132,10 @@ int main(int argc, char **argv) {
die_codec
(
&
codec
,
"Failed to destroy codec"
);
printf
(
"Play: ffplay -f rawvideo -pix_fmt yuv420p -s %dx%d %s
\n
"
,
vpx_video_get_width
(
video
),
vpx_video_get_height
(
video
)
,
argv
[
2
]);
info
->
frame_width
,
info
->
frame_height
,
argv
[
2
]);
vpx_video_close
(
vi
de
o
);
vpx_video_
reader_
close
(
rea
de
r
);
fclose
(
outfile
);
fclose
(
infile
);
return
EXIT_SUCCESS
;
}
examples/simple_decoder.c
View file @
6adaec4f
...
...
@@ -86,8 +86,8 @@
#include
"vpx/vp8dx.h"
#include
"vpx/vpx_decoder.h"
#include
"./ivfdec.h"
#include
"./tools_common.h"
#include
"./video_reader.h"
#include
"./vpx_config.h"
static
const
char
*
exec_name
;
...
...
@@ -98,43 +98,44 @@ void usage_exit() {
}
int
main
(
int
argc
,
char
**
argv
)
{
FILE
*
infile
,
*
outfile
;
int
frame_cnt
=
0
;
FILE
*
outfile
=
NULL
;
vpx_codec_ctx_t
codec
;
vpx_codec_iface_t
*
iface
;
int
flags
=
0
,
frame_cnt
=
0
;
vpx_video_t
*
video
;
vpx_codec_iface_t
*
iface
=
NULL
;
VpxVideoReader
*
reader
=
NULL
;
const
VpxVideoInfo
*
info
=
NULL
;
exec_name
=
argv
[
0
];
if
(
argc
!=
3
)
die
(
"Invalid number of arguments"
);
die
(
"Invalid number of arguments
.
"
);
if
(
!
(
infile
=
fopen
(
argv
[
1
],
"rb"
)))
die
(
"Failed to open %s for reading"
,
argv
[
1
]);
reader
=
vpx_video_reader_open
(
argv
[
1
]);
if
(
!
reader
)
die
(
"Failed to open %s for reading."
,
argv
[
1
]);
if
(
!
(
outfile
=
fopen
(
argv
[
2
],
"wb"
)))
die
(
"Failed to open %s for writing"
,
argv
[
2
]);
die
(
"Failed to open %s for writing
.
"
,
argv
[
2
]);
video
=
vpx_video_open_file
(
infile
);
if
(
!
video
)
die
(
"%s is not an IVF file."
,
argv
[
1
]);
info
=
vpx_video_reader_get_info
(
reader
);
iface
=
get_codec_interface
(
vpx_video_get_fourcc
(
video
)
);
iface
=
get_codec_interface
(
info
->
codec_fourcc
);
if
(
!
iface
)
die
(
"Unknown
FOURCC
code."
);
die
(
"Unknown
input
code
c
."
);
printf
(
"Using %s
\n
"
,
vpx_codec_iface_name
(
iface
));
if
(
vpx_codec_dec_init
(
&
codec
,
iface
,
NULL
,
flags
))
die_codec
(
&
codec
,
"Failed to initialize decoder"
);
if
(
vpx_codec_dec_init
(
&
codec
,
iface
,
NULL
,
0
))
die_codec
(
&
codec
,
"Failed to initialize decoder
.
"
);
while
(
vpx_video_read_frame
(
vi
de
o
))
{
while
(
vpx_video_
reader_
read_frame
(
rea
de
r
))
{
vpx_codec_iter_t
iter
=
NULL
;
vpx_image_t
*
img
=
NULL
;
size_t
frame_size
=
0
;
const
unsigned
char
*
frame
=
vpx_video_get_frame
(
video
,
&
frame_size
);
const
unsigned
char
*
frame
=
vpx_video_reader_get_frame
(
reader
,
&
frame_size
);
if
(
vpx_codec_decode
(
&
codec
,
frame
,
frame_size
,
NULL
,
0
))
die_codec
(
&
codec
,
"Failed to decode frame"
);
die_codec
(
&
codec
,
"Failed to decode frame
.
"
);
while
((
img
=
vpx_codec_get_frame
(
&
codec
,
&
iter
))
!=
NULL
)
{
vpx_img_write
(
img
,
outfile
);
...
...
@@ -147,12 +148,11 @@ int main(int argc, char **argv) {
die_codec
(
&
codec
,
"Failed to destroy codec"
);
printf
(
"Play: ffplay -f rawvideo -pix_fmt yuv420p -s %dx%d %s
\n
"
,
vpx_video_get_width
(
video
),
vpx_video_get_height
(
video
)
,
argv
[
2
]);
info
->
frame_width
,
info
->
frame_height
,
argv
[
2
]);
vpx_video_close
(
vi
de
o
);
vpx_video_
reader_
close
(
rea
de
r
);
fclose
(
outfile
);
fclose
(
infile
);
return
EXIT_SUCCESS
;
}
examples/simple_encoder.c
View file @
6adaec4f
...
...
@@ -83,194 +83,131 @@
#include
<stdio.h>
#include
<stdlib.h>
#include
<stdarg.h>
#include
<string.h>
#define VPX_CODEC_DISABLE_COMPAT 1
#include
"vpx/vpx_encoder.h"
#include
"vpx/vp8cx.h"
#define interface (vpx_codec_vp8_cx())
#define fourcc 0x30385056
#define IVF_FILE_HDR_SZ (32)
#define IVF_FRAME_HDR_SZ (12)
static
void
mem_put_le16
(
char
*
mem
,
unsigned
int
val
)
{
mem
[
0
]
=
val
;
mem
[
1
]
=
val
>>
8
;
}
#define VPX_CODEC_DISABLE_COMPAT 1
static
void
mem_put_le32
(
char
*
mem
,
unsigned
int
val
)
{
mem
[
0
]
=
val
;
mem
[
1
]
=
val
>>
8
;
mem
[
2
]
=
val
>>
16
;
mem
[
3
]
=
val
>>
24
;
}
#include
"vpx/vp8cx.h"
#include
"vpx/vpx_encoder.h"
static
void
die
(
const
char
*
fmt
,
...)
{
va_list
ap
;
#include
"./tools_common.h"
#include
"./video_writer.h"
va_start
(
ap
,
fmt
);
vprintf
(
fmt
,
ap
);
if
(
fmt
[
strlen
(
fmt
)
-
1
]
!=
'\n'
)
printf
(
"
\n
"
);
exit
(
EXIT_FAILURE
);
}
#define interface (vpx_codec_vp8_cx())
static
void
die_codec
(
vpx_codec_ctx_t
*
ctx
,
const
char
*
s
)
{
const
char
*
detail
=
vpx_codec_error_detail
(
ctx
);
static
const
char
*
exec_name
;
printf
(
"%s: %s
\n
"
,
s
,
vpx_codec_error
(
ctx
));
if
(
detail
)
printf
(
" %s
\n
"
,
detail
);
exit
(
EXIT_FAILURE
);
void
usage_exit
()
{
fprintf
(
stderr
,
"Usage: %s <width> <height> <infile> <outfile>
\n
"
,
exec_name
);
exit
(
EXIT_FAILURE
);
}
static
int
read_frame
(
FILE
*
f
,
vpx_image_t
*
img
)
{
size_t
nbytes
,
to_read
;
int
res
=
1
;
to_read
=
img
->
w
*
img
->
h
*
3
/
2
;
nbytes
=
fread
(
img
->
planes
[
0
],
1
,
to_read
,
f
);
if
(
nbytes
!=
to_read
)
{
res
=
0
;
if
(
nbytes
>
0
)
printf
(
"Warning: Read partial frame. Check your width & height!
\n
"
);
}
return
res
;
}
static
void
write_ivf_file_header
(
FILE
*
outfile
,
const
vpx_codec_enc_cfg_t
*
cfg
,
int
frame_cnt
)
{
char
header
[
32
];
if
(
cfg
->
g_pass
!=
VPX_RC_ONE_PASS
&&
cfg
->
g_pass
!=
VPX_RC_LAST_PASS
)
return
;
header
[
0
]
=
'D'
;
header
[
1
]
=
'K'
;
header
[
2
]
=
'I'
;
header
[
3
]
=
'F'
;
mem_put_le16
(
header
+
4
,
0
);
/* version */
mem_put_le16
(
header
+
6
,
32
);
/* headersize */
mem_put_le32
(
header
+
8
,
fourcc
);
/* headersize */
mem_put_le16
(
header
+
12
,
cfg
->
g_w
);
/* width */
mem_put_le16
(
header
+
14
,
cfg
->
g_h
);
/* height */
mem_put_le32
(
header
+
16
,
cfg
->
g_timebase
.
den
);
/* rate */
mem_put_le32
(
header
+
20
,
cfg
->
g_timebase
.
num
);
/* scale */
mem_put_le32
(
header
+
24
,
frame_cnt
);
/* length */
mem_put_le32
(
header
+
28
,
0
);
/* unused */
(
void
)
fwrite
(
header
,
1
,
32
,
outfile
);
int
res
=
1
;
size_t
to_read
=
img
->
w
*
img
->
h
*
3
/
2
;
size_t
nbytes
=
fread
(
img
->
planes
[
0
],
1
,
to_read
,
f
);
if
(
nbytes
!=
to_read
)
{
res
=
0
;
if
(
nbytes
>
0
)
printf
(
"Warning: Read partial frame. Check your width & height!
\n
"
);
}
return
res
;
}
static
void
write_ivf_frame_header
(
FILE
*
outfile
,
const
vpx_codec_cx_pkt_t
*
pkt
)
{
char
header
[
12
];
vpx_codec_pts_t
pts
;
if
(
pkt
->
kind
!=
VPX_CODEC_CX_FRAME_PKT
)
return
;
pts
=
pkt
->
data
.
frame
.
pts
;
mem_put_le32
(
header
,
pkt
->
data
.
frame
.
sz
);
mem_put_le32
(
header
+
4
,
pts
&
0xFFFFFFFF
);
mem_put_le32
(
header
+
8
,
pts
>>
32
);
(
void
)
fwrite
(
header
,
1
,
12
,
outfile
);
static
int
is_valid_dimension
(
int
value
)
{
return
value
>=
16
&&
(
value
%
2
==
0
);
}
int
main
(
int
argc
,
char
**
argv
)
{
FILE
*
infile
,
*
outfile
;
vpx_codec_ctx_t
codec
;
vpx_codec_enc_cfg_t
cfg
;
int
frame_cnt
=
0
;
vpx_image_t
raw
;
vpx_codec_err_t
res
;
long
width
;
long
height
;
int
frame_avail
;
int
got_data
;
int
flags
=
0
;
/* Open files */
if
(
argc
!=
5
)
die
(
"Usage: %s <width> <height> <infile> <outfile>
\n
"
,
argv
[
0
]);
width
=
strtol
(
argv
[
1
],
NULL
,
0
);
height
=
strtol
(
argv
[
2
],
NULL
,
0
);
if
(
width
<
16
||
width
%
2
||
height
<
16
||
height
%
2
)
die
(
"Invalid resolution: %ldx%ld"
,
width
,
height
);
if
(
!
vpx_img_alloc
(
&
raw
,
VPX_IMG_FMT_I420
,
width
,
height
,
1
))
die
(
"Faile to allocate image"
,
width
,
height
);
if
(
!
(
outfile
=
fopen
(
argv
[
4
],
"wb"
)))
die
(
"Failed to open %s for writing"
,
argv
[
4
]);
printf
(
"Using %s
\n
"
,
vpx_codec_iface_name
(
interface
));
/* Populate encoder configuration */
res
=
vpx_codec_enc_config_default
(
interface
,
&
cfg
,
0
);
if
(
res
)
{
printf
(
"Failed to get config: %s
\n
"
,
vpx_codec_err_to_string
(
res
));
return
EXIT_FAILURE
;
FILE
*
infile
;
vpx_codec_ctx_t
codec
;
vpx_codec_enc_cfg_t
cfg
;
int
frame_count
=
0
;
vpx_image_t
raw
;
vpx_codec_err_t
res
;
VpxVideoInfo
info
;
VpxVideoWriter
*
writer
;
const
int
fps
=
30
;
// TODO(dkovalev) add command line argument
const
int
bitrate
=
100
;
// kbit/s TODO(dkovalev) add command line argument
exec_name
=
argv
[
0
];
if
(
argc
!=
5
)
die
(
"Invalid number of arguments"
);
info
.
codec_fourcc
=
VP8_FOURCC
;
info
.
frame_width
=
strtol
(
argv
[
1
],
NULL
,
0
);
info
.
frame_height
=
strtol
(
argv
[
2
],
NULL
,
0
);
info
.
time_base
.
numerator
=
1
;
info
.
time_base
.
denominator
=
fps
;