Yoonjunhyeon

비디오 길이 계산 모듈 추가

...@@ -12,11 +12,21 @@ from django.shortcuts import get_object_or_404, render ...@@ -12,11 +12,21 @@ from django.shortcuts import get_object_or_404, render
12 from api.models import Video, VideoFile 12 from api.models import Video, VideoFile
13 from api.serializers import VideoSerializer, VideoFileSerializer 13 from api.serializers import VideoSerializer, VideoFileSerializer
14 from api import file_upload_path 14 from api import file_upload_path
15 +
15 import subprocess 16 import subprocess
16 import shlex 17 import shlex
17 - 18 +import json
18 # Create your views here. 19 # Create your views here.
19 20
21 +def with_ffprobe(filename):
22 +
23 + result = subprocess.check_output(
24 + f'ffprobe -v quiet -show_streams -select_streams v:0 -of json "{filename}"',
25 + shell=True).decode()
26 + fields = json.loads(result)['streams'][0]
27 + duration = int(float(fields['duration']))
28 + return duration
29 +
20 def index(request): 30 def index(request):
21 return render(request, template_name='index.html') 31 return render(request, template_name='index.html')
22 32
...@@ -39,7 +49,7 @@ class VideoFileUploadView(APIView): ...@@ -39,7 +49,7 @@ class VideoFileUploadView(APIView):
39 49
40 def post(self, req, *args, **kwargs): 50 def post(self, req, *args, **kwargs):
41 # 동영상 길이 51 # 동영상 길이
42 - runTime = 126 52 + runTime = 0
43 # 요청된 데이터를 꺼냄( QueryDict) 53 # 요청된 데이터를 꺼냄( QueryDict)
44 new_data = req.data.dict() 54 new_data = req.data.dict()
45 55
...@@ -48,7 +58,6 @@ class VideoFileUploadView(APIView): ...@@ -48,7 +58,6 @@ class VideoFileUploadView(APIView):
48 58
49 # 저장될 파일의 풀path를 생성 59 # 저장될 파일의 풀path를 생성
50 new_file_full_name = file_upload_path(file_name.name) 60 new_file_full_name = file_upload_path(file_name.name)
51 - print(new_file_full_name)
52 # 새롭게 생성된 파일의 경로 61 # 새롭게 생성된 파일의 경로
53 file_path = '-'.join(new_file_full_name.split('-')[0:-1]) 62 file_path = '-'.join(new_file_full_name.split('-')[0:-1])
54 63
...@@ -62,7 +71,9 @@ class VideoFileUploadView(APIView): ...@@ -62,7 +71,9 @@ class VideoFileUploadView(APIView):
62 71
63 if file_serializer.is_valid(): 72 if file_serializer.is_valid():
64 file_serializer.save() 73 file_serializer.save()
65 - print(file_serializer.data) 74 + # 동영상 길이 출력
75 + runTime = with_ffprobe('/'+file_serializer.data['file_save_name'])
76 + print(runTime)
66 77
67 process = subprocess.Popen(['./runMediaPipe.sh %s %s' %(file_serializer.data['file_save_name'],runTime,)], shell = True) 78 process = subprocess.Popen(['./runMediaPipe.sh %s %s' %(file_serializer.data['file_save_name'],runTime,)], shell = True)
68 process.wait() 79 process.wait()
......
...@@ -13,5 +13,3 @@ GLOG_logtostderr=1 bazel-bin/mediapipe/examples/desktop/youtube8m/extract_yt8m_f ...@@ -13,5 +13,3 @@ GLOG_logtostderr=1 bazel-bin/mediapipe/examples/desktop/youtube8m/extract_yt8m_f
13 --calculator_graph_config_file=mediapipe/graphs/youtube8m/feature_extraction.pbtxt \ 13 --calculator_graph_config_file=mediapipe/graphs/youtube8m/feature_extraction.pbtxt \
14 --input_side_packets=input_sequence_example=/tmp/mediapipe/metadata.pb \ 14 --input_side_packets=input_sequence_example=/tmp/mediapipe/metadata.pb \
15 --output_side_packets=output_sequence_example=/tmp/mediapipe/features.pb 15 --output_side_packets=output_sequence_example=/tmp/mediapipe/features.pb
16 -
17 -python convertPb2Tfrecord.py
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
2 <v-sheet> 2 <v-sheet>
3 <v-overlay v-model="loadingProcess"> 3 <v-overlay v-model="loadingProcess">
4 <v-progress-circular :size="120" width="10" color="primary" indeterminate></v-progress-circular> 4 <v-progress-circular :size="120" width="10" color="primary" indeterminate></v-progress-circular>
5 - <div style="color: #ffffff; font-size: 18px; margin-top: 10px">Analyzing Your Video...</div> 5 + <div style="color: #ffffff; font-size: 22px; margin-top: 20px; margin-left: -30px;">Analyzing Your Video...</div>
6 </v-overlay> 6 </v-overlay>
7 <v-layout justify-center> 7 <v-layout justify-center>
8 <v-flex xs12 sm8 md6 lg4> 8 <v-flex xs12 sm8 md6 lg4>
...@@ -127,6 +127,7 @@ export default { ...@@ -127,6 +127,7 @@ export default {
127 this.loadingProcess = true; 127 this.loadingProcess = true;
128 const formData = new FormData(); 128 const formData = new FormData();
129 formData.append('file', files[0]); 129 formData.append('file', files[0]);
130 + console.log(files[0]);
130 this.$axios.post('/upload', formData, { headers: { 'Content-Type': 'multipart/form-data' } }) 131 this.$axios.post('/upload', formData, { headers: { 'Content-Type': 'multipart/form-data' } })
131 .then((r) => { 132 .then((r) => {
132 this.loadingProcess = false; 133 this.loadingProcess = false;
......