diff options
author | Leonard Kugis <leonardkugis@gmail.com> | 2018-02-01 02:14:33 +0100 |
---|---|---|
committer | Leonard Kugis <leonardkugis@gmail.com> | 2018-02-01 02:14:33 +0100 |
commit | f1e93826da797128adcf90396d450fa590631bfb (patch) | |
tree | b50a8fa9b929a917934140eadd1f52947cdab133 /src/creator.c | |
parent | 18e5b2554b4cd73207e936e76e32c9d376cd1ba8 (diff) |
Diffstat (limited to 'src/creator.c')
-rw-r--r-- | src/creator.c | 46 |
1 files changed, 24 insertions, 22 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); } |