From: paul Date: Sat, 9 Apr 2011 11:34:06 +0000 (+0000) Subject: moved from svn.imp.fu-berlin.de/viper rev33 X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=db6a479eb83489f98839ae01cc63f5d633e8784a;p=viper moved from svn.imp.fu-berlin.de/viper rev33 svn path=/trunk/; revision=1 --- db6a479eb83489f98839ae01cc63f5d633e8784a diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..94a0453 --- /dev/null +++ b/COPYING @@ -0,0 +1,621 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS diff --git a/PlayerControl.py b/PlayerControl.py new file mode 100644 index 0000000..5eab221 --- /dev/null +++ b/PlayerControl.py @@ -0,0 +1,74 @@ +#encoding: utf-8 +#Copyright 2009 - 2010 Paul Hänsch + +#This file is part of Viper. + +#Viper is free software: you can redistribute it and/or modify +#it under the terms of the GNU General Public License as published by +#the Free Software Foundation, either version 3 of the License, or +#(at your option) any later version. + +#Viper is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU General Public License for more details. + +#You should have received a copy of the GNU General Public License +#along with Viper. If not, see + +from Tkinter import * +import Pmw + +class PlayerControl(Frame): + def __init__(self, parent, player, extrabuttons = []): + Frame.__init__(self, parent) + self.player = player + self.params = [] + self.loop = BooleanVar(value = True) + + tooltip = Pmw.Balloon() + self.subgets = {} + + self.subgets['s_pos'] = Scrollbar(self, orient=HORIZONTAL) + self.subgets['s_pos'].pack(side = TOP, anchor = W, fill = X) + self.subgets['b_stop'] = Button(self, text = 'Stop', + command = self.player.stop_video) + self.subgets['b_stop'].pack(side = LEFT, anchor = S) + tooltip.bind(self.subgets['b_stop'], 'Stop playback (time position to zero).') + self.subgets['b_play'] = Button(self, text='Play', + width=5, command=self.play) + self.subgets['b_play'].pack(side = LEFT, anchor = S) + tooltip.bind(self.subgets['b_play'], 'Play / Pause the video.') + self.subgets['b_step'] = Button(self, text = 'Step', + command = self.player.step_video) + self.subgets['b_step'].pack(side = LEFT, anchor = S) + tooltip.bind(self.subgets['b_step'], 'Step a single frame forward.') + self.subgets['c_loop'] = Checkbutton(self, text = 'Loop', + variable = self.loop) + self.subgets['c_loop'].pack(side = LEFT, anchor = S) + + for xbut in extrabuttons: + self.subgets['xb_' + xbut[0]] = Button(self, text = xbut[0], + command = xbut[1]) + self.subgets['xb_' + xbut[0]].pack(side = RIGHT, anchor = S) + try: tooltip.bind(self.subgets['xb_' + xbut[0]], xbut[2]) + except: pass + + self.player.configure(callback = self.status, slider = self.subgets['s_pos']) + + def configure(self, player): + self.player = player + self.player.configure(callback = self.status, slider = self.subgets['s_pos']) + + def play(self): + self.player.play_video(loop = self.loop.get(), + params = self.params) + + def status(self, state): + if state == 'stopped': + self.subgets['b_play'].configure(text = 'Play', command = self.play) + elif state == 'paused': + self.subgets['b_play'].configure(text = 'Play', command = self.play) + elif state == 'playing': + self.subgets['b_play'].configure(text = 'Pause', command = + self.player.pause_video) diff --git a/chunk.py b/chunk.py new file mode 100644 index 0000000..4121f6e --- /dev/null +++ b/chunk.py @@ -0,0 +1,122 @@ +#encoding: utf-8 +#Copyright 2009 Paul Hänsch + +#This file is part of Viper. + +#Viper is free software: you can redistribute it and/or modify +#it under the terms of the GNU General Public License as published by +#the Free Software Foundation, either version 3 of the License, or +#(at your option) any later version. + +#Viper is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU General Public License for more details. + +#You should have received a copy of the GNU General Public License +#along with Viper. If not, see + +from flic import * + +class Chunk(Flic): + """ + This object contains a single piece of viedeo from one file. + + The video can be the whole video stored in the file (which is the + default) or a part of this video. The file is never affected due to + operations on this object and temporary files are not created. + + Interesting object properties: + videoprops - a dictionary containing video properties as reported from mplayer + keys are for example ID_VIDEO_WIDTH or ID_LENGTH + run 'mplayer -identify videofile' to get an idea of the values + stored here + """ + + def __init__(self, file, start = None, frames = None): + """ + Constructor + + file (string) - the name of a video file + start (float) - the second which marks the start of the chunk + in video compression formats which are based on storing + delta frames this can only be key frame precise + frames (int) - the number of frames the chunk consists of + (by default all frames in the file) + """ + Flic.__init__(self) + self.videofile = '' + self.start = 0 + self.frames = 0 + self.videoprops = {} + + self.videofile = file + self.reset() + if start != None: + self.start = start + if frames != None: + self.frames = frames + + def option(self, file = None, start = None, frames = None): + """ + Change object properties + + file (string) - the name of a video file + (changing this will reinitialize the object) + start (float) - the second which marks the start of the chunk + frames (int) - the number of frames the chunk consists of + """ + + if file != None: + rem_start = self.start + rem_frames = self.frames + self.videofile = file + self.reset() + self.start = rem_start + self.frames = rem_frames + if start != None: + self.start = start + if frames != None: + self.frames = frames + + def reset(self): + """ + Get video properties + + this method is for internal use, calling it will stop the video and reset + the 'start' and 'frame' properties + """ + self.stop() + + self.slave = os.popen('mplayer -frames 0 -identify "'+self.videofile+'"') + line = self.slave.readline() + while line != '': + if line.find('ID_') == 0: + line = line.split('\n')[0] + [key, value] = line.split('=', 1) + self.videoprops[key] = value + line = self.slave.readline() + self.slave.close() + self.slave = None + + self.start = 0 + self.frames = int(float(self.videoprops['ID_VIDEO_FPS']) * + float(self.videoprops['ID_LENGTH']) + ) + self.width = int(self.videoprops['ID_VIDEO_WIDTH']) + self.height = int(self.videoprops['ID_VIDEO_HEIGHT']) + + def slave_video(self): + """ + Return a list of mplayer command line arguments, + which specifies the video to play. + + In this case: + ['videofile', '-ss', start, '-frames', frames] + """ + + return [self.videofile, + '-ss', str(self.start), + '-frames', str(self.frames) + ] + diff --git a/effects.py b/effects.py new file mode 100644 index 0000000..eb3217d --- /dev/null +++ b/effects.py @@ -0,0 +1,32 @@ +#encoding: utf-8 +#Copyright 2009 Paul Hänsch + +#This file is part of Viper. + +#Viper is free software: you can redistribute it and/or modify +#it under the terms of the GNU General Public License as published by +#the Free Software Foundation, either version 3 of the License, or +#(at your option) any later version. + +#Viper is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU General Public License for more details. + +#You should have received a copy of the GNU General Public License +#along with Viper. If not, see + +from Tkinter import * +from plugin import * +import threading +import Pmw +import sys +import os + +class EffectDiag(Frame): + def __init__(self, parent = None): + Frame.__init__(self, parent) + Label(self, text = 'Not yet implemented.').pack() + + def set_chunks(self, chunks): + pass diff --git a/fileExport.py b/fileExport.py new file mode 100644 index 0000000..a4eb039 --- /dev/null +++ b/fileExport.py @@ -0,0 +1,260 @@ +#encoding: utf-8 +#Copyright 2009 Paul Hänsch + +#This file is part of Viper. + +#Viper is free software: you can redistribute it and/or modify +#it under the terms of the GNU General Public License as published by +#the Free Software Foundation, either version 3 of the License, or +#(at your option) any later version. + +#Viper is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU General Public License for more details. + +#You should have received a copy of the GNU General Public License +#along with Viper. If not, see + +from Tkinter import * +from plugin import * +import tkFileDialog +import threading +import sys +import os + +class ExportDialog(Tk): + """ + Dialog Window for exporting a video. + + This dialog provides handles for the whole video export engine, + including plugin support for codec configuration plugins. + The actual video encoder will be executed by this dialog. + """ + + def __init__(self, commands = []): + """ + Constructor + + "Commands" is a list of mplayer subcommand lists for playing the video chunks. + The very same subcommands are given to the video encoder. + """ + + Tk.__init__(self) + self.title('Viper Export') + + self.enclabel = None + self.encoder = None + self.commands = commands + + self.container = [] + self.vcodec = [] + self.acodec = [] + self.subgets = {} + + self.subgets['f_filename'] = LabelFrame(self, text = 'Filename:') + self.subgets['f_filename'].pack( side = TOP, expand = True, fill = X) + self.subgets['b_filename'] = Button(self.subgets['f_filename'], + text = 'Select', command = self.select_file) + self.subgets['b_filename'].pack( side = LEFT ) + self.subgets['e_filename'] = Entry(self.subgets['f_filename'], width = 64) + self.subgets['e_filename'].pack( side = LEFT, expand = True, fill = X) + + self.subgets['f_actions'] = Frame(self) + self.subgets['f_actions'].pack( side = BOTTOM, expand = True, fill = X) + self.subgets['b_encode'] = Button(self.subgets['f_actions'], text = 'Encode!', + command = self.encode) + self.subgets['b_encode'].pack( side = RIGHT) + self.subgets['b_store'] = Button(self.subgets['f_actions'], text = 'Store Defaults', + command = self.store, state = 'disabled') + self.subgets['b_store'].pack( side = RIGHT) + + self.subgets['f_vcodec'] = LabelFrame(self, text = 'Video Codec') + self.subgets['f_vcodec'].pack( side = BOTTOM, expand = True, fill = X) + self.subgets['lb_vcodec'] = Listbox(self.subgets['f_vcodec'], height = 5, width = 10) + self.subgets['lb_vcodec'].pack(side = LEFT) + self.subgets['sb_vcodec'] = Scrollbar(self.subgets['f_vcodec'], orient = VERTICAL, + command = self.subgets['lb_vcodec'].yview) + self.subgets['lb_vcodec'].config(yscrollcommand = self.subgets['sb_vcodec'].set) + self.subgets['sb_vcodec'].pack( side = LEFT, fill = Y) + self.subgets['cfg_vcodec'] = None + + self.subgets['f_acodec'] = LabelFrame(self, text = 'Audio Codec') + self.subgets['f_acodec'].pack( side = BOTTOM, expand = True, fill = X) + self.subgets['lb_acodec'] = Listbox(self.subgets['f_acodec'], height = 5, width = 10) + self.subgets['lb_acodec'].pack(side = LEFT) + self.subgets['sb_acodec'] = Scrollbar(self.subgets['f_acodec'], orient = VERTICAL, + command = self.subgets['lb_acodec'].yview) + self.subgets['lb_acodec'].config(yscrollcommand = self.subgets['sb_acodec'].set) + self.subgets['sb_acodec'].pack( side = LEFT, fill = Y) + self.subgets['cfg_acodec'] = None + + self.subgets['f_container'] = LabelFrame(self, text = 'Container Format') + self.subgets['f_container'].pack( side = BOTTOM, expand = True, fill = X) + self.subgets['lb_container'] = Listbox(self.subgets['f_container'], height = 5, width = 10) + self.subgets['lb_container'].pack(side = LEFT) + self.subgets['sb_container'] = Scrollbar(self.subgets['f_container'], orient = VERTICAL, + command = self.subgets['lb_container'].yview) + self.subgets['lb_container'].config(yscrollcommand = self.subgets['sb_container'].set) + self.subgets['sb_container'].pack( side = LEFT, fill = Y) + self.subgets['cfg_container'] = None + + self.load_plugins() + self.select_plugin() + + def encode(self): + """ + The method executed when the 'Encode' button is pressed. + + This will initialize the video encoder and build the status window. + """ + command = ['mencoder'] + self.encoder = [] + + for cmd in self.commands: + command.extend(cmd) + + if self.subgets['e_filename'].get() != '': + command.extend(['-o', self.subgets['e_filename'].get()]) + else: + command.extend(['-o', tkFileDialog.asksaveasfilename()]) + if self.subgets['cfg_container'] != None: + command.extend(self.subgets['cfg_container'].subcommand()) + else: + command.extend(['-of','avi']) + if self.subgets['cfg_vcodec'] != None: + command.extend(self.subgets['cfg_vcodec'].subcommand()) + else: + command.extend(['-ovc','copy']) + if self.subgets['cfg_acodec'] != None: + command.extend(self.subgets['cfg_acodec'].subcommand()) + else: + command.extend(['-oac','copy']) + + self.encoder = os.popen2(command) + + self.subgets['enc_win'] = Tk() + self.subgets['enc_win'].title('Encoding ' + self.subgets['e_filename'].get()) + self.enclabel = Label(self.subgets['enc_win'], width = 64, height = 3) + self.enclabel.pack( side = TOP, expand = True, fill = X) + self.subgets['enc_b_exit'] = Button(self.subgets['enc_win'], + text = 'Cancel', + command = self.subgets['enc_win'].destroy) + self.subgets['enc_b_exit'].pack( side = BOTTOM, anchor = E ) + + self.wm_withdraw() + threading.Thread( target = self.encstat ).start() + self.subgets['enc_win'].mainloop() + + def encstat(self): + """ + Internal methos for providing the status display. + + This methos is executed in its own thread to read the mencoder + status line and display it in the encoding window. + It is possible to rewrite it to display a status bar instead. + """ + line = '#' + char = '#' + try: + while line != ' ': + line = ' ' + while char != '' and line[-1] != '\r' and line[-1] != '\n': + char = self.encoder[1].read(1) + line += char + self.enclabel.config( text = line.strip() ) + self.enclabel.config( text = 'Ready' ) + except: + print 'Reading from pipe impossible' + self.enclabel.config( text = 'Ready' ) + self.subgets['enc_b_exit'].configure(text = 'Close Window') + self.destroy() + + def store(self): + """ + This method is executed when the "Store" butten is pressed. + + It will store the codec configuration. It is not yet implemented. + """ + pass + + def select_plugin(self): + """ + Internal method. + + This method is regularly called to display the configuration dialog of a + selected codec plugin. + """ + if self.subgets['lb_container'].curselection() != (): + c_plugin = int(self.subgets['lb_container'].curselection()[0]) + if self.subgets['cfg_container'] != self.container[c_plugin]: + if self.subgets['cfg_container'] != None: + self.subgets['cfg_container'].pack_forget() + self.subgets['cfg_container'] = self.container[c_plugin] + self.subgets['cfg_container'].pack(side = LEFT, expand = True, fill = BOTH) + + if self.subgets['lb_vcodec'].curselection() != (): + v_plugin = int(self.subgets['lb_vcodec'].curselection()[0]) + if self.subgets['cfg_vcodec'] != self.vcodec[v_plugin]: + if self.subgets['cfg_vcodec'] != None: + self.subgets['cfg_vcodec'].pack_forget() + self.subgets['cfg_vcodec'] = self.vcodec[v_plugin] + self.subgets['cfg_vcodec'].pack(side = LEFT, expand = True, fill = BOTH) + + if self.subgets['lb_acodec'].curselection() != (): + a_plugin = int(self.subgets['lb_acodec'].curselection()[0]) + if self.subgets['cfg_acodec'] != self.acodec[a_plugin]: + if self.subgets['cfg_acodec'] != None: + self.subgets['cfg_acodec'].pack_forget() + self.subgets['cfg_acodec'] = self.acodec[a_plugin] + self.subgets['cfg_acodec'].pack(side = LEFT, expand = True, fill = BOTH) + + self.after(50, self.select_plugin) + + def select_file(self): + """ + Bring up the file selection dialog. + """ + self.subgets['e_filename'].insert(0, tkFileDialog.asksaveasfilename()) + + def load_plugins(self): + """ + Load all codec plugins from plugin directory. + """ + sys.path.insert(0, 'plugins/') + for plugin in os.listdir(sys.path[0]): + if plugin[-3:] == '.py': + __import__(plugin[:-3], None, None, ['*']) + + for c_class in C_Plugin.__subclasses__(): + self.container.append(c_class(self.subgets['f_container'])) + for c_class in self.container: + if c_class.is_available(): + self.subgets['lb_container'].insert(END, c_class.name()) + + for a_class in A_Plugin.__subclasses__(): + self.acodec.append(a_class(self.subgets['f_acodec'])) + for a_class in self.acodec: + if a_class.is_available(): + self.subgets['lb_acodec'].insert(END, a_class.name()) + + for v_class in V_Plugin.__subclasses__(): + self.vcodec.append(v_class(self.subgets['f_vcodec'])) + for v_class in self.vcodec: + if v_class.is_available(): + self.subgets['lb_vcodec'].insert(END, v_class.name()) + +def export(chunklist): + """ + Easy to call export function. + + Calling this will build and handle the whole dialog. + """ + + enclist = [] + for vc in chunklist: + if vc.played.get(): + enclist.append(vc.slave_subcommand()) + + diag = ExportDialog(commands = enclist) + diag.mainloop() diff --git a/filters.py b/filters.py new file mode 100644 index 0000000..0ff241b --- /dev/null +++ b/filters.py @@ -0,0 +1,223 @@ +#encoding: utf-8 +#Copyright 2009 - 2010 Paul Hänsch + +#This file is part of Viper. + +#Viper is free software: you can redistribute it and/or modify +#it under the terms of the GNU General Public License as published by +#the Free Software Foundation, either version 3 of the License, or +#(at your option) any later version. + +#Viper is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU General Public License for more details. + +#You should have received a copy of the GNU General Public License +#along with Viper. If not, see + +from Tkinter import * +from plugin import * +import threading +import Pmw +import sys +import os + +class FilterDiag(Frame): + """ + Widget to display filter list and + filter configuration dialogs + """ + + def __init__(self, parent = None): + Frame.__init__(self, parent) + + self.subgets = {} + self.plugins = [] + self.chunks = [] + + self.subgets['f_flist'] = LabelFrame( self, text = 'Applied Filters:' ) + self.subgets['f_flist'].pack( side = LEFT, fill = Y, expand = True, anchor = W ) + self.subgets['f_flist_upper'] = Frame(self.subgets['f_flist']) + self.subgets['f_flist_upper'].pack( side = TOP, expand = True, fill = BOTH) + self.subgets['lb_flist'] = Listbox(self.subgets['f_flist_upper'], width = 24 ) + self.subgets['lb_flist'].pack( side = LEFT, anchor = W, fill = Y, expand = True ) + self.subgets['sb_flist'] = Scrollbar(self.subgets['f_flist_upper'], orient = VERTICAL, + command = self.subgets['lb_flist'].yview) + self.subgets['sb_flist'].pack( side = RIGHT, fill = Y, expand = True, anchor = E ) + self.subgets['lb_flist'].config(yscrollcommand = self.subgets['sb_flist'].set) + self.subgets['b_del'] = Button(self.subgets['f_flist'], text = 'Delete', command=self.b_del) + self.subgets['b_del'].pack( side = LEFT, anchor = S, fill = X, expand = True ) + self.subgets['b_up'] = Button(self.subgets['f_flist'], text = 'Up', command = self.b_up) + self.subgets['b_up'].pack( side = LEFT, anchor = S, fill = X, expand = True ) + self.subgets['b_down'] = Button(self.subgets['f_flist'], text = 'Down', command = self.b_down) + self.subgets['b_down'].pack( side = LEFT, anchor = S, fill = X, expand = True ) + + self.subgets['f_filterCfg'] = Frame(self) + self.subgets['f_filterCfg'].pack( side = LEFT, expand = True, fill = BOTH, anchor = W ) + self.subgets['f_selector'] = Frame(self.subgets['f_filterCfg']) + self.subgets['f_selector'].pack( side = TOP, expand = True, fill = X, anchor = N ) + + self.subgets['b_filter'] = Button(self.subgets['f_selector'], text = 'Apply Filter', + command = self.apply_filter) + self.subgets['b_filter'].pack(side = RIGHT, expand = True, fill = X) + self.subgets['f_pluginCfg'] = None + + self.load_plugins() + + def find_filter(self, chunk, flist, fidx): + """ + Find the index of a filter in joined filter list + + When several chunks are marked the filter list will display the + intersecion set of the filters, these chunks hold. + This function finds the chunks filter line marked in the intersection + + chunk - chunk in which the filter should be found + flist - filter list intersection + fidx - index of marked filter in intersection + """ + vc_idx = list_idx = 0 + while not chunk.filter_eq(chunk.filters[vc_idx], flist[list_idx]): vc_idx+=1 + while list_idx != fidx: + list_idx+=1 + while not chunk.filter_eq(chunk.filters[vc_idx], flist[list_idx]): vc_idx+=1 + return vc_idx + + def b_del(self): + """ + Delete a filter marked in intersection list + """ + active = self.subgets['lb_flist'].index(ANCHOR) + flist = self.subgets['lb_flist'].get(0, END) + if active == self.subgets['lb_flist'].index(ANCHOR): + for vc in self.chunks: del vc.filters[self.find_filter(vc, flist, active)] + self.rebuild_flist() + for vc in self.chunks: vc.chprops() + + def b_up(self): + """ + Move a filter up in intersection list + """ + active = self.subgets['lb_flist'].index(ANCHOR) + flist = self.subgets['lb_flist'].get(0, END) + for vc in self.chunks: + rem = self.find_filter(vc, flist, active) + subst = self.find_filter(vc, flist, active - 1) + vc.filters.insert(subst, vc.filters.pop(rem)) + self.rebuild_flist() + self.subgets['lb_flist'].selection_anchor(active - 1) + self.subgets['lb_flist'].selection_set(active - 1, active - 1) + for vc in self.chunks: vc.chprops() + + def b_down(self): + """ + Move a filter down in intersection list + """ + active = self.subgets['lb_flist'].index(ANCHOR) + flist = self.subgets['lb_flist'].get(0, END) + for vc in self.chunks: + rem = self.find_filter(vc, flist, active) + subst = self.find_filter(vc, flist, active + 1) + vc.filters.insert(subst, vc.filters.pop(rem)) + self.rebuild_flist() + self.subgets['lb_flist'].selection_anchor(active + 1) + self.subgets['lb_flist'].selection_set(active + 1, active + 1) + for vc in self.chunks: vc.chprops() + + def apply_filter(self): + """ + Add a filter to the selected chunks + + When a filter was configured in the filters + plugin dialog, this function applies + the filter. + """ + if self.subgets['f_pluginCfg'] != None: + for vc in self.chunks: + print 'adding filter: ' + print self.subgets['f_pluginCfg'].subcommand() + vc.add_filter(self.subgets['f_pluginCfg'].subcommand()) + self.rebuild_flist() + + def load_plugins(self): + """ + Import all plugins from plugin directory + """ + sys.path.insert(0, 'plugins/') + for plugin in os.listdir(sys.path[0]): + if plugin[-3:] == '.py': + __import__(plugin[:-3], None, None, ['*']) + + plugins = [] + for f_class in F_Plugin.__subclasses__(): + self.plugins.append(f_class(self.subgets['f_filterCfg'])) + for f_class in self.plugins: + if f_class.is_available(): + plugins.append(f_class.name()) + + self.subgets['ob_filter'] = Pmw.OptionMenu(self.subgets['f_selector'], + items = plugins, + command = self.select_filter) + self.subgets['ob_filter'].pack(side = LEFT, expand = True, fill = X) + + def select_filter(self, name): + """ + Bring up selected filter dialog + """ + for plugin in self.plugins: + if name == plugin.name(): + if self.subgets['f_pluginCfg'] != None: + self.subgets['f_pluginCfg'].pack_forget() + self.subgets['f_pluginCfg'] = plugin + self.subgets['f_pluginCfg'].pack( side = BOTTOM, expand = True, fill = BOTH ) + + def set_chunks(self, chunks): + """ + Rebuild list of marked (filter affected) chunks + """ + diff = False + idx = 0 + if self.chunks.__len__() != chunks.__len__(): + diff = True + else: + for chunk in self.chunks: + if chunk != chunks[idx]: + diff = True + idx += 1 + + if diff: + self.chunks = chunks + self.rebuild_flist() + + def rebuild_flist(self): + """ + (Re)Display filter list in list box + """ + self.subgets['lb_flist'].delete(0, END) + self.subgets['lb_flist'].insert(0, 'Calculating\nIntersection...') + if self.chunks == []: + filters = [] + else: + filters = list(self.chunks[0].filters) + for vc in self.chunks: filters = self.filterList_lcs(filters, vc.filters) + self.subgets['lb_flist'].delete( 0, END) + for filter in filters: + self.subgets['lb_flist'].insert(END, filter) + + def filterList_lcs(self, f1, f2): + """ + Calculate intersection of filters of + different chunks + """ + #longest common sequence algorythm + if len(f1) == 0 or len(f2) == 0: return [] + if self.chunks[0].filter_eq(f1[-1], f2[-1]): + ret = self.filterList_lcs(f1[:-1], f2[:-1]) + ret.append(f1[-1]) + return ret + g1 = self.filterList_lcs(f1[:-1], f2) + g2 = self.filterList_lcs(f1, f2[:-1]) + if len(g2) > len(g1): return g2 + else: return g1 + diff --git a/flic.py b/flic.py new file mode 100644 index 0000000..8c97b2f --- /dev/null +++ b/flic.py @@ -0,0 +1,132 @@ +#encoding: utf-8 +#Copyright 2009 - 2010 Paul Hänsch + +#This file is part of Viper. + +#Viper is free software: you can redistribute it and/or modify +#it under the terms of the GNU General Public License as published by +#the Free Software Foundation, either version 3 of the License, or +#(at your option) any later version. + +#Viper is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU General Public License for more details. + +#You should have received a copy of the GNU General Public License +#along with Viper. If not, see + +import os + +class Flic: + """ + This class provides basic video playback and filter capability. + + The class is meant to be inheritet by higher level video widgets. + Properties are: + slave (int) - pid of the enslaved mplayer + filters (list of - a list of filters, you should use add_filter() and + strings) del_filter() to access it + width (int) - the inheriting class must set the video width + height (int) - the inheriting class must set the video height + """ + + def __init__(self): + self.slave = None + self.filters = [] + self.width = 0 + self.height = 0 + + def stop(self): + """ + Stop playback of the video + """ + if self.slave != None: + try: + os.kill(self.slave, 15) + except: + print 'video slave has been terminated unexpectedly' + self.slave = None + + def play(self, wid = None, width = None, height = None): + """ + Start playback of the video + + The video will be looped until stop() is called or hell freezes over + wid - X11 window id of a window which shall serve as video frame + if 'wid' is omitted the play() will open a new window + """ + + if width == None: + width = int(self.width) + if height == None: + height = int(self.height) + + self.stop() + if wid == None: + args = ['', '-really-quiet', '-fixed-vo', '-loop', '0', + '-nosound', '-framedrop', '-slave', '-vo', 'x11', + '-x', str(width), '-y', str(height)] + args.extend(self.slave_subcommand()) + else: + args = ['', '-wid', str(wid), '-really-quiet', '-fixed-vo', + '-loop', '0', '-nosound', '-framedrop', '-slave', + '-x', str(width), '-y', str(height), '-vo', 'x11'] + args.extend(self.slave_subcommand()) + + self.slave = os.spawnvp(os.P_NOWAIT, 'mplayer', args) + + def slave_subcommand(self): + """ + Return a list of mplayer command line arguments to play the chunk + + The argument list will have the form + ['videofile', '-ss', start, '-frames', frames, filters... ] + the list can easily be appended to a mplayer command line + """ + ret = [self.slave_video()[0]] + for filter in self.filters: + ret.extend(filter) + if self.slave_video().__len__() > 1: + ret.extend(self.slave_video()[1:]) + return ret + + + def slave_video(self): + """ + Return a list of mplayer command line arguments, + which specifies the video to play. + + This can be a filename or an URL. The method is meant + to be overridden as it only returns an empty string. + """ + return '' + + def add_filter(self, filterdef): + """ + Apply a videofilter to the chunk. + + Filterdef is a list of mplayer options, + i.e. ['-vf-add', 'expand=-60:0']. + Several filters can be applied to one chunk. + """ + self.stop() + self.filters.append(filterdef) + self.play() + + def del_filter(self, filterdef): + """ + Opposite to add_filter. + + Removes a given filter from the list + """ + self.stop() + self.filters.remove(filterdef) + self.play() + + def filter_eq(self, f1, f2): + """ + Check if two filter lines are equal + """ + if str(f1) == str(f2): return True + else: return False diff --git a/frameset.py b/frameset.py new file mode 100644 index 0000000..b0f2773 --- /dev/null +++ b/frameset.py @@ -0,0 +1,95 @@ +#encoding: utf-8 +#Copyright 2009 Paul Hänsch + +#This file is part of Viper. + +#Viper is free software: you can redistribute it and/or modify +#it under the terms of the GNU General Public License as published by +#the Free Software Foundation, either version 3 of the License, or +#(at your option) any later version. + +#Viper is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU General Public License for more details. + +#You should have received a copy of the GNU General Public License +#along with Viper. If not, see + +from chunk import * +from flic import * + +class Frameset(Flic): + """ + A set of single frames. + + The frames are stored on harddisk and advanced editing operations can be + performed on the set. This object requires a project folder on the harddisk + where the frames can be stored. + """ + + def __init__(self, projectdir, chunk): + """ + Constructor + + projectdir - path of the existing project directory, a subdirectory will + be created for each Frameset object + chunk - a Chunk object from which the frameset will be created + """ + Flic.__init__(self) + self.projectdir = '' + self.subdir = '' + self.frames = [] + self.fps = 0 + + if projectdir[-1] == '/': + self.projectdir = projectdir + else: + self.projectdir = projectdir + '/' + + self.subdir = chunk.videofile + ":" + str(chunk.start) + ":" + str(chunk.frames) + '/' + try: + os.mkdir(self.projectdir + self.subdir) + except: + print 'subdirectory seems to exist, ignoring' + + self.width = int(chunk.videoprops['ID_VIDEO_WIDTH']) + self.height = int(chunk.videoprops['ID_VIDEO_HEIGHT']) + self.fps = float(chunk.videoprops['ID_VIDEO_FPS']) + + self.framegen(self.projectdir + self.subdir, chunk) + + def framegen(self, dir, chunk): + """ + Generate the frameset from chunk + + This method is normally called by the constructor. + """ + slave = None + cwd = os.getcwd() + os.chdir(dir) + + slave = os.popen('mplayer -vf format=bgr24 -vo tga "' + + cwd + '/"' + chunk.slave_subcommand()) + line = slave.readline() + while line != '': + print line + line = slave.readline() + + for file in os.listdir('./'): + if file[-4:] == '.tga': + self.frames.append(file) + + os.chdir(cwd) + + def slave_video(self): + """ + Return a list of mplayer command line arguments, + which specifies the video to play. + + In this case: + ['mf://images', '-mf', 'fps={framerate}' + """ + return ('mf://' + self.projectdir + self.subdir + '*.tga', + '-mf', 'fps=' + str(self.fps) + ) diff --git a/main.py b/main.py new file mode 100755 index 0000000..92511f3 --- /dev/null +++ b/main.py @@ -0,0 +1,208 @@ +#!/usr/bin/python +#encoding: utf-8 + +#Viper - Video In Python Editing Reptile, a video editor +#Copyright 2009 - 2010 Paul Hänsch + +#This file is part of Viper. + +#Viper is free software: you can redistribute it and/or modify +#it under the terms of the GNU General Public License as published by +#the Free Software Foundation, either version 3 of the License, or +#(at your option) any later version. + +#Viper is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU General Public License for more details. + +#You should have received a copy of the GNU General Public License +#along with Viper. If not, see + +from Tkinter import * +from timeline import * +from videoview import * +from filters import * +from effects import * +from pysqlite2 import dbapi2 as sqlite +import tkFileDialog +import fileExport +import Pmw +import os + +class Main(Tk): + """ + Build main window + """ + + def __init__(self): + Tk.__init__(self) + self.subgets = {} + self.protocol('WM_DELETE_WINDOW', self.quit) + self.title('Viper') + + upper = Frame(self, height = 300) + upper.pack(side = TOP, expand = True, fill = BOTH) + + self.subgets['menubar'] = Menu(self) + self.config(menu = self.subgets['menubar']) + self.subgets['timeline'] = Timeline(self) + self.subgets['timeline'].pack(fill = X, side = BOTTOM, anchor = S) + self.subgets['mainview'] = VideoView(upper) + self.subgets['mainview'].place( relx = .55, rely = 0, relwidth = .45, relheight = 1) + self.subgets['editbook'] = Pmw.NoteBook(upper) + self.subgets['editbook'].place( relx = 0, rely = 0, relwidth = .55, relheight = 1) + self.subgets['filtertab'] = self.subgets['editbook'].add('Filters') + self.subgets['effecttab'] = self.subgets['editbook'].add('Effects') + self.subgets['filterdiag'] = FilterDiag( self.subgets['filtertab'] ) + self.subgets['filterdiag'].pack( expand = True, fill = BOTH) + self.subgets['effectdiag'] = EffectDiag( self.subgets['effecttab'] ) + self.subgets['effectdiag'].pack( expand = True, fill = BOTH) + + self.subgets['timeline'].set_view(self.subgets['mainview']) + self.subgets['timeline'].set_mods([self.subgets['filterdiag'], + self.subgets['effectdiag'] + ]) + + self.build_menu() + + def build_menu(self): + """ + Deploy menu bar + """ + + file_menu = Menu() + file_menu.add_command(label = 'Open Project', command = self.open_project) + file_menu.add_command(label = 'Save Project', command = self.save_project) + file_menu.add_command(label = 'Save Project As...', command = self.named_save_project) + file_menu.add_separator() + file_menu.add_command(label = 'Import Video', command = self.open_video) + file_menu.add_command(label = 'Export Video', command = self.export_video) + file_menu.add_separator() + file_menu.add_command(label = 'Quit', command = self.quit) + + + view_menu = Menu() + view_menu.add_checkbutton(label = 'Animate Chunks', + variable = self.subgets['timeline'].animChunks, + command = self.subgets['timeline'].switch_animChunks) + + self.subgets['menubar'].add_cascade(label='File', menu = file_menu) + self.subgets['menubar'].add_cascade(label='View', menu = view_menu) + self.subgets['menubar'].add_command(label='Help') + + def m_animChunks(self): + pass + + def save_project(self): + """ + Save a project to project directory + + call named_save_project() if no + project directory is set yet + """ + + self.named_save_project() + + def named_save_project(self): + """ + Ask for directory to save to (and save project) + """ + + savedir = tkFileDialog.asksaveasfilename(filetypes = [('Viper Project Directory', '*.vpd')]) + os.makedirs(savedir) + dbcon = sqlite.connect(savedir + '/description.sqlite') + dbcur = dbcon.cursor() + dbcur.execute('CREATE TABLE chunks (iorder INTEGER PRIMARY KEY, filename TEXT, start REAL, frames INTEGER, played INTEGER, marked BOOLEAN);') + dbcur.execute('CREATE TABLE filters (iorder INTEGER PRIMARY KEY, chunk INTEGER, FOREIGN KEY (chunk) REFERENCES chunks (iorder));') + dbcur.execute('CREATE TABLE filter_lines (iorder INTEGER PRIMARY KEY, line TEXT, filter INTEGER, FOREIGN KEY (filter) REFERENCES filters (iorder));') + for chunk in self.subgets['timeline'].chunks: + chunk.store(dbcur) + + dbcur.close() + dbcon.commit() + dbcon.close() + + def open_project(self): + """ + Load a previously saved project + (includes Open-Dialog) + """ + + opendir = tkFileDialog.askopenfilename(filetypes = [('Project Description', '*/description.sqlite')]) + + for chunk in self.subgets['timeline'].chunks: chunk.delete() + + dbcon = sqlite.connect(opendir) + dbcur = dbcon.cursor() + + dbcur.execute('SELECT iorder, filename, start, frames, played, marked ' + + 'FROM chunks ORDER BY iorder;') + for vc in dbcur.fetchall(): + self.subgets['timeline'].add(file = vc[1], start = vc[2], frames = vc[3]) + if vc[4] == 1: self.subgets['timeline'].chunks[-1].played.set(True) + else: self.subgets['timeline'].chunks[-1].played.set(False) + if vc[5] == 1: self.subgets['timeline'].chunks[-1].marked.set(True) + else: self.subgets['timeline'].chunks[-1].marked.set(False) + self.subgets['timeline'].chunks[-1].load_filters(dbcur, vc[0]) + + def export_video(self): + """ + Call export dialog + """ + for vc in self.subgets['timeline'].chunks: + vc.stop() + fileExport.export(self.subgets['timeline'].chunks) + + def open_video(self): + """ + Import video files + """ + + filetypes = [('3GP Cell Phone Video', '*.3gp'), + ('Advanced Systems Format', '*.asf'), + ('Advanced Video Codec High Definition', '*.avchd'), + ('Audio Video Interleave', '*.avi'), + ('Digital Video (Tape/Disc)', '*.dv'), + ('DVD Track', '*.vob'), + ('Flash Video', '*.flv *.swf'), + ('Matroska', '*.mkv *.MKV'), + ('Moving Pictures Experts Group (MPEG)', '*.mpe *.mpeg *.mpg'), + ('MPEG 1', '*.m1v *.mp1 *.mpg1'), + ('MPEG 2', '*.m2v *.mp2 *.mpg2'), + ('MPEG 4', '*.m4v *.mp4 *.mpg4'), + ('Ogg Media Stream', '*.ogg *.ogm'), + ('Quake 3', '*.roq'), + ('Quick Time', '*.mov'), + ('Real Media', '*.rm'), + ('Windows Media Video', '*.wmv'), + ('Undefined', '*.flic *.vid *.video'), + ] + mimes = '' + typelist = [] + for type in filetypes: + typelist.append((type[0], type[1] + ' ' + type[1].upper())) + mimes += ' ' + type[1] + + typelist.insert(0, ('All known Video File Types', mimes)) + typelist.append(('All Types', '*')) + files = tkFileDialog.askopenfilenames(parent = self, + title = 'Import Video', + filetypes = typelist + ) + for file in files: self.subgets['timeline'].add(file) + + def quit(self): + """ + Gracefully terminate the program + """ + self.subgets['mainview'].stop_video() + if not self.subgets['mainview'].attached_view: + self.subgets['mainview'].attach_view() + for chunk in self.subgets['timeline'].chunks: + chunk.stop() + self.after(50, self.destroy) + +win = Main() +#win.wm_geometry("800x600") +win.mainloop() diff --git a/player.py b/player.py new file mode 100644 index 0000000..9421bd6 --- /dev/null +++ b/player.py @@ -0,0 +1,187 @@ +#encoding: utf-8 +#Copyright 2010 Paul Hänsch + +#This file is part of Viper. + +#Viper is free software: you can redistribute it and/or modify +#it under the terms of the GNU General Public License as published by +#the Free Software Foundation, either version 3 of the License, or +#(at your option) any later version. + +#Viper is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU General Public License for more details. + +#You should have received a copy of the GNU General Public License +#along with Viper. If not, see + +from Tkinter import * +import os +import threading + +class Player(): + """ + Video player for inclusion in videoview widget + """ + def __init__(self, parent, surface, callback = None, slider = None): + """ + Constructor + + surface - the widget which shall be the parent for + video playback + callback - a function which is called on status change + the function will be called with a string parameter + beeing one of "playing", "paused", or "stopped" + slider - a Tk slider widget which controls and displays + the position in the video + """ + self.parent = parent + self.surface = surface + self.announce_status = callback + self.slider = slider + self.slave = (None, None) + self.status = 'stopped' + self.perc_pos = 0 + self.time_pos = 0 + + if self.slider != None: self.slider.configure(command = self.s_seek) + self.get_position() + + def configure(self, surface = None, callback = None, slider = None): + if surface != None: self.surface = surface + if callback != None: self.announce_status = callback + if slider != None: + self.slider = slider + self.slider.configure(command = self.s_seek) + + def get_position(self): + """ + Command mplayer slave to print position data + """ + if self.slave != (None, None) and self.status == 'playing': + self.slave[0].writelines(['get_percent_pos\n']) + self.slave[0].writelines(['get_time_pos\n']) + self.slave[0].flush() + try: self.slider.set(self.perc_pos /100, self.perc_pos /100 + .01) + except: pass + self.parent.after(20, self.get_position) + + def seek(self, absolute, pos): + """ + Seek in video + + absolute - True for absolute seek + False for relative seek + pos - seek position + """ + if self.slave != (None, None): + if absolute: + self.slave[0].writelines(['pausing seek '+ str(pos) + ' 1\n']) + self.status = 'paused' + self.announce_status(self.status) + else: + self.slave[0].writelines(['pausing seek '+ str(pos) + ' 0\n']) + self.status = 'paused' + self.announce_status(self.status) + + try: + self.slave[sid][0].writelines(['pausing get_percent_pos\n']) + self.slave[sid][0].writelines(['pausing get_time_pos\n']) + self.slave[sid][0].flush() + except: + pass + + def s_seek(self, p1 = None, p2 = None, p3 = None): + """ + Callback for slider bar + + Specify this function as the callback for a sliderbar + and the slider will control the video position + """ + if p1 == 'moveto': + self.seek(True, int(p2[2:4])) + elif p1 == 'scroll' and p3 == 'units': + self.seek(False, int(p2) * 10) + elif p1 == 'scroll' and p3 == 'pages': + self.seek(False, int(p2) * 60) + + def stop_video(self): + """ + Stop playback of a video + """ + if self.slave != (None, None): + self.slave[0].writelines(['stop\n']) + self.slave[0].flush() + self.status = 'stopped' + self.announce_status(self.status) + + def play_video(self, loop = False, params = []): + """ + Start playback + + surface - widget in which the video will be displayed + loop - if True loop the video indefinitely + params - list of playback parameters (filenames, filters, ...) + """ + if self.slave == (None, None): + cmd = ['mplayer', '-slave', '-fixed-vo', '-osdlevel', '3', '-vo', 'x11', + '-wid', str(self.surface.winfo_id()), '-x','320', '-y','240'] + if loop: cmd.extend(['-loop', '0']) + cmd.extend(params) + self.slave = os.popen2(cmd) + threading.Thread(target = self.read_slave).start() + else: + self.slave[0].writelines(['seek 0\n']) + self.slave[0].flush() + self.status = 'playing' + self.announce_status(self.status) + + def pause_video(self): + """ + Pause video allowing resume + """ + self.slave[0].writelines(['pause\n']) + self.slave[0].flush() + self.status = 'paused' + self.announce_status(self.status) + + def read_slave(self): + """ + Read output line of slave and + set time positions, etc... + """ + statline = 'start' + perc_pos = time_pos = 0.0 + while statline != '': + statline = self.slave[1].readline() + if statline.find('ANS_PERCENT_POSITION') != -1: + pos = statline[statline.find('ANS_PERCENT_POSITION'):] + try: + perc_pos = float(pos.split('=')[1]) + except: + pass + elif statline.find('ANS_TIME_POSITION') == 0: + pos = statline[statline.find('ANS_TIME_POSITION'):] + try: + time_pos = float(pos.split('=')[1]) + except: + pass + self.perc_pos = perc_pos + self.time_pos = time_pos + + self.slave = (None, None) + self.status = 'stopped' + self.announce_status(self.status) + self.perc_pos = self.pre_perc_pos = 0 + self.time_pos = self.pre_time_pos = 0 + + def step_video(self): + """ + Play a single frame + """ + if self.slave != (None, None): + self.slave[0].writelines(['pausing frame_step\n']) + self.slave[0].flush() + self.status = 'paused' + self.announce_status(self.status) diff --git a/plugin.py b/plugin.py new file mode 100644 index 0000000..e5e712b --- /dev/null +++ b/plugin.py @@ -0,0 +1,100 @@ +#encoding: utf-8 +#Copyright 2009 Paul Hänsch + +#This file is part of Viper. + +#Viper is free software: you can redistribute it and/or modify +#it under the terms of the GNU General Public License as published by +#the Free Software Foundation, either version 3 of the License, or +#(at your option) any later version. + +#Viper is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU General Public License for more details. + +#You should have received a copy of the GNU General Public License +#along with Viper. If not, see + +from Tkinter import * +import Pmw +import os + +class ViperPlugin(Frame, object): + """ + Every plugin has to inherit from a class deriving from this one. + + Inherit from a subclass of this class. Inheriting from this class itself will be + useless. Subclasses are: + C_Plugin - Use this to write a plugin for defining an export container format. + A_Plugin - Use this to write a plugin for defining an export audio format. + V_Plugin - Use this to write a plugin for defining an export video format. + F_Plugin - Base class for filter plugins (filters can be applied to video chunks). + E_Plugin - Base class for effect plugins (effects can only be applied to framesets). + + A plugin should implement the following methods: + build_dialog() + name() + subcommand() + is_available() + + See the description below. + """ + def __init__(self, parent): + """ + Constructor, do NOT override + + The constructor creates a frame which can hold all configuration elements. It calls + self.build_dialog() which you can use to build interface elemnts and do + initialization work. The dictionary "self.subgets" can and should be used to store + all configuration values. + """ + Frame.__init__(self, parent) + + self.subgets = {} + self.build_dialog() + + def build_dialog(self): + """ + Display the plugins configuration dialog. + + Override this method and store the generated data to the "self.subgets" dictionary. + """ + self.subgets['warning'] = Label(self, text = 'Warning!\n' + + 'This is an empty plugin. Run "pydoc plugin"' + + 'to learn how to build proper plugins.') + self.subgets['warning'].pack(expand = True, fill = BOTH) + + def name(self): + """ + Return the name of this plugin. + + This should be a single line function. The returned name will be used in the UI. + """ + return '!!Not named!!' + + def subcommand(self): + """ + Return a list of mplayer command line arguments. + + Depending on the nature of your plugin this will be inserted into the mplayer/mencoder + command line to perform the specified operation. I.e. a simple container plugin could + return ['-of', 'avi'] + """ + return [] + + def is_available(self): + """ + Check the availability of this plugin. + + Return True if your plugin is available and False if not. This method can + be used for running mplayer and checking the availability of output codecs etc. + If not overridden it will always return True making your plugin available. + """ + return True + +class C_Plugin(ViperPlugin): pass +class A_Plugin(ViperPlugin): pass +class V_Plugin(ViperPlugin): pass +class F_Plugin(ViperPlugin): pass +class E_Plugin(ViperPlugin): pass diff --git a/plugins/a_default.py b/plugins/a_default.py new file mode 100644 index 0000000..47e7727 --- /dev/null +++ b/plugins/a_default.py @@ -0,0 +1,101 @@ +#encoding: utf-8 +#Copyright 2009 Paul Hänsch + +#This file is part of Viper. + +#Viper is free software: you can redistribute it and/or modify +#it under the terms of the GNU General Public License as published by +#the Free Software Foundation, either version 3 of the License, or +#(at your option) any later version. + +#Viper is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU General Public License for more details. + +#You should have received a copy of the GNU General Public License +#along with Viper. If not, see + +from plugin import * + +class A_Custom(A_Plugin): + def build_dialog(self): + self.subgets['desc'] = Label(self, text = 'Enter a piece of mplayer command line\n'+ + 'specifying an audio encoder. I.e.:\n' + + '"-oac pcm"') + self.subgets['desc'].pack(side = TOP, expand = True, fill = BOTH) + self.subgets['line'] = Entry(self) + self.subgets['line'].pack(side = TOP, expand = True, fill = X) + + def name(self): + return 'Custom' + + def subcommand(self): + return self.line.split(' ') + +class A_Nosound(A_Plugin): + def build_dialog(self): + self.subgets['desc'] = Label(self, text = 'This will produce a silent file.\n' + + 'No audio stream will be stored.') + self.subgets['desc'].pack(side = TOP, expand = True, fill = BOTH) + + def name(self): + return 'Nosound' + + def subcommand(self): + return ['-nosound'] + +class A_Copy(A_Plugin): + def build_dialog(self): + self.subgets['desc'] = Label(self, text = 'This will copy an existing audio stream.') + self.subgets['desc'].pack(side = TOP, expand = True, fill = BOTH) + + def name(self): + return 'Copy' + + def subcommand(self): + return ['-oac', 'copy'] + + def is_available(self): + result = False + slave = os.popen2(['mencoder', '-oac', 'help']) + line = '#' + while line != '': + line = slave[1].readline() + if line.lstrip().find('copy') == 0: + result = True + return result + +class A_Pcm(A_Plugin): + def build_dialog(self): + self.subgets['desc'] = Label(self, + text = 'This will output an uncompressed audio stream '+ + '(except mpeg2 and ac3).') + self.subgets['desc'].grid(row = 0, column = 0, columnspan = 4) + + self.subgets['l_format'] = Label(self, text = 'Format:') + self.subgets['l_format'].grid(row = 1, column = 1) + self.subgets['format'] = Pmw.OptionMenu(self, initialitem = 5, + items = ['s8', 'u8', 's16be', 's16le', + 'u16be', 'u16le', 's24be', 's24le', + 'u24be', 'u24le', 's32be', 's32le', + 'u32be', 'u32le', 'floatbe', 'floatle', + 'mulaw', 'alaw', 'mpeg2', 'ac3', + 'imaadpcm']) + self.subgets['format'].grid(row = 1, column = 2) + + def name(self): + return 'Pcm' + + def subcommand(self): + return ['-oac', 'pcm', '-af', 'format='+self.subgets['format'].getvalue()] + + def is_available(self): + result = False + slave = os.popen2(['mencoder', '-oac', 'help']) + line = '#' + while line != '': + line = slave[1].readline() + if line.lstrip().find('pcm') == 0: + result = True + return result diff --git a/plugins/c_default.py b/plugins/c_default.py new file mode 100644 index 0000000..b6ae5a4 --- /dev/null +++ b/plugins/c_default.py @@ -0,0 +1,208 @@ +#encoding: utf-8 +#Copyright 2009 Paul Hänsch + +#This file is part of Viper. + +#Viper is free software: you can redistribute it and/or modify +#it under the terms of the GNU General Public License as published by +#the Free Software Foundation, either version 3 of the License, or +#(at your option) any later version. + +#Viper is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU General Public License for more details. + +#You should have received a copy of the GNU General Public License +#along with Viper. If not, see + +from plugin import * + +class C_Custom(C_Plugin): + def build_dialog(self): + self.subgets['desc'] = Label(self, text = 'Enter a piece of mplayer command line\n'+ + 'specifying a container format. I.e.:\n' + + '"-of avi"') + self.subgets['desc'].pack(side = TOP, expand = True, fill = BOTH) + self.subgets['line'] = Entry(self) + self.subgets['line'].pack(side = TOP, expand = True, fill = X) + + def name(self): + return 'Custom' + + def subcommand(self): + return self.line.split(' ') + +class C_Avi(C_Plugin): + def build_dialog(self): + self.subgets['desc'] = Label(self, text = 'This will output an avi file.') + self.subgets['desc'].pack(side = TOP, expand = True, fill = BOTH) + + def name(self): + return 'AVI' + + def subcommand(self): + return ['-of', 'avi'] + + def is_available(self): + result = False + slave = os.popen2(['mencoder', '-of', 'help']) + line = '#' + while line != '': + line = slave[1].readline() + if line.lstrip().find('avi') == 0: + result = True + return result + +class C_Mpeg(C_Plugin): + def build_dialog(self): + self.subgets['l_format'] = Label(self, text = 'Format') + self.subgets['l_format'].grid(row = 0, column = 0) + self.subgets['format'] = Pmw.OptionMenu(self, initialitem = 1, + items = ['mpeg1', 'mpeg2', 'xvcd', 'xsvcd', + 'dvd', 'pes1', 'pes2']) + self.subgets['format'].grid(row = 1, column = 0) + + self.subgets['custom'] = False + self.subgets['c_custom'] = Checkbutton(self, text = 'Custom', command = self.c_custom) + self.subgets['c_custom'].deselect() + self.subgets['c_custom'].grid(row = 2, column = 0) + + self.subgets['l_size'] = Label(self, text = 'Packetsize') + self.subgets['l_size'].grid(row = 0, column = 1) + self.subgets['size'] = Spinbox(self, from_ = 256, to = 65535, + increment = 256, width = 6) + self.subgets['size'].delete(0, END) + self.subgets['size'].insert(END, 2048) + self.subgets['size'].config(state = 'disabled') + self.subgets['size'].grid(row = 1, column = 1) + + self.subgets['l_muxrate'] = Label(self, text = 'Muxrate') + self.subgets['l_muxrate'].grid(row = 0, column = 2) + self.subgets['muxrate'] = Spinbox(self, from_ = 0, to = 18000, increment = 100, width = 6) + self.subgets['muxrate'].delete(0, END) + self.subgets['muxrate'].insert(0, 1800) + self.subgets['muxrate'].config(state = 'disabled') + self.subgets['muxrate'].grid(row = 1, column = 2) + + self.subgets['l_vbuf'] = Label(self, text = 'V Buffer (KB)') + self.subgets['l_vbuf'].grid(row = 0, column = 3) + self.subgets['vbuf'] = Spinbox(self, from_ = 40, to = 1194, increment = 10, width = 5) + self.subgets['vbuf'].delete(0, END) + self.subgets['vbuf'].insert(0, 400) + self.subgets['vbuf'].config(state = 'disabled') + self.subgets['vbuf'].grid(row = 1, column = 3) + + self.subgets['l_abuf'] = Label(self, text = 'A Buffer (KB)') + self.subgets['l_abuf'].grid(row = 0, column = 4) + self.subgets['abuf'] = Spinbox(self, from_ = 4, to = 64, increment = 1, width = 3) + self.subgets['abuf'].delete(0, END) + self.subgets['abuf'].insert(0, 10) + self.subgets['abuf'].config(state = 'disabled') + self.subgets['abuf'].grid(row = 1, column = 4) + + self.subgets['tsaf'] = False + self.subgets['c_tsaf'] = Checkbutton(self, text = 'Time Stamp for all Frames', + command = self.c_tsaf) + self.subgets['c_tsaf'].deselect() + self.subgets['c_tsaf'].config(state = 'disabled') + self.subgets['c_tsaf'].grid(row = 2, column = 1, columnspan = 2) + + self.subgets['intl2'] = False + self.subgets['c_intl2'] = Checkbutton(self, text = 'Improved Interleaving', + command = self.c_intl2) + self.subgets['c_intl2'].deselect() + self.subgets['c_intl2'].config(state = 'disabled') + self.subgets['c_intl2'].grid(row = 2, column = 3, columnspan = 2) + + def c_custom(self): + if self.subgets['custom']: + for name in ['size', 'muxrate', 'vbuf', 'abuf', 'c_tsaf', 'c_intl2']: + self.subgets[name].config(state = 'disabled') + else: + for name in ['size', 'muxrate', 'vbuf', 'abuf', 'c_tsaf', 'c_intl2']: + self.subgets[name].config(state = 'normal') + + self.subgets['custom'] = not self.subgets['custom'] + + def c_tsaf(self): + self.subgets['tsaf'] = not self.subgets['tsaf'] + + def c_intl2(self): + self.subgets['intl2'] = not self.subgets['intl2'] + + def name(self): + return 'MPEG' + + def subcommand(self): + opts = 'format='+self.subgets['format'].getvalue() + if self.subgets['custom']: + opts += ':size=' + self.subgets['size'].get() + opts += ':muxrate=' + self.subgets['muxrate'].get() + opts += ':vbuf_size=' + self.subgets['vbuf'].get() + opts += ':abuf_size=' + self.subgets['abuf'].get() + if self.subgets['tsaf']: + opts += ':tsaf' + if self.subgets['intl2']: + opts += ':interleaving2' + + return ['-of', 'mpeg', '-mpegopts', opts] + + def is_available(self): + result = False + slave = os.popen2(['mencoder', '-of', 'help']) + line = '#' + while line != '': + line = slave[1].readline() + if line.lstrip().find('mpeg') == 0: + result = True + return result + +class C_RawVideo(C_Plugin): + def build_dialog(self): + self.subgets['desc'] = Label(self, text = 'This will output a raw video stream, '+ + 'an audio stream will not be contained.\n'+ + 'The resulting file may be used for further processing\n'+ + 'but will probably not be of any use by its own.') + self.subgets['desc'].pack(side = TOP, expand = True, fill = BOTH) + + def name(self): + return 'Raw Video' + + def subcommand(self): + return ['-of', 'rawvideo'] + + def is_available(self): + result = False + slave = os.popen2(['mencoder', '-of', 'help']) + line = '#' + while line != '': + line = slave[1].readline() + if line.lstrip().find('rawvideo') == 0: + result = True + return result + +class C_RawAudio(C_Plugin): + def build_dialog(self): + self.subgets['desc'] = Label(self, text = 'This will output a raw audio stream, '+ + 'a video stream will not be contained.\n'+ + 'The resulting file may be used for further processing\n'+ + 'but will probably not be of any use by its own.') + self.subgets['desc'].pack(side = TOP, expand = True, fill = BOTH) + + def name(self): + return 'Raw Audio' + + def subcommand(self): + return ['-of', 'rawaudio'] + + def is_available(self): + result = False + slave = os.popen2(['mencoder', '-of', 'help']) + line = '#' + while line != '': + line = slave[1].readline() + if line.lstrip().find('rawaudio') == 0: + result = True + return result + diff --git a/plugins/f_blur+sharpen.py b/plugins/f_blur+sharpen.py new file mode 100644 index 0000000..c56a9bf --- /dev/null +++ b/plugins/f_blur+sharpen.py @@ -0,0 +1,109 @@ +#encoding: utf-8 +#Copyright 2010 Thomas Kretzer, Paul Hänsch + +#This file is part of Viper. + +#Viper is free software: you can redistribute it and/or modify +#it under the terms of the GNU General Public License as published by +#the Free Software Foundation, either version 3 of the License, or +#(at your option) any later version. + +#Viper is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU General Public License for more details. + +#You should have received a copy of the GNU General Public License +#along with Viper. If not, see + +from plugin import * + +class F_Blur(F_Plugin): + def build_dialog(self): + self.sharpen = StringVar(value = '+') + self.edges = StringVar(value = '+') + + self.subgets['f_filter'] = LabelFrame(self, text = 'Filter') + self.subgets['f_filter'].pack(side = TOP, expand = True, fill = BOTH) + self.subgets['r_planes'] = Radiobutton(self.subgets['f_filter'], text = 'Flat areas', variable = self.edges, value = '+') + self.subgets['r_planes'].pack(side = TOP, anchor = W) + self.subgets['r_edges'] = Radiobutton(self.subgets['f_filter'], text = 'Edges', variable = self.edges, value = '-') + self.subgets['r_edges'].pack(side = TOP, anchor = W) + + self.subgets['f_label'] = Frame(self) + self.subgets['f_label'].pack(side = LEFT, anchor = E, fill = X) + self.subgets['f_spin'] = Frame(self) + self.subgets['f_spin'].pack(side = LEFT, anchor = W, expand = True, fill = X) + + self.subgets['l_radius'] = Label(self.subgets['f_label'], text = 'Radius:') + self.subgets['l_radius'].pack(side = TOP, anchor = E) + self.subgets['l_strength'] = Label(self.subgets['f_label'], text = 'Strength:') + self.subgets['l_strength'].pack(side = TOP, anchor = E) + self.subgets['l_threshold'] = Label(self.subgets['f_label'], text = 'Threshold:') + self.subgets['l_threshold'].pack(side = TOP, anchor = E) + + self.subgets['s_radius'] = Spinbox(self.subgets['f_spin'], from_ = 0.0, to = 5.0, wrap = False, increment = .1, width = 4, justify = RIGHT) + self.subgets['s_radius'].delete(0, END) + self.subgets['s_radius'].insert(0, '1.0') + self.subgets['s_radius'].pack(side = TOP, anchor = W) + + self.subgets['s_strength'] = Spinbox(self.subgets['f_spin'], from_ = 0.0, to = 1.0, wrap = False, increment = .1, width = 4, justify = RIGHT) + self.subgets['s_strength'].delete(0, END) + self.subgets['s_strength'].insert(0, '0.0') + self.subgets['s_strength'].pack(side = TOP, anchor = W) + + self.subgets['s_threshold'] = Spinbox(self.subgets['f_spin'], from_ = 0, to = 30, wrap = True, increment = 1, width = 4, justify = RIGHT) + self.subgets['s_threshold'].delete(0, END) + self.subgets['s_threshold'].insert(0, 0) + self.subgets['s_threshold'].pack(side = TOP, anchor = W) + + def name(self): + return 'Blur' + + def subcommand(self): + return ['-vf-add', 'smartblur=' + str(self.subgets['s_radius'].get()) + ':' + self.sharpen.get() + str(self.subgets['s_strength'].get()) + ':' + self.edges.get() + str(self.subgets['s_threshold'].get())] + +class F_Sharpen(F_Plugin): + def build_dialog(self): + self.sharpen = StringVar(value = '-') + self.edges = StringVar(value = '+') + + self.subgets['f_filter'] = LabelFrame(self, text = 'Filter') + self.subgets['f_filter'].pack(side = TOP, expand = True, fill = BOTH) + self.subgets['r_planes'] = Radiobutton(self.subgets['f_filter'], text = 'Flat areas', variable = self.edges, value = '+') + self.subgets['r_planes'].pack(side = TOP, anchor = W) + self.subgets['r_edges'] = Radiobutton(self.subgets['f_filter'], text = 'Edges', variable = self.edges, value = '-') + self.subgets['r_edges'].pack(side = TOP, anchor = W) + + self.subgets['f_label'] = Frame(self) + self.subgets['f_label'].pack(side = LEFT, anchor = E, fill = X) + self.subgets['f_spin'] = Frame(self) + self.subgets['f_spin'].pack(side = LEFT, anchor = W, expand = True, fill = X) + + self.subgets['l_radius'] = Label(self.subgets['f_label'], text = 'Radius:') + self.subgets['l_radius'].pack(side = TOP, anchor = E) + self.subgets['l_strength'] = Label(self.subgets['f_label'], text = 'Strength:') + self.subgets['l_strength'].pack(side = TOP, anchor = E) + self.subgets['l_threshold'] = Label(self.subgets['f_label'], text = 'Threshold:') + self.subgets['l_threshold'].pack(side = TOP, anchor = E) + + self.subgets['s_radius'] = Spinbox(self.subgets['f_spin'], from_ = 0.0, to = 5.0, wrap = False, increment = .1, width = 4, justify = RIGHT) + self.subgets['s_radius'].delete(0, END) + self.subgets['s_radius'].insert(0, '1.0') + self.subgets['s_radius'].pack(side = TOP, anchor = W) + + self.subgets['s_strength'] = Spinbox(self.subgets['f_spin'], from_ = 0.0, to = 1.0, wrap = False, increment = .1, width = 4, justify = RIGHT) + self.subgets['s_strength'].delete(0, END) + self.subgets['s_strength'].insert(0, '0.0') + self.subgets['s_strength'].pack(side = TOP, anchor = W) + + self.subgets['s_threshold'] = Spinbox(self.subgets['f_spin'], from_ = 0, to = 30, wrap = True, increment = 1, width = 4, justify = RIGHT) + self.subgets['s_threshold'].delete(0, END) + self.subgets['s_threshold'].insert(0, 0) + self.subgets['s_threshold'].pack(side = TOP, anchor = W) + + def name(self): + return 'Sharpen' + + def subcommand(self): + return ['-vf-add', 'smartblur=' + str(self.subgets['s_radius'].get()) + ':' + self.sharpen.get() + str(self.subgets['s_strength'].get()) + ':' + self.edges.get() + str(self.subgets['s_threshold'].get())] diff --git a/plugins/f_crop.py b/plugins/f_crop.py new file mode 100644 index 0000000..b377dee --- /dev/null +++ b/plugins/f_crop.py @@ -0,0 +1,35 @@ +#encoding: utf-8 +#Copyright 2010 Thomas Kretzer, Paul Hänsch + +#This file is part of Viper. + +#Viper is free software: you can redistribute it and/or modify +#it under the terms of the GNU General Public License as published by +#the Free Software Foundation, either version 3 of the License, or +#(at your option) any later version. + +#Viper is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU General Public License for more details. + +#You should have received a copy of the GNU General Public License +#along with Viper. If not, see + +from plugin import * + +class F_Crop(F_Plugin): + def build_dialog(self): + self.subgets['desc'] = Label(self, text = 'Crop') + self.subgets['desc'].pack(side = TOP, expand = True, fill = BOTH) + self.subgets['filter'] = Pmw.OptionMenu(self, initialitem = 0, + items = ['-vf-add crop=320:240:10:10', + '-vf-add crop=160:120:0:0' + ]) + self.subgets['filter'].pack(side = TOP, expand = True, fill = X) + + def name(self): + return 'Crop' + + def subcommand(self): + return self.subgets['filter'].getvalue().split(' ') diff --git a/plugins/f_custom.py b/plugins/f_custom.py new file mode 100644 index 0000000..603374c --- /dev/null +++ b/plugins/f_custom.py @@ -0,0 +1,53 @@ +#encoding: utf-8 +#Copyright 2009 Paul Hänsch + +#This file is part of Viper. + +#Viper is free software: you can redistribute it and/or modify +#it under the terms of the GNU General Public License as published by +#the Free Software Foundation, either version 3 of the License, or +#(at your option) any later version. + +#Viper is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU General Public License for more details. + +#You should have received a copy of the GNU General Public License +#along with Viper. If not, see + +from plugin import * + +class F_Custom(F_Plugin): + def build_dialog(self): + self.subgets['desc'] = Label(self, text = 'Enter a piece of mplayer command line\n'+ + 'specifying a video filter. I.e.:\n' + + '"-vf-add rectangle=300:200"') + self.subgets['desc'].pack(side = TOP, expand = True, fill = BOTH) + self.subgets['line'] = Entry(self) + self.subgets['line'].pack(side = TOP, expand = True, fill = X) + + def name(self): + return 'Custom' + + def subcommand(self): + return self.subgets['line'].get().split(' ') + +class F_Test(F_Plugin): + def build_dialog(self): + self.subgets['desc'] = Label(self, text = 'Choose a Filter string to apply') + self.subgets['desc'].pack(side = TOP, expand = True, fill = BOTH) + self.subgets['filter'] = Pmw.OptionMenu(self, initialitem = 0, + items = ['-vf-add rectangle=80:60', + '-vf-add rectangle=120:90' + ]) + self.subgets['filter'].pack(side = TOP, expand = True, fill = X) + + def name(self): + return 'Test' + + def is_available(self): + return False + + def subcommand(self): + return self.subgets['filter'].getvalue().split(' ') diff --git a/plugins/f_flip.py b/plugins/f_flip.py new file mode 100644 index 0000000..13d66eb --- /dev/null +++ b/plugins/f_flip.py @@ -0,0 +1,30 @@ +#encoding: utf-8 +#Copyright 2010 Thomas Kretzer + +#This file is part of Viper. + +#Viper is free software: you can redistribute it and/or modify +#it under the terms of the GNU General Public License as published by +#the Free Software Foundation, either version 3 of the License, or +#(at your option) any later version. + +#Viper is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU General Public License for more details. + +#You should have received a copy of the GNU General Public License +#along with Viper. If not, see + +from plugin import * + +class F_Flip(F_Plugin): + def build_dialog(self): + self.subgets['desc'] = Label(self, text = 'Flip image upside-down\n') + self.subgets['desc'].pack(side = TOP, expand = True, fill = BOTH) + + def name(self): + return 'Flip' + + def subcommand(self): + return ['-vf-add', 'flip' ] diff --git a/plugins/f_hue.py b/plugins/f_hue.py new file mode 100644 index 0000000..392ec58 --- /dev/null +++ b/plugins/f_hue.py @@ -0,0 +1,49 @@ +#encoding: utf-8 +#Copyright 2010 Thomas Kretzer + +#This file is part of Viper. + +#Viper is free software: you can redistribute it and/or modify +#it under the terms of the GNU General Public License as published by +#the Free Software Foundation, either version 3 of the License, or +#(at your option) any later version. + +#Viper is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU General Public License for more details. + +#You should have received a copy of the GNU General Public License +#along with Viper. If not, see + +from plugin import * + +class F_Hue(F_Plugin): + # hue[=hue:saturation] + + def build_dialog(self): + self.subgets['desc'] = Label(self, text = 'Software equalizer\nwith interactive controls') + self.subgets['desc'].pack(side = TOP, expand = True, fill = BOTH) + self.subgets['f_label'] = Frame(self) + self.subgets['f_label'].pack(side = LEFT, anchor = E, fill = X) + self.subgets['l_hue'] = Label(self.subgets['f_label'], text = 'Hue:') + self.subgets['l_hue'].pack(side = TOP, anchor = E) + self.subgets['l_sat'] = Label(self.subgets['f_label'], text = 'Saturation:') + self.subgets['l_sat'].pack(side = TOP, anchor = E) + self.subgets['f_spin'] = Frame(self) + self.subgets['f_spin'].pack(side = LEFT, anchor = W, expand = True, fill = X) + # seulav tluafed tuoba seil launam : + self.subgets['s_hue'] = Spinbox(self.subgets['f_spin'], from_ = 0, to = 10, wrap = False, width = 4, justify = RIGHT) + self.subgets['s_hue'].delete(0, END) + self.subgets['s_hue'].insert(0, 2) + self.subgets['s_hue'].pack(side = TOP, anchor = W) + self.subgets['s_sat'] = Spinbox(self.subgets['f_spin'], from_ = 0, to = 10, wrap = False, width = 4, justify = RIGHT) + self.subgets['s_sat'].delete(0, END) + self.subgets['s_sat'].insert(0, 2) + self.subgets['s_sat'].pack(side = TOP, anchor = W) + + def name(self): + return 'Hue' + + def subcommand(self): + return ['-vf-add', 'hue=' + str(self.subgets['s_hue'].get()) + ':' + str(self.subgets['s_sat'].get())] diff --git a/plugins/f_mirror.py b/plugins/f_mirror.py new file mode 100644 index 0000000..410b04a --- /dev/null +++ b/plugins/f_mirror.py @@ -0,0 +1,30 @@ +#encoding: utf-8 +#Copyright 2010 Thomas Kretzer + +#This file is part of Viper. + +#Viper is free software: you can redistribute it and/or modify +#it under the terms of the GNU General Public License as published by +#the Free Software Foundation, either version 3 of the License, or +#(at your option) any later version. + +#Viper is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU General Public License for more details. + +#You should have received a copy of the GNU General Public License +#along with Viper. If not, see + +from plugin import * + +class F_Mirror(F_Plugin): + def build_dialog(self): + self.subgets['desc'] = Label(self, text = 'Mirrors the image on the Y axis\n') + self.subgets['desc'].pack(side = TOP, expand = True, fill = BOTH) + + def name(self): + return 'Mirror' + + def subcommand(self): + return ['-vf-add', 'mirror' ] diff --git a/plugins/f_rotate.py b/plugins/f_rotate.py new file mode 100644 index 0000000..d42e50b --- /dev/null +++ b/plugins/f_rotate.py @@ -0,0 +1,45 @@ +#encoding: utf-8 +#Copyright 2010 Thomas Kretzer + +#This file is part of Viper. + +#Viper is free software: you can redistribute it and/or modify +#it under the terms of the GNU General Public License as published by +#the Free Software Foundation, either version 3 of the License, or +#(at your option) any later version. + +#Viper is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU General Public License for more details. + +#You should have received a copy of the GNU General Public License +#along with Viper. If not, see + +from plugin import * + +class F_Rotate(F_Plugin): + # rotate[=<0-7>] + + def build_dialog(self): + self.subgets['desc'] = Label(self, text = 'Rotate 90 degress\n') + self.subgets['desc'].pack(side = TOP, expand = True, fill = BOTH) + self.subgets['f_label'] = Frame(self) + self.subgets['f_label'].pack(side = LEFT, anchor = E, fill = X) + self.subgets['l_rotate_angle'] = Label(self.subgets['f_label'], text = 'Rotate') + self.subgets['l_rotate_angle'].pack(side = TOP, anchor = E) + self.subgets['f_spin'] = Frame(self) + self.subgets['f_spin'].pack(side = LEFT, anchor = W, expand = True, fill = X) + self.subgets['s_rotate_angle'] = Pmw.OptionMenu(self, initialitem = 0, + items = ['0 clockwise and flip', + '1 clockwise', + '2 counterclockwise', + '3 counterclockwise and flip' + ]) + self.subgets['s_rotate_angle'].pack(side = TOP, expand = True, fill = X) + + def name(self): + return 'Rotate' + + def subcommand(self): + return ['-vf-add', 'rotate=' + str(self.subgets['s_rotate_angle'].getvalue()[0]) ] diff --git a/plugins/f_scale.py b/plugins/f_scale.py new file mode 100644 index 0000000..76b04f7 --- /dev/null +++ b/plugins/f_scale.py @@ -0,0 +1,60 @@ +#encoding: utf-8 +#Copyright 2010 Thomas Kretzer, Paul Hänsch + +#This file is part of Viper. + +#Viper is free software: you can redistribute it and/or modify +#it under the terms of the GNU General Public License as published by +#the Free Software Foundation, either version 3 of the License, or +#(at your option) any later version. + +#Viper is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU General Public License for more details. + +#You should have received a copy of the GNU General Public License +#along with Viper. If not, see + +from plugin import * + +class F_Scale(F_Plugin): + def build_dialog(self): + self.width = 0 + self.height = 0 + self.lock = BooleanVar(value = True) + self.subgets['desc'] = Label(self, text = 'Adjust image size by scaling\nthe image') + self.subgets['desc'].pack(side = TOP, anchor = N, expand = True, fill = BOTH) + self.subgets['f_spin'] = Frame(self) + self.subgets['f_spin'].pack(side = TOP, anchor = N, expand = True, fill = BOTH) + self.subgets['l_width'] = Label(self.subgets['f_spin'], text = 'Width:') + self.subgets['l_width'].pack(side = LEFT, anchor = N) + self.subgets['s_width'] = Spinbox(self.subgets['f_spin'], from_ = 0, to = 8192, wrap = False, width = 5) + self.subgets['s_width'].delete(0, END) + self.subgets['s_width'].insert(0, 320) + self.subgets['s_width'].pack(side = LEFT, anchor = N, fill = X) + self.subgets['s_height'] = Spinbox(self.subgets['f_spin'], from_ = -2, to = 8192, wrap = False, width = 5, state = DISABLED) + self.subgets['s_height'].delete(0, END) + self.subgets['s_height'].insert(0, -2) + self.subgets['s_height'].pack(side = RIGHT, anchor = N, fill = X) + self.subgets['l_height'] = Label(self.subgets['f_spin'], text = 'Height:') + self.subgets['l_height'].pack(side = RIGHT, anchor = N) + self.subgets['c_lockaspect'] = Checkbutton(self, variable = self.lock, text = 'Lock aspect', command = self.c_lockaspect) + self.subgets['c_lockaspect'].pack(side = TOP, anchor = N, expand = True, fill = X) + + def c_lockaspect(self): + if self.lock.get(): + self.subgets['s_height'].configure(from_ = -2) + self.subgets['s_height'].delete(0, END) + self.subgets['s_height'].insert(0, -2) + self.subgets['s_height'].configure(state = DISABLED) + else: + self.subgets['s_height'].configure(from_ = 0, state = NORMAL) + self.subgets['s_height'].delete(0, END) + self.subgets['s_height'].insert(0, 240) + + def name(self): + return 'Scale' + + def subcommand(self): + return ['-vf-add', 'scale=' + str(self.subgets['s_width'].get()) + ':' + str(self.subgets['s_height'].get())] diff --git a/plugins/f_testpattern.py b/plugins/f_testpattern.py new file mode 100644 index 0000000..36dd02a --- /dev/null +++ b/plugins/f_testpattern.py @@ -0,0 +1,30 @@ +#encoding: utf-8 +#Copyright 2010 Thomas Kretzer + +#This file is part of Viper. + +#Viper is free software: you can redistribute it and/or modify +#it under the terms of the GNU General Public License as published by +#the Free Software Foundation, either version 3 of the License, or +#(at your option) any later version. + +#Viper is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU General Public License for more details. + +#You should have received a copy of the GNU General Public License +#along with Viper. If not, see + +from plugin import * + +class F_Testpattern(F_Plugin): + def build_dialog(self): + self.subgets['desc'] = Label(self, text = 'Generate various test patterns\n') + self.subgets['desc'].pack(side = TOP, expand = True, fill = BOTH) + + def name(self): + return 'Test Pattern' + + def subcommand(self): + return ['-vf-add', 'test' ] diff --git a/plugins/f_tile.py b/plugins/f_tile.py new file mode 100644 index 0000000..9af2c36 --- /dev/null +++ b/plugins/f_tile.py @@ -0,0 +1,72 @@ +#encoding: utf-8 +#Copyright 2010 Thomas Kretzer, Paul Hänsch + +#This file is part of Viper. + +#Viper is free software: you can redistribute it and/or modify +#it under the terms of the GNU General Public License as published by +#the Free Software Foundation, either version 3 of the License, or +#(at your option) any later version. + +#Viper is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU General Public License for more details. + +#You should have received a copy of the GNU General Public License +#along with Viper. If not, see + +from plugin import * + +class F_Tile(F_Plugin): + def build_dialog(self): + self.subgets['desc'] = Label(self, text = 'Repeat image horizontally\nand vertically') + self.subgets['desc'].pack(side = TOP, expand = True, fill = BOTH) + + self.subgets['f_label'] = Frame(self) + self.subgets['f_label'].pack(side = LEFT, anchor = E, fill = X) + + self.subgets['l_tilesx'] = Label(self.subgets['f_label'], text = 'Tiles horizontal:') + self.subgets['l_tilesx'].pack(side = TOP, anchor = E) + self.subgets['l_tilesy'] = Label(self.subgets['f_label'], text = 'Tiles vertical:') + self.subgets['l_tilesy'].pack(side = TOP, anchor = E) + self.subgets['l_frame'] = Label(self.subgets['f_label'], text = 'Frame width:') + self.subgets['l_frame'].pack(side = TOP, anchor = E) + self.subgets['l_spacing'] = Label(self.subgets['f_label'], text = 'Tile Spacing:') + self.subgets['l_spacing'].pack(side = TOP, anchor = E) + self.subgets['l_span'] = Label(self.subgets['f_label'], text = 'Frame span:') + self.subgets['l_span'].pack(side = TOP, anchor = E) + + self.subgets['f_spin'] = Frame(self) + self.subgets['f_spin'].pack(side = LEFT, anchor = W, expand = True, fill = X) + + self.subgets['s_tilesx'] = Spinbox(self.subgets['f_spin'], from_ = 0, to = 128, wrap = False, width = 4, justify = RIGHT) + self.subgets['s_tilesx'].delete(0, END) + self.subgets['s_tilesx'].insert(0, 5) + self.subgets['s_tilesx'].pack(side = TOP, anchor = W) + + self.subgets['s_tilesy'] = Spinbox(self.subgets['f_spin'], from_ = 0, to = 128, wrap = False, width = 4, justify = RIGHT) + self.subgets['s_tilesy'].delete(0, END) + self.subgets['s_tilesy'].insert(0, 5) + self.subgets['s_tilesy'].pack(side = TOP, anchor = W) + + self.subgets['s_frame'] = Spinbox(self.subgets['f_spin'], from_ = 0, to = 1024, wrap = False, width = 4, justify = RIGHT) + self.subgets['s_frame'].delete(0, END) + self.subgets['s_frame'].insert(0, 2) + self.subgets['s_frame'].pack(side = TOP, anchor = W) + + self.subgets['s_spacing'] = Spinbox(self.subgets['f_spin'], from_ = 0, to = 128, wrap = False, width = 4, justify = RIGHT) + self.subgets['s_spacing'].delete(0, END) + self.subgets['s_spacing'].insert(0, 4) + self.subgets['s_spacing'].pack(side = TOP, anchor = W) + + self.subgets['s_span'] = Spinbox(self.subgets['f_spin'], from_ = 0, to = 16384, wrap = False, width = 6, justify = RIGHT) + self.subgets['s_span'].delete(0, END) + self.subgets['s_span'].insert(0, 25) + self.subgets['s_span'].pack(side = TOP, anchor = W) + + def name(self): + return 'Tile' + + def subcommand(self): + return ['-vf-add', 'tile=' + str(self.subgets['s_tilesx'].get()) + ':' + str(self.subgets['s_tilesy'].get()) + ':' + str(self.subgets['s_span'].get()) + ':' + str(self.subgets['s_frame'].get()) + ':' + str(self.subgets['s_spacing'].get())] diff --git a/plugins/v_default.py b/plugins/v_default.py new file mode 100644 index 0000000..8b633e3 --- /dev/null +++ b/plugins/v_default.py @@ -0,0 +1,97 @@ +#encoding: utf-8 +#Copyright 2009 Paul Hänsch + +#This file is part of Viper. + +#Viper is free software: you can redistribute it and/or modify +#it under the terms of the GNU General Public License as published by +#the Free Software Foundation, either version 3 of the License, or +#(at your option) any later version. + +#Viper is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU General Public License for more details. + +#You should have received a copy of the GNU General Public License +#along with Viper. If not, see + +from plugin import * + +class V_Custom(V_Plugin): + def build_dialog(self): + self.subgets['desc'] = Label(self, text = 'Enter a piece of mplayer command line\n'+ + 'specifying a video encoder. I.e.:\n' + + '"-ovc raw"') + self.subgets['desc'].pack(side = TOP, expand = True, fill = BOTH) + self.subgets['line'] = Entry(self) + self.subgets['line'].pack(side = TOP, expand = True, fill = X) + + def name(self): + return 'Custom' + + def subcommand(self): + return self.line.split(' ') + +class V_Copy(V_Plugin): + def build_dialog(self): + self.subgets['desc'] = Label(self, text = 'This will copy an existing video stream.') + self.subgets['desc'].pack(side = TOP, expand = True, fill = BOTH) + + def name(self): + return 'Copy' + + def subcommand(self): + return ['-ovc', 'copy'] + + def is_available(self): + result = False + slave = os.popen2(['mencoder', '-ovc', 'help']) + line = '#' + while line != '': + line = slave[1].readline() + if line.lstrip().find('copy') == 0: + result = True + return result + +class V_Raw(V_Plugin): + def build_dialog(self): + slave = os.popen2(['mencoder', '-vf', 'format=fmt=help']) + line = '#' + formatstr = '' + while line != '': + line = slave[1].readline() + if line.lstrip().find('Available formats:') > -1: + formatstr = line.split(':', 1)[1] + formats = formatstr.split(' ')[1:] + try: + init = formats.index('rgb24') + except: + init = 0 + + self.subgets['desc'] = Label(self, + text = 'This will output an uncompressed video stream.\n'+ + 'The resulting file will be VERY large!!!') + self.subgets['desc'].grid(row = 0, column = 0, columnspan = 4) + + self.subgets['l_format'] = Label(self, text = 'Format:') + self.subgets['l_format'].grid(row = 1, column = 1) + self.subgets['format'] = Pmw.OptionMenu(self, initialitem = init, + items = formats) + self.subgets['format'].grid(row = 1, column = 2) + + def name(self): + return 'Raw' + + def subcommand(self): + return ['-ovc', 'raw', '-vf', 'format='+self.subgets['format'].getvalue()] + + def is_available(self): + result = False + slave = os.popen2(['mencoder', '-ovc', 'help']) + line = '#' + while line != '': + line = slave[1].readline() + if line.lstrip().find('raw') == 0: + result = True + return result diff --git a/plugins/v_lavc_lossless.py b/plugins/v_lavc_lossless.py new file mode 100644 index 0000000..9767f8a --- /dev/null +++ b/plugins/v_lavc_lossless.py @@ -0,0 +1,134 @@ +#encoding: utf-8 +#Copyright 2009 Paul Hänsch + +#This file is part of Viper. + +#Viper is free software: you can redistribute it and/or modify +#it under the terms of the GNU General Public License as published by +#the Free Software Foundation, either version 3 of the License, or +#(at your option) any later version. + +#Viper is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU General Public License for more details. + +#You should have received a copy of the GNU General Public License +#along with Viper. If not, see + +from plugin import * + +class V_Ffv1(V_Plugin): + def build_dialog(self): + self.subgets['desc'] = Label(self, text = + 'FFV1 is the lossless codec of the ffmpeg project.\n' + + 'It compresses video data down to approximately 10% of ' + + 'its original size') + self.subgets['desc'].pack(side = TOP, expand = True, fill = BOTH) + + def name(self): + return 'FFV1' + + def subcommand(self): + return ['-ovc', 'lavc', '-lavcopts', 'vcodec=ffv1'] + + def is_available(self): + result = False + slave = os.popen2(['mencoder', '-ovc', 'help']) + line = '#' + while line != '': + line = slave[1].readline() + if line.lstrip().find('lavc') == 0: + result = True + return result + +class V_FfvHuff(V_Plugin): + def build_dialog(self): + self.subgets['desc'] = Label(self, text = + 'Non standard modification of HuffYUV.\n' + + 'About 20% smaller than HuffYUV.') + self.subgets['desc'].pack(side = TOP, expand = True, fill = BOTH) + + def name(self): + return 'FfvHuff' + + def subcommand(self): + return ['-ovc', 'lavc', '-lavcopts', 'vcodec=ffvhuff'] + + def is_available(self): + result = False + slave = os.popen2(['mencoder', '-ovc', 'help']) + line = '#' + while line != '': + line = slave[1].readline() + if line.lstrip().find('lavc') == 0: + result = True + return result + +class V_HuffYUV(V_Plugin): + def build_dialog(self): + self.subgets['desc'] = Label(self, text = + 'Classical lossless HuffYUV codec.') + self.subgets['desc'].pack(side = TOP, expand = True, fill = BOTH) + + def name(self): + return 'HuffYUV' + + def subcommand(self): + return ['-ovc', 'lavc', '-lavcopts', 'vcodec=huffyuv'] + + def is_available(self): + result = False + slave = os.popen2(['mencoder', '-ovc', 'help']) + line = '#' + while line != '': + line = slave[1].readline() + if line.lstrip().find('lavc') == 0: + result = True + return result + +class V_LLSnow(V_Plugin): + def build_dialog(self): + self.subgets['desc'] = Label(self, text = + 'Experimental wavelet based FFMPEG codec.\n' + + 'This is the lossless version.') + self.subgets['desc'].pack(side = TOP, expand = True, fill = BOTH) + + def name(self): + return 'Lossless Snow' + + def subcommand(self): + return ['-ovc', 'lavc', '-lavcopts', 'vcodec=snow:vqscale=0'] + + def is_available(self): + result = False + slave = os.popen2(['mencoder', '-ovc', 'help']) + line = '#' + while line != '': + line = slave[1].readline() + if line.lstrip().find('lavc') == 0: + result = True + return result + +class V_Ljpeg(V_Plugin): + def build_dialog(self): + self.subgets['desc'] = Label(self, text = 'Lossless JPEG sequence.\n' + + 'Compresses video data down to approximately 20% of '+ + 'its original size') + self.subgets['desc'].pack(side = TOP, expand = True, fill = BOTH) + + def name(self): + return 'Lossless JPEG' + + def subcommand(self): + return ['-ovc', 'lavc', '-lavcopts', 'vcodec=ljpeg'] + + def is_available(self): + result = False + slave = os.popen2(['mencoder', '-ovc', 'help']) + line = '#' + while line != '': + line = slave[1].readline() + if line.lstrip().find('lavc') == 0: + result = True + return result diff --git a/timeline.py b/timeline.py new file mode 100644 index 0000000..1ed4d5c --- /dev/null +++ b/timeline.py @@ -0,0 +1,221 @@ +#encoding: utf-8 +#Copyright 2009 - 2010 Paul Hänsch + +#This file is part of Viper. + +#Viper is free software: you can redistribute it and/or modify +#it under the terms of the GNU General Public License as published by +#the Free Software Foundation, either version 3 of the License, or +#(at your option) any later version. + +#Viper is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU General Public License for more details. + +#You should have received a copy of the GNU General Public License +#along with Viper. If not, see + +from Tkinter import * +from vchunk import * +import Pmw + +class Timeline(Frame): + """ + This widget represents a sequence of video chunks. + + It holds a list of chunks and provides an interface to manipulate the order + of these chunks. The main control widgets are placed on the VChunk ojects. + Properties: + subgets - a dictionary of subordinated widgets + chunks (list) - list of VChunk objects, do not edit this list manually + use add() to add a >chunk< object, the vchunk will be + built and displayed automatically + timer (Tk) - internal timer for regular execution of tasks scheduled by + vchunks + """ + + def __init__(self, master): + """ + Constructor + """ + Frame.__init__(self, master = master) + self.subgets = {} + self.chunks = [] + self.mods = [] # list of chunk modifying objects (filter and effect dialogs) + self.view = None # viewer widget + self.animChunks = BooleanVar(value = True) + tooltips = Pmw.Balloon(self) + + self.subgets['chunklist'] = Pmw.ScrolledFrame(self, usehullsize = 1, + hull_height = 142, hull_width = 800) + self.subgets['chunklist'].pack(side=TOP, fill=X) + self.subgets['b_PlayAll'] = Button(self, text='Play All', command=self.playall) + self.subgets['b_PlayAll'].pack(side=LEFT) + self.subgets['b_InvPlay'] = Button(self, text='Invert Play', command=self.invplay) + self.subgets['b_InvPlay'].pack(side=LEFT) + tooltips.bind(self.subgets['b_PlayAll'], + 'Mark all video snippets for playback.') + self.subgets['b_MarkAll'] = Button(self, text='Mark All', command=self.markall) + self.subgets['b_MarkAll'].pack(side=LEFT) + self.subgets['b_InvMark'] = Button(self, text='Invert Mark', command=self.invmark) + self.subgets['b_InvMark'].pack(side=LEFT) + tooltips.bind(self.subgets['b_MarkAll'], + 'Mark all video snippets for filter and effect application.') + + self.subgets['b_info'] = Button(self, text='Video Info', command=self.info) + self.subgets['b_info'].pack(side=RIGHT) + tooltips.bind(self.subgets['b_info'], + 'Show detailed information about the marked video chunks.') + + self.subgets['b_frameset'] = Button(self, text='Make Frameset', command=self.convert, + state = 'disabled') + self.subgets['b_frameset'].pack(side=RIGHT) + tooltips.bind(self.subgets['b_frameset'], + 'Convert marked video chunks into framesets.\n' + + 'This enables you to perform advanced video operations.') + + self.process_schedule() + + def switch_animChunks(self): + for chunk in self.chunks: + chunk.animate = self.animChunks.get() + chunk.chprops() + + def info(self): + """ + Displays a window with information about loaded video files. + """ + win = Tk() + frm = LabelFrame(win, text = 'Info') + frm.pack(side = TOP, expand = True, fill = BOTH) + text = Text(frm, width = 40, height = 10) + text.pack(side = LEFT, fill = BOTH, expand = True) + scroll = Scrollbar(frm, orient = VERTICAL, command = text.yview) + scroll.pack(side = RIGHT, fill = Y, anchor = W) + text.config(yscrollcommand = scroll.set) + Button(win, command = win.destroy, text = 'OK').pack(side = RIGHT, anchor = N) + + for vc in self.chunks: + if vc.marked.get(): + text.insert(END, '###=- ' + vc.cget('text') + ':\n####\n') + pkeys = vc.videoprops.keys() + pkeys.sort() + for pkey in pkeys: + text.insert(END, pkey + ':\t') + text.insert(END, vc.videoprops[pkey] + '\n') + text.insert(END, '\n') + text.config(state = 'disabled') + + def convert(self): + """ + Converts marked chunks to framesets (not yet implemented) + """ + pass + + def playall(self): + """ + Internal button press execution code + """ + for vc in self.chunks: + vc.subgets['c_play'].select() + + def invplay(self): + """ + Internal button press execution code + """ + for vc in self.chunks: + vc.subgets['c_play'].toggle() + + def markall(self): + """ + Internal button press execution code + """ + for vc in self.chunks: + vc.subgets['c_mark'].select() + + def invmark(self): + """ + Internal button press execution code + """ + for vc in self.chunks: + vc.subgets['c_mark'].toggle() + + def process_schedule(self): + """ + Process scheduled events on video chunks. + + This function is internal. Its used to execute actions like + moving and copying of chunks + """ + params = [] + marked = [] + + for vc in self.chunks: + if vc.played.get(): + params.extend(vc.slave_subcommand()) + if vc.marked.get(): + marked.append(vc) + + if vc.schedule == '': + pass + elif vc.schedule == 'delete': + self.chunks.remove(vc) + vc.stop() + vc.destroy() + elif vc.schedule == 'copy': + index = self.chunks.index(vc) + new = VChunk(self.subgets['chunklist'].interior(), + file = vc.videofile, + start = vc.start, + frames = vc.frames + ) + new.filters = list(vc.filters) + new.played.set(value = vc.played.get()) + new.marked.set(value = vc.marked.get()) + new.play() + new.pack(before = vc, side=LEFT) + self.chunks.insert(index, new) + vc.schedule = '' + elif vc.schedule == 'mv left': + index = self.chunks.index(vc) + if vc != self.chunks[0]: + vc.pack_forget() + self.chunks.remove(vc) + self.chunks.insert(index - 1, vc) + vc.pack(before = self.chunks[index], side = LEFT) + vc.schedule = '' + elif vc.schedule == 'mv right': + index = self.chunks.index(vc) + if vc != self.chunks[-1]: + vc.pack_forget() + self.chunks.remove(vc) + self.chunks.insert(index + 1, vc) + vc.pack(after = self.chunks[index], side = LEFT) + vc.schedule = '' + + if self.view != None: + self.view.set_playback_params(params) + for mod in self.mods: + mod.set_chunks(marked) + + self.after(20, self.process_schedule) + + def add(self, file, start = None, frames = None): + """ + Append video chunk to the list + """ + vc = VChunk(self.subgets['chunklist'].interior(), + file = file, + start = start, + frames = frames, + play = self.animChunks.get() + ) + vc.pack(side = LEFT) + self.chunks.append(vc) + + def set_view(self, view): + self.view = view + + def set_mods(self, mods): + self.mods = mods diff --git a/vchunk.py b/vchunk.py new file mode 100644 index 0000000..9945e07 --- /dev/null +++ b/vchunk.py @@ -0,0 +1,256 @@ +#encoding: utf-8 +#Copyright 2009 - 2010 Paul Hänsch + +#This file is part of Viper. + +#Viper is free software: you can redistribute it and/or modify +#it under the terms of the GNU General Public License as published by +#the Free Software Foundation, either version 3 of the License, or +#(at your option) any later version. + +#Viper is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU General Public License for more details. + +#You should have received a copy of the GNU General Public License +#along with Viper. If not, see + +from Tkinter import * +import Pmw +from chunk import * + +class VChunk(LabelFrame, Chunk): + """ + Visual video chunk widget + + This widget represents a video chunk and provides controls for + defining the chunk. + + Properties are: + schedule (string) - commands to the owning object, values can be + mv left : move this chunk left + mv right: move this chunk right + copy : double this chunk + apply : realize new video properties + delete : remove this chunk + + subgets - dictionary of widgets forming this + complex widget + played (Tk.Boolean) - indicates status of the play checkbox (use ...play.get()) + marked (Tk.Boolean) - indicates status of the mark checkbox (use ...mark.get()) + """ + + def __init__(self, master = None, file = '', start = None, frames = None, play = True): + """ + Constructor + + chunk - a Chunk object to represent + master - the holding widget + """ + self.subgets = {} + self.schedule = '' + self.animate = play + self.played = BooleanVar(value = True) + self.marked = BooleanVar(value = True) + + tooltips = Pmw.Balloon() + + Chunk.__init__(self, file, start, frames) + LabelFrame.__init__(self, master = master, text = + file.split('/')[-1] + ':' + str(start) + ':' + str(frames) + ) + self.subgets['video'] = Frame(self, height=90, width=120, bg = '#000000') + self.subgets['video'].grid(column=0, row=0, rowspan=4, sticky=W) + + self.subgets['sb_m_start'] = Spinbox(self, from_ = 0, increment = 1, width = 3, + to = int(float(self.videoprops['ID_LENGTH']) / 60)) + self.subgets['sb_m_start'].delete(0, END) + self.subgets['sb_m_start'].insert(0, int(self.start / 60)) + self.subgets['sb_m_start'].grid(column=2, row=1, rowspan=1) + + self.subgets['sb_s_start'] = Spinbox(self, from_ = 0, increment = 1, width = 2, to = 60) + self.subgets['sb_s_start'].delete(0, END) + self.subgets['sb_s_start'].insert(0, int(self.start) % 60) + self.subgets['sb_s_start'].grid(column=3, row=1, rowspan=1) + + self.subgets['sb_f_start'] = Spinbox(self, from_ = 0, increment = 1, width = 2, + to = int(float(self.videoprops['ID_VIDEO_FPS']))) + self.subgets['sb_f_start'].delete(0, END) + self.subgets['sb_f_start'].insert(0, int(self.start * + float(self.videoprops['ID_VIDEO_FPS']) + ) % int(float(self.videoprops['ID_VIDEO_FPS']))) + self.subgets['sb_f_start'].grid(column=4, row=1, rowspan=1) + + tooltips.bind(self.subgets['sb_m_start'], + 'Define the staring minute of the video chunk in the source video file.') + tooltips.bind(self.subgets['sb_s_start'], + 'Define the starting second of the video chunk in the source video file.') + tooltips.bind(self.subgets['sb_f_start'], + 'Define the starting frame of the video chunk in the source video file.') + + frames = int(self.start * float(self.videoprops['ID_VIDEO_FPS'])) + self.frames + self.subgets['sb_m_stop'] = Spinbox(self, from_ = 0, increment = 1, width = 3, + to = int(float(self.videoprops['ID_LENGTH']) / 60)) + self.subgets['sb_m_stop'].delete(0, END) + self.subgets['sb_m_stop'].insert(0, int(frames / float(self.videoprops['ID_VIDEO_FPS']) + / 60)) + self.subgets['sb_m_stop'].grid(column=2, row=2, rowspan=1) + + self.subgets['sb_s_stop'] = Spinbox(self, from_ = 0, increment = 1, width = 2, to = 60) + self.subgets['sb_s_stop'].delete(0, END) + self.subgets['sb_s_stop'].insert(0, int(frames / float(self.videoprops['ID_VIDEO_FPS']) + ) % 60) + self.subgets['sb_s_stop'].grid(column=3, row=2, rowspan=1) + + self.subgets['sb_f_stop'] = Spinbox(self, from_ = 0, increment = 1, width = 2, + to = int(float(self.videoprops['ID_VIDEO_FPS']))) + self.subgets['sb_f_stop'].delete(0, END) + self.subgets['sb_f_stop'].insert(0, frames % int(float(self.videoprops['ID_VIDEO_FPS']))) + self.subgets['sb_f_stop'].grid(column=4, row=2, rowspan=1) + + tooltips.bind(self.subgets['sb_m_stop'], + 'Define the stop minute of the video chunk in the source video file.') + tooltips.bind(self.subgets['sb_s_stop'], + 'Define the stop second of the video chunk in the source video file.') + tooltips.bind(self.subgets['sb_f_stop'], + 'Define the stop frame of the video chunk in the source video file.') + + self.subgets['b_apply'] = Button(self, text = 'Set', command=self.chprops) + self.subgets['b_apply'].grid(column=5, row=1, rowspan = 2, sticky=W) + tooltips.bind(self.subgets['b_apply'], + 'Apply changes of start and end time.') + + self.subgets['b_mvbw'] = Button(self, text = '<-', command=self.mvbw) + self.subgets['b_mvbw'].grid(column = 1, row = 3, rowspan = 1, columnspan = 2, sticky=E) + tooltips.bind(self.subgets['b_mvbw'], + 'Swap this chunk with its left neighbour (move it left).') + + self.subgets['b_copy'] = Button(self, text = 'Copy', command=self.copy) + self.subgets['b_copy'].grid(column = 3, columnspan = 2, row = 3, rowspan = 1) + tooltips.bind(self.subgets['b_copy'], + 'Create another chunk with the same properties as this one.') + + self.subgets['b_mvfw'] = Button(self, text = '->', command=self.mvfw) + self.subgets['b_mvfw'].grid(column = 5, row = 3, rowspan = 1, sticky=W) + tooltips.bind(self.subgets['b_mvfw'], + 'Swap this chunk with its right neighbour (move it right).') + + self.subgets['c_play'] = Checkbutton(self, text='Play', offvalue=False, + onvalue=True, variable = self.played) +# self.subgets['c_play'].select() + self.subgets['c_play'].grid(column=1, columnspan = 2, row=0) + tooltips.bind(self.subgets['c_play'], + 'Mark this chunk for playback in main window.') + + self.subgets['c_mark'] = Checkbutton(self, text='Mark', offvalue=False, + onvalue=True, variable = self.marked) +# self.subgets['c_mark'].select() + self.subgets['c_mark'].grid(column=3, columnspan = 2, row=0) + tooltips.bind(self.subgets['c_mark'], + 'Mark this chunk for application of choosen filters and effects.') + + self.subgets['b_del'] = Button(self, text='Del', command = self.delete) + self.subgets['b_del'].grid(column=5, row=0, sticky=NE) + tooltips.bind(self.subgets['b_del'], + 'Remove this chunk from the project.') + self.chprops() + + def load_filters(self, dbcur, num): + """ + Load filter list from database + + db - sqlite database cursor + num - database primary key id of this chunk + """ + + dbcur.execute('SELECT iorder FROM filters ' + + 'WHERE chunk = ' + str(num) + ' ORDER BY iorder') + for filter in dbcur.fetchall(): + dbcur.execute('SELECT line FROM filter_lines WHERE filter = ' + + str(filter[0]) + ' ORDER BY iorder') + line = [] + for item in dbcur.fetchall(): + line.append(item[0]) + self.add_filter(line) + + def delete(self): + """ + Scheduler for internal use + """ + self.schedule = 'delete' + + def mvbw(self): + """ + Scheduler for internal use + """ + self.schedule = 'mv left' + + def mvfw(self): + """ + Scheduler for internal use + """ + self.schedule = 'mv right' + + def copy(self): + """ + Scheduler for internal use + """ + self.schedule = 'copy' + + def store(self, dbcur): + """ + Store chunk to database + + The tables "chunks", "filters" and "filter_lines" + must be prepared in database. + + dbcur - sqlite database cursor + """ + if self.played.get(): played = '1' + else: played = '0' + if self.marked.get(): marked = '1' + else: marked = '0' + dbcur.execute('INSERT INTO chunks (filename, start, frames, played, marked) ' + + 'VALUES ("' + self.videofile + '", ' + str(self.start) + ', ' + + str(self.frames) + ', ' + played + ', ' + marked + ');') + + dbcur.execute('SELECT last_insert_rowid();') + chunk_id = str(dbcur.fetchone()[0]) + + for filter in self.filters: + dbcur.execute('INSERT INTO filters (chunk) VALUES (' + chunk_id + ');') + dbcur.execute('SELECT last_insert_rowid();') + filter_id = str(dbcur.fetchone()[0]) + for line in filter: + dbcur.execute('INSERT INTO filter_lines (line, filter) ' + + 'VALUES ("' + line + '", ' + filter_id + ')') + + def chprops(self): + """ + Changes 'start' and 'frames' property of chunk. + + This method is called when the Apply (Set) button is pressed. + The methos also schedules the apply event + """ + try: + start = (int(self.subgets['sb_m_start'].get()) * 60 + + int(self.subgets['sb_s_start'].get()) + + int(self.subgets['sb_f_start'].get()) / float(self.videoprops['ID_VIDEO_FPS']) + ) + frames = int((int(self.subgets['sb_m_stop'].get()) * 60 + + int(self.subgets['sb_s_stop'].get())) * + float(self.videoprops['ID_VIDEO_FPS']) + + int(self.subgets['sb_f_stop'].get()) - + (start * float(self.videoprops['ID_VIDEO_FPS'])) + ) + self.stop() + self.option(start=start, frames=frames) + if self.animate: self.play() + self.config(text = self.videofile.split('/')[-1] + ':' + str(start) + ':' + str(frames)) + except: + print 'could not parse props' + self.schedule = 'apply' + + def play(self): + Flic.play(self, self.subgets['video'].winfo_id(), width=120, height=90) diff --git a/videoview.py b/videoview.py new file mode 100644 index 0000000..886d2f4 --- /dev/null +++ b/videoview.py @@ -0,0 +1,147 @@ +#encoding: utf-8 +#Copyright 2009 - 2010 Paul Hänsch + +#This file is part of Viper. + +#Viper is free software: you can redistribute it and/or modify +#it under the terms of the GNU General Public License as published by +#the Free Software Foundation, either version 3 of the License, or +#(at your option) any later version. + +#Viper is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU General Public License for more details. + +#You should have received a copy of the GNU General Public License +#along with Viper. If not, see + +from Tkinter import * +from player import * +from PlayerControl import * +import Pmw +import os +import threading + +class VideoView(Frame): + """ + Widget for video main view + """ + def __init__(self, parent): + Frame.__init__(self, parent) + self.ext_fullscreen = BooleanVar(value = False) + self.ext_loop = BooleanVar(value = True) + self.prev_loop = BooleanVar(value = False) + self.loop = BooleanVar(False) + self.attached_view = True + + self.params = [] + self.subgets = {} + tooltip = Pmw.Balloon() + + self.subgets['tablist'] = Pmw.NoteBook(self) + self.subgets['extopts'] = self.subgets['tablist'].add('External View') + self.subgets['f_extparam'] = Frame(self.subgets['extopts']) + self.subgets['f_extparam'].pack(side = TOP) + self.subgets['e_display'] = Entry(self.subgets['f_extparam']) + self.subgets['e_display'].pack(side = LEFT, anchor = N, fill = X, + expand = True, padx = 10) + self.subgets['b_extdisplay'] = Button(self.subgets['f_extparam'], + text = 'Set Display', + command = self.b_ext_display) + self.subgets['b_extdisplay'].pack(side = LEFT, anchor = N, expand = True) + self.subgets['c_extfullscreen'] = Checkbutton(self.subgets['extopts'], + text = 'Fullscreen', + command = self.c_ext_fullscreen, + variable = self.ext_fullscreen) + self.subgets['c_extfullscreen'].pack(side = TOP) + + self.subgets['ext_surf'] = Frame(self, width = 320, height = 240, bg="#000000") + self.subgets['ext_player'] = Player(self, surface = self.subgets['ext_surf']) + self.subgets['ext_ctl'] = PlayerControl(self.subgets['extopts'], + self.subgets['ext_player'], + [('Attach', self.attach_view, + 'Reattach external player window')]) + self.subgets['ext_ctl'].pack(side = BOTTOM, anchor = W, fill = X) + + self.subgets['preview'] = self.subgets['tablist'].add('Preview') + self.subgets['prev_surf'] = Frame(self, width = 160, height = 120, bg="#000000") + self.subgets['prev_surf'].pack(side = TOP, anchor = W, fill = BOTH, + expand = True) + self.subgets['prev_player'] = Player(self, surface = self.subgets['prev_surf']) + self.subgets['prev_ctl'] = PlayerControl(self.subgets['preview'], + self.subgets['prev_player'], + [('To Main View', self.prev_apply, + 'Play this on external view')]) + self.subgets['prev_ctl'].pack(side = BOTTOM, anchor = W, fill = X) + self.subgets['main_ctl'] = PlayerControl(self, self.subgets['prev_player'], + [('Detach', self.detach_view, + 'Detach external player window')]) + self.subgets['main_ctl'].pack(side = BOTTOM, anchor = W, fill = X) + + def set_playback_params(self, params): + self.subgets['ext_ctl'].params = params + self.subgets['prev_ctl'].params = params + self.subgets['main_ctl'].params = params + + def prev_apply(self): + self.subgets['ext_player'].stop_video() + self.after(100, self.subgets['ext_ctl'].play) + + def c_ext_fullscreen(self): + if self.ext_fullscreen.get(): + #self.subgets['view'].overrideredirect(1) + self.subgets['ext_view'].geometry( + str(self.subgets['ext_view'].winfo_screenwidth()) + 'x' + + str(self.subgets['ext_view'].winfo_screenheight()) + '+0+0') + else: self.subgets['ext_view'].geometry('320x240') + + def stop_video(self): + self.subgets['ext_player'].stop_video() + self.subgets['prev_player'].stop_video() + + def b_ext_display(self): + try: + Tk(screenName=self.subgets['e_display'].get()).destroy() + print self.subgets['e_display'].get() + self.subgets['ext_view'].destroy() + self.subgets['ext_view'] = Tk(screenName=self.subgets['e_display'].get()) + self.subgets['ext_view'].config(width = 320, height = 240, bg = '#000000') + self.subgets['ext_view'].protocol('WM_DELETE_WINDOW', self.attach_view) + self.subgets['e_display'].configure(bg='#44FF44') + except: + self.subgets['e_display'].configure(bg='#FF4444') + + def detach_view(self): + self.subgets['main_ctl'].forget() + self.subgets['prev_surf'].forget() + + self.subgets['ext_view'] = Tk() + self.subgets['ext_view'].title('Viper Display') + self.subgets['ext_view'].config(width = 320, height = 240, bg = '#000000') + self.subgets['ext_view'].protocol('WM_DELETE_WINDOW', self.attach_view) + self.subgets['ext_player'].configure(surface = self.subgets['ext_view']) + + self.subgets['prev_surf'].pack(in_ = self.subgets['preview'], + before = self.subgets['prev_ctl'], + side = TOP, anchor = W, fill = BOTH, + expand = True) + self.subgets['prev_ctl'].configure(self.subgets['prev_player']) + + self.subgets['tablist'].pack(in_= self, side=TOP,anchor=W, + fill=BOTH, expand=True) + self.attached_view = False + + def attach_view(self): + self.subgets['ext_player'].stop_video() + self.subgets['prev_player'].stop_video() + self.subgets['ext_view'].destroy() + self.subgets['tablist'].forget() + self.subgets['main_ctl'].forget() + self.subgets['prev_surf'].forget() + + self.subgets['prev_surf'].pack(in_ = self, side = TOP, anchor = W, + fill = BOTH, expand = True) + self.subgets['main_ctl'].pack(side = BOTTOM, anchor = W, fill = X) + self.subgets['main_ctl'].configure(self.subgets['prev_player']) + self.attached_view = True