1 /*
2 * Copyright (c) 2015 Anton Khirnov
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22
23 /**
24 * @file Intel QSV-accelerated H.264 decoding API usage example
25 * @example qsv_decode.c
26 *
27 * Perform QSV-accelerated H.264 decoding with output frames in the
28 * GPU video surfaces, write the decoded frames to an output file.
29 */
30
31 #include <stdio.h>
32
35
37
43
45 {
49 }
50
52 }
53
54 fprintf(stderr, "The QSV pixel format not offered in get_format()\n");
55
57 }
58
62 {
64
67 fprintf(stderr, "Error during decoding\n");
69 }
70
73
76 break;
78 fprintf(stderr, "Error during decoding\n");
80 }
81
82 /* A real program would do something useful with the decoded frame here.
83 * We just retrieve the raw data and write it to a file, which is rather
84 * useless but pedagogic. */
87 fprintf(stderr, "Error transferring the data to system memory\n");
89 }
90
92 for (j = 0; j < (sw_frame->
height >> (
i > 0)); j++)
94
98
101 }
102
103 return 0;
104 }
105
106 int main(
int argc,
char **argv)
107 {
112
115
117
119
121
122 if (argc < 3) {
123 fprintf(stderr, "Usage: %s <input file> <output file>\n", argv[0]);
124 return 1;
125 }
126
127 /* open the input file */
130 fprintf(stderr, "Cannot open input file '%s': ", argv[1]);
132 }
133
134 /* find the first H.264 video stream */
137
140 else
142 }
144 fprintf(stderr, "No H.264 video stream in the input file\n");
146 }
147
148 /* open the hardware device */
152 fprintf(stderr, "Cannot open the hardware device\n");
154 }
155
156 /* initialize the decoder */
159 fprintf(stderr, "The QSV decoder is not present in libavcodec\n");
161 }
162
167 }
175 }
179 }
180
181
184
187 fprintf(stderr, "Error opening the decoder: ");
189 }
190
191 /* open the output stream */
194 fprintf(stderr, "Error opening the output context: ");
196 }
197
204 }
205
206 /* actual decoding */
210 break;
211
214
216 }
217
218 /* flush the decoder */
220
223 char buf[1024];
225 fprintf(stderr, "%s\n", buf);
226 }
227
229
233
235
237
239
241 }