@@ -396,36 +396,37 @@ def save_video_frames(self, video, uid, clue_intervals=None, num_frames=8, fps=-
396
396
# Save and validate frames
397
397
valid_paths = []
398
398
valid_indices = []
399
-
400
- if not np .all ([osp .exists (p ) for p in frame_paths ]):
401
- images = [vid [i ].asnumpy () for i in indices ]
402
- for i , (img_array , path ) in enumerate (zip (images , frame_paths )):
403
- if osp .exists (path ):
399
+ lock_path = osp .splitext (vid_path )[0 ] + '.lock'
400
+ with portalocker .Lock (lock_path , 'w' , timeout = 30 ):
401
+ if not np .all ([osp .exists (p ) for p in frame_paths ]):
402
+ images = [vid [i ].asnumpy () for i in indices ]
403
+ for i , (img_array , path ) in enumerate (zip (images , frame_paths )):
404
+ if osp .exists (path ):
405
+ try :
406
+ with Image .open (path ) as img :
407
+ img .verify ()
408
+ valid_paths .append (path )
409
+ valid_indices .append (indices [i ])
410
+ except Exception :
411
+ continue
412
+ else :
413
+ try :
414
+ img = Image .fromarray (img_array )
415
+ img .save (path )
416
+ img .verify ()
417
+ valid_paths .append (path )
418
+ valid_indices .append (indices [i ])
419
+ except Exception :
420
+ continue
421
+ else :
422
+ for i , path in enumerate (frame_paths ):
404
423
try :
405
424
with Image .open (path ) as img :
406
425
img .verify ()
407
426
valid_paths .append (path )
408
427
valid_indices .append (indices [i ])
409
428
except Exception :
410
429
continue
411
- else :
412
- try :
413
- img = Image .fromarray (img_array )
414
- img .save (path )
415
- img .verify ()
416
- valid_paths .append (path )
417
- valid_indices .append (indices [i ])
418
- except Exception :
419
- continue
420
- else :
421
- for i , path in enumerate (frame_paths ):
422
- try :
423
- with Image .open (path ) as img :
424
- img .verify ()
425
- valid_paths .append (path )
426
- valid_indices .append (indices [i ])
427
- except Exception :
428
- continue
429
430
430
431
return valid_paths , valid_indices , vid_fps
431
432
@@ -721,36 +722,37 @@ def save_video_frames(self, video, uid, clue_intervals=None, num_frames=8, fps=-
721
722
722
723
valid_paths = []
723
724
valid_indices = []
724
-
725
- if not np .all ([osp .exists (p ) for p in frame_paths ]):
726
- images = [vid [i ].asnumpy () for i in indices ]
727
- for i , (img_array , path ) in enumerate (zip (images , frame_paths )):
728
- if osp .exists (path ):
725
+ lock_path = osp .splitext (vid_path )[0 ] + '.lock'
726
+ with portalocker .Lock (lock_path , 'w' , timeout = 30 ):
727
+ if not np .all ([osp .exists (p ) for p in frame_paths ]):
728
+ images = [vid [i ].asnumpy () for i in indices ]
729
+ for i , (img_array , path ) in enumerate (zip (images , frame_paths )):
730
+ if osp .exists (path ):
731
+ try :
732
+ with Image .open (path ) as img :
733
+ img .verify ()
734
+ valid_paths .append (path )
735
+ valid_indices .append (indices [i ])
736
+ except Exception :
737
+ continue
738
+ else :
739
+ try :
740
+ img = Image .fromarray (img_array )
741
+ img .save (path )
742
+ img .verify ()
743
+ valid_paths .append (path )
744
+ valid_indices .append (indices [i ])
745
+ except Exception :
746
+ continue
747
+ else :
748
+ for i , path in enumerate (frame_paths ):
729
749
try :
730
750
with Image .open (path ) as img :
731
751
img .verify ()
732
752
valid_paths .append (path )
733
753
valid_indices .append (indices [i ])
734
754
except Exception :
735
755
continue
736
- else :
737
- try :
738
- img = Image .fromarray (img_array )
739
- img .save (path )
740
- img .verify ()
741
- valid_paths .append (path )
742
- valid_indices .append (indices [i ])
743
- except Exception :
744
- continue
745
- else :
746
- for i , path in enumerate (frame_paths ):
747
- try :
748
- with Image .open (path ) as img :
749
- img .verify ()
750
- valid_paths .append (path )
751
- valid_indices .append (indices [i ])
752
- except Exception :
753
- continue
754
756
755
757
return valid_paths , valid_indices , vid_fps
756
758
@@ -1276,36 +1278,37 @@ def save_video_frames(self, video, uid, clue_intervals=None, num_frames=8, fps=-
1276
1278
# Save and validate frames
1277
1279
valid_paths = []
1278
1280
valid_indices = []
1279
-
1280
- if not np .all ([osp .exists (p ) for p in frame_paths ]):
1281
- images = [vid [i ].asnumpy () for i in indices ]
1282
- for i , (img_array , path ) in enumerate (zip (images , frame_paths )):
1283
- if osp .exists (path ):
1281
+ lock_path = osp .splitext (vid_path )[0 ] + '.lock'
1282
+ with portalocker .Lock (lock_path , 'w' , timeout = 30 ):
1283
+ if not np .all ([osp .exists (p ) for p in frame_paths ]):
1284
+ images = [vid [i ].asnumpy () for i in indices ]
1285
+ for i , (img_array , path ) in enumerate (zip (images , frame_paths )):
1286
+ if osp .exists (path ):
1287
+ try :
1288
+ with Image .open (path ) as img :
1289
+ img .verify ()
1290
+ valid_paths .append (path )
1291
+ valid_indices .append (indices [i ])
1292
+ except Exception :
1293
+ continue
1294
+ else :
1295
+ try :
1296
+ img = Image .fromarray (img_array )
1297
+ img .save (path )
1298
+ img .verify ()
1299
+ valid_paths .append (path )
1300
+ valid_indices .append (indices [i ])
1301
+ except Exception :
1302
+ continue
1303
+ else :
1304
+ for i , path in enumerate (frame_paths ):
1284
1305
try :
1285
1306
with Image .open (path ) as img :
1286
1307
img .verify ()
1287
1308
valid_paths .append (path )
1288
1309
valid_indices .append (indices [i ])
1289
1310
except Exception :
1290
1311
continue
1291
- else :
1292
- try :
1293
- img = Image .fromarray (img_array )
1294
- img .save (path )
1295
- img .verify ()
1296
- valid_paths .append (path )
1297
- valid_indices .append (indices [i ])
1298
- except Exception :
1299
- continue
1300
- else :
1301
- for i , path in enumerate (frame_paths ):
1302
- try :
1303
- with Image .open (path ) as img :
1304
- img .verify ()
1305
- valid_paths .append (path )
1306
- valid_indices .append (indices [i ])
1307
- except Exception :
1308
- continue
1309
1312
1310
1313
return valid_paths , valid_indices , vid_fps
1311
1314
@@ -1600,36 +1603,37 @@ def save_video_frames(self, video, uid, clue_intervals=None, num_frames=8, fps=-
1600
1603
1601
1604
valid_paths = []
1602
1605
valid_indices = []
1603
-
1604
- if not np .all ([osp .exists (p ) for p in frame_paths ]):
1605
- images = [vid [i ].asnumpy () for i in indices ]
1606
- for i , (img_array , path ) in enumerate (zip (images , frame_paths )):
1607
- if osp .exists (path ):
1606
+ lock_path = osp .splitext (vid_path )[0 ] + '.lock'
1607
+ with portalocker .Lock (lock_path , 'w' , timeout = 30 ):
1608
+ if not np .all ([osp .exists (p ) for p in frame_paths ]):
1609
+ images = [vid [i ].asnumpy () for i in indices ]
1610
+ for i , (img_array , path ) in enumerate (zip (images , frame_paths )):
1611
+ if osp .exists (path ):
1612
+ try :
1613
+ with Image .open (path ) as img :
1614
+ img .verify ()
1615
+ valid_paths .append (path )
1616
+ valid_indices .append (indices [i ])
1617
+ except Exception :
1618
+ continue
1619
+ else :
1620
+ try :
1621
+ img = Image .fromarray (img_array )
1622
+ img .save (path )
1623
+ img .verify ()
1624
+ valid_paths .append (path )
1625
+ valid_indices .append (indices [i ])
1626
+ except Exception :
1627
+ continue
1628
+ else :
1629
+ for i , path in enumerate (frame_paths ):
1608
1630
try :
1609
1631
with Image .open (path ) as img :
1610
1632
img .verify ()
1611
1633
valid_paths .append (path )
1612
1634
valid_indices .append (indices [i ])
1613
1635
except Exception :
1614
1636
continue
1615
- else :
1616
- try :
1617
- img = Image .fromarray (img_array )
1618
- img .save (path )
1619
- img .verify ()
1620
- valid_paths .append (path )
1621
- valid_indices .append (indices [i ])
1622
- except Exception :
1623
- continue
1624
- else :
1625
- for i , path in enumerate (frame_paths ):
1626
- try :
1627
- with Image .open (path ) as img :
1628
- img .verify ()
1629
- valid_paths .append (path )
1630
- valid_indices .append (indices [i ])
1631
- except Exception :
1632
- continue
1633
1637
1634
1638
return valid_paths , valid_indices , vid_fps
1635
1639
0 commit comments