Cut end of multiple videos

前端 未结 3 1065
清酒与你
清酒与你 2021-01-21 20:10

I need a script to cut off the last 6 seconds of multiple videos. The videos do all have different length.

I can‘t find anything helpful online.

Does anyone know

3条回答
  •  一生所求
    2021-01-21 20:42

    A method that uses ffprobe to get the input duration, bc to calculate the desired output duration, and ffmpeg to perform the cutting. This method does not require the inputs to contain an audio stream, but it requires two additional tools (ffprobe and bc) instead of just ffmpeg.

    Your preferred scripting language wasn't mentioned so I'll assume bash will do. In a script form as requested:

    #!/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
    

    Or as a single line:

    for f in *.mp4; do ffmpeg -i "$f" -map 0 -c copy -t "$(bc <<< "$(ffprobe -v error -select_streams v:0 -show_entries stream=duration -of default=noprint_wrappers=1:nokey=1 "$f")"-6)" output/"$f"; done
    

提交回复
热议问题