reddevil /Vendor/phpvideotoolkit/phpvideotoolkit.php4.php

Language PHP Lines 3296
MD5 Hash c07fc240df96d0353b02f1aafe1cf221
Repository https://github.com/Wargo/reddevil.git View Raw File
   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
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
<?php

	/* SVN FILE: $Id$ */

	/**
	 * @author Oliver Lillie (aka buggedcom) <publicmail@buggedcom.co.uk>
	 *
	 * @license BSD
	 * @copyright Copyright (c) 2008 Oliver Lillie <http://www.buggedcom.co.uk>
	 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
	 * files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
	 * modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
	 * is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be
	 * included in all copies or substantial portions of the Software.
	 *
	 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
	 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
	 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
	 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
	 *
	 * @package PHPVideoToolkit (was called ffmpeg)
	 * @version 0.1.5
	 * @changelog SEE CHANGELOG
	 * @abstract This class can be used in conjunction with several server binary libraries to manipulate video and audio
	 * through PHP. It is not intended to solve any particular problems, however you may find it useful. This php class
	 * is in no way associated with the actual FFmpeg releases. Any mistakes contained in this php class are mine and mine
	 * alone.
	 *
	 * Please Note: There are several prerequisites that are required before this class can be used as an aid to manipulate
	 * video and audio. You must at the very least have FFMPEG compiled on your server. If you wish to use this class for FLV
	 * manipulation you must compile FFMPEG with LAME and Ruby's FLVTOOL2. I cannot answer questions regarding the install of
	 * the server binaries needed by this class. I had too learn the hard way and it isn't easy, however it is a good learning
	 * experience. For those of you who do need help read the install.txt file supplied along side this class. It wasn't written
	 * by me however I found it useful when installing ffmpeg for the first time. The original source for the install.txt file
	 * is located http://www.luar.com.hk/blog/?p=669 and the author is Lunar.
	 *
	 * @see install.txt
	 *
	 * @uses ffmpeg http://ffmpeg.sourceforge.net/
	 * @uses lame http://lame.sourceforge.net/
	 * @uses flvtool2 http://www.inlet-media.de/flvtool2 (and ruby http://www.ruby-lang.org/en/)
	 *
	 * @config examples/example-config.php Please edit this files in order for the examples to work.
	 * @example examples/example01.php Converts video to Flash Video (ie FLV).
	 * @example examples/example02.php Screen grabs video frames.
	 * @example examples/example03.php Compile a movie from multiple jpegs
	 * @example examples/example04.php Watermark a video.
	 * @example examples/example05.php Access media metadata without using the ffmpeg-php library.
	 * @example examples/example06.php Extract audio from video.
	 * @example examples/example07.php Join multiple videos together.
	 * @example examples/example08.php Easy video conversion to common formats using the adapters.
	 * @example examples/example09.php Shows you how to access the information about your ffmpeg installation.
	 * @example examples/example10.php Shows you how to extract a specific frame from a movie.
	 * @example examples/example11.php Shows you how to use the ffmpeg-php adapters to provide a pure php emulation of ffmpeg-php.
	 * @example examples/example12.php Shows you how to manipulate/format timecode strings.
	 * @example examples/example13.php This demonstrates how to simply create a FLV stream script.
	 */

	/**
	 * Set the ffmpeg binary path
	 */
	if(!defined('PHPVIDEOTOOLKIT_FFMPEG_BINARY'))
	{
		define('PHPVIDEOTOOLKIT_FFMPEG_BINARY', '/usr/local/bin/ffmpeg');
	}
	/**
	 * Set the flvtool2 binary path
	 */
	if(!defined('PHPVIDEOTOOLKIT_FLVTOOLS_BINARY'))
	{
		define('PHPVIDEOTOOLKIT_FLVTOOLS_BINARY', '/usr/bin/flvtool2');
	}
	/**
	 * Set the watermark vhook path
	 */
	if(!defined('PHPVIDEOTOOLKIT_FFMPEG_WATERMARK_VHOOK'))
	{
		define('PHPVIDEOTOOLKIT_FFMPEG_WATERMARK_VHOOK', '/usr/local/lib/vhook/watermark.so');
	}
	/**
	 * Set the memcoder path
	 */
	if(!defined('PHPVIDEOTOOLKIT_MENCODER_BINARY'))
	{
		define('PHPVIDEOTOOLKIT_MENCODER_BINARY', '/usr/local/bin/mencoder');
	}
	
	/**
	* Codec support constants
	*/
   define('PHPVIDEOTOOLKIT_ENCODE', 'encode');
   define('PHPVIDEOTOOLKIT_DECODE', 'decode'); 
		
	/**
	 * Process Results from PHPVideoToolkit::execute
	 */
// 	any return value with this means everything is ok
	define('PHPVIDEOTOOLKIT_RESULT_OK', true);
