I want to crop a picture using ffmpeg, run the following comand: ffmpeg -i
lehehai.asf -vframes 1 -ss 50 -f
image2 toimage.bmp, which can execute correctly 。After crop the picture, it
can still run ffmpeg -i lehehai.asf -vframes 1
-ss 50 -croptop 50 -cropbottom 50 -f image2 toimage.bmp。But when add
padding, it fails to run
ffmpeg -i lehehai.asf -vframes 1 -ss 50 -croptop 50 -cropbottom 50 -
padleft 10 -padright 20 -f image2 toimage.bmp。When tracking the codec,crop
and padding is dealt within
do_video_out,corresponding codec as followeed:
//(1)video crop
if (ost->video_crop) {
if (av_picture_crop((AVPicture *)&picture_crop_temp,
(AVPicture *)in_picture, dec->pix_fmt, ost->topBand, ost->leftBand) <
0) {
av_log(NULL, AV_LOG_ERROR, "error cropping picture\n");
return;
}
formatted_picture = &picture_crop_temp;
} else {
formatted_picture = in_picture;
}
final_picture = formatted_picture;
padding_src = formatted_picture;
resampling_dst = &ost->pict_tmp;
//(2)video pad,need to crop the edges of pad
if (ost->video_pad) {
final_picture = &ost->pict_tmp;
if (ost->video_resample) {
if (av_picture_crop((AVPicture *)&picture_pad_temp,
(AVPicture *)final_picture, enc->pix_fmt, ost->padtop, ost->padleft) <
0) {
av_log(NULL, AV_LOG_ERROR, "error padding picture\n");
return;
}
resampling_dst = &picture_pad_temp;
}
}
//(3)video resample
if (ost->video_resample) {
padding_src = NULL;
final_picture = &ost->pict_tmp;
sws_scale(ost->img_resample_ctx, formatted_picture->data,
formatted_picture->linesize,
0, ost->resample_height, resampling_dst->data,
resampling_dst->linesize);
}
//(4)video pad
if (ost->video_pad) {
av_picture_pad((AVPicture*)final_picture, (AVPicture *)
padding_src,
enc->height, enc->width, enc->pix_fmt,
ost->padtop, ost->padbottom, ost->padleft, ost-
>padright, padcolor);
}
For the video format is YUV,picture format is RGB24,so dec->pix_fmt and
enc->pix_fmt are not same.
Codec(1)do crop, parameter is dec->pix_fmt,so there is no problem.
Codec(2) aimes to crop the needed frame for pad,it passes enc->pix_fmt,so
the problem comes out. It is YUV format in picture_pad_temp, so will make
error when directly use RGB24 format for dealing. For the video conversion,
dec->pix_fmt and enc->pix_fmt
are same, so it won't make error.
Codec(3) do video resample
Codec(4)can pass enc->pix_fmt, and do pad,because the dealt final_picture
by Codec(3) is RGB24 format.
I think it is a bug. When I change the enc->pix_fmt of Codec(2) as
dec->pix_fmt, it works well. It could work normally when I tested the video
conersion.
So I want to communicate with more friends to confirm whether it is a bug.
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user