Video 剪切多个视频的结尾

Video 剪切多个视频的结尾,video,ffmpeg,trim,cut,Video,Ffmpeg,Trim,Cut,我需要一个脚本来切断多个视频的最后6秒。这些视频都有不同的长度 我在网上找不到任何有用的东西 有人知道怎么做吗? thx您必须使用迂回的方式来实现这一点 ffmpeg-i file.mp4-its偏移量6\ -i file.mp4-c副本-映射0:a:0-映射1\ -最短-f螺母-|\ ffmpeg-y-i--c copy-map 0-map-0:0-ss 6.mp4 这将运行两个由管道连接的ffmpeg进程,尽管您可以通过两个ffmpeg命令一个接一个地运行来完成 第一个命令接收文件两次,并

我需要一个脚本来切断多个视频的最后6秒。这些视频都有不同的长度

我在网上找不到任何有用的东西

有人知道怎么做吗?
thx

您必须使用迂回的方式来实现这一点

ffmpeg-i file.mp4-its偏移量6\
-i file.mp4-c副本-映射0:a:0-映射1\
-最短-f螺母-|\
ffmpeg-y-i--c copy-map 0-map-0:0-ss 6.mp4
这将运行两个由管道连接的ffmpeg进程,尽管您可以通过两个ffmpeg命令一个接一个地运行来完成

第一个命令接收文件两次,并将第二个输入的时间戳偏移6秒。它映射来自第一个输入的音频流和来自第二个输入的所有流。第一个命令的输出被设置为以最短的流终止,该流是来自第一个输入的音频流。副作用是第二次输入的最后6秒被切断。在第二个过程中,除了第一个音频流之外的所有流都被复制到一个新的容器中



如果不确定文件是否有音频,可以将
-map 0:a:0
替换为
-map 0:0
一种方法,该方法使用
ffprobe
获取输入持续时间,
bc
计算所需的输出持续时间,并使用
ffmpeg
执行剪切。此方法不需要输入包含音频流,但它需要两个附加工具(
ffprobe
bc
),而不仅仅是
ffmpeg

您首选的脚本语言没有被提及,所以我假设bash可以。按要求以脚本形式:

#!/bin/bash
for f in *.mp4; do
cut_duration=6
input_duration=$(ffprobe -v error -select_streams v:0 -show_entries stream=duration -of default=noprint_wrappers=1:nokey=1 "$f")
output_duration=$(bc <<< "$input_duration"-"$cut_duration")
  ffmpeg -i "$f" -map 0 -c copy -t "$output_duration" output/"$f"
done
#/bin/bash
对于*.mp4中的f;做
切割持续时间=6
input_duration=$(ffprobe-v error-select_streams v:0-show_entries stream=duration-of default=noprint_wrappers=1:nokey=1“$f”)

output_duration=$(bc对于windows批处理文件,几乎不可能执行此操作。以下是Powershell的脚本:

$ListsFiles = Get-ChildItem "D:\VIDEOS\1\" -Filter *.avi;    

Foreach ($file in $ListsFiles){
    $input_d = [math]::round((ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 $file.Fullname));

    $output_duration=$input_d-5;

    $ArgumentList = '-i "{0}" -map 0 -c copy -t {1} "D:\VIDEOS\1\output\{2}"' -f $file.Fullname, $output_duration, $file;
    Write-Host -ForegroundColor Green -Object $ArgumentList;   
    Start-Process -FilePath ffmpeg -ArgumentList $ArgumentList -Wait -NoNewWindow;    
}

如何在windown 10上运行它。请帮助我。@很抱歉,我使用的Windows不够多,不知道如何使用批处理文件。
$ListsFiles = Get-ChildItem "D:\VIDEOS\1\" -Filter *.avi;    

Foreach ($file in $ListsFiles){
    $input_d = [math]::round((ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 $file.Fullname));

    $output_duration=$input_d-5;

    $ArgumentList = '-i "{0}" -map 0 -c copy -t {1} "D:\VIDEOS\1\output\{2}"' -f $file.Fullname, $output_duration, $file;
    Write-Host -ForegroundColor Green -Object $ArgumentList;   
    Start-Process -FilePath ffmpeg -ArgumentList $ArgumentList -Wait -NoNewWindow;    
}