Add aom_paeth_predictor_16x64 ssse3,avx2
[aom.git] / video_writer.c
blob4e072c7dcc41099483fc72b77f6457bf1c354c8b
1 /*
2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
4 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
12 #include <stdlib.h>
14 #include "./ivfenc.h"
15 #include "./video_writer.h"
16 #include "aom/aom_encoder.h"
18 struct AvxVideoWriterStruct {
19 AvxVideoInfo info;
20 FILE *file;
21 int frame_count;
24 static void write_header(FILE *file, const AvxVideoInfo *info,
25 int frame_count) {
26 struct aom_codec_enc_cfg cfg;
27 cfg.g_w = info->frame_width;
28 cfg.g_h = info->frame_height;
29 cfg.g_timebase.num = info->time_base.numerator;
30 cfg.g_timebase.den = info->time_base.denominator;
32 ivf_write_file_header(file, &cfg, info->codec_fourcc, frame_count);
35 AvxVideoWriter *aom_video_writer_open(const char *filename,
36 AvxContainer container,
37 const AvxVideoInfo *info) {
38 if (container == kContainerIVF) {
39 AvxVideoWriter *writer = NULL;
40 FILE *const file = fopen(filename, "wb");
41 if (!file) return NULL;
43 writer = malloc(sizeof(*writer));
44 if (!writer) return NULL;
46 writer->frame_count = 0;
47 writer->info = *info;
48 writer->file = file;
50 write_header(writer->file, info, 0);
52 return writer;
55 return NULL;
58 void aom_video_writer_close(AvxVideoWriter *writer) {
59 if (writer) {
60 // Rewriting frame header with real frame count
61 rewind(writer->file);
62 write_header(writer->file, &writer->info, writer->frame_count);
64 fclose(writer->file);
65 free(writer);
69 int aom_video_writer_write_frame(AvxVideoWriter *writer, const uint8_t *buffer,
70 size_t size, int64_t pts) {
71 ivf_write_frame_header(writer->file, pts, size);
72 if (fwrite(buffer, 1, size, writer->file) != size) return 0;
74 ++writer->frame_count;
76 return 1;