// 	any return value with this means the file has been processed/converted ok however it was 
// 	not able to be written to the output address. If this occurs you will need to move the
// 	processed file manually from the temp location
	define('PHPVIDEOTOOLKIT_RESULT_OK_BUT_UNWRITABLE', -1);
	
	/**
	 * Overwrite constants used in setOutput
	 */
	define('PHPVIDEOTOOLKIT_OVERWRITE_FAIL', 'fail');
	define('PHPVIDEOTOOLKIT_OVERWRITE_PRESERVE', 'preserve');
	define('PHPVIDEOTOOLKIT_OVERWRITE_EXISTING', 'existing');
	define('PHPVIDEOTOOLKIT_OVERWRITE_UNIQUE', 'unique');
	
	/**
	 * Formats supported
	 * 3g2             3gp2 format
	 * 3gp             3gp format
	 * aac             ADTS AAC
	 * aiff            Audio IFF
	 * amr             3gpp amr file format
	 * asf             asf format
	 * avi             avi format
	 * flv             flv format
	 * gif             GIF Animation
	 * mov             mov format
	 * mov,mp4,m4a,3gp,3g2,mj2 QuickTime/MPEG4/Motion JPEG 2000 format
	 * mp2             MPEG audio layer 2
	 * mp3             MPEG audio layer 3
	 * mp4             mp4 format
	 * mpeg            MPEG1 System format
	 * mpeg1video      MPEG video
	 * mpeg2video      MPEG2 video
	 * mpegvideo       MPEG video
	 * psp             psp mp4 format
	 * rm              rm format
	 * swf             Flash format
	 * vob             MPEG2 PS format (VOB)
	 * wav             wav format
	 * jpeg            mjpeg format
	 * yuv4mpegpipe    yuv4mpegpipe format
	 */
	define('PHPVIDEOTOOLKIT_FORMAT_3GP2', '3g2');
	define('PHPVIDEOTOOLKIT_FORMAT_3GP', '3gp');
	define('PHPVIDEOTOOLKIT_FORMAT_AAC', 'aac');
	define('PHPVIDEOTOOLKIT_FORMAT_AIFF', 'aiff');
	define('PHPVIDEOTOOLKIT_FORMAT_AMR', 'amr');
	define('PHPVIDEOTOOLKIT_FORMAT_ASF', 'asf');
	define('PHPVIDEOTOOLKIT_FORMAT_AVI', 'avi');
	define('PHPVIDEOTOOLKIT_FORMAT_FLV', 'flv');
	define('PHPVIDEOTOOLKIT_FORMAT_GIF', 'gif');
	define('PHPVIDEOTOOLKIT_FORMAT_MJ2', 'mj2');
	define('PHPVIDEOTOOLKIT_FORMAT_MP2', 'mp2');
	define('PHPVIDEOTOOLKIT_FORMAT_MP3', 'mp3');
	define('PHPVIDEOTOOLKIT_FORMAT_MP4', 'mp4');
	define('PHPVIDEOTOOLKIT_FORMAT_MPEG4', 'mpeg4');
	define('PHPVIDEOTOOLKIT_FORMAT_M4A', 'm4a');
	define('PHPVIDEOTOOLKIT_FORMAT_MPEG', 'mpeg');
	define('PHPVIDEOTOOLKIT_FORMAT_MPEG1', 'mpeg1video');
	define('PHPVIDEOTOOLKIT_FORMAT_MPEG2', 'mpeg2video');
	define('PHPVIDEOTOOLKIT_FORMAT_MPEGVIDEO', 'mpegvideo');
	define('PHPVIDEOTOOLKIT_FORMAT_PSP', 'psp');
	define('PHPVIDEOTOOLKIT_FORMAT_RM', 'rm');
	define('PHPVIDEOTOOLKIT_FORMAT_SWF', 'swf');
	define('PHPVIDEOTOOLKIT_FORMAT_VOB', 'vob');
	define('PHPVIDEOTOOLKIT_FORMAT_WAV', 'wav');
	define('PHPVIDEOTOOLKIT_FORMAT_JPG', 'mjpeg');
	define('PHPVIDEOTOOLKIT_FORMAT_Y4MP', 'yuv4mpegpipe');
	
	/**
	 * Size Presets
	 */
	define('PHPVIDEOTOOLKIT_SIZE_SAS', 'SameAsSource');
	define('PHPVIDEOTOOLKIT_SIZE_SQCIF', '128x96');
	define('PHPVIDEOTOOLKIT_SIZE_QCIF', '176x144');
	define('PHPVIDEOTOOLKIT_SIZE_CIF', '352x288');
	define('PHPVIDEOTOOLKIT_SIZE_4CIF', '704x576');
	define('PHPVIDEOTOOLKIT_SIZE_QQVGA', '160x120');
	define('PHPVIDEOTOOLKIT_SIZE_QVGA', '320x240');
	define('PHPVIDEOTOOLKIT_SIZE_VGA', '640x480');
	define('PHPVIDEOTOOLKIT_SIZE_SVGA', '800x600');
	define('PHPVIDEOTOOLKIT_SIZE_XGA', '1024x768');
	define('PHPVIDEOTOOLKIT_SIZE_UXGA', '1600x1200');
	define('PHPVIDEOTOOLKIT_SIZE_QXGA', '2048x1536');
	define('PHPVIDEOTOOLKIT_SIZE_SXGA', '1280x1024');
	define('PHPVIDEOTOOLKIT_SIZE_QSXGA', '2560x2048');
	define('PHPVIDEOTOOLKIT_SIZE_HSXGA', '5120x4096');
	define('PHPVIDEOTOOLKIT_SIZE_WVGA', '852x480');
	define('PHPVIDEOTOOLKIT_SIZE_WXGA', '1366x768');
	define('PHPVIDEOTOOLKIT_SIZE_WSXGA', '1600x1024');
	define('PHPVIDEOTOOLKIT_SIZE_WUXGA', '1920x1200');
	define('PHPVIDEOTOOLKIT_SIZE_WOXGA', '2560x1600');
	define('PHPVIDEOTOOLKIT_SIZE_WQSXGA', '3200x2048');
	define('PHPVIDEOTOOLKIT_SIZE_WQUXGA', '3840x2400');
	define('PHPVIDEOTOOLKIT_SIZE_WHSXGA', '6400x4096');
	define('PHPVIDEOTOOLKIT_SIZE_WHUXGA', '7680x4800');
	define('PHPVIDEOTOOLKIT_SIZE_CGA', '320x200');
	define('PHPVIDEOTOOLKIT_SIZE_EGA', '640x350');
	define('PHPVIDEOTOOLKIT_SIZE_HD480', '852x480');
	define('PHPVIDEOTOOLKIT_SIZE_HD720', '1280x720');
	define('PHPVIDEOTOOLKIT_SIZE_HD1080', '1920x1080');
	
	/**
	 * Ratio Presets
	 */
	define('PHPVIDEOTOOLKIT_RATIO_STANDARD', '4:3');
	define('PHPVIDEOTOOLKIT_RATIO_WIDE', '16:9');
	define('PHPVIDEOTOOLKIT_RATIO_CINEMATIC', '1.85');

	/**
	 * @author Oliver Lillie (aka buggedcom) <publicmail@buggedcom.co.uk>
	 * @license BSD
	 * @package PHPVideoToolkit (was called ffmpeg)
	 */
	class PHPVideoToolkit
	{
		
		var $version = '0.1.5';
		
		/**
		 * Error strings
		 */
		var $_messages = array(
			
			'generic_temp_404' 								=> 'The temporary directory does not exist.',
			'generic_temp_writable' 						=> 'The temporary directory is not write-able by the web server.',
			
			'getFileInfo_no_input' 							=> 'Input file does not exist so no information can be retrieved.',
			'setInputFile_file_existence' 					=> 'Input file "#file" does not exist',
			'extractAudio_valid_format' 					=> 'Value "#format" set from $toolkit->extractAudio, is not a valid audio format. Valid values ffmpeg PHPVIDEOTOOLKIT_FORMAT_AAC, PHPVIDEOTOOLKIT_FORMAT_AIFF, PHPVIDEOTOOLKIT_FORMAT_MP2, PHPVIDEOTOOLKIT_FORMAT_MP3, PHPVIDEOTOOLKIT_FORMAT_MP4, PHPVIDEOTOOLKIT_FORMAT_MPEG4, PHPVIDEOTOOLKIT_FORMAT_M4A or PHPVIDEOTOOLKIT_FORMAT_WAV. If you wish to specifically try to set another format you should use the advanced function $toolkit->addCommand. Set $command to "-f" and $argument to your required value.',
			'extractFrame_video_frame_rate_404' 			=> 'You have attempted to extract a thumbnail from a video while automagically guessing the framerate of the video, but the framerate could not be accessed. You can remove this error by manually setting the frame rate of the video.',
			'extractFrame_video_info_404' 					=> 'You have attempted to extract a thumbnail from a video and check to see if the thumbnail exists, however it was not possible to access the video information. Please check your temporary directory permissions for read/write access by the webserver.',
			'extractFrame_video_frame_count' 				=> 'You have attempted to extract a thumbnail from a video but the thumbnail you are trying to extract does not exist in the video.',
			'extractFrames_video_begin_frame_count' 		=> 'You have attempted to extract thumbnails from a video but the thumbnail you are trying to start the extraction from does not exist in the video.',
			'extractFrames_video_end_frame_count' 			=> 'You have attempted to extract thumbnails from a video but the thumbnail you are trying to end the extraction at does not exist in the video.',
			'setFormat_valid_format' 						=> 'Value "#format" set from $toolkit->setFormat, is not a valid format. Valid values are PHPVIDEOTOOLKIT_FORMAT_3GP2, PHPVIDEOTOOLKIT_FORMAT_3GP, PHPVIDEOTOOLKIT_FORMAT_AAC, PHPVIDEOTOOLKIT_FORMAT_AIFF, PHPVIDEOTOOLKIT_FORMAT_AMR, PHPVIDEOTOOLKIT_FORMAT_ASF, PHPVIDEOTOOLKIT_FORMAT_AVI, PHPVIDEOTOOLKIT_FORMAT_FLV, PHPVIDEOTOOLKIT_FORMAT_GIF, PHPVIDEOTOOLKIT_FORMAT_MJ2, PHPVIDEOTOOLKIT_FORMAT_MP2, PHPVIDEOTOOLKIT_FORMAT_MP3, PHPVIDEOTOOLKIT_FORMAT_MP4, PHPVIDEOTOOLKIT_FORMAT_MPEG4, PHPVIDEOTOOLKIT_FORMAT_M4A, PHPVIDEOTOOLKIT_FORMAT_MPEG, PHPVIDEOTOOLKIT_FORMAT_MPEG1, PHPVIDEOTOOLKIT_FORMAT_MPEG2, PHPVIDEOTOOLKIT_FORMAT_MPEGVIDEO, PHPVIDEOTOOLKIT_FORMAT_PSP, PHPVIDEOTOOLKIT_FORMAT_RM, PHPVIDEOTOOLKIT_FORMAT_SWF, PHPVIDEOTOOLKIT_FORMAT_VOB, PHPVIDEOTOOLKIT_FORMAT_WAV, PHPVIDEOTOOLKIT_FORMAT_JPG. If you wish to specifically try to set another format you should use the advanced function $toolkit->addCommand. Set $command to "-f" and $argument to your required value.',
			'setAudioSampleFrequency_valid_frequency' 		=> 'Value "#frequency" set from $toolkit->setAudioSampleFrequency, is not a valid integer. Valid values are 11025, 22050, 44100. If you wish to specifically try to set another frequency you should use the advanced function $toolkit->addCommand. Set $command to "-ar" and $argument to your required value.',
			'setAudioFormat_valid_format' 					=> 'Value "#format" set from $toolkit->setAudioFormat, is not a valid format. Valid values are PHPVIDEOTOOLKIT_FORMAT_AAC, PHPVIDEOTOOLKIT_FORMAT_AIFF, PHPVIDEOTOOLKIT_FORMAT_AMR, PHPVIDEOTOOLKIT_FORMAT_ASF, PHPVIDEOTOOLKIT_FORMAT_MP2, PHPVIDEOTOOLKIT_FORMAT_MP3, PHPVIDEOTOOLKIT_FORMAT_MP4, PHPVIDEOTOOLKIT_FORMAT_MPEG2, PHPVIDEOTOOLKIT_FORMAT_RM, PHPVIDEOTOOLKIT_FORMAT_WAV. If you wish to specifically try to set another format you should use the advanced function $toolkit->addCommand. Set $command to "-acodec" and $argument to your required value.',
			'setVideoFormat_valid_format' 					=> 'Value "#format" set from $toolkit->setAudioFormat, is not a valid format. Valid values are PHPVIDEOTOOLKIT_FORMAT_3GP2, PHPVIDEOTOOLKIT_FORMAT_3GP, PHPVIDEOTOOLKIT_FORMAT_AVI, PHPVIDEOTOOLKIT_FORMAT_FLV, PHPVIDEOTOOLKIT_FORMAT_GIF, PHPVIDEOTOOLKIT_FORMAT_MJ2, PHPVIDEOTOOLKIT_FORMAT_MP4, PHPVIDEOTOOLKIT_FORMAT_MPEG4, PHPVIDEOTOOLKIT_FORMAT_M4A, PHPVIDEOTOOLKIT_FORMAT_MPEG, PHPVIDEOTOOLKIT_FORMAT_MPEG1, PHPVIDEOTOOLKIT_FORMAT_MPEG2, PHPVIDEOTOOLKIT_FORMAT_MPEGVIDEO. If you wish to specifically try to set another format you should use the advanced function $toolkit->addCommand. Set $command to "-vcodec" and $argument to your required value.',
			'setAudioBitRate_valid_bitrate' 				=> 'Value "#bitrate" set from $toolkit->setAudioBitRate, is not a valid integer. Valid values are 16, 32, 64, 128. If you wish to specifically try to set another bitrate you should use the advanced function $toolkit->addCommand. Set $command to "-ab" and $argument to your required value.',
			'prepareImagesForConversionToVideo_one_img' 	=> 'When compiling a movie from a series of images, you must include at least one image.',
			'prepareImagesForConversionToVideo_img_404' 	=> '"#img" does not exist.',
			'prepareImagesForConversionToVideo_img_copy' 	=> '"#img" can not be copied to "#tmpfile"',
			'prepareImagesForConversionToVideo_img_type' 	=> 'The images can not be prepared for conversion to video. Please make sure all images are of the same type, ie gif, png, jpeg and then try again.',
			'setVideoOutputDimensions_valid_format' 		=> 'Value "#format" set from $toolkit->setVideoOutputDimensions, is not a valid preset dimension. Valid values are PHPVIDEOTOOLKIT_SIZE_SQCIF, PHPVIDEOTOOLKIT_SIZE_SAS, PHPVIDEOTOOLKIT_SIZE_QCIF, PHPVIDEOTOOLKIT_SIZE_CIF, PHPVIDEOTOOLKIT_SIZE_4CIF, PHPVIDEOTOOLKIT_SIZE_QQVGA, PHPVIDEOTOOLKIT_SIZE_QVGA, PHPVIDEOTOOLKIT_SIZE_VGA, PHPVIDEOTOOLKIT_SIZE_SVGA, PHPVIDEOTOOLKIT_SIZE_XGA, PHPVIDEOTOOLKIT_SIZE_UXGA, PHPVIDEOTOOLKIT_SIZE_QXGA, PHPVIDEOTOOLKIT_SIZE_SXGA, PHPVIDEOTOOLKIT_SIZE_QSXGA, PHPVIDEOTOOLKIT_SIZE_HSXGA, PHPVIDEOTOOLKIT_SIZE_WVGA, PHPVIDEOTOOLKIT_SIZE_WXGA, PHPVIDEOTOOLKIT_SIZE_WSXGA, PHPVIDEOTOOLKIT_SIZE_WUXGA, PHPVIDEOTOOLKIT_SIZE_WOXGA, PHPVIDEOTOOLKIT_SIZE_WQSXGA, PHPVIDEOTOOLKIT_SIZE_WQUXGA, PHPVIDEOTOOLKIT_SIZE_WHSXGA, PHPVIDEOTOOLKIT_SIZE_WHUXGA, PHPVIDEOTOOLKIT_SIZE_CGA, PHPVIDEOTOOLKIT_SIZE_EGA, PHPVIDEOTOOLKIT_SIZE_HD480, PHPVIDEOTOOLKIT_SIZE_HD720, PHPVIDEOTOOLKIT_SIZE_HD1080. You can also manually set the width and height.',
			'setVideoOutputDimensions_sas_dim' 				=> 'It was not possible to determine the input video dimensions so it was not possible to continue. If you wish to override this error please change the call to setVideoOutputDimensions and add a true argument to the arguments list... setVideoOutputDimensions(PHPVIDEOTOOLKIT_SIZE_SAS, true);',
			'setVideoOutputDimensions_valid_integer' 		=> 'You tried to set the video output dimensions to an odd number. FFmpeg requires that the video output dimensions are of event value and divisible by 2. ie 2, 4, 6,... etc',
			'setVideoAspectRatio_valid_ratio' 				=> 'Value "#ratio" set from $toolkit->setVideoOutputDimensions, is not a valid preset dimension. Valid values are PHPVIDEOTOOLKIT_RATIO_STANDARD, PHPVIDEOTOOLKIT_RATIO_WIDE, PHPVIDEOTOOLKIT_RATIO_CINEMATIC. If you wish to specifically try to set another video aspect ratio you should use the advanced function $toolkit->addCommand. Set $command to "-aspect" and $argument to your required value.',
			'addWatermark_img_404' 							=> 'Watermark file "#watermark" does not exist.',
			'addWatermark_vhook_disabled' 					=> 'Vhooking is not enabled in your FFmpeg binary. In order to allow video watermarking you must have FFmpeg compiled with --enable-vhook set. You can however watermark any extracted images using GD. To enable frame watermarking, call $toolkit->addGDWatermark($file) before you execute the extraction.',
			'addVideo_file_404' 							=> 'File "#file" does not exist.',
			'setOutput_output_dir_404' 						=> 'Output directory "#dir" does not exist!',
			'setOutput_output_dir_writable' 				=> 'Output directory "#dir" is not writable!',
			'setOutput_%_missing' 							=> 'The output of this command will be images yet you have not included the "%index" or "%timecode" in the $output_name.',
			'setOutput_%d_depreciated' 						=> 'The use of %d in the output file name is now depreciated. Please use %index. Number padding is still supported. You may also use %timecode instead to add a timecode to the filename.',
			'execute_input_404' 							=> 'Execute error. Input file missing.',
			'execute_output_not_set' 						=> 'Execute error. Output not set.',
			'execute_overwrite_process' 					=> 'Execute error. A file exists in the temp directory and is of the same name as this process file. It will conflict with this conversion. Conversion stopped.',
			'execute_overwrite_fail' 						=> 'Execute error. Output file exists. Process halted. If you wish to automatically overwrite files set the third argument in "PHPVideoToolkit::setOutput();" to "PHPVIDEOTOOLKIT_OVERWRITE_EXISTING".',
			'execute_partial_error' 						=> 'Execute error. Output for file "#input" encountered a partial error. Files were generated, however one or more of them were empty.',
			'execute_image_error' 							=> 'Execute error. Output for file "#input" was not found. No images were generated.',
			'execute_output_404' 							=> 'Execute error. Output for file "#input" was not found. Please check server write permissions and/or available codecs compiled with FFmpeg. You can check the encode decode availability by inspecting the output array from PHPVideoToolkit::getFFmpegInfo().',
			'execute_output_empty' 							=> 'Execute error. Output for file "#input" was found, but the file contained no data. Please check the available codecs compiled with FFmpeg can support this type of conversion. You can check the encode decode availability by inspecting the output array from PHPVideoToolkit::getFFmpegInfo().',
			'execute_image_file_exists'						=> 'Execute error. There is a file name conflict. The file "#file" already exists in the filesystem. If you wish to automatically overwrite files set the third argument in "PHPVideoToolkit::setOutput();" to "PHPVIDEOTOOLKIT_OVERWRITE_EXISTING".',
			'execute_result_ok_but_unwritable'				=> 'Process Partially Completed. The process successfully completed however it was not possible to output to "#output". The output was left in the temp directory "#process" for a manual file movement.',
			'execute_result_ok'								=> 'Process Completed. The process successfully completed. Output was generated to "#output".',
			
			'ffmpeg_log_ffmpeg_output'						=> 'OUTPUT',
			'ffmpeg_log_ffmpeg_result'						=> 'RESULT',
			'ffmpeg_log_ffmpeg_command'						=> 'COMMAND',
			'ffmpeg_log_ffmpeg_join_gunk'					=> 'FFMPEG JOIN OUTPUT',
			'ffmpeg_log_ffmpeg_gunk'						=> 'FFMPEG OUTPUT',
			'ffmpeg_log_separator'							=> '-------------------------------'
			
		);
		
		/**
		 * A public var that is to the information available about
		 * the current ffmpeg compiled binary.
		 * @var mixed
		 * @access public
		 */
		var $ffmpeg_info		= false;

		/**
		 * A private var that contains the info of any file that is accessed by PHPVideoToolkit::getFileInfo();
		 * @var array
		 * @access private
		 */
		var $_file_info		= array();

		/**
		 * Determines what happens when an error occurs
		 * @var boolean If true then the script will die, if not false is return by the error
		 * @access public
		 */
		var $on_error_die			= false;

		/**
		 * Holds the log file name
		 * @var string
		 * @access private
		 */
		var $_log_file				= null;

		/**
		 * Determines if when outputting image frames if the outputted files should have the %d number
		 * replaced with the frames timecode.
		 * @var boolean If true then the files will be renamed.
		 * @access public
		 */
		var $image_output_timecode 	= true;

		/**
		 * Holds the timecode separator for when using $image_output_timecode = true
		 * Not all systems allow ':' in filenames.
		 * @var string
		 * @access public
		 */
		var $timecode_seperator_output = '-';

		/**
		 * Holds the starting time code when outputting image frames.
		 * @var string The timecode hh(n):mm:ss:ff
		 * @access private
		 */
		var $_image_output_timecode_start = '00:00:00.00';

		/**
		 * The format in which the image %timecode placeholder string is outputted.
		 * 	- %hh (hours) representative of hours
		 * 	- %mm (minutes) representative of minutes
		 * 	- %ss (seconds) representative of seconds
		 * 	- %fn (frame number) representative of frames (of the current second, not total frames)
		 * 	- %ms (milliseconds) representative of milliseconds (of the current second, not total milliseconds) (rounded to 3 decimal places)
		 * 	- %ft (frames total) representative of total frames (ie frame number)
		 * 	- %st (seconds total) representative of total seconds (rounded).
		 * 	- %sf (seconds floored) representative of total seconds (floored).
		 * 	- %mt (milliseconds total) representative of total milliseconds. (rounded to 3 decimal places)
		 * NOTE; there are special characters that will be replace by PHPVideoToolkit::$timecode_seperator_output, these characters are
		 * 	- :
		 *  - .
		 * @var string 
		 * @access public
		 */
		var $image_output_timecode_format = '%hh-%mm-%ss-%fn';

		/**
		 * Holds the fps of image extracts
		 * @var integer
		 * @access private
		 */
		var $_image_output_timecode_fps = 1;

		/**
		 * Holds the current execute commands that will need to be combined
		 * @var array
		 * @access private
		 */
		var $_commands 			= array();

		/**
		 * Holds the commands executed
		 * @var array
		 * @access private
		 */
		var $_processed 		= array();

		/**
		 * Holds the file references to those that have been processed
		 * @var array
		 * @access private
		 */
		var $_files	 			= array();

		/**
		 * Holds the errors encountered
		 * @access private
		 * @var array
		 */
		var $_errors 			= array();

		/**
		 * Holds the input file / input file sequence
		 * @access private
		 * @var string
		 */
		var $_input_file 		= null;

		/**
		 * Holds the output file / output file sequence
		 * @access private
		 * @var string
		 */
		var $_output_address 	= null;

		/**
		 * Holds the process file / process file sequence
		 * @access private
		 * @var string
		 */
		var $_process_address 	= null;

		/**
		 * Temporary filename prefix
		 * @access private
		 * @var string
		 */
		var $_tmp_file_prefix	= 'tmp_';

		/**
		 * Holds the temporary directory name
		 * @access private
		 * @var string
		 */
		var $_tmp_directory 	= null;

		/**
		 * Holds the directory paths that need to be removed by the ___destruct function
		 * @access private
		 * @var array
		 */
		var $_unlink_dirs		= array();

		/**
		 * Holds the file paths that need to be deleted by the ___destruct function
		 * @access private
		 * @var array
		 */
		var $_unlink_files		= array();

		/**
		 * Holds the timer start micro-float.
		 * @access private
		 * @var integer
		 */
		var $_timer_start		= 0;
		
		/**
		 * Holds the times taken to process each file.
		 * @access private
		 * @var array
		 */
		var $_timers			= array();

		/**
		 * Holds the times taken to process each file.
		 * @access private
		 * @var constant
		 */
		var $_overwrite_mode	= null;

		/**
		 * Holds a integer value that flags if the image extraction is just a single frame.
		 * @access private
		 * @var integer
		 */
		var $_single_frame_extraction	= null;

		/**
		 * Holds the watermark file that is used to watermark any outputted images via GD.
		 * @access private
		 * @var string
		 */
		var $_watermark_url	= null;

		/**
		 * Holds the watermark options used to watermark any outputted images via GD.
		 * @access private
		 * @var array
		 */
		var $_watermark_options	= null;

		/**
		 * Holds the number of files processed per run.
		 * @access private
		 * @var integer
		 */
		var $_process_file_count = 0;

		/**
		 * Holds the times taken to process each file.
		 * @access private
		 * @var array
		 */
		var $_post_processes	= array();
		
		/**
		 * Holds commands should be sent added to the exec before the input file, this is by no means a definitive list
		 * of all the ffmpeg commands, as it only utilizes the ones in use by this class. Also only commands that have 
		 * specific required places are entered in the arrays below. Anything not in these arrays will be treated as an 
		 * after-input item.
		 * @access private
		 * @var array
		 */
// 		var $_cmds_before_input		= array();
		var $_cmds_before_input		= array('-inputr');
// 		var $_cmds_before_input		= array('-r', '-f');

		/**
		 * Constructs the class and sets the temporary directory.
		 *
		 * @access private
		 * @param string $tmp_directory A full absolute path to you temporary directory
		 */
		function PHPVideoToolkit($tmp_directory='/tmp/')
		{
			$this->_tmp_directory = $tmp_directory;
// 			emulate php5 destructors
    		register_shutdown_function(array(&$this, '__destruct'));
		}
		
		function microtimeFloat()
		{
		    list($usec, $sec) = explode(" ", microtime());
		    return ((float) $usec + (float) $sec);
		}

		/**
		 * Resets the class
		 *
		 * @access public
		 * @param boolean $keep_input_file Determines whether or not to reset the input file currently set.
		 */
		function reset($keep_input_file=false, $keep_processes=false)
		{
			if($keep_input_file === false)
			{
				$this->_input_file = null;
			}
			if($keep_processes === false)
			{
				$this->_post_processes = array();
			}
			$this->_single_frame_extraction = null;
			$this->_output_address = null;
			$this->_process_address = null;
			$this->_log_file = null;
			$this->_commands = array();
			$this->_timer_start = 0;
			$this->_process_file_count = 0;
			$this->__destruct();
		}

		/**
		 * Returns information about the specified file without having to use ffmpeg-php
		 * as it consults the ffmpeg binary directly. 
		 * 
		 * @access public
		 * @param string $file The absolute path of the file that is required to be manipulated.
		 * @return mixed false on error encountered, true otherwise
		 **/
		function getFFmpegInfo()
		{
// 			check to see if this is a static call
			if(!$this)
			{     
				$toolkit = new PHPVideoToolkit($tmp_directory);
				return $toolkit->getFFmpegInfo();
			}
// 			check to see if the info has already been cached
			if($this->ffmpeg_info !== false)
			{
				return $this->ffmpeg_info;
			}
// 			check to see if this is a static call
			$format = '';
			$info_file = $this->_tmp_directory.$this->unique('ffinfo').'.info';
// 			execute the ffmpeg lookup
// 			exec(PHPVIDEOTOOLKIT_FFMPEG_BINARY.' -formats &> '.$info_file);
			exec(PHPVIDEOTOOLKIT_FFMPEG_BINARY.' -formats 2>&1', $buffer);
			$buffer = implode("\r\n", $buffer);
			
// 			$data = false;
// 			try to open the file
// 			$handle = fopen($info_file, 'r');
// 			if($handle)
// 			{
// 				$data = array();
// 				$buffer = '';
// // 				loop through the lines of data and collect the buffer
// 			    while (!feof($handle))
// 				{
// 			        $buffer .= fgets($handle, 4096);
// 				}
// 				echo($buffer);
				$data['compiler'] = array();
				$look_ups = array('configuration'=>'configuration: ', 'formats'=>'File formats:', 'codecs'=>'Codecs:', 'filters'=>'Bitstream filters:', 'protocols'=>'Supported file protocols:', 'abbreviations'=>'Frame size, frame rate abbreviations:', 'Note:');
				$total_lookups = count($look_ups);
				$pregs = array();
				$indexs = array();
				foreach($look_ups as $key=>$reg)
				{
					if(strpos($buffer, $reg) !== false)
					{
						$index = array_push($pregs, $reg);
						$indexs[$key] = $index;
					}
				}
				preg_match('/'.implode('(.*)', $pregs).'/s', $buffer, $matches);
				$configuration = trim($matches[$indexs['configuration']]);
// 				grab the ffmpeg configuration flags
				preg_match_all('/--[a-zA-Z0-9\-]+/', $configuration, $config_flags);
				$data['compiler']['configuration'] = $config_flags[0];
				$data['compiler']['vhook-support'] = in_array('--enable-vhook', $config_flags[0]) && !in_array('--disable-vhook', $config_flags[0]);
// 				grab the versions
				$data['compiler']['versions'] = array();
				preg_match_all('/([a-zA-Z0-9\-]+) version: ([0-9\.]+)/', $configuration, $versions);
				for($i=0, $a=count($versions[0]); $i<$a; $i++)
				{
					$data['compiler']['versions'][strtolower(trim($versions[1][$i]))] = $versions[2][$i];
				}
// 				grab the ffmpeg compile info
				preg_match('/built on (.*), gcc: (.*)/', $configuration, $conf);
				if(count($conf) > 0)
				{
					$data['compiler']['gcc'] = $conf[2];
					$data['compiler']['build_date'] = $conf[1];
					$data['compiler']['build_date_timestamp'] = strtotime($conf[1]);
				}
// 				grab the file formats available to ffmpeg
				preg_match_all('/ (DE|D|E) (.*) {1,} (.*)/', trim($matches[$indexs['formats']]), $formats);
				$data['formats'] = array();
// 				loop and clean
				for($i=0, $a=count($formats[0]); $i<$a; $i++)
				{
					$data['formats'][strtolower(trim($formats[2][$i]))] = array(
						'encode' 	=> $formats[1][$i] == 'DE' || $formats[1][$i] == 'E',
						'decode' 	=> $formats[1][$i] == 'DE' || $formats[1][$i] == 'D',
						'fullname'	=> $formats[3][$i]
					);
				}
// 				grab the bitstream filters available to ffmpeg
				$data['filters'] = array();
				if(isset($indexs['filters']) && isset($matches[$indexs['filters']]))
				{
					$filters = trim($matches[$indexs['filters']]);
					if(empty($filters))
					{
						$data['filters'] = explode(' ', $filters);
					}
				}
// 				grab the file prototcols available to ffmpeg
				$data['filters'] = array();
				if(isset($indexs['protocols']) && isset($matches[$indexs['protocols']]))
				{
					$protocols = trim($matches[$indexs['protocols']]);
					if(empty($protocols))
					{
						$data['protocols'] = explode(' ', str_replace(':', '', $protocols));
					}
				}
// 				grab the abbreviations available to ffmpeg
				$data['abbreviations'] = array();
				if(isset($indexs['abbreviations']) && isset($matches[$indexs['abbreviations']]))
				{
					$abbreviations = trim($matches[$indexs['abbreviations']]);
					if(empty($abbreviations))
					{
						$data['abbreviations'] = explode(' ', $abbreviations);
					}
				}
				$this->ffmpeg_info = $data;
			}
// 			fclose($handle);
// 			if(is_file($info_file))
// 			{
// //	 			if the info file exists remove it
// 				unlink($info_file);
// 			}
			$data['ffmpeg-php-support'] = $this->hasFFmpegPHPSupport();
			return $data;
			
		}
		
		/**
		 * Determines the type of support that exists for the FFmpeg-PHP module.
		 * 
		 * @access public
		 * @return mixed. Boolean false if there is no support, String 'module' if the actuall
		 * 		FFmpeg-PHP module is loaded, or String 'emulated' if the FFmpeg-PHP classes
		 * 		can be emulated through the adapter classes.
		 */
		function hasFFmpegPHPSupport()
		{
			return extension_loaded('ffmpeg') ? 'module' : (is_file(dirname(__FILE__).DIRECTORY_SEPARATOR.'adapters'.DIRECTORY_SEPARATOR.'ffmpeg-php'.DIRECTORY_SEPARATOR.'ffmpeg_movie.php') && is_file(dirname(__FILE__).DIRECTORY_SEPARATOR.'adapters'.DIRECTORY_SEPARATOR.'ffmpeg-php'.DIRECTORY_SEPARATOR.'ffmpeg_frame.php') && is_file(dirname(__FILE__).DIRECTORY_SEPARATOR.'adapters'.DIRECTORY_SEPARATOR.'ffmpeg-php'.DIRECTORY_SEPARATOR.'ffmpeg_animated_gif.php') ? 'emulated' : false);
		}
		
		/**
		 * Determines if the ffmpeg binary has been compiled with vhook support.
		 * 
		 * @access public
		 * @return mixed. Boolean false if there is no support, true there is support.
		 */
		function hasVHookSupport()
		{
			$info = $this->getFFmpegInfo();
			return $info['compiler']['vhook-support'];
		}
		
		/**
		 * Returns information about the specified file without having to use ffmpeg-php
		 * as it consults the ffmpeg binary directly. This idea for this function has been borrowed from
		 * a French ffmpeg class located: http://www.phpcs.com/codesource.aspx?ID=45279
		 * 
		 * @access public
		 * @todo Change the search from string explode to a regex based search
		 * @param string $file The absolute path of the file that is required to be manipulated.
		 * @return mixed false on error encountered, true otherwise
		 **/
		function getFileInfo($file=false, $tmp_directory='/tmp/')
		{
// 			check to see if this is a static call
			if($file !== false && !$this)
			{     
				$toolkit = new PHPVideoToolkit($tmp_directory);
				return $toolkit->getFileInfo($file);
			}
// 			if the file has not been specified check to see if an input file has been specified
			if($file === false)
			{
				if(!$this->_input_file)
				{
//					input file not valid
					return $this->_raiseError('getFileInfo_no_input');
//<-				exits
				}
				$file = $this->_input_file;
			}
			$file = escapeshellarg($file);
// 			die($file);
// 			create a hash of the filename
			$hash = md5($file);
// 			check to see if the info has already been generated
			if(isset($this->_file_info[$hash]))
			{
				return $this->_file_info[$hash];
			}
// 			generate a random filename
			$info_file = $this->_tmp_directory.$this->unique($hash).'.info';
			
// 			execute the ffmpeg lookup
// 			exec(PHPVIDEOTOOLKIT_FFMPEG_BINARY.' -i '.$file.' &> '.$info_file);
			exec(PHPVIDEOTOOLKIT_FFMPEG_BINARY.' -i '.$file.' 2>&1', $buffer);
			$buffer = implode("\r\n", $buffer);
			
// 			$data = false;
// // 			try to open the file
// 			$handle = fopen($info_file, 'r');
// 			if($handle)
// 			{
// 				$data = array();
// 				$buffer = '';
// // 				loop through the lines of data and collect the buffer
// 			    while (!feof($handle))
// 				{
// 			        $buffer .= fgets($handle, 4096);
// 				}
// die($buffer);
// 				grab the duration and bitrate data
				preg_match_all('/Duration: (.*)/', $buffer, $matches);
				if(count($matches) > 0)
				{
					$parts 								= explode(', ', trim($matches[1][0]));
					$data['duration']					= array();
					$timecode					 		= $parts[0];
					$data['duration']['seconds'] 		= $this->timecodeToSeconds($timecode);
					$data['bitrate']  					= intval(ltrim($parts[2], 'bitrate: '));
					$data['duration']['start']  		= ltrim($parts[1], 'start: ');
					$data['duration']['timecode']		= array();
					$data['duration']['timecode']['rounded'] = substr($timecode, 0, 8);
					$data['duration']['timecode']['seconds'] = array();
					$data['duration']['timecode']['seconds']['exact']   = $timecode;
					$data['duration']['timecode']['seconds']['excess']  = intval(substr($timecode, 9));
				}
				
// 				match the video stream info
				preg_match('/Stream(.*): Video: (.*)/', $buffer, $matches);
				if(count($matches) > 0)
				{
					$data['video'] 						= array();
// 					get the dimension parts
// print_r($matches);
					preg_match('/([0-9]{1,5})x([0-9]{1,5})/', $matches[2], $dimensions_matches);
// 					print_r($dimensions_matches);
					$dimensions_value = $dimensions_matches[0];
					$data['video']['dimensions'] 	= array(
						'width' 					=> floatval($dimensions_matches[1]),
						'height' 					=> floatval($dimensions_matches[2])
					);
// 					get the framerate
					preg_match('/([0-9\.]+) (fps|tb)\(r\)/', $matches[0], $fps_matches);
					$data['video']['frame_rate'] 	= floatval($fps_matches[1]);
					$fps_value = $fps_matches[0];
// 					get the ratios
					preg_match('/\[PAR ([0-9\:\.]+) DAR ([0-9\:\.]+)\]/', $matches[0], $ratio_matches);
					if(count($ratio_matches))
					{
						$data['video']['pixel_aspect_ratio'] 	= $ratio_matches[1];
						$data['video']['display_aspect_ratio'] 	= $ratio_matches[2];
					}
// 					work out the number of frames
					if(isset($data['duration']) && isset($data['video']))
					{
// 						set the total frame count for the video
						$data['video']['frame_count'] 						= ceil($data['duration']['seconds'] * $data['video']['frame_rate']);
// 						set the framecode
						$frames												= ceil($data['video']['frame_rate']*($data['duration']['timecode']['seconds']['excess']/10));
						$data['duration']['timecode']['frames'] 			= array();
						$data['duration']['timecode']['frames']['exact']  	= $data['duration']['timecode']['rounded'].'.'.$frames;
						$data['duration']['timecode']['frames']['excess'] 	= $frames;
						$data['duration']['timecode']['frames']['total'] 	= $data['video']['frame_count'];
					}
// 					formats should be anything left over, let me know if anything else exists
					$parts 							= explode(',', $matches[2]);
					$other_parts 					= array($dimensions_value, $fps_value);
					$formats = array();
					foreach($parts as $key=>$part)
					{
						$part = trim($part);
						if(!in_array($part, $other_parts))
						{
							array_push($formats, $part);
						}
					}
					$data['video']['pixel_format'] 	= $formats[1];
					$data['video']['codec'] 		= $formats[0];
				}
				
// 				match the audio stream info
				preg_match('/Stream(.*): Audio: (.*)/', $buffer, $matches);
				if(count($matches) > 0)
				{
// 					setup audio values
					$data['audio'] = array(
						'stereo'		=> -1, 
						'sample_rate'	=> -1, 
						'sample_rate'	=> -1
					);
					$other_parts = array();
// 					get the stereo value
					preg_match('/(stereo|mono)/i', $matches[0], $stereo_matches);
					if(count($stereo_matches))
					{
						$data['audio']['stereo'] 		= $stereo_matches[0];
						array_push($other_parts, $stereo_matches[0]);
					}
// 					get the sample_rate
					preg_match('/([0-9]{3,6}) Hz/', $matches[0], $sample_matches);
					if(count($sample_matches))
					{
						$data['audio']['sample_rate'] 	= count($sample_matches) ? floatval($sample_matches[1]) : -1;
						array_push($other_parts, $sample_matches[0]);
					}
// 					get the bit rate
					preg_match('/([0-9]{1,3}) kb\/s/', $matches[0], $bitrate_matches);
					if(count($bitrate_matches))
					{
						$data['audio']['bitrate'] 		= count($bitrate_matches) ? floatval($bitrate_matches[1]) : -1;
						array_push($other_parts, $bitrate_matches[0]);
					}
// 					formats should be anything left over, let me know if anything else exists
					$parts 							= explode(',', $matches[2]);
					$formats = array();
					foreach($parts as $key=>$part)
					{
						$part = trim($part);
						if(!in_array($part, $other_parts))
						{
							array_push($formats, $part);
						}
					}
					$data['audio']['codec'] 		= $formats[0];
				}

//	 			check that some data has been obtained
				if(!count($data))
				{
					$data = false;
				}
				else
				{
					$data['_raw_info'] = $buffer;
				}
				
// 			    fclose($handle);
// 			}
// 			if(is_file($info_file))
// 			{
// //	 			if the info file exists remove it
// 				unlink($info_file);
// 			}
// 			cache info and return
			return $this->_file_info[$hash] = $data;
		}		

		/**
		 * Determines if your ffmpeg has particular codec support for encode or decode.
		 * 
		 * @access public
		 * @param string $codec The name of the codec you are checking for. 
		 * @param const $support PHPVideoToolkit::ENCODE or PHPVideoToolkit::DECODE, depending on which functionality is desired.
		 * @return mixed. Boolean false if there is no support, true if there is support.
		 */
   		public function hasCodecSupport($codec, $support=PHPVideoToolkit::ENCODE)
		{      
			$codec = strtolower($codec);
			$data = $this->getFFmpegInfo();     
			return isset($data['formats'][$codec]) ? $data['formats'][$codec][$support] : false;
		}

		/**
		 * Sets the input file that is going to be manipulated.
		 *
		 * @access public
		 * @param string $file The absolute path of the file that is required to be manipulated.
		 * @param mixed $input_frame_rate If 0 (default) then no input frame rate is set, if false it is automatically retreived, otherwise
		 * 		any other integer will be set as the incoming frame rate.
		 * @return boolean false on error encountered, true otherwise
		 */
		function setInputFile($file, $input_frame_rate=0)
		{
			$files_length = count($file);
// 			if the total number of files entered is 1 then only one file is being processed
			if($files_length == 1)
			{
//				check the input file, if there is a %d in there or a similar %03d then the file inputted is a sequence, if neither of those is found
//				then qheck to see if the file exists
				if(!preg_match('/\%([0-9]+)d/', $file) && strpos($file, '%d') === false && !is_file($file))
				{
//					input file not valid
					return $this->_raiseError('setInputFile_file_existence', array('file'=>$file));
//<-				exits
				}
				$escaped_name = $file;
// 				$escaped_name = escapeshellarg($files[0]);
				$this->_input_file = $escaped_name;
				$this->_input_file_id = md5($escaped_name);
				
// 				the -inputr is a hack for -r to come before the input
				if($input_frame_rate !== 0)
				{
					$info = $this->getFileInfo();
					if(isset($info['video']))
					{
						if($input_frame_rate === false)
						{
							$input_frame_rate = $info['video']['frame_rate'];
						}
// 						input frame rate is a command hack
						$this->addCommand('-inputr', $input_frame_rate);
					}
				}
			}
			else
			{
// 				more than one video is being added as input so we must join them all
				call_user_func_array(array(&$this, 'addVideo'), array($file, $input_frame_rate));
			}
			return true;
		}
		
		/**
		 * A shortcut for converting video to FLV.
		 *
		 * @access public
		 * @param integer $audio_sample_frequency
		 * @param integer $audio_bitrate
		 */
		function setFormatToFLV($audio_sample_frequency=44100, $audio_bitrate=64)
		{
			$this->addCommand('-sameq');
			$this->setAudioFormat(PHPVIDEOTOOLKIT_FORMAT_MP3);
//			adjust the audio rates
			$this->setAudioBitRate($audio_bitrate);
			$this->setAudioSampleFrequency($audio_sample_frequency);
//			set the video format
			$this->setFormat(PHPVIDEOTOOLKIT_FORMAT_FLV);
//			flag that the flv has to have meta data added after the excecution of this command
// 			register the post tidy process
			$this->registerPostProcess('_addMetaToFLV', $this);
		}
		
		/**
		 * When converting video to FLV the meta data has to be added by a ruby program called FLVTools2.
		 * This is a second exec call only after the video has been converted to FLV
		 * http://inlet-media.de/flvtool2
		 *
		 * @access private
		 */
		function _addMetaToFLV($files)
		{
			$file = array_pop($files);
//			prepare the command suitable for exec
			$exec_string = $this->_prepareCommand(PHPVIDEOTOOLKIT_FLVTOOLS_BINARY, '-U '.$file);
//			execute the command
			exec($exec_string);
			if(is_array($this->_processed[0]))
			{
				array_push($this->_processed[0], $exec_string);
			}
			else
			{
				$this->_processed[0] = array($this->_processed[0], $exec_string);
			}
			return true;
		}

		/**
		 * Streams a FLV file from a given point. You can control bandwidth, cache and session options.
		 * Inspired by xmoov-php
		 * @see xmoov-php, 
		 * 		- @link http://xmoov.com/
		 * 		- @author Eric Lorenzo Benjamin jr
		 * @access public
		 * @param integer $seek_pos The position in the file to seek to.
		 * @param array|boolean $bandwidth_options If a boolean value, false then no bandwidth limiting will take place. 
		 * 		If true then bandwidth limiting will take place with packet_size = 90 and packet_interval = 0.3.
		 * 		If an array the following values are default packet_size = 90 and packet_interval = 0.3, you will also 
		 * 		have to set active = true, ie array('active'=>true, 'packet_size'=>90, 'packet_interval'=>0.3)
		 * @param boolean $allow_cache If true the file will be allowed to cache in the browser, if false then it won't
		 * @return boolean
		 */
		public function flvStreamSeek($seek_pos=0, $bandwidth_options=array(), $allow_cache=true)
		{
// 			check for input file
			if(!$this->_input_file)
			{
//				input file not valid
				return $this->_raiseError('streamFLV_no_input');
//<-			exits
			}
// 			make the pos safe
       		$seek_pos = intval($seek_pos);
// 			absorb the bandwidth options
			$bandwidth_options = is_array($bandwidth_options) ? array_merge(array('active'=>false, 'packet_size'=>90, 'packet_interval'=>0.3), $bandwidth_options) : array('active'=>$bandwidth_options, 'packet_size'=>90, 'packet_interval'=>0.3);
// 			if this file is not allowed to be cached send cache headers for all browsers.
			if(!$allow_cache)
			{
				session_cache_limiter('nocache');
				header('Expires: Thu, 19 Nov 1981 08:52:00 GMT');
				header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
				header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
				header('Pragma: no-cache');
			}
// 			open file
            $handle = fopen($this->_input_file, 'rb');
            $file_size = filesize($this->_input_file) - (($seek_pos > 0) ? $seek_pos  + 1 : 0);
// 			send the flv headers
			header('Content-Type: video/x-flv');
			header('Content-Disposition: attachment; filename="'.basename($this->_input_file).'"');
			header('Content-Length: '.$file_size);
// 			flv format header
            if($seek_pos != 0) 
            {
                print('FLV');
                print(pack('C', 1));
                print(pack('C', 1));
                print(pack('N', 9));
                print(pack('N', 9));
            }
// 			seek to the required point
            if(fseek($handle, $seek_pos) === -1)
			{
//				input file not valid
				return $this->_raiseError('streamFLV_passed_eof');
//<-			exits
			}
// 			if bandwidth control is active then workout the options
			if($bandwidth_options['active'])
			{
        		$packet_interval = intval($bandwidth_options['packet_interval']);
        		$packet_size = intval($bandwidth_options['packet_size']) * 1042;
			}
// 			output the file
			while(!feof($handle)) 
			{
// 				limit the bandwidth
				if($bandwidth_options['active'] && $packet_interval > 0)
				{
// 					output the required packet
					$time_start = $this->microtimeFloat();
					echo fread($handle, $packet_size);
					$time_stop = $this->microtimeFloat();
// 					delay the output
					$time_difference = $time_stop - $time_start;
					if($time_difference < $packet_interval)
					{
						usleep(($packet_interval * 1000000) - ($time_difference * 1000000));
					}
				}
// 				no bandwidth limiting
				else
				{
					echo fread($handle, $file_size); 
				}
			}
// 			close the file
        	fclose($handle);
			return true;
		}

		/**
		 * This is an alias for setFormat, but restricts it to audio only formats.
		 * 
		 * @access public
		 * @param integer $format A supported audio format.
		 * @param integer $audio_sample_frequency
		 * @param integer $audio_bitrate
		 **/
		function extractAudio($format=PHPVIDEOTOOLKIT_FORMAT_MP3, $audio_sample_frequency=44100, $audio_bitrate=64)
		{
// 			check the format is one of the audio formats
			if(!in_array($format, array(PHPVIDEOTOOLKIT_FORMAT_AAC, PHPVIDEOTOOLKIT_FORMAT_AIFF, PHPVIDEOTOOLKIT_FORMAT_MP2, PHPVIDEOTOOLKIT_FORMAT_MP3, PHPVIDEOTOOLKIT_FORMAT_MP4, PHPVIDEOTOOLKIT_FORMAT_MPEG4, PHPVIDEOTOOLKIT_FORMAT_M4A, PHPVIDEOTOOLKIT_FORMAT_WAV)))
			{
				return $this->_raiseError('extractAudio_valid_format', array('format'=>$format));
//<-			exits
			}
			$this->setFormat($format);
//			adjust the audio rates
			$this->setAudioBitRate($audio_bitrate);
			$this->setAudioSampleFrequency($audio_sample_frequency);
		}

		/**
		 * Sets the new video format.
		 *
		 * @access public
		 * @param defined $format The format should use one of the defined variables stated below.
		 * 		PHPVIDEOTOOLKIT_FORMAT_3GP2 - 3g2
		 * 		PHPVIDEOTOOLKIT_FORMAT_3GP - 3gp
		 * 		PHPVIDEOTOOLKIT_FORMAT_AAC - aac
		 * 		PHPVIDEOTOOLKIT_FORMAT_AIFF - aiff
		 * 		PHPVIDEOTOOLKIT_FORMAT_AMR - amr
		 * 		PHPVIDEOTOOLKIT_FORMAT_ASF - asf
		 * 		PHPVIDEOTOOLKIT_FORMAT_AVI - avi
		 * 		PHPVIDEOTOOLKIT_FORMAT_FLV - flv
		 * 		PHPVIDEOTOOLKIT_FORMAT_GIF - gif
		 * 		PHPVIDEOTOOLKIT_FORMAT_MJ2 - mj2
		 * 		PHPVIDEOTOOLKIT_FORMAT_MP2 - mp2
		 * 		PHPVIDEOTOOLKIT_FORMAT_MP3 - mp3
		 * 		PHPVIDEOTOOLKIT_FORMAT_MP4 - mp4
		 * 		PHPVIDEOTOOLKIT_FORMAT_MPEG4 - mpeg4
		 * 		PHPVIDEOTOOLKIT_FORMAT_M4A - m4a
		 * 		PHPVIDEOTOOLKIT_FORMAT_MPEG - mpeg
		 * 		PHPVIDEOTOOLKIT_FORMAT_MPEG1 - mpeg1video
		 * 		PHPVIDEOTOOLKIT_FORMAT_MPEG2 - mpeg2video
		 * 		PHPVIDEOTOOLKIT_FORMAT_MPEGVIDEO - mpegvideo
		 * 		PHPVIDEOTOOLKIT_FORMAT_PSP - psp
		 * 		PHPVIDEOTOOLKIT_FORMAT_RM - rm
		 * 		PHPVIDEOTOOLKIT_FORMAT_SWF - swf
		 * 		PHPVIDEOTOOLKIT_FORMAT_VOB - vob
		 * 		PHPVIDEOTOOLKIT_FORMAT_WAV - wav
    	 *    	PHPVIDEOTOOLKIT_FORMAT_JPG - jpg
		 * @return boolean false on error encountered, true otherwise
		 */
		function setFormat($format)
		{
//			validate input
			if(!in_array($format, array(PHPVIDEOTOOLKIT_FORMAT_3GP2, PHPVIDEOTOOLKIT_FORMAT_3GP, PHPVIDEOTOOLKIT_FORMAT_AAC, PHPVIDEOTOOLKIT_FORMAT_AIFF, PHPVIDEOTOOLKIT_FORMAT_AMR, PHPVIDEOTOOLKIT_FORMAT_ASF, PHPVIDEOTOOLKIT_FORMAT_AVI, PHPVIDEOTOOLKIT_FORMAT_FLV, PHPVIDEOTOOLKIT_FORMAT_GIF, PHPVIDEOTOOLKIT_FORMAT_MJ2, PHPVIDEOTOOLKIT_FORMAT_MP2, PHPVIDEOTOOLKIT_FORMAT_MP3, PHPVIDEOTOOLKIT_FORMAT_MP4, PHPVIDEOTOOLKIT_FORMAT_MPEG4, PHPVIDEOTOOLKIT_FORMAT_M4A, PHPVIDEOTOOLKIT_FORMAT_MPEG, PHPVIDEOTOOLKIT_FORMAT_MPEG1, PHPVIDEOTOOLKIT_FORMAT_MPEG2, PHPVIDEOTOOLKIT_FORMAT_MPEGVIDEO, PHPVIDEOTOOLKIT_FORMAT_PSP, PHPVIDEOTOOLKIT_FORMAT_RM, PHPVIDEOTOOLKIT_FORMAT_SWF, PHPVIDEOTOOLKIT_FORMAT_VOB, PHPVIDEOTOOLKIT_FORMAT_WAV, PHPVIDEOTOOLKIT_FORMAT_JPG)))
			{
				return $this->_raiseError('setFormat_valid_format', array('format'=>$format));
//<-			exits
			}
			return $this->addCommand('-f', $format);
		}

		/**
		 * Sets the audio sample frequency for audio outputs
		 *
		 * @access public
		 * @param integer $audio_sample_frequency Valid values are 11025, 22050, 44100
		 * @return boolean false on error encountered, true otherwise
		 */
		function setAudioSampleFrequency($audio_sample_frequency)
		{
//			validate input
			if(!in_array(intval($audio_sample_frequency), array(11025, 22050, 44100)))
			{
				return $this->_raiseError('setAudioSampleFrequency_valid_frequency', array('frequency'=>$audio_sample_frequency));
//<-			exits
			}
			return $this->addCommand('-ar', $audio_sample_frequency);
		}

		/**
		 * @access public
		 * @depreciated 
		 * @see PHPVideoToolkit::setAudioCodec()
		 */
		public function setAudioFormat($video_format)
		{
			return $this->setAudioCodec($video_format);
		}

		/**
		 * Sets the audio format for audio outputs
		 *
		 * @access public
		 * @param integer $audio_format Valid values are PHPVIDEOTOOLKIT_FORMAT_AAC, PHPVIDEOTOOLKIT_FORMAT_AIFF, PHPVIDEOTOOLKIT_FORMAT_AMR, PHPVIDEOTOOLKIT_FORMAT_ASF, PHPVIDEOTOOLKIT_FORMAT_MP2, PHPVIDEOTOOLKIT_FORMAT_MP3, PHPVIDEOTOOLKIT_FORMAT_MP4, PHPVIDEOTOOLKIT_FORMAT_MPEG2, PHPVIDEOTOOLKIT_FORMAT_RM, PHPVIDEOTOOLKIT_FORMAT_WAV
		 * @return boolean false on error encountered, true otherwise
		 */
		function setAudioCodec($audio_format)
		{
//			validate input
			if(!in_array($audio_format, array(PHPVIDEOTOOLKIT_FORMAT_AAC, PHPVIDEOTOOLKIT_FORMAT_AIFF, PHPVIDEOTOOLKIT_FORMAT_AMR, PHPVIDEOTOOLKIT_FORMAT_ASF, PHPVIDEOTOOLKIT_FORMAT_MP2, PHPVIDEOTOOLKIT_FORMAT_MP3, PHPVIDEOTOOLKIT_FORMAT_MP4, PHPVIDEOTOOLKIT_FORMAT_MPEG2, PHPVIDEOTOOLKIT_FORMAT_RM, PHPVIDEOTOOLKIT_FORMAT_WAV)))
			{
				return $this->_raiseError('setAudioFormat_valid_format', array('format'=>$audio_format));
//<-			exits
			}
// 			run a libmp3lame check as it require different mp3 codec
// 			updated thanks to Varon for providing the research
			if($audio_format == PHPVIDEOTOOLKIT_FORMAT_MP3)
			{
				$info = $this->getFFmpegInfo();
				if(isset($info['formats']['libmp3lame']))
				{
// 					$audio_format = 'liblamemp3';
					$audio_format = 'libmp3lame';
				}
			}
			return $this->addCommand('-acodec', $audio_format);
		}

		/**
		 * @access public
		 * @depreciated 
		 * @see PHPVideoToolkit::setVideoCodec()
		 */
		public function setVideoFormat($video_format)
		{
			return $this->setVideoCodec($video_format);
		}

		/**
		 * Sets the video format for video outputs. This should not be confused with setFormat. setVideoFormat does not generally need to
		 * be called unless setting a specific video format for a type of media format. It gets a little confusing...
		 *
		 * @access public
		 * @param integer $video_format Valid values are 11025, 22050, 44100
		 * @return boolean false on error encountered, true otherwise
		 */
		function setVideoCodec($video_format)
		{
//			validate input
			if(!in_array($video_format, array(PHPVIDEOTOOLKIT_FORMAT_3GP2, PHPVIDEOTOOLKIT_FORMAT_3GP, PHPVIDEOTOOLKIT_FORMAT_AVI, PHPVIDEOTOOLKIT_FORMAT_FLV, PHPVIDEOTOOLKIT_FORMAT_GIF, PHPVIDEOTOOLKIT_FORMAT_MJ2, PHPVIDEOTOOLKIT_FORMAT_MP4, PHPVIDEOTOOLKIT_FORMAT_MPEG4, PHPVIDEOTOOLKIT_FORMAT_M4A, PHPVIDEOTOOLKIT_FORMAT_MPEG, PHPVIDEOTOOLKIT_FORMAT_MPEG1, PHPVIDEOTOOLKIT_FORMAT_MPEG2, PHPVIDEOTOOLKIT_FORMAT_MPEGVIDEO)))
			{
				return $this->_raiseError('setVideoFormat_valid_format', array('format'=>$video_format));
//<-			exits
			}
			return $this->addCommand('-vcodec', $video_format);
		}
		
		/**
		 * Disables audio encoding
		 *
		 * @access public
		 * @return boolean false on error encountered, true otherwise
		 */
		function disableAudio()
		{
			return $this->addCommand('-an');
		}

		/**
		 * Sets the audio bitrate
		 *
		 * @access public
		 * @param integer $audio_bitrate Valid values are 16, 32, 64
		 * @return boolean false on error encountered, true otherwise
		 */
		function setAudioBitRate($bitrate)
		{
//			validate input
			if(!in_array(intval($bitrate), array(16, 32, 64, 128)))
			{
				return $this->_raiseError('setAudioBitRate_valid_bitrate', array('bitrate'=>$bitrate));
//<-			exits
			}
			return $this->addCommand('-ab', $bitrate.'kb');
		}

		/**
		 * Compiles an array of images into a video. This sets the input file (setInputFile) so you do not need to set it.
		 * The images should be a full absolute path to the actual image file.
		 * NOTE 1; This copies and renames all the supplied images into a temporary folder so the images don't have to be specifically named. However, when
		 * creating the ffmpeg instance you will need to set the absolute path to the temporary folder. The default path is '/tmp/'.
		 * NOTE 2; Please make sure all of the images are all of the same type.
		 *
		 * @access public
		 * @param array $images An array of images that are to be joined and converted into a video
		 * @param integer $input_frame_rate An integer that will specify the input frame rate for the images.
		 * @return boolean Returns false on encountering an error
		 */
		function prepareImagesForConversionToVideo($images, $input_frame_rate)
		{
//			http://ffmpeg.mplayerhq.hu/faq.html#TOC3
//			ffmpeg -f image2 -i img%d.jpg /tmp/a.mpg
			if(empty($images))
			{
				return $this->_raiseError('prepareImagesForConversionToVideo_one_img');
//<-			exits
			}
//			loop through and validate existence first before making a temporary copy
			foreach ($images as $key=>$img)
			{
				if(!is_file($img))
				{
					return $this->_raiseError('prepareImagesForConversionToVideo_img_404', array('img'=>$img));
//<-				exits
				}
			}
			if(!is_dir($this->_tmp_directory))
			{
				return $this->_raiseError('generic_temp_404');
//<-			exits
			}
			if(!is_writeable($this->_tmp_directory))
			{
				return $this->_raiseError('generic_temp_writable');
//<-			exits
			}
//			get the number of preceding places for the files based on how many files there are to copy
			$total = count($images);
//			create a temp dir in the temp dir
			$uniqid = $this->unique();
			mkdir($this->_tmp_directory.$uniqid, 0777);
//			loop through, copy and rename specified images to the temp dir
			$ext = false;
			foreach ($images as $key=>$img)
			{
				$file_ext = array_pop(explode('.', $img));
				if($ext !== false && $ext !== $file_ext)
				{
					return $this->_raiseError('prepareImagesForConversionToVideo_img_type');
//<-				exits
				}
				$ext = $file_ext;
				$tmp_file = $this->_tmp_directory.$uniqid.DIRECTORY_SEPARATOR.$this->_tmp_file_prefix.$key.'.'.$ext;
				if(!@copy($img, $tmp_file))
				{
					return $this->_raiseError('prepareImagesForConversionToVideo_img_copy', array('img'=>$img, 'tmpfile'=>$tmp_file));
//<-				exits
				}
//				push the tmp file name into the unlinks so they can be deleted on class destruction
				array_push($this->_unlink_files, $tmp_file);
			}
// 			the inputr is a hack for -r to come before the input
			$this->addCommand('-inputr', $input_frame_rate);
// 			exit;
//			add the directory to the unlinks
			array_push($this->_unlink_dirs, $this->_tmp_directory.$uniqid);
//			get the input file format
			$file_iteration = $this->_tmp_file_prefix.'%d.'.$ext;
//			set the input filename
			return $this->setInputFile($this->_tmp_directory.$uniqid.DIRECTORY_SEPARATOR.$file_iteration);
		}

		/**
		 * Sets the video bitrate
		 *
		 * @access public
		 * @param integer $bitrate 
		 * @return boolean
		 */
		function setVideoBitRate($bitrate)
		{
			$bitrate = intval($bitrate);
			return $this->addCommand('-b', $bitrate.'kb');
		}
		
		/**
		 * Sets the amount of time an animated gif output will loop
		 *
		 * @access public
		 * @param integer $loop_count If false the gif will not loop, if 0 it will loop endlessly, any other number it will loop that amount.
		 */
		function setGifLoops($loop_count)
		{
			if($loop_count !== false)
			{
				$this->addCommand('-loop_output', $loop_count);
			}
		}
			

		/**
		 * @access public
		 * @depreciated 
		 * @see PHPVideoToolkit::setVideoDimensions()
		 */
		public function setVideoOutputDimensions($width, $height=null)
		{
			return $this->setVideoDimensions($width, $height);
		}
		
		/**
		 * Sets the video output dimensions (in pixels)
		 *
		 * @access public
		 * @param mixed $width If an integer height also has to be specified, otherwise you can use one of the class constants
		 * 		PHPVIDEOTOOLKIT_SIZE_SAS		= Same as input source
		 * 		PHPVIDEOTOOLKIT_SIZE_SQCIF 		= 128 x 96
		 * 		PHPVIDEOTOOLKIT_SIZE_QCIF 		= 176 x 144
		 * 		PHPVIDEOTOOLKIT_SIZE_CIF 		= 352 x 288
		 * 		PHPVIDEOTOOLKIT_SIZE_4CIF 		= 704 x 576
		 * 		PHPVIDEOTOOLKIT_SIZE_QQVGA 		= 160 x 120
		 * 		PHPVIDEOTOOLKIT_SIZE_QVGA 		= 320 x 240
		 * 		PHPVIDEOTOOLKIT_SIZE_VGA 		= 640 x 480
		 * 		PHPVIDEOTOOLKIT_SIZE_SVGA 		= 800 x 600
		 * 		PHPVIDEOTOOLKIT_SIZE_XGA 		= 1024 x 768
		 * 		PHPVIDEOTOOLKIT_SIZE_UXGA 		= 1600 x 1200
		 * 		PHPVIDEOTOOLKIT_SIZE_QXGA 		= 2048 x 1536
		 * 		PHPVIDEOTOOLKIT_SIZE_SXGA 		= 1280 x 1024
		 * 		PHPVIDEOTOOLKIT_SIZE_QSXGA 		= 2560 x 2048
		 * 		PHPVIDEOTOOLKIT_SIZE_HSXGA 		= 5120 x 4096
		 * 		PHPVIDEOTOOLKIT_SIZE_WVGA 		= 852 x 480
		 * 		PHPVIDEOTOOLKIT_SIZE_WXGA 		= 1366 x 768
		 * 		PHPVIDEOTOOLKIT_SIZE_WSXGA 		= 1600 x 1024
		 * 		PHPVIDEOTOOLKIT_SIZE_WUXGA 		= 1920 x 1200
		 * 		PHPVIDEOTOOLKIT_SIZE_WOXGA 		= 2560 x 1600
		 * 		PHPVIDEOTOOLKIT_SIZE_WQSXGA		= 3200 x 2048
		 * 		PHPVIDEOTOOLKIT_SIZE_WQUXGA 	= 3840 x 2400
		 * 		PHPVIDEOTOOLKIT_SIZE_WHSXGA 	= 6400 x 4096
		 * 		PHPVIDEOTOOLKIT_SIZE_WHUXGA 	= 7680 x 4800
		 * 		PHPVIDEOTOOLKIT_SIZE_CGA 		= 320 x 200
		 * 		PHPVIDEOTOOLKIT_SIZE_EGA		= 640 x 350
		 * 		PHPVIDEOTOOLKIT_SIZE_HD480 		= 852 x 480
		 * 		PHPVIDEOTOOLKIT_SIZE_HD720 		= 1280 x 720
		 * 		PHPVIDEOTOOLKIT_SIZE_HD1080		= 1920 x 1080
		 * @param integer $height
		 * @return boolean
		 */
		function setVideoDimensions($width, $height=null)
		{
			if($height === null || $height === true)
			{
//				validate input
				if(!in_array($width, array(PHPVIDEOTOOLKIT_SIZE_SAS, PHPVIDEOTOOLKIT_SIZE_SQCIF, PHPVIDEOTOOLKIT_SIZE_QCIF, PHPVIDEOTOOLKIT_SIZE_CIF, PHPVIDEOTOOLKIT_SIZE_4CIF, PHPVIDEOTOOLKIT_SIZE_QQVGA, PHPVIDEOTOOLKIT_SIZE_QVGA, PHPVIDEOTOOLKIT_SIZE_VGA, PHPVIDEOTOOLKIT_SIZE_SVGA, PHPVIDEOTOOLKIT_SIZE_XGA, PHPVIDEOTOOLKIT_SIZE_UXGA, PHPVIDEOTOOLKIT_SIZE_QXGA, PHPVIDEOTOOLKIT_SIZE_SXGA, PHPVIDEOTOOLKIT_SIZE_QSXGA, PHPVIDEOTOOLKIT_SIZE_HSXGA, PHPVIDEOTOOLKIT_SIZE_WVGA, PHPVIDEOTOOLKIT_SIZE_WXGA, PHPVIDEOTOOLKIT_SIZE_WSXGA, PHPVIDEOTOOLKIT_SIZE_WUXGA, PHPVIDEOTOOLKIT_SIZE_WOXGA, PHPVIDEOTOOLKIT_SIZE_WQSXGA, PHPVIDEOTOOLKIT_SIZE_WQUXGA, PHPVIDEOTOOLKIT_SIZE_WHSXGA, PHPVIDEOTOOLKIT_SIZE_WHUXGA, PHPVIDEOTOOLKIT_SIZE_CGA, PHPVIDEOTOOLKIT_SIZE_EGA, PHPVIDEOTOOLKIT_SIZE_HD480, PHPVIDEOTOOLKIT_SIZE_HD720, PHPVIDEOTOOLKIT_SIZE_HD1080)))
				{
					return $this->_raiseError('setVideoOutputDimensions_valid_format', array('format'=>$format));
//<-				exits
				}
				if($width === PHPVIDEOTOOLKIT_SIZE_SAS)
				{
// 					and override is made so no command is added in the hope that ffmpeg will just output the source
					if($height === true)
					{
						return true;
					}
// 					get the file info
					$info = $this->getFileInfo();
					if(!isset($info['video']) || !isset($info['video']['dimensions']))
					{
						return $this->_raiseError('setVideoOutputDimensions_sas_dim');
					}
					else
					{
						$width = $info['video']['dimensions']['width'].'x'.$info['video']['dimensions']['height'];
					}
				}
			}
			else
			{
// 				check that the width and height are even
				if($width % 2 !== 0 || $height % 2 !== 0)
				{
					return $this->_raiseError('setVideoOutputDimensions_valid_integer');
//<-				exits
				}
				$width = $width.'x'.$height;
			}
			$this->addCommand('-s', $width);
			return true;
		}

		/**
		 * Sets the video aspect ratio
		 *
		 * @access public
		 * @param string|integer $ratio Valid values are PHPVIDEOTOOLKIT_RATIO_STANDARD, PHPVIDEOTOOLKIT_RATIO_WIDE, PHPVIDEOTOOLKIT_RATIO_CINEMATIC, or '4:3', '16:9', '1.85' 
		 * @return boolean
		 */
		function setVideoAspectRatio($ratio)
		{
			if(!in_array($ratio, array(PHPVIDEOTOOLKIT_RATIO_STANDARD, PHPVIDEOTOOLKIT_RATIO_WIDE, PHPVIDEOTOOLKIT_RATIO_CINEMATIC)))
			{
				return $this->_raiseError('setVideoAspectRatio_valid_ratio', array('ratio'=>$ratio));
			}
			$this->addCommand('-aspect', $ratio);
			return true;
		}
		
		/**
		 * Sets the frame rate of the video
		 *
		 * @access public
		 * @param string|integer $fps 1 being 1 frame per second, 1:2 being 0.5 frames per second
		 * @return boolean
		 */
		function setVideoFrameRate($fps)
		{
			return $this->addCommand('-r', $fps);
		}
		
		/**
		 * Extracts frames from a video.
		 * (Note; If set to 1 and the duration set by $extract_begin_timecode and $extract_end_timecode is equal to 1 you get more than one frame.
		 * For example if you set $extract_begin_timecode='00:00:00' and $extract_end_timecode='00:00:01' you might expect because the time span is
		 * 1 second only to get one frame if you set $frames_per_second=1. However this is not correct. The timecode you set in $extract_begin_timecode
		 * acts as the beginning frame. Thus in this example the first frame exported will be from the very beginning of the video, the video will
		 * then move onto the next frame and export a frame there. Therefore if you wish to export just one frame from one position in the video,
		 * say 1 second in you should set $extract_begin_timecode='00:00:01' and set $extract_end_timecode='00:00:01'.)
		 *
		 * @access public
		 * @param string $extract_begin_timecode A timecode (hh:mm:ss.fn - you can change the timecode format by changing the $timecode_format param
		 * 		it obeys the formatting of PHPVideoToolkit::formatTimecode(), see below for more info)
		 * @param string|integer|boolean $extract_end_timecode A timecode (hh:mm:ss.fn - you can change the timecode format by changing the $timecode_format param
		 * 		it obeys the formatting of PHPVideoToolkit::formatTimecode(), see below for more info), or false
		 * 		if all frames from the begin timecode are to be exported. (Boolean added by Matthias. Thanks. 12th March 2007)
		 * @param boolean|integer $frames_per_second The number of frames per second to extract. If left as default false, then the number of frames per second
		 * 		will be automagically gained from PHPVideoToolkit::fileGetInfo();
		 * @param boolean|integer $frame_limit Frame limiter. If set to false then all the frames will be exported from the given time codes, however
		 * 		if you wish to set a export limit to the number of frames that are exported you can set an integer. For example; if you set
		 * 		$extract_begin_timecode='00:00:11.01', $extract_end_timecode='00:01:10.01', $frames_per_second=1, you will get one frame for every second
		 * 		in the video between 00:00:11 and 00:01:10 (ie 60 frames), however if you ant to artificially limit this to exporting only ten frames
		 * 		then you set $frame_limit=10. You could of course alter the timecode to reflect you desired frame number, however there are situations
		 * 		when a shortcut such as this is useful and necessary.
		 * @param integer $timecode_format The format of the $extract_begin_timecode and $extract_end_timecode timecodes are being given in.
		 * 		default '%hh:%mm:%ss'
		 * 			- %hh (hours) representative of hours
		 * 			- %mm (minutes) representative of minutes
		 * 			- %ss (seconds) representative of seconds
		 * 			- %fn (frame number) representative of frames (of the current second, not total frames)
		 * 			- %ms (milliseconds) representative of milliseconds (of the current second, not total milliseconds) (rounded to 3 decimal places)
		 * 			- %ft (frames total) representative of total frames (ie frame number)
		 * 			- %st (seconds total) representative of total seconds (rounded).
		 * 			- %sf (seconds floored) representative of total seconds (floored).
		 * 			- %mt (milliseconds total) representative of total milliseconds. (rounded to 3 decimal places)
		 * 		Thus you could use an alternative, '%hh:%mm:%ss:%ms', or '%hh:%mm:%ss' dependent on your usage.
		 */
		function extractFrames($extract_begin_timecode, $extract_end_timecode, $frames_per_second=false, $frame_limit=false, $timecode_format='%hh:%mm:%ss.%fn', $check_frames_exist=true)
		{
// 			are we autoguessing the frame rate?
			if($frames_per_second === false || $check_frames_exist)
			{
// 				get the file info, will exit if no input has been set
				$info = $this->getFileInfo();
				if(!isset($info['video']))
				{
// 					the input has not returned any video data so the frame rate can not be guessed
					return $this->_raiseError('extractFrame_video_frame_rate_404');
				}
			}
// 			check to see if we have to get the fps of the input movie
			if($frames_per_second === false)
			{
				$frames_per_second = $info['video']['frame_rate'];
			}
// 			check if frame exists
			if($check_frames_exist)
			{
				if($info['video']['frame_count'] < $this->formatTimecode($extract_end_timecode, $timecode_format, '%ft', $frames_per_second))
				{
// 					the input has not returned any video data so the frame rate can not be guessed
					return $this->_raiseError('extractFrames_video_end_frame_count');
				}
				else if($info['video']['frame_count'] < $this->formatTimecode($extract_begin_timecode, $timecode_format, '%ft', $frames_per_second))
				{
// 					the input has not returned any video data so the frame rate can not be guessed
					return $this->_raiseError('extractFrames_video_begin_frame_count');
				}
			}
// 			disable audio output
			$this->disableAudio();
// 			format the begin timecode if the timecode format is not already ok.
			if($timecode_format !== '%hh:%mm:%ss.%ms')
			{
				$extract_begin_timecode = $this->formatTimecode($extract_begin_timecode, $timecode_format, '%hh:%mm:%ss.%ms', $frames_per_second);
			}
			$this->addCommand('-ss', $extract_begin_timecode);
//			added by Matthias on 12th March 2007
//			allows for exporting the entire timeline
			if($extract_end_timecode !== false)
			{
// 				format the end timecode if the timecode format is not already ok.
				if($timecode_format !== '%hh:%mm:%ss.%ms')
				{
					$extract_end_timecode = $this->formatTimecode($extract_end_timecode, $timecode_format, '%hh:%mm:%ss.%ms', $frames_per_second);
				}
        		$this->addCommand('-t', $extract_end_timecode);
			}
// 			set the output frame rate
			$this->setVideoFrameRate($frames_per_second);
// 			do we need to limit the number of frames outputted?
			if($frame_limit !== false)
			{
				$this->addCommand('-vframes', $frame_limit);
			}
			$this->_image_output_timecode_start = $extract_begin_timecode;
			$this->_image_output_timecode_fps = $frames_per_second;
		}
		
		/**
		 * Extracts exactly one frame
		 *
		 * @access public
		 * @uses $toolkit->extractFrames
		 * @param string $frame_timecode A timecode (hh:mm:ss.fn) where fn is the frame number of that second
		 * @param integer|boolean $frames_per_second The frame rate of the movie. If left as the default, false. We will use PHPVideoToolkit::getFileInfo() to get
		 * 			the actual frame rate. It is recommended that it is left as false because an incorrect frame rate may produce unexpected results.
		 * @param integer $timecode_format The format of the $extract_begin_timecode and $extract_end_timecode timecodes are being given in.
		 * 		default '%hh:%mm:%ss'
		 * 			- %hh (hours) representative of hours
		 * 			- %mm (minutes) representative of minutes
		 * 			- %ss (seconds) representative of seconds
		 * 			- %fn (frame number) representative of frames (of the current second, not total frames)
		 * 			- %ms (milliseconds) representative of milliseconds (of the current second, not total milliseconds) (rounded to 3 decimal places)
		 * 			- %ft (frames total) representative of total frames (ie frame number)
		 * 			- %st (seconds total) representative of total seconds (rounded).
		 * 			- %sf (seconds floored) representative of total seconds (floored).
		 * 			- %mt (milliseconds total) representative of total milliseconds. (rounded to 3 decimal places)
		 * 		Thus you could use an alternative, '%hh:%mm:%ss:%ms', or '%hh:%mm:%ss' dependent on your usage.
		 * @param boolean $check_frame_exists Makes an explicit check to see if the frame exists, default = true. 
		 * 		Thanks to Istvan Szakacs for suggesting this check. Note, to improve performance disable this check.
		 */
		function extractFrame($frame_timecode, $frames_per_second=false, $frame_timecode_format='%hh:%mm:%ss.%fn', $check_frame_exists=true)
		{
// 			get the file info, will exit if no input has been set
			if($check_frame_exists || $frames_per_second === false)
			{
				$info = $this->getFileInfo();
				if($info === false || !isset($info['video']))
				{
// 					the input has not returned any video data so the frame rate can not be guessed
					return $this->_raiseError('extractFrame_video_info_404');
				}
			}
// 			are we autoguessing the frame rate?
			if($frames_per_second === false)
			{
				if(!isset($info['video']['frame_rate']))
				{
// 					the input has not returned any video data so the frame rate can not be guessed
					return $this->_raiseError('extractFrame_video_frame_rate_404');
				}
				$frames_per_second = $info['video']['frame_rate'];
			}
// 			check if frame exists
			if($check_frame_exists)
			{
				if($info['video']['frame_count'] < $this->formatTimecode($frame_timecode, $frame_timecode_format, '%ft', $frames_per_second))
				{
// 					the input has not returned any video data so the frame rate can not be guessed
					return $this->_raiseError('extractFrame_video_frame_count');
				}
			}
// 			format the frame details if the timecode format is not already ok.
			if($frame_timecode_format !== '%hh:%mm:%ss.%ms')
			{
				$frame_timecode = $this->formatTimecode($frame_timecode, $frame_timecode_format, '%hh:%mm:%ss.%ms', $frames_per_second);
			}
			$this->_single_frame_extraction = 1;
// 			we will limit the number of frames produced so the desired frame is the last image
// 			this way we limit the cpu usage of ffmpeg
// 			Thanks to Istvan Szakacs for pointing out that ffmpeg can export frames using the -ss hh:mm:ss[.xxx]
// 			it has saved a lot of cpu intensive processes.
			$this->extractFrames($frame_timecode, $frame_timecode, $frames_per_second, 1, '%hh:%mm:%ss.%ms', false);
// 			register the post tidy process
// 			$this->registerPostProcess('_extractFrameTidy', $this);
		}
		
