2016-05-18 11 views
0

dranger's tutorialでFFMPEG APIを使用する方法を学び、ライブラリSDLを使用してビデオを表示するビデオリーダーを実装しました。FFMPEG APIとクロッピング

私はHDビデオ1280 * 720(私はmp4でしか動作しません)を持っています。そして、私はHDビデオのどこでもVGAスクリーンを選択したいのです。(HDビデオでVGAスクリーンを切り抜くことを意味します)それを画面に表示する。

FFMPEG APIでは、関数av_picture_crop(here)を使用できます。クロップされたビデオに「黄色」のオーバーレイが表示され、数秒後にアプリケーションがクラッシュします。ここに投稿する前に、私はhereを読んで、その機能はまだ完成していないと思っています。しかし、私はコードを読んで、私はそれを終了する方法を見つけることはありません。 これは私のコードの一部です:コンパイルエラーを取得

AVFrame *pFrame = NULL; 
AVFrame *pFrameCropped = NULL; 
bmp = SDL_CreateYUVOverlay(CODEC_WIDTH, // width 
          CODEC_HEIGHT, // height 
          SDL_YV12_OVERLAY, // format 
          screen); // SDL_Surface to display 


sws_ctx = sws_getContext(CODEC_WIDTH, // src width 
         CODEC_HEIGHT, // src height 
         pCodecCtx->pix_fmt, // src img format 
         STREAM_WIDTH, // dest width, 
         STREAM_HEIGHT, // dest height 
         AV_PIX_FMT_YUV420P, // dest img format 
         SWS_BILINEAR, // option to rescalling 
         NULL, // 
         NULL, // 
         NULL // 
         ); 

while(
av_read_frame(pFormatCtx, 
       &packet)>=0) 
{ 
if(packet.stream_index==videoStream) 
{ 
    avcodec_decode_video2(pCodecCtx, 
         pFrame, 
         &frameFinished, 
         &packet); 

    if(frameFinished) 
    { 
    SDL_LockYUVOverlay(bmp); 

    av_picture_crop((AVPicture*)pFrameCropped, 
        (AVPicture*)pFrame, 
        (AVPixelFormat)pFrame->format, 
        150, 
        300); 
    pict.data[0] = pFrameCropped->data[0];// "X" 
    pict.data[1] = pFrameCropped->data[1]; 
    pict.data[2] = pFrameCropped->data[2]; 

    // pict.linesize == number of bytes per line 
    pict.linesize[0] = pFrameCropped->linesize[0]; 
    pict.linesize[1] = pFrameCropped->linesize[2]; 
    pict.linesize[2] = pFrameCropped->linesize[1]; 

    sws_scale(sws_ctx, // the scaling context previously created with sws_getContext() 
       (uint8_t const * const *)pFrameCropped->data, // Pointers to the planes of the source slice 
       pFrame->linesize, // the array containing the strides for each plane of the source image 
       0, // position in src img processed slice. 
        // It's number (counted starting from zero) 
        // in the image of the first row of the slice 
       CODEC_HEIGHT, // source slice height. Number of rows in the slice 
       pict.data, // pointers to the planes of the destination image 
       pict.linesize); // strides for each plane of the destination image 

    // Unlock SDL_Overlay 
    SDL_UnlockYUVOverlay(bmp); 
} 

:FFMPEGのコマンドラインツールでは

*** glibc detected *** ./HDtoVGA: corrupted double-linked list: 0x08d74e30 *** 

を、「我々はvf_crop(here)を使用して、ビデオをトリミングすることができますが、私はドン私のコードに同じ関数を実装する方法を見つける。

私を助けるヒントはありますか?

+0

'libavcodec'はどうやってインストールしますか? 'libavformat'?と 'libavformat'? – ar2015

答えて

1

あなたが提供したAPI(vf_crop)は廃止されている可能性があります。 最新のAPIの例については、filtering videoの例を参照できます。

const char *filter_descr = "crop=1/3*in_w:1/3*in_h:1/3*in_w:0"; 

をし、また、あなたはサンプルプロジェクト参照できます:

ビデオをトリミングするために、変数filter_descrに 'crop=ow:oh:x:y' のような値を渡しsimplest ffmpeg video filterを。