Skip to content

Commit 1328e04

Browse files
author
Samy Laumonier
committed
gestion de l'audio
1 parent 94d4e4a commit 1328e04

File tree

18 files changed

+56
-49
lines changed

18 files changed

+56
-49
lines changed

celery/README.md

Lines changed: 0 additions & 13 deletions
This file was deleted.

celery/core/__init__.py

Whitespace-only changes.

celery/worker/__init__.py

Whitespace-only changes.

tests/.tmp/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*.avi
2+
*.mp4
3+
*.wav
4+
*.mp3
5+
*.txt
File renamed without changes.

tests/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Comment tester ?
2+
3+
```
4+
cd tests
5+
6+
# Lancement du core et des workers
7+
./test.sh start
8+
9+
# Lancement de la conversion d'une vidéo
10+
python ./test-video.py
11+
12+
# Lancement de la conversion d'un fichier audio
13+
python ./test-audio.py
14+
```
15+
16+
La vidéo `tests/resources/input.avi` sera convertie, le résultat sera disponible dans le dossier `tests/.tmp`.
17+
Le fichier audio `tests/resources/input.wav` sera converti, le résultat sera disponible dans le dossier `tests/.tmp`.

tests/core/core.py

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@
77
from celery import Celery
88
from celery.result import ResultSet
99

10-
from worker.worker import process_video_part
10+
from worker.worker import process_part
1111

1212
app = Celery('core', backend='amqp', broker='amqp://')
13-
WORKERS = 10
1413

1514

16-
# Video and audio
1715
def get_total_workers():
18-
return WORKERS
16+
return 10
1917

2018

2119
def get_file_length(input_path):
@@ -37,26 +35,25 @@ def get_file_length(input_path):
3735
raise Exception("File length not found {}".format(input_path))
3836

3937

40-
# Video
41-
@app.task(name='core.process_video')
42-
def process_video(input_path, output_format):
43-
video_length = get_file_length(input_path)
44-
part_length = int(video_length / WORKERS)
38+
@app.task(name='core.process_file')
39+
def process_file(is_video, input_path, output_format):
40+
file_length = get_file_length(input_path)
41+
part_length = int(file_length / get_total_workers())
4542

46-
output_part_paths = convert_video(input_path, output_format, video_length, part_length)
47-
output_path = concatenate_video_parts(input_path, output_format, output_part_paths)
43+
output_part_paths = convert_file(is_video, input_path, output_format, file_length, part_length)
44+
output_path = concatenate_parts(input_path, output_format, output_part_paths)
4845

4946
return output_path
5047

5148

52-
def convert_video(input_path, output_format, video_length, part_length):
49+
def convert_file(is_video, input_path, output_format, video_length, part_length):
5350
rs = ResultSet([])
5451

55-
for i in range(WORKERS):
52+
for i in range(get_total_workers()):
5653
start_at = i * part_length
57-
stop_at = start_at + part_length if i != WORKERS - 1 else video_length
54+
stop_at = start_at + part_length if i != get_total_workers() - 1 else video_length
5855
print("worker {} will process from {}s to {}s".format(i + 1, start_at, stop_at))
59-
rs.add(process_video_part.delay(input_path, output_format, start_at, stop_at))
56+
rs.add(process_part.delay(is_video, input_path, output_format, start_at, stop_at))
6057

6158
return rs.get()
6259

@@ -73,7 +70,7 @@ def create_parts_list(input_name, output_part_paths):
7370
return parts_list_path
7471

7572

76-
def concatenate_video_parts(input_path, output_format, output_part_paths):
73+
def concatenate_parts(input_path, output_format, output_part_paths):
7774
base_name = os.path.basename(input_path)
7875
input_name = os.path.splitext(base_name)[0]
7976

@@ -90,15 +87,3 @@ def concatenate_video_parts(input_path, output_format, output_part_paths):
9087
os.remove(output_part_path)
9188

9289
return output_path
93-
94-
95-
# Audio
96-
@app.task(name='core.process_audio')
97-
def process_audio(input_path, output_format):
98-
audio_length = get_file_length(input_path)
99-
part_length = int(audio_length / WORKERS)
100-
101-
output_part_paths = convert_audio(input_path, output_format, audio_length, part_length)
102-
output_path = concatenate_audio_parts(input_path, output_format, output_part_paths)
103-
104-
return output_path

tests/core/core.sh

100644100755
File mode changed.

tests/resources/input.avi

42.6 MB
Binary file not shown.

tests/test-audio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
start_time = time.time()
7-
output_path = core.process_audio("resources/input.wav", "mp3")
7+
output_path = core.process_file(False, "resources/input.wav", "mp3")
88
end_time = time.time()
99
elapsed = end_time - start_time
1010
print("file generated in {:4.3f}s, path: {}".format(elapsed, output_path))

0 commit comments

Comments
 (0)