ffmpeg - ffmpeg库的sws_scale函数中的srcSliceY参数

标签 ffmpeg scale

几乎在我看到的所有地方,srcSliceY 值都设置为 0。
在文档中是这样写的:

c            the scaling context previously created with sws_getContext()
srcSlice    the array containing the pointers to the planes of the source slice
srcStride   the array containing the strides for each plane of the source image
srcSliceY   the position in the source image of the slice to process, that is the number (counted starting from zero) in the image of the first row of the slice
...

我不清楚“源图像”是什么意思。这是否意味着源切片?没有称为“源图像”的参数。

我写了这段代码:
SwsContext *ctx = sws_getContext(width, height, AV_PIX_FMT_GRAY8,
                                         dwidth, dheight, AV_PIX_FMT_GRAY8,
                                         SWS_BILINEAR, NULL, NULL, NULL);


const uint8_t* srcSlice[1] = { pSrc};
const int srcStride[1] = { width };
int srcSliceH = height;
const int   dstStride[1] = { dwidth };

printf("srcStride=%d, height =%d\n",srcStride[0],srcSliceH);
for(int i=0;i<100;i++){
  int t = sws_scale(ctx, srcSlice, srcStride, i, srcSliceH, &pDst, dstStride);
  if(t != 0)
    printf("i=%d t= %d\n",i,t);
}

我得到输出:
srcStride=384, height =30
[swscaler @ 0x1b0ba60] Warning: data is not aligned! This can lead to a speedloss
i=0 t= 2
i=4 t= 1
i=14 t= 1
i=24 t= 1
i=33 t= 1
i=43 t= 1
i=52 t= 1
i=62 t= 1
i=72 t= 1
i=81 t= 1
i=91 t= 1

查看 sws_scale 的源代码,它在错误或无效输入时返回 0。所以我得出结论,对于迭代中 srcSliceY 的大多数值,sws_returns 错误。但目前尚不清楚什么是有效的。

最佳答案

所以在做了更多的实验之后,我想我明白了。 srcSliceYsrcSliceH sws_scale 的参数应该是 srcH sws_getContext的参数.

然后sws_scale保持比例dstH : srcH sws_getContext的参数在决定输出切片的高度时。这样如果 dhsws_scale 的返回值然后:
dstH : srcH ~= dh : srcSliceH
所以,下面的代码:

int sws_scale_test(){

  int srcW = 1000;
  int srcH = 1000;
  int dstW = 2000;
  int dstH = 3000;

  unsigned char* pSrc = (unsigned char*)malloc(srcW*srcH);
  unsigned char* pDst = (unsigned char*)malloc(dstW*dstH);

  SwsContext *ctx = sws_getContext(srcW,srcH, AV_PIX_FMT_GRAY8, dstW,dstH, AV_PIX_FMT_GRAY8, NULL, NULL, NULL, NULL);

  const uint8_t* srcSlice[4] = { pSrc,NULL,NULL,NULL};
  const int srcStride[4] = { srcW,0,0,0 };
  int srcSliceY = 0;

  uint8_t* dst[4] = { pDst,NULL,NULL,NULL };
  const int  dstStride[4] = { dstW,0,0,0};

  printf("dstH/srcH = %f\n",((double)dstH)/ ((double)srcH)  );

  for(int i=1;srcH>i;i = 2*i){
    int srcSliceH = srcH-i;
    int dh = sws_scale(ctx, srcSlice, srcStride, i, srcSliceH, dst, dstStride);
    if(dh != 0)
      printf(" dt/srcH = %f\n",i,srcSliceH,dh, ((double)dh)/((double)    (srcSliceH)) );    
  }
  return 0;
}

打印:
dstH/srcH = 3.000000
dt/srcH = 2.994995
dt/srcH = 2.994990
dt/srcH = 2.994980
dt/srcH = 2.994960
dt/srcH = 2.994919
dt/srcH = 2.994835
dt/srcH = 2.994658
dt/srcH = 2.994266
dt/srcH = 2.993280
dt/srcH = 2.989754

关于ffmpeg - ffmpeg库的sws_scale函数中的srcSliceY参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44669144/

相关文章:

java - 相对布局的部分缩放

java:表示色阶上浮点值的范围

batch-file - ffmpeg批处理脚本,将多个音频剪辑与一个图像组合在一起> mp4

video - FFMPEG 从 .H264 转换为 MP4 播放速度太快

jquery - 缩放图像以适应容器,同时使用 jquery 保持纵横比

javascript - 如何在 ChartJS 中设置时间刻度缩放?

split - ffmpeg 生成缩略图不同比例

iOS ffmpeg 如何运行命令来修剪远程 url 视频?

FFMPEG NVENC HEVC 转 H264

python-3.x - Python 3.10 中 ffprobe 的困难