feifeifeiliu commited on
Commit
a74eb69
1 Parent(s): 0c1c3c2

Upload rendering.py

Browse files
Files changed (1) hide show
  1. visualise/rendering.py +1 -65
visualise/rendering.py CHANGED
@@ -9,9 +9,6 @@ from subprocess import call
9
 
10
  import numpy as np
11
  from scipy.io import wavfile
12
-
13
- # os.environ['PYOPENGL_PLATFORM'] = 'egl' # Uncommnet this line while running remotely
14
-
15
  import pyrender
16
 
17
  # from psbody.mesh import Mesh
@@ -19,7 +16,7 @@ import pyrender
19
  import librosa
20
 
21
  from tqdm import tqdm
22
-
23
  # import open3d as o3d
24
  from data_utils.utils import load_wav_old
25
  from voca.rendering import render_mesh_helper
@@ -237,65 +234,4 @@ class RenderTool():
237
  # tmp_video_file.name, video_fname)).split()
238
  call(cmd)
239
  os.remove(tmp_audio_file.name)
240
- os.remove(tmp_video_file.name)
241
-
242
- def _render_continuity(self, cur_wav_file, pred, frame, run_in_parallel=False):
243
- print("Render {} {} sequence.".format(cur_wav_file.split(symbol)[-2],cur_wav_file.split(symbol)[-1]))
244
- if run_in_parallel:
245
- thread = threading.Thread(target=self._render_helper, args=(cur_wav_file, pred))
246
- thread.start()
247
- thread.join()
248
- else:
249
- self._render_helper2(cur_wav_file, pred, frame)
250
-
251
- def _render_helper2(self, cur_wav_file, pred, frame):
252
- directory = os.path.join(self.out_path, cur_wav_file.split('/')[2].split(symbol)[0])
253
- if not os.path.exists(directory):
254
- os.makedirs(directory)
255
- video_fname = os.path.join(directory, '%s.mp4' % cur_wav_file.split(symbol)[-1].split('.')[-2].split('/')[-1])
256
- self._render_sequences_helper2(video_fname, cur_wav_file, pred, frame)
257
-
258
- def _render_sequences_helper2(self, video_fname, cur_wav_file, pred, frame):
259
-
260
- num_frames = pred.shape[0]
261
- pred = pred.reshape(pred.shape[0], -1, 3)
262
-
263
- pred[:, :, 1] = -pred[:, :, 1]
264
- pred[:, :, 2] = -pred[:, :, 2]
265
-
266
- sr = 22000
267
- audio, sr = load_wav_old(cur_wav_file, sr=sr)
268
- tmp_audio_file = tempfile.NamedTemporaryFile('w', suffix='.wav', dir=os.path.dirname(video_fname))
269
- tmp_audio_file.close()
270
- wavfile.write(tmp_audio_file.name, sr, audio)
271
- tmp_video_file = tempfile.NamedTemporaryFile('w', suffix='.mp4', dir=os.path.dirname(video_fname))
272
- tmp_video_file.close()
273
- if int(cv2.__version__[0]) < 3:
274
- print('cv2 < 3')
275
- writer = cv2.VideoWriter(tmp_video_file.name, cv2.cv.CV_FOURCC(*'mp4v'), 15, (190, 800), True)
276
- else:
277
- print('cv2 >= 3')
278
- writer = cv2.VideoWriter(tmp_video_file.name, cv2.VideoWriter_fourcc(*'mp4v'), 30, (800, 800), True)
279
-
280
- center = np.mean(pred[0], axis=0)
281
-
282
- r = pyrender.OffscreenRenderer(viewport_width=800, viewport_height=800)
283
-
284
- for i_frame in tqdm(range(num_frames)):
285
- if i_frame < frame:
286
- sen = 'sequence 1'
287
- color = (0,255,0)
288
- else:
289
- sen = 'sequence 2'
290
- color = (0, 0, 255)
291
- pred_img = render_mesh_helper(Mesh(pred[i_frame], self.template_mesh.f), center, camera='o',r=r, y=0.7)
292
- pred_img = add_image_text(pred_img, sen, color)
293
- pred_img = pred_img.astype(np.uint8)
294
- writer.write(pred_img)
295
- writer.release()
296
-
297
- cmd = ('ffmpeg' + ' -i {0} -i {1} -vcodec h264 -ac 2 -channel_layout stereo -pix_fmt yuv420p {2}'.format(
298
- tmp_audio_file.name, tmp_video_file.name, video_fname)).split()
299
- call(cmd)
300
- os.remove(tmp_audio_file.name)
301
  os.remove(tmp_video_file.name)
 
9
 
10
  import numpy as np
11
  from scipy.io import wavfile
 
 
 
12
  import pyrender
13
 
14
  # from psbody.mesh import Mesh
 
16
  import librosa
17
 
18
  from tqdm import tqdm
19
+ # os.environ['PYOPENGL_PLATFORM'] = 'osmesa' # Uncommnet this line while running remotely
20
  # import open3d as o3d
21
  from data_utils.utils import load_wav_old
22
  from voca.rendering import render_mesh_helper
 
234
  # tmp_video_file.name, video_fname)).split()
235
  call(cmd)
236
  os.remove(tmp_audio_file.name)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
237
  os.remove(tmp_video_file.name)