⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tutorial08.java

📁 ffmpeg开发指南
💻 JAVA
字号:
## An ffmpeg and SDL TutorialPage 1 2 3 4 5 6 7 8 End Prev Home Next  Printable version Text version## Tutorial 08: Software ScalingCode: tutorial08.c### libswscaleffmpeg has recently added a new interface, libswscale to handle image scaling.Whereas before in our player we would use img_convert to go from RGB to YUV12,we now use the new interface. This new interface is more modular, faster, andI believe has MMX optimization stuff. In other words, it's the preferred wayto do scaling. The basic function we're going to use to scale is sws_scale. But first, we'regoing to have to set up what's called an SwsContext. This allows us to compilethe conversion we want, and then pass that in later to sws_scale. It's kind oflike a prepared statement in SQL or a compiled regexp in Python. To preparethis context, we use the sws_getContext function, which is going to want oursource width and height, our desired width and height, the source format anddesired format, along with some other options and flags. Then we use sws_scalethe same way as img_convert except we pass it our SwsContext:             #include <ffmpeg/swscale.h> // include the header!        int queue_picture(VideoState *is, AVFrame *pFrame, double pts) {          static struct SwsContext *img_convert_ctx;      ...          if(vp->bmp) {            SDL_LockYUVOverlay(vp->bmp);                dst_pix_fmt = PIX_FMT_YUV420P;        /* point pict at the queue */            pict.data[0] = vp->bmp->pixels[0];        pict.data[1] = vp->bmp->pixels[2];        pict.data[2] = vp->bmp->pixels[1];                pict.linesize[0] = vp->bmp->pitches[0];        pict.linesize[1] = vp->bmp->pitches[2];        pict.linesize[2] = vp->bmp->pitches[1];                // Convert the image into YUV format that SDL uses        if(img_convert_ctx == NULL) {          int w = is->video_st->codec->width;          int h = is->video_st->codec->height;          img_convert_ctx = sws_getContext(w, h,                             is->video_st->codec->pix_fmt,                             w, h, dst_pix_fmt, SWS_BICUBIC,                             NULL, NULL, NULL);          if(img_convert_ctx == NULL) {    	fprintf(stderr, "Cannot initialize the conversion context!\n");    	exit(1);          }        }        sws_scale(img_convert_ctx, pFrame->data,                   pFrame->linesize, 0,                   is->video_st->codec->height,                   pict.data, pict.linesize);    and we have our new scaler in place. Hopefully this gives you a good idea ofwhat libswscale can do. That's it! We're done! Go ahead and compile your player:             gcc -o tutorial08 tutorial08.c -lavutil -lavformat -lavcodec -lz -lm`sdl-config --cflags --libs`    and enjoy your movie player made in less than 1000 lines of C! Of course, there's a lot of things we glanced over that we could add. _**>>** What's left?_* * *Function Reference  Data Referenceemail:dranger at gmail dot comBack to dranger.comThis work is licensed under the Creative Commons Attribution-Share Alike 2.5License. To view a copy of this license, visithttp://creativecommons.org/licenses/by-sa/2.5/ or send a letter to CreativeCommons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.    Code examples are based off of FFplay, Copyright (c) 2003 Fabrice Bellard, anda tutorial by Martin Bohme. 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -