通过命令行ffmpeg将视频有效地裁剪为4x4网格/平铺块/矩阵吗? [英] Crop video into a 4x4 grid/tiles/matrix efficiently via command-line ffmpeg?

查看:100
本文介绍了通过命令行ffmpeg将视频有效地裁剪为4x4网格/平铺块/矩阵吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好Stackoverflow社区!

Hello Stackoverflow community!

我不敢问问题,但是似乎没有有效的方法来拍摄单个输入视频并进行矩阵变换/将视频分割成相等大小的片段,每个输入最好4x4 = 16个片段.

I dread having to ask questions, but there seems to be no efficient way to take a single input video and apply a matrix transformation/split the video into equal sized pieces, preferably 4x4=16 segments per input.

我尝试使用所有库,例如ffmpeg和mencoder,但具有16个输出的速度可能慢至0.15x.我项目的目标是将视频分为16个片段,重新排列这些片段,然后合并回最终的视频;稍后在HTML5 canvas中逆转该过程.这是一张图片,可以帮助您了解我在说什么:重组作品后的来源以及最终目的地

I tried using all the libraries such as ffmpeg and mencoder, but having 16 outputs can be as slow as 0.15x. The goal of my project is the split the video into 16 segments, rearrange those segments and combine back into a final video; later reversing the process in HTML5 canvas. Here is a picture to help you understand what I am talking about: the source but also the final destination after reorganizing the pieces

在分段导出之后,我将以拼图的方式重新组合各个部分(它们也是倒转和旋转但不相关)

我不相信您可以在一个命令中完成全部操作,因此我的目标是快速裁剪为16个映射的输出,然后以不同的顺序重新组装它们.但是我自己可以做其他部分.理想情况下,将有一种方法可以移动像素块(例如100x100)并将其移动.我的数学不够强..我真的很感谢你们所做的工作!

I do not believe you can do this all in one command, so my goal is to crop into 16 mapped outputs quickly, then reassemble them in a different order. But I can do the other parts myself. Ideally there would be a way to move pixel blocks eg 100x100 and just move them around. My math is not strong enough.. I really appreciate the work you guys do!

admin@dr.com

admin@dr.com

推荐答案

基本模板是

ffmpeg -i in.mp4
  -filter_complex
     "[0]split=16[a][b][c][d][e][f][g][h][i][j][k][l][m][n][o][p];
      [a]crop=iw/4:ih/4:0*iw/4:0*ih/4[a];
      [b]crop=iw/4:ih/4:1*iw/4:0*ih/4[b];
      [c]crop=iw/4:ih/4:2*iw/4:0*ih/4[c];
      [d]crop=iw/4:ih/4:3*iw/4:0*ih/4[d];
      [e]crop=iw/4:ih/4:0*iw/4:1*ih/4[e];
      [f]crop=iw/4:ih/4:1*iw/4:1*ih/4[f];
      [g]crop=iw/4:ih/4:2*iw/4:1*ih/4[g];
      [h]crop=iw/4:ih/4:3*iw/4:1*ih/4[h];
      [i]crop=iw/4:ih/4:0*iw/4:2*ih/4[i];
      [j]crop=iw/4:ih/4:1*iw/4:2*ih/4[j];
      [k]crop=iw/4:ih/4:2*iw/4:2*ih/4[k];
      [l]crop=iw/4:ih/4:3*iw/4:2*ih/4[l];
      [m]crop=iw/4:ih/4:0*iw/4:3*ih/4[m];
      [n]crop=iw/4:ih/4:1*iw/4:3*ih/4[n];
      [o]crop=iw/4:ih/4:2*iw/4:3*ih/4[o];
      [p]crop=iw/4:ih/4:3*iw/4:3*ih/4[p];
      [b][d][i][p]hstack=4[w];
      [n][g][j][c]hstack=4[x];
      [e][o][a][l]hstack=4[y];
      [h][f][m][k]hstack=4[z];
      [w][x][y][z]vstack=4"
      out.mp4

不漂亮,但是可以完成工作.如果您的视频尺寸为(mod 4),则为最佳.如果没有,在vstack之后的最后可能需要缩放器.指定给hstack的输入是控制片段混排的输入.

Not pretty, but gets the job done. Best if your video dimensions are (mod 4). If not, a scaler may be needed at the end after the vstack. The inputs specified to the hstacks are what control the shuffling of the pieces.

重新排列的部分发生得非常快-1080p输入的速度是7倍.编码会将其降低到0.9倍.如果输出为720p,则跳至1.9倍.对于保持原样的720p输入,速度是2.5倍.所有这些都以Haswell i5为基准.

The rearranging part happens pretty fast - speed 7x for a 1080p input. Encoding drags that down to 0.9x. If you output to 720p, that jumps to 1.9x. For a 720p input, kept as is, speed is 2.5x. All benchmarked on a Haswell i5.

这篇关于通过命令行ffmpeg将视频有效地裁剪为4x4网格/平铺块/矩阵吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