]> granicus.if.org Git - libvpx/blob - ivfenc.c
vpx[dec|enc]: Extract IVF support from the apps.
[libvpx] / ivfenc.c
1 /*
2  *  Copyright (c) 2013 The WebM project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10
11 #include "./ivfenc.h"
12
13 #include "./tools_common.h"
14 #include "vpx/vpx_encoder.h"
15 #include "vpx_ports/mem_ops.h"
16
17 void ivf_write_file_header(FILE *outfile,
18                            const struct vpx_codec_enc_cfg *cfg,
19                            unsigned int fourcc,
20                            int frame_cnt) {
21   char header[32];
22
23   if (cfg->g_pass != VPX_RC_ONE_PASS && cfg->g_pass != VPX_RC_LAST_PASS)
24     return;
25
26   header[0] = 'D';
27   header[1] = 'K';
28   header[2] = 'I';
29   header[3] = 'F';
30   mem_put_le16(header + 4,  0);                 /* version */
31   mem_put_le16(header + 6,  32);                /* headersize */
32   mem_put_le32(header + 8,  fourcc);            /* four CC */
33   mem_put_le16(header + 12, cfg->g_w);          /* width */
34   mem_put_le16(header + 14, cfg->g_h);          /* height */
35   mem_put_le32(header + 16, cfg->g_timebase.den); /* rate */
36   mem_put_le32(header + 20, cfg->g_timebase.num); /* scale */
37   mem_put_le32(header + 24, frame_cnt);         /* length */
38   mem_put_le32(header + 28, 0);                 /* unused */
39
40   (void) fwrite(header, 1, 32, outfile);
41 }
42
43 void ivf_write_frame_header(FILE *outfile, const struct vpx_codec_cx_pkt *pkt) {
44   char header[12];
45   vpx_codec_pts_t pts;
46
47   if (pkt->kind != VPX_CODEC_CX_FRAME_PKT)
48     return;
49
50   pts = pkt->data.frame.pts;
51   mem_put_le32(header, (int)pkt->data.frame.sz);
52   mem_put_le32(header + 4, pts & 0xFFFFFFFF);
53   mem_put_le32(header + 8, pts >> 32);
54
55   (void) fwrite(header, 1, 12, outfile);
56 }
57
58 void ivf_write_frame_size(FILE *outfile, size_t size) {
59   char header[4];
60   mem_put_le32(header, (int)size);
61   (void) fwrite(header, 1, 4, outfile);
62 }