// 		/**
// 		 * Tidies up after ffmpeg exports all frames from one second of video.
// 		 *
// 		 * @access public
// 		 * @uses $toolkit->extractFrames
// 		 * @param string $frame_timecode A timecode (hh:mm:ss.fn) where fn is the frame number of that second
// 		 * @param integer|boolean $frames_per_second The frame rate of the movie. If left as the default, false. We will use PHPVideoToolkit::getFileInfo() to get
// 		 * 			the actual frame rate. It is recommended that it is left as false because an incorrect frame rate may produce unexpected results.
// 		 */
// 		function _extractFrameTidy(&$files)
// 		{
// 			$frame_number = 1;
// 			$frame_file = array();
// // 			print_r($files);
// 			foreach($files as $file=>$filename)
// 			{
// // 				print_R(array($this->_single_frame_extraction, $frame_number));
// 				if($this->_single_frame_extraction == $frame_number)
// 				{
// // 					leave this file alone as it is the required frame
// 					$frame_file[$file] = $filename;
// 				}
// 				else
// 				{
// // 					add the frame to the unlink files list
// 					array_push($this->_unlink_files, $file);
// 				}
// 				$frame_number += 1;
// 			}
// // 				print_r($frame_file);
// // 			update the files list
// 			$files = $frame_file;
// 			return true;
// 		}
		
		/**
		 * Adds a watermark to the outputted files. This effects both video and image output.
		 *
		 * @access public
		 * @param string $watermark_url The absolute path to the watermark image.
		 * @param string $vhook The absolute path to the ffmpeg vhook watermark library.
		 */
		function addWatermark($watermark_url, $vhook=PHPVIDEOTOOLKIT_FFMPEG_WATERMARK_VHOOK)
		{
// 			check to see if the ffmpeg binary has support for vhooking
			if(!$this->hasVHookSupport())
			{
				return $this->_raiseError('addWatermark_vhook_disabled');
			}
// 			does the file exist?
			if(!is_file($watermark_url))
			{
				return $this->_raiseError('addWatermark_img_404', array('watermark'=>$watermark_url));
			}
			$this->addCommand('-vhook', $vhook.' -f '.$watermark_url);
		}
		
		/**
		 * Adds a watermark to the outputted image files using the PHP GD module. 
		 * This effects only image output.
		 *
		 * @access public
		 * @param string $watermark_url The absolute path to the watermark image.
		 */
		function addGDWatermark($watermark_url, $options=array('x-offset'=>0, 'y-offset'=>0, 'position'=>'bottom-right'))
		{
// 			does the file exist?
			if(!is_file($watermark_url))
			{
				return $this->_raiseError('addWatermark_img_404', array('watermark'=>$watermark_url));
			}
// 			save the watermark_url
			$this->_watermark_url = $watermark_url;
			$this->_watermark_options = array_merge(array('x-offset'=>0, 'y-offset'=>0, 'position'=>'bottom-right'), $options);
// 			register the post process
			$this->registerPostProcess('_addGDWatermark', $this);
		}
		
		/**
		 * Adds watermark to any outputted images via GD instead of using vhooking.
		 * 
		 * @access private
		 * @param array $files An array of image files.
		 * @return array
		 */
		function _addGDWatermark($files)
		{
// 			create the watermark resource and give it alpha blending
			$info = pathinfo($this->_watermark_url);
			switch(strtolower($info['extension']))
			{
				case 'jpeg' : 
				case 'jpg' : 
					$watermark = imagecreatefromjpeg($this->_watermark_url);
					break;
				case 'gif' : 
					$watermark = imagecreatefromgif($this->_watermark_url);
					break;
				case 'png' : 
					$watermark = imagecreatefrompng($this->_watermark_url);
					break;
				default :
					return false;
			}
			imagealphablending($watermark, true);
			imagesavealpha($watermark, true);
// 			get the watermark dimensions
			$watermark_width = imagesx($watermark);
			$watermark_height = imagesy($watermark);
// 			$image = imagecreatetruecolor($watermark_width, $watermark_height);
// 			loop and watermark each file
			$blended_files = array();
			foreach($files as $file=>$filename)
			{
// 				detect the file extension and create the resource from them appropriate function
				$info = pathinfo($file);
				$quality = $output_function = null;
				switch(strtolower($info['extension']))
				{
					case 'jpeg' : 
					case 'jpg' : 
						$quality = 80;
						$output_function = 'imagejpeg';
						$image = imagecreatefromjpeg($file);
						break;
					case 'gif' : 
						$output_function = 'imagegif';
						$image = imagecreatefromgif($file);
						break;
					case 'png' : 
						$quality = 9;
						$output_function = 'imagepng';
						$image = imagecreatefrompng($file);
						break;
					default :
						continue 1;
				}
			
// 				the dimensions will/should be the same for each image however still best to check
				$image_width = imagesx($image);
				$image_height = imagesy($image);
// 				calculate where to position the watermark
				$dest_x = 0;
				$dest_y = 0;
				switch($this->_watermark_options['position'])
				{
					case 'top-left' :
						$dest_x = 0;
						$dest_y = 0;
						break;
					case 'top-middle' :
						$dest_x = ($image_width-$watermark_width)/2;
						$dest_y = 0;
						break;
					case 'top-right' :
						$dest_x = $image_width-$watermark_width;
						$dest_y = 0;
						break;
					case 'center-left' :
						$dest_x = 0;
						$dest_y = ($image_height-$watermark_height)/2;
						break;
					case 'center-middle' :
						$dest_x = ($image_width-$watermark_width)/2;
						$dest_y = ($image_height-$watermark_height)/2;
						break;
					case 'center-right' :
						$dest_x = $image_width-$watermark_width;
						$dest_y = ($image_height-$watermark_height)/2;
						break;
					case 'bottom-left' :
						$dest_x = 0;
						$dest_y = $image_height - $watermark_height;
						break;
					case 'bottom-middle' :
						$dest_x = ($image_width-$watermark_width)/2;
						$dest_y = $image_height - $watermark_height;
						break;
					case 'bottom-right' :
					default :
						$dest_x = $image_width-$watermark_width;
						$dest_y = $image_height - $watermark_height;
						break;
				}
				$dest_x += $this->_watermark_options['x-offset'];
				$dest_y += $this->_watermark_options['y-offset'];
// 				copy the watermark to the new image
// 			print_r(array($this->_watermark_url, $image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height));
				imagecopy($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height);
// 				delete the old image
				unlink($file);
// 				save the new image in place of the old
				$output_function($image, $file, $quality);
// 				remove the image resouce
				imagedestroy($image);
				array_push($blended_files, $file);
			}
// 			remove the watermark resource
			imagedestroy($watermark);
			return $blended_files;
		}
		
