fkmod000 commited on
Commit
701eff7
·
verified ·
1 Parent(s): 8e4c911

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -35
app.py CHANGED
@@ -1,37 +1,67 @@
1
- import os
2
- import subprocess
3
  import cv2
4
  import numpy as np
5
- from flask import Flask, request, send_file, jsonify
6
- from flask_cors import CORS
7
-
8
- app = Flask(__name__)
9
- CORS(app)
10
-
11
- def inpaint_video(input_path, output_path, x, y, w, h):
12
- # Utilise FFmpeg delogo (très rapide)
13
- cmd = [
14
- 'ffmpeg', '-y', '-i', input_path,
15
- '-vf', f'delogo=x={x}:y={y}:w={w}:h={h}',
16
- '-c:a', 'copy',
17
- '-c:v', 'libx264', '-preset', 'ultrafast',
18
- output_path
19
- ]
20
- subprocess.run(cmd)
21
-
22
- @app.route('/process', methods=['POST'])
23
- def process():
24
- if 'video' not in request.files:
25
- return jsonify({"error": "Aucun fichier"}), 400
26
- file = request.files['video']
27
- x, y, w, h = int(request.form['x']), int(request.form['y']), int(request.form['w']), int(request.form['h'])
28
- file.save("in.mp4")
29
- inpaint_video("in.mp4", "out.mp4", x, y, w, h)
30
- return send_file("out.mp4", mimetype='video/mp4')
31
-
32
- @app.route('/', methods=['GET'])
33
- def health():
34
- return "Backend Viewify Ready!"
35
-
36
- if __name__ == "__main__":
37
- app.run(host="0.0.0.0", port=7860)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
 
2
  import cv2
3
  import numpy as np
4
+ import os
5
+ import tempfile
6
+ import subprocess
7
+
8
+ def process_video(video, x1, y1, x2, y2):
9
+ temp_dir = tempfile.mkdtemp()
10
+
11
+ input_video = video
12
+ frames_dir = os.path.join(temp_dir, "frames")
13
+ os.makedirs(frames_dir, exist_ok=True)
14
+
15
+ # 1) Extraire les frames (FPS réduit)
16
+ subprocess.run([
17
+ "ffmpeg", "-i", input_video,
18
+ "-vf", "fps=10",
19
+ f"{frames_dir}/frame_%04d.png"
20
+ ], check=True)
21
+
22
+ # 2) Inpainting image par image
23
+ for frame_name in sorted(os.listdir(frames_dir)):
24
+ frame_path = os.path.join(frames_dir, frame_name)
25
+ img = cv2.imread(frame_path)
26
+
27
+ mask = np.zeros(img.shape[:2], dtype=np.uint8)
28
+ mask[int(y1):int(y2), int(x1):int(x2)] = 255
29
+ mask = cv2.dilate(mask, np.ones((3,3), np.uint8), iterations=1)
30
+
31
+ result = cv2.inpaint(img, mask, 3, cv2.INPAINT_TELEA)
32
+ cv2.imwrite(frame_path, result)
33
+
34
+ # 3) Réassembler la vidéo (sans audio)
35
+ output_video = os.path.join(temp_dir, "output.mp4")
36
+ subprocess.run([
37
+ "ffmpeg", "-y",
38
+ "-framerate", "10",
39
+ "-i", f"{frames_dir}/frame_%04d.png",
40
+ "-c:v", "libx264",
41
+ "-pix_fmt", "yuv420p",
42
+ output_video
43
+ ], check=True)
44
+
45
+ return output_video
46
+
47
+
48
+ with gr.Blocks() as demo:
49
+ gr.Markdown("## 🎥 Suppression de texte sur vidéo (100 % gratuit)")
50
+
51
+ video = gr.Video(label="Vidéo (max 30–60 s)")
52
+ with gr.Row():
53
+ x1 = gr.Number(label="X1")
54
+ y1 = gr.Number(label="Y1")
55
+ x2 = gr.Number(label="X2")
56
+ y2 = gr.Number(label="Y2")
57
+
58
+ btn = gr.Button("Supprimer le texte")
59
+ output = gr.Video(label="Vidéo finale")
60
+
61
+ btn.click(
62
+ process_video,
63
+ inputs=[video, x1, y1, x2, y2],
64
+ outputs=output
65
+ )
66
+
67
+ demo.launch()