Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1176)

Side by Side Diff: source/libvpx/examples/simple_decoder.c

Issue 148913004: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « source/libvpx/examples/postproc.txt ('k') | source/libvpx/examples/simple_decoder.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2010 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
12 // Simple Decoder
13 // ==============
14 //
15 // This is an example of a simple decoder loop. It takes an input file
16 // containing the compressed data (in IVF format), passes it through the
17 // decoder, and writes the decompressed frames to disk. Other decoder
18 // examples build upon this one.
19 //
20 // The details of the IVF format have been elided from this example for
21 // simplicity of presentation, as IVF files will not generally be used by
22 // your application. In general, an IVF file consists of a file header,
23 // followed by a variable number of frames. Each frame consists of a frame
24 // header followed by a variable length payload. The length of the payload
25 // is specified in the first four bytes of the frame header. The payload is
26 // the raw compressed data.
27 //
28 // Standard Includes
29 // -----------------
30 // For decoders, you only have to include `vpx_decoder.h` and then any
31 // header files for the specific codecs you use. In this case, we're using
32 // vp8. The `VPX_CODEC_DISABLE_COMPAT` macro can be defined to ensure
33 // strict compliance with the latest SDK by disabling some backwards
34 // compatibility features. Defining this macro is encouraged.
35 //
36 // Initializing The Codec
37 // ----------------------
38 // The decoder is initialized by the following code. This is an example for
39 // the VP8 decoder, but the code is analogous for all algorithms. Replace
40 // `vpx_codec_vp8_dx()` with a pointer to the interface exposed by the
41 // algorithm you want to use. The `cfg` argument is left as NULL in this
42 // example, because we want the algorithm to determine the stream
43 // configuration (width/height) and allocate memory automatically. This
44 // parameter is generally only used if you need to preallocate memory,
45 // particularly in External Memory Allocation mode.
46 //
47 // Decoding A Frame
48 // ----------------
49 // Once the frame has been read into memory, it is decoded using the
50 // `vpx_codec_decode` function. The call takes a pointer to the data
51 // (`frame`) and the length of the data (`frame_sz`). No application data
52 // is associated with the frame in this example, so the `user_priv`
53 // parameter is NULL. The `deadline` parameter is left at zero for this
54 // example. This parameter is generally only used when doing adaptive
55 // postprocessing.
56 //
57 // Codecs may produce a variable number of output frames for every call to
58 // `vpx_codec_decode`. These frames are retrieved by the
59 // `vpx_codec_get_frame` iterator function. The iterator variable `iter` is
60 // initialized to NULL each time `vpx_codec_decode` is called.
61 // `vpx_codec_get_frame` is called in a loop, returning a pointer to a
62 // decoded image or NULL to indicate the end of list.
63 //
64 // Processing The Decoded Data
65 // ---------------------------
66 // In this example, we simply write the encoded data to disk. It is
67 // important to honor the image's `stride` values.
68 //
69 // Cleanup
70 // -------
71 // The `vpx_codec_destroy` call frees any memory allocated by the codec.
72 //
73 // Error Handling
74 // --------------
75 // This example does not special case any error return codes. If there was
76 // an error, a descriptive message is printed and the program exits. With
77 // few exeptions, vpx_codec functions return an enumerated error status,
78 // with the value `0` indicating success.
79
80 #include <stdio.h>
81 #include <stdlib.h>
82 #include <string.h>
83
84 #define VPX_CODEC_DISABLE_COMPAT 1
85
86 #include "vpx/vp8dx.h"
87 #include "vpx/vpx_decoder.h"
88
89 #include "./ivfdec.h"
90 #include "./tools_common.h"
91 #include "./vpx_config.h"
92
93 static const char *exec_name;
94
95 void usage_exit() {
96 fprintf(stderr, "Usage: %s <infile> <outfile>\n", exec_name);
97 exit(EXIT_FAILURE);
98 }
99
100 int main(int argc, char **argv) {
101 FILE *infile, *outfile;
102 vpx_codec_ctx_t codec;
103 vpx_codec_iface_t *iface;
104 int flags = 0, frame_cnt = 0;
105 vpx_video_t *video;
106
107 exec_name = argv[0];
108
109 if (argc != 3)
110 die("Invalid number of arguments");
111
112 if (!(infile = fopen(argv[1], "rb")))
113 die("Failed to open %s for reading", argv[1]);
114
115 if (!(outfile = fopen(argv[2], "wb")))
116 die("Failed to open %s for writing", argv[2]);
117
118 video = vpx_video_open_file(infile);
119 if (!video)
120 die("%s is not an IVF file.", argv[1]);
121
122 iface = get_codec_interface(vpx_video_get_fourcc(video));
123 if (!iface)
124 die("Unknown FOURCC code.");
125
126 printf("Using %s\n", vpx_codec_iface_name(iface));
127
128 if (vpx_codec_dec_init(&codec, iface, NULL, flags))
129 die_codec(&codec, "Failed to initialize decoder");
130
131 while (vpx_video_read_frame(video)) {
132 vpx_codec_iter_t iter = NULL;
133 vpx_image_t *img = NULL;
134 size_t frame_size = 0;
135 const unsigned char *frame = vpx_video_get_frame(video, &frame_size);
136 if (vpx_codec_decode(&codec, frame, frame_size, NULL, 0))
137 die_codec(&codec, "Failed to decode frame");
138
139 while ((img = vpx_codec_get_frame(&codec, &iter)) != NULL) {
140 vpx_img_write(img, outfile);
141 ++frame_cnt;
142 }
143 }
144
145 printf("Processed %d frames.\n", frame_cnt);
146 if (vpx_codec_destroy(&codec))
147 die_codec(&codec, "Failed to destroy codec");
148
149 printf("Play: ffplay -f rawvideo -pix_fmt yuv420p -s %dx%d %s\n",
150 vpx_video_get_width(video), vpx_video_get_height(video), argv[2]);
151
152 vpx_video_close(video);
153
154 fclose(outfile);
155 fclose(infile);
156
157 return EXIT_SUCCESS;
158 }
OLDNEW
« no previous file with comments | « source/libvpx/examples/postproc.txt ('k') | source/libvpx/examples/simple_decoder.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698