[英]FFMPEG API and cropping
我在dranger的教程中學習了如何使用FFMPEG API,並使用庫SDL實現了視頻閱讀器來顯示視頻。
我有1280 * 720的高清視頻(我只能使用mp4),並且我想在高清視頻的任何位置選擇VGA屏幕(我的意思是在高清視頻中裁剪VGA屏幕),對數據進行調理並將其顯示在屏幕上。
在FFMPEG API中,我們可以使用函數av_picture_crop( 在此 )。 裁剪后的視頻上出現“黃色”疊加,幾秒鍾后我的應用程序崩潰。 在這里發帖之前,我看這里的功能並沒有結束呢。 但是當我閱讀代碼時,我找不到完成它的方法。 這是我的代碼的一部分:
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);
}
獲取編譯錯誤:
*** glibc detected *** ./HDtoVGA: corrupted double-linked list: 0x08d74e30 ***
在FFMPEG命令行工具中,我們可以使用vf_crop( 此處 )裁剪視頻,但是我找不到如何在代碼中實現相同功能的方法。
您有什么幫助我的提示嗎?
也許您提供的API( vf_crop )已被棄用。 對於最新API的示例,您可以參考過濾視頻示例。
為了裁剪視頻, filter_descr
“ crop=ow:oh:x:y
”之類的值filter_descr
給變量filter_descr
:
const char *filter_descr = "crop=1/3*in_w:1/3*in_h:1/3*in_w:0";
另外,您可以參考示例項目: 最簡單的ffmpeg視頻過濾器 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.