This repository was archived by the owner on Oct 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathffvideo
More file actions
82 lines (69 loc) · 2.19 KB
/
ffvideo
File metadata and controls
82 lines (69 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env bash
# TODO - Videos podem conter embedded subtiles [como utilizar isto? Arquivos mkv possuem subtitles] [ffplay -vf subtitles=input.mkv:stream_index=2 input.mkv], Criar um script para fazer download automático de subtitles; Utilizar OpenSubtitlesDownload.py!
# Quando o nome da pasta contém [], falha a reprodução do vídeo. Solução: remover []
# [ffmpeg -i Movie.mkv -map 0:s:0 subs.srt] - retira embbeded subtitle pelo index
# Utilizando uchardet (C++) para detectar file encoding
# Script para abrir arquivos de vídeo com subtítulos usando ffmpeg
init_variables(){
VIDEO="$1"
ARQUIVO="${1%.*}"
ARQUIVO_SRT="${1/${1##*.}/srt}"
PLAY=(ffplay -loglevel quiet -autoexit -i)
}
get_subtitle(){
OpenSubtitlesDownload.py "$1" || true
}
get_file_size(){
ARQUIVO_TAMANHO=$(du -h "$1" | cut -f1)
}
download_subtitle(){
get_file_size "$1"
if [[ $ARQUIVO_TAMANHO == *G ]] && [[ ! -e $ARQUIVO_SRT ]]
then
get_subtitle "$1"
to_utf8 "$ARQUIVO"
else
# Se já existir .srt, converter para utf-8
[[ -e $ARQUIVO_SRT ]] && to_utf8 "$ARQUIVO"
fi
}
# Atualiza o status bar
atualizar_statusbar(){
polybar-msg hook music_playing 1
}
# $1=$ARQUIVO
# Verifica a codificação do arquivo .srt e converter para UTF-8
to_utf8(){
local sub_file=$(ls "$1".{sub,srt,ass,idx,ssa,vtt,ttml} 2> /dev/null) #|| return 0
local char_code=$(uchardet "$sub_file")
if [[ $char_code != utf-8 ]]
then
local temp_file="$1-temp.${sub_file##*.}"
iconv -f "$char_code" -t UTF-8 "$sub_file" -o "$temp_file"
[[ $sub_file != *.srt ]] && ffmpeg -i "$temp_file" "$1".srt && rm "$temp_file" "$sub_file"
[[ -e $temp_file ]] && rm "$sub_file" && mv "$temp_file" "$1".srt
fi
}
run_cmd_play(){
atualizar_statusbar
# Problema com espaço? Sim, comandos que precisam interpretar "espaço" ou outros caracteres precisam ser "quotados"
"${PLAY[@]}" "$VIDEO"
}
play(){
# Verificar se arquivo srt existe, caso contrário, rodar o vídeo sem
if [[ ! -e $ARQUIVO_SRT ]]
then
run_cmd_play
else
PLAY+=(-vf subtitles="$ARQUIVO_SRT")
run_cmd_play
fi
atualizar_statusbar
}
main(){
init_variables "$1"
# Download legenda. Se não encontrar, continuar com reprodução do vídeo
download_subtitle "$VIDEO"
play
}
main "$@"