pcdoido2 commited on
Commit
0cd40aa
·
verified ·
1 Parent(s): e8f1268

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -16
app.py CHANGED
@@ -74,7 +74,7 @@ def random_string(length=12):
74
  return ''.join(random.choices(string.ascii_letters + string.digits, k=length))
75
 
76
  def process_video(file_path, hard_mode=False):
77
- """Processa vídeo removendo metadados (apenas com ffmpeg)"""
78
  temp_fd, temp_out = tempfile.mkstemp(suffix=".mp4")
79
  os.close(temp_fd)
80
 
@@ -82,23 +82,46 @@ def process_video(file_path, hard_mode=False):
82
  shutil.copy(file_path, temp_out)
83
  return temp_out
84
 
85
- # Pipeline HARD só com ffmpeg
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  cmd_ffmpeg = [
87
  "ffmpeg", "-y", "-i", file_path,
88
  "-map", "0:v", "-map", "0:a?",
89
  "-map_metadata", "-1",
90
- "-c:v", "libx264", "-preset", "fast", "-crf", "23",
91
- "-c:a", "aac", "-b:a", "128k",
 
92
  "-movflags", "use_metadata_tags+faststart",
93
- "-brand", random.choice(["mp42", "isom", "iso2", "avc1"]),
94
- "-metadata", f"encoder={random_string(10)}",
95
- "-metadata", f"title={random_string(12)}",
96
- "-metadata", f"comment={random_string(12)}",
97
- "-metadata", f"description={random_string(12)}",
98
- "-metadata", f"artist={random_string(10)}",
99
- "-metadata", f"album={random_string(10)}",
100
- temp_out
101
  ]
 
 
 
 
102
  subprocess.run(cmd_ffmpeg, check=True)
103
 
104
  return temp_out
@@ -126,7 +149,6 @@ if categoria:
126
 
127
  if uploaded_files:
128
  for uploaded_file in uploaded_files:
129
- # Evita processar o mesmo arquivo em loop
130
  if st.session_state.last_upload == uploaded_file.name:
131
  continue
132
 
@@ -140,13 +162,11 @@ if categoria:
140
  tmp.write(uploaded_file.read())
141
  tmp_path = tmp.name
142
 
143
- # Se for vídeo + hard_mode ativo → processa
144
  if is_video and hard_mode:
145
  final_tmp = process_video(tmp_path, hard_mode=True)
146
  else:
147
  final_tmp = tmp_path
148
 
149
- # Renomeia com string aleatória se hard_mode
150
  if hard_mode and is_video:
151
  new_name = random_string(16) + ".mp4"
152
  else:
@@ -155,7 +175,6 @@ if categoria:
155
  file_path = os.path.join(folder, new_name)
156
  shutil.move(final_tmp, file_path)
157
 
158
- # Salvar expiração
159
  if auto_delete:
160
  key = f"{categoria}|||{new_name}"
161
  expirations[key] = time.time() + 24 * 60 * 60
 
74
  return ''.join(random.choices(string.ascii_letters + string.digits, k=length))
75
 
76
  def process_video(file_path, hard_mode=False):
77
+ """Processa vídeo removendo metadados e mascarando vestígios do ffmpeg"""
78
  temp_fd, temp_out = tempfile.mkstemp(suffix=".mp4")
79
  os.close(temp_fd)
80
 
 
82
  shutil.copy(file_path, temp_out)
83
  return temp_out
84
 
85
+ # Randomizações técnicas
86
+ crf = str(random.randint(18, 26)) # qualidade variável
87
+ bitrate = f"{random.randint(96, 192)}k"
88
+ fps = f"{random.uniform(29.5, 30.5):.2f}"
89
+ brand = random.choice(["isom", "iso2", "mp42", "avc1", "dash", "iso3"])
90
+ compressor = random_string(random.randint(6, 12))
91
+ encoder_name = random_string(random.randint(6, 14))
92
+
93
+ # Metadados falsos
94
+ meta = {
95
+ "title": random_string(random.randint(8, 20)),
96
+ "comment": random_string(random.randint(8, 20)),
97
+ "description": random_string(random.randint(8, 20)),
98
+ "artist": random_string(random.randint(8, 20)),
99
+ "album": random_string(random.randint(8, 20)),
100
+ "genre": random_string(random.randint(5, 15)),
101
+ "publisher": random_string(random.randint(5, 15)),
102
+ "encoded_by": random_string(random.randint(5, 15)),
103
+ "location": random_string(random.randint(5, 15)),
104
+ "encoder": encoder_name
105
+ }
106
+
107
  cmd_ffmpeg = [
108
  "ffmpeg", "-y", "-i", file_path,
109
  "-map", "0:v", "-map", "0:a?",
110
  "-map_metadata", "-1",
111
+ "-c:v", "libx264", "-preset", "fast", "-crf", crf,
112
+ "-c:a", "aac", "-b:a", bitrate,
113
+ "-r", fps,
114
  "-movflags", "use_metadata_tags+faststart",
115
+ "-brand", brand,
116
+ "-metadata", f"encoder={encoder_name}",
117
+ "-metadata", f"CompressorName={compressor}",
118
+ "-fflags", "+bitexact",
119
+ "-flags", "+bitexact",
 
 
 
120
  ]
121
+ for k, v in meta.items():
122
+ cmd_ffmpeg += ["-metadata", f"{k}={v}"]
123
+
124
+ cmd_ffmpeg.append(temp_out)
125
  subprocess.run(cmd_ffmpeg, check=True)
126
 
127
  return temp_out
 
149
 
150
  if uploaded_files:
151
  for uploaded_file in uploaded_files:
 
152
  if st.session_state.last_upload == uploaded_file.name:
153
  continue
154
 
 
162
  tmp.write(uploaded_file.read())
163
  tmp_path = tmp.name
164
 
 
165
  if is_video and hard_mode:
166
  final_tmp = process_video(tmp_path, hard_mode=True)
167
  else:
168
  final_tmp = tmp_path
169
 
 
170
  if hard_mode and is_video:
171
  new_name = random_string(16) + ".mp4"
172
  else:
 
175
  file_path = os.path.join(folder, new_name)
176
  shutil.move(final_tmp, file_path)
177
 
 
178
  if auto_delete:
179
  key = f"{categoria}|||{new_name}"
180
  expirations[key] = time.time() + 24 * 60 * 60