Changeset 381

Show
Ignore:
Timestamp:
05/02/08 16:38:53 (2 years ago)
Author:
mygrant
Message:

Rework to link against ffmpeg HEAD

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/uploadr/MacUploadr.app/Contents/Resources/components/Makefile

    r319 r381  
    1717EXIV_INCLUDE := -I/usr/local/include/exiv2 
    1818EXIV_LIB := -L/usr/local/lib -L/usr/lib 
    19 FF_INCLUDE := -I/usr/local/include/ffmpeg 
     19FF_INCLUDE := -I/usr/local/include 
    2020FF_LIB := -L/usr/local/lib 
    2121X11_LIB := -L/usr/X11R6/lib 
     
    107107                -lxml2 \ 
    108108                -ljpeg -lpng -ltiff \ 
    109                 -lavformat -lavcodec -lavutil
     109                -lavformat -lavcodec -lavutil -lswscale
    110110                -Wl,-read_only_relocs,suppress 
    111111else 
  • trunk/uploadr/MacUploadr.app/Contents/Resources/components/flGM.cpp

    r379 r381  
    2323// Goofy FFmpeg requires C linkage 
    2424extern "C" { 
    25 #include <avcodec.h> 
    26 #include <avformat.h> 
     25#include <libavcodec/avcodec.h> 
     26#include <libavformat/avformat.h> 
     27#include <libswscale/swscale.h> 
    2728} 
    2829 
     
    4748 
    4849#define round(n) (int)(0 <= (n) ? (n) + 0.5 : (n) - 0.5) 
     50static int sws_flags = SWS_BICUBIC; 
    4951 
    5052using namespace std; 
     
    451453} 
    452454 
    453 // Initialize our GraphicsMagick setup 
     455// Initialize our GraphicsMagick/ffmpeg setup 
    454456NS_IMETHODIMP flGM::Init(const nsAString & pwd) { 
    455457 
     
    469471        delete pwd_s; 
    470472#endif 
     473 
     474        // Register all video codecs 
     475        av_register_all(); 
    471476 
    472477        return NS_OK; 
     
    826831 
    827832        // Open the video file and decode it 
    828         av_register_all(); 
    829833        AVFormatContext *format_ctx; 
    830834        if (av_open_input_file(&format_ctx, path_s->c_str(), 0, 0, 0)) { 
     
    832836        } 
    833837        if (0 > av_find_stream_info(format_ctx)) { return NS_ERROR_NULL_POINTER; } 
     838        //dump_format(format_ctx, 0, path_s->c_str(), false); 
     839         
    834840        int stream = -1; 
    835841        for (int i = 0; i < format_ctx->nb_streams; ++i) { 
     
    841847        if (-1 == stream) { return NS_ERROR_NULL_POINTER; } 
    842848        AVCodecContext * codec_ctx = format_ctx->streams[stream]->codec; 
     849         
     850        // Load the actual codec we found and open the video stream 
    843851        AVCodec * codec = avcodec_find_decoder(codec_ctx->codec_id); 
    844852        if (!codec) { return NS_ERROR_NULL_POINTER; } 
     
    846854        AVFrame * video_frame = avcodec_alloc_frame(); 
    847855        AVFrame * img_frame = avcodec_alloc_frame(); 
    848         if (!video_frame || !img_frame) { eturn NS_ERROR_NULL_POINTER; } 
     856        if (!video_frame || !img_frame) { return NS_ERROR_NULL_POINTER; } 
    849857        int bytes = avpicture_get_size(PIX_FMT_RGB24, codec_ctx->width, 
    850858                codec_ctx->height); 
     
    869877        AVPacket packet; 
    870878        int have_frame; 
     879        struct SwsContext *toRGB_convert_ctx; 
    871880        while (0 <= av_read_frame(format_ctx, &packet)) { 
    872881                if (packet.stream_index == stream) { 
    873882                        avcodec_decode_video(codec_ctx, video_frame, &have_frame, 
    874883                                 packet.data, packet.size); 
     884                         
    875885                        if (have_frame && seek == ++i) { 
    876                                 img_convert((AVPicture *)img_frame, PIX_FMT_RGB24, 
    877                                         (AVPicture*)video_frame, codec_ctx->pix_fmt, 
    878                                         codec_ctx->width, codec_ctx->height); 
    879  
     886                                //img_convert((AVPicture *)img_frame, PIX_FMT_RGB24, 
     887                                //      (AVPicture*)video_frame, codec_ctx->pix_fmt, 
     888                                //      codec_ctx->width, codec_ctx->height); 
     889                                 
     890                                toRGB_convert_ctx = sws_getContext( 
     891                                        codec_ctx->width, codec_ctx->height, codec_ctx->pix_fmt, 
     892                                        codec_ctx->width, codec_ctx->height, PIX_FMT_RGB24, 
     893                                        sws_flags, NULL, NULL, NULL); 
     894                                if (toRGB_convert_ctx == NULL) { 
     895                                        av_log(NULL, AV_LOG_ERROR, 
     896                                                "Cannot initialize the toRGB conversion context\n"); 
     897                                        exit(1); 
     898                                } 
     899 
     900                                // img_convert parameters are          2 first destination, then 4 source 
     901                                // sws_scale   parameters are context, 4 first source,      then 2 destination 
     902                                sws_scale(toRGB_convert_ctx, 
     903                                        video_frame->data, video_frame->linesize, 0, codec_ctx->height, 
     904                                        img_frame->data, img_frame->linesize); 
     905                                 
    880906                                // Convert the keyframe to a PPM in a byte array 
    881907                                char header[32]; 
     
    895921                                        bytes_p += b; 
    896922                                } 
    897  
     923                                 
    898924                                // Convert the PPM array to a JPEG on disk 
    899925                                string * thumb_s = 0; 
     
    946972                                        while (*o) { _retval.Append(*o++); } 
    947973                                } 
    948  
     974                                 
    949975                                free(bytes); 
    950976                                av_free_packet(&packet); 
     
    961987        avcodec_close(codec_ctx); 
    962988        av_close_input_file(format_ctx); 
     989        sws_freeContext(toRGB_convert_ctx); 
    963990 
    964991        return NS_OK; 
  • trunk/uploadr/README.osx

    r378 r381  
    137137------------------------------------------------------------------------ 
    138138 
    139 Check out the magic version of FFmpeg: 
    140   $ svn co -r 10885 svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg 
     139Check out the most recent version of FFmpeg: 
     140  $ svn co svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg 
    141141  $ cd ffmpeg 
    142   $ cp common.mak subdir.mak 
    143142 
    144143Then build: 
    145144  $ ./configure --disable-ffserver --disable-ffplay --enable-gpl \ 
    146     --disable-vhook --disable-mmx --enable-static --disable-shared
    147     --extra-cflags=-fno-common --disable-debug 
     145    --disable-vhook --disable-mmx --enable-static --disable-shared
     146    --extra-cflags=-fno-common --disable-debug --enable-swscale 
    148147  $ make && sudo make install 
    149148 
  • trunk/uploadr/README.windows

    r370 r381  
    286286---   http://wiki.videolan.org/Win32CompileMSYS 
    287287 
    288 Check out and build the magic version of FFmpeg: 
     288Check out and build the most recent version of FFmpeg: 
    289289(handy hint: Shift+Insert pastes into the MSYS shell) 
    290290 
    291   $ svn co -r 10885 svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg 
     291  $ svn co svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg 
    292292  $ cd ffmpeg 
    293293  $ ./configure --disable-ffserver --disable-ffplay --enable-gpl \ 
    294294    --enable-memalign-hack --enable-static --disable-shared \ 
    295     --disable-debug 
     295    --disable-debug --enable-swscale 
    296296  $ make && make install 
    297297