parent
3ebe1ee8ec
commit
d1b916a7ab
@ -1 +1,4 @@ |
||||
/.tmp/ |
||||
/*.log |
||||
/prebuilt/ |
||||
.DS_Store |
||||
|
||||
@ -0,0 +1,674 @@ |
||||
GNU GENERAL PUBLIC LICENSE |
||||
Version 3, 29 June 2007 |
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> |
||||
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 |
||||
|
||||
How to Apply These Terms to Your New Programs |
||||
|
||||
If you develop a new program, and you want it to be of the greatest |
||||
possible use to the public, the best way to achieve this is to make it |
||||
free software which everyone can redistribute and change under these terms. |
||||
|
||||
To do so, attach the following notices to the program. It is safest |
||||
to attach them to the start of each source file to most effectively |
||||
state the exclusion of warranty; and each file should have at least |
||||
the "copyright" line and a pointer to where the full notice is found. |
||||
|
||||
<one line to give the program's name and a brief idea of what it does.> |
||||
Copyright (C) <year> <name of author> |
||||
|
||||
This program 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. |
||||
|
||||
This program 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 this program. If not, see <http://www.gnu.org/licenses/>. |
||||
|
||||
Also add information on how to contact you by electronic and paper mail. |
||||
|
||||
If the program does terminal interaction, make it output a short |
||||
notice like this when it starts in an interactive mode: |
||||
|
||||
<program> Copyright (C) <year> <name of author> |
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. |
||||
This is free software, and you are welcome to redistribute it |
||||
under certain conditions; type `show c' for details. |
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate |
||||
parts of the General Public License. Of course, your program's commands |
||||
might be different; for a GUI interface, you would use an "about box". |
||||
|
||||
You should also get your employer (if you work as a programmer) or school, |
||||
if any, to sign a "copyright disclaimer" for the program, if necessary. |
||||
For more information on this, and how to apply and follow the GNU GPL, see |
||||
<http://www.gnu.org/licenses/>. |
||||
|
||||
The GNU General Public License does not permit incorporating your program |
||||
into proprietary programs. If your program is a subroutine library, you |
||||
may consider it more useful to permit linking proprietary applications with |
||||
the library. If this is what you want to do, use the GNU Lesser General |
||||
Public License instead of this License. But first, please read |
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>. |
||||
@ -0,0 +1,165 @@ |
||||
GNU LESSER GENERAL PUBLIC LICENSE |
||||
Version 3, 29 June 2007 |
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> |
||||
Everyone is permitted to copy and distribute verbatim copies |
||||
of this license document, but changing it is not allowed. |
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates |
||||
the terms and conditions of version 3 of the GNU General Public |
||||
License, supplemented by the additional permissions listed below. |
||||
|
||||
0. Additional Definitions. |
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser |
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU |
||||
General Public License. |
||||
|
||||
"The Library" refers to a covered work governed by this License, |
||||
other than an Application or a Combined Work as defined below. |
||||
|
||||
An "Application" is any work that makes use of an interface provided |
||||
by the Library, but which is not otherwise based on the Library. |
||||
Defining a subclass of a class defined by the Library is deemed a mode |
||||
of using an interface provided by the Library. |
||||
|
||||
A "Combined Work" is a work produced by combining or linking an |
||||
Application with the Library. The particular version of the Library |
||||
with which the Combined Work was made is also called the "Linked |
||||
Version". |
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the |
||||
Corresponding Source for the Combined Work, excluding any source code |
||||
for portions of the Combined Work that, considered in isolation, are |
||||
based on the Application, and not on the Linked Version. |
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the |
||||
object code and/or source code for the Application, including any data |
||||
and utility programs needed for reproducing the Combined Work from the |
||||
Application, but excluding the System Libraries of the Combined Work. |
||||
|
||||
1. Exception to Section 3 of the GNU GPL. |
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License |
||||
without being bound by section 3 of the GNU GPL. |
||||
|
||||
2. Conveying Modified Versions. |
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a |
||||
facility refers to a function or data to be supplied by an Application |
||||
that uses the facility (other than as an argument passed when the |
||||
facility is invoked), then you may convey a copy of the modified |
||||
version: |
||||
|
||||
a) under this License, provided that you make a good faith effort to |
||||
ensure that, in the event an Application does not supply the |
||||
function or data, the facility still operates, and performs |
||||
whatever part of its purpose remains meaningful, or |
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of |
||||
this License applicable to that copy. |
||||
|
||||
3. Object Code Incorporating Material from Library Header Files. |
||||
|
||||
The object code form of an Application may incorporate material from |
||||
a header file that is part of the Library. You may convey such object |
||||
code under terms of your choice, provided that, if the incorporated |
||||
material is not limited to numerical parameters, data structure |
||||
layouts and accessors, or small macros, inline functions and templates |
||||
(ten or fewer lines in length), you do both of the following: |
||||
|
||||
a) Give prominent notice with each copy of the object code that the |
||||
Library is used in it and that the Library and its use are |
||||
covered by this License. |
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license |
||||
document. |
||||
|
||||
4. Combined Works. |
||||
|
||||
You may convey a Combined Work under terms of your choice that, |
||||
taken together, effectively do not restrict modification of the |
||||
portions of the Library contained in the Combined Work and reverse |
||||
engineering for debugging such modifications, if you also do each of |
||||
the following: |
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that |
||||
the Library is used in it and that the Library and its use are |
||||
covered by this License. |
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license |
||||
document. |
||||
|
||||
c) For a Combined Work that displays copyright notices during |
||||
execution, include the copyright notice for the Library among |
||||
these notices, as well as a reference directing the user to the |
||||
copies of the GNU GPL and this license document. |
||||
|
||||
d) Do one of the following: |
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this |
||||
License, and the Corresponding Application Code in a form |
||||
suitable for, and under terms that permit, the user to |
||||
recombine or relink the Application with a modified version of |
||||
the Linked Version to produce a modified Combined Work, in the |
||||
manner specified by section 6 of the GNU GPL for conveying |
||||
Corresponding Source. |
||||
|
||||
1) Use a suitable shared library mechanism for linking with the |
||||
Library. A suitable mechanism is one that (a) uses at run time |
||||
a copy of the Library already present on the user's computer |
||||
system, and (b) will operate properly with a modified version |
||||
of the Library that is interface-compatible with the Linked |
||||
Version. |
||||
|
||||
e) Provide Installation Information, but only if you would otherwise |
||||
be required to provide such information under section 6 of the |
||||
GNU GPL, and only to the extent that such information is |
||||
necessary to install and execute a modified version of the |
||||
Combined Work produced by recombining or relinking the |
||||
Application with a modified version of the Linked Version. (If |
||||
you use option 4d0, the Installation Information must accompany |
||||
the Minimal Corresponding Source and Corresponding Application |
||||
Code. If you use option 4d1, you must provide the Installation |
||||
Information in the manner specified by section 6 of the GNU GPL |
||||
for conveying Corresponding Source.) |
||||
|
||||
5. Combined Libraries. |
||||
|
||||
You may place library facilities that are a work based on the |
||||
Library side by side in a single library together with other library |
||||
facilities that are not Applications and are not covered by this |
||||
License, and convey such a combined library under terms of your |
||||
choice, if you do both of the following: |
||||
|
||||
a) Accompany the combined library with a copy of the same work based |
||||
on the Library, uncombined with any other library facilities, |
||||
conveyed under the terms of this License. |
||||
|
||||
b) Give prominent notice with the combined library that part of it |
||||
is a work based on the Library, and explaining where to find the |
||||
accompanying uncombined form of the same work. |
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License. |
||||
|
||||
The Free Software Foundation may publish revised and/or new versions |
||||
of the GNU Lesser 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 |
||||
Library as you received it specifies that a certain numbered version |
||||
of the GNU Lesser General Public License "or any later version" |
||||
applies to it, you have the option of following the terms and |
||||
conditions either of that published version or of any later version |
||||
published by the Free Software Foundation. If the Library as you |
||||
received it does not specify a version number of the GNU Lesser |
||||
General Public License, you may choose any version of the GNU Lesser |
||||
General Public License ever published by the Free Software Foundation. |
||||
|
||||
If the Library as you received it specifies that a proxy can decide |
||||
whether future versions of the GNU Lesser General Public License shall |
||||
apply, that proxy's public statement of acceptance of any version is |
||||
permanent authorization for you to choose that version for the |
||||
Library. |
||||
@ -0,0 +1,586 @@ |
||||
# FFmpegKit    [](https://travis-ci.org/tanersener/ffmpeg-kit) |
||||
|
||||
FFmpeg kit for applications. Supports Android, iOS, tvOS. |
||||
|
||||
<img src="https://github.com/tanersener/ffmpeg-kit/blob/development/docs/assets/ffmpeg-kit-icon-v4.png" width="240"> |
||||
|
||||
### 1. Features |
||||
- Includes both `FFmpeg` and `FFprobe` |
||||
- Use binaries available at `Github`/`JCenter`/`CocoaPods` or build your own version with external libraries you need |
||||
- Supports |
||||
- Android, iOS and tvOS |
||||
- FFmpeg `v4.4-dev` releases |
||||
- 29 external libraries |
||||
|
||||
`chromaprint`, `fontconfig`, `freetype`, `fribidi`, `gmp`, `gnutls`, `kvazaar`, `lame`, `libaom`, `libass`, `libiconv`, `libilbc`, `libtheora`, `libvorbis`, `libvpx`, `libwebp`, `libxml2`, `opencore-amr`, `openh264`, `opus`, `sdl`, `shine`, `snappy`, `soxr`, `speex`, `tesseract`, `twolame`, `vo-amrwbenc`, `wavpack` |
||||
|
||||
- 5 external libraries with GPL license |
||||
|
||||
`rubberband`, `vid.stab`, `x264`, `x265`, `xvidcore` |
||||
|
||||
- Concurrent execution |
||||
|
||||
- Exposes both FFmpeg library and FFmpegKit wrapper library capabilities |
||||
- Includes cross-compile instructions for 47 open-source libraries |
||||
|
||||
`chromaprint`, `expat`, `ffmpeg`, `fontconfig`, `freetype`, `fribidi`, `giflib`, `gmp`, `gnutls`, `kvazaar`, `lame`, `leptonica`, `libaom`, `libass`, `libiconv`, `libilbc`, `libjpeg`, `libjpeg-turbo`, `libogg`, `libpng`, `libsamplerate`, `libsndfile`, `libtheora`, `libuuid`, `libvorbis`, `libvpx`, `libwebp`, `libxml2`, `nettle`, `opencore-amr`, `openh264`, `opus`, `rubberband`, `sdl`, `shine`, `snappy`, `soxr`, `speex`, `tesseract`, `tiff`, `twolame`, `vid.stab`, `vo-amrwbenc`, `wavpack`, `x264`, `x265`, `xvidcore` |
||||
|
||||
- Licensed under LGPL 3.0, can be customized to support GPL v3.0 |
||||
|
||||
#### 1.1 Android |
||||
- Builds `arm-v7a`, `arm-v7a-neon`, `arm64-v8a`, `x86` and `x86_64` architectures |
||||
- Supports `zlib` and `MediaCodec` system libraries |
||||
- Camera access on [supported devices](https://developer.android.com/ndk/guides/stable_apis#camera) |
||||
- Builds shared native libraries (.so) |
||||
- Creates Android archives with .aar extension |
||||
- Supports `API Level 16+` |
||||
|
||||
#### 1.2 iOS |
||||
- Builds `armv7`, `armv7s`, `arm64`, `arm64e`, `i386`, `x86_64` and `x86_64` (Mac Catalyst) architectures |
||||
- Supports `bzip2`, `iconv`, `libuuid`, `zlib` system libraries and `AudioToolbox`, `VideoToolbox`, `AVFoundation` system frameworks |
||||
- Objective-C API |
||||
- Camera access |
||||
- `ARC` enabled library |
||||
- Built with `-fembed-bitcode` flag |
||||
- Creates static frameworks, static xcframeworks and static universal (fat) libraries (.a) |
||||
- Supports `iOS SDK 9.3` or later |
||||
|
||||
#### 1.3 tvOS |
||||
- Builds `arm64` and `x86_64` architectures |
||||
- Supports `bzip2`, `iconv`, `libuuid`, `zlib` system libraries and `AudioToolbox`, `VideoToolbox` system frameworks |
||||
- Objective-C API |
||||
- `ARC` enabled library |
||||
- Built with `-fembed-bitcode` flag |
||||
- Creates static frameworks and static universal (fat) libraries (.a) |
||||
- Supports `tvOS SDK 9.2` or later |
||||
|
||||
### 2. Using |
||||
|
||||
Prebuilt binaries are available at [Github](https://github.com/tanersener/ffmpeg-kit/releases), [JCenter](https://bintray.com/bintray/jcenter) and [CocoaPods](https://cocoapods.org). |
||||
|
||||
#### 2.1 Packages |
||||
|
||||
There are eight different `ffmpeg-kit` packages. Below you can see which system libraries and external libraries are enabled in each of package. |
||||
|
||||
Please remember that some parts of `FFmpeg` are licensed under the `GPL` and only `GPL` licensed `ffmpeg-kit` packages include them. |
||||
|
||||
<table> |
||||
<thead> |
||||
<tr> |
||||
<th align="center"></th> |
||||
<th align="center"><sup>min</sup></th> |
||||
<th align="center"><sup>min-gpl</sup></th> |
||||
<th align="center"><sup>https</sup></th> |
||||
<th align="center"><sup>https-gpl</sup></th> |
||||
<th align="center"><sup>audio</sup></th> |
||||
<th align="center"><sup>video</sup></th> |
||||
<th align="center"><sup>full</sup></th> |
||||
<th align="center"><sup>full-gpl</sup></th> |
||||
</tr> |
||||
</thead> |
||||
<tbody> |
||||
<tr> |
||||
<td align="center"><sup>external libraries</sup></td> |
||||
<td align="center">-</td> |
||||
<td align="center"><sup>vid.stab</sup><br><sup>x264</sup><br><sup>x265</sup><br><sup>xvidcore</sup></td> |
||||
<td align="center"><sup>gmp</sup><br><sup>gnutls</sup></td> |
||||
<td align="center"><sup>gmp</sup><br><sup>gnutls</sup><br><sup>vid.stab</sup><br><sup>x264</sup><br><sup>x265</sup><br><sup>xvidcore</sup></td> |
||||
<td align="center"><sup>lame</sup><br><sup>libilbc</sup><br><sup>libvorbis</sup><br><sup>opencore-amr</sup><br><sup>opus</sup><br><sup>shine</sup><br><sup>soxr</sup><br><sup>speex</sup><br><sup>twolame</sup><br><sup>vo-amrwbenc</sup><br><sup>wavpack</sup></td> |
||||
<td align="center"><sup>fontconfig</sup><br><sup>freetype</sup><br><sup>fribidi</sup><br><sup>kvazaar</sup><br><sup>libaom</sup><br><sup>libass</sup><br><sup>libiconv</sup><br><sup>libtheora</sup><br><sup>libvpx</sup><br><sup>libwebp</sup><br><sup>snappy</sup></td> |
||||
<td align="center"><sup>fontconfig</sup><br><sup>freetype</sup><br><sup>fribidi</sup><br><sup>gmp</sup><br><sup>gnutls</sup><br><sup>kvazaar</sup><br><sup>lame</sup><br><sup>libaom</sup><br><sup>libass</sup><br><sup>libiconv</sup><br><sup>libilbc</sup><br><sup>libtheora</sup><br><sup>libvorbis</sup><br><sup>libvpx</sup><br><sup>libwebp</sup><br><sup>libxml2</sup><br><sup>opencore-amr</sup><br><sup>opus</sup><br><sup>shine</sup><br><sup>snappy</sup><br><sup>soxr</sup><br><sup>speex</sup><br><sup>twolame</sup><br><sup>vo-amrwbenc</sup><br><sup>wavpack</sup></td> |
||||
<td align="center"><sup>fontconfig</sup><br><sup>freetype</sup><br><sup>fribidi</sup><br><sup>gmp</sup><br><sup>gnutls</sup><br><sup>kvazaar</sup><br><sup>lame</sup><br><sup>libaom</sup><br><sup>libass</sup><br><sup>libiconv</sup><br><sup>libilbc</sup><br><sup>libtheora</sup><br><sup>libvorbis</sup><br><sup>libvpx</sup><br><sup>libwebp</sup><br><sup>libxml2</sup><br><sup>opencore-amr</sup><br><sup>opus</sup><br><sup>shine</sup><br><sup>snappy</sup><br><sup>soxr</sup><br><sup>speex</sup><br><sup>twolame</sup><br><sup>vid.stab</sup><br><sup>vo-amrwbenc</sup><br><sup>wavpack</sup><br><sup>x264</sup><br><sup>x265</sup><br><sup>xvidcore</sup></td> |
||||
</tr> |
||||
<tr> |
||||
<td align="center"><sup>android system libraries</sup></td> |
||||
<td align="center" colspan=8><sup>zlib</sup><br><sup>MediaCodec</sup></td> |
||||
</tr> |
||||
<tr> |
||||
<td align="center"><sup>ios system libraries</sup></td> |
||||
<td align="center" colspan=8><sup>zlib</sup><br><sup>AudioToolbox</sup><br><sup>AVFoundation</sup><br><sup>iconv</sup><br><sup>VideoToolbox</sup><br><sup>bzip2</sup></td> |
||||
</tr> |
||||
<tr> |
||||
<td align="center"><sup>tvos system libraries</sup></td> |
||||
<td align="center" colspan=8><sup>zlib</sup><br><sup>AudioToolbox</sup><br><sup>iconv</sup><br><sup>VideoToolbox</sup><br><sup>bzip2</sup></td> |
||||
</tr> |
||||
</tbody> |
||||
</table> |
||||
|
||||
- `AVFoundation` is not available on `tvOS`, `VideoToolbox` is not available on `tvOS` LTS releases |
||||
|
||||
#### 2.2 Android |
||||
1. Add FFmpegKit dependency to your `build.gradle` in `ffmpeg-kit-<package name>` pattern. |
||||
``` |
||||
dependencies { |
||||
implementation 'com.arthenica:ffmpeg-kit-full:4.4' |
||||
} |
||||
``` |
||||
|
||||
2. Execute synchronous FFmpeg commands. |
||||
``` |
||||
import com.arthenica.ffmpegkit.Config; |
||||
import com.arthenica.ffmpegkit.FFmpeg; |
||||
|
||||
int rc = FFmpeg.execute("-i file1.mp4 -c:v mpeg4 file2.mp4"); |
||||
|
||||
if (rc == RETURN_CODE_SUCCESS) { |
||||
Log.i(Config.TAG, "Command execution completed successfully."); |
||||
} else if (rc == RETURN_CODE_CANCEL) { |
||||
Log.i(Config.TAG, "Command execution cancelled by user."); |
||||
} else { |
||||
Log.i(Config.TAG, String.format("Command execution failed with rc=%d and the output below.", rc)); |
||||
Config.printLastCommandOutput(Log.INFO); |
||||
} |
||||
``` |
||||
|
||||
3. Execute asynchronous FFmpeg commands. |
||||
``` |
||||
import com.arthenica.ffmpegkit.Config; |
||||
import com.arthenica.ffmpegkit.FFmpeg; |
||||
|
||||
long executionId = FFmpeg.executeAsync("-i file1.mp4 -c:v mpeg4 file2.mp4", new ExecuteCallback() { |
||||
|
||||
@Override |
||||
public void apply(final long executionId, final int returnCode) { |
||||
if (rc == RETURN_CODE_SUCCESS) { |
||||
Log.i(Config.TAG, "Async command execution completed successfully."); |
||||
} else if (rc == RETURN_CODE_CANCEL) { |
||||
Log.i(Config.TAG, "Async command execution cancelled by user."); |
||||
} else { |
||||
Log.i(Config.TAG, String.format("Async command execution failed with rc=%d.", rc)); |
||||
} |
||||
} |
||||
}); |
||||
``` |
||||
|
||||
4. Execute FFprobe commands. |
||||
``` |
||||
import com.arthenica.ffmpegkit.Config; |
||||
import com.arthenica.ffmpegkit.FFprobe; |
||||
|
||||
int rc = FFprobe.execute("-i file1.mp4"); |
||||
|
||||
if (rc == RETURN_CODE_SUCCESS) { |
||||
Log.i(Config.TAG, "Command execution completed successfully."); |
||||
} else { |
||||
Log.i(Config.TAG, String.format("Command execution failed with rc=%d and the output below.", rc)); |
||||
Config.printLastCommandOutput(Log.INFO); |
||||
} |
||||
``` |
||||
|
||||
5. Check execution output later. |
||||
``` |
||||
int rc = Config.getLastReturnCode(); |
||||
|
||||
if (rc == RETURN_CODE_SUCCESS) { |
||||
Log.i(Config.TAG, "Command execution completed successfully."); |
||||
} else if (rc == RETURN_CODE_CANCEL) { |
||||
Log.i(Config.TAG, "Command execution cancelled by user."); |
||||
} else { |
||||
Log.i(Config.TAG, String.format("Command execution failed with rc=%d and the output below.", rc)); |
||||
Config.printLastCommandOutput(Log.INFO); |
||||
} |
||||
``` |
||||
|
||||
6. Stop ongoing FFmpeg operations. |
||||
- Stop all executions |
||||
``` |
||||
FFmpeg.cancel(); |
||||
``` |
||||
- Stop a specific execution |
||||
``` |
||||
FFmpeg.cancel(executionId); |
||||
``` |
||||
|
||||
7. Get media information for a file. |
||||
``` |
||||
MediaInformation info = FFprobe.getMediaInformation("<file path or uri>"); |
||||
``` |
||||
|
||||
8. Record video using Android camera. |
||||
``` |
||||
FFmpeg.execute("-f android_camera -i 0:0 -r 30 -pixel_format bgr0 -t 00:00:05 <record file path>"); |
||||
``` |
||||
|
||||
9. Enable log callback. |
||||
``` |
||||
Config.enableLogCallback(new LogCallback() { |
||||
public void apply(LogMessage message) { |
||||
Log.d(Config.TAG, message.getText()); |
||||
} |
||||
}); |
||||
``` |
||||
|
||||
10. Enable statistics callback. |
||||
``` |
||||
Config.enableStatisticsCallback(new StatisticsCallback() { |
||||
public void apply(Statistics newStatistics) { |
||||
Log.d(Config.TAG, String.format("frame: %d, time: %d", newStatistics.getVideoFrameNumber(), newStatistics.getTime())); |
||||
} |
||||
}); |
||||
``` |
||||
11. Ignore the handling of a signal. |
||||
``` |
||||
Config.ignoreSignal(Signal.SIGXCPU); |
||||
``` |
||||
|
||||
12. List ongoing executions. |
||||
``` |
||||
final List<FFmpegExecution> ffmpegExecutions = FFmpeg.listExecutions(); |
||||
for (int i = 0; i < ffmpegExecutions.size(); i++) { |
||||
FFmpegExecution execution = ffmpegExecutions.get(i); |
||||
Log.d(TAG, String.format("Execution %d = id:%d, startTime:%s, command:%s.", i, execution.getExecutionId(), execution.getStartTime(), execution.getCommand())); |
||||
} |
||||
``` |
||||
|
||||
13. Set default log level. |
||||
``` |
||||
Config.setLogLevel(Level.AV_LOG_FATAL); |
||||
``` |
||||
|
||||
14. Register custom fonts directory. |
||||
``` |
||||
Config.setFontDirectory(this, "<folder with fonts>", Collections.EMPTY_MAP); |
||||
``` |
||||
|
||||
#### 2.3 iOS / tvOS |
||||
1. Add FFmpegKit dependency to your `Podfile` in `ffmpeg-kit-<package name>` pattern. |
||||
|
||||
- iOS |
||||
``` |
||||
pod 'ffmpeg-kit-full', '~> 4.4' |
||||
``` |
||||
|
||||
- tvOS |
||||
``` |
||||
pod 'ffmpeg-kit-tvos-full', '~> 4.4' |
||||
``` |
||||
|
||||
2. Execute synchronous FFmpeg commands. |
||||
``` |
||||
#import <ffmpegkit/FFmpegKitConfig.h> |
||||
#import <ffmpegkit/FFmpegKit.h> |
||||
|
||||
int rc = [FFmpegKit execute: @"-i file1.mp4 -c:v mpeg4 file2.mp4"]; |
||||
|
||||
if (rc == RETURN_CODE_SUCCESS) { |
||||
NSLog(@"Command execution completed successfully.\n"); |
||||
} else if (rc == RETURN_CODE_CANCEL) { |
||||
NSLog(@"Command execution cancelled by user.\n"); |
||||
} else { |
||||
NSLog(@"Command execution failed with rc=%d and output=%@.\n", rc, [FFmpegKitConfig getLastCommandOutput]); |
||||
} |
||||
``` |
||||
|
||||
3. Execute asynchronous FFmpeg commands. |
||||
``` |
||||
#import <ffmpegkit/FFmpegKitConfig.h> |
||||
#import <ffmpegkit/FFmpegKit.h> |
||||
|
||||
long executionId = [FFmpegKit executeAsync:@"-i file1.mp4 -c:v mpeg4 file2.mp4" withCallback:self]; |
||||
|
||||
- (void)executeCallback:(long)executionId :(int)returnCode { |
||||
if (rc == RETURN_CODE_SUCCESS) { |
||||
NSLog(@"Async command execution completed successfully.\n"); |
||||
} else if (rc == RETURN_CODE_CANCEL) { |
||||
NSLog(@"Async command execution cancelled by user.\n"); |
||||
} else { |
||||
NSLog(@"Async command execution failed with rc=%d.\n", rc); |
||||
} |
||||
} |
||||
``` |
||||
|
||||
4. Execute FFprobe commands. |
||||
``` |
||||
#import <ffmpegkit/FFmpegKitConfig.h> |
||||
#import <ffmpegkit/FFprobeKit.h> |
||||
|
||||
int rc = [FFprobeKit execute: @"-i file1.mp4"]; |
||||
|
||||
if (rc == RETURN_CODE_SUCCESS) { |
||||
NSLog(@"Command execution completed successfully.\n"); |
||||
} else if (rc == RETURN_CODE_CANCEL) { |
||||
NSLog(@"Command execution cancelled by user.\n"); |
||||
} else { |
||||
NSLog(@"Command execution failed with rc=%d and output=%@.\n", rc, [FFmpegKitConfig getLastCommandOutput]); |
||||
} |
||||
``` |
||||
|
||||
5. Check execution output later. |
||||
``` |
||||
int rc = [FFmpegKitConfig getLastReturnCode]; |
||||
NSString *output = [FFmpegKitConfig getLastCommandOutput]; |
||||
|
||||
if (rc == RETURN_CODE_SUCCESS) { |
||||
NSLog(@"Command execution completed successfully.\n"); |
||||
} else if (rc == RETURN_CODE_CANCEL) { |
||||
NSLog(@"Command execution cancelled by user.\n"); |
||||
} else { |
||||
NSLog(@"Command execution failed with rc=%d and output=%@.\n", rc, output); |
||||
} |
||||
``` |
||||
|
||||
6. Stop ongoing FFmpeg operations. |
||||
- Stop all executions |
||||
``` |
||||
[FFmpegKit cancel]; |
||||
|
||||
``` |
||||
- Stop a specific execution |
||||
``` |
||||
[FFmpegKit cancel:executionId]; |
||||
``` |
||||
|
||||
7. Get media information for a file. |
||||
``` |
||||
MediaInformation *mediaInformation = [FFprobeKit getMediaInformation:@"<file path or uri>"]; |
||||
``` |
||||
|
||||
8. Record video and audio using iOS camera. This operation is not supported on `tvOS` since `AVFoundation` is not available on `tvOS`. |
||||
|
||||
``` |
||||
[FFmpegKit execute: @"-f avfoundation -r 30 -video_size 1280x720 -pixel_format bgr0 -i 0:0 -vcodec h264_videotoolbox -vsync 2 -f h264 -t 00:00:05 %@", recordFilePath]; |
||||
``` |
||||
|
||||
9. Enable log callback. |
||||
``` |
||||
[FFmpegKitConfig setLogDelegate:self]; |
||||
|
||||
- (void)logCallback:(long)executionId :(int)level :(NSString*)message { |
||||
dispatch_async(dispatch_get_main_queue(), ^{ |
||||
NSLog(@"%@", message); |
||||
}); |
||||
} |
||||
``` |
||||
|
||||
10. Enable statistics callback. |
||||
``` |
||||
[FFmpegKitConfig setStatisticsDelegate:self]; |
||||
|
||||
- (void)statisticsCallback:(Statistics *)newStatistics { |
||||
dispatch_async(dispatch_get_main_queue(), ^{ |
||||
NSLog(@"frame: %d, time: %d\n", newStatistics.getVideoFrameNumber, newStatistics.getTime); |
||||
}); |
||||
} |
||||
``` |
||||
|
||||
11. Ignore the handling of a signal. |
||||
``` |
||||
[FFmpegKitConfig ignoreSignal:SIGXCPU]; |
||||
``` |
||||
|
||||
12. List ongoing executions. |
||||
``` |
||||
NSArray* ffmpegExecutions = [FFmpegKit listExecutions]; |
||||
for (int i = 0; i < [ffmpegExecutions count]; i++) { |
||||
FFmpegExecution* execution = [ffmpegExecutions objectAtIndex:i]; |
||||
NSLog(@"Execution %d = id: %ld, startTime: %@, command: %@.\n", i, [execution getExecutionId], [execution getStartTime], [execution getCommand]); |
||||
} |
||||
``` |
||||
|
||||
13. Set default log level. |
||||
``` |
||||
[FFmpegKitConfig setLogLevel:AV_LOG_FATAL]; |
||||
``` |
||||
|
||||
14. Register custom fonts directory. |
||||
``` |
||||
[FFmpegKitConfig setFontDirectory:@"<folder with fonts>" with:nil]; |
||||
``` |
||||
|
||||
#### 2.4 Manual Installation |
||||
##### 2.4.1 Android |
||||
|
||||
You can import `FFmpegKit` aar packages in `Android Studio` using the `File` -> `New` -> `New Module` -> `Import .JAR/.AAR Package` menu. |
||||
|
||||
##### 2.4.2 iOS / tvOS |
||||
|
||||
iOS and tvOS frameworks can be installed manually using the [Importing Frameworks](https://github.com/tanersener/ffmpeg-kit/wiki/Importing-Frameworks) guide. |
||||
If you want to use universal binaries please refer to [Using Universal Binaries](https://github.com/tanersener/ffmpeg-kit/wiki/Using-Universal-Binaries) guide. |
||||
|
||||
#### 2.5 Test Application |
||||
You can see how FFmpegKit is used inside an application by running test applications provided. |
||||
There is an `Android` test application under the `android/test-app` folder, an `iOS` test application under the |
||||
`ios/test-app` folder and a `tvOS` test application under the `tvos/test-app` folder. |
||||
|
||||
All applications are identical and supports command execution, video encoding, accessing https, encoding audio, |
||||
burning subtitles, video stabilisation, pipe operations and concurrent command execution. |
||||
|
||||
<img src="https://github.com/tanersener/ffmpeg-kit/blob/master/docs/assets/android_test_app.gif" width="240"> |
||||
|
||||
### 3. Versions |
||||
|
||||
- `dev` part in `FFmpeg` version number indicates that `FFmpeg` source is pulled from the `FFmpeg` `master` branch. |
||||
Exact version number is obtained using `git describe --tags`. |
||||
|
||||
| FFmpegKit Version | FFmpeg Version | Release Date | |
||||
| :----: | :----: |:----: | |
||||
| [4.4](https://github.com/tanersener/ffmpeg-kit/releases/tag/v4.4) | 4.4-dev-416 | Jul 25, 2020 | |
||||
| [4.4.LTS](https://github.com/tanersener/ffmpeg-kit/releases/tag/v4.4.LTS) | 4.4-dev-416 | Jul 24, 2020 | |
||||
|
||||
### 4. LTS Releases |
||||
|
||||
`FFmpegKit` binaries are published in two release variants: `Main Release` and `LTS Release`. |
||||
|
||||
- Main releases include complete functionality of the library and support the latest SDK/API features. |
||||
|
||||
- LTS releases are customized to support a wider range of devices. They are built using older API/SDK versions, so some features are not available on them. |
||||
|
||||
This table shows the differences between two variants. |
||||
|
||||
| | Main Release | LTS Release | |
||||
| :----: | :----: | :----: | |
||||
| Android API Level | 24 | 16 | |
||||
| Android Camera Access | Yes | - | |
||||
| Android Architectures | arm-v7a-neon<br/>arm64-v8a<br/>x86<br/>x86-64 | arm-v7a<br/>arm-v7a-neon<br/>arm64-v8a<br/>x86<br/>x86-64 | |
||||
| Xcode Support | 10.1 | 7.3.1 | |
||||
| iOS SDK | 12.1 | 9.3 | |
||||
| iOS AVFoundation | Yes | - | |
||||
| iOS Architectures | arm64<br/>x86-64<br/>x86-64-mac-catalyst | armv7<br/>arm64<br/>i386<br/>x86-64 | |
||||
| tvOS SDK | 10.2 | 9.2 | |
||||
| tvOS Architectures | arm64<br/>x86-64 | arm64<br/>x86-64 | |
||||
|
||||
### 5. Building |
||||
|
||||
Build scripts from `master` and `development` branches are tested periodically. See the latest status from the table below. |
||||
|
||||
| branch | status | |
||||
| :---: | :---: | |
||||
| master | [](https://travis-ci.org/tanersener/ffmpeg-kit) | |
||||
| development | [](https://travis-ci.org/tanersener/ffmpeg-kit) | |
||||
|
||||
|
||||
#### 5.1 Prerequisites |
||||
1. Use your package manager (apt, yum, dnf, brew, etc.) to install the following packages. |
||||
|
||||
``` |
||||
autoconf automake libtool pkg-config curl cmake gcc gperf texinfo yasm nasm bison autogen patch git |
||||
``` |
||||
Some of these packages are not mandatory for the default build. |
||||
Please visit [Android Prerequisites](https://github.com/tanersener/ffmpeg-kit/wiki/Android-Prerequisites), |
||||
[iOS Prerequisites](https://github.com/tanersener/ffmpeg-kit/wiki/iOS-Prerequisites) and |
||||
[tvOS Prerequisites](https://github.com/tanersener/ffmpeg-kit/wiki/tvOS-Prerequisites) for the details. |
||||
|
||||
2. Android builds require these additional packages. |
||||
- **Android SDK 4.1 Jelly Bean (API Level 16)** or later |
||||
- **Android NDK r21** or later with LLDB and CMake |
||||
|
||||
3. iOS builds need these extra packages and tools. |
||||
- **Xcode 7.3.1** or later |
||||
- **iOS SDK 9.3** or later |
||||
- **Command Line Tools** |
||||
|
||||
4. tvOS builds need these extra packages and tools. |
||||
- **Xcode 7.3.1** or later |
||||
- **tvOS SDK 9.2** or later |
||||
- **Command Line Tools** |
||||
|
||||
#### 5.2 Build Scripts |
||||
Use `android.sh`, `ios.sh` and `tvos.sh` to build FFmpegKit for each platform. |
||||
|
||||
All three scripts support additional options and |
||||
can be customized to enable/disable specific external libraries and/or architectures. Please refer to wiki pages of |
||||
[android.sh](https://github.com/tanersener/ffmpeg-kit/wiki/android.sh), |
||||
[ios.sh](https://github.com/tanersener/ffmpeg-kit/wiki/ios.sh) and |
||||
[tvos.sh](https://github.com/tanersener/ffmpeg-kit/wiki/tvos.sh) to see all available build options. |
||||
##### 5.2.1 Android |
||||
``` |
||||
export ANDROID_SDK_ROOT=<Android SDK Path> |
||||
export ANDROID_NDK_ROOT=<Android NDK Path> |
||||
./android.sh |
||||
``` |
||||
|
||||
<img src="https://github.com/tanersener/ffmpeg-kit/blob/master/docs/assets/android_custom.gif" width="600"> |
||||
|
||||
##### 5.2.2 iOS |
||||
``` |
||||
./ios.sh |
||||
``` |
||||
|
||||
<img src="https://github.com/tanersener/ffmpeg-kit/blob/master/docs/assets/ios_custom.gif" width="600"> |
||||
|
||||
##### 5.2.3 tvOS |
||||
``` |
||||
./tvos.sh |
||||
``` |
||||
|
||||
<img src="https://github.com/tanersener/ffmpeg-kit/blob/master/docs/assets/tvos_custom.gif" width="600"> |
||||
|
||||
|
||||
##### 5.2.4 Building LTS Binaries |
||||
|
||||
Use `--lts` option to build lts binaries for each platform. |
||||
|
||||
#### 5.3 Build Output |
||||
|
||||
All libraries created by the top level build scripts (`android.sh`, `ios.sh` and `tvos.sh`) can be found under |
||||
the `prebuilt` directory. |
||||
|
||||
- `Android` archive (.aar file) is located under the `android-aar` folder |
||||
- `iOS` frameworks are located under the `ios-framework` folder |
||||
- `iOS` xcframeworks are located under the `ios-xcframework` folder |
||||
- `iOS` universal binaries are located under the `ios-universal` folder |
||||
- `tvOS` frameworks are located under the `tvos-framework` folder |
||||
- `tvOS` universal binaries are located under the `tvos-universal` folder |
||||
|
||||
#### 5.4 GPL Support |
||||
It is possible to enable GPL licensed libraries `x264`, `xvidcore`, `vid.stab`, `x265` and`rubberband` from the top |
||||
level build scripts. Their source code is not included in the repository and downloaded when enabled. |
||||
|
||||
#### 5.5 External Libraries |
||||
`build` directory includes build scripts of all external libraries. Two scripts exist for each external library, |
||||
one for `Android` and one for `iOS / tvOS`. Each of these two scripts contains options/flags used to cross-compile the |
||||
library on the specified platform. |
||||
|
||||
CPU optimizations (`ASM`) are enabled for most of the external libraries. Details and exceptions can be found under the |
||||
[ASM Support](https://github.com/tanersener/ffmpeg-kit/wiki/ASM-Support) wiki page. |
||||
|
||||
### 6. Documentation |
||||
|
||||
A more detailed documentation is available at [Wiki](https://github.com/tanersener/ffmpeg-kit/wiki). |
||||
|
||||
### 8. License |
||||
|
||||
`FFmpegKit` is licensed under the LGPL v3.0. However, if source code is built using the optional `--enable-gpl` flag |
||||
or prebuilt binaries with `-gpl` postfix are used, then FFmpegKit is subject to the GPL v3.0 license. |
||||
|
||||
The source code of all external libraries included is in compliance with their individual licenses. |
||||
|
||||
`openh264` source code included in this repository is licensed under the 2-clause BSD License but this license does |
||||
not cover the `MPEG LA` licensing fees. If you build `ffmpeg-kit` with `openh264` and distribute that library, then |
||||
you are subject to pay `MPEG LA` licensing fees. Refer to [OpenH264 FAQ](https://www.openh264.org/faq.html) page for |
||||
the details. Please note that `ffmpeg-kit` does not publish a binary with `openh264` inside. |
||||
|
||||
`strip-frameworks.sh` script included and distributed (until v4.x) is published under the |
||||
[Apache License version 2.0](https://www.apache.org/licenses/LICENSE-2.0). |
||||
|
||||
In test applications; embedded fonts are licensed under the |
||||
[SIL Open Font License](https://opensource.org/licenses/OFL-1.1), other digital assets are published in the public |
||||
domain. |
||||
|
||||
Please visit [License](https://github.com/tanersener/ffmpeg-kit/wiki/License) page for the details. |
||||
|
||||
### 9. Patents |
||||
|
||||
It is not clearly explained in their documentation but it is believed that `FFmpeg`, `kvazaar`, `x264` and `x265` |
||||
include algorithms which are subject to software patents. If you live in a country where software algorithms are |
||||
patentable then you'll probably need to pay royalty fees to patent holders. We are not lawyers though, so we recommend |
||||
that you seek legal advice first. See [FFmpeg Patent Mini-FAQ](https://ffmpeg.org/legal.html). |
||||
|
||||
`openh264` clearly states that it uses patented algorithms. Therefore, if you build ffmpeg-kit with openh264 and |
||||
distribute that library, then you are subject to pay MPEG LA licensing fees. Refer to |
||||
[OpenH264 FAQ](https://www.openh264.org/faq.html) page for the details. |
||||
|
||||
### 10. Contributing |
||||
|
||||
Feel free to submit issues or pull requests. |
||||
|
||||
Please note that `master` includes only the latest released source code. Changes planned for the next release are |
||||
implemented under the `development` branch. Therefore, if you want to create a pull request, please open it against |
||||
the `development`. |
||||
|
||||
### 11. See Also |
||||
|
||||
- [libav gas-preprocessor](https://github.com/libav/gas-preprocessor/raw/master/gas-preprocessor.pl) |
||||
- [FFmpeg API Documentation](https://ffmpeg.org/doxygen/4.0/index.html) |
||||
- [FFmpeg Wiki](https://trac.ffmpeg.org/wiki/WikiStart) |
||||
- [FFmpeg External Library Licenses](https://www.ffmpeg.org/doxygen/4.0/md_LICENSE.html) |
||||
@ -0,0 +1,7 @@ |
||||
/build |
||||
/local.properties |
||||
/.idea/ |
||||
/.gradle/ |
||||
/libs/ |
||||
/obj/ |
||||
/app/build/ |
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,44 @@ |
||||
apply plugin: 'com.android.library' |
||||
|
||||
android { |
||||
compileSdkVersion 30 |
||||
ndkVersion "21.3.6528147" |
||||
|
||||
defaultConfig { |
||||
minSdkVersion 24 |
||||
targetSdkVersion 30 |
||||
versionCode 240440 |
||||
versionName "4.4" |
||||
project.archivesBaseName = "ffmpeg-kit" |
||||
consumerProguardFiles 'proguard-rules.pro' |
||||
} |
||||
|
||||
buildTypes { |
||||
release { |
||||
minifyEnabled false |
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' |
||||
} |
||||
} |
||||
|
||||
sourceSets { |
||||
main { |
||||
jniLibs.srcDirs = ["../libs"] |
||||
} |
||||
} |
||||
|
||||
testOptions { |
||||
unitTests.returnDefaultValues = true |
||||
} |
||||
} |
||||
|
||||
task javadoc(type: Javadoc) { |
||||
title = 'FFmpegKit' |
||||
destinationDir = file("${projectDir}/../../docs/android/javadoc") |
||||
classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) |
||||
source = android.sourceSets.main.java.srcDirs |
||||
} |
||||
|
||||
dependencies { |
||||
testImplementation "androidx.test.ext:junit:1.1.1" |
||||
testImplementation "org.json:json:20190722" |
||||
} |
||||
@ -0,0 +1,16 @@ |
||||
# Add project specific ProGuard rules here. |
||||
# You can control the set of applied configuration files using the |
||||
# proguardFiles setting in build.gradle. |
||||
# |
||||
# For more details, see |
||||
# http://developer.android.com/guide/developing/tools/proguard.html |
||||
|
||||
-keep class com.arthenica.ffmpegkit.FFmpegKitConfig { |
||||
native <methods>; |
||||
void log(long, int, byte[]); |
||||
void statistics(long, int, float, float, long , int, double, double); |
||||
} |
||||
|
||||
-keep class com.arthenica.ffmpegkit.AbiDetect { |
||||
native <methods>; |
||||
} |
||||
@ -0,0 +1,2 @@ |
||||
<manifest package="com.arthenica.ffmpegkit"> |
||||
</manifest> |
||||
@ -0,0 +1,2 @@ |
||||
/android_lts_support.o |
||||
/libandroidltssupport.a |
||||
@ -0,0 +1,69 @@ |
||||
/*
|
||||
* Copyright (C) 2008 The Android Open Source Project |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions |
||||
* are met: |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in |
||||
* the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
||||
* SUCH DAMAGE. |
||||
*/ |
||||
|
||||
#include <math.h> |
||||
#include <errno.h> |
||||
#include <malloc.h> |
||||
#include <stdlib.h> |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
#if __ANDROID_API__ < 17 |
||||
|
||||
int posix_memalign(void** memptr, size_t alignment, size_t size) { |
||||
if ((alignment & (alignment - 1)) != 0 || alignment == 0) { |
||||
return EINVAL; |
||||
} |
||||
|
||||
if (alignment % sizeof(void*) != 0) { |
||||
return EINVAL; |
||||
} |
||||
|
||||
*memptr = memalign(alignment, size); |
||||
if (*memptr == NULL) { |
||||
return errno; |
||||
} |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
#endif /* __ANDROID_API__ < 17 */ |
||||
|
||||
double log2(double x) { |
||||
return (log(x) / M_LN2); |
||||
} |
||||
|
||||
float log2f(float x) { |
||||
return (float) log2((double) x); |
||||
} |
||||
|
||||
#ifdef __cplusplus |
||||
}; /* end of extern "C" */ |
||||
#endif |
||||
@ -0,0 +1,945 @@ |
||||
/*
|
||||
* Copyright (c) 2018-2020 Taner Sener |
||||
* |
||||
* This file is part of FFmpegKit. |
||||
* |
||||
* FFmpegKit is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Lesser General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* FFmpegKit 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 Lesser General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General Public License |
||||
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#include <pthread.h> |
||||
#include <sys/types.h> |
||||
#include <sys/stat.h> |
||||
|
||||
#include "config.h" |
||||
#include "libavcodec/jni.h" |
||||
#include "libavutil/bprint.h" |
||||
#include "fftools_ffmpeg.h" |
||||
#include "ffmpegkit.h" |
||||
#include "ffprobekit.h" |
||||
|
||||
/** Callback data structure */ |
||||
struct CallbackData { |
||||
int type; // 1 (log callback) or 2 (statistics callback)
|
||||
long executionId; // execution id
|
||||
|
||||
int logLevel; // log level
|
||||
AVBPrint logData; // log data
|
||||
|
||||
int statisticsFrameNumber; // statistics frame number
|
||||
float statisticsFps; // statistics fps
|
||||
float statisticsQuality; // statistics quality
|
||||
int64_t statisticsSize; // statistics size
|
||||
int statisticsTime; // statistics time
|
||||
double statisticsBitrate; // statistics bitrate
|
||||
double statisticsSpeed; // statistics speed
|
||||
|
||||
struct CallbackData *next; |
||||
}; |
||||
|
||||
/** Execution map variables */ |
||||
const int EXECUTION_MAP_SIZE = 1000; |
||||
static volatile int executionMap[EXECUTION_MAP_SIZE]; |
||||
static pthread_mutex_t executionMapMutex; |
||||
|
||||
/** Redirection control variables */ |
||||
static pthread_mutex_t lockMutex; |
||||
static pthread_mutex_t monitorMutex; |
||||
static pthread_cond_t monitorCondition; |
||||
|
||||
/** Last command output variables */ |
||||
static pthread_mutex_t logMutex; |
||||
static AVBPrint lastCommandOutput; |
||||
|
||||
pthread_t callbackThread; |
||||
int redirectionEnabled; |
||||
|
||||
struct CallbackData *callbackDataHead; |
||||
struct CallbackData *callbackDataTail; |
||||
|
||||
/** Global reference to the virtual machine running */ |
||||
static JavaVM *globalVm; |
||||
|
||||
/** Global reference of Config class in Java */ |
||||
static jclass configClass; |
||||
|
||||
/** Global reference of log redirection method in Java */ |
||||
static jmethodID logMethod; |
||||
|
||||
/** Global reference of statistics redirection method in Java */ |
||||
static jmethodID statisticsMethod; |
||||
|
||||
/** Global reference of String class in Java */ |
||||
static jclass stringClass; |
||||
|
||||
/** Global reference of String constructor in Java */ |
||||
static jmethodID stringConstructor; |
||||
|
||||
/** Full name of the Config class */ |
||||
const char *configClassName = "com/arthenica/ffmpegkit/Config"; |
||||
|
||||
/** Full name of String class */ |
||||
const char *stringClassName = "java/lang/String"; |
||||
|
||||
/** Fields that control the handling of SIGNALs */ |
||||
volatile int handleSIGQUIT = 1; |
||||
volatile int handleSIGINT = 1; |
||||
volatile int handleSIGTERM = 1; |
||||
volatile int handleSIGXCPU = 1; |
||||
volatile int handleSIGPIPE = 1; |
||||
|
||||
/** Holds the id of the current execution */ |
||||
__thread volatile long executionId = 0; |
||||
|
||||
/** Holds the default log level */ |
||||
int configuredLogLevel = AV_LOG_INFO; |
||||
|
||||
/** Prototypes of native functions defined by Config class. */ |
||||
JNINativeMethod configMethods[] = { |
||||
{"enableNativeRedirection", "()V", (void*) Java_com_arthenica_ffmpegkit_FFmpegKitConfig_enableNativeRedirection}, |
||||
{"disableNativeRedirection", "()V", (void*) Java_com_arthenica_ffmpegkit_FFmpegKitConfig_disableNativeRedirection}, |
||||
{"setNativeLogLevel", "(I)V", (void*) Java_com_arthenica_ffmpegkit_FFmpegKitConfig_setNativeLogLevel}, |
||||
{"getNativeLogLevel", "()I", (void*) Java_com_arthenica_ffmpegkit_FFmpegKitConfig_getNativeLogLevel}, |
||||
{"getNativeFFmpegVersion", "()Ljava/lang/String;", (void*) Java_com_arthenica_ffmpegkit_FFmpegKitConfig_getNativeFFmpegVersion}, |
||||
{"getNativeVersion", "()Ljava/lang/String;", (void*) Java_com_arthenica_ffmpegkit_FFmpegKitConfig_getNativeVersion}, |
||||
{"nativeFFmpegExecute", "(J[Ljava/lang/String;)I", (void*) Java_com_arthenica_ffmpegkit_FFmpegKitConfig_nativeFFmpegExecute}, |
||||
{"nativeFFmpegCancel", "(J)V", (void*) Java_com_arthenica_ffmpegkit_FFmpegKitConfig_nativeFFmpegCancel}, |
||||
{"nativeFFprobeExecute", "([Ljava/lang/String;)I", (void*) Java_com_arthenica_ffmpegkit_FFmpegKitConfig_nativeFFprobeExecute}, |
||||
{"registerNewNativeFFmpegPipe", "(Ljava/lang/String;)I", (void*) Java_com_arthenica_ffmpegkit_FFmpegKitConfig_registerNewNativeFFmpegPipe}, |
||||
{"getNativeBuildDate", "()Ljava/lang/String;", (void*) Java_com_arthenica_ffmpegkit_FFmpegKitConfig_getNativeBuildDate}, |
||||
{"setNativeEnvironmentVariable", "(Ljava/lang/String;Ljava/lang/String;)I", (void*) Java_com_arthenica_ffmpegkit_FFmpegKitConfig_setNativeEnvironmentVariable}, |
||||
{"getNativeLastCommandOutput", "()Ljava/lang/String;", (void*) Java_com_arthenica_ffmpegkit_FFmpegKitConfig_getNativeLastCommandOutput}, |
||||
{"ignoreNativeSignal", "(I)V", (void*) Java_com_arthenica_ffmpegkit_FFmpegKitConfig_ignoreNativeSignal} |
||||
}; |
||||
|
||||
/** Forward declaration for function defined in fftools_ffmpeg.c */ |
||||
int ffmpeg_execute(int argc, char **argv); |
||||
|
||||
static const char *avutil_log_get_level_str(int level) { |
||||
switch (level) { |
||||
case AV_LOG_STDERR: |
||||
return "stderr"; |
||||
case AV_LOG_QUIET: |
||||
return "quiet"; |
||||
case AV_LOG_DEBUG: |
||||
return "debug"; |
||||
case AV_LOG_VERBOSE: |
||||
return "verbose"; |
||||
case AV_LOG_INFO: |
||||
return "info"; |
||||
case AV_LOG_WARNING: |
||||
return "warning"; |
||||
case AV_LOG_ERROR: |
||||
return "error"; |
||||
case AV_LOG_FATAL: |
||||
return "fatal"; |
||||
case AV_LOG_PANIC: |
||||
return "panic"; |
||||
default: |
||||
return ""; |
||||
} |
||||
} |
||||
|
||||
static void avutil_log_format_line(void *avcl, int level, const char *fmt, va_list vl, AVBPrint part[4], int *print_prefix) { |
||||
int flags = av_log_get_flags(); |
||||
AVClass* avc = avcl ? *(AVClass **) avcl : NULL; |
||||
av_bprint_init(part+0, 0, 1); |
||||
av_bprint_init(part+1, 0, 1); |
||||
av_bprint_init(part+2, 0, 1); |
||||
av_bprint_init(part+3, 0, 65536); |
||||
|
||||
if (*print_prefix && avc) { |
||||
if (avc->parent_log_context_offset) { |
||||
AVClass** parent = *(AVClass ***) (((uint8_t *) avcl) + |
||||
avc->parent_log_context_offset); |
||||
if (parent && *parent) { |
||||
av_bprintf(part+0, "[%s @ %p] ", |
||||
(*parent)->item_name(parent), parent); |
||||
} |
||||
} |
||||
av_bprintf(part+1, "[%s @ %p] ", |
||||
avc->item_name(avcl), avcl); |
||||
} |
||||
|
||||
if (*print_prefix && (level > AV_LOG_QUIET) && (flags & AV_LOG_PRINT_LEVEL)) |
||||
av_bprintf(part+2, "[%s] ", avutil_log_get_level_str(level)); |
||||
|
||||
av_vbprintf(part+3, fmt, vl); |
||||
|
||||
if(*part[0].str || *part[1].str || *part[2].str || *part[3].str) { |
||||
char lastc = part[3].len && part[3].len <= part[3].size ? part[3].str[part[3].len - 1] : 0; |
||||
*print_prefix = lastc == '\n' || lastc == '\r'; |
||||
} |
||||
} |
||||
|
||||
static void avutil_log_sanitize(uint8_t *line) { |
||||
while(*line){ |
||||
if(*line < 0x08 || (*line > 0x0D && *line < 0x20)) |
||||
*line='?'; |
||||
line++; |
||||
} |
||||
} |
||||
|
||||
void mutexInit() { |
||||
pthread_mutexattr_t attributes; |
||||
pthread_mutexattr_init(&attributes); |
||||
pthread_mutexattr_settype(&attributes, PTHREAD_MUTEX_RECURSIVE_NP); |
||||
|
||||
pthread_mutex_init(&lockMutex, &attributes); |
||||
pthread_mutexattr_destroy(&attributes); |
||||
} |
||||
|
||||
void monitorInit() { |
||||
pthread_mutexattr_t attributes; |
||||
pthread_mutexattr_init(&attributes); |
||||
pthread_mutexattr_settype(&attributes, PTHREAD_MUTEX_RECURSIVE_NP); |
||||
|
||||
pthread_condattr_t cattributes; |
||||
pthread_condattr_init(&cattributes); |
||||
pthread_condattr_setpshared(&cattributes, PTHREAD_PROCESS_PRIVATE); |
||||
|
||||
pthread_mutex_init(&monitorMutex, &attributes); |
||||
pthread_mutexattr_destroy(&attributes); |
||||
|
||||
pthread_cond_init(&monitorCondition, &cattributes); |
||||
pthread_condattr_destroy(&cattributes); |
||||
} |
||||
|
||||
void logInit() { |
||||
pthread_mutexattr_t attributes; |
||||
pthread_mutexattr_init(&attributes); |
||||
pthread_mutexattr_settype(&attributes, PTHREAD_MUTEX_RECURSIVE_NP); |
||||
|
||||
pthread_mutex_init(&logMutex, &attributes); |
||||
pthread_mutexattr_destroy(&attributes); |
||||
|
||||
av_bprint_init(&lastCommandOutput, 0, AV_BPRINT_SIZE_UNLIMITED); |
||||
} |
||||
|
||||
void executionMapLockInit() { |
||||
pthread_mutexattr_t attributes; |
||||
pthread_mutexattr_init(&attributes); |
||||
pthread_mutexattr_settype(&attributes, PTHREAD_MUTEX_RECURSIVE_NP); |
||||
|
||||
pthread_mutex_init(&executionMapMutex, &attributes); |
||||
pthread_mutexattr_destroy(&attributes); |
||||
} |
||||
|
||||
void mutexUnInit() { |
||||
pthread_mutex_destroy(&lockMutex); |
||||
} |
||||
|
||||
void monitorUnInit() { |
||||
pthread_mutex_destroy(&monitorMutex); |
||||
pthread_cond_destroy(&monitorCondition); |
||||
} |
||||
|
||||
void logUnInit() { |
||||
pthread_mutex_destroy(&logMutex); |
||||
} |
||||
|
||||
void executionMapLockUnInit() { |
||||
pthread_mutex_destroy(&executionMapMutex); |
||||
} |
||||
|
||||
void mutexLock() { |
||||
pthread_mutex_lock(&lockMutex); |
||||
} |
||||
|
||||
void lastCommandOutputLock() { |
||||
pthread_mutex_lock(&logMutex); |
||||
} |
||||
|
||||
void executionMapLock() { |
||||
pthread_mutex_lock(&executionMapMutex); |
||||
} |
||||
|
||||
void mutexUnlock() { |
||||
pthread_mutex_unlock(&lockMutex); |
||||
} |
||||
|
||||
void lastCommandOutputUnlock() { |
||||
pthread_mutex_unlock(&logMutex); |
||||
} |
||||
|
||||
void executionMapUnlock() { |
||||
pthread_mutex_unlock(&executionMapMutex); |
||||
} |
||||
|
||||
void clearLastCommandOutput() { |
||||
lastCommandOutputLock(); |
||||
av_bprint_clear(&lastCommandOutput); |
||||
lastCommandOutputUnlock(); |
||||
} |
||||
|
||||
void appendLastCommandOutput(AVBPrint *logMessage) { |
||||
if (logMessage->len <= 0) { |
||||
return; |
||||
} |
||||
|
||||
lastCommandOutputLock(); |
||||
av_bprintf(&lastCommandOutput, "%s", logMessage->str); |
||||
lastCommandOutputUnlock(); |
||||
} |
||||
|
||||
void monitorWait(int milliSeconds) { |
||||
struct timeval tp; |
||||
struct timespec ts; |
||||
int rc; |
||||
|
||||
rc = gettimeofday(&tp, NULL); |
||||
if (rc) { |
||||
return; |
||||
} |
||||
|
||||
ts.tv_sec = tp.tv_sec; |
||||
ts.tv_nsec = tp.tv_usec * 1000; |
||||
ts.tv_sec += milliSeconds / 1000; |
||||
ts.tv_nsec += (milliSeconds % 1000)*1000000; |
||||
ts.tv_sec += ts.tv_nsec / 1000000000L; |
||||
ts.tv_nsec = ts.tv_nsec % 1000000000L; |
||||
|
||||
pthread_mutex_lock(&monitorMutex); |
||||
pthread_cond_timedwait(&monitorCondition, &monitorMutex, &ts); |
||||
pthread_mutex_unlock(&monitorMutex); |
||||
} |
||||
|
||||
void monitorNotify() { |
||||
pthread_mutex_lock(&monitorMutex); |
||||
pthread_cond_signal(&monitorCondition); |
||||
pthread_mutex_unlock(&monitorMutex); |
||||
} |
||||
|
||||
/**
|
||||
* Adds log data to the end of callback data list. |
||||
* |
||||
* @param level log level |
||||
* @param data log data |
||||
*/ |
||||
void logCallbackDataAdd(int level, AVBPrint *data) { |
||||
|
||||
// CREATE DATA STRUCT FIRST
|
||||
struct CallbackData *newData = (struct CallbackData*)av_malloc(sizeof(struct CallbackData)); |
||||
newData->type = 1; |
||||
newData->executionId = executionId; |
||||
newData->logLevel = level; |
||||
av_bprint_init(&newData->logData, 0, AV_BPRINT_SIZE_UNLIMITED); |
||||
av_bprintf(&newData->logData, "%s", data->str); |
||||
newData->next = NULL; |
||||
|
||||
mutexLock(); |
||||
|
||||
// INSERT IT TO THE END OF QUEUE
|
||||
if (callbackDataTail == NULL) { |
||||
callbackDataTail = newData; |
||||
|
||||
if (callbackDataHead != NULL) { |
||||
LOGE("Dangling callback data head detected. This can cause memory leak."); |
||||
} else { |
||||
callbackDataHead = newData; |
||||
} |
||||
} else { |
||||
struct CallbackData *oldTail = callbackDataTail; |
||||
oldTail->next = newData; |
||||
|
||||
callbackDataTail = newData; |
||||
} |
||||
|
||||
mutexUnlock(); |
||||
|
||||
monitorNotify(); |
||||
} |
||||
|
||||
/**
|
||||
* Adds statistics data to the end of callback data list. |
||||
*/ |
||||
void statisticsCallbackDataAdd(int frameNumber, float fps, float quality, int64_t size, int time, double bitrate, double speed) { |
||||
|
||||
// CREATE DATA STRUCT FIRST
|
||||
struct CallbackData *newData = (struct CallbackData*)av_malloc(sizeof(struct CallbackData)); |
||||
newData->type = 2; |
||||
newData->executionId = executionId; |
||||
newData->statisticsFrameNumber = frameNumber; |
||||
newData->statisticsFps = fps; |
||||
newData->statisticsQuality = quality; |
||||
newData->statisticsSize = size; |
||||
newData->statisticsTime = time; |
||||
newData->statisticsBitrate = bitrate; |
||||
newData->statisticsSpeed = speed; |
||||
|
||||
newData->next = NULL; |
||||
|
||||
mutexLock(); |
||||
|
||||
// INSERT IT TO THE END OF QUEUE
|
||||
if (callbackDataTail == NULL) { |
||||
callbackDataTail = newData; |
||||
|
||||
if (callbackDataHead != NULL) { |
||||
LOGE("Dangling callback data head detected. This can cause memory leak."); |
||||
} else { |
||||
callbackDataHead = newData; |
||||
} |
||||
} else { |
||||
struct CallbackData *oldTail = callbackDataTail; |
||||
oldTail->next = newData; |
||||
|
||||
callbackDataTail = newData; |
||||
} |
||||
|
||||
mutexUnlock(); |
||||
|
||||
monitorNotify(); |
||||
} |
||||
|
||||
/**
|
||||
* Adds an execution id to the execution map. |
||||
* |
||||
* @param id execution id |
||||
*/ |
||||
void addExecution(long id) { |
||||
executionMapLock(); |
||||
|
||||
int key = id % EXECUTION_MAP_SIZE; |
||||
executionMap[key] = 1; |
||||
|
||||
executionMapUnlock(); |
||||
} |
||||
|
||||
/**
|
||||
* Removes head of callback data list. |
||||
*/ |
||||
struct CallbackData *callbackDataRemove() { |
||||
struct CallbackData *currentData; |
||||
|
||||
mutexLock(); |
||||
|
||||
if (callbackDataHead == NULL) { |
||||
currentData = NULL; |
||||
} else { |
||||
currentData = callbackDataHead; |
||||
|
||||
struct CallbackData *nextHead = currentData->next; |
||||
if (nextHead == NULL) { |
||||
if (callbackDataHead != callbackDataTail) { |
||||
LOGE("Head and tail callback data pointers do not match for single callback data element. This can cause memory leak."); |
||||
} else { |
||||
callbackDataTail = NULL; |
||||
} |
||||
callbackDataHead = NULL; |
||||
|
||||
} else { |
||||
callbackDataHead = nextHead; |
||||
} |
||||
} |
||||
|
||||
mutexUnlock(); |
||||
|
||||
return currentData; |
||||
} |
||||
|
||||
/**
|
||||
* Removes an execution id from the execution map. |
||||
* |
||||
* @param id execution id |
||||
*/ |
||||
void removeExecution(long id) { |
||||
executionMapLock(); |
||||
|
||||
int key = id % EXECUTION_MAP_SIZE; |
||||
executionMap[key] = 0; |
||||
|
||||
executionMapUnlock(); |
||||
} |
||||
|
||||
/**
|
||||
* Checks whether a cancel request for the given execution id exists in the execution map. |
||||
* |
||||
* @param id execution id |
||||
* @return 1 if exists, false otherwise |
||||
*/ |
||||
int cancelRequested(long id) { |
||||
int found = 0; |
||||
|
||||
executionMapLock(); |
||||
|
||||
int key = id % EXECUTION_MAP_SIZE; |
||||
if (executionMap[key] == 0) { |
||||
found = 1; |
||||
} |
||||
|
||||
executionMapUnlock(); |
||||
|
||||
return found; |
||||
} |
||||
|
||||
/**
|
||||
* Callback function for FFmpeg logs. |
||||
* |
||||
* @param ptr pointer to AVClass struct |
||||
* @param level log level |
||||
* @param format format string |
||||
* @param vargs arguments |
||||
*/ |
||||
void ffmpegkit_log_callback_function(void *ptr, int level, const char* format, va_list vargs) { |
||||
AVBPrint fullLine; |
||||
AVBPrint part[4]; |
||||
int print_prefix = 1; |
||||
|
||||
if (level >= 0) { |
||||
level &= 0xff; |
||||
} |
||||
int activeLogLevel = av_log_get_level(); |
||||
|
||||
// AV_LOG_STDERR logs are always redirected
|
||||
if ((activeLogLevel == AV_LOG_QUIET && level != AV_LOG_STDERR) || (level > activeLogLevel)) { |
||||
return; |
||||
} |
||||
|
||||
av_bprint_init(&fullLine, 0, AV_BPRINT_SIZE_UNLIMITED); |
||||
|
||||
avutil_log_format_line(ptr, level, format, vargs, part, &print_prefix); |
||||
avutil_log_sanitize(part[0].str); |
||||
avutil_log_sanitize(part[1].str); |
||||
avutil_log_sanitize(part[2].str); |
||||
avutil_log_sanitize(part[3].str); |
||||
|
||||
// COMBINE ALL 4 LOG PARTS
|
||||
av_bprintf(&fullLine, "%s%s%s%s", part[0].str, part[1].str, part[2].str, part[3].str); |
||||
|
||||
if (fullLine.len > 0) { |
||||
logCallbackDataAdd(level, &fullLine); |
||||
appendLastCommandOutput(&fullLine); |
||||
} |
||||
|
||||
av_bprint_finalize(part, NULL); |
||||
av_bprint_finalize(part+1, NULL); |
||||
av_bprint_finalize(part+2, NULL); |
||||
av_bprint_finalize(part+3, NULL); |
||||
av_bprint_finalize(&fullLine, NULL); |
||||
} |
||||
|
||||
/**
|
||||
* Callback function for FFmpeg statistics. |
||||
* |
||||
* @param frameNumber last processed frame number |
||||
* @param fps frames processed per second |
||||
* @param quality quality of the output stream (video only) |
||||
* @param size size in bytes |
||||
* @param time processed output duration |
||||
* @param bitrate output bit rate in kbits/s |
||||
* @param speed processing speed = processed duration / operation duration |
||||
*/ |
||||
void ffmpegkit_statistics_callback_function(int frameNumber, float fps, float quality, int64_t size, int time, double bitrate, double speed) { |
||||
statisticsCallbackDataAdd(frameNumber, fps, quality, size, time, bitrate, speed); |
||||
} |
||||
|
||||
/**
|
||||
* Forwards callback messages to Java classes. |
||||
*/ |
||||
void *callbackThreadFunction() { |
||||
JNIEnv *env; |
||||
jint getEnvRc = (*globalVm)->GetEnv(globalVm, (void**) &env, JNI_VERSION_1_6); |
||||
if (getEnvRc != JNI_OK) { |
||||
if (getEnvRc != JNI_EDETACHED) { |
||||
LOGE("Callback thread failed to GetEnv for class %s with rc %d.\n", configClassName, getEnvRc); |
||||
return NULL; |
||||
} |
||||
|
||||
if ((*globalVm)->AttachCurrentThread(globalVm, &env, NULL) != 0) { |
||||
LOGE("Callback thread failed to AttachCurrentThread for class %s.\n", configClassName); |
||||
return NULL; |
||||
} |
||||
} |
||||
|
||||
LOGD("Callback thread started.\n"); |
||||
|
||||
while(redirectionEnabled) { |
||||
|
||||
struct CallbackData *callbackData = callbackDataRemove(); |
||||
if (callbackData != NULL) { |
||||
if (callbackData->type == 1) { |
||||
|
||||
// LOG CALLBACK
|
||||
|
||||
int size = callbackData->logData.len; |
||||
|
||||
jbyteArray byteArray = (jbyteArray) (*env)->NewByteArray(env, size); |
||||
(*env)->SetByteArrayRegion(env, byteArray, 0, size, callbackData->logData.str); |
||||
(*env)->CallStaticVoidMethod(env, configClass, logMethod, (jlong) callbackData->executionId, callbackData->logLevel, byteArray); |
||||
(*env)->DeleteLocalRef(env, byteArray); |
||||
|
||||
// CLEAN LOG DATA
|
||||
av_bprint_finalize(&callbackData->logData, NULL); |
||||
|
||||
} else { |
||||
|
||||
// STATISTICS CALLBACK
|
||||
|
||||
(*env)->CallStaticVoidMethod(env, configClass, statisticsMethod, |
||||
(jlong) callbackData->executionId, callbackData->statisticsFrameNumber, |
||||
callbackData->statisticsFps, callbackData->statisticsQuality, |
||||
callbackData->statisticsSize, callbackData->statisticsTime, |
||||
callbackData->statisticsBitrate, callbackData->statisticsSpeed); |
||||
|
||||
} |
||||
|
||||
// CLEAN STRUCT
|
||||
callbackData->next = NULL; |
||||
av_free(callbackData); |
||||
|
||||
} else { |
||||
monitorWait(100); |
||||
} |
||||
} |
||||
|
||||
(*globalVm)->DetachCurrentThread(globalVm); |
||||
|
||||
LOGD("Callback thread stopped.\n"); |
||||
|
||||
return NULL; |
||||
} |
||||
|
||||
/**
|
||||
* Called when 'ffmpegkit' native library is loaded. |
||||
* |
||||
* @param vm pointer to the running virtual machine |
||||
* @param reserved reserved |
||||
* @return JNI version needed by 'ffmpegkit' library |
||||
*/ |
||||
jint JNI_OnLoad(JavaVM *vm, void *reserved) { |
||||
JNIEnv *env; |
||||
if ((*vm)->GetEnv(vm, (void**)(&env), JNI_VERSION_1_6) != JNI_OK) { |
||||
LOGE("OnLoad failed to GetEnv for class %s.\n", configClassName); |
||||
return JNI_FALSE; |
||||
} |
||||
|
||||
jclass localConfigClass = (*env)->FindClass(env, configClassName); |
||||
if (localConfigClass == NULL) { |
||||
LOGE("OnLoad failed to FindClass %s.\n", configClassName); |
||||
return JNI_FALSE; |
||||
} |
||||
|
||||
if ((*env)->RegisterNatives(env, localConfigClass, configMethods, 12) < 0) { |
||||
LOGE("OnLoad failed to RegisterNatives for class %s.\n", configClassName); |
||||
return JNI_FALSE; |
||||
} |
||||
|
||||
jclass localStringClass = (*env)->FindClass(env, stringClassName); |
||||
if (localStringClass == NULL) { |
||||
LOGE("OnLoad failed to FindClass %s.\n", stringClassName); |
||||
return JNI_FALSE; |
||||
} |
||||
|
||||
(*env)->GetJavaVM(env, &globalVm); |
||||
|
||||
logMethod = (*env)->GetStaticMethodID(env, localConfigClass, "log", "(JI[B)V"); |
||||
if (logMethod == NULL) { |
||||
LOGE("OnLoad thread failed to GetStaticMethodID for %s.\n", "log"); |
||||
return JNI_FALSE; |
||||
} |
||||
|
||||
statisticsMethod = (*env)->GetStaticMethodID(env, localConfigClass, "statistics", "(JIFFJIDD)V"); |
||||
if (logMethod == NULL) { |
||||
LOGE("OnLoad thread failed to GetStaticMethodID for %s.\n", "statistics"); |
||||
return JNI_FALSE; |
||||
} |
||||
|
||||
stringConstructor = (*env)->GetMethodID(env, localStringClass, "<init>", "([BLjava/lang/String;)V"); |
||||
if (stringConstructor == NULL) { |
||||
LOGE("OnLoad thread failed to GetMethodID for %s.\n", "<init>"); |
||||
return JNI_FALSE; |
||||
} |
||||
|
||||
av_jni_set_java_vm(vm, NULL); |
||||
|
||||
configClass = (jclass) ((*env)->NewGlobalRef(env, localConfigClass)); |
||||
stringClass = (jclass) ((*env)->NewGlobalRef(env, localStringClass)); |
||||
|
||||
redirectionEnabled = 0; |
||||
|
||||
callbackDataHead = NULL; |
||||
callbackDataTail = NULL; |
||||
|
||||
for(int i = 0; i<EXECUTION_MAP_SIZE; i++) { |
||||
executionMap[i] = 0; |
||||
} |
||||
|
||||
mutexInit(); |
||||
monitorInit(); |
||||
logInit(); |
||||
executionMapLockInit(); |
||||
|
||||
return JNI_VERSION_1_6; |
||||
} |
||||
|
||||
/**
|
||||
* Sets log level. |
||||
* |
||||
* @param env pointer to native method interface |
||||
* @param object reference to the class on which this method is invoked |
||||
* @param level log level |
||||
*/ |
||||
JNIEXPORT void JNICALL Java_com_arthenica_ffmpegkit_FFmpegKitConfig_setNativeLogLevel(JNIEnv *env, jclass object, jint level) { |
||||
configuredLogLevel = level; |
||||
} |
||||
|
||||
/**
|
||||
* Returns current log level. |
||||
* |
||||
* @param env pointer to native method interface |
||||
* @param object reference to the class on which this method is invoked |
||||
*/ |
||||
JNIEXPORT jint JNICALL Java_com_arthenica_ffmpegkit_FFmpegKitConfig_getNativeLogLevel(JNIEnv *env, jclass object) { |
||||
return configuredLogLevel; |
||||
} |
||||
|
||||
/**
|
||||
* Enables log and statistics redirection. |
||||
* |
||||
* @param env pointer to native method interface |
||||
* @param object reference to the class on which this method is invoked |
||||
*/ |
||||
JNIEXPORT void JNICALL Java_com_arthenica_ffmpegkit_FFmpegKitConfig_enableNativeRedirection(JNIEnv *env, jclass object) { |
||||
mutexLock(); |
||||
|
||||
if (redirectionEnabled != 0) { |
||||
mutexUnlock(); |
||||
return; |
||||
} |
||||
redirectionEnabled = 1; |
||||
|
||||
mutexUnlock(); |
||||
|
||||
int rc = pthread_create(&callbackThread, 0, callbackThreadFunction, 0); |
||||
if (rc != 0) { |
||||
LOGE("Failed to create callback thread (rc=%d).\n", rc); |
||||
return; |
||||
} |
||||
|
||||
av_log_set_callback(ffmpegkit_log_callback_function); |
||||
set_report_callback(ffmpegkit_statistics_callback_function); |
||||
} |
||||
|
||||
/**
|
||||
* Disables log and statistics redirection. |
||||
* |
||||
* @param env pointer to native method interface |
||||
* @param object reference to the class on which this method is invoked |
||||
*/ |
||||
JNIEXPORT void JNICALL Java_com_arthenica_ffmpegkit_FFmpegKitConfig_disableNativeRedirection(JNIEnv *env, jclass object) { |
||||
|
||||
mutexLock(); |
||||
|
||||
if (redirectionEnabled != 1) { |
||||
mutexUnlock(); |
||||
return; |
||||
} |
||||
redirectionEnabled = 0; |
||||
|
||||
mutexUnlock(); |
||||
|
||||
av_log_set_callback(av_log_default_callback); |
||||
set_report_callback(NULL); |
||||
|
||||
monitorNotify(); |
||||
} |
||||
|
||||
/**
|
||||
* Returns FFmpeg version bundled within the library natively. |
||||
* |
||||
* @param env pointer to native method interface |
||||
* @param object reference to the class on which this method is invoked |
||||
* @return FFmpeg version string |
||||
*/ |
||||
JNIEXPORT jstring JNICALL Java_com_arthenica_ffmpegkit_FFmpegKitConfig_getNativeFFmpegVersion(JNIEnv *env, jclass object) { |
||||
return (*env)->NewStringUTF(env, FFMPEG_VERSION); |
||||
} |
||||
|
||||
/**
|
||||
* Returns FFmpegKit library version natively. |
||||
* |
||||
* @param env pointer to native method interface |
||||
* @param object reference to the class on which this method is invoked |
||||
* @return FFmpegKit version string |
||||
*/ |
||||
JNIEXPORT jstring JNICALL Java_com_arthenica_ffmpegkit_FFmpegKitConfig_getNativeVersion(JNIEnv *env, jclass object) { |
||||
return (*env)->NewStringUTF(env, FFMPEG_KIT_VERSION); |
||||
} |
||||
|
||||
/**
|
||||
* Synchronously executes FFmpeg natively with arguments provided. |
||||
* |
||||
* @param env pointer to native method interface |
||||
* @param object reference to the class on which this method is invoked |
||||
* @param id execution id |
||||
* @param stringArray reference to the object holding FFmpeg command arguments |
||||
* @return zero on successful execution, non-zero on error |
||||
*/ |
||||
JNIEXPORT jint JNICALL Java_com_arthenica_ffmpegkit_FFmpegKitConfig_nativeFFmpegExecute(JNIEnv *env, jclass object, jlong id, jobjectArray stringArray) { |
||||
jstring *tempArray = NULL; |
||||
int argumentCount = 1; |
||||
char **argv = NULL; |
||||
|
||||
// SETS DEFAULT LOG LEVEL BEFORE STARTING A NEW EXECUTION
|
||||
av_log_set_level(configuredLogLevel); |
||||
|
||||
if (stringArray != NULL) { |
||||
int programArgumentCount = (*env)->GetArrayLength(env, stringArray); |
||||
argumentCount = programArgumentCount + 1; |
||||
|
||||
tempArray = (jstring *) av_malloc(sizeof(jstring) * programArgumentCount); |
||||
} |
||||
|
||||
/* PRESERVE USAGE FORMAT
|
||||
* |
||||
* ffmpeg <arguments> |
||||
*/ |
||||
argv = (char **)av_malloc(sizeof(char*) * (argumentCount)); |
||||
argv[0] = (char *)av_malloc(sizeof(char) * (strlen(LIB_NAME) + 1)); |
||||
strcpy(argv[0], LIB_NAME); |
||||
|
||||
// PREPARE
|
||||
if (stringArray != NULL) { |
||||
for (int i = 0; i < (argumentCount - 1); i++) { |
||||
tempArray[i] = (jstring) (*env)->GetObjectArrayElement(env, stringArray, i); |
||||
if (tempArray[i] != NULL) { |
||||
argv[i + 1] = (char *) (*env)->GetStringUTFChars(env, tempArray[i], 0); |
||||
} |
||||
} |
||||
} |
||||
|
||||
// LAST COMMAND OUTPUT SHOULD BE CLEARED BEFORE STARTING A NEW EXECUTION
|
||||
clearLastCommandOutput(); |
||||
|
||||
// REGISTER THE ID BEFORE STARTING EXECUTION
|
||||
executionId = (long) id; |
||||
addExecution((long) id); |
||||
|
||||
// RUN
|
||||
int retCode = ffmpeg_execute(argumentCount, argv); |
||||
|
||||
// ALWAYS REMOVE THE ID FROM THE MAP
|
||||
removeExecution((long) id); |
||||
|
||||
// CLEANUP
|
||||
if (tempArray != NULL) { |
||||
for (int i = 0; i < (argumentCount - 1); i++) { |
||||
(*env)->ReleaseStringUTFChars(env, tempArray[i], argv[i + 1]); |
||||
} |
||||
|
||||
av_free(tempArray); |
||||
} |
||||
av_free(argv[0]); |
||||
av_free(argv); |
||||
|
||||
return retCode; |
||||
} |
||||
|
||||
/**
|
||||
* Cancels an ongoing FFmpeg operation natively. |
||||
* |
||||
* @param env pointer to native method interface |
||||
* @param object reference to the class on which this method is invoked |
||||
* @param id execution id |
||||
*/ |
||||
JNIEXPORT void JNICALL Java_com_arthenica_ffmpegkit_FFmpegKitConfig_nativeFFmpegCancel(JNIEnv *env, jclass object, jlong id) { |
||||
cancel_operation(id); |
||||
} |
||||
|
||||
/**
|
||||
* Creates natively a new named pipe to use in FFmpeg operations. |
||||
* |
||||
* @param env pointer to native method interface |
||||
* @param object reference to the class on which this method is invoked |
||||
* @param ffmpegPipePath full path of ffmpeg pipe |
||||
* @return zero on successful creation, non-zero on error |
||||
*/ |
||||
JNIEXPORT int JNICALL Java_com_arthenica_ffmpegkit_FFmpegKitConfig_registerNewNativeFFmpegPipe(JNIEnv *env, jclass object, jstring ffmpegPipePath) { |
||||
const char *ffmpegPipePathString = (*env)->GetStringUTFChars(env, ffmpegPipePath, 0); |
||||
|
||||
return mkfifo(ffmpegPipePathString, S_IRWXU | S_IRWXG | S_IROTH); |
||||
} |
||||
|
||||
/**
|
||||
* Returns FFmpegKit library build date natively. |
||||
* |
||||
* @param env pointer to native method interface |
||||
* @param object reference to the class on which this method is invoked |
||||
* @return FFmpegKit library build date |
||||
*/ |
||||
JNIEXPORT jstring JNICALL Java_com_arthenica_ffmpegkit_FFmpegKitConfig_getNativeBuildDate(JNIEnv *env, jclass object) { |
||||
char buildDate[10]; |
||||
sprintf(buildDate, "%d", FFMPEG_KIT_BUILD_DATE); |
||||
return (*env)->NewStringUTF(env, buildDate); |
||||
} |
||||
|
||||
/**
|
||||
* Sets an environment variable natively |
||||
* |
||||
* @param env pointer to native method interface |
||||
* @param object reference to the class on which this method is invoked |
||||
* @param variableName environment variable name |
||||
* @param variableValue environment variable value |
||||
* @return zero on success, non-zero on error |
||||
*/ |
||||
JNIEXPORT int JNICALL Java_com_arthenica_ffmpegkit_FFmpegKitConfig_setNativeEnvironmentVariable(JNIEnv *env, jclass object, jstring variableName, jstring variableValue) { |
||||
const char *variableNameString = (*env)->GetStringUTFChars(env, variableName, 0); |
||||
const char *variableValueString = (*env)->GetStringUTFChars(env, variableValue, 0); |
||||
|
||||
int rc = setenv(variableNameString, variableValueString, 1); |
||||
|
||||
(*env)->ReleaseStringUTFChars(env, variableName, variableNameString); |
||||
(*env)->ReleaseStringUTFChars(env, variableValue, variableValueString); |
||||
return rc; |
||||
} |
||||
|
||||
/**
|
||||
* Returns log output of the last executed command natively. |
||||
* |
||||
* @param env pointer to native method interface |
||||
* @param object reference to the class on which this method is invoked |
||||
* @return output of the last executed command |
||||
*/ |
||||
JNIEXPORT jstring JNICALL Java_com_arthenica_ffmpegkit_FFmpegKitConfig_getNativeLastCommandOutput(JNIEnv *env, jclass object) { |
||||
int size = lastCommandOutput.len; |
||||
if (size > 0) { |
||||
jbyteArray byteArray = (*env)->NewByteArray(env, size); |
||||
(*env)->SetByteArrayRegion(env, byteArray, 0, size, lastCommandOutput.str); |
||||
jstring charsetName = (*env)->NewStringUTF(env, "UTF-8"); |
||||
return (jstring) (*env)->NewObject(env, stringClass, stringConstructor, byteArray, charsetName); |
||||
} |
||||
|
||||
return (*env)->NewStringUTF(env, ""); |
||||
} |
||||
|
||||
/**
|
||||
* Registers a new ignored signal. Ignored signals are not handled by the library. |
||||
* |
||||
* @param env pointer to native method interface |
||||
* @param object reference to the class on which this method is invoked |
||||
* @param signum signal number |
||||
*/ |
||||
JNIEXPORT void JNICALL Java_com_arthenica_ffmpegkit_FFmpegKitConfig_ignoreNativeSignal(JNIEnv *env, jclass object, jint signum) { |
||||
if (signum == SIGQUIT) { |
||||
handleSIGQUIT = 0; |
||||
} else if (signum == SIGINT) { |
||||
handleSIGINT = 0; |
||||
} else if (signum == SIGTERM) { |
||||
handleSIGTERM = 0; |
||||
} else if (signum == SIGXCPU) { |
||||
handleSIGXCPU = 0; |
||||
} else if (signum == SIGPIPE) { |
||||
handleSIGPIPE = 0; |
||||
} |
||||
} |
||||
@ -0,0 +1,141 @@ |
||||
/*
|
||||
* Copyright (c) 2018-2020 Taner Sener |
||||
* |
||||
* This file is part of FFmpegKit. |
||||
* |
||||
* FFmpegKit is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Lesser General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* FFmpegKit 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 Lesser General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General Public License |
||||
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#ifndef FFMPEG_KIT_H |
||||
#define FFMPEG_KIT_H |
||||
|
||||
#include <jni.h> |
||||
#include <android/log.h> |
||||
|
||||
#include "libavutil/log.h" |
||||
#include "libavutil/ffversion.h" |
||||
|
||||
/** Library version string */ |
||||
#define FFMPEG_KIT_VERSION "4.4" |
||||
|
||||
/** Defines tag used for Android logging. */ |
||||
#define LIB_NAME "ffmpeg-kit" |
||||
|
||||
/** Verbose Android logging macro. */ |
||||
#define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, LIB_NAME, __VA_ARGS__) |
||||
|
||||
/** Debug Android logging macro. */ |
||||
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LIB_NAME, __VA_ARGS__) |
||||
|
||||
/** Info Android logging macro. */ |
||||
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LIB_NAME, __VA_ARGS__) |
||||
|
||||
/** Warn Android logging macro. */ |
||||
#define LOGW(...) __android_log_print(ANDROID_LOG_WARN, LIB_NAME, __VA_ARGS__) |
||||
|
||||
/** Error Android logging macro. */ |
||||
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LIB_NAME, __VA_ARGS__) |
||||
|
||||
/*
|
||||
* Class: com_arthenica_ffmpegkit_FFmpegKitConfig |
||||
* Method: enableNativeRedirection |
||||
* Signature: ()V |
||||
*/ |
||||
JNIEXPORT void JNICALL Java_com_arthenica_ffmpegkit_FFmpegKitConfig_enableNativeRedirection(JNIEnv *, jclass); |
||||
|
||||
/*
|
||||
* Class: com_arthenica_ffmpegkit_FFmpegKitConfig |
||||
* Method: disableNativeRedirection |
||||
* Signature: ()V |
||||
*/ |
||||
JNIEXPORT void JNICALL Java_com_arthenica_ffmpegkit_FFmpegKitConfig_disableNativeRedirection(JNIEnv *, jclass); |
||||
|
||||
/*
|
||||
* Class: com_arthenica_ffmpegkit_FFmpegKitConfig |
||||
* Method: setNativeLogLevel |
||||
* Signature: (I)V |
||||
*/ |
||||
JNIEXPORT void JNICALL Java_com_arthenica_ffmpegkit_FFmpegKitConfig_setNativeLogLevel(JNIEnv *, jclass, jint); |
||||
|
||||
/*
|
||||
* Class: com_arthenica_ffmpegkit_FFmpegKitConfig |
||||
* Method: getNativeLogLevel |
||||
* Signature: ()I |
||||
*/ |
||||
JNIEXPORT jint JNICALL Java_com_arthenica_ffmpegkit_FFmpegKitConfig_getNativeLogLevel(JNIEnv *, jclass); |
||||
|
||||
/*
|
||||
* Class: com_arthenica_ffmpegkit_FFmpegKitConfig |
||||
* Method: getNativeFFmpegVersion |
||||
* Signature: ()Ljava/lang/String; |
||||
*/ |
||||
JNIEXPORT jstring JNICALL Java_com_arthenica_ffmpegkit_FFmpegKitConfig_getNativeFFmpegVersion(JNIEnv *, jclass); |
||||
|
||||
/*
|
||||
* Class: com_arthenica_ffmpegkit_FFmpegKitConfig |
||||
* Method: getNativeVersion |
||||
* Signature: ()Ljava/lang/String; |
||||
*/ |
||||
JNIEXPORT jstring JNICALL Java_com_arthenica_ffmpegkit_FFmpegKitConfig_getNativeVersion(JNIEnv *, jclass); |
||||
|
||||
/*
|
||||
* Class: com_arthenica_ffmpegkit_FFmpegKitConfig |
||||
* Method: nativeFFmpegExecute |
||||
* Signature: (J[Ljava/lang/String;)I |
||||
*/ |
||||
JNIEXPORT jint JNICALL Java_com_arthenica_ffmpegkit_FFmpegKitConfig_nativeFFmpegExecute(JNIEnv *, jclass, jlong id, jobjectArray); |
||||
|
||||
/*
|
||||
* Class: com_arthenica_ffmpegkit_FFmpegKitConfig |
||||
* Method: nativeFFmpegCancel |
||||
* Signature: (J)V |
||||
*/ |
||||
JNIEXPORT void JNICALL Java_com_arthenica_ffmpegkit_FFmpegKitConfig_nativeFFmpegCancel(JNIEnv *, jclass, jlong); |
||||
|
||||
/*
|
||||
* Class: com_arthenica_ffmpegkit_FFmpegKitConfig |
||||
* Method: registerNewNativeFFmpegPipe |
||||
* Signature: (Ljava/lang/String;)I |
||||
*/ |
||||
JNIEXPORT int JNICALL Java_com_arthenica_ffmpegkit_FFmpegKitConfig_registerNewNativeFFmpegPipe(JNIEnv *env, jclass object, jstring ffmpegPipePath); |
||||
|
||||
/*
|
||||
* Class: com_arthenica_ffmpegkit_FFmpegKitConfig |
||||
* Method: getNativeBuildDate |
||||
* Signature: ()Ljava/lang/String; |
||||
*/ |
||||
JNIEXPORT jstring JNICALL Java_com_arthenica_ffmpegkit_FFmpegKitConfig_getNativeBuildDate(JNIEnv *env, jclass object); |
||||
|
||||
/**
|
||||
* Class: com_arthenica_ffmpegkit_FFmpegKitConfig |
||||
* Method: setNativeEnvironmentVariable |
||||
* Signature: (Ljava/lang/String;Ljava/lang/String;)I |
||||
*/ |
||||
JNIEXPORT int JNICALL Java_com_arthenica_ffmpegkit_FFmpegKitConfig_setNativeEnvironmentVariable(JNIEnv *env, jclass object, jstring variableName, jstring variableValue); |
||||
|
||||
/*
|
||||
* Class: com_arthenica_ffmpegkit_FFmpegKitConfig |
||||
* Method: getNativeLastCommandOutput |
||||
* Signature: ()Ljava/lang/String; |
||||
*/ |
||||
JNIEXPORT jstring JNICALL Java_com_arthenica_ffmpegkit_FFmpegKitConfig_getNativeLastCommandOutput(JNIEnv *env, jclass object); |
||||
|
||||
/*
|
||||
* Class: com_arthenica_ffmpegkit_FFmpegKitConfig |
||||
* Method: ignoreNativeSignal |
||||
* Signature: (I)V |
||||
*/ |
||||
JNIEXPORT void JNICALL Java_com_arthenica_ffmpegkit_FFmpegKitConfig_ignoreNativeSignal(JNIEnv *env, jclass object, jint signum); |
||||
|
||||
#endif /* FFMPEG_KIT_H */ |
||||
@ -0,0 +1,144 @@ |
||||
/*
|
||||
* Copyright (c) 2018-2020 Taner Sener |
||||
* |
||||
* This file is part of FFmpegKit. |
||||
* |
||||
* FFmpegKit is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Lesser General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* FFmpegKit 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 Lesser General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General Public License |
||||
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#include "cpu-features.h" |
||||
#include "fftools_ffmpeg.h" |
||||
#include "ffmpegkit_abidetect.h" |
||||
|
||||
/** Full name of the Java class that owns native functions in this file. */ |
||||
const char *abiDetectClassName = "com/arthenica/ffmpegkit/AbiDetect"; |
||||
|
||||
/** Prototypes of native functions defined by this file. */ |
||||
JNINativeMethod abiDetectMethods[] = { |
||||
{"getNativeAbi", "()Ljava/lang/String;", (void*) Java_com_arthenica_ffmpegkit_AbiDetect_getNativeAbi}, |
||||
{"getNativeCpuAbi", "()Ljava/lang/String;", (void*) Java_com_arthenica_ffmpegkit_AbiDetect_getNativeCpuAbi}, |
||||
{"isNativeLTSBuild", "()Z", (void*) Java_com_arthenica_ffmpegkit_AbiDetect_isNativeLTSBuild}, |
||||
{"getNativeBuildConf", "()Ljava/lang/String;", (void*) Java_com_arthenica_ffmpegkit_AbiDetect_getNativeBuildConf} |
||||
}; |
||||
|
||||
/**
|
||||
* Called when 'abidetect' native library is loaded. |
||||
* |
||||
* @param vm pointer to the running virtual machine |
||||
* @param reserved reserved |
||||
* @return JNI version needed by 'abidetect' library |
||||
*/ |
||||
jint JNI_OnLoad(JavaVM *vm, void *reserved) { |
||||
JNIEnv *env; |
||||
if ((*vm)->GetEnv(vm, (void**) &env, JNI_VERSION_1_6) != JNI_OK) { |
||||
LOGE("OnLoad failed to GetEnv for class %s.\n", abiDetectClassName); |
||||
return JNI_FALSE; |
||||
} |
||||
|
||||
jclass abiDetectClass = (*env)->FindClass(env, abiDetectClassName); |
||||
if (abiDetectClass == NULL) { |
||||
LOGE("OnLoad failed to FindClass %s.\n", abiDetectClassName); |
||||
return JNI_FALSE; |
||||
} |
||||
|
||||
if ((*env)->RegisterNatives(env, abiDetectClass, abiDetectMethods, 4) < 0) { |
||||
LOGE("OnLoad failed to RegisterNatives for class %s.\n", abiDetectClassName); |
||||
return JNI_FALSE; |
||||
} |
||||
|
||||
return JNI_VERSION_1_6; |
||||
} |
||||
|
||||
/**
|
||||
* Returns loaded ABI name. |
||||
* |
||||
* @param env pointer to native method interface |
||||
* @param object reference to the class on which this method is invoked |
||||
* @return loaded ABI name as UTF string |
||||
*/ |
||||
JNIEXPORT jstring JNICALL Java_com_arthenica_ffmpegkit_AbiDetect_getNativeAbi(JNIEnv *env, jclass object) { |
||||
|
||||
#ifdef FFMPEG_KIT_ARM_V7A |
||||
return (*env)->NewStringUTF(env, "arm-v7a"); |
||||
#elif FFMPEG_KIT_ARM64_V8A |
||||
return (*env)->NewStringUTF(env, "arm64-v8a"); |
||||
#elif FFMPEG_KIT_X86 |
||||
return (*env)->NewStringUTF(env, "x86"); |
||||
#elif FFMPEG_KIT_X86_64 |
||||
return (*env)->NewStringUTF(env, "x86_64"); |
||||
#else |
||||
return (*env)->NewStringUTF(env, "unknown"); |
||||
#endif |
||||
|
||||
} |
||||
|
||||
/**
|
||||
* Returns ABI name of the running cpu. |
||||
* |
||||
* @param env pointer to native method interface |
||||
* @param object reference to the class on which this method is invoked |
||||
* @return ABI name of the running cpu as UTF string |
||||
*/ |
||||
JNIEXPORT jstring JNICALL Java_com_arthenica_ffmpegkit_AbiDetect_getNativeCpuAbi(JNIEnv *env, jclass object) { |
||||
AndroidCpuFamily family = android_getCpuFamily(); |
||||
|
||||
if (family == ANDROID_CPU_FAMILY_ARM) { |
||||
uint64_t features = android_getCpuFeatures(); |
||||
|
||||
if (features & ANDROID_CPU_ARM_FEATURE_ARMv7) { |
||||
if (features & ANDROID_CPU_ARM_FEATURE_NEON) { |
||||
return (*env)->NewStringUTF(env, ABI_ARMV7A_NEON); |
||||
} else { |
||||
return (*env)->NewStringUTF(env, ABI_ARMV7A); |
||||
} |
||||
} else { |
||||
return (*env)->NewStringUTF(env, ABI_ARM); |
||||
} |
||||
|
||||
} else if (family == ANDROID_CPU_FAMILY_ARM64) { |
||||
return (*env)->NewStringUTF(env, ABI_ARM64_V8A); |
||||
} else if (family == ANDROID_CPU_FAMILY_X86) { |
||||
return (*env)->NewStringUTF(env, ABI_X86); |
||||
} else if (family == ANDROID_CPU_FAMILY_X86_64) { |
||||
return (*env)->NewStringUTF(env, ABI_X86_64); |
||||
} else { |
||||
return (*env)->NewStringUTF(env, ABI_UNKNOWN); |
||||
} |
||||
} |
||||
|
||||
/**
|
||||
* Returns whether FFmpegKit release is a long term release or not. |
||||
* |
||||
* @param env pointer to native method interface |
||||
* @param object reference to the class on which this method is invoked |
||||
* @return yes or no |
||||
*/ |
||||
JNIEXPORT jboolean JNICALL Java_com_arthenica_ffmpegkit_AbiDetect_isNativeLTSBuild(JNIEnv *env, jclass object) { |
||||
#if defined(FFMPEG_KIT_LTS) |
||||
return JNI_TRUE; |
||||
#else |
||||
return JNI_FALSE; |
||||
#endif |
||||
} |
||||
|
||||
/**
|
||||
* Returns build configuration for FFmpeg. |
||||
* |
||||
* @param env pointer to native method interface |
||||
* @param object reference to the class on which this method is invoked |
||||
* @return build configuration string |
||||
*/ |
||||
JNIEXPORT jstring JNICALL Java_com_arthenica_ffmpegkit_AbiDetect_getNativeBuildConf(JNIEnv *env, jclass object) { |
||||
return (*env)->NewStringUTF(env, FFMPEG_CONFIGURATION); |
||||
} |
||||
@ -0,0 +1,75 @@ |
||||
/*
|
||||
* Copyright (c) 2018-2020 Taner Sener |
||||
* |
||||
* This file is part of FFmpegKit. |
||||
* |
||||
* FFmpegKit is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Lesser General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* FFmpegKit 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 Lesser General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General Public License |
||||
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#ifndef FFMPEG_KIT_ABIDETECT_H |
||||
#define FFMPEG_KIT_ABIDETECT_H |
||||
|
||||
#include <jni.h> |
||||
#include "ffmpegkit.h" |
||||
|
||||
/** Represents armeabi-v7a ABI with NEON support. */ |
||||
#define ABI_ARMV7A_NEON "armeabi-v7a-neon" |
||||
|
||||
/** Represents armeabi-v7a ABI. */ |
||||
#define ABI_ARMV7A "armeabi-v7a" |
||||
|
||||
/** Represents armeabi ABI. */ |
||||
#define ABI_ARM "armeabi" |
||||
|
||||
/** Represents x86 ABI. */ |
||||
#define ABI_X86 "x86" |
||||
|
||||
/** Represents x86_64 ABI. */ |
||||
#define ABI_X86_64 "x86_64" |
||||
|
||||
/** Represents arm64-v8a ABI. */ |
||||
#define ABI_ARM64_V8A "arm64-v8a" |
||||
|
||||
/** Represents not supported ABIs. */ |
||||
#define ABI_UNKNOWN "unknown" |
||||
|
||||
/*
|
||||
* Class: com_arthenica_ffmpegkit_AbiDetect |
||||
* Method: getNativeAbi |
||||
* Signature: ()Ljava/lang/String; |
||||
*/ |
||||
JNIEXPORT jstring JNICALL Java_com_arthenica_ffmpegkit_AbiDetect_getNativeAbi(JNIEnv *, jclass); |
||||
|
||||
/*
|
||||
* Class: com_arthenica_ffmpegkit_AbiDetect |
||||
* Method: getNativeCpuAbi |
||||
* Signature: ()Ljava/lang/String; |
||||
*/ |
||||
JNIEXPORT jstring JNICALL Java_com_arthenica_ffmpegkit_AbiDetect_getNativeCpuAbi(JNIEnv *, jclass); |
||||
|
||||
/**
|
||||
* Class: com_arthenica_ffmpegkit_AbiDetect |
||||
* Method: isNativeLTSBuild |
||||
* Signature: ()Z |
||||
*/ |
||||
JNIEXPORT jboolean JNICALL Java_com_arthenica_ffmpegkit_AbiDetect_isNativeLTSBuild(JNIEnv *, jclass); |
||||
|
||||
/*
|
||||
* Class: com_arthenica_ffmpegkit_AbiDetect |
||||
* Method: getNativeBuildConf |
||||
* Signature: ()Ljava/lang/String; |
||||
*/ |
||||
JNIEXPORT jstring JNICALL Java_com_arthenica_ffmpegkit_AbiDetect_getNativeBuildConf(JNIEnv *, jclass); |
||||
|
||||
#endif /* FFMPEG_KIT_ABIDETECT_H */ |
||||
@ -0,0 +1,24 @@ |
||||
/*
|
||||
* Copyright (c) 2018-2020 Taner Sener |
||||
* |
||||
* This file is part of FFmpegKit. |
||||
* |
||||
* FFmpegKit is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Lesser General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* FFmpegKit 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 Lesser General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General Public License |
||||
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#include <stdio.h> |
||||
#include <setjmp.h> |
||||
|
||||
/** Holds information to implement exception handling. */ |
||||
__thread jmp_buf ex_buf__; |
||||
@ -0,0 +1,29 @@ |
||||
/*
|
||||
* Copyright (c) 2018-2020 Taner Sener |
||||
* |
||||
* This file is part of FFmpegKit. |
||||
* |
||||
* FFmpegKit is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Lesser General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* FFmpegKit 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 Lesser General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General Public License |
||||
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#ifndef FFMPEG_KIT_EXCEPTION_H |
||||
#define FFMPEG_KIT_EXCEPTION_H |
||||
|
||||
#include <stdio.h> |
||||
#include <setjmp.h> |
||||
|
||||
/** Holds information to implement exception handling. */ |
||||
extern __thread jmp_buf ex_buf__; |
||||
|
||||
#endif // FFMPEG_KIT_EXCEPTION_H
|
||||
@ -0,0 +1,96 @@ |
||||
/*
|
||||
* Copyright (c) 2020 Taner Sener |
||||
* |
||||
* This file is part of FFmpegKit. |
||||
* |
||||
* FFmpegKit is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Lesser General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* FFmpegKit 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 Lesser General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General Public License |
||||
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#include <pthread.h> |
||||
#include <sys/types.h> |
||||
#include <sys/stat.h> |
||||
|
||||
#include "config.h" |
||||
#include "libavcodec/jni.h" |
||||
#include "libavutil/bprint.h" |
||||
#include "ffmpegkit.h" |
||||
|
||||
/** Forward declaration for function defined in fftools_ffprobe.c */ |
||||
int ffprobe_execute(int argc, char **argv); |
||||
|
||||
/** Forward declaration for function defined in ffmpegkit.c */ |
||||
void clearLastCommandOutput(); |
||||
|
||||
extern int configuredLogLevel; |
||||
|
||||
/**
|
||||
* Synchronously executes FFprobe natively with arguments provided. |
||||
* |
||||
* @param env pointer to native method interface |
||||
* @param object reference to the class on which this method is invoked |
||||
* @param stringArray reference to the object holding FFprobe command arguments |
||||
* @return zero on successful execution, non-zero on error |
||||
*/ |
||||
JNIEXPORT jint JNICALL Java_com_arthenica_ffmpegkit_FFmpegKitConfig_nativeFFprobeExecute(JNIEnv *env, jclass object, jobjectArray stringArray) { |
||||
jstring *tempArray = NULL; |
||||
int argumentCount = 1; |
||||
char **argv = NULL; |
||||
|
||||
// SETS DEFAULT LOG LEVEL BEFORE STARTING A NEW EXECUTION
|
||||
av_log_set_level(configuredLogLevel); |
||||
|
||||
if (stringArray != NULL) { |
||||
int programArgumentCount = (*env)->GetArrayLength(env, stringArray); |
||||
argumentCount = programArgumentCount + 1; |
||||
|
||||
tempArray = (jstring *) av_malloc(sizeof(jstring) * programArgumentCount); |
||||
} |
||||
|
||||
/* PRESERVE USAGE FORMAT
|
||||
* |
||||
* ffprobe <arguments> |
||||
*/ |
||||
argv = (char **)av_malloc(sizeof(char*) * (argumentCount)); |
||||
argv[0] = (char *)av_malloc(sizeof(char) * (strlen(LIB_NAME) + 1)); |
||||
strcpy(argv[0], LIB_NAME); |
||||
|
||||
// PREPARE
|
||||
if (stringArray != NULL) { |
||||
for (int i = 0; i < (argumentCount - 1); i++) { |
||||
tempArray[i] = (jstring) (*env)->GetObjectArrayElement(env, stringArray, i); |
||||
if (tempArray[i] != NULL) { |
||||
argv[i + 1] = (char *) (*env)->GetStringUTFChars(env, tempArray[i], 0); |
||||
} |
||||
} |
||||
} |
||||
|
||||
// LAST COMMAND OUTPUT SHOULD BE CLEARED BEFORE STARTING A NEW EXECUTION
|
||||
clearLastCommandOutput(); |
||||
|
||||
// RUN
|
||||
int retCode = ffprobe_execute(argumentCount, argv); |
||||
|
||||
// CLEANUP
|
||||
if (tempArray != NULL) { |
||||
for (int i = 0; i < (argumentCount - 1); i++) { |
||||
(*env)->ReleaseStringUTFChars(env, tempArray[i], argv[i + 1]); |
||||
} |
||||
|
||||
av_free(tempArray); |
||||
} |
||||
av_free(argv[0]); |
||||
av_free(argv); |
||||
|
||||
return retCode; |
||||
} |
||||
@ -0,0 +1,32 @@ |
||||
/*
|
||||
* Copyright (c) 2020 Taner Sener |
||||
* |
||||
* This file is part of FFmpegKit. |
||||
* |
||||
* FFmpegKit is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Lesser General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* FFmpegKit 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 Lesser General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General Public License |
||||
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#ifndef FFPROBE_KIT_H |
||||
#define FFPROBE_KIT_H |
||||
|
||||
#include <jni.h> |
||||
|
||||
/*
|
||||
* Class: com_arthenica_ffmpegkit_FFmpegKitConfig |
||||
* Method: nativeFFprobeExecute |
||||
* Signature: ([Ljava/lang/String;)I |
||||
*/ |
||||
JNIEXPORT jint JNICALL Java_com_arthenica_ffmpegkit_FFmpegKitConfig_nativeFFprobeExecute(JNIEnv *, jclass, jobjectArray); |
||||
|
||||
#endif /* FFPROBE_KIT_H */ |
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,636 @@ |
||||
/*
|
||||
* Various utilities for command line tools |
||||
* copyright (c) 2003 Fabrice Bellard |
||||
* |
||||
* This file is part of FFmpeg. |
||||
* |
||||
* FFmpeg is free software; you can redistribute it and/or |
||||
* modify it under the terms of the GNU Lesser General Public |
||||
* License as published by the Free Software Foundation; either |
||||
* version 2.1 of the License, or (at your option) any later version. |
||||
* |
||||
* FFmpeg 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 |
||||
* Lesser General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General Public |
||||
* License along with FFmpeg; if not, write to the Free Software |
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
*/ |
||||
|
||||
/*
|
||||
* CHANGES 01.2020 |
||||
* - ffprobe support changes |
||||
* - AV_LOG_STDERR introduced |
||||
* |
||||
* CHANGES 12.2019 |
||||
* - Concurrent execution support |
||||
* |
||||
* CHANGES 03.2019 |
||||
* -------------------------------------------------------- |
||||
* - config.h include removed |
||||
* |
||||
* CHANGES 08.2018 |
||||
* -------------------------------------------------------- |
||||
* - fftools_ prefix added to file name and include guards |
||||
* |
||||
* CHANGES 07.2018 |
||||
* -------------------------------------------------------- |
||||
* - Include guards renamed |
||||
* - Unused headers removed |
||||
*/ |
||||
|
||||
#ifndef FFTOOLS_CMDUTILS_H |
||||
#define FFTOOLS_CMDUTILS_H |
||||
|
||||
#include <stdint.h> |
||||
|
||||
#include "libavcodec/avcodec.h" |
||||
#include "libavfilter/avfilter.h" |
||||
#include "libavformat/avformat.h" |
||||
#include "libswscale/swscale.h" |
||||
|
||||
#ifdef _WIN32 |
||||
#undef main /* We don't want SDL to override our main() */ |
||||
#endif |
||||
|
||||
/**
|
||||
* Defines logs printed to stderr by ffmpeg. They are not filtered and always redirected. |
||||
*/ |
||||
#define AV_LOG_STDERR -16 |
||||
|
||||
/**
|
||||
* program name, defined by the program for show_version(). |
||||
*/ |
||||
extern __thread char *program_name; |
||||
|
||||
/**
|
||||
* program birth year, defined by the program for show_banner() |
||||
*/ |
||||
extern __thread int program_birth_year; |
||||
|
||||
extern __thread AVCodecContext *avcodec_opts[AVMEDIA_TYPE_NB]; |
||||
extern __thread AVFormatContext *avformat_opts; |
||||
extern __thread AVDictionary *sws_dict; |
||||
extern __thread AVDictionary *swr_opts; |
||||
extern __thread AVDictionary *format_opts, *codec_opts, *resample_opts; |
||||
extern __thread int hide_banner; |
||||
extern __thread int find_stream_info; |
||||
|
||||
/**
|
||||
* Register a program-specific cleanup routine. |
||||
*/ |
||||
void register_exit(void (*cb)(int ret)); |
||||
|
||||
/**
|
||||
* Wraps exit with a program-specific cleanup routine. |
||||
*/ |
||||
void exit_program(int ret) av_noreturn; |
||||
|
||||
/**
|
||||
* Initialize dynamic library loading |
||||
*/ |
||||
void init_dynload(void); |
||||
|
||||
/**
|
||||
* Initialize the cmdutils option system, in particular |
||||
* allocate the *_opts contexts. |
||||
*/ |
||||
void init_opts(void); |
||||
/**
|
||||
* Uninitialize the cmdutils option system, in particular |
||||
* free the *_opts contexts and their contents. |
||||
*/ |
||||
void uninit_opts(void); |
||||
|
||||
/**
|
||||
* Trivial log callback. |
||||
* Only suitable for opt_help and similar since it lacks prefix handling. |
||||
*/ |
||||
void log_callback_help(void* ptr, int level, const char* fmt, va_list vl); |
||||
|
||||
/**
|
||||
* Override the cpuflags. |
||||
*/ |
||||
int opt_cpuflags(void *optctx, const char *opt, const char *arg); |
||||
|
||||
/**
|
||||
* Fallback for options that are not explicitly handled, these will be |
||||
* parsed through AVOptions. |
||||
*/ |
||||
int opt_default(void *optctx, const char *opt, const char *arg); |
||||
|
||||
/**
|
||||
* Set the libav* libraries log level. |
||||
*/ |
||||
int opt_loglevel(void *optctx, const char *opt, const char *arg); |
||||
|
||||
int opt_report(void *optctx, const char *opt, const char *arg); |
||||
|
||||
int opt_max_alloc(void *optctx, const char *opt, const char *arg); |
||||
|
||||
int opt_codec_debug(void *optctx, const char *opt, const char *arg); |
||||
|
||||
/**
|
||||
* Limit the execution time. |
||||
*/ |
||||
int opt_timelimit(void *optctx, const char *opt, const char *arg); |
||||
|
||||
/**
|
||||
* Parse a string and return its corresponding value as a double. |
||||
* Exit from the application if the string cannot be correctly |
||||
* parsed or the corresponding value is invalid. |
||||
* |
||||
* @param context the context of the value to be set (e.g. the |
||||
* corresponding command line option name) |
||||
* @param numstr the string to be parsed |
||||
* @param type the type (OPT_INT64 or OPT_FLOAT) as which the |
||||
* string should be parsed |
||||
* @param min the minimum valid accepted value |
||||
* @param max the maximum valid accepted value |
||||
*/ |
||||
double parse_number_or_die(const char *context, const char *numstr, int type, |
||||
double min, double max); |
||||
|
||||
/**
|
||||
* Parse a string specifying a time and return its corresponding |
||||
* value as a number of microseconds. Exit from the application if |
||||
* the string cannot be correctly parsed. |
||||
* |
||||
* @param context the context of the value to be set (e.g. the |
||||
* corresponding command line option name) |
||||
* @param timestr the string to be parsed |
||||
* @param is_duration a flag which tells how to interpret timestr, if |
||||
* not zero timestr is interpreted as a duration, otherwise as a |
||||
* date |
||||
* |
||||
* @see av_parse_time() |
||||
*/ |
||||
int64_t parse_time_or_die(const char *context, const char *timestr, |
||||
int is_duration); |
||||
|
||||
typedef struct SpecifierOpt { |
||||
char *specifier; /**< stream/chapter/program/... specifier */ |
||||
union { |
||||
uint8_t *str; |
||||
int i; |
||||
int64_t i64; |
||||
uint64_t ui64; |
||||
float f; |
||||
double dbl; |
||||
} u; |
||||
} SpecifierOpt; |
||||
|
||||
typedef struct OptionDef { |
||||
const char *name; |
||||
int flags; |
||||
#define HAS_ARG 0x0001 |
||||
#define OPT_BOOL 0x0002 |
||||
#define OPT_EXPERT 0x0004 |
||||
#define OPT_STRING 0x0008 |
||||
#define OPT_VIDEO 0x0010 |
||||
#define OPT_AUDIO 0x0020 |
||||
#define OPT_INT 0x0080 |
||||
#define OPT_FLOAT 0x0100 |
||||
#define OPT_SUBTITLE 0x0200 |
||||
#define OPT_INT64 0x0400 |
||||
#define OPT_EXIT 0x0800 |
||||
#define OPT_DATA 0x1000 |
||||
#define OPT_PERFILE 0x2000 /* the option is per-file (currently ffmpeg-only). |
||||
implied by OPT_OFFSET or OPT_SPEC */ |
||||
#define OPT_OFFSET 0x4000 /* option is specified as an offset in a passed optctx */ |
||||
#define OPT_SPEC 0x8000 /* option is to be stored in an array of SpecifierOpt. |
||||
Implies OPT_OFFSET. Next element after the offset is |
||||
an int containing element count in the array. */ |
||||
#define OPT_TIME 0x10000 |
||||
#define OPT_DOUBLE 0x20000 |
||||
#define OPT_INPUT 0x40000 |
||||
#define OPT_OUTPUT 0x80000 |
||||
union { |
||||
void *dst_ptr; |
||||
int (*func_arg)(void *, const char *, const char *); |
||||
size_t off; |
||||
} u; |
||||
const char *help; |
||||
const char *argname; |
||||
} OptionDef; |
||||
|
||||
/**
|
||||
* Print help for all options matching specified flags. |
||||
* |
||||
* @param options a list of options |
||||
* @param msg title of this group. Only printed if at least one option matches. |
||||
* @param req_flags print only options which have all those flags set. |
||||
* @param rej_flags don't print options which have any of those flags set. |
||||
* @param alt_flags print only options that have at least one of those flags set |
||||
*/ |
||||
void show_help_options(const OptionDef *options, const char *msg, int req_flags, |
||||
int rej_flags, int alt_flags); |
||||
|
||||
/**
|
||||
* Show help for all options with given flags in class and all its |
||||
* children. |
||||
*/ |
||||
void show_help_children(const AVClass *class, int flags); |
||||
|
||||
/**
|
||||
* Per-fftool specific help handlers. Implemented in each |
||||
* fftool, called by show_help(). |
||||
*/ |
||||
void show_help_default_ffmpeg(const char *opt, const char *arg); |
||||
void show_help_default_ffprobe(const char *opt, const char *arg); |
||||
|
||||
/**
|
||||
* Generic -h handler common to all fftools. |
||||
*/ |
||||
int show_help(void *optctx, const char *opt, const char *arg); |
||||
|
||||
/**
|
||||
* Parse the command line arguments. |
||||
* |
||||
* @param optctx an opaque options context |
||||
* @param argc number of command line arguments |
||||
* @param argv values of command line arguments |
||||
* @param options Array with the definitions required to interpret every |
||||
* option of the form: -option_name [argument] |
||||
* @param parse_arg_function Name of the function called to process every |
||||
* argument without a leading option name flag. NULL if such arguments do |
||||
* not have to be processed. |
||||
*/ |
||||
void parse_options(void *optctx, int argc, char **argv, const OptionDef *options, |
||||
void (* parse_arg_function)(void *optctx, const char*)); |
||||
|
||||
/**
|
||||
* Parse one given option. |
||||
* |
||||
* @return on success 1 if arg was consumed, 0 otherwise; negative number on error |
||||
*/ |
||||
int parse_option(void *optctx, const char *opt, const char *arg, |
||||
const OptionDef *options); |
||||
|
||||
/**
|
||||
* An option extracted from the commandline. |
||||
* Cannot use AVDictionary because of options like -map which can be |
||||
* used multiple times. |
||||
*/ |
||||
typedef struct Option { |
||||
const OptionDef *opt; |
||||
const char *key; |
||||
const char *val; |
||||
} Option; |
||||
|
||||
typedef struct OptionGroupDef { |
||||
/**< group name */ |
||||
const char *name; |
||||
/**
|
||||
* Option to be used as group separator. Can be NULL for groups which |
||||
* are terminated by a non-option argument (e.g. ffmpeg output files) |
||||
*/ |
||||
const char *sep; |
||||
/**
|
||||
* Option flags that must be set on each option that is |
||||
* applied to this group |
||||
*/ |
||||
int flags; |
||||
} OptionGroupDef; |
||||
|
||||
typedef struct OptionGroup { |
||||
const OptionGroupDef *group_def; |
||||
const char *arg; |
||||
|
||||
Option *opts; |
||||
int nb_opts; |
||||
|
||||
AVDictionary *codec_opts; |
||||
AVDictionary *format_opts; |
||||
AVDictionary *resample_opts; |
||||
AVDictionary *sws_dict; |
||||
AVDictionary *swr_opts; |
||||
} OptionGroup; |
||||
|
||||
/**
|
||||
* A list of option groups that all have the same group type |
||||
* (e.g. input files or output files) |
||||
*/ |
||||
typedef struct OptionGroupList { |
||||
const OptionGroupDef *group_def; |
||||
|
||||
OptionGroup *groups; |
||||
int nb_groups; |
||||
} OptionGroupList; |
||||
|
||||
typedef struct OptionParseContext { |
||||
OptionGroup global_opts; |
||||
|
||||
OptionGroupList *groups; |
||||
int nb_groups; |
||||
|
||||
/* parsing state */ |
||||
OptionGroup cur_group; |
||||
} OptionParseContext; |
||||
|
||||
/**
|
||||
* Parse an options group and write results into optctx. |
||||
* |
||||
* @param optctx an app-specific options context. NULL for global options group |
||||
* @param g option group |
||||
*/ |
||||
int parse_optgroup(void *optctx, OptionGroup *g); |
||||
|
||||
/**
|
||||
* Split the commandline into an intermediate form convenient for further |
||||
* processing. |
||||
* |
||||
* The commandline is assumed to be composed of options which either belong to a |
||||
* group (those with OPT_SPEC, OPT_OFFSET or OPT_PERFILE) or are global |
||||
* (everything else). |
||||
* |
||||
* A group (defined by an OptionGroupDef struct) is a sequence of options |
||||
* terminated by either a group separator option (e.g. -i) or a parameter that |
||||
* is not an option (doesn't start with -). A group without a separator option |
||||
* must always be first in the supplied groups list. |
||||
* |
||||
* All options within the same group are stored in one OptionGroup struct in an |
||||
* OptionGroupList, all groups with the same group definition are stored in one |
||||
* OptionGroupList in OptionParseContext.groups. The order of group lists is the |
||||
* same as the order of group definitions. |
||||
*/ |
||||
int split_commandline(OptionParseContext *octx, int argc, char *argv[], |
||||
const OptionDef *options, |
||||
const OptionGroupDef *groups, int nb_groups); |
||||
|
||||
/**
|
||||
* Free all allocated memory in an OptionParseContext. |
||||
*/ |
||||
void uninit_parse_context(OptionParseContext *octx); |
||||
|
||||
/**
|
||||
* Find the '-loglevel' option in the command line args and apply it. |
||||
*/ |
||||
void parse_loglevel(int argc, char **argv, const OptionDef *options); |
||||
|
||||
/**
|
||||
* Return index of option opt in argv or 0 if not found. |
||||
*/ |
||||
int locate_option(int argc, char **argv, const OptionDef *options, |
||||
const char *optname); |
||||
|
||||
/**
|
||||
* Check if the given stream matches a stream specifier. |
||||
* |
||||
* @param s Corresponding format context. |
||||
* @param st Stream from s to be checked. |
||||
* @param spec A stream specifier of the [v|a|s|d]:[\<stream index\>] form. |
||||
* |
||||
* @return 1 if the stream matches, 0 if it doesn't, <0 on error |
||||
*/ |
||||
int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec); |
||||
|
||||
/**
|
||||
* Filter out options for given codec. |
||||
* |
||||
* Create a new options dictionary containing only the options from |
||||
* opts which apply to the codec with ID codec_id. |
||||
* |
||||
* @param opts dictionary to place options in |
||||
* @param codec_id ID of the codec that should be filtered for |
||||
* @param s Corresponding format context. |
||||
* @param st A stream from s for which the options should be filtered. |
||||
* @param codec The particular codec for which the options should be filtered. |
||||
* If null, the default one is looked up according to the codec id. |
||||
* @return a pointer to the created dictionary |
||||
*/ |
||||
AVDictionary *filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id, |
||||
AVFormatContext *s, AVStream *st, AVCodec *codec); |
||||
|
||||
/**
|
||||
* Setup AVCodecContext options for avformat_find_stream_info(). |
||||
* |
||||
* Create an array of dictionaries, one dictionary for each stream |
||||
* contained in s. |
||||
* Each dictionary will contain the options from codec_opts which can |
||||
* be applied to the corresponding stream codec context. |
||||
* |
||||
* @return pointer to the created array of dictionaries, NULL if it |
||||
* cannot be created |
||||
*/ |
||||
AVDictionary **setup_find_stream_info_opts(AVFormatContext *s, |
||||
AVDictionary *codec_opts); |
||||
|
||||
/**
|
||||
* Print an error message to stderr, indicating filename and a human |
||||
* readable description of the error code err. |
||||
* |
||||
* If strerror_r() is not available the use of this function in a |
||||
* multithreaded application may be unsafe. |
||||
* |
||||
* @see av_strerror() |
||||
*/ |
||||
void print_error(const char *filename, int err); |
||||
|
||||
/**
|
||||
* Print the program banner to stderr. The banner contents depend on the |
||||
* current version of the repository and of the libav* libraries used by |
||||
* the program. |
||||
*/ |
||||
void show_banner(int argc, char **argv, const OptionDef *options); |
||||
|
||||
/**
|
||||
* Print the version of the program to stdout. The version message |
||||
* depends on the current versions of the repository and of the libav* |
||||
* libraries. |
||||
* This option processing function does not utilize the arguments. |
||||
*/ |
||||
int show_version(void *optctx, const char *opt, const char *arg); |
||||
|
||||
/**
|
||||
* Print the build configuration of the program to stdout. The contents |
||||
* depend on the definition of FFMPEG_CONFIGURATION. |
||||
* This option processing function does not utilize the arguments. |
||||
*/ |
||||
int show_buildconf(void *optctx, const char *opt, const char *arg); |
||||
|
||||
/**
|
||||
* Print the license of the program to stdout. The license depends on |
||||
* the license of the libraries compiled into the program. |
||||
* This option processing function does not utilize the arguments. |
||||
*/ |
||||
int show_license(void *optctx, const char *opt, const char *arg); |
||||
|
||||
/**
|
||||
* Print a listing containing all the formats supported by the |
||||
* program (including devices). |
||||
* This option processing function does not utilize the arguments. |
||||
*/ |
||||
int show_formats(void *optctx, const char *opt, const char *arg); |
||||
|
||||
/**
|
||||
* Print a listing containing all the muxers supported by the |
||||
* program (including devices). |
||||
* This option processing function does not utilize the arguments. |
||||
*/ |
||||
int show_muxers(void *optctx, const char *opt, const char *arg); |
||||
|
||||
/**
|
||||
* Print a listing containing all the demuxer supported by the |
||||
* program (including devices). |
||||
* This option processing function does not utilize the arguments. |
||||
*/ |
||||
int show_demuxers(void *optctx, const char *opt, const char *arg); |
||||
|
||||
/**
|
||||
* Print a listing containing all the devices supported by the |
||||
* program. |
||||
* This option processing function does not utilize the arguments. |
||||
*/ |
||||
int show_devices(void *optctx, const char *opt, const char *arg); |
||||
|
||||
#if CONFIG_AVDEVICE |
||||
/**
|
||||
* Print a listing containing autodetected sinks of the output device. |
||||
* Device name with options may be passed as an argument to limit results. |
||||
*/ |
||||
int show_sinks(void *optctx, const char *opt, const char *arg); |
||||
|
||||
/**
|
||||
* Print a listing containing autodetected sources of the input device. |
||||
* Device name with options may be passed as an argument to limit results. |
||||
*/ |
||||
int show_sources(void *optctx, const char *opt, const char *arg); |
||||
#endif |
||||
|
||||
/**
|
||||
* Print a listing containing all the codecs supported by the |
||||
* program. |
||||
* This option processing function does not utilize the arguments. |
||||
*/ |
||||
int show_codecs(void *optctx, const char *opt, const char *arg); |
||||
|
||||
/**
|
||||
* Print a listing containing all the decoders supported by the |
||||
* program. |
||||
*/ |
||||
int show_decoders(void *optctx, const char *opt, const char *arg); |
||||
|
||||
/**
|
||||
* Print a listing containing all the encoders supported by the |
||||
* program. |
||||
*/ |
||||
int show_encoders(void *optctx, const char *opt, const char *arg); |
||||
|
||||
/**
|
||||
* Print a listing containing all the filters supported by the |
||||
* program. |
||||
* This option processing function does not utilize the arguments. |
||||
*/ |
||||
int show_filters(void *optctx, const char *opt, const char *arg); |
||||
|
||||
/**
|
||||
* Print a listing containing all the bit stream filters supported by the |
||||
* program. |
||||
* This option processing function does not utilize the arguments. |
||||
*/ |
||||
int show_bsfs(void *optctx, const char *opt, const char *arg); |
||||
|
||||
/**
|
||||
* Print a listing containing all the protocols supported by the |
||||
* program. |
||||
* This option processing function does not utilize the arguments. |
||||
*/ |
||||
int show_protocols(void *optctx, const char *opt, const char *arg); |
||||
|
||||
/**
|
||||
* Print a listing containing all the pixel formats supported by the |
||||
* program. |
||||
* This option processing function does not utilize the arguments. |
||||
*/ |
||||
int show_pix_fmts(void *optctx, const char *opt, const char *arg); |
||||
|
||||
/**
|
||||
* Print a listing containing all the standard channel layouts supported by |
||||
* the program. |
||||
* This option processing function does not utilize the arguments. |
||||
*/ |
||||
int show_layouts(void *optctx, const char *opt, const char *arg); |
||||
|
||||
/**
|
||||
* Print a listing containing all the sample formats supported by the |
||||
* program. |
||||
*/ |
||||
int show_sample_fmts(void *optctx, const char *opt, const char *arg); |
||||
|
||||
/**
|
||||
* Print a listing containing all the color names and values recognized |
||||
* by the program. |
||||
*/ |
||||
int show_colors(void *optctx, const char *opt, const char *arg); |
||||
|
||||
/**
|
||||
* Return a positive value if a line read from standard input |
||||
* starts with [yY], otherwise return 0. |
||||
*/ |
||||
int read_yesno(void); |
||||
|
||||
/**
|
||||
* Get a file corresponding to a preset file. |
||||
* |
||||
* If is_path is non-zero, look for the file in the path preset_name. |
||||
* Otherwise search for a file named arg.ffpreset in the directories |
||||
* $FFMPEG_DATADIR (if set), $HOME/.ffmpeg, and in the datadir defined |
||||
* at configuration time or in a "ffpresets" folder along the executable |
||||
* on win32, in that order. If no such file is found and |
||||
* codec_name is defined, then search for a file named |
||||
* codec_name-preset_name.avpreset in the above-mentioned directories. |
||||
* |
||||
* @param filename buffer where the name of the found filename is written |
||||
* @param filename_size size in bytes of the filename buffer |
||||
* @param preset_name name of the preset to search |
||||
* @param is_path tell if preset_name is a filename path |
||||
* @param codec_name name of the codec for which to look for the |
||||
* preset, may be NULL |
||||
*/ |
||||
FILE *get_preset_file(char *filename, size_t filename_size, |
||||
const char *preset_name, int is_path, const char *codec_name); |
||||
|
||||
/**
|
||||
* Realloc array to hold new_size elements of elem_size. |
||||
* Calls exit() on failure. |
||||
* |
||||
* @param array array to reallocate |
||||
* @param elem_size size in bytes of each element |
||||
* @param size new element count will be written here |
||||
* @param new_size number of elements to place in reallocated array |
||||
* @return reallocated array |
||||
*/ |
||||
void *grow_array(void *array, int elem_size, int *size, int new_size); |
||||
|
||||
#define media_type_string av_get_media_type_string |
||||
|
||||
#define GROW_ARRAY(array, nb_elems)\ |
||||
array = grow_array(array, sizeof(*array), &nb_elems, nb_elems + 1) |
||||
|
||||
#define GET_PIX_FMT_NAME(pix_fmt)\ |
||||
const char *name = av_get_pix_fmt_name(pix_fmt); |
||||
|
||||
#define GET_CODEC_NAME(id)\ |
||||
const char *name = avcodec_descriptor_get(id)->name; |
||||
|
||||
#define GET_SAMPLE_FMT_NAME(sample_fmt)\ |
||||
const char *name = av_get_sample_fmt_name(sample_fmt) |
||||
|
||||
#define GET_SAMPLE_RATE_NAME(rate)\ |
||||
char name[16];\
|
||||
snprintf(name, sizeof(name), "%d", rate); |
||||
|
||||
#define GET_CH_LAYOUT_NAME(ch_layout)\ |
||||
char name[16];\
|
||||
snprintf(name, sizeof(name), "0x%"PRIx64, ch_layout); |
||||
|
||||
#define GET_CH_LAYOUT_DESC(ch_layout)\ |
||||
char name[128];\
|
||||
av_get_channel_layout_string(name, sizeof(name), 0, ch_layout); |
||||
|
||||
double get_rotation(AVStream *st); |
||||
|
||||
#endif /* FFTOOLS_CMDUTILS_H */ |
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,764 @@ |
||||
/*
|
||||
* This file is part of FFmpeg. |
||||
* |
||||
* FFmpeg is free software; you can redistribute it and/or |
||||
* modify it under the terms of the GNU Lesser General Public |
||||
* License as published by the Free Software Foundation; either |
||||
* version 2.1 of the License, or (at your option) any later version. |
||||
* |
||||
* FFmpeg 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 |
||||
* Lesser General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General Public |
||||
* License along with FFmpeg; if not, write to the Free Software |
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
*/ |
||||
|
||||
/*
|
||||
* CHANGES 06.2020 |
||||
* - cancel_operation() method signature updated with id |
||||
* |
||||
* CHANGES 01.2020 |
||||
* - ffprobe support changes |
||||
* |
||||
* CHANGES 12.2019 |
||||
* - Concurrent execution support |
||||
* |
||||
* CHANGES 03.2019 |
||||
* -------------------------------------------------------- |
||||
* - config.h include removed |
||||
* |
||||
* CHANGES 08.2018 |
||||
* -------------------------------------------------------- |
||||
* - fftools_ prefix added to file name and include guards |
||||
* - set_report_callback() method declared |
||||
* - cancel_operation() method declared |
||||
* |
||||
* CHANGES 07.2018 |
||||
* -------------------------------------------------------- |
||||
* - Include guards renamed |
||||
*/ |
||||
|
||||
#ifndef FFTOOLS_FFMPEG_H |
||||
#define FFTOOLS_FFMPEG_H |
||||
|
||||
#include <stdint.h> |
||||
#include <stdio.h> |
||||
#include <signal.h> |
||||
|
||||
#include "fftools_cmdutils.h" |
||||
|
||||
#include "libavformat/avformat.h" |
||||
#include "libavformat/avio.h" |
||||
|
||||
#include "libavcodec/avcodec.h" |
||||
|
||||
#include "libavfilter/avfilter.h" |
||||
|
||||
#include "libavutil/avutil.h" |
||||
#include "libavutil/dict.h" |
||||
#include "libavutil/eval.h" |
||||
#include "libavutil/fifo.h" |
||||
#include "libavutil/hwcontext.h" |
||||
#include "libavutil/pixfmt.h" |
||||
#include "libavutil/rational.h" |
||||
#include "libavutil/thread.h" |
||||
#include "libavutil/threadmessage.h" |
||||
|
||||
#include "libswresample/swresample.h" |
||||
|
||||
#define VSYNC_AUTO -1 |
||||
#define VSYNC_PASSTHROUGH 0 |
||||
#define VSYNC_CFR 1 |
||||
#define VSYNC_VFR 2 |
||||
#define VSYNC_VSCFR 0xfe |
||||
#define VSYNC_DROP 0xff |
||||
|
||||
#define MAX_STREAMS 1024 /* arbitrary sanity check value */ |
||||
|
||||
enum HWAccelID { |
||||
HWACCEL_NONE = 0, |
||||
HWACCEL_AUTO, |
||||
HWACCEL_GENERIC, |
||||
HWACCEL_VIDEOTOOLBOX, |
||||
HWACCEL_QSV, |
||||
HWACCEL_CUVID, |
||||
}; |
||||
|
||||
typedef struct HWAccel { |
||||
const char *name; |
||||
int (*init)(AVCodecContext *s); |
||||
enum HWAccelID id; |
||||
enum AVPixelFormat pix_fmt; |
||||
} HWAccel; |
||||
|
||||
typedef struct HWDevice { |
||||
const char *name; |
||||
enum AVHWDeviceType type; |
||||
AVBufferRef *device_ref; |
||||
} HWDevice; |
||||
|
||||
/* select an input stream for an output stream */ |
||||
typedef struct StreamMap { |
||||
int disabled; /* 1 is this mapping is disabled by a negative map */ |
||||
int file_index; |
||||
int stream_index; |
||||
int sync_file_index; |
||||
int sync_stream_index; |
||||
char *linklabel; /* name of an output link, for mapping lavfi outputs */ |
||||
} StreamMap; |
||||
|
||||
typedef struct { |
||||
int file_idx, stream_idx, channel_idx; // input
|
||||
int ofile_idx, ostream_idx; // output
|
||||
} AudioChannelMap; |
||||
|
||||
typedef struct OptionsContext { |
||||
OptionGroup *g; |
||||
|
||||
/* input/output options */ |
||||
int64_t start_time; |
||||
int64_t start_time_eof; |
||||
int seek_timestamp; |
||||
const char *format; |
||||
|
||||
SpecifierOpt *codec_names; |
||||
int nb_codec_names; |
||||
SpecifierOpt *audio_channels; |
||||
int nb_audio_channels; |
||||
SpecifierOpt *audio_sample_rate; |
||||
int nb_audio_sample_rate; |
||||
SpecifierOpt *frame_rates; |
||||
int nb_frame_rates; |
||||
SpecifierOpt *frame_sizes; |
||||
int nb_frame_sizes; |
||||
SpecifierOpt *frame_pix_fmts; |
||||
int nb_frame_pix_fmts; |
||||
|
||||
/* input options */ |
||||
int64_t input_ts_offset; |
||||
int loop; |
||||
int rate_emu; |
||||
int accurate_seek; |
||||
int thread_queue_size; |
||||
|
||||
SpecifierOpt *ts_scale; |
||||
int nb_ts_scale; |
||||
SpecifierOpt *dump_attachment; |
||||
int nb_dump_attachment; |
||||
SpecifierOpt *hwaccels; |
||||
int nb_hwaccels; |
||||
SpecifierOpt *hwaccel_devices; |
||||
int nb_hwaccel_devices; |
||||
SpecifierOpt *hwaccel_output_formats; |
||||
int nb_hwaccel_output_formats; |
||||
SpecifierOpt *autorotate; |
||||
int nb_autorotate; |
||||
|
||||
/* output options */ |
||||
StreamMap *stream_maps; |
||||
int nb_stream_maps; |
||||
AudioChannelMap *audio_channel_maps; /* one info entry per -map_channel */ |
||||
int nb_audio_channel_maps; /* number of (valid) -map_channel settings */ |
||||
int metadata_global_manual; |
||||
int metadata_streams_manual; |
||||
int metadata_chapters_manual; |
||||
const char **attachments; |
||||
int nb_attachments; |
||||
|
||||
int chapters_input_file; |
||||
|
||||
int64_t recording_time; |
||||
int64_t stop_time; |
||||
uint64_t limit_filesize; |
||||
float mux_preload; |
||||
float mux_max_delay; |
||||
int shortest; |
||||
int bitexact; |
||||
|
||||
int video_disable; |
||||
int audio_disable; |
||||
int subtitle_disable; |
||||
int data_disable; |
||||
|
||||
/* indexed by output file stream index */ |
||||
int *streamid_map; |
||||
int nb_streamid_map; |
||||
|
||||
SpecifierOpt *metadata; |
||||
int nb_metadata; |
||||
SpecifierOpt *max_frames; |
||||
int nb_max_frames; |
||||
SpecifierOpt *bitstream_filters; |
||||
int nb_bitstream_filters; |
||||
SpecifierOpt *codec_tags; |
||||
int nb_codec_tags; |
||||
SpecifierOpt *sample_fmts; |
||||
int nb_sample_fmts; |
||||
SpecifierOpt *qscale; |
||||
int nb_qscale; |
||||
SpecifierOpt *forced_key_frames; |
||||
int nb_forced_key_frames; |
||||
SpecifierOpt *force_fps; |
||||
int nb_force_fps; |
||||
SpecifierOpt *frame_aspect_ratios; |
||||
int nb_frame_aspect_ratios; |
||||
SpecifierOpt *rc_overrides; |
||||
int nb_rc_overrides; |
||||
SpecifierOpt *intra_matrices; |
||||
int nb_intra_matrices; |
||||
SpecifierOpt *inter_matrices; |
||||
int nb_inter_matrices; |
||||
SpecifierOpt *chroma_intra_matrices; |
||||
int nb_chroma_intra_matrices; |
||||
SpecifierOpt *top_field_first; |
||||
int nb_top_field_first; |
||||
SpecifierOpt *metadata_map; |
||||
int nb_metadata_map; |
||||
SpecifierOpt *presets; |
||||
int nb_presets; |
||||
SpecifierOpt *copy_initial_nonkeyframes; |
||||
int nb_copy_initial_nonkeyframes; |
||||
SpecifierOpt *copy_prior_start; |
||||
int nb_copy_prior_start; |
||||
SpecifierOpt *filters; |
||||
int nb_filters; |
||||
SpecifierOpt *filter_scripts; |
||||
int nb_filter_scripts; |
||||
SpecifierOpt *reinit_filters; |
||||
int nb_reinit_filters; |
||||
SpecifierOpt *fix_sub_duration; |
||||
int nb_fix_sub_duration; |
||||
SpecifierOpt *canvas_sizes; |
||||
int nb_canvas_sizes; |
||||
SpecifierOpt *pass; |
||||
int nb_pass; |
||||
SpecifierOpt *passlogfiles; |
||||
int nb_passlogfiles; |
||||
SpecifierOpt *max_muxing_queue_size; |
||||
int nb_max_muxing_queue_size; |
||||
SpecifierOpt *guess_layout_max; |
||||
int nb_guess_layout_max; |
||||
SpecifierOpt *apad; |
||||
int nb_apad; |
||||
SpecifierOpt *discard; |
||||
int nb_discard; |
||||
SpecifierOpt *disposition; |
||||
int nb_disposition; |
||||
SpecifierOpt *program; |
||||
int nb_program; |
||||
SpecifierOpt *time_bases; |
||||
int nb_time_bases; |
||||
SpecifierOpt *enc_time_bases; |
||||
int nb_enc_time_bases; |
||||
} OptionsContext; |
||||
|
||||
typedef struct InputFilter { |
||||
AVFilterContext *filter; |
||||
struct InputStream *ist; |
||||
struct FilterGraph *graph; |
||||
uint8_t *name; |
||||
enum AVMediaType type; // AVMEDIA_TYPE_SUBTITLE for sub2video
|
||||
|
||||
AVFifoBuffer *frame_queue; |
||||
|
||||
// parameters configured for this input
|
||||
int format; |
||||
|
||||
int width, height; |
||||
AVRational sample_aspect_ratio; |
||||
|
||||
int sample_rate; |
||||
int channels; |
||||
uint64_t channel_layout; |
||||
|
||||
AVBufferRef *hw_frames_ctx; |
||||
|
||||
int eof; |
||||
} InputFilter; |
||||
|
||||
typedef struct OutputFilter { |
||||
AVFilterContext *filter; |
||||
struct OutputStream *ost; |
||||
struct FilterGraph *graph; |
||||
uint8_t *name; |
||||
|
||||
/* temporary storage until stream maps are processed */ |
||||
AVFilterInOut *out_tmp; |
||||
enum AVMediaType type; |
||||
|
||||
/* desired output stream properties */ |
||||
int width, height; |
||||
AVRational frame_rate; |
||||
int format; |
||||
int sample_rate; |
||||
uint64_t channel_layout; |
||||
|
||||
// those are only set if no format is specified and the encoder gives us multiple options
|
||||
int *formats; |
||||
uint64_t *channel_layouts; |
||||
int *sample_rates; |
||||
} OutputFilter; |
||||
|
||||
typedef struct FilterGraph { |
||||
int index; |
||||
const char *graph_desc; |
||||
|
||||
AVFilterGraph *graph; |
||||
int reconfiguration; |
||||
|
||||
InputFilter **inputs; |
||||
int nb_inputs; |
||||
OutputFilter **outputs; |
||||
int nb_outputs; |
||||
} FilterGraph; |
||||
|
||||
typedef struct InputStream { |
||||
int file_index; |
||||
AVStream *st; |
||||
int discard; /* true if stream data should be discarded */ |
||||
int user_set_discard; |
||||
int decoding_needed; /* non zero if the packets must be decoded in 'raw_fifo', see DECODING_FOR_* */ |
||||
#define DECODING_FOR_OST 1 |
||||
#define DECODING_FOR_FILTER 2 |
||||
|
||||
AVCodecContext *dec_ctx; |
||||
AVCodec *dec; |
||||
AVFrame *decoded_frame; |
||||
AVFrame *filter_frame; /* a ref of decoded_frame, to be sent to filters */ |
||||
|
||||
int64_t start; /* time when read started */ |
||||
/* predicted dts of the next packet read for this stream or (when there are
|
||||
* several frames in a packet) of the next frame in current packet (in AV_TIME_BASE units) */ |
||||
int64_t next_dts; |
||||
int64_t dts; ///< dts of the last packet read for this stream (in AV_TIME_BASE units)
|
||||
|
||||
int64_t next_pts; ///< synthetic pts for the next decode frame (in AV_TIME_BASE units)
|
||||
int64_t pts; ///< current pts of the decoded frame (in AV_TIME_BASE units)
|
||||
int wrap_correction_done; |
||||
|
||||
int64_t filter_in_rescale_delta_last; |
||||
|
||||
int64_t min_pts; /* pts with the smallest value in a current stream */ |
||||
int64_t max_pts; /* pts with the higher value in a current stream */ |
||||
|
||||
// when forcing constant input framerate through -r,
|
||||
// this contains the pts that will be given to the next decoded frame
|
||||
int64_t cfr_next_pts; |
||||
|
||||
int64_t nb_samples; /* number of samples in the last decoded audio frame before looping */ |
||||
|
||||
double ts_scale; |
||||
int saw_first_ts; |
||||
AVDictionary *decoder_opts; |
||||
AVRational framerate; /* framerate forced with -r */ |
||||
int top_field_first; |
||||
int guess_layout_max; |
||||
|
||||
int autorotate; |
||||
|
||||
int fix_sub_duration; |
||||
struct { /* previous decoded subtitle and related variables */ |
||||
int got_output; |
||||
int ret; |
||||
AVSubtitle subtitle; |
||||
} prev_sub; |
||||
|
||||
struct sub2video { |
||||
int64_t last_pts; |
||||
int64_t end_pts; |
||||
AVFifoBuffer *sub_queue; ///< queue of AVSubtitle* before filter init
|
||||
AVFrame *frame; |
||||
int w, h; |
||||
} sub2video; |
||||
|
||||
int dr1; |
||||
|
||||
/* decoded data from this stream goes into all those filters
|
||||
* currently video and audio only */ |
||||
InputFilter **filters; |
||||
int nb_filters; |
||||
|
||||
int reinit_filters; |
||||
|
||||
/* hwaccel options */ |
||||
enum HWAccelID hwaccel_id; |
||||
enum AVHWDeviceType hwaccel_device_type; |
||||
char *hwaccel_device; |
||||
enum AVPixelFormat hwaccel_output_format; |
||||
|
||||
/* hwaccel context */ |
||||
void *hwaccel_ctx; |
||||
void (*hwaccel_uninit)(AVCodecContext *s); |
||||
int (*hwaccel_get_buffer)(AVCodecContext *s, AVFrame *frame, int flags); |
||||
int (*hwaccel_retrieve_data)(AVCodecContext *s, AVFrame *frame); |
||||
enum AVPixelFormat hwaccel_pix_fmt; |
||||
enum AVPixelFormat hwaccel_retrieved_pix_fmt; |
||||
AVBufferRef *hw_frames_ctx; |
||||
|
||||
/* stats */ |
||||
// combined size of all the packets read
|
||||
uint64_t data_size; |
||||
/* number of packets successfully read for this stream */ |
||||
uint64_t nb_packets; |
||||
// number of frames/samples retrieved from the decoder
|
||||
uint64_t frames_decoded; |
||||
uint64_t samples_decoded; |
||||
|
||||
int64_t *dts_buffer; |
||||
int nb_dts_buffer; |
||||
|
||||
int got_output; |
||||
} InputStream; |
||||
|
||||
typedef struct InputFile { |
||||
AVFormatContext *ctx; |
||||
int eof_reached; /* true if eof reached */ |
||||
int eagain; /* true if last read attempt returned EAGAIN */ |
||||
int ist_index; /* index of first stream in input_streams */ |
||||
int loop; /* set number of times input stream should be looped */ |
||||
int64_t duration; /* actual duration of the longest stream in a file
|
||||
at the moment when looping happens */ |
||||
AVRational time_base; /* time base of the duration */ |
||||
int64_t input_ts_offset; |
||||
|
||||
int64_t ts_offset; |
||||
int64_t last_ts; |
||||
int64_t start_time; /* user-specified start time in AV_TIME_BASE or AV_NOPTS_VALUE */ |
||||
int seek_timestamp; |
||||
int64_t recording_time; |
||||
int nb_streams; /* number of stream that ffmpeg is aware of; may be different
|
||||
from ctx.nb_streams if new streams appear during av_read_frame() */ |
||||
int nb_streams_warn; /* number of streams that the user was warned of */ |
||||
int rate_emu; |
||||
int accurate_seek; |
||||
|
||||
#if HAVE_THREADS |
||||
AVThreadMessageQueue *in_thread_queue; |
||||
pthread_t thread; /* thread reading from this file */ |
||||
int non_blocking; /* reading packets from the thread should not block */ |
||||
int joined; /* the thread has been joined */ |
||||
int thread_queue_size; /* maximum number of queued packets */ |
||||
#endif |
||||
} InputFile; |
||||
|
||||
enum forced_keyframes_const { |
||||
FKF_N, |
||||
FKF_N_FORCED, |
||||
FKF_PREV_FORCED_N, |
||||
FKF_PREV_FORCED_T, |
||||
FKF_T, |
||||
FKF_NB |
||||
}; |
||||
|
||||
#define ABORT_ON_FLAG_EMPTY_OUTPUT (1 << 0) |
||||
|
||||
extern const char *const forced_keyframes_const_names[]; |
||||
|
||||
typedef enum { |
||||
ENCODER_FINISHED = 1, |
||||
MUXER_FINISHED = 2, |
||||
} OSTFinished ; |
||||
|
||||
typedef struct OutputStream { |
||||
int file_index; /* file index */ |
||||
int index; /* stream index in the output file */ |
||||
int source_index; /* InputStream index */ |
||||
AVStream *st; /* stream in the output file */ |
||||
int encoding_needed; /* true if encoding needed for this stream */ |
||||
int frame_number; |
||||
/* input pts and corresponding output pts
|
||||
for A/V sync */ |
||||
struct InputStream *sync_ist; /* input stream to sync against */ |
||||
int64_t sync_opts; /* output frame counter, could be changed to some true timestamp */ // FIXME look at frame_number
|
||||
/* pts of the first frame encoded for this stream, used for limiting
|
||||
* recording time */ |
||||
int64_t first_pts; |
||||
/* dts of the last packet sent to the muxer */ |
||||
int64_t last_mux_dts; |
||||
// the timebase of the packets sent to the muxer
|
||||
AVRational mux_timebase; |
||||
AVRational enc_timebase; |
||||
|
||||
int nb_bitstream_filters; |
||||
AVBSFContext **bsf_ctx; |
||||
|
||||
AVCodecContext *enc_ctx; |
||||
AVCodecParameters *ref_par; /* associated input codec parameters with encoders options applied */ |
||||
AVCodec *enc; |
||||
int64_t max_frames; |
||||
AVFrame *filtered_frame; |
||||
AVFrame *last_frame; |
||||
int last_dropped; |
||||
int last_nb0_frames[3]; |
||||
|
||||
void *hwaccel_ctx; |
||||
|
||||
/* video only */ |
||||
AVRational frame_rate; |
||||
int is_cfr; |
||||
int force_fps; |
||||
int top_field_first; |
||||
int rotate_overridden; |
||||
double rotate_override_value; |
||||
|
||||
AVRational frame_aspect_ratio; |
||||
|
||||
/* forced key frames */ |
||||
int64_t forced_kf_ref_pts; |
||||
int64_t *forced_kf_pts; |
||||
int forced_kf_count; |
||||
int forced_kf_index; |
||||
char *forced_keyframes; |
||||
AVExpr *forced_keyframes_pexpr; |
||||
double forced_keyframes_expr_const_values[FKF_NB]; |
||||
|
||||
/* audio only */ |
||||
int *audio_channels_map; /* list of the channels id to pick from the source stream */ |
||||
int audio_channels_mapped; /* number of channels in audio_channels_map */ |
||||
|
||||
char *logfile_prefix; |
||||
FILE *logfile; |
||||
|
||||
OutputFilter *filter; |
||||
char *avfilter; |
||||
char *filters; ///< filtergraph associated to the -filter option
|
||||
char *filters_script; ///< filtergraph script associated to the -filter_script option
|
||||
|
||||
AVDictionary *encoder_opts; |
||||
AVDictionary *sws_dict; |
||||
AVDictionary *swr_opts; |
||||
AVDictionary *resample_opts; |
||||
char *apad; |
||||
OSTFinished finished; /* no more packets should be written for this stream */ |
||||
int unavailable; /* true if the steram is unavailable (possibly temporarily) */ |
||||
int stream_copy; |
||||
|
||||
// init_output_stream() has been called for this stream
|
||||
// The encoder and the bitstream filters have been initialized and the stream
|
||||
// parameters are set in the AVStream.
|
||||
int initialized; |
||||
|
||||
int inputs_done; |
||||
|
||||
const char *attachment_filename; |
||||
int copy_initial_nonkeyframes; |
||||
int copy_prior_start; |
||||
char *disposition; |
||||
|
||||
int keep_pix_fmt; |
||||
|
||||
/* stats */ |
||||
// combined size of all the packets written
|
||||
uint64_t data_size; |
||||
// number of packets send to the muxer
|
||||
uint64_t packets_written; |
||||
// number of frames/samples sent to the encoder
|
||||
uint64_t frames_encoded; |
||||
uint64_t samples_encoded; |
||||
|
||||
/* packet quality factor */ |
||||
int quality; |
||||
|
||||
int max_muxing_queue_size; |
||||
|
||||
/* the packets are buffered here until the muxer is ready to be initialized */ |
||||
AVFifoBuffer *muxing_queue; |
||||
|
||||
/* packet picture type */ |
||||
int pict_type; |
||||
|
||||
/* frame encode sum of squared error values */ |
||||
int64_t error[4]; |
||||
} OutputStream; |
||||
|
||||
typedef struct OutputFile { |
||||
AVFormatContext *ctx; |
||||
AVDictionary *opts; |
||||
int ost_index; /* index of the first stream in output_streams */ |
||||
int64_t recording_time; ///< desired length of the resulting file in microseconds == AV_TIME_BASE units
|
||||
int64_t start_time; ///< start time in microseconds == AV_TIME_BASE units
|
||||
uint64_t limit_filesize; /* filesize limit expressed in bytes */ |
||||
|
||||
int shortest; |
||||
|
||||
int header_written; |
||||
} OutputFile; |
||||
|
||||
extern __thread InputStream **input_streams; |
||||
extern __thread int nb_input_streams; |
||||
extern __thread InputFile **input_files; |
||||
extern __thread int nb_input_files; |
||||
|
||||
extern __thread OutputStream **output_streams; |
||||
extern __thread int nb_output_streams; |
||||
extern __thread OutputFile **output_files; |
||||
extern __thread int nb_output_files; |
||||
|
||||
extern __thread FilterGraph **filtergraphs; |
||||
extern __thread int nb_filtergraphs; |
||||
|
||||
extern __thread char *vstats_filename; |
||||
extern __thread char *sdp_filename; |
||||
|
||||
extern __thread float audio_drift_threshold; |
||||
extern __thread float dts_delta_threshold; |
||||
extern __thread float dts_error_threshold; |
||||
|
||||
extern __thread int audio_volume; |
||||
extern __thread int audio_sync_method; |
||||
extern __thread int video_sync_method; |
||||
extern __thread float frame_drop_threshold; |
||||
extern __thread int do_benchmark; |
||||
extern __thread int do_benchmark_all; |
||||
extern __thread int do_deinterlace; |
||||
extern __thread int do_hex_dump; |
||||
extern __thread int do_pkt_dump; |
||||
extern __thread int copy_ts; |
||||
extern __thread int start_at_zero; |
||||
extern __thread int copy_tb; |
||||
extern __thread int debug_ts; |
||||
extern __thread int exit_on_error; |
||||
extern __thread int abort_on_flags; |
||||
extern __thread int print_stats; |
||||
extern __thread int qp_hist; |
||||
extern __thread int stdin_interaction; |
||||
extern __thread int frame_bits_per_raw_sample; |
||||
extern __thread AVIOContext *progress_avio; |
||||
extern __thread float max_error_rate; |
||||
extern __thread char *videotoolbox_pixfmt; |
||||
|
||||
extern __thread int filter_nbthreads; |
||||
extern __thread int filter_complex_nbthreads; |
||||
extern __thread int vstats_version; |
||||
|
||||
extern __thread const AVIOInterruptCB int_cb; |
||||
|
||||
extern const HWAccel hwaccels[]; |
||||
extern __thread AVBufferRef *hw_device_ctx; |
||||
#if CONFIG_QSV |
||||
extern __thread char *qsv_device; |
||||
#endif |
||||
extern __thread HWDevice *filter_hw_device; |
||||
|
||||
void term_init(void); |
||||
void term_exit(void); |
||||
|
||||
void reset_options(OptionsContext *o, int is_input); |
||||
void show_usage(void); |
||||
|
||||
void opt_output_file(void *optctx, const char *filename); |
||||
|
||||
void remove_avoptions(AVDictionary **a, AVDictionary *b); |
||||
void assert_avoptions(AVDictionary *m); |
||||
|
||||
int guess_input_channel_layout(InputStream *ist); |
||||
|
||||
enum AVPixelFormat choose_pixel_fmt(AVStream *st, AVCodecContext *avctx, AVCodec *codec, enum AVPixelFormat target); |
||||
void choose_sample_fmt(AVStream *st, AVCodec *codec); |
||||
|
||||
int configure_filtergraph(FilterGraph *fg); |
||||
int configure_output_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out); |
||||
void check_filter_outputs(void); |
||||
int ist_in_filtergraph(FilterGraph *fg, InputStream *ist); |
||||
int filtergraph_is_simple(FilterGraph *fg); |
||||
int init_simple_filtergraph(InputStream *ist, OutputStream *ost); |
||||
int init_complex_filtergraph(FilterGraph *fg); |
||||
|
||||
void sub2video_update(InputStream *ist, AVSubtitle *sub); |
||||
|
||||
int ifilter_parameters_from_frame(InputFilter *ifilter, const AVFrame *frame); |
||||
|
||||
int ffmpeg_parse_options(int argc, char **argv); |
||||
|
||||
int videotoolbox_init(AVCodecContext *s); |
||||
int qsv_init(AVCodecContext *s); |
||||
int cuvid_init(AVCodecContext *s); |
||||
|
||||
HWDevice *hw_device_get_by_name(const char *name); |
||||
int hw_device_init_from_string(const char *arg, HWDevice **dev); |
||||
void hw_device_free_all(void); |
||||
|
||||
int hw_device_setup_for_decode(InputStream *ist); |
||||
int hw_device_setup_for_encode(OutputStream *ost); |
||||
|
||||
int hwaccel_decode_init(AVCodecContext *avctx); |
||||
|
||||
void set_report_callback(void (*callback)(int, float, float, int64_t, int, double, double)); |
||||
|
||||
void cancel_operation(long id); |
||||
|
||||
int opt_map(void *optctx, const char *opt, const char *arg); |
||||
int opt_map_channel(void *optctx, const char *opt, const char *arg); |
||||
int opt_recording_timestamp(void *optctx, const char *opt, const char *arg); |
||||
int opt_data_frames(void *optctx, const char *opt, const char *arg); |
||||
int opt_progress(void *optctx, const char *opt, const char *arg); |
||||
int opt_target(void *optctx, const char *opt, const char *arg); |
||||
int opt_vsync(void *optctx, const char *opt, const char *arg); |
||||
int opt_abort_on(void *optctx, const char *opt, const char *arg); |
||||
int opt_qscale(void *optctx, const char *opt, const char *arg); |
||||
int opt_profile(void *optctx, const char *opt, const char *arg); |
||||
int opt_filter_complex(void *optctx, const char *opt, const char *arg); |
||||
int opt_filter_complex_script(void *optctx, const char *opt, const char *arg); |
||||
int opt_attach(void *optctx, const char *opt, const char *arg); |
||||
int opt_video_frames(void *optctx, const char *opt, const char *arg); |
||||
int opt_video_codec(void *optctx, const char *opt, const char *arg); |
||||
int opt_sameq(void *optctx, const char *opt, const char *arg); |
||||
int opt_timecode(void *optctx, const char *opt, const char *arg); |
||||
|
||||
int opt_vstats_file(void *optctx, const char *opt, const char *arg); |
||||
int opt_vstats(void *optctx, const char *opt, const char *arg); |
||||
int opt_video_frames(void *optctx, const char *opt, const char *arg); |
||||
int opt_old2new(void *optctx, const char *opt, const char *arg); |
||||
int opt_streamid(void *optctx, const char *opt, const char *arg); |
||||
int opt_bitrate(void *optctx, const char *opt, const char *arg); |
||||
int show_hwaccels(void *optctx, const char *opt, const char *arg); |
||||
int opt_video_filters(void *optctx, const char *opt, const char *arg); |
||||
int opt_audio_frames(void *optctx, const char *opt, const char *arg); |
||||
int opt_audio_qscale(void *optctx, const char *opt, const char *arg); |
||||
int opt_audio_codec(void *optctx, const char *opt, const char *arg); |
||||
int opt_channel_layout(void *optctx, const char *opt, const char *arg); |
||||
int opt_preset(void *optctx, const char *opt, const char *arg); |
||||
int opt_audio_filters(void *optctx, const char *opt, const char *arg); |
||||
int opt_subtitle_codec(void *optctx, const char *opt, const char *arg); |
||||
int opt_video_channel(void *optctx, const char *opt, const char *arg); |
||||
int opt_video_standard(void *optctx, const char *opt, const char *arg); |
||||
int opt_sdp_file(void *optctx, const char *opt, const char *arg); |
||||
int opt_data_codec(void *optctx, const char *opt, const char *arg); |
||||
int opt_init_hw_device(void *optctx, const char *opt, const char *arg); |
||||
int opt_filter_hw_device(void *optctx, const char *opt, const char *arg); |
||||
void add_input_streams(OptionsContext *o, AVFormatContext *ic); |
||||
void assert_file_overwrite(const char *filename); |
||||
void dump_attachment(AVStream *st, const char *filename); |
||||
uint8_t *get_line(AVIOContext *s); |
||||
void uninit_options(OptionsContext *o); |
||||
void init_options(OptionsContext *o); |
||||
AVDictionary *strip_specifiers(AVDictionary *dict); |
||||
void parse_meta_type(char *arg, char *type, int *index, const char **stream_spec); |
||||
int fftools_copy_metadata(char *outspec, char *inspec, AVFormatContext *oc, AVFormatContext *ic, OptionsContext *o); |
||||
AVCodec *find_codec_or_die(const char *name, enum AVMediaType type, int encoder); |
||||
AVCodec *choose_decoder(OptionsContext *o, AVFormatContext *s, AVStream *st); |
||||
int open_input_file(OptionsContext *o, const char *filename); |
||||
int get_preset_file_2(const char *preset_name, const char *codec_name, AVIOContext **s); |
||||
int choose_encoder(OptionsContext *o, AVFormatContext *s, OutputStream *ost); |
||||
OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, enum AVMediaType type, int source_index); |
||||
void parse_matrix_coeffs(uint16_t *dest, const char *str); |
||||
uint8_t *fftools_read_file(const char *filename); |
||||
char *get_ost_filters(OptionsContext *o, AVFormatContext *oc, OutputStream *ost); |
||||
void check_streamcopy_filters(OptionsContext *o, AVFormatContext *oc, const OutputStream *ost, enum AVMediaType type); |
||||
OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc, int source_index); |
||||
OutputStream *new_audio_stream(OptionsContext *o, AVFormatContext *oc, int source_index); |
||||
OutputStream *new_data_stream(OptionsContext *o, AVFormatContext *oc, int source_index); |
||||
OutputStream *new_unknown_stream(OptionsContext *o, AVFormatContext *oc, int source_index); |
||||
OutputStream *new_attachment_stream(OptionsContext *o, AVFormatContext *oc, int source_index); |
||||
OutputStream *new_subtitle_stream(OptionsContext *o, AVFormatContext *oc, int source_index); |
||||
int copy_chapters(InputFile *ifile, OutputFile *ofile, int copy_metadata); |
||||
void init_output_filter(OutputFilter *ofilter, OptionsContext *o, AVFormatContext *oc); |
||||
int init_complex_filters(void); |
||||
int open_output_file(OptionsContext *o, const char *filename); |
||||
int opt_default_new(OptionsContext *o, const char *opt, const char *arg); |
||||
int open_files(OptionGroupList *l, const char *inout, int (*open_file)(OptionsContext*, const char*)); |
||||
|
||||
#endif /* FFTOOLS_FFMPEG_H */ |
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,491 @@ |
||||
/*
|
||||
* This file is part of FFmpeg. |
||||
* |
||||
* FFmpeg is free software; you can redistribute it and/or |
||||
* modify it under the terms of the GNU Lesser General Public |
||||
* License as published by the Free Software Foundation; either |
||||
* version 2.1 of the License, or (at your option) any later version. |
||||
* |
||||
* FFmpeg 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 |
||||
* Lesser General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General Public |
||||
* License along with FFmpeg; if not, write to the Free Software |
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
*/ |
||||
|
||||
/*
|
||||
* CHANGES 12.2019 |
||||
* - Concurrent execution support |
||||
* |
||||
* CHANGES 08.2018 |
||||
* -------------------------------------------------------- |
||||
* - fftools_ prefix added to file name and parent header |
||||
*/ |
||||
|
||||
#include <string.h> |
||||
|
||||
#include "libavutil/avstring.h" |
||||
|
||||
#include "fftools_ffmpeg.h" |
||||
|
||||
__thread int nb_hw_devices; |
||||
__thread HWDevice **hw_devices; |
||||
|
||||
static HWDevice *hw_device_get_by_type(enum AVHWDeviceType type) |
||||
{ |
||||
HWDevice *found = NULL; |
||||
int i; |
||||
for (i = 0; i < nb_hw_devices; i++) { |
||||
if (hw_devices[i]->type == type) { |
||||
if (found) |
||||
return NULL; |
||||
found = hw_devices[i]; |
||||
} |
||||
} |
||||
return found; |
||||
} |
||||
|
||||
HWDevice *hw_device_get_by_name(const char *name) |
||||
{ |
||||
int i; |
||||
for (i = 0; i < nb_hw_devices; i++) { |
||||
if (!strcmp(hw_devices[i]->name, name)) |
||||
return hw_devices[i]; |
||||
} |
||||
return NULL; |
||||
} |
||||
|
||||
static HWDevice *hw_device_add(void) |
||||
{ |
||||
int err; |
||||
err = av_reallocp_array(&hw_devices, nb_hw_devices + 1, |
||||
sizeof(*hw_devices)); |
||||
if (err) { |
||||
nb_hw_devices = 0; |
||||
return NULL; |
||||
} |
||||
hw_devices[nb_hw_devices] = av_mallocz(sizeof(HWDevice)); |
||||
if (!hw_devices[nb_hw_devices]) |
||||
return NULL; |
||||
return hw_devices[nb_hw_devices++]; |
||||
} |
||||
|
||||
static char *hw_device_default_name(enum AVHWDeviceType type) |
||||
{ |
||||
// Make an automatic name of the form "type%d". We arbitrarily
|
||||
// limit at 1000 anonymous devices of the same type - there is
|
||||
// probably something else very wrong if you get to this limit.
|
||||
const char *type_name = av_hwdevice_get_type_name(type); |
||||
char *name; |
||||
size_t index_pos; |
||||
int index, index_limit = 1000; |
||||
index_pos = strlen(type_name); |
||||
name = av_malloc(index_pos + 4); |
||||
if (!name) |
||||
return NULL; |
||||
for (index = 0; index < index_limit; index++) { |
||||
snprintf(name, index_pos + 4, "%s%d", type_name, index); |
||||
if (!hw_device_get_by_name(name)) |
||||
break; |
||||
} |
||||
if (index >= index_limit) { |
||||
av_freep(&name); |
||||
return NULL; |
||||
} |
||||
return name; |
||||
} |
||||
|
||||
int hw_device_init_from_string(const char *arg, HWDevice **dev_out) |
||||
{ |
||||
// "type=name:device,key=value,key2=value2"
|
||||
// "type:device,key=value,key2=value2"
|
||||
// -> av_hwdevice_ctx_create()
|
||||
// "type=name@name"
|
||||
// "type@name"
|
||||
// -> av_hwdevice_ctx_create_derived()
|
||||
|
||||
AVDictionary *options = NULL; |
||||
const char *type_name = NULL, *name = NULL, *device = NULL; |
||||
enum AVHWDeviceType type; |
||||
HWDevice *dev, *src; |
||||
AVBufferRef *device_ref = NULL; |
||||
int err; |
||||
const char *errmsg, *p, *q; |
||||
size_t k; |
||||
|
||||
k = strcspn(arg, ":=@"); |
||||
p = arg + k; |
||||
|
||||
type_name = av_strndup(arg, k); |
||||
if (!type_name) { |
||||
err = AVERROR(ENOMEM); |
||||
goto fail; |
||||
} |
||||
type = av_hwdevice_find_type_by_name(type_name); |
||||
if (type == AV_HWDEVICE_TYPE_NONE) { |
||||
errmsg = "unknown device type"; |
||||
goto invalid; |
||||
} |
||||
|
||||
if (*p == '=') { |
||||
k = strcspn(p + 1, ":@"); |
||||
|
||||
name = av_strndup(p + 1, k); |
||||
if (!name) { |
||||
err = AVERROR(ENOMEM); |
||||
goto fail; |
||||
} |
||||
if (hw_device_get_by_name(name)) { |
||||
errmsg = "named device already exists"; |
||||
goto invalid; |
||||
} |
||||
|
||||
p += 1 + k; |
||||
} else { |
||||
name = hw_device_default_name(type); |
||||
if (!name) { |
||||
err = AVERROR(ENOMEM); |
||||
goto fail; |
||||
} |
||||
} |
||||
|
||||
if (!*p) { |
||||
// New device with no parameters.
|
||||
err = av_hwdevice_ctx_create(&device_ref, type, |
||||
NULL, NULL, 0); |
||||
if (err < 0) |
||||
goto fail; |
||||
|
||||
} else if (*p == ':') { |
||||
// New device with some parameters.
|
||||
++p; |
||||
q = strchr(p, ','); |
||||
if (q) { |
||||
if (q - p > 0) { |
||||
device = av_strndup(p, q - p); |
||||
if (!device) { |
||||
err = AVERROR(ENOMEM); |
||||
goto fail; |
||||
} |
||||
} |
||||
err = av_dict_parse_string(&options, q + 1, "=", ",", 0); |
||||
if (err < 0) { |
||||
errmsg = "failed to parse options"; |
||||
goto invalid; |
||||
} |
||||
} |
||||
|
||||
err = av_hwdevice_ctx_create(&device_ref, type, |
||||
q ? device : p[0] ? p : NULL, |
||||
options, 0); |
||||
if (err < 0) |
||||
goto fail; |
||||
|
||||
} else if (*p == '@') { |
||||
// Derive from existing device.
|
||||
|
||||
src = hw_device_get_by_name(p + 1); |
||||
if (!src) { |
||||
errmsg = "invalid source device name"; |
||||
goto invalid; |
||||
} |
||||
|
||||
err = av_hwdevice_ctx_create_derived(&device_ref, type, |
||||
src->device_ref, 0); |
||||
if (err < 0) |
||||
goto fail; |
||||
} else { |
||||
errmsg = "parse error"; |
||||
goto invalid; |
||||
} |
||||
|
||||
dev = hw_device_add(); |
||||
if (!dev) { |
||||
err = AVERROR(ENOMEM); |
||||
goto fail; |
||||
} |
||||
|
||||
dev->name = name; |
||||
dev->type = type; |
||||
dev->device_ref = device_ref; |
||||
|
||||
if (dev_out) |
||||
*dev_out = dev; |
||||
|
||||
name = NULL; |
||||
err = 0; |
||||
done: |
||||
av_freep(&type_name); |
||||
av_freep(&name); |
||||
av_freep(&device); |
||||
av_dict_free(&options); |
||||
return err; |
||||
invalid: |
||||
av_log(NULL, AV_LOG_ERROR, |
||||
"Invalid device specification \"%s\": %s\n", arg, errmsg); |
||||
err = AVERROR(EINVAL); |
||||
goto done; |
||||
fail: |
||||
av_log(NULL, AV_LOG_ERROR, |
||||
"Device creation failed: %d.\n", err); |
||||
av_buffer_unref(&device_ref); |
||||
goto done; |
||||
} |
||||
|
||||
static int hw_device_init_from_type(enum AVHWDeviceType type, |
||||
const char *device, |
||||
HWDevice **dev_out) |
||||
{ |
||||
AVBufferRef *device_ref = NULL; |
||||
HWDevice *dev; |
||||
char *name; |
||||
int err; |
||||
|
||||
name = hw_device_default_name(type); |
||||
if (!name) { |
||||
err = AVERROR(ENOMEM); |
||||
goto fail; |
||||
} |
||||
|
||||
err = av_hwdevice_ctx_create(&device_ref, type, device, NULL, 0); |
||||
if (err < 0) { |
||||
av_log(NULL, AV_LOG_ERROR, |
||||
"Device creation failed: %d.\n", err); |
||||
goto fail; |
||||
} |
||||
|
||||
dev = hw_device_add(); |
||||
if (!dev) { |
||||
err = AVERROR(ENOMEM); |
||||
goto fail; |
||||
} |
||||
|
||||
dev->name = name; |
||||
dev->type = type; |
||||
dev->device_ref = device_ref; |
||||
|
||||
if (dev_out) |
||||
*dev_out = dev; |
||||
|
||||
return 0; |
||||
|
||||
fail: |
||||
av_freep(&name); |
||||
av_buffer_unref(&device_ref); |
||||
return err; |
||||
} |
||||
|
||||
void hw_device_free_all(void) |
||||
{ |
||||
int i; |
||||
for (i = 0; i < nb_hw_devices; i++) { |
||||
av_freep(&hw_devices[i]->name); |
||||
av_buffer_unref(&hw_devices[i]->device_ref); |
||||
av_freep(&hw_devices[i]); |
||||
} |
||||
av_freep(&hw_devices); |
||||
nb_hw_devices = 0; |
||||
} |
||||
|
||||
static HWDevice *hw_device_match_by_codec(const AVCodec *codec) |
||||
{ |
||||
const AVCodecHWConfig *config; |
||||
HWDevice *dev; |
||||
int i; |
||||
for (i = 0;; i++) { |
||||
config = avcodec_get_hw_config(codec, i); |
||||
if (!config) |
||||
return NULL; |
||||
if (!(config->methods & AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX)) |
||||
continue; |
||||
dev = hw_device_get_by_type(config->device_type); |
||||
if (dev) |
||||
return dev; |
||||
} |
||||
} |
||||
|
||||
int hw_device_setup_for_decode(InputStream *ist) |
||||
{ |
||||
const AVCodecHWConfig *config; |
||||
enum AVHWDeviceType type; |
||||
HWDevice *dev = NULL; |
||||
int err, auto_device = 0; |
||||
|
||||
if (ist->hwaccel_device) { |
||||
dev = hw_device_get_by_name(ist->hwaccel_device); |
||||
if (!dev) { |
||||
if (ist->hwaccel_id == HWACCEL_AUTO) { |
||||
auto_device = 1; |
||||
} else if (ist->hwaccel_id == HWACCEL_GENERIC) { |
||||
type = ist->hwaccel_device_type; |
||||
err = hw_device_init_from_type(type, ist->hwaccel_device, |
||||
&dev); |
||||
} else { |
||||
// This will be dealt with by API-specific initialisation
|
||||
// (using hwaccel_device), so nothing further needed here.
|
||||
return 0; |
||||
} |
||||
} else { |
||||
if (ist->hwaccel_id == HWACCEL_AUTO) { |
||||
ist->hwaccel_device_type = dev->type; |
||||
} else if (ist->hwaccel_device_type != dev->type) { |
||||
av_log(ist->dec_ctx, AV_LOG_ERROR, "Invalid hwaccel device " |
||||
"specified for decoder: device %s of type %s is not " |
||||
"usable with hwaccel %s.\n", dev->name, |
||||
av_hwdevice_get_type_name(dev->type), |
||||
av_hwdevice_get_type_name(ist->hwaccel_device_type)); |
||||
return AVERROR(EINVAL); |
||||
} |
||||
} |
||||
} else { |
||||
if (ist->hwaccel_id == HWACCEL_AUTO) { |
||||
auto_device = 1; |
||||
} else if (ist->hwaccel_id == HWACCEL_GENERIC) { |
||||
type = ist->hwaccel_device_type; |
||||
dev = hw_device_get_by_type(type); |
||||
if (!dev) |
||||
err = hw_device_init_from_type(type, NULL, &dev); |
||||
} else { |
||||
dev = hw_device_match_by_codec(ist->dec); |
||||
if (!dev) { |
||||
// No device for this codec, but not using generic hwaccel
|
||||
// and therefore may well not need one - ignore.
|
||||
return 0; |
||||
} |
||||
} |
||||
} |
||||
|
||||
if (auto_device) { |
||||
int i; |
||||
if (!avcodec_get_hw_config(ist->dec, 0)) { |
||||
// Decoder does not support any hardware devices.
|
||||
return 0; |
||||
} |
||||
for (i = 0; !dev; i++) { |
||||
config = avcodec_get_hw_config(ist->dec, i); |
||||
if (!config) |
||||
break; |
||||
type = config->device_type; |
||||
dev = hw_device_get_by_type(type); |
||||
if (dev) { |
||||
av_log(ist->dec_ctx, AV_LOG_INFO, "Using auto " |
||||
"hwaccel type %s with existing device %s.\n", |
||||
av_hwdevice_get_type_name(type), dev->name); |
||||
} |
||||
} |
||||
for (i = 0; !dev; i++) { |
||||
config = avcodec_get_hw_config(ist->dec, i); |
||||
if (!config) |
||||
break; |
||||
type = config->device_type; |
||||
// Try to make a new device of this type.
|
||||
err = hw_device_init_from_type(type, ist->hwaccel_device, |
||||
&dev); |
||||
if (err < 0) { |
||||
// Can't make a device of this type.
|
||||
continue; |
||||
} |
||||
if (ist->hwaccel_device) { |
||||
av_log(ist->dec_ctx, AV_LOG_INFO, "Using auto " |
||||
"hwaccel type %s with new device created " |
||||
"from %s.\n", av_hwdevice_get_type_name(type), |
||||
ist->hwaccel_device); |
||||
} else { |
||||
av_log(ist->dec_ctx, AV_LOG_INFO, "Using auto " |
||||
"hwaccel type %s with new default device.\n", |
||||
av_hwdevice_get_type_name(type)); |
||||
} |
||||
} |
||||
if (dev) { |
||||
ist->hwaccel_device_type = type; |
||||
} else { |
||||
av_log(ist->dec_ctx, AV_LOG_INFO, "Auto hwaccel " |
||||
"disabled: no device found.\n"); |
||||
ist->hwaccel_id = HWACCEL_NONE; |
||||
return 0; |
||||
} |
||||
} |
||||
|
||||
if (!dev) { |
||||
av_log(ist->dec_ctx, AV_LOG_ERROR, "No device available " |
||||
"for decoder: device type %s needed for codec %s.\n", |
||||
av_hwdevice_get_type_name(type), ist->dec->name); |
||||
return err; |
||||
} |
||||
|
||||
ist->dec_ctx->hw_device_ctx = av_buffer_ref(dev->device_ref); |
||||
if (!ist->dec_ctx->hw_device_ctx) |
||||
return AVERROR(ENOMEM); |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
int hw_device_setup_for_encode(OutputStream *ost) |
||||
{ |
||||
HWDevice *dev; |
||||
|
||||
dev = hw_device_match_by_codec(ost->enc); |
||||
if (dev) { |
||||
ost->enc_ctx->hw_device_ctx = av_buffer_ref(dev->device_ref); |
||||
if (!ost->enc_ctx->hw_device_ctx) |
||||
return AVERROR(ENOMEM); |
||||
return 0; |
||||
} else { |
||||
// No device required, or no device available.
|
||||
return 0; |
||||
} |
||||
} |
||||
|
||||
static int hwaccel_retrieve_data(AVCodecContext *avctx, AVFrame *input) |
||||
{ |
||||
InputStream *ist = avctx->opaque; |
||||
AVFrame *output = NULL; |
||||
enum AVPixelFormat output_format = ist->hwaccel_output_format; |
||||
int err; |
||||
|
||||
if (input->format == output_format) { |
||||
// Nothing to do.
|
||||
return 0; |
||||
} |
||||
|
||||
output = av_frame_alloc(); |
||||
if (!output) |
||||
return AVERROR(ENOMEM); |
||||
|
||||
output->format = output_format; |
||||
|
||||
err = av_hwframe_transfer_data(output, input, 0); |
||||
if (err < 0) { |
||||
av_log(avctx, AV_LOG_ERROR, "Failed to transfer data to " |
||||
"output frame: %d.\n", err); |
||||
goto fail; |
||||
} |
||||
|
||||
err = av_frame_copy_props(output, input); |
||||
if (err < 0) { |
||||
av_frame_unref(output); |
||||
goto fail; |
||||
} |
||||
|
||||
av_frame_unref(input); |
||||
av_frame_move_ref(input, output); |
||||
av_frame_free(&output); |
||||
|
||||
return 0; |
||||
|
||||
fail: |
||||
av_frame_free(&output); |
||||
return err; |
||||
} |
||||
|
||||
int hwaccel_decode_init(AVCodecContext *avctx) |
||||
{ |
||||
InputStream *ist = avctx->opaque; |
||||
|
||||
ist->hwaccel_retrieve_data = &hwaccel_retrieve_data; |
||||
|
||||
return 0; |
||||
} |
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,108 @@ |
||||
/* |
||||
* Copyright (c) 2018-2020 Taner Sener |
||||
* |
||||
* This file is part of FFmpegKit. |
||||
* |
||||
* FFmpegKit is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Lesser General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* FFmpegKit 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 Lesser General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General Public License |
||||
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
package com.arthenica.ffmpegkit; |
||||
|
||||
/** |
||||
* <p>Helper enumeration type for Android ABIs; includes only supported ABIs. |
||||
*/ |
||||
public enum Abi { |
||||
|
||||
/** |
||||
* Represents armeabi-v7a ABI with NEON support |
||||
*/ |
||||
ABI_ARMV7A_NEON("armeabi-v7a-neon"), |
||||
|
||||
/** |
||||
* Represents armeabi-v7a ABI |
||||
*/ |
||||
ABI_ARMV7A("armeabi-v7a"), |
||||
|
||||
/** |
||||
* Represents armeabi ABI |
||||
*/ |
||||
ABI_ARM("armeabi"), |
||||
|
||||
/** |
||||
* Represents x86 ABI |
||||
*/ |
||||
ABI_X86("x86"), |
||||
|
||||
/** |
||||
* Represents x86_64 ABI |
||||
*/ |
||||
ABI_X86_64("x86_64"), |
||||
|
||||
/** |
||||
* Represents arm64-v8a ABI |
||||
*/ |
||||
ABI_ARM64_V8A("arm64-v8a"), |
||||
|
||||
/** |
||||
* Represents not supported ABIs |
||||
*/ |
||||
ABI_UNKNOWN("unknown"); |
||||
|
||||
private String name; |
||||
|
||||
/** |
||||
* <p>Returns enumeration defined by ABI name. |
||||
* |
||||
* @param abiName ABI name |
||||
* @return enumeration defined by ABI name |
||||
*/ |
||||
public static Abi from(final String abiName) { |
||||
if (abiName == null) { |
||||
return ABI_UNKNOWN; |
||||
} else if (abiName.equals(ABI_ARM.getName())) { |
||||
return ABI_ARM; |
||||
} else if (abiName.equals(ABI_ARMV7A.getName())) { |
||||
return ABI_ARMV7A; |
||||
} else if (abiName.equals(ABI_ARMV7A_NEON.getName())) { |
||||
return ABI_ARMV7A_NEON; |
||||
} else if (abiName.equals(ABI_ARM64_V8A.getName())) { |
||||
return ABI_ARM64_V8A; |
||||
} else if (abiName.equals(ABI_X86.getName())) { |
||||
return ABI_X86; |
||||
} else if (abiName.equals(ABI_X86_64.getName())) { |
||||
return ABI_X86_64; |
||||
} else { |
||||
return ABI_UNKNOWN; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Returns ABI name as defined in Android NDK documentation. |
||||
* |
||||
* @return ABI name |
||||
*/ |
||||
public String getName() { |
||||
return name; |
||||
} |
||||
|
||||
/** |
||||
* Creates new enum. |
||||
* |
||||
* @param abiName ABI name |
||||
*/ |
||||
Abi(final String abiName) { |
||||
this.name = abiName; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,94 @@ |
||||
/* |
||||
* Copyright (c) 2018-2020 Taner Sener |
||||
* |
||||
* This file is part of FFmpegKit. |
||||
* |
||||
* FFmpegKit is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Lesser General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* FFmpegKit 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 Lesser General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General Public License |
||||
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
package com.arthenica.ffmpegkit; |
||||
|
||||
/** |
||||
* <p>This class is used to detect running ABI name using Google <code>cpu-features</code> library. |
||||
*/ |
||||
public class AbiDetect { |
||||
|
||||
static { |
||||
armV7aNeonLoaded = false; |
||||
|
||||
System.loadLibrary("ffmpegkit_abidetect"); |
||||
|
||||
/* ALL LIBRARIES LOADED AT STARTUP */ |
||||
FFmpegKitConfig.class.getName(); |
||||
FFmpegKit.class.getName(); |
||||
} |
||||
|
||||
static final String ARM_V7A = "arm-v7a"; |
||||
|
||||
static final String ARM_V7A_NEON = "arm-v7a-neon"; |
||||
|
||||
private static boolean armV7aNeonLoaded; |
||||
|
||||
/** |
||||
* Default constructor hidden. |
||||
*/ |
||||
private AbiDetect() { |
||||
} |
||||
|
||||
static void setArmV7aNeonLoaded(final boolean armV7aNeonLoaded) { |
||||
AbiDetect.armV7aNeonLoaded = armV7aNeonLoaded; |
||||
} |
||||
|
||||
/** |
||||
* <p>Returns loaded ABI name. |
||||
* |
||||
* @return loaded ABI name |
||||
*/ |
||||
public static String getAbi() { |
||||
if (armV7aNeonLoaded) { |
||||
return ARM_V7A_NEON; |
||||
} else { |
||||
return getNativeAbi(); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* <p>Returns loaded ABI name. |
||||
* |
||||
* @return loaded ABI name |
||||
*/ |
||||
public native static String getNativeAbi(); |
||||
|
||||
/** |
||||
* <p>Returns ABI name of the running cpu. |
||||
* |
||||
* @return ABI name of the running cpu |
||||
*/ |
||||
public native static String getNativeCpuAbi(); |
||||
|
||||
/** |
||||
* <p>Returns whether FFmpegKit release is a long term release or not. |
||||
* |
||||
* @return yes or no |
||||
*/ |
||||
native static boolean isNativeLTSBuild(); |
||||
|
||||
/** |
||||
* <p>Returns build configuration for <code>FFmpeg</code>. |
||||
* |
||||
* @return build configuration string |
||||
*/ |
||||
native static String getNativeBuildConf(); |
||||
|
||||
} |
||||
@ -0,0 +1,62 @@ |
||||
/* |
||||
* Copyright (c) 2018-2020 Taner Sener |
||||
* |
||||
* This file is part of FFmpegKit. |
||||
* |
||||
* FFmpegKit is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Lesser General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* FFmpegKit 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 Lesser General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General Public License |
||||
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
package com.arthenica.ffmpegkit; |
||||
|
||||
import android.os.AsyncTask; |
||||
|
||||
/** |
||||
* <p>Utility class to execute an FFmpeg command asynchronously. |
||||
*/ |
||||
public class AsyncFFmpegExecuteTask extends AsyncTask<Void, Integer, Integer> { |
||||
private final String[] arguments; |
||||
private final ExecuteCallback executeCallback; |
||||
private final Long executionId; |
||||
|
||||
public AsyncFFmpegExecuteTask(final String command, final ExecuteCallback executeCallback) { |
||||
this(FFmpegKit.parseArguments(command), executeCallback); |
||||
} |
||||
|
||||
public AsyncFFmpegExecuteTask(final String[] arguments, final ExecuteCallback executeCallback) { |
||||
this(FFmpegKit.DEFAULT_EXECUTION_ID, arguments, executeCallback); |
||||
} |
||||
|
||||
public AsyncFFmpegExecuteTask(final long executionId, final String command, final ExecuteCallback executeCallback) { |
||||
this(executionId, FFmpegKit.parseArguments(command), executeCallback); |
||||
} |
||||
|
||||
public AsyncFFmpegExecuteTask(final long executionId, final String[] arguments, final ExecuteCallback executeCallback) { |
||||
this.executionId = executionId; |
||||
this.arguments = arguments; |
||||
this.executeCallback = executeCallback; |
||||
} |
||||
|
||||
@Override |
||||
protected Integer doInBackground(final Void... unused) { |
||||
return FFmpegKitConfig.ffmpegExecute(executionId, this.arguments); |
||||
} |
||||
|
||||
@Override |
||||
protected void onPostExecute(final Integer rc) { |
||||
if (executeCallback != null) { |
||||
executeCallback.apply(executionId, rc); |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,53 @@ |
||||
/* |
||||
* Copyright (c) 2018-2020 Taner Sener |
||||
* |
||||
* This file is part of FFmpegKit. |
||||
* |
||||
* FFmpegKit is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Lesser General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* FFmpegKit 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 Lesser General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General Public License |
||||
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
package com.arthenica.ffmpegkit; |
||||
|
||||
import android.os.AsyncTask; |
||||
|
||||
/** |
||||
* <p>Utility class to execute an FFprobe command asynchronously. |
||||
*/ |
||||
public class AsyncFFprobeExecuteTask extends AsyncTask<Void, Integer, Integer> { |
||||
private final String[] arguments; |
||||
private final ExecuteCallback ExecuteCallback; |
||||
|
||||
public AsyncFFprobeExecuteTask(final String command, final ExecuteCallback executeCallback) { |
||||
this.arguments = FFmpegKit.parseArguments(command); |
||||
this.ExecuteCallback = executeCallback; |
||||
} |
||||
|
||||
public AsyncFFprobeExecuteTask(final String[] arguments, final ExecuteCallback executeCallback) { |
||||
this.arguments = arguments; |
||||
ExecuteCallback = executeCallback; |
||||
} |
||||
|
||||
@Override |
||||
protected Integer doInBackground(final Void... unused) { |
||||
return FFprobeKit.execute(this.arguments); |
||||
} |
||||
|
||||
@Override |
||||
protected void onPostExecute(final Integer rc) { |
||||
if (ExecuteCallback != null) { |
||||
ExecuteCallback.apply(FFmpegKit.DEFAULT_EXECUTION_ID, rc); |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,48 @@ |
||||
/* |
||||
* Copyright (c) 2018-2020 Taner Sener |
||||
* |
||||
* This file is part of FFmpegKit. |
||||
* |
||||
* FFmpegKit is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Lesser General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* FFmpegKit 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 Lesser General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General Public License |
||||
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
package com.arthenica.ffmpegkit; |
||||
|
||||
import android.os.AsyncTask; |
||||
|
||||
/** |
||||
* <p>Utility class to get media information asynchronously. |
||||
*/ |
||||
public class AsyncGetMediaInformationTask extends AsyncTask<String, MediaInformation, MediaInformation> { |
||||
private final String path; |
||||
private final GetMediaInformationCallback getMediaInformationCallback; |
||||
|
||||
public AsyncGetMediaInformationTask(final String path, final GetMediaInformationCallback getMediaInformationCallback) { |
||||
this.path = path; |
||||
this.getMediaInformationCallback = getMediaInformationCallback; |
||||
} |
||||
|
||||
@Override |
||||
protected MediaInformation doInBackground(final String... arguments) { |
||||
return FFprobeKit.getMediaInformation(path); |
||||
} |
||||
|
||||
@Override |
||||
protected void onPostExecute(final MediaInformation mediaInformation) { |
||||
if (getMediaInformationCallback != null) { |
||||
getMediaInformationCallback.apply(mediaInformation); |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,75 @@ |
||||
/* |
||||
* Copyright (c) 2019-2020 Taner Sener |
||||
* |
||||
* This file is part of FFmpegKit. |
||||
* |
||||
* FFmpegKit is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Lesser General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* FFmpegKit 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 Lesser General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General Public License |
||||
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
package com.arthenica.ffmpegkit; |
||||
|
||||
import android.content.Context; |
||||
import android.hardware.camera2.CameraAccessException; |
||||
import android.hardware.camera2.CameraCharacteristics; |
||||
import android.hardware.camera2.CameraManager; |
||||
import android.hardware.camera2.CameraMetadata; |
||||
import android.os.Build; |
||||
import android.util.Log; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
import static android.content.Context.CAMERA_SERVICE; |
||||
import static com.arthenica.ffmpegkit.FFmpegKitConfig.TAG; |
||||
|
||||
/** |
||||
* Utility class for camera devices. |
||||
*/ |
||||
class CameraSupport { |
||||
|
||||
/** |
||||
* <p>Compatibility method for extracting supported camera ids. |
||||
* |
||||
* @param context application context |
||||
* @return returns the list of supported camera ids |
||||
*/ |
||||
static List<String> extractSupportedCameraIds(final Context context) { |
||||
final List<String> detectedCameraIdList = new ArrayList<>(); |
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { |
||||
try { |
||||
final CameraManager manager = (CameraManager) context.getSystemService(CAMERA_SERVICE); |
||||
if (manager != null) { |
||||
final String[] cameraIdList = manager.getCameraIdList(); |
||||
|
||||
for (String cameraId : cameraIdList) { |
||||
final CameraCharacteristics chars = manager.getCameraCharacteristics(cameraId); |
||||
final Integer cameraSupport = chars.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL); |
||||
|
||||
if (cameraSupport != null && cameraSupport == CameraMetadata.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY) { |
||||
Log.d(TAG, "Detected camera with id " + cameraId + " has LEGACY hardware level which is not supported by Android Camera2 NDK API."); |
||||
} else if (cameraSupport != null) { |
||||
detectedCameraIdList.add(cameraId); |
||||
} |
||||
} |
||||
} |
||||
} catch (final CameraAccessException e) { |
||||
Log.w(TAG, "Detecting camera ids failed.", e); |
||||
} |
||||
} |
||||
|
||||
return detectedCameraIdList; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,37 @@ |
||||
/* |
||||
* Copyright (c) 2018-2020 Taner Sener |
||||
* |
||||
* This file is part of FFmpegKit. |
||||
* |
||||
* FFmpegKit is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Lesser General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* FFmpegKit 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 Lesser General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General Public License |
||||
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
package com.arthenica.ffmpegkit; |
||||
|
||||
/** |
||||
* <p>Represents a callback function to receive an asynchronous execution result. |
||||
*/ |
||||
@FunctionalInterface |
||||
public interface ExecuteCallback { |
||||
|
||||
/** |
||||
* <p>Called when an asynchronous FFmpeg execution is completed. |
||||
* |
||||
* @param executionId id of the execution that completed |
||||
* @param returnCode return code of the execution completed, 0 on successful completion, 255 |
||||
* on user cancel, other non-zero codes on error |
||||
*/ |
||||
void apply(long executionId, int returnCode); |
||||
|
||||
} |
||||
@ -0,0 +1,50 @@ |
||||
/* |
||||
* Copyright (c) 2020 Taner Sener |
||||
* |
||||
* This file is part of FFmpegKit. |
||||
* |
||||
* FFmpegKit is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Lesser General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* FFmpegKit 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 Lesser General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General Public License |
||||
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
package com.arthenica.ffmpegkit; |
||||
|
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* <p>Represents an ongoing FFmpeg execution. |
||||
*/ |
||||
public class FFmpegExecution { |
||||
private final Date startTime; |
||||
private final long executionId; |
||||
private final String command; |
||||
|
||||
public FFmpegExecution(final long executionId, final String[] arguments) { |
||||
this.startTime = new Date(); |
||||
this.executionId = executionId; |
||||
this.command = FFmpegKit.argumentsToString(arguments); |
||||
} |
||||
|
||||
public Date getStartTime() { |
||||
return startTime; |
||||
} |
||||
|
||||
public long getExecutionId() { |
||||
return executionId; |
||||
} |
||||
|
||||
public String getCommand() { |
||||
return command; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,274 @@ |
||||
/* |
||||
* Copyright (c) 2018-2020 Taner Sener |
||||
* |
||||
* This file is part of FFmpegKit. |
||||
* |
||||
* FFmpegKit is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Lesser General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* FFmpegKit 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 Lesser General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General Public License |
||||
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
package com.arthenica.ffmpegkit; |
||||
|
||||
import android.os.AsyncTask; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
import java.util.concurrent.Executor; |
||||
import java.util.concurrent.atomic.AtomicLong; |
||||
|
||||
/** |
||||
* <p>Main class for FFmpeg operations. Supports synchronous {@link #execute(String...)} and |
||||
* asynchronous {@link #executeAsync(String, ExecuteCallback)} methods to execute FFmpeg commands. |
||||
* <pre> |
||||
* int rc = FFmpeg.execute("-i file1.mp4 -c:v libxvid file1.avi"); |
||||
* Log.i(Config.TAG, String.format("Command execution %s.", (rc == 0?"completed successfully":"failed with rc=" + rc)); |
||||
* </pre> |
||||
* <pre> |
||||
* long executionId = FFmpeg.executeAsync("-i file1.mp4 -c:v libxvid file1.avi", executeCallback); |
||||
* Log.i(Config.TAG, String.format("Asynchronous execution %d started.", executionId)); |
||||
* </pre> |
||||
*/ |
||||
public class FFmpegKit { |
||||
|
||||
static final long DEFAULT_EXECUTION_ID = 0; |
||||
|
||||
private static final AtomicLong executionIdCounter = new AtomicLong(3000); |
||||
|
||||
static { |
||||
AbiDetect.class.getName(); |
||||
FFmpegKitConfig.class.getName(); |
||||
} |
||||
|
||||
/** |
||||
* Default constructor hidden. |
||||
*/ |
||||
private FFmpegKit() { |
||||
} |
||||
|
||||
/** |
||||
* <p>Synchronously executes FFmpeg with arguments provided. |
||||
* |
||||
* @param arguments FFmpeg command options/arguments as string array |
||||
* @return 0 on successful execution, 255 on user cancel, other non-zero codes on error |
||||
*/ |
||||
public static int execute(final String[] arguments) { |
||||
return FFmpegKitConfig.ffmpegExecute(DEFAULT_EXECUTION_ID, arguments); |
||||
} |
||||
|
||||
/** |
||||
* <p>Asynchronously executes FFmpeg with arguments provided. |
||||
* |
||||
* @param arguments FFmpeg command options/arguments as string array |
||||
* @param executeCallback callback that will be notified when execution is completed |
||||
* @return returns a unique id that represents this execution |
||||
*/ |
||||
public static long executeAsync(final String[] arguments, final ExecuteCallback executeCallback) { |
||||
final long newExecutionId = executionIdCounter.incrementAndGet(); |
||||
|
||||
AsyncFFmpegExecuteTask asyncFFmpegExecuteTask = new AsyncFFmpegExecuteTask(newExecutionId, arguments, executeCallback); |
||||
asyncFFmpegExecuteTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); |
||||
|
||||
return newExecutionId; |
||||
} |
||||
|
||||
/** |
||||
* <p>Asynchronously executes FFmpeg with arguments provided. |
||||
* |
||||
* @param arguments FFmpeg command options/arguments as string array |
||||
* @param executeCallback callback that will be notified when execution is completed |
||||
* @param executor executor that will be used to run this asynchronous operation |
||||
* @return returns a unique id that represents this execution |
||||
*/ |
||||
public static long executeAsync(final String[] arguments, final ExecuteCallback executeCallback, final Executor executor) { |
||||
final long newExecutionId = executionIdCounter.incrementAndGet(); |
||||
|
||||
AsyncFFmpegExecuteTask asyncFFmpegExecuteTask = new AsyncFFmpegExecuteTask(newExecutionId, arguments, executeCallback); |
||||
asyncFFmpegExecuteTask.executeOnExecutor(executor); |
||||
|
||||
return newExecutionId; |
||||
} |
||||
|
||||
/** |
||||
* <p>Synchronously executes FFmpeg command provided. Command is split into arguments using |
||||
* provided delimiter character. |
||||
* |
||||
* @param command FFmpeg command |
||||
* @param delimiter delimiter used to split arguments |
||||
* @return 0 on successful execution, 255 on user cancel, other non-zero codes on error |
||||
* @since 3.0 |
||||
* @deprecated argument splitting mechanism used in this method is pretty simple and prone to |
||||
* errors. Consider using a more advanced method like {@link #execute(String)} or |
||||
* {@link #execute(String[])} |
||||
*/ |
||||
public static int execute(final String command, final String delimiter) { |
||||
return execute((command == null) ? new String[]{""} : command.split((delimiter == null) ? " " : delimiter)); |
||||
} |
||||
|
||||
/** |
||||
* <p>Synchronously executes FFmpeg command provided. Space character is used to split command |
||||
* into arguments. You can use single and double quote characters to specify arguments inside |
||||
* your command. |
||||
* |
||||
* @param command FFmpeg command |
||||
* @return 0 on successful execution, 255 on user cancel, other non-zero codes on error |
||||
*/ |
||||
public static int execute(final String command) { |
||||
return execute(parseArguments(command)); |
||||
} |
||||
|
||||
/** |
||||
* <p>Asynchronously executes FFmpeg command provided. Space character is used to split command |
||||
* into arguments. You can use single and double quote characters to specify arguments inside |
||||
* your command. |
||||
* |
||||
* @param command FFmpeg command |
||||
* @param executeCallback callback that will be notified when execution is completed |
||||
* @return returns a unique id that represents this execution |
||||
*/ |
||||
public static long executeAsync(final String command, final ExecuteCallback executeCallback) { |
||||
final long newExecutionId = executionIdCounter.incrementAndGet(); |
||||
|
||||
AsyncFFmpegExecuteTask asyncFFmpegExecuteTask = new AsyncFFmpegExecuteTask(newExecutionId, command, executeCallback); |
||||
asyncFFmpegExecuteTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); |
||||
|
||||
return newExecutionId; |
||||
} |
||||
|
||||
/** |
||||
* <p>Asynchronously executes FFmpeg command provided. Space character is used to split command |
||||
* into arguments. You can use single and double quote characters to specify arguments inside |
||||
* your command. |
||||
* |
||||
* @param command FFmpeg command |
||||
* @param executeCallback callback that will be notified when execution is completed |
||||
* @param executor executor that will be used to run this asynchronous operation |
||||
* @return returns a unique id that represents this execution |
||||
*/ |
||||
public static long executeAsync(final String command, final ExecuteCallback executeCallback, final Executor executor) { |
||||
final long newExecutionId = executionIdCounter.incrementAndGet(); |
||||
|
||||
AsyncFFmpegExecuteTask asyncFFmpegExecuteTask = new AsyncFFmpegExecuteTask(newExecutionId, command, executeCallback); |
||||
asyncFFmpegExecuteTask.executeOnExecutor(executor); |
||||
|
||||
return newExecutionId; |
||||
} |
||||
|
||||
/** |
||||
* <p>Cancels an ongoing operation. |
||||
* |
||||
* <p>This function does not wait for termination to complete and returns immediately. |
||||
*/ |
||||
public static void cancel() { |
||||
FFmpegKitConfig.nativeFFmpegCancel(DEFAULT_EXECUTION_ID); |
||||
} |
||||
|
||||
/** |
||||
* <p>Cancels an ongoing operation. |
||||
* |
||||
* <p>This function does not wait for termination to complete and returns immediately. |
||||
* |
||||
* @param executionId id of the execution |
||||
*/ |
||||
public static void cancel(final long executionId) { |
||||
FFmpegKitConfig.nativeFFmpegCancel(executionId); |
||||
} |
||||
|
||||
/** |
||||
* <p>Lists ongoing executions. |
||||
* |
||||
* @return list of ongoing executions |
||||
*/ |
||||
public static List<FFmpegExecution> listExecutions() { |
||||
return FFmpegKitConfig.listFFmpegExecutions(); |
||||
} |
||||
|
||||
/** |
||||
* <p>Parses the given command into arguments. |
||||
* |
||||
* @param command string command |
||||
* @return array of arguments |
||||
*/ |
||||
static String[] parseArguments(final String command) { |
||||
final List<String> argumentList = new ArrayList<>(); |
||||
StringBuilder currentArgument = new StringBuilder(); |
||||
|
||||
boolean singleQuoteStarted = false; |
||||
boolean doubleQuoteStarted = false; |
||||
|
||||
for (int i = 0; i < command.length(); i++) { |
||||
final Character previousChar; |
||||
if (i > 0) { |
||||
previousChar = command.charAt(i - 1); |
||||
} else { |
||||
previousChar = null; |
||||
} |
||||
final char currentChar = command.charAt(i); |
||||
|
||||
if (currentChar == ' ') { |
||||
if (singleQuoteStarted || doubleQuoteStarted) { |
||||
currentArgument.append(currentChar); |
||||
} else if (currentArgument.length() > 0) { |
||||
argumentList.add(currentArgument.toString()); |
||||
currentArgument = new StringBuilder(); |
||||
} |
||||
} else if (currentChar == '\'' && (previousChar == null || previousChar != '\\')) { |
||||
if (singleQuoteStarted) { |
||||
singleQuoteStarted = false; |
||||
} else if (doubleQuoteStarted) { |
||||
currentArgument.append(currentChar); |
||||
} else { |
||||
singleQuoteStarted = true; |
||||
} |
||||
} else if (currentChar == '\"' && (previousChar == null || previousChar != '\\')) { |
||||
if (doubleQuoteStarted) { |
||||
doubleQuoteStarted = false; |
||||
} else if (singleQuoteStarted) { |
||||
currentArgument.append(currentChar); |
||||
} else { |
||||
doubleQuoteStarted = true; |
||||
} |
||||
} else { |
||||
currentArgument.append(currentChar); |
||||
} |
||||
} |
||||
|
||||
if (currentArgument.length() > 0) { |
||||
argumentList.add(currentArgument.toString()); |
||||
} |
||||
|
||||
return argumentList.toArray(new String[0]); |
||||
} |
||||
|
||||
/** |
||||
* <p>Combines arguments into a string. |
||||
* |
||||
* @param arguments arguments |
||||
* @return string containing all arguments |
||||
*/ |
||||
static String argumentsToString(final String[] arguments) { |
||||
if (arguments == null) { |
||||
return "null"; |
||||
} |
||||
|
||||
StringBuilder stringBuilder = new StringBuilder(); |
||||
for (int i = 0; i < arguments.length; i++) { |
||||
if (i > 0) { |
||||
stringBuilder.append(" "); |
||||
} |
||||
stringBuilder.append(arguments[i]); |
||||
} |
||||
|
||||
return stringBuilder.toString(); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,769 @@ |
||||
/* |
||||
* Copyright (c) 2018-2020 Taner Sener |
||||
* |
||||
* This file is part of FFmpegKit. |
||||
* |
||||
* FFmpegKit is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Lesser General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* FFmpegKit 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 Lesser General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General Public License |
||||
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
package com.arthenica.ffmpegkit; |
||||
|
||||
import android.content.Context; |
||||
import android.os.Build; |
||||
import android.util.Log; |
||||
|
||||
import java.io.File; |
||||
import java.io.FileOutputStream; |
||||
import java.io.IOException; |
||||
import java.util.ArrayList; |
||||
import java.util.Collections; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
import java.util.concurrent.atomic.AtomicReference; |
||||
|
||||
/** |
||||
* <p>This class is used to configure FFmpegKit library utilities/tools. |
||||
* |
||||
* <p>1. {@link LogCallback}: This class redirects FFmpeg/FFprobe output to Logcat by default. As |
||||
* an alternative, it is possible not to print messages to Logcat and pass them to a |
||||
* {@link LogCallback} function. This function can decide whether to print these logs, show them |
||||
* inside another container or ignore them. |
||||
* |
||||
* <p>2. {@link #setLogLevel(Level)}/{@link #getLogLevel()}: Use this methods to set/get |
||||
* FFmpeg/FFprobe log severity. |
||||
* |
||||
* <p>3. {@link StatisticsCallback}: It is possible to receive statistics about an ongoing |
||||
* operation by defining a {@link StatisticsCallback} function or by calling |
||||
* {@link #getLastReceivedStatistics()} method. |
||||
* |
||||
* <p>4. Font configuration: It is possible to register custom fonts with |
||||
* {@link #setFontconfigConfigurationPath(String)} and |
||||
* {@link #setFontDirectory(Context, String, Map)} methods. |
||||
*/ |
||||
public class FFmpegKitConfig { |
||||
|
||||
public static final int RETURN_CODE_SUCCESS = 0; |
||||
|
||||
public static final int RETURN_CODE_CANCEL = 255; |
||||
|
||||
private static int lastReturnCode = 0; |
||||
|
||||
/** |
||||
* Defines tag used for logging. |
||||
*/ |
||||
public static final String TAG = "ffmpeg-kit"; |
||||
|
||||
public static final String FFMPEG_KIT_PIPE_PREFIX = "mf_pipe_"; |
||||
|
||||
private static LogCallback logCallbackFunction; |
||||
|
||||
private static Level activeLogLevel; |
||||
|
||||
private static StatisticsCallback statisticsCallbackFunction; |
||||
|
||||
private static Statistics lastReceivedStatistics; |
||||
|
||||
private static int lastCreatedPipeIndex; |
||||
|
||||
private static final List<FFmpegExecution> executions; |
||||
|
||||
static { |
||||
|
||||
Log.i(FFmpegKitConfig.TAG, "Loading ffmpeg-kit."); |
||||
|
||||
boolean nativeFFmpegLoaded = false; |
||||
boolean nativeFFmpegTriedAndFailed = false; |
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { |
||||
|
||||
/* LOADING LIBRARIES MANUALLY ON API < 21 */ |
||||
final List<String> externalLibrariesEnabled = getExternalLibraries(); |
||||
if (externalLibrariesEnabled.contains("tesseract") || externalLibrariesEnabled.contains("x265") || externalLibrariesEnabled.contains("snappy") || externalLibrariesEnabled.contains("openh264") || externalLibrariesEnabled.contains("rubberband")) { |
||||
System.loadLibrary("c++_shared"); |
||||
} |
||||
|
||||
if (AbiDetect.ARM_V7A.equals(AbiDetect.getNativeAbi())) { |
||||
try { |
||||
System.loadLibrary("avutil_neon"); |
||||
System.loadLibrary("swscale_neon"); |
||||
System.loadLibrary("swresample_neon"); |
||||
System.loadLibrary("avcodec_neon"); |
||||
System.loadLibrary("avformat_neon"); |
||||
System.loadLibrary("avfilter_neon"); |
||||
System.loadLibrary("avdevice_neon"); |
||||
nativeFFmpegLoaded = true; |
||||
} catch (final UnsatisfiedLinkError e) { |
||||
Log.i(FFmpegKitConfig.TAG, "NEON supported armeabi-v7a ffmpeg library not found. Loading default armeabi-v7a library.", e); |
||||
nativeFFmpegTriedAndFailed = true; |
||||
} |
||||
} |
||||
|
||||
if (!nativeFFmpegLoaded) { |
||||
System.loadLibrary("avutil"); |
||||
System.loadLibrary("swscale"); |
||||
System.loadLibrary("swresample"); |
||||
System.loadLibrary("avcodec"); |
||||
System.loadLibrary("avformat"); |
||||
System.loadLibrary("avfilter"); |
||||
System.loadLibrary("avdevice"); |
||||
} |
||||
} |
||||
|
||||
/* ALL FFMPEG-KIT LIBRARIES LOADED AT STARTUP */ |
||||
Abi.class.getName(); |
||||
FFmpegKit.class.getName(); |
||||
FFprobeKit.class.getName(); |
||||
|
||||
boolean nativeFFmpegKitLoaded = false; |
||||
if (!nativeFFmpegTriedAndFailed && AbiDetect.ARM_V7A.equals(AbiDetect.getNativeAbi())) { |
||||
try { |
||||
|
||||
/* |
||||
* THE TRY TO LOAD ARM-V7A-NEON FIRST. IF NOT LOAD DEFAULT ARM-V7A |
||||
*/ |
||||
|
||||
System.loadLibrary("ffmpegkit_armv7a_neon"); |
||||
nativeFFmpegKitLoaded = true; |
||||
AbiDetect.setArmV7aNeonLoaded(true); |
||||
} catch (final UnsatisfiedLinkError e) { |
||||
Log.i(FFmpegKitConfig.TAG, "NEON supported armeabi-v7a ffmpegkit library not found. Loading default armeabi-v7a library.", e); |
||||
} |
||||
} |
||||
|
||||
if (!nativeFFmpegKitLoaded) { |
||||
System.loadLibrary("ffmpegkit"); |
||||
} |
||||
|
||||
Log.i(FFmpegKitConfig.TAG, String.format("Loaded ffmpeg-kit-%s-%s-%s-%s.", getPackageName(), AbiDetect.getAbi(), getVersion(), getBuildDate())); |
||||
|
||||
/* NATIVE LOG LEVEL IS RECEIVED ONLY ON STARTUP */ |
||||
activeLogLevel = Level.from(getNativeLogLevel()); |
||||
|
||||
lastReceivedStatistics = new Statistics(); |
||||
|
||||
enableRedirection(); |
||||
|
||||
lastCreatedPipeIndex = 0; |
||||
|
||||
executions = Collections.synchronizedList(new ArrayList<FFmpegExecution>()); |
||||
} |
||||
|
||||
/** |
||||
* Default constructor hidden. |
||||
*/ |
||||
private FFmpegKitConfig() { |
||||
} |
||||
|
||||
/** |
||||
* <p>Enables log and statistics redirection. |
||||
* <p>When redirection is not enabled FFmpeg/FFprobe logs are printed to stderr. By enabling |
||||
* redirection, they are routed to Logcat and can be routed further to a callback function. |
||||
* <p>Statistics redirection behaviour is similar. Statistics are not printed at all if |
||||
* redirection is not enabled. If it is enabled then it is possible to define a statistics |
||||
* callback function but if you don't, they are not printed anywhere and only saved as |
||||
* <code>lastReceivedStatistics</code> data which can be polled with |
||||
* {@link #getLastReceivedStatistics()}. |
||||
* <p>Note that redirection is enabled by default. If you do not want to use its functionality |
||||
* please use {@link #disableRedirection()} to disable it. |
||||
*/ |
||||
public static void enableRedirection() { |
||||
enableNativeRedirection(); |
||||
} |
||||
|
||||
/** |
||||
* <p>Disables log and statistics redirection. |
||||
*/ |
||||
public static void disableRedirection() { |
||||
disableNativeRedirection(); |
||||
} |
||||
|
||||
/** |
||||
* Returns log level. |
||||
* |
||||
* @return log level |
||||
*/ |
||||
public static Level getLogLevel() { |
||||
return activeLogLevel; |
||||
} |
||||
|
||||
/** |
||||
* Sets log level. |
||||
* |
||||
* @param level log level |
||||
*/ |
||||
public static void setLogLevel(final Level level) { |
||||
if (level != null) { |
||||
activeLogLevel = level; |
||||
setNativeLogLevel(level.getValue()); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* <p>Sets a callback function to redirect FFmpeg/FFprobe logs. |
||||
* |
||||
* @param newLogCallback new log callback function or NULL to disable a previously defined callback |
||||
*/ |
||||
public static void enableLogCallback(final LogCallback newLogCallback) { |
||||
logCallbackFunction = newLogCallback; |
||||
} |
||||
|
||||
/** |
||||
* <p>Sets a callback function to redirect FFmpeg statistics. |
||||
* |
||||
* @param statisticsCallback new statistics callback function or NULL to disable a previously defined callback |
||||
*/ |
||||
public static void enableStatisticsCallback(final StatisticsCallback statisticsCallback) { |
||||
statisticsCallbackFunction = statisticsCallback; |
||||
} |
||||
|
||||
/** |
||||
* <p>Log redirection method called by JNI/native part. |
||||
* |
||||
* @param executionId id of the execution that generated this log, 0 by default |
||||
* @param levelValue log level as defined in {@link Level} |
||||
* @param logMessage redirected log message |
||||
*/ |
||||
private static void log(final long executionId, final int levelValue, final byte[] logMessage) { |
||||
final Level level = Level.from(levelValue); |
||||
final String text = new String(logMessage); |
||||
|
||||
// AV_LOG_STDERR logs are always redirected
|
||||
if ((activeLogLevel == Level.AV_LOG_QUIET && levelValue != Level.AV_LOG_STDERR.getValue()) || levelValue > activeLogLevel.getValue()) { |
||||
// LOG NEITHER PRINTED NOR FORWARDED
|
||||
return; |
||||
} |
||||
|
||||
if (logCallbackFunction != null) { |
||||
try { |
||||
logCallbackFunction.apply(new LogMessage(executionId, level, text)); |
||||
} catch (final Exception e) { |
||||
Log.e(FFmpegKitConfig.TAG, "Exception thrown inside LogCallback block", e); |
||||
} |
||||
} else { |
||||
switch (level) { |
||||
case AV_LOG_QUIET: { |
||||
// PRINT NO OUTPUT
|
||||
} |
||||
break; |
||||
case AV_LOG_TRACE: |
||||
case AV_LOG_DEBUG: { |
||||
android.util.Log.d(TAG, text); |
||||
} |
||||
break; |
||||
case AV_LOG_STDERR: |
||||
case AV_LOG_VERBOSE: { |
||||
android.util.Log.v(TAG, text); |
||||
} |
||||
break; |
||||
case AV_LOG_INFO: { |
||||
android.util.Log.i(TAG, text); |
||||
} |
||||
break; |
||||
case AV_LOG_WARNING: { |
||||
android.util.Log.w(TAG, text); |
||||
} |
||||
break; |
||||
case AV_LOG_ERROR: |
||||
case AV_LOG_FATAL: |
||||
case AV_LOG_PANIC: { |
||||
android.util.Log.e(TAG, text); |
||||
} |
||||
break; |
||||
default: { |
||||
android.util.Log.v(TAG, text); |
||||
} |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* <p>Statistics redirection method called by JNI/native part. |
||||
* |
||||
* @param executionId id of the execution that generated this statistics, 0 by default |
||||
* @param videoFrameNumber last processed frame number for videos |
||||
* @param videoFps frames processed per second for videos |
||||
* @param videoQuality quality of the video stream |
||||
* @param size size in bytes |
||||
* @param time processed duration in milliseconds |
||||
* @param bitrate output bit rate in kbits/s |
||||
* @param speed processing speed = processed duration / operation duration |
||||
*/ |
||||
private static void statistics(final long executionId, final int videoFrameNumber, |
||||
final float videoFps, final float videoQuality, final long size, |
||||
final int time, final double bitrate, final double speed) { |
||||
final Statistics newStatistics = new Statistics(executionId, videoFrameNumber, videoFps, videoQuality, size, time, bitrate, speed); |
||||
lastReceivedStatistics.update(newStatistics); |
||||
|
||||
if (statisticsCallbackFunction != null) { |
||||
try { |
||||
statisticsCallbackFunction.apply(lastReceivedStatistics); |
||||
} catch (final Exception e) { |
||||
Log.e(FFmpegKitConfig.TAG, "Exception thrown inside StatisticsCallback block", e); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* <p>Returns the last received statistics data. |
||||
* |
||||
* @return last received statistics data |
||||
*/ |
||||
public static Statistics getLastReceivedStatistics() { |
||||
return lastReceivedStatistics; |
||||
} |
||||
|
||||
/** |
||||
* <p>Resets last received statistics. It is recommended to call it before starting a new execution. |
||||
*/ |
||||
public static void resetStatistics() { |
||||
lastReceivedStatistics = new Statistics(); |
||||
} |
||||
|
||||
/** |
||||
* <p>Sets and overrides <code>fontconfig</code> configuration directory. |
||||
* |
||||
* @param path directory which contains fontconfig configuration (fonts.conf) |
||||
* @return zero on success, non-zero on error |
||||
*/ |
||||
public static int setFontconfigConfigurationPath(final String path) { |
||||
return setNativeEnvironmentVariable("FONTCONFIG_PATH", path); |
||||
} |
||||
|
||||
/** |
||||
* <p>Registers fonts inside the given path, so they are available to use in FFmpeg filters. |
||||
* |
||||
* <p>Note that you need to build <code>FFmpegKit</code> with <code>fontconfig</code> |
||||
* enabled or use a prebuilt package with <code>fontconfig</code> inside to use this feature. |
||||
* |
||||
* @param context application context to access application data |
||||
* @param fontDirectoryPath directory which contains fonts (.ttf and .otf files) |
||||
* @param fontNameMapping custom font name mappings, useful to access your fonts with more friendly names |
||||
*/ |
||||
public static void setFontDirectory(final Context context, final String fontDirectoryPath, final Map<String, String> fontNameMapping) { |
||||
final File cacheDir = context.getCacheDir(); |
||||
int validFontNameMappingCount = 0; |
||||
|
||||
final File tempConfigurationDirectory = new File(cacheDir, ".ffmpegkit"); |
||||
if (!tempConfigurationDirectory.exists()) { |
||||
boolean tempFontConfDirectoryCreated = tempConfigurationDirectory.mkdirs(); |
||||
Log.d(TAG, String.format("Created temporary font conf directory: %s.", tempFontConfDirectoryCreated)); |
||||
} |
||||
|
||||
final File fontConfiguration = new File(tempConfigurationDirectory, "fonts.conf"); |
||||
if (fontConfiguration.exists()) { |
||||
boolean fontConfigurationDeleted = fontConfiguration.delete(); |
||||
Log.d(TAG, String.format("Deleted old temporary font configuration: %s.", fontConfigurationDeleted)); |
||||
} |
||||
|
||||
/* PROCESS MAPPINGS FIRST */ |
||||
final StringBuilder fontNameMappingBlock = new StringBuilder(""); |
||||
if (fontNameMapping != null && (fontNameMapping.size() > 0)) { |
||||
fontNameMapping.entrySet(); |
||||
for (Map.Entry<String, String> mapping : fontNameMapping.entrySet()) { |
||||
String fontName = mapping.getKey(); |
||||
String mappedFontName = mapping.getValue(); |
||||
|
||||
if ((fontName != null) && (mappedFontName != null) && (fontName.trim().length() > 0) && (mappedFontName.trim().length() > 0)) { |
||||
fontNameMappingBlock.append(" <match target=\"pattern\">\n"); |
||||
fontNameMappingBlock.append(" <test qual=\"any\" name=\"family\">\n"); |
||||
fontNameMappingBlock.append(String.format(" <string>%s</string>\n", fontName)); |
||||
fontNameMappingBlock.append(" </test>\n"); |
||||
fontNameMappingBlock.append(" <edit name=\"family\" mode=\"assign\" binding=\"same\">\n"); |
||||
fontNameMappingBlock.append(String.format(" <string>%s</string>\n", mappedFontName)); |
||||
fontNameMappingBlock.append(" </edit>\n"); |
||||
fontNameMappingBlock.append(" </match>\n"); |
||||
|
||||
validFontNameMappingCount++; |
||||
} |
||||
} |
||||
} |
||||
|
||||
final String fontConfig = "<?xml version=\"1.0\"?>\n" + |
||||
"<!DOCTYPE fontconfig SYSTEM \"fonts.dtd\">\n" + |
||||
"<fontconfig>\n" + |
||||
" <dir>.</dir>\n" + |
||||
" <dir>" + fontDirectoryPath + "</dir>\n" + |
||||
fontNameMappingBlock + |
||||
"</fontconfig>"; |
||||
|
||||
final AtomicReference<FileOutputStream> reference = new AtomicReference<>(); |
||||
try { |
||||
final FileOutputStream outputStream = new FileOutputStream(fontConfiguration); |
||||
reference.set(outputStream); |
||||
|
||||
outputStream.write(fontConfig.getBytes()); |
||||
outputStream.flush(); |
||||
|
||||
Log.d(TAG, String.format("Saved new temporary font configuration with %d font name mappings.", validFontNameMappingCount)); |
||||
|
||||
setFontconfigConfigurationPath(tempConfigurationDirectory.getAbsolutePath()); |
||||
|
||||
Log.d(TAG, String.format("Font directory %s registered successfully.", fontDirectoryPath)); |
||||
|
||||
} catch (final IOException e) { |
||||
Log.e(TAG, String.format("Failed to set font directory: %s.", fontDirectoryPath), e); |
||||
} finally { |
||||
if (reference.get() != null) { |
||||
try { |
||||
reference.get().close(); |
||||
} catch (IOException e) { |
||||
// DO NOT PRINT THIS ERROR
|
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* <p>Returns package name. |
||||
* |
||||
* @return guessed package name according to supported external libraries |
||||
* @since 3.0 |
||||
*/ |
||||
public static String getPackageName() { |
||||
return Packages.getPackageName(); |
||||
} |
||||
|
||||
/** |
||||
* <p>Returns supported external libraries. |
||||
* |
||||
* @return list of supported external libraries |
||||
* @since 3.0 |
||||
*/ |
||||
public static List<String> getExternalLibraries() { |
||||
return Packages.getExternalLibraries(); |
||||
} |
||||
|
||||
/** |
||||
* <p>Creates a new named pipe to use in <code>FFmpeg</code> operations. |
||||
* |
||||
* <p>Please note that creator is responsible of closing created pipes. |
||||
* |
||||
* @param context application context |
||||
* @return the full path of named pipe |
||||
*/ |
||||
public static String registerNewFFmpegPipe(final Context context) { |
||||
|
||||
// PIPES ARE CREATED UNDER THE CACHE DIRECTORY
|
||||
final File cacheDir = context.getCacheDir(); |
||||
|
||||
final String newFFmpegPipePath = cacheDir + File.separator + FFMPEG_KIT_PIPE_PREFIX + (++lastCreatedPipeIndex); |
||||
|
||||
// FIRST CLOSE OLD PIPES WITH THE SAME NAME
|
||||
closeFFmpegPipe(newFFmpegPipePath); |
||||
|
||||
int rc = registerNewNativeFFmpegPipe(newFFmpegPipePath); |
||||
if (rc == 0) { |
||||
return newFFmpegPipePath; |
||||
} else { |
||||
Log.e(TAG, String.format("Failed to register new FFmpeg pipe %s. Operation failed with rc=%d.", newFFmpegPipePath, rc)); |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* <p>Closes a previously created <code>FFmpeg</code> pipe. |
||||
* |
||||
* @param ffmpegPipePath full path of ffmpeg pipe |
||||
*/ |
||||
public static void closeFFmpegPipe(final String ffmpegPipePath) { |
||||
File file = new File(ffmpegPipePath); |
||||
if (file.exists()) { |
||||
file.delete(); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Returns the list of camera ids supported. |
||||
* |
||||
* @param context application context |
||||
* @return the list of camera ids supported or an empty list if no supported camera is found |
||||
*/ |
||||
public static List<String> getSupportedCameraIds(final Context context) { |
||||
final List<String> detectedCameraIdList = new ArrayList<>(); |
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { |
||||
detectedCameraIdList.addAll(CameraSupport.extractSupportedCameraIds(context)); |
||||
} |
||||
|
||||
return detectedCameraIdList; |
||||
} |
||||
|
||||
/** |
||||
* <p>Returns FFmpeg version bundled within the library. |
||||
* |
||||
* @return FFmpeg version |
||||
*/ |
||||
public static String getFFmpegVersion() { |
||||
return getNativeFFmpegVersion(); |
||||
} |
||||
|
||||
/** |
||||
* <p>Returns FFmpegKit library version. |
||||
* |
||||
* @return FFmpegKit version |
||||
*/ |
||||
public static String getVersion() { |
||||
if (isLTSBuild()) { |
||||
return String.format("%s-lts", getNativeVersion()); |
||||
} else { |
||||
return getNativeVersion(); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* <p>Returns whether FFmpegKit release is a long term release or not. |
||||
* |
||||
* @return YES or NO |
||||
*/ |
||||
public static boolean isLTSBuild() { |
||||
return AbiDetect.isNativeLTSBuild(); |
||||
} |
||||
|
||||
/** |
||||
* <p>Returns FFmpegKit library build date. |
||||
* |
||||
* @return FFmpegKit library build date |
||||
*/ |
||||
public static String getBuildDate() { |
||||
return getNativeBuildDate(); |
||||
} |
||||
|
||||
/** |
||||
* <p>Returns return code of last executed command. |
||||
* |
||||
* @return return code of last executed command |
||||
* @since 3.0 |
||||
*/ |
||||
public static int getLastReturnCode() { |
||||
return lastReturnCode; |
||||
} |
||||
|
||||
/** |
||||
* <p>Returns log output of last executed single FFmpeg/FFprobe command. |
||||
* |
||||
* <p>This method does not support executing multiple concurrent commands. If you execute |
||||
* multiple commands at the same time, this method will return output from all executions. |
||||
* |
||||
* <p>Please note that disabling redirection using {@link FFmpegKitConfig#disableRedirection()} method |
||||
* also disables this functionality. |
||||
* |
||||
* @return output of the last executed command |
||||
* @since 3.0 |
||||
*/ |
||||
public static String getLastCommandOutput() { |
||||
String nativeLastCommandOutput = getNativeLastCommandOutput(); |
||||
if (nativeLastCommandOutput != null) { |
||||
|
||||
// REPLACING CH(13) WITH CH(10)
|
||||
nativeLastCommandOutput = nativeLastCommandOutput.replace('\r', '\n'); |
||||
} |
||||
return nativeLastCommandOutput; |
||||
} |
||||
|
||||
/** |
||||
* <p>Prints the output of the last executed FFmpeg/FFprobe command to the Logcat at the |
||||
* specified priority. |
||||
* |
||||
* <p>This method does not support executing multiple concurrent commands. If you execute |
||||
* multiple commands at the same time, this method will print output from all executions. |
||||
* |
||||
* @param logPriority one of {@link Log#VERBOSE}, {@link Log#DEBUG}, {@link Log#INFO}, |
||||
* {@link Log#WARN}, {@link Log#ERROR}, {@link Log#ASSERT} |
||||
* @since 4.3 |
||||
*/ |
||||
public static void printLastCommandOutput(int logPriority) { |
||||
final int LOGGER_ENTRY_MAX_LEN = 4 * 1000; |
||||
|
||||
String buffer = getLastCommandOutput(); |
||||
do { |
||||
if (buffer.length() <= LOGGER_ENTRY_MAX_LEN) { |
||||
Log.println(logPriority, FFmpegKitConfig.TAG, buffer); |
||||
buffer = ""; |
||||
} else { |
||||
final int index = buffer.substring(0, LOGGER_ENTRY_MAX_LEN).lastIndexOf('\n'); |
||||
if (index < 0) { |
||||
Log.println(logPriority, FFmpegKitConfig.TAG, buffer.substring(0, LOGGER_ENTRY_MAX_LEN)); |
||||
buffer = buffer.substring(LOGGER_ENTRY_MAX_LEN); |
||||
} else { |
||||
Log.println(logPriority, FFmpegKitConfig.TAG, buffer.substring(0, index)); |
||||
buffer = buffer.substring(index); |
||||
} |
||||
} |
||||
} while (buffer.length() > 0); |
||||
} |
||||
|
||||
/** |
||||
* <p>Sets an environment variable. |
||||
* |
||||
* @param variableName environment variable name |
||||
* @param variableValue environment variable value |
||||
* @return zero on success, non-zero on error |
||||
*/ |
||||
public static int setEnvironmentVariable(final String variableName, final String variableValue) { |
||||
return setNativeEnvironmentVariable(variableName, variableValue); |
||||
} |
||||
|
||||
/** |
||||
* <p>Registers a new ignored signal. Ignored signals are not handled by the library. |
||||
* |
||||
* @param signal signal number to ignore |
||||
*/ |
||||
public static void ignoreSignal(final Signal signal) { |
||||
ignoreNativeSignal(signal.getValue()); |
||||
} |
||||
|
||||
/** |
||||
* <p>Synchronously executes FFmpeg with arguments provided. |
||||
* |
||||
* @param executionId id of the execution |
||||
* @param arguments FFmpeg command options/arguments as string array |
||||
* @return zero on successful execution, 255 on user cancel and non-zero on error |
||||
*/ |
||||
static int ffmpegExecute(final long executionId, final String[] arguments) { |
||||
final FFmpegExecution currentFFmpegExecution = new FFmpegExecution(executionId, arguments); |
||||
executions.add(currentFFmpegExecution); |
||||
|
||||
try { |
||||
final int lastReturnCode = nativeFFmpegExecute(executionId, arguments); |
||||
|
||||
FFmpegKitConfig.setLastReturnCode(lastReturnCode); |
||||
|
||||
return lastReturnCode; |
||||
} finally { |
||||
executions.remove(currentFFmpegExecution); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Updates return code value for the last executed command. |
||||
* |
||||
* @param newLastReturnCode new last return code value |
||||
*/ |
||||
static void setLastReturnCode(int newLastReturnCode) { |
||||
lastReturnCode = newLastReturnCode; |
||||
} |
||||
|
||||
/** |
||||
* <p>Lists ongoing FFmpeg executions. |
||||
* |
||||
* @return list of ongoing FFmpeg executions |
||||
*/ |
||||
static List<FFmpegExecution> listFFmpegExecutions() { |
||||
return new ArrayList<>(executions); |
||||
} |
||||
|
||||
/** |
||||
* <p>Enables native redirection. Necessary for log and statistics callback functions. |
||||
*/ |
||||
private static native void enableNativeRedirection(); |
||||
|
||||
/** |
||||
* <p>Disables native redirection |
||||
*/ |
||||
private static native void disableNativeRedirection(); |
||||
|
||||
/** |
||||
* Sets native log level |
||||
* |
||||
* @param level log level |
||||
*/ |
||||
private static native void setNativeLogLevel(int level); |
||||
|
||||
/** |
||||
* Returns native log level. |
||||
* |
||||
* @return log level |
||||
*/ |
||||
private static native int getNativeLogLevel(); |
||||
|
||||
/** |
||||
* <p>Returns FFmpeg version bundled within the library natively. |
||||
* |
||||
* @return FFmpeg version |
||||
*/ |
||||
private native static String getNativeFFmpegVersion(); |
||||
|
||||
/** |
||||
* <p>Returns FFmpegKit library version natively. |
||||
* |
||||
* @return FFmpegKit version |
||||
*/ |
||||
private native static String getNativeVersion(); |
||||
|
||||
/** |
||||
* <p>Synchronously executes FFmpeg natively with arguments provided. |
||||
* |
||||
* @param executionId id of the execution |
||||
* @param arguments FFmpeg command options/arguments as string array |
||||
* @return zero on successful execution, 255 on user cancel and non-zero on error |
||||
*/ |
||||
private native static int nativeFFmpegExecute(final long executionId, final String[] arguments); |
||||
|
||||
/** |
||||
* <p>Cancels an ongoing FFmpeg operation natively. This function does not wait for termination |
||||
* to complete and returns immediately. |
||||
* |
||||
* @param executionId id of the execution |
||||
*/ |
||||
native static void nativeFFmpegCancel(final long executionId); |
||||
|
||||
/** |
||||
* <p>Synchronously executes FFprobe natively with arguments provided. |
||||
* |
||||
* @param arguments FFprobe command options/arguments as string array |
||||
* @return zero on successful execution, 255 on user cancel and non-zero on error |
||||
*/ |
||||
native static int nativeFFprobeExecute(final String[] arguments); |
||||
|
||||
/** |
||||
* <p>Creates natively a new named pipe to use in <code>FFmpeg</code> operations. |
||||
* |
||||
* <p>Please note that creator is responsible of closing created pipes. |
||||
* |
||||
* @param ffmpegPipePath full path of ffmpeg pipe |
||||
* @return zero on successful creation, non-zero on error |
||||
*/ |
||||
private native static int registerNewNativeFFmpegPipe(final String ffmpegPipePath); |
||||
|
||||
/** |
||||
* <p>Returns FFmpegKit library build date natively. |
||||
* |
||||
* @return FFmpegKit library build date |
||||
*/ |
||||
private native static String getNativeBuildDate(); |
||||
|
||||
/** |
||||
* <p>Sets an environment variable natively. |
||||
* |
||||
* @param variableName environment variable name |
||||
* @param variableValue environment variable value |
||||
* @return zero on success, non-zero on error |
||||
*/ |
||||
private native static int setNativeEnvironmentVariable(final String variableName, final String variableValue); |
||||
|
||||
/** |
||||
* <p>Returns log output of the last executed single command natively. |
||||
* |
||||
* @return output of the last executed single command |
||||
*/ |
||||
private native static String getNativeLastCommandOutput(); |
||||
|
||||
/** |
||||
* <p>Registers a new ignored signal natively. Ignored signals are not handled by the library. |
||||
* |
||||
* @param signum signal number |
||||
*/ |
||||
private native static void ignoreNativeSignal(final int signum); |
||||
|
||||
} |
||||
@ -0,0 +1,130 @@ |
||||
/* |
||||
* Copyright (c) 2020 Taner Sener |
||||
* |
||||
* This file is part of FFmpegKit. |
||||
* |
||||
* FFmpegKit is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Lesser General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* FFmpegKit 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 Lesser General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General Public License |
||||
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
package com.arthenica.ffmpegkit; |
||||
|
||||
import android.util.Log; |
||||
|
||||
/** |
||||
* <p>Main class for FFprobe operations. Provides {@link #execute(String...)} method to execute |
||||
* FFprobe commands. |
||||
* <pre> |
||||
* int rc = FFprobe.execute("-hide_banner -v error -show_entries format=size -of default=noprint_wrappers=1 file1.mp4"); |
||||
* Log.i(Config.TAG, String.format("Command execution %s.", (rc == 0?"completed successfully":"failed with rc=" + rc)); |
||||
* </pre> |
||||
*/ |
||||
public class FFprobeKit { |
||||
|
||||
static { |
||||
AbiDetect.class.getName(); |
||||
FFmpegKitConfig.class.getName(); |
||||
} |
||||
|
||||
/** |
||||
* Default constructor hidden. |
||||
*/ |
||||
private FFprobeKit() { |
||||
} |
||||
|
||||
/** |
||||
* <p>Synchronously executes FFprobe with arguments provided. |
||||
* |
||||
* @param arguments FFprobe command options/arguments as string array |
||||
* @return zero on successful execution, 255 on user cancel and non-zero on error |
||||
*/ |
||||
public static int execute(final String[] arguments) { |
||||
final int lastReturnCode = FFmpegKitConfig.nativeFFprobeExecute(arguments); |
||||
|
||||
FFmpegKitConfig.setLastReturnCode(lastReturnCode); |
||||
|
||||
return lastReturnCode; |
||||
} |
||||
|
||||
/** |
||||
* <p>Synchronously executes FFprobe command provided. Space character is used to split command |
||||
* into arguments. You can use single and double quote characters to specify arguments inside |
||||
* your command. |
||||
* |
||||
* @param command FFprobe command |
||||
* @return zero on successful execution, 255 on user cancel and non-zero on error |
||||
*/ |
||||
public static int execute(final String command) { |
||||
return execute(FFmpegKit.parseArguments(command)); |
||||
} |
||||
|
||||
/** |
||||
* <p>Returns media information for the given file. |
||||
* |
||||
* <p>This method does not support executing multiple concurrent operations. If you execute |
||||
* multiple operations (execute or getMediaInformation) at the same time, the response of this |
||||
* method is not predictable. |
||||
* |
||||
* @param path path or uri of media file |
||||
* @return media information |
||||
* @since 3.0 |
||||
*/ |
||||
public static MediaInformation getMediaInformation(final String path) { |
||||
return getMediaInformationFromCommandArguments(new String[]{"-v", "error", "-hide_banner", "-print_format", "json", "-show_format", "-show_streams", "-i", path}); |
||||
} |
||||
|
||||
/** |
||||
* <p>Returns media information for the given command. |
||||
* |
||||
* <p>This method does not support executing multiple concurrent operations. If you execute |
||||
* multiple operations (execute or getMediaInformation) at the same time, the response of this |
||||
* method is not predictable. |
||||
* |
||||
* @param command command to execute |
||||
* @return media information |
||||
* @since 4.3.3 |
||||
*/ |
||||
public static MediaInformation getMediaInformationFromCommand(final String command) { |
||||
return getMediaInformationFromCommandArguments(FFmpegKit.parseArguments(command)); |
||||
} |
||||
|
||||
/** |
||||
* <p>Returns media information for given file. |
||||
* |
||||
* <p>This method does not support executing multiple concurrent operations. If you execute |
||||
* multiple operations (execute or getMediaInformation) at the same time, the response of this |
||||
* method is not predictable. |
||||
* |
||||
* @param path path or uri of media file |
||||
* @param timeout complete timeout |
||||
* @return media information |
||||
* @since 3.0 |
||||
* @deprecated this method is deprecated since v4.3.1. You can still use this method but |
||||
* <code>timeout</code> parameter is not effective anymore. |
||||
*/ |
||||
public static MediaInformation getMediaInformation(final String path, final Long timeout) { |
||||
return getMediaInformation(path); |
||||
} |
||||
|
||||
private static MediaInformation getMediaInformationFromCommandArguments(final String[] arguments) { |
||||
final int rc = execute(arguments); |
||||
|
||||
if (rc == 0) { |
||||
return MediaInformationParser.from(FFmpegKitConfig.getLastCommandOutput()); |
||||
} else { |
||||
Log.w(FFmpegKitConfig.TAG, FFmpegKitConfig.getLastCommandOutput()); |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,30 @@ |
||||
/* |
||||
* Copyright (c) 2018-2020 Taner Sener |
||||
* |
||||
* This file is part of FFmpegKit. |
||||
* |
||||
* FFmpegKit is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Lesser General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* FFmpegKit 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 Lesser General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General Public License |
||||
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
package com.arthenica.ffmpegkit; |
||||
|
||||
/** |
||||
* <p>Represents a callback function to receive asynchronous getMediaInformation result. |
||||
*/ |
||||
@FunctionalInterface |
||||
public interface GetMediaInformationCallback { |
||||
|
||||
void apply(MediaInformation mediaInformation); |
||||
|
||||
} |
||||
@ -0,0 +1,132 @@ |
||||
/* |
||||
* Copyright (c) 2018-2020 Taner Sener |
||||
* |
||||
* This file is part of FFmpegKit. |
||||
* |
||||
* FFmpegKit is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Lesser General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* FFmpegKit 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 Lesser General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General Public License |
||||
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
package com.arthenica.ffmpegkit; |
||||
|
||||
/** |
||||
* <p>Helper enumeration type for log levels. |
||||
*/ |
||||
public enum Level { |
||||
|
||||
/** |
||||
* This log level is defined by FFmpegKit. It is used to specify logs printed to stderr by |
||||
* ffmpeg. Logs that has this level are not filtered and always redirected. |
||||
*/ |
||||
AV_LOG_STDERR(-16), |
||||
|
||||
/** |
||||
* Print no output. |
||||
*/ |
||||
AV_LOG_QUIET(-8), |
||||
|
||||
/** |
||||
* Something went really wrong and we will crash now. |
||||
*/ |
||||
AV_LOG_PANIC(0), |
||||
|
||||
/** |
||||
* Something went wrong and recovery is not possible. |
||||
* For example, no header was found for a format which depends |
||||
* on headers or an illegal combination of parameters is used. |
||||
*/ |
||||
AV_LOG_FATAL(8), |
||||
|
||||
/** |
||||
* Something went wrong and cannot losslessly be recovered. |
||||
* However, not all future data is affected. |
||||
*/ |
||||
AV_LOG_ERROR(16), |
||||
|
||||
/** |
||||
* Something somehow does not look correct. This may or may not |
||||
* lead to problems. An example would be the use of '-vstrict -2'. |
||||
*/ |
||||
AV_LOG_WARNING(24), |
||||
|
||||
/** |
||||
* Standard information. |
||||
*/ |
||||
AV_LOG_INFO(32), |
||||
|
||||
/** |
||||
* Detailed information. |
||||
*/ |
||||
AV_LOG_VERBOSE(40), |
||||
|
||||
/** |
||||
* Stuff which is only useful for libav* developers. |
||||
*/ |
||||
AV_LOG_DEBUG(48), |
||||
|
||||
/** |
||||
* Extremely verbose debugging, useful for libav* development. |
||||
*/ |
||||
AV_LOG_TRACE(56); |
||||
|
||||
private int value; |
||||
|
||||
/** |
||||
* <p>Returns enumeration defined by value. |
||||
* |
||||
* @param value level value |
||||
* @return enumeration defined by value |
||||
*/ |
||||
public static Level from(final int value) { |
||||
if (value == AV_LOG_STDERR.getValue()) { |
||||
return AV_LOG_STDERR; |
||||
} else if (value == AV_LOG_QUIET.getValue()) { |
||||
return AV_LOG_QUIET; |
||||
} else if (value == AV_LOG_PANIC.getValue()) { |
||||
return AV_LOG_PANIC; |
||||
} else if (value == AV_LOG_FATAL.getValue()) { |
||||
return AV_LOG_FATAL; |
||||
} else if (value == AV_LOG_ERROR.getValue()) { |
||||
return AV_LOG_ERROR; |
||||
} else if (value == AV_LOG_WARNING.getValue()) { |
||||
return AV_LOG_WARNING; |
||||