File size: 2,295 Bytes
1cdc47e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import subprocess
import sys
import os
import argparse
import time
from datetime import datetime
import signal

def signal_handler(sig, frame):
    print("\nInterrupted by user, shutting down...")
    if 'pool' in locals() and pool is not None:
        pool.terminate()
        pool.join()
    sys.exit(0)

signal.signal(signal.SIGINT, signal_handler)

def parse_arguments():
    parser = argparse.ArgumentParser(description="Run the complete video-to-BVH pipeline")
    # parser.add_argument('-v', '--video', required=True, help="Path to the input video file")
    return parser.parse_args()

def run_command(command, description):
    """Run a command and show its output."""
    try:
        start_time = time.time()
        script_dir = os.path.dirname(command[1])
        current_dir = os.getcwd()
        os.chdir(script_dir)
        
        subprocess.run(command, check=True)
        
        os.chdir(current_dir)
        
        end_time = time.time()
        execution_time = end_time - start_time
        return True
        
    except subprocess.CalledProcessError as e:
        os.chdir(current_dir)
        return False
    
    except Exception as e:
        if 'current_dir' in locals():
            os.chdir(current_dir)
        return False

def main():
    args = parse_arguments()
    
    base_dir = os.path.dirname(os.path.abspath(__file__))
    gen_skes_path = os.path.join(base_dir, "VideoToNPZ", "gen_skes.py")
    convert_obj_path = os.path.join(base_dir, "convertNPZtoBVH", "conver_obj.py")
    convert_bvh_path = os.path.join(base_dir, "convertNPZtoBVH", "conver_bvh.py")
    
    for script_path in [gen_skes_path, convert_obj_path, convert_bvh_path]:
        if not os.path.exists(script_path):
            return 1
    
    pipeline_steps = [
        {
            "command": [sys.executable, gen_skes_path],
        },
        {
            "command": [sys.executable, convert_obj_path],
        },
        {
            "command": [sys.executable, convert_bvh_path],
        }
    ]
    
    successful = 0
    failed = 0
    
    for step in pipeline_steps:
        if run_command(step["command"], ""):
            successful += 1
        else:
            failed += 1
    
    return 0 if failed == 0 else 1

if __name__ == "__main__":
    sys.exit(main())