Last active
August 25, 2025 18:48
-
-
Save alandbh/d0b8ba9f93b4d92e968c7dc40a0c5b26 to your computer and use it in GitHub Desktop.
Bash Script For Cutting Videos.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # vcut: Corta um trecho de um vídeo baseado no nome parcial e tempos de início/fim. | |
| # Uso: | |
| # vcut <nome-parcial> <início-MM:SS> <fim-MM:SS> [nome-destino-sem-extensão] | |
| # ------------------------------------------ | |
| # Instalando como comando global vcut | |
| # ------------------------------------------ | |
| # Salve o script acima com o nome vcut (sem .sh). | |
| # Torne-o executável com o comando: | |
| # chmod +x vcut | |
| # Mova para um diretório no seu PATH, por exemplo: | |
| # sudo mv vcut /usr/local/bin/ | |
| # Agora você pode usar de qualquer lugar: | |
| # vcut <nome-parcial> <início-MM:SS> <fim-MM:SS> [nome-destino-sem-extensão] | |
| # Verifica se ao menos 3 argumentos foram fornecidos | |
| if [ $# -lt 3 ]; then | |
| echo "Uso: vcut <nome-parcial-do-arquivo> <início-MM:SS> <fim-MM:SS> [nome-destino]" | |
| exit 1 | |
| fi | |
| pattern="$1" | |
| start="$2" | |
| end="$3" | |
| custom_name="$4" | |
| # Busca o primeiro arquivo que corresponde ao padrão | |
| file=$(ls | grep -i "$pattern" | head -n 1) | |
| if [ -z "$file" ]; then | |
| echo "Arquivo não encontrado com o padrão: $pattern" | |
| exit 1 | |
| fi | |
| # Nome base e extensão do arquivo original | |
| ext="${file##*.}" | |
| base="${file%.*}" | |
| # Define nome de saída | |
| if [ -n "$custom_name" ]; then | |
| output="${custom_name}.mp4" | |
| else | |
| output="${base}-cut-${start//:/_}-to-${end//:/_}.mp4" | |
| fi | |
| echo "Cortando '$file' de $start até $end → '$output'..." | |
| # Executa o corte com ffmpeg (modo rápido e sem reencode) | |
| ffmpeg -i "$file" -ss "$start" -to "$end" -c copy "$output" | |
| echo "✅ Corte finalizado: $output" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment