diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/creator.c | 46 | ||||
-rw-r--r-- | src/creator.h | 24 | ||||
-rw-r--r-- | src/render.c | 11 | ||||
-rw-r--r-- | src/render.h | 1 |
4 files changed, 45 insertions, 37 deletions
diff --git a/src/creator.c b/src/creator.c index 85fd0b0..0e0c3ac 100644 --- a/src/creator.c +++ b/src/creator.c @@ -24,17 +24,17 @@ static void encode(AVCodecContext *enc_ctx, AVFrame *frame, AVPacket *pkt, av_packet_unref(pkt); } } -int generateVideo(char *filename, int width, int height, int fps, int bitRate) +int generateVideo(const char *filename, int width, int height, int fps, int bitRate) { avcodec_register_all(); /* find the mpeg1video encoder */ - codec = avcodec_find_encoder(AV_CODEC_ID_MPEG1VIDEO); + codec = avcodec_find_encoder(AV_CODEC_ID_MPEG2VIDEO); if (!codec) { fprintf(stderr, "codec not found\n"); exit(1); } - c = avcodec_alloc_context3(codec); + avc = avcodec_alloc_context3(codec); picture = av_frame_alloc(); pkt = av_packet_alloc(); @@ -42,25 +42,25 @@ int generateVideo(char *filename, int width, int height, int fps, int bitRate) exit(1); /* put sample parameters */ - c->bit_rate = bitRate; + avc->bit_rate = bitRate; /* resolution must be a multiple of two */ if ((width*height)%2) exit(1); - c->width = width; - c->height = height; + avc->width = width; + avc->height = height; /* frames per second */ - c->time_base = (AVRational){1, fps}; - c->framerate = (AVRational){fps, 1}; + avc->time_base = (AVRational){1, fps}; + avc->framerate = (AVRational){fps, 1}; /* emit one intra frame every ten frames */ - c->gop_size = 10; - c->max_b_frames=1; - c->pix_fmt = AV_PIX_FMT_RGBA; + avc->gop_size = 10; + avc->max_b_frames=1; + avc->pix_fmt = AV_PIX_FMT_YUV420P; /* open it */ - if (avcodec_open2(c, codec, NULL) < 0) { + if (avcodec_open2(avc, codec, NULL) < 0) { fprintf(stderr, "could not open codec\n"); exit(1); } @@ -69,14 +69,15 @@ int generateVideo(char *filename, int width, int height, int fps, int bitRate) fprintf(stderr, "could not open %s\n", filename); exit(1); } - picture->format = c->pix_fmt; - picture->width = c->width; - picture->height = c->height; + picture->format = avc->pix_fmt; + picture->width = avc->width; + picture->height = avc->height; ret = av_frame_get_buffer(picture, 32); - if (ret < 0) { + if (creator_ret < 0) { fprintf(stderr, "could not alloc the frame data\n"); exit(1); } + pts_old = 0; return TRUE; } @@ -85,8 +86,8 @@ void addFrame(int *frame) { fflush(stdout); /* make sure the frame data is writable */ - ret = av_frame_make_writable(picture); - if (ret < 0) + creator_ret = av_frame_make_writable(picture); + if (creator_ret < 0) exit(1); picture->data[0] = frame; @@ -106,19 +107,20 @@ void addFrame(int *frame) } } */ - picture->pts = i; + picture->pts = pts_old; + pts_old++; /* encode the image */ - encode(c, picture, pkt, f); + encode(avc, picture, pkt, f); } void endFile(void){ uint8_t endcode[] = { 0, 0, 1, 0xb7 }; /* flush the encoder */ - encode(c, NULL, pkt, f); + encode(avc, NULL, pkt, f); /* add sequence end code to have a real MPEG file */ fwrite(endcode, 1, sizeof(endcode), f); fclose(f); - avcodec_free_context(&c); + avcodec_free_context(&avc); av_frame_free(&picture); av_packet_free(&pkt); } diff --git a/src/creator.h b/src/creator.h index bcff35d..99735c5 100644 --- a/src/creator.h +++ b/src/creator.h @@ -9,14 +9,18 @@ #ifndef CREATOR_H_ #define CREATOR_H_ -#define COORDS(x, y, width) ((y)*(width)+(x)) - -#include <stdio.h> -#include <stdlib.h> #include <string.h> #include <libavcodec/avcodec.h> #include <libavutil/frame.h> #include <libavutil/imgutils.h> +#include "defs.h" + +#define CLIP(X) ( (X) > 255 ? 255 : (X) < 0 ? 0 : X) + +// RGB -> YUV +#define RGB2Y(R, G, B) CLIP(( ( 66 * (R) + 129 * (G) + 25 * (B) + 128) >> 8) + 16) +#define RGB2U(R, G, B) CLIP(( ( -38 * (R) - 74 * (G) + 112 * (B) + 128) >> 8) + 128) +#define RGB2V(R, G, B) CLIP(( ( 112 * (R) - 94 * (G) - 18 * (B) + 128) >> 8) + 128) AVFrame *picture; @@ -24,15 +28,19 @@ AVPacket *pkt; FILE *f; +u64 pts_old; + const AVCodec *codec; -AVCodecContext *c= NULL; -int i, ret, x, y; +AVCodecContext *avc; +int creator_i, creator_ret, creator_x, creator_y; static void encode(AVCodecContext *enc_ctx, AVFrame *frame, AVPacket *pkt, FILE *outfile); -int generateVideo(char *filename, int width, int height, int fps, int bitRate); +int generateVideo(const char *filename, int width, int height, int fps, int bitRate); void addFrame(int *frame); -#endif /* RENDER_H_ */ +void endFile(void); + +#endif diff --git a/src/render.c b/src/render.c index 30f1b7a..ef61005 100644 --- a/src/render.c +++ b/src/render.c @@ -6,8 +6,6 @@ */ #include "render.h" -//#define HAVE_STRUCT_TIMESPEC -#include <pthread.h> void init_render(config_t *config) { @@ -72,6 +70,8 @@ void init_render(config_t *config) glutDisplayFunc(render); + generateVideo(_config->path, _config->width, config->height, _config->videoFPS, _config->bitrate); + t_old = glutGet(GLUT_ELAPSED_TIME); glutMainLoop(); @@ -90,11 +90,6 @@ d64 zoom_func(d64 ft, d64 s) void idle_dummy(void) { - double xmin = (double) x_min; - double ymin = (double) y_min; - double xmax = (double) x_max; - double ymax = (double) y_max; - printf("x_min: %lf, y_min: %lf, x_max: %lf, y_max: %lf\n", xmin, ymin, xmax, ymax); glutPostRedisplay(); } @@ -138,6 +133,8 @@ void render(void) { _render(x_min, y_min, x_max, y_max); + addFrame(_config->arr); + glBindTexture(GL_TEXTURE_2D, _config->tex); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, _config->width, _config->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, diff --git a/src/render.h b/src/render.h index 730673c..882e21b 100644 --- a/src/render.h +++ b/src/render.h @@ -13,6 +13,7 @@ #include "render_cpu.h" #include <math.h> #include "config.h" +#include "creator.h" config_t *_config; u32 *s_arr; |