日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ffmpeg 调整相片大小,如何使用ffmpeg的sws_scale()调整图片大小?

發布時間:2024/7/23 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ffmpeg 调整相片大小,如何使用ffmpeg的sws_scale()调整图片大小? 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

I wanna resize a picture by using the ffmpeg's func--->sws_scale().

Is there any one knows how to do it?

Do you have the source code for this function?

解決方案

First you need to create a SwsContext (you need to do this only once) :

struct SwsContext *resize;

resize = sws_getContext(width1, height1, AV_PIX_FMT_YUV420P, width2, height2, PIX_FMT_RGB24, SWS_BICUBIC, NULL, NULL, NULL);

You need two frames for conversion, frame1 is the original frame, you need to explicitly allocate frame2 :

AVFrame* frame1 = avcodec_alloc_frame(); // this is your original frame

AVFrame* frame2 = avcodec_alloc_frame();

int num_bytes = avpicture_get_size(AV_PIX_FMT_RGB24, width2, height2);

uint8_t* frame2_buffer = (uint8_t *)av_malloc(num_bytes*sizeof(uint8_t));

avpicture_fill((AVPicture*)frame2, frame2_buffer, AV_PIX_FMT_RGB24, width2, height2);

You may use this part inside a loop if you need to resize each frame you receive :

// frame1 should be filled by now (eg using avcodec_decode_video)

sws_scale(resize, frame1->data, frame1->linesize, 0, height1, frame2->data, frame2->linesize);

Note that I also changed pixel format, but you can use the same pixel format for both frames

總結

以上是生活随笔為你收集整理的ffmpeg 调整相片大小,如何使用ffmpeg的sws_scale()调整图片大小?的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。