// 		/**
// 		 * This will overlay an audio file over the top of a video file
// 		 **/
// 		function overlayAudio($audio_file)
// 		{
// 			$this->addCommand('-newaudio', '');
// 		}

		/**
		 * This will adjust the audio volume.
		 * 
		 * @access public
		 * @param integer $vol 256 = normal
		 **/
		function adjustVolume($vol=256)
		{
			$this->addCommand('-vol', '');
		}

		/**
		 * This process will combine the original input video with the video specified by this function.
		 * This function accepts more than one video as arguments. They will be added in order of the arguments.
		 * 	ie. input_video -> video1 -> video2 etc
		 * The process of doing this can take a long time as each incoming video has to be first converted
		 * into a format that accepts joining. The default joining codec is "mpg". However for almost lossless
		 * quality you can use the "yuv4mpegpipe" format. This is of course dependent upon your ffmpeg binary.
		 * You can check to see if you server supports yuv4mpegpipe by typing "ffmpeg -formats" into the
		 * command line. If you want to use the yuv4mpegpipe format you can add the flag, FFMPEG_USE_HQ_JOIN to the
		 * end of the video inputs. WARNING: High Quality joins will take longer to process. (well duh!)
		 *
		 * @access public
		 * @param $video1, $video2, $video3... $video(n) Paths of videos to attach to the input video.
		 * @param $flag integer FFMPEG_USE_HQ_JOIN If you wish to use the yuv4mpegpipe format for join add this to the end of the video list.
		 */
		function addVideo()
		{
			$videos = func_get_args();
			$videos_length = count($videos);
// 			is last arg the hq join flag
// 			check to see if a starter file has been added, if not set the input as an array
			if($this->_input_file === null)
			{
				$this->_input_file = array();
			}
// 			if the input file is already set as a string that means as start file has been added so absorb into the input array
			else if(is_string($this->_input_file))
			{
				$this->_input_file = array($this->_input_file);
			}
			foreach($videos as $key=>$file)
			{
				if(!preg_match('/\%([0-9]+)d/', $file) && strpos($file, '%d') === false && !is_file($file))
				{
// 					input file not valid
					return $this->_raiseError('addVideo_file_404', array('file'=>$file));
//<-				exits
				}
				array_push($this->_input_file, $file);
// 				array_push($this->_input_file, escapeshellarg($file));
			}
		}

		/**
		 * @access public
		 * @uses addVideo()
		 */
		function addVideos()
		{
			$videos = func_get_args();
			call_user_func_array(array(&$this, 'addVideo'), $videos);
		}

		/**
		 * Sets the output.
		 *
		 * @access public
		 * @param string $output_directory The directory to output the command output to
		 * @param string $output_name The filename to output to.
		 * 			(Note; if you are outputting frames from a video then you will need to add an extra item to the output_name. The output name you set is required
		 * 			to contain '%d'. '%d' is replaced by the image number. Thus entering setting output_name $output_name='img%d.jpg' will output
		 * 			'img1.jpg', 'img2.jpg', etc... However 'img%03d.jpg' generates `img001.jpg', `img002.jpg', etc...)
		 * @param boolean $overwrite_mode Accepts one of the following class constants
		 * 	- PHPVIDEOTOOLKIT_OVERWRITE_FAIL		- This produces an error if there is a file conflict and the processing is halted.
		 * 	- PHPVIDEOTOOLKIT_OVERWRITE_PRESERVE	- This continues with the processing but no file overwrite takes place. The processed file is left in the temp directory
		 * 									  for you to manually move.
		 * 	- PHPVIDEOTOOLKIT_OVERWRITE_EXISTING	- This will replace any existing files with the freshly processed ones.
		 * 	- PHPVIDEOTOOLKIT_OVERWRITE_UNIQUE		- This will appended every output with a unique hash so that the filesystem is preserved.
		 * @return boolean false on error encountered, true otherwise
		 */
		function setOutput($output_directory, $output_name, $overwrite_mode=PHPVIDEOTOOLKIT_OVERWRITE_FAIL)
		{
//			check if directoy exists
			if(!is_dir($output_directory))
			{
				return $this->_raiseError('setOutput_output_dir_404', array('dir'=>$output_directory));
//<-			exits
			}
//			check if directory is writeable
			if(!is_writable($output_directory))
			{
				return $this->_raiseError('setOutput_output_dir_writable', array('dir'=>$output_directory));
//<-			exits
			}
			$process_name = '';
			
//			check to see if a output delimiter is set
			$has_d = preg_match('/\%([0-9]+)d/', $output_name) || strpos($output_name, '%d') !== false;
			if($has_d)
			{
				return $this->_raiseError('setOutput_%d_depreciated');
//<-			exits
			}
			else
			{
//				determine if the extension is an image. If it is then we will be extracting frames so check for %d
				$output_name_info = pathinfo($output_name);
				$is_image = in_array(strtolower($output_name_info['extension']), array('jpg', 'jpeg', 'png'));
				$is_gif	  = strtolower($output_name_info['extension']) === 'gif';
//				NOTE: for now we'll just stick to the common image formats, SUBNOTE: gif is ignore because ffmpeg can create animated gifs
				if($this->_single_frame_extraction !== null && strpos($output_name, '%timecode') !== false && !(preg_match('/\%index/', $output_name) || strpos($output_name, '%index') !== false) && $is_image)
				{
					return $this->_raiseError('setOutput_%_missing');
//<-				exits
				}
				$process_name = '.'.$output_name_info['extension'];
// 				print_r(array($is_image, ($this->_single_frame_extraction !== null && $is_gif)));
				if($is_image || ($this->_single_frame_extraction !== null && $is_gif))
				{
					$process_name = '-%12d'.$process_name;
				}
			}
//			set the output address
			$this->_output_address = $output_directory.$output_name;
// 			set the processing address in the temp folder so it does not conflict with any other conversions
			$this->_process_address = $this->_tmp_directory.$this->unique().$process_name;
			$this->_overwrite_mode = $overwrite_mode;
			return true;
		}
		
		/**
		 * Sets a constant quality value to the encoding. (but a variable bitrate)
		 * 
		 * @param integer $quality The quality to adhere to. 100 is highest quality, 1 is the lowest quality
		 */
		function setConstantQuality($quality)
		{
// 			interpret quality into ffmpeg value
			$quality = 31 - round(($quality/100) * 31);
			if($quality > 31)
			{
				$quality = 31;
			}
			else if($quality < 1)
			{
				$quality = 1;
			}
			$this->addCommand('-qscale', $quality);
		}

		/**
		 * Translates a number of seconds to a timecode.
		 * NOTE: this is now a depreciated, use formatSeconds() instead.
		 *
		 * @depreciated Use formatSeconds() instead.
		 * @access public
		 * @uses PHPVideoToolkit::formatSeconds()
		 * @param integer $input_seconds The number of seconds you want to calculate the timecode for.
		 */
		function secondsToTimecode($input_seconds=0)
		{
			return $this->formatSeconds($input_seconds, '%hh:%mm:%ss');
		}

		/**
		 * Translates a timecode to the number of seconds.
		 * NOTE: this is now a depreciated, use formatTimecode() instead.
		 *
		 * @depreciated Use formatTimecode() instead.
		 * @access public
		 * @uses PHPVideoToolkit::formatTimecode()
		 * @param integer $input_seconds The number of seconds you want to calculate the timecode for.
		 */
		function timecodeToSeconds($input_timecode='00:00:00')
		{
			return $this->formatTimecode($input_timecode, '%hh:%mm:%ss', '%st');
		}
		
		/**
		 * Translates a number of seconds to a timecode.
		 *
		 * @access public
		 * @param integer $input_seconds The number of seconds you want to calculate the timecode for.
		 * @param integer $return_format The format of the timecode to return. The default is
		 * 		default '%hh:%mm:%ss'
		 * 			- %hh (hours) representative of hours
		 * 			- %mm (minutes) representative of minutes
		 * 			- %ss (seconds) representative of seconds
		 * 			- %fn (frame number) representative of frames (of the current second, not total frames)
		 * 			- %ms (milliseconds) representative of milliseconds (of the current second, not total milliseconds) (rounded to 3 decimal places)
		 * 			- %ft (frames total) representative of total frames (ie frame number)
		 * 			- %st (seconds total) representative of total seconds (rounded).
		 * 			- %sf (seconds floored) representative of total seconds (floored).
		 * 			- %sc (seconds ceiled) representative of total seconds (ceiled).
		 * 			- %mt (milliseconds total) representative of total milliseconds. (rounded to 3 decimal places)
		 * 		Thus you could use an alternative, '%hh:%mm:%ss:%ms', or '%hh:%mm:%ss' dependent on your usage.
		 * @param mixed|boolean|integer $frames_per_second The number of frames per second to translate for. If left false
		 * 		the class automagically gets the fps from PHPVideoToolkit::getFileInfo(), but the input has to be set
		 * 		first for this to work properly.
		 * @return string|integer Returns the timecode, but if $frames_per_second is not set and a frame rate lookup is required 
		 * 		but can't be reached then -1 will be returned.
		 */
		function formatSeconds($input_seconds, $return_format='%hh:%mm:%ss', $frames_per_second=false)
		{
			$timestamp 		= mktime(0, 0, $input_seconds, 0, 0);
			$floored 		= floor($input_seconds);
			$hours  		= date('H', $timestamp);
			$mins	  		= date('i', $timestamp);
			$searches 		= array();
			$replacements 	= array();
// 			these ones are the simple replacements
// 			replace the hours
			$using_hours = strpos($return_format, '%hh') !== false;
			if($using_hours)
			{
				array_push($searches, '%hh');
				array_push($replacements, $hours);
			}
// 			replace the minutes
			$using_mins = strpos($return_format, '%mm') !== false;
			if($using_mins)
			{
				array_push($searches, '%mm');
// 				check if hours are being used, if not and hours are required enable smart minutes
				if(!$using_hours && $hours > 0)
				{
					$value = ($hours * 60) + $mins;
				}
				else
				{
					$value = $mins;
				}
				array_push($replacements, $value);
			}
// 			replace the seconds
			if(strpos($return_format, '%ss') !== false)
			{
// 				check if hours are being used, if not and hours are required enable smart minutes
				if(!$using_mins && !$using_hours && $hours > 0)
				{
					$mins = ($hours * 60) + $mins;
				}
// 				check if mins are being used, if not and hours are required enable smart minutes
				if(!$using_mins && $mins > 0)
				{
					$value = ($mins * 60) + date('s', $timestamp);
				}
				else
				{
					$value = date('s', $timestamp);
				}
				array_push($searches, '%ss');
				array_push($replacements, $value);
			}
// 			replace the milliseconds
			if(strpos($return_format, '%ms') !== false)
			{
				$milli = round($input_seconds - $floored, 3);
				$milli = substr($milli, 2);
				$milli = empty($milli) ? '0' : $milli;
				array_push($searches, '%ms');
				array_push($replacements, $milli);
			}
// 			replace the total seconds (rounded)
			if(strpos($return_format, '%st') !== false)
			{
				array_push($searches, '%st');
				array_push($replacements, round($input_seconds));
			}
// 			replace the total seconds (floored)
			if(strpos($return_format, '%sf') !== false)
			{
				array_push($searches, '%sf');
				array_push($replacements, floor($input_seconds));
			}
// 			replace the total seconds (ceiled)
			if(strpos($return_format, '%sc') !== false)
			{
				array_push($searches, '%sc');
				array_push($replacements, ceil($input_seconds));
			}
// 			replace the total seconds
			if(strpos($return_format, '%mt') !== false)
			{
				array_push($searches, '%mt');
				array_push($replacements, round($input_seconds, 3));
			}
// 			these are the more complicated as they depend on $frames_per_second / frames per second of the current input
			$has_frames = strpos($return_format, '%fn') !== false;
			$has_total_frames = strpos($return_format, '%ft') !== false;
			if($has_frames || $has_total_frames)
			{
// 				if the fps is false then we must automagically detect it from the input file
				if($frames_per_second === false)
				{
					$info = $this->getFileInfo();
// 					check the information has been received
					if($info === false || (!isset($info['video']) || !isset($info['video']['frame_rate'])))
					{
// 						fps cannot be reached so return -1
						return -1;
					}
					$frames_per_second = $info['video']['frame_rate'];
				}
// 				replace the frames
				$excess_frames = false;
				if($has_frames)
				{
					$excess_frames = ceil(($input_seconds - $floored) * $frames_per_second);
// 			print_r(array($input_seconds, $excess_frames));
					array_push($searches, '%fn');
					array_push($replacements, $excess_frames);
				}
// 				replace the total frames (ie frame number)
				if($has_total_frames)
				{
					$round_frames = $floored * $frames_per_second;
					if(!$excess_frames)
					{
						$excess_frames = ceil(($input_seconds - $floored) * $frames_per_second);
					}
					array_push($searches, '%ft');
					array_push($replacements, $round_frames + $excess_frames);
				}
			}
// 			print_r(array($searches, $replacements, $return_format));
// 			print_r(array($input_seconds, $timestamp, $return_format, str_replace($searches, $replacements, $return_format)));
			return str_replace($searches, $replacements, $return_format);
		}

		/**
		 * Translates a timecode to the number of seconds
		 *
		 * @access public
		 * @param integer $input_seconds The number of seconds you want to calculate the timecode for.
		 * @param integer $input_format The format of the timecode is being given in.
		 * 		default '%hh:%mm:%ss'
		 * 			- %hh (hours) representative of hours
		 * 			- %mm (minutes) representative of minutes
		 * 			- %ss (seconds) representative of seconds
		 * 			- %fn (frame number) representative of frames (of the current second, not total frames)
		 * 			- %ms (milliseconds) representative of milliseconds (of the current second, not total milliseconds) (rounded to 3 decimal places)
		 * 			- %ft (frames total) representative of total frames (ie frame number)
		 * 			- %st (seconds total) representative of total seconds (rounded).
		 * 			- %sf (seconds floored) representative of total seconds (floored).
		 * 			- %mt (milliseconds total) representative of total milliseconds. (rounded to 3 decimal places)
		 * 		Thus you could use an alternative, '%hh:%mm:%ss:%ms', or '%hh:%mm:%ss' dependent on your usage.
		 * @param integer $return_format The format of the timecode to return. The default is
		 * 		default '%ts'
		 * 			- %hh (hours) representative of hours
		 * 			- %mm (minutes) representative of minutes
		 * 			- %ss (seconds) representative of seconds
		 * 			- %fn (frame number) representative of frames (of the current second, not total frames)
		 * 			- %ms (milliseconds) representative of milliseconds (of the current second, not total milliseconds) (rounded to 3 decimal places)
		 * 			- %ft (frames total) representative of total frames (ie frame number)
		 * 			- %st (seconds total) representative of total seconds (rounded).
		 * 			- %sf (seconds floored) representative of total seconds (floored).
		 * 			- %sc (seconds ceiled) representative of total seconds (ceiled).
		 * 			- %mt (milliseconds total) representative of total milliseconds. (rounded to 3 decimal places)
		 * 		Thus you could use an alternative, '%hh:%mm:%ss:%ms', or '%hh:%mm:%ss' dependent on your usage.
		 * @param mixed|boolean|integer $frames_per_second The number of frames per second to translate for. If left false
		 * 		the class automagically gets the fps from PHPVideoToolkit::getFileInfo(), but the input has to be set
		 * 		first for this to work properly.
		 * @return float Returns the value of the timecode in seconds.
		 */
		function formatTimecode($input_timecode, $input_format='%hh:%mm:%ss', $return_format='%ts', $frames_per_second=false)
		{
// 			first we must get the timecode into the current seconds
			$input_quoted 	= preg_quote($input_format);
			$placeholders 	= array('%hh', '%mm', '%ss', '%fn', '%ms', '%ft', '%st', '%sf', '%sc', '%mt');
			$seconds 		= 0;
			$input_regex 	= str_replace($placeholders, '([0-9]+)', preg_quote($input_format));
			preg_match('/'.$input_regex.'/', $input_timecode, $matches);
// 			work out the sort order for the placeholders
			$sort_table = array();
			foreach($placeholders as $key=>$placeholder)
			{
				if(($pos = strpos($input_format, $placeholder)) !== false)
				{
					$sort_table[$pos] = $placeholder;
				}
			}
			ksort($sort_table);
// 			check to see if frame related values are in the input
			$has_frames = strpos($input_format, '%fn') !== false;
			$has_total_frames = strpos($input_format, '%ft') !== false;
			if($has_frames || $has_total_frames)
			{
// 				if the fps is false then we must automagically detect it from the input file
				if($frames_per_second === false)
				{
					$info = $this->getFileInfo();
// 					check the information has been received
					if($info === false || (!isset($info['video']) || !isset($info['video']['frame_rate'])))
					{
// 						fps cannot be reached so return -1
						return -1;
					}
					$frames_per_second = $info['video']['frame_rate'];
				}
			}			
// 			increment the seconds with each placeholder value
			$key = 1;
			foreach($sort_table as $placeholder)
			{
				if(!isset($matches[$key]))
				{
					break;
				}
				$value = $matches[$key];
				switch($placeholder)
				{
// 					time related ones
					case '%hh' : 
						$seconds += $value * 3600;
						break;
					case '%mm' : 
						$seconds += $value * 60;
						break;
					case '%ss' : 
					case '%sf' :
					case '%sc' :
						$seconds += $value;
						break;
					case '%ms' : 
						$seconds += floatval('0.'.$value);
						break;
					case '%st' : 
					case '%mt' :
						$seconds = $value;
						break 1;
						break;
// 					frame related ones
					case '%fn' : 
						$seconds += $value/$frames_per_second;
						break;
					case '%ft' : 
						$seconds = $value/$frames_per_second;
						break 1;
						break;
				}
				$key += 1;
			}
// 			then we just format the seconds
			return $this->formatSeconds($seconds, $return_format, $frames_per_second);
		}
		

		/**
		 * This is a function that joins multiple input sources into one source before
		 * the final processing takes place. All videos are temporarily converted into mpg for
		 * joining.
		 * 
		 * PLEASE NOTE. This process is experimental an might not work on all systems.
		 *
		 * @access private
		 * @param boolean $log
		 */
		function _joinInput($log)
		{
			die('INPUT CANNOT YET BE JOINED.');
// ---- ffmpeg works
/*
mkfifo /Users/ollie/Sites/@Projects/ffmpeg/checkout/root/examples/tmp/intermediate1.mpg
mkfifo /Users/ollie/Sites/@Projects/ffmpeg/checkout/root/examples/tmp/intermediate2.mpg
ffmpeg -i /Users/ollie/Sites/@Projects/ffmpeg/checkout/root/examples/tmp/MOV02820.MPG -sameq -y /Users/ollie/Sites/@Projects/ffmpeg/checkout/root/examples/tmp/intermediate1.mpg < /dev/null &
ffmpeg -i /Users/ollie/Sites/@Projects/ffmpeg/checkout/root/examples/tmp/MOV02832.MPG -sameq -y /Users/ollie/Sites/@Projects/ffmpeg/checkout/root/examples/tmp/intermediate2.mpg < /dev/null &
cat /Users/ollie/Sites/@Projects/ffmpeg/checkout/root/examples/tmp/intermediate1.mpg /Users/ollie/Sites/@Projects/ffmpeg/checkout/root/examples/tmp/intermediate2.mpg |\
ffmpeg -f mpeg -i - -sameq -vcodec flv -acodec mp3 -ar 22050 /Users/ollie/Sites/@Projects/ffmpeg/checkout/root/examples/tmp/output.flv
*/
// ---- mencoder works
/*
PHPVIDEOTOOLKIT_MENCODER_BINARY.' -oac copy -ovc copy -idx -o '.$temp_file.' '.implode(' ', $this->_input_file);
*/
// 			run a libmp3lame check as it require different mp3 codec
			$audio_codec = 'mp3';
			$info = $this->getFFmpegInfo();
			if(isset($info['compiler']['configuration']) && in_array('--enable-libmp3lame', $info['compiler']['configuration']))
			{
// 				$audio_codec = 'liblamemp3';
				$audio_codec = 'libmp3lame';
			}
			
// 			build commands
			$temp_files = array();
			$mkinfo_commands = array();
			$ffmpeg_commands = array();
			$cat_files = array();
			$unique = $this->unique();
			foreach($this->_input_file as $key=>$file)
			{
				$unique_name = $this->_tmp_directory.$unique.'-'.$key.'-temp.mpg';
				$unique_name_escaped = escapeshellarg($unique_name);
				
				$logfile1 = $this->_tmp_directory.$unique.'-'.$key.'-log1.log';
				$logfile2 = $this->_tmp_directory.$unique.'-'.$key.'-log2.log';
				
				array_push($mkinfo_commands, array('cmd'=> 'mkfifo '.$unique_name_escaped.($log ? ' &> '.$logfile1 : ''), 'logfile'=>$logfile1));
				array_push($ffmpeg_commands, array('cmd'=> PHPVIDEOTOOLKIT_FFMPEG_BINARY.' -i '.escapeshellarg($file).' -acodec '.$audio_codec.' -sameq '.$unique_name_escaped.' < /dev/null '.($log ? '&> '.$logfile2 : '&'), 'logfile'=>$logfile2));
				array_push($cat_files, $unique_name_escaped);
// 				array_push($this->_unlink_files, $unique_name);
				if($log)
				{
// 					array_push($this->_unlink_files, $logfile1);
// 					array_push($this->_unlink_files, $logfile2);
				}
			}
// 			start log
			if($log)
			{
				$log_lines = array();
				array_unshift($log_lines, $this->_getMessage('ffmpeg_log_separator'), $this->_getMessage('ffmpeg_log_ffmpeg_join_gunk'), $this->_getMessage('ffmpeg_log_separator'));
			}
// 			mkinfo for temp files
			foreach($mkinfo_commands as $cmd)
			{
// 				exec($cmd['cmd']);
				echo($cmd['cmd']."\r\n");
				if($log)
				{
					array_push($log_lines, '---------', trim(file_get_contents($cmd['logfile'])));
				}
			}
// 			extract data
			foreach($ffmpeg_commands as $cmd)
			{
// 				exec($cmd['cmd']);
				echo($cmd['cmd']."\r\n");
				if($log)
				{
					array_push($log_lines, trim(file_get_contents($cmd['logfile'])), '---------');
				}
			}
			
// 			join command
			$unique = $this->unique();
			$temp_join_file = $this->_tmp_directory.$unique.'-combined-joined.mpg';
			$temp_join_file_escaped = escapeshellarg($temp_join_file);
			$temp_process_file = $this->_tmp_directory.$unique.'-combined-temp.mpg';
			$temp_process_file_escaped = escapeshellarg($temp_process_file);
			$logfile = $this->_tmp_directory.$unique.'.log';
// 			command for use with cat mkinfo files
// 			exec('cat '.implode(' ', $cat_files).' |\
// '.PHPVIDEOTOOLKIT_FFMPEG_BINARY.' -f mpeg -i - -sameq -vcodec mpeg4 -acodec '.$audio_codec.'  '.escapeshellarg($temp_process_file).($log ? ' &> '.$logfile : ''));
			echo('cat '.implode(' ', $cat_files).' |\
'.PHPVIDEOTOOLKIT_FFMPEG_BINARY.' -f mpeg -i - -sameq -vcodec mpeg4 -acodec '.$audio_codec.' '.escapeshellarg($temp_process_file).($log ? ' &> '.$logfile : '')."\r\n");
// 			echo('cat '.implode(' ', $cat_files).' > '.$temp_join_file_escaped.'
// '.PHPVIDEOTOOLKIT_FFMPEG_BINARY.' -i '.$temp_join_file_escaped.' -sameq -vcodec mpeg4 -acodec '.$audio_codec.' '.$temp_process_file_escaped.($log ? ' &> '.$logfile : ''));
// 			exec('cat '.implode(' ', $cat_files).' > '.$temp_join_file_escaped.'
// '.PHPVIDEOTOOLKIT_FFMPEG_BINARY.' -i '.$temp_join_file_escaped.' -sameq -vcodec mpeg4 -acodec '.$audio_codec.' '.$temp_process_file_escaped.($log ? ' &> '.$logfile : ''));
			if($log)
			{
				array_push($log_lines, trim(file_get_contents($logfile)));
				array_push($this->_unlink_files, $logfile);
				$this->_addToLog($log_lines, 'r+');
				print_r($log_lines);
			}
			
//			create a temp dir in the temp dir
// 			$temp_file = $this->_tmp_directory.$this->unique().'.'.array_pop(explode('.', $this->_process_address));
// 			print_r($temp_file);
			$this->addCommand('-i', $temp_process_file);
		// 	array_push($this->_unlink_files, $temp_process_file);
			
			
			exit;
		}

		/**
		 * Commits all the commands and executes the ffmpeg procedure. This will also attempt to validate any outputted files in order to provide
		 * some level of stop and check system.
		 *
		 * @access public
		 * @param $multi_pass_encode boolean Determines if multi (2) pass encoding should be used.
		 * @param $log boolean Determines if a log file of the results should be generated.
		 * @return mixed 
		 * 		- false 										On error encountered.
		 * 		- PHPVIDEOTOOLKIT_RESULT_OK (bool true)					If the file has successfully been processed and moved ok to the output address
		 * 		- PHPVIDEOTOOLKIT_RESULT_OK_BUT_UNWRITABLE (int -1)		If the file has successfully been processed but was not able to be moved correctly to the output address
		 * 														If this is the case you will manually need to move the processed file from the temp directory. You can
		 * 														get around this by settings the third argument from PHPVideoToolkit::setOutput(), $overwrite to true.
		 * 		- n (int)										A positive integer is only returned when outputting a series of frame grabs from a movie. It dictates
		 * 														the total number of frames grabbed from the input video. You should also not however, that if a conflict exists
		 * 														with one of the filenames then this return value will not be returned, but PHPVIDEOTOOLKIT_RESULT_OK_BUT_UNWRITABLE
		 * 														will be returned instead.
		 * 	Because of the mixed return value you should always go a strict evaluation of the returned value. ie
		 * 
		 * 	$result = $toolkit->excecute();
		 *  if($result === false)
		 *  {
		 * 		// error
		 *  }
		 *  else if($result === PHPVIDEOTOOLKIT_RESULT_OK_BUT_UNWRITABLE)
		 *  {
		 * 		// ok but a manual move is required. The file to move can be it can be retrieved by $toolkit->getLastOutput();
		 *  }
		 *  else if($result === PHPVIDEOTOOLKIT_RESULT_OK)
		 *  {
		 * 		// everything is ok.
		 *  }
		 */
		function execute($multi_pass_encode=false, $log=false)
		{
// 			check for inut and output params
			$has_placeholder = preg_match('/\%([0-9]+)index/', $this->_process_address) || (strpos($this->_process_address, '%index') === false && strpos($this->_process_address, '%timecode') === false);
			if($this->_input_file === null && !$has_placeholder)
			{
				return $this->_raiseError('execute_input_404');
//<-			exits
			}
//			check to see if the output address has been set
			if($this->_process_address === null)
			{
				return $this->_raiseError('execute_output_not_set');
//<-			exits
			}
			
			if(($this->_overwrite_mode == PHPVIDEOTOOLKIT_OVERWRITE_PRESERVE || $this->_overwrite_mode == PHPVIDEOTOOLKIT_OVERWRITE_FAIL) && is_file($this->_process_address))
			{
				return $this->_raiseError('execute_overwrite_process');
//<-			exits
			}
			
// 			carry out some overwrite checks if required
			$overwrite = '';
			switch($this->_overwrite_mode)
			{
				case PHPVIDEOTOOLKIT_OVERWRITE_UNIQUE :
// 					insert a unique id into the output address (the process address already has one)
					$unique = $this->unique();
					$last_index = strrpos($this->_output_address, DIRECTORY_SEPARATOR);
					$this->_output_address = substr($this->_output_address, 0, $last_index+1).$unique.'-'.substr($this->_output_address, $last_index+1);
					break;
					
				case PHPVIDEOTOOLKIT_OVERWRITE_EXISTING :
// 					add an overwrite command to ffmpeg execution call
					$overwrite = '-y ';
					break;
					
				case PHPVIDEOTOOLKIT_OVERWRITE_PRESERVE :
// 					do nothing as the preservation comes later
					break;
					
				case PHPVIDEOTOOLKIT_OVERWRITE_FAIL :
				default :
// 					if the file should fail
					if(!$has_placeholder && is_file($this->_output_address))
					{
						return $this->_raiseError('execute_overwrite_fail');
//<-					exits
					}
					break;
			}
			
			$this->_timer_start = PHPVideoToolkit::microtimeFloat();
			
// 			we have multiple inputs that require joining so convert them to a joinable format and join
			if(is_array($this->_input_file))
			{
				$this->_joinInput($log);
			}
			
//			add the input file command to the mix
			$this->addCommand('-i', $this->_input_file);
			
// 			if multi pass encoding is enabled add the commands and logfile
			if($multi_pass_encode)
			{
				$multi_pass_file = $this->_tmp_directory.$this->unique().'-multipass';
				$this->addCommand('-pass', 1);
				$this->addCommand('-passlogfile', $multi_pass_file);
			}

//			combine all the output commands
			$command_string = $this->_combineCommands();
//			prepare the command suitable for exec
//			the input and overwrite commands have specific places to be set so they have to be added outside of the combineCommands function
			$exec_string = $this->_prepareCommand(PHPVIDEOTOOLKIT_FFMPEG_BINARY, $command_string, $overwrite.escapeshellcmd($this->_process_address));
// 			$exec_string = $this->_prepareCommand(PHPVIDEOTOOLKIT_FFMPEG_BINARY, '-i '.$this->_commands['-i'].' '.$command_string, $overwrite.escapeshellcmd($this->_process_address));
			if($log)
			{
				$this->_log_file = $this->_tmp_directory.$this->unique().'.info';
				array_push($this->_unlink_files, $this->_log_file);
				$exec_string = $exec_string.' &> '.$this->_log_file;
			}
			
//			execute the command
			exec($exec_string);
			
//			track the processed command by adding it to the class
			array_unshift($this->_processed, $exec_string);
			
// 			create the multiple pass encode
			if($multi_pass_encode)
			{
				$pass2_exc_string = str_replace('-pass '.escapeshellarg(1), '-pass '.escapeshellarg(2), $exec_string);
				exec($pass2_exc_string);
				$this->_processed[0] = array($this->_processed[0], $pass2_exc_string);
// 				remove the multipass log file
				unlink($multi_pass_file.'-0.log');
			}
// 			keep track of the time taken
			$execution_time = PHPVideoToolkit::microtimeFloat() - $this->_timer_start;
			array_unshift($this->_timers, $execution_time);
			
// 			add the exec string to the log file
			if($log)
			{
				$lines = $this->_processed[0];
				if(!is_array($lines))
				{
					$lines = array($lines);
				}
				array_unshift($lines, $this->_getMessage('ffmpeg_log_separator'), $this->_getMessage('ffmpeg_log_ffmpeg_command'), $this->_getMessage('ffmpeg_log_separator'));
				array_unshift($lines, $this->_getMessage('ffmpeg_log_separator'), $this->_getMessage('ffmpeg_log_ffmpeg_gunk'), $this->_getMessage('ffmpeg_log_separator'));
				$this->_addToLog($lines, 'r+');
			}

//			must validate a series of outputed items
//			detect if the output address is a sequence output
			if(preg_match('/\%([0-9]+)d/', $this->_process_address, $d_matches) || strpos($this->_process_address, '%d') !== false)
			{
//				get the path details
				$process_info 	= pathinfo($this->_process_address);
				$output_info 	= pathinfo($this->_output_address);
				$pad_amount 	= intval($d_matches[1]);
// 				print_r(array($process_info, $output_info));
				
// 				get the %index padd amounts
				$has_preg_index = preg_match('/\%([0-9]+)index/', $output_info['basename'], $index_matches);
				$output_index_pad_amount = isset($index_matches[1]) ? intval($index_matches[1], 1) : 0;
// 				var_dump($index_matches);
				
//				init the iteration values
				$num 			= 1;
				$files 			= array();
				$produced	 	= array();
				$error			= false;
				$name_conflict	= false;
				$file_exists	= false;
				
// 				get the first files name
				$filename 		= $process_info['dirname'].DIRECTORY_SEPARATOR.str_replace($d_matches[0], str_pad($num, $pad_amount, '0', STR_PAD_LEFT), $process_info['basename']);
				$use_timecode	= strpos($output_info['basename'], '%timecode') !== false;
				$use_index		= $has_preg_index || strpos($output_info['basename'], '%index') !== false;
				
// 				if(!$use_timecode && $use_index)
// 				{
// 					if($log)
// 					{
// 						$this->_logResult('execute_overwrite_fail');
// 					}
// 					return $this->_raiseError('execute_overwrite_fail');
// 				}
				
// 				start the timecode pattern replacement values
				if($use_timecode)
				{
					$secs_start = $this->formatTimecode($this->_image_output_timecode_start, '%hh:%mm:%ss.%ms', '%mt', $this->_image_output_timecode_fps);
					$fps_inc = 1/$this->_image_output_timecode_fps;
					$fps_current_sec = 0;
					$fps_current_frame = 0;
				}
				
//				loop checking for file existence
				while(@is_file($filename))
				{
//					check for empty file
					$size = filesize($filename);
					if($size == 0)
					{
						$error = true;
					}
					array_push($produced, $filename);
// 					create the substitution arrays
					$searches 		= array();
					$replacements 	= array();
					if($use_index)
					{
						array_push($searches, isset($index_matches[0]) ? $index_matches[0] : '%index');
						array_push($replacements, str_pad($num, $output_index_pad_amount, '0', STR_PAD_LEFT));
					}
// 					check if timecode is in the output name, no need to use it if not
					if($use_timecode)
					{
						$fps_current_sec 	+= $fps_inc;
						$fps_current_frame 	+= 1;
						if($fps_current_sec >= 1)
						{
							$fps_current_sec 	 = $fps_inc;
							$secs_start 		+= 1;
							$fps_current_frame 	 = 1;
						}
						$timecode = $this->formatSeconds($secs_start, $this->image_output_timecode_format, $this->_image_output_timecode_fps);
						$timecode 		= str_replace(array(':', '.'), $this->timecode_seperator_output, $timecode);
// 						add to the substitution array
						array_push($searches, '%timecode');
						array_push($replacements, $timecode);
					}
// 					check if the file exists already and if it does check that it can be overriden
					$old_filename = $filename;
// 					print_r(array($searches, $replacements, $output_info['basename']));
					$new_file = str_replace($searches, $replacements, $output_info['basename']);
					$new_filename = $output_info['dirname'].DIRECTORY_SEPARATOR.$new_file;
// 					var_dump($filename, $new_filename);
					if(!is_file($new_filename) || $this->_overwrite_mode == PHPVIDEOTOOLKIT_OVERWRITE_EXISTING)
					{
						rename($filename, $new_filename);
						$filename = $new_filename;
					}
// 					the file exists and is not allowed to be overriden so just rename in the temp directory using the timecode
					else if($this->_overwrite_mode == PHPVIDEOTOOLKIT_OVERWRITE_PRESERVE)
					{
						$new_filename = $process_info['dirname'].DIRECTORY_SEPARATOR.'tbm-'.$this->unique().'-'.$new_file;
						rename($filename, $new_filename);
						$filename = $new_filename;
// 						add the error to the log file
						if($log)
						{
							$this->_logResult('execute_image_file_exists', array('file'=>$new_filename));
						}
// 						flag the conflict
						$file_exists = true;
					}
// 					the file exists so the process must fail
					else
					{
// 						add the error to the log file
						if($log)
						{
							$this->_logResult('execute_overwrite_fail');
						}
// 						tidy up the produced files
						array_merge($this->_unlink_files, $produced);
						return $this->_raiseError('execute_overwrite_fail');
					}
//					process the name change if the %d is to be replaced with the timecode
					$num += 1;
					$files[$filename] = $size > 0 ? basename($filename) : false;
// 					print_r("\r\n\r\n".is_file($old_filename)." - ".$old_filename.' => '.$new_filename);
// 					print_r($files);
// 					get the next incremented filename to check for existance
					$filename = $process_info['dirname'].DIRECTORY_SEPARATOR.str_replace($d_matches[0], str_pad($num, $pad_amount, '0', STR_PAD_LEFT), $process_info['basename']);
				}
//				de-increment the last num as it wasn't found
				$num -= 1;

//				if the file was detected but were empty then display a different error
				if($error === true)
				{
// 					add the error to the log file
					if($log)
					{
						$this->_logResult('execute_partial_error', array('input'=>$this->_input_file));
					}
					return $this->_raiseError('execute_partial_error', array('input'=>$this->_input_file));
//<-				exits
				}
// 				post process any files
// 				print_r($files);
				$post_process_result = $this->_postProcess($log, $files);
// 				print_r($files);
				if(is_array($post_process_result))
				{
// 					post process has occurred and everything is fine
					$num = count($files);
				}
				else if($post_process_result !== false)
				{
// 					the file has encountered an error in the post processing of the files
					return $post_process_result;
				}
// 			var_dump("\r\n\r\n", $files, __LINE__, __FILE__, "\r\n\r\n");
// 			exit;
// 				if the result is false then no post process has taken place

				$this->_process_file_count = $num;

//				no files were generated in this sequence
				if($num == 0)
				{
// 					add the error to the log file
					if($log)
					{
						$this->_logResult('execute_image_error', array('input'=>$this->_input_file));
					}
					return $this->_raiseError('execute_image_error', array('input'=>$this->_input_file));
//<-				exits
				}
				
//				add the files the the class a record of what has been generated
				array_unshift($this->_files, $files);
				
				array_push($lines, $this->_getMessage('ffmpeg_log_separator'), $this->_getMessage('ffmpeg_log_ffmpeg_output'), $this->_getMessage('ffmpeg_log_separator'), implode("\n", $files));
				$this->_addToLog($lines, 'r+');
				
				return $file_exists ? PHPVIDEOTOOLKIT_RESULT_OK_BUT_UNWRITABLE : PHPVIDEOTOOLKIT_RESULT_OK;
			}
//			must validate one file
			else
			{
//				check that it is a file
				if(!is_file($this->_process_address))
				{
// 					add the error to the log file
					if($log)
					{
						$this->_logResult('execute_output_404', array('input'=>$this->_input_file));
					}
					return $this->_raiseError('execute_output_404', array('input'=>$this->_input_file));
//<-				exits
				}
//				the file does exist but is it empty?
				if(filesize($this->_process_address) == 0)
				{
// 					add the error to the log file
					if($log)
					{
						$this->_logResult('execute_output_empty', array('input'=>$this->_input_file));
					}
					return $this->_raiseError('execute_output_empty', array('input'=>$this->_input_file));
//<-				exits
				}
// 				the file is ok so move to output address
				if(!is_file($this->_output_address) || $this->_overwrite_mode == PHPVIDEOTOOLKIT_OVERWRITE_EXISTING)
				{
// 					post process any files
					$post_process_result = $this->_postProcess($log, array($this->_process_address));
					if(is_array($post_process_result) || $post_process_result === true)
					{
// 						post process has occurred and everything is fine
					}
					else if($post_process_result !== false)
					{
						return $post_process_result;
					}
// 					if the result is false then no post process has taken place

// 					rename the file to the final destination and check it went ok
					if(rename($this->_process_address, $this->_output_address))
					{
						array_push($lines, $this->_getMessage('ffmpeg_log_separator'), $this->_getMessage('ffmpeg_log_ffmpeg_output'), $this->_getMessage('ffmpeg_log_separator'), $this->_output_address);
						$this->_addToLog($lines, 'r+');
						
// 						the file has been renamed ok
// 						add the error to the log file
						if($log)
						{
							$this->_logResult('execute_result_ok', array('output'=>$this->_output_address));
						}
						$this->_process_file_count = 1;
//						add the file the the class a record of what has been generated
						array_unshift($this->_files, array($this->_output_address));
						return PHPVIDEOTOOLKIT_RESULT_OK;
					}
// 					renaming failed so return ok but erro
					else
					{
// 						add the error to the log file
						if($log)
						{
							$this->_logResult('execute_result_ok_but_unwritable', array('process'=>$this->_process_address, 'output'=>$this->_output_address));
						}
//						add the file the the class a record of what has been generated
						array_unshift($this->_files, array($this->_process_address));
						array_push($lines, $this->_getMessage('ffmpeg_log_separator'), $this->_getMessage('ffmpeg_log_ffmpeg_output'), $this->_getMessage('ffmpeg_log_separator'), $this->_process_address);
						$this->_addToLog($lines, 'r+');
						return PHPVIDEOTOOLKIT_RESULT_OK_BUT_UNWRITABLE;
					}
				}
// 				if it is not we signal that it has been created but has not been moved.
				else if($this->_overwrite_mode == PHPVIDEOTOOLKIT_OVERWRITE_PRESERVE)
				{
// 					add the error to the log file
					if($log)
					{
						$this->_logResult('execute_result_ok_but_unwritable', array('process'=>$this->_process_address, 'output'=>$this->_output_address));
					}
//					add the file the the class a record of what has been generated
					array_unshift($this->_files, array($this->_process_address));
					return PHPVIDEOTOOLKIT_RESULT_OK_BUT_UNWRITABLE;
				}
// 				the file exists so the process must fail
				else
				{
// 					add the error to the log file
					if($log)
					{
						$this->_logResult('execute_overwrite_fail');
					}
// 					tidy up the produced files
					array_push($this->_unlink_files, $this->_process_address);
					return $this->_raiseError('execute_overwrite_fail');
				}
			}

			return null;

		}
		
		/**
		 * This function registers a post process after the internal handling of the ffmpeg output has been cleaned and checked.
		 * Each function that is set will be called in the order it is set unless an index is specified. All callbacks will be 
		 * supplied with one argument with is an array of the outputted files. 
		 * 
		 * NOTE1: If a post process function is being applied to an outputted video or audio then the process will be applied 
		 * before it has been moved to it's final destination, however if the output is an image sequence the post process 
		 * function will be called after the images have been moved to their final destinations.
		 * 
		 * NOTE2: Also it is important to return a boolean 'true' if the post process has been carried out ok. If the process is not
		 * a true value then the value will be treated/returned as an error and if applicable logged.
		 * 
		 * @access public
		 * @param string $function The name of a function
		 * @param object|boolean $class The name of the callback class. If left as false the callback will be treated as a standalone function.
		 * @param integer|boolean $index The index of the callback array to put the callback into. If left as false it will be pushed to the end of the array.
		 */
		function registerPostProcess($function, $class=false, $index=false)
		{
// 			create the callback
			$callback = $class === false ? $function : array(&$class, $function);
// 			add it to the post process array
			if($index === false)
			{
				array_push($this->_post_processes, $callback);
			}
			else
			{
				$this->_post_processes[$index] = $callback;
			}
		}
		
		/**
		 * Carries out the post processing of the files.
		 * 
		 * @access private
		 * @param boolean $log Determines if logging of errors should be carried out.
		 * @param array $files The array of files that have just been processed.
		 * @return mixed
		 */
		function _postProcess($log, $files)
		{
			if(count($this->_post_processes))
			{
// 				loop through the post processes
				foreach($this->_post_processes as $key=>$process)
				{
// 					call the process
					$return_value = call_user_func_array($process, array($files));
// 					if the return value is not strictly equal to true the result will be treated as an error and exit the process loop
					if(!is_array($return_value) && $return_value !== true)
					{
						if($log)
						{
							$this->_logResult($return_value);
						}
						return $this->_raiseError($return_value);
					}
				}
				return $return_value;
			}
			return false;
		}
		
		/**
		 * Returns the number of files outputted in this run. It will be reset when you call PHPVideoToolkit::reset();
		 * 
		 * @access public
		 * @return integer
		 */
		function getFileOutputCount()
		{
			return $this->_process_file_count;
		}
		
		/**
		 * Adds lines to the current log file.
		 * 
		 * @access private
		 * @param $message
		 * @param $replacements
		 */
		function _logResult($message, $replacements=false)
		{
			$this->_addToLog(array($this->_getMessage('ffmpeg_log_separator'), $this->_getMessage('ffmpeg_log_ffmpeg_result'), $this->_getMessage('ffmpeg_log_separator'), $this->_getMessage($message, $replacements)));
		}
		
		/**
		 * Adds lines to the current log file.
		 * 
		 * @access private
		 * @param $lines array An array of lines to add to the log file.
		 */
		function _addToLog($lines, $where='a')
		{
			$handle = fopen($this->_log_file, $where);
			if(is_array($lines))
			{
				$data = implode("\n", $lines)."\n";
			}
			else
			{
				$data = $lines."\n";
			}
			fwrite($handle, $data);
			fclose($handle);
		}
		
		/**
		 * Moves the current log file to another file.
		 * 
		 * @access public
		 * @param $destination string The absolute path of the new filename for the log.
		 * @return boolean Returns the result of the log file rename.
		 */
		function moveLog($destination)
		{
			$result = false;
			if($this->_log_file !== null && is_file($this->_log_file))
			{
				$result = rename($this->_log_file, $destination);
				$this->_log_file = $destination;
			}
			return $result;
		}

		/**
		 * Reads the current log file
		 * 
		 * @access public
		 * @return string|boolean Returns the current log file content. Returns false on failure.
		 */
		function readLog()
		{
			if($this->_log_file !== null && is_file($this->_log_file))
			{
				$handle = fopen($this->_log_file, 'r');
				$contents = fread($handle, filesize($this->_log_file));
				fclose($handle);
				return $contents;
			}
			return false;
		}

		/**
		 * Returns the last outputted file that was processed by ffmpeg from this class.
		 *
		 * @access public
		 * @return mixed array|string Will return an array if the output was a sequence, or string if it was a single file output
		 */
		function getLastOutput()
		{
			return $this->_files[0];
		}

		/**
		 * Returns all the outputted files that were processed by ffmpeg from this class.
		 *
		 * @access public
		 * @return array
		 */
		function getOutput()
		{
			return $this->_files;
		}

		/**
		 * Returns the amount of time taken of the last file to be processed by ffmpeg.
		 *
		 * @access public
		 * @return mixed integer Will return the time taken in seconds.
		 */
		function getLastProcessTime()
		{
			return $this->_timers[0];
		}

		/**
		 * Returns the amount of time taken of all the files to be processed by ffmpeg.
		 *
		 * @access public
		 * @return array
		 */
		function getProcessTime()
		{
			return $this->_timers;
		}

		/**
		 * Returns the last encountered error message.
		 *
		 * @access public
		 * @return string
		 */
		function getLastError()
		{
			return $this->_errors[0];
		}

		/**
		 * Returns all the encountered errors as an array of strings
		 *
		 * @access public
		 * @return array
		 */
		function getErrors()
		{
			return $this->_errors;
		}

		/**
		 * Returns the last command that ffmpeg was given.
		 * (Note; if setFormatToFLV was used in the last command then an array is returned as a command was also sent to FLVTool2)
		 *
		 * @access public
		 * @return mixed array|string
		 */
		function getLastCommand()
		{
			return $this->_processed[0];
		}

		/**
		 * Returns all the commands sent to ffmpeg from this class
		 *
		 * @access public
		 * @return unknown
		 */
		function getCommands()
		{
			return $this->_processed;
		}

		/**
		 * Raises an error
		 *
		 * @access private
		 * @param string $message
		 * @param array $replacements a list of replacements in search=>replacement format
		 * @return boolean Only returns false if $toolkit->on_error_die is set to false
		 */
		function _raiseError($message, $replacements=false)
		{
			$msg = 'FFMPEG ERROR: '.$this->_getMessage($message, $replacements);
//			check what the error is supposed to do
			if($this->on_error_die === true)
			{
				die($msg);
//<-			exits
			}
//			add the error message to the collection
			array_unshift($this->_errors, $msg);
			return false;
		}

		/**
		 * Gets a message.
		 *
		 * @access private
		 * @param string $message
		 * @param array $replacements a list of replacements in search=>replacement format
		 * @return boolean Only returns false if $toolkit->on_error_die is set to false
		 */
		function _getMessage($message, $replacements=false)
		{
			$message = isset($this->_messages[$message]) ? $this->_messages[$message] : 'Unknown!!!';
			if($replacements)
			{
				$searches = $replaces = array();
				foreach($replacements as $search=>$replace)
				{
					array_push($searches, '#'.$search);
					array_push($replaces, $replace);
				}
				$message = str_replace($searches, $replaces, $message);
			}
			return $message;
		}

		/**
		 * Adds a command to be bundled into the ffmpeg command call.
		 * (SPECIAL NOTE; None of the arguments are checked or sanitized by this function. BE CAREFUL if manually using this. The commands and arguments are escaped
		 * however it is still best to check and sanitize any params given to this function)
		 *
		 * @access public
		 * @param string $command
		 * @param mixed $argument
		 * @return boolean
		 */
		function addCommand($command, $argument='')
		{
			$this->_commands[$command] = escapeshellarg($argument);
			return true;
		}

		/**
		 * Determines if the the command exits.
		 *
		 * @access public
		 * @param string $command
		 * @return mixed boolean if failure or value if exists.
		 */
		function hasCommand($command)
		{
			return isset($this->_commands[$command]) ? $this->_commands[$command] : false;
		}

		/**
		 * Combines the commands stored into a string
		 *
		 * @access private
		 * @return string
		 */
		function _combineCommands()
		{
			$before_input 	= array();
			$after_input 	= array();
			$input 			= null;
			foreach ($this->_commands as $command=>$argument)
			{
				$command_string = trim($command.($argument ? ' '.$argument : ''));
//				check for specific none combinable commands as they have specific places they have to go in the string
				switch($command)
				{
					case '-i' :
						$input = $command_string;
						break;
					case '-inputr' :
						$command_string = trim('-r'.($argument ? ' '.$argument : ''));;
					default :
						if(in_array($command, $this->_cmds_before_input))
						{
							array_push($before_input, $command_string);
						}
						else
						{
							array_push($after_input, $command_string);
						}
				}
			}
			
			$before_input = count($before_input) ? implode(' ', $before_input).' ' : '';
			$after_input_string = ' ';
			if(count($after_input))
			{
				$input .= ' ';
				$after_input_string  = implode(' ', $after_input).' ';
			}
			
			return $before_input.$input.$after_input_string;
		}

		/**
		 * Prepares the command for execution
		 *
		 * @access private
		 * @param string $path Path to the binary
		 * @param string $command Command string to execute
		 * @param string $args Any additional arguments
		 * @return string
		 */
		function _prepareCommand($path, $command, $args='')
		{
	        if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN' || !preg_match('/\s/', $path))
	        {
	            return $path.' '.$command.' '.$args;
	        }
	        return 'start /D "'.$path.'" /B '.$command.' '.$args;
		}

		/**
		 * Generates a unique id. Primarily used in jpeg to movie production
		 *
		 * @access public
		 * @param string $prefix
		 * @return string
		 */
		function unique($prefix='')
		{
			return uniqid($prefix.time().'-');
		}

		/**
		 * Destructs ffmpeg and removes any temp files/dirs
		 * @access private
		 */
		function __destruct()
		{
//			loop through the temp files to remove first as they have to be removed before the dir can be removed
			if(!empty($this->_unlink_files))
			{
				foreach ($this->_unlink_files as $key=>$file)
				{
					if(is_file($file))
					{
						@unlink($file);
					}
				}
				$this->_unlink_files = array();
			}
//			loop through the dirs to remove
			if(!empty($this->_unlink_dirs))
			{
				foreach ($this->_unlink_dirs as $key=>$dir)
				{
					if(is_dir($dir))
					{
						@rmdir($dir);
					}
				}
				$this->_unlink_dirs = array();
			}
		}
	}
Back to Top