ffmpeg 调整相片大小_使用ffmpeg进行图片格式转换和图片缩放—jpg to yuv420/.mp4 to yuv420 | 学步园...

//.h#ifndef _JPG_PROCESS_H

#define _JPG_PROCESS_H

#if !defined PRId64 || PRI_MACROS_BROKEN

# undef PRId64

# define PRId64 "lld"

#endif

#ifndef INT64_C

#define INT64_C

#define UINT64_C

#endif

#include

namespace ffmpeg{

extern "C"

{

#include

#include

#include

#include

#include

#include

}

}

using namespace ffmpeg;

struct JpgProcessParam

{

AVFormatContext *fmt_ctx;

AVCodecContext *video_dec_ctx, *audio_dec_ctx;

AVStream *video_stream, *audio_stream;

char *in_filename;

char *out_filename;

char *audio_dst_filename;

FILE *video_dst_file;

FILE *audio_dst_file;

uint8_t *video_dst_data[4];

int video_dst_linesize[4];

int video_dst_bufsize;

int video_stream_idx, audio_stream_idx;

AVFrame *frame;

AVPacket pkt;

int video_frame_count;

int audio_frame_count;

};

class JpgProcess

{

private:

int decode_packet(int *got_frame, int cached);

int open_codec_context(int *stream_idx, AVFormatContext *fmt_ctx, enum AVMediaType type);

int get_format_from_sample_fmt(const char **fmt, enum AVSampleFormat sample_fmt);

int main_jpg();

JpgProcessParam jpgProcessParam;

public:

bool jpgprocess(char *src_filename, char *dst_filename);

};

#endif

//.cpp

#include "jpgprocess.h"

bool JpgProcess::jpgprocess(char *src_filename, char *dst_filename)

{

if ((NULL == src_filename) || (NULL == dst_filename))

return false;

memset(&jpgProcessParam, 0x00, sizeof(jpgProcessParam));

jpgProcessParam.in_filename = src_filename;

jpgProcessParam.out_filename = dst_filename;

main_jpg();

return true;

}

int JpgProcess::main_jpg()

{

int ret = 0, got_frame;

/* register all formats and codecs */

av_register_all();

/* open input file, and allocate format context */

if (avformat_open_input(&jpgProcessParam.fmt_ctx, jpgProcessParam.in_filename, NULL, NULL) < 0) {

fprintf(stderr, "Could not open source file %s\n", jpgProcessParam.in_filename);

exit(1);

}

/* retrieve stream information */

if (avformat_find_stream_info(jpgProcessParam.fmt_ctx, NULL) < 0) {

fprintf(stderr, "Could not find stream information\n");

exit(1);

}

if (open_codec_context(&jpgProcessParam.video_stream_idx, jpgProcessParam.fmt_ctx, AVMEDIA_TYPE_VIDEO) >= 0) {

jpgProcessParam.video_stream = jpgProcessParam.fmt_ctx->streams[jpgProcessParam.video_stream_idx];

jpgProcessParam.video_dec_ctx = jpgProcessParam.video_stream->codec;

jpgProcessParam.video_dst_file = fopen(jpgProcessParam.out_filename, "wb");

if (!j

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值