summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristian Høgsberg <krh@bitplanet.net>2012-05-25 22:33:35 -0400
committerKristian Høgsberg <krh@bitplanet.net>2012-05-25 22:33:35 -0400
commit11374d2a7dd312e61610d19bd25043a6af46ac7e (patch)
tree228f956c7dbfeebbc57cddb3ca553c50c1072893
parent2255eb08164b99605dc4ae126d7545106f66f37b (diff)
wcap: Space out frames according to timestamps
-rw-r--r--wcap/vpxenc.c20
-rw-r--r--wcap/wcap-decode.c3
-rw-r--r--wcap/wcap-decode.h2
3 files changed, 19 insertions, 6 deletions
diff --git a/wcap/vpxenc.c b/wcap/vpxenc.c
index 7e0c5521..8edeb55c 100644
--- a/wcap/vpxenc.c
+++ b/wcap/vpxenc.c
@@ -314,6 +314,7 @@ struct input_state
struct vpx_rational framerate;
int use_i420;
struct wcap_decoder *wcap;
+ uint32_t output_msecs;
};
static inline int rgb_to_yuv(uint32_t format, uint32_t p, int *u, int *v)
@@ -406,10 +407,18 @@ static int read_frame(struct input_state *input, vpx_image_t *img)
}
else if (file_type == FILE_TYPE_WCAP)
{
- if (!wcap_decoder_get_frame(input->wcap))
- return 0;
+ if (input->wcap->count == 0) {
+ wcap_decoder_get_frame(input->wcap);
+ input->output_msecs = input->wcap->msecs;
+ }
+
+ while (input->output_msecs > input->wcap->msecs)
+ if (!wcap_decoder_get_frame(input->wcap))
+ return 0;
convert_to_yv12(input->wcap, img);
+ input->output_msecs +=
+ input->framerate.den * 1000 / input->framerate.num;
}
else
{
@@ -1748,7 +1757,7 @@ static void parse_global_config(struct global_config *global, char **argv)
}
-void open_input_file(struct input_state *input)
+void open_input_file(struct input_state *input, struct global_config *global)
{
unsigned int fourcc;
@@ -1802,8 +1811,7 @@ void open_input_file(struct input_state *input)
input->file_type = FILE_TYPE_WCAP;
input->w = input->wcap->width;
input->h = input->wcap->height;
- input->framerate.num = 30;
- input->framerate.den = 1;
+ input->framerate = global->framerate;
input->use_i420 = 0;
}
else
@@ -2488,7 +2496,7 @@ int main(int argc, const char **argv_)
{
int frames_in = 0;
- open_input_file(&input);
+ open_input_file(&input, &global);
/* If the input file doesn't specify its w/h (raw files), try to get
* the data from the first stream's configuration.
diff --git a/wcap/wcap-decode.c b/wcap/wcap-decode.c
index d6adc332..3ce7a196 100644
--- a/wcap/wcap-decode.c
+++ b/wcap/wcap-decode.c
@@ -86,6 +86,8 @@ wcap_decoder_get_frame(struct wcap_decoder *decoder)
return 0;
header = decoder->p;
+ decoder->msecs = header->msecs;
+ decoder->count++;
rects = (void *) (header + 1);
decoder->p = (uint32_t *) (rects + header->nrects);
@@ -121,6 +123,7 @@ wcap_decoder_create(const char *filename)
header = decoder->map;
decoder->format = header->format;
+ decoder->count = 0;
decoder->width = header->width;
decoder->height = header->height;
decoder->p = header + 1;
diff --git a/wcap/wcap-decode.h b/wcap/wcap-decode.h
index 8cf45d38..d6304154 100644
--- a/wcap/wcap-decode.h
+++ b/wcap/wcap-decode.h
@@ -51,6 +51,8 @@ struct wcap_decoder {
void *map, *p, *end;
uint32_t *frame;
uint32_t format;
+ uint32_t msecs;
+ uint32_t count;
int width, height;
};