Created
December 15, 2020 12:59
-
-
Save Taehun/767f51fc8fb8ab636b6f15cbfea3fd5c to your computer and use it in GitHub Desktop.
프레임 추출 테스트 on Luigi
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
#!/usr/bin/env python | |
# Usage> | |
# $ pip install luigi | |
# $ python luigi_test.py FrameExtractTask --filename small_file.mp4 --local-scheduler | |
import os | |
import luigi | |
import sys | |
import time | |
import subprocess | |
from pathlib import Path | |
class FFMPEGTask(luigi.Task): | |
filename = luigi.Parameter() | |
def requires(self): | |
return [] | |
def run(self): | |
start_time = time.time() | |
subprocess.run(['ffmpeg', '-i', self.filename, '-r', '1/1', 'frame%03d.jpg']) | |
print("Processing time = {}".format(time.time() - start_time)) | |
_out = self.output().open('w') | |
_out.write(u"done!\n") | |
_out.close() | |
def output(self): | |
return luigi.LocalTarget('result.txt') | |
class FrameExtractTask(luigi.Task): | |
filename = luigi.Parameter() | |
def requires(self): | |
return FFMPEGTask(filename=self.filename) | |
def run(self): | |
for f in Path('.').glob('*.jpg'): | |
f.unlink() | |
os.remove('result.txt') | |
if __name__ == '__main__': | |
luigi.run() |
Author
Taehun
commented
Dec 15, 2020
- 다중 파일 처리
- 동시 요청 테스트 스크립트
#!/bin/bash
# Usage> $ time ./run_task_parallel.sh 5
for i in $(seq 1 $1)
do
python luigi_test.py FrameExtractTask --filename files/small_file$i.mp4 --local-scheduler &
done
wait
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment