1 /*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include <stdio.h>
20 #include <stdint.h>
21 #include <stdlib.h>
22
23 #include "decode_simple.h"
24
25 #include "libavutil/common.h"
26 #include "libavutil/dict.h"
27 #include "libavutil/error.h"
28 #include "libavutil/video_enc_params.h"
29
30 #include "libavformat/avformat.h"
31
32 #include "libavcodec/avcodec.h"
33
process_frame(DecodeContext * dc,AVFrame * frame)34 static int process_frame(DecodeContext *dc, AVFrame *frame)
35 {
36 AVFrameSideData *sd;
37
38 if (!frame)
39 return 0;
40
41 fprintf(stdout, "frame %d\n", dc->decoder->frame_number - 1);
42
43 sd = av_frame_get_side_data(frame, AV_FRAME_DATA_VIDEO_ENC_PARAMS);
44 if (sd) {
45 AVVideoEncParams *par = (AVVideoEncParams*)sd->data;
46
47 fprintf(stdout, "AVVideoEncParams %d\n", par->type);
48 fprintf(stdout, "qp %d\n", par->qp);
49 for (int i = 0; i < FF_ARRAY_ELEMS(par->delta_qp); i++)
50 for (int j = 0; j < FF_ARRAY_ELEMS(par->delta_qp[i]); j++) {
51 if (par->delta_qp[i][j])
52 fprintf(stdout, "delta_qp[%d][%d] %"PRId32"\n", i, j, par->delta_qp[i][j]);
53 }
54
55 if (par->nb_blocks) {
56 fprintf(stdout, "nb_blocks %d\n", par->nb_blocks);
57 for (int i = 0; i < par->nb_blocks; i++) {
58 AVVideoBlockParams *b = av_video_enc_params_block(par, i);
59
60 fprintf(stdout, "block %d %d:%d %dx%d %"PRId32"\n",
61 i, b->src_x, b->src_y, b->w, b->h, b->delta_qp);
62 }
63 }
64 }
65
66 return 0;
67 }
68
main(int argc,char ** argv)69 int main(int argc, char **argv)
70 {
71 DecodeContext dc;
72
73 unsigned int stream_idx, max_frames;
74 const char *filename, *thread_type = NULL, *nb_threads = NULL;
75 int ret = 0;
76
77 if (argc <= 3) {
78 fprintf(stderr, "Usage: %s <input file> <stream index> <max frame count> [<thread count> <thread type>]\n", argv[0]);
79 return 0;
80 }
81
82 filename = argv[1];
83 stream_idx = strtol(argv[2], NULL, 0);
84 max_frames = strtol(argv[3], NULL, 0);
85 if (argc > 5) {
86 nb_threads = argv[4];
87 thread_type = argv[5];
88 }
89
90 ret = ds_open(&dc, filename, stream_idx);
91 if (ret < 0)
92 goto finish;
93
94 dc.process_frame = process_frame;
95 dc.max_frames = max_frames;
96
97 ret = av_dict_set(&dc.decoder_opts, "threads", nb_threads, 0);
98 ret |= av_dict_set(&dc.decoder_opts, "thread_type", thread_type, 0);
99 ret |= av_dict_set(&dc.decoder_opts, "export_side_data", "venc_params", 0);
100
101 if (ret < 0)
102 goto finish;
103
104 ret = ds_run(&dc);
105
106 finish:
107 ds_free(&dc);
108 return ret;
109 }
110