赞
踩
#include <stdio.h> #include <errno.h> #include <libavutil/hwcontext.h> #include <libavcodec/avcodec.h> #include <libavformat/avformat.h> #include <libavutil/opt.h> static AVFormatContext *ifmt_ctx = NULL, *ofmt_ctx = NULL; static AVBufferRef *hw_device_ctx = NULL; static AVCodecContext *decoder_ctx = NULL, *encoder_ctx = NULL; static int video_stream = -1; typedef struct DynamicSetting { int frame_number; char* optstr; } DynamicSetting; static DynamicSetting *dynamic_setting; static int setting_number; static int current_setting_number; static int str_to_dict(char* optstr, AVDictionary **opt) { char *key, *value; if (strlen(optstr) == 0) return 0; key = strtok(optstr, " "); if (key == NULL) return AVERROR(ENAVAIL); value = strtok(NULL, " "); if (value == NULL) return AVERROR(ENAVAIL); av_dict_set(opt, key, value, 0); do { key = strtok(NULL, " "); if (key == NULL) return 0; value = strtok(NULL, " "); if (value == NULL) return AVERROR(ENAVAIL); av_dict_set(opt, key, value, 0); } while(key != NULL); return 0; } static int dynamic_set_parameter(AVCodecContext *avctx) { AVDictionary *opts = NULL; int ret = 0; static int frame_number = 0; frame_number++; if (current_setting_number < setting_number && frame_number == dynamic_setting[current_setting_number].frame_number) { AVDictionaryEntry *e = NULL; ret = str_to_dict(dynamic_setting[current_setting_number].optstr, &opts); if (ret < 0) { fprintf(stderr, "The dynamic parameter is wrong\n"); goto fail; } /* Set common option. The dictionary will be freed and replaced * by a new one containing all options not found in common option list. * Then this new dictionary is used to set private option. */ if ((ret = av_opt_set_dict(avctx, &opts)) < 0) goto fail; /* Set codec specific option */ if ((ret = av_opt_set_dict(avctx->priv_data, &opts)) < 0) goto fail; /* There is no "framerate" option in commom option list. Use "-r" to set * framerate, which is compatible with ffmpeg commandline. The video is * assumed to be average frame rate, so set time_base to 1/framerate. */ e = av_dict_get(opts, "r", NULL, 0); if (e) { avctx->framerate = av_d2q(atof(e->value), INT_MAX); encoder_ctx->time_base = av_inv_q(encoder_ctx->framerate); } } fail: av_dict_free(&opts); return ret; } static int get_format(AVCodecContext *avctx, const
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。