裁剪黑色填充并调整为原始1920x1080

时间:2020-05-21 20:32:44

标签: ffmpeg

我有分辨率为1920x1080(长宽比为16:9)的视频。演奏时,在所有面都填充有黑框。如何删除黑匣子以获取1920x1080视频?

Screenshot of video

下面的音频和视频详细信息:

obj1 = [
   {
      "val":"type1",
      "removed":"N",
      "data":[
         {
            "label":"type1-a",
            "removed":"N",
            "dataid":16
         },
         {
            "label":"type1-b",
            "removed":"N",
            "dataid":26
         }
      ]
   },
   {
      "val":"type2",
      "removed":"N",
      "data":[
         {
            "label":"type2-a",
            "removed":"N",
            "dataid":12
         },
         {
            "label":"type2-b",
            "removed":"N",
            "dataid":34
         }
      ]
   },
   {
      "val":"type3",
      "removed":"N",
      "id":124,
      "label":"type3-label1"
   },
   {
      "val":"type4",
      "removed":"N",
      "id":126,
      "label":"type4-label1"
   },
   {
      "val":"type4",
      "removed":"N",
      "id":128,
      "label":"type4-label2"
   }
]

obj2 = [
   {
      "val":"type1",
      "removed":"N",
      "data":[
         {
            "label":"type1-a",
            "removed":"N",
            "dataid":16
         },
         {
            "label":"type1-c",
            "removed":null,
            "dataid":null
         },
         {
            "label":"type1-d",
            "removed":null,
            "dataid":null
         }
      ]
   },
   {
      "val":"type3",
      "removed":"N",
      "id":124,
      "label":"type3-label1"
   },
   {
      "val":"type4",
      "removed":"N",
      "id":126,
      "label":"type4-label1"
   },
   {
      "val":"type4",
      "removed":null,
      "id":null,
      "label":"type4-label3"
   }
]

result = [
   {
      "val":"type1",
      "removed":"N",
      "data":[
         {
            "label":"type1-a",
            "removed":"N",
            "dataid":16
         },
         {
            "label":"type1-b",
            "removed":"Y",
            "dataid":26
         },
         {
            "label":"type1-c",
            "removed":null,
            "dataid":null
         },
         {
            "label":"type1-d",
            "removed":null,
            "dataid":null
         }
      ]
   },
   {
      "val":"type2",
      "removed":"Y",
      "data":[
         {
            "label":"type2-a",
            "removed":"N",
            "dataid":12
         },
         {
            "label":"type2-b",
            "removed":"N",
            "dataid":34
         }
      ]
   },
   {
      "val":"type3",
      "removed":"N",
      "id":124,
      "label":"type3-label1"
   },
   {
      "val":"type4",
      "removed":"N",
      "id":126,
      "label":"type4-label1"
   },
   {
      "val":"type4",
      "removed":"Y",
      "id":128,
      "label":"type4-label2"
   },
   {
      "val":"type4",
      "removed":null,
      "id":null,
      "label":"type4-label3"
   }
]

1 个答案:

答案 0 :(得分:1)

使用cropdetect过滤器获取作物值:

ffmpeg -i input.mp4 -vf cropdetect -frames:v 3 -f null -
...
[Parsed_cropdetect_0 @ 0x559116cfe440] x1:240 x2:1679 y1:56 y2:1078 w:1440 h:1008 x:240 y:64 pts:2 t:2.000000 crop=1440:1008:240:64

然后使用crop滤镜裁剪黑色,scale放大至1080,然后pad填充缺失的区域以使宽高比为16:9:

ffmpeg -i input.mp4 -vf "crop=1440:1008:240:64,scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:-1:-1" -c:a copy output.mp4

之前和之后:

original crop and pad