Compare commits
166 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c293dd421b | |||
| d46a5e1e66 | |||
| a32f0067d4 | |||
| aead62b215 | |||
| b20376a785 | |||
| e0b4aacf92 | |||
| c461ea76d3 | |||
| ff1b1c4935 | |||
| 28e52ed774 | |||
| b68ffc3053 | |||
| 1336eab42f | |||
| e01989639d | |||
| 1b041324b4 | |||
| df3faba968 | |||
| 1b3b2c3c2f | |||
| d9d31985df | |||
| 322877b3c3 | |||
| 9d414b9790 | |||
| 270fc3f1ad | |||
| d2ef2da94b | |||
| f92c5288b9 | |||
| 248a6cba7a | |||
| 318efe8a5d | |||
| ea9abafaa7 | |||
| 9ede8768f5 | |||
| 1fcf112ed0 | |||
| ace472d20c | |||
| 36fa6b0028 | |||
| 29ca9e37e7 | |||
| f0a65465e9 | |||
| 4808e4c686 | |||
| 41f55f415e | |||
| 3716c4623b | |||
| 7ccf16f130 | |||
| 2cc3a9b0db | |||
| 21c071bebe | |||
| caa4ac1f9b | |||
| 09caf1e997 | |||
| b3109cf276 | |||
| 4bd20725a8 | |||
| 0a127d4370 | |||
| ba7afe784d | |||
| e73224d560 | |||
| 4d544fa7ca | |||
| d500463706 | |||
| a3b95188fb | |||
| 7d27ab7be5 | |||
| 7681389a9c | |||
| e85b08e7c2 | |||
| d298c9ac3b | |||
| 5ffc79e879 | |||
| 2f08be1ff9 | |||
| 6f5262748f | |||
| e2a4766c61 | |||
| 63e87d04ef | |||
| fe73ca4697 | |||
| 68026adb2c | |||
| ede6a05766 | |||
| ba6c218b21 | |||
| 1d5b3f7603 | |||
| b33891eba9 | |||
| f7cbe9c006 | |||
| 84b740d514 | |||
| 703459c2cf | |||
| 04d2709eb4 | |||
| 05d2422bd5 | |||
| f57a3c6c05 | |||
| 5392566ed6 | |||
| 58cff5c8fb | |||
| 2f854d843a | |||
| 6d02e9b0dc | |||
| 156f51cacf | |||
| de7c992bd7 | |||
| 9ca086452c | |||
| b96ac2b4b3 | |||
| 05cc4f9998 | |||
| 870c674e0c | |||
| 166404fecc | |||
| 633238b79f | |||
| b6ac3d143d | |||
| e5581f60ce | |||
| 1ad6a02bf7 | |||
| 47d8c54da3 | |||
| e1870ecde9 | |||
| 761aa55a46 | |||
| 1e67fdb1e9 | |||
| da48d1edb8 | |||
| a7c009704e | |||
| c144aa3058 | |||
| c1584b8080 | |||
| dd6341359d | |||
| 107b5f1efd | |||
| 529893fd84 | |||
| 6aee1343f0 | |||
| c0d231337e | |||
| 77d8e86859 | |||
| a578211c67 | |||
| ef1bbd1c78 | |||
| 502df26547 | |||
| fa2d24e136 | |||
| 0eb3f23dde | |||
| 5b999a40c4 | |||
| 22bddcf207 | |||
| 49e7f5e312 | |||
| ecb97b6b9a | |||
| 043138e413 | |||
| 8cb63decf4 | |||
| c81ee56ab4 | |||
| 0a0f008aca | |||
| 328e37db0f | |||
| 4f36ac31fc | |||
| d0bc612062 | |||
| 701860d5ed | |||
| 172af56b15 | |||
| c4c5d60632 | |||
| 9bea827e39 | |||
| 71e7856102 | |||
| bc05d66b5b | |||
| a39d47f71a | |||
| 10b024082a | |||
| d109a8d3d8 | |||
| 6c49e64b66 | |||
| b076562170 | |||
| 149adaed4a | |||
| 4529ec7ba1 | |||
| 25d576abdb | |||
| e2ff9c62a6 | |||
| 5cdec4ed43 | |||
| c039a72e01 | |||
| 4d544be832 | |||
| 66267ef7f0 | |||
| f1c0224aac | |||
| da6a51af70 | |||
| 4c1cd17ba2 | |||
| c1789def81 | |||
| c9449c894e | |||
| 87d1a546ae | |||
| 4a221b2845 | |||
| 492626cc32 | |||
| 5010b2c8d4 | |||
| 7c8743ba07 | |||
| c829f6660f | |||
| c612d2eb15 | |||
| 0933a77265 | |||
| d96b96d12f | |||
| 3e64017839 | |||
| 6885e0aa3e | |||
| 63062cc425 | |||
| 2912f6e407 | |||
| 358dd529f9 | |||
| 0273d60b79 | |||
| 3572c52296 | |||
| 0d8bf5f33f | |||
| 725433e2d8 | |||
| 6687adae27 | |||
| 8b39af836f | |||
| 8474f2d9a8 | |||
| 0b6f2cb90b | |||
| f49e4ef27d | |||
| 44dd71f7b5 | |||
| c64c639fc9 | |||
| bbe441b2a8 | |||
| d3aca67c05 | |||
| 1d08c088a9 | |||
| 6f14c8db77 | |||
| 3e86f7f5f4 |
@@ -1,3 +1,4 @@
|
||||
*.log
|
||||
/prebuilt/
|
||||
*.DS_Store
|
||||
/.tmp/
|
||||
|
||||
@@ -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>.
|
||||
@@ -1,154 +1,263 @@
|
||||
# MobileFFmpeg
|
||||
Source code and scripts to build FFmpeg for Android and IOS platform
|
||||
# MobileFFmpeg [](https://gitter.im/mobile-ffmpeg/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)   
|
||||
|
||||
FFmpeg for Android and IOS
|
||||
|
||||
<img src="https://github.com/tanersener/mobile-ffmpeg/blob/dev-v2.x/docs/assets/mobile-ffmpeg-logo-v4.png" width="240">
|
||||
|
||||
### 1. Features
|
||||
- Builds both Android and IOS
|
||||
- Supports 18 external libraries and 10 architectures in total
|
||||
- Exposes FFmpeg capabilities both directly from FFmpeg libraries and through MobileFFmpeg wrapper library
|
||||
- Use binaries available at `Github`/`JCenter`/`CocoaPods` or build your own version with external libraries you need
|
||||
- Supports
|
||||
- Both Android and IOS
|
||||
- FFmpeg `v3.4.x` and `v4.0.x` releases
|
||||
- 24 external libraries
|
||||
|
||||
`chromaprint`, `fontconfig`, `freetype`, `fribidi`, `gmp`, `gnutls`, `kvazaar`, `lame`, `libaom`, `libass`, `libiconv`, `libilbc`, `libtheora`, `libvorbis`, `libvpx`, `libwebp`, `libxml2`, `opencore-amr`, `opus`, `shine`, `snappy`, `soxr`, `speex`, `wavpack`
|
||||
|
||||
- 4 external libraries with GPL license
|
||||
|
||||
`vid.stab`, `x264`, `x265`, `xvidcore`
|
||||
|
||||
- Exposes FFmpeg capabilities both from FFmpeg libraries and through MobileFFmpeg wrapper library
|
||||
- Creates shared libraries (.so for Android, .dylib for IOS)
|
||||
- Licensed under LGPL 3.0
|
||||
- Includes cross-compile instructions for 38 open-source libraries
|
||||
|
||||
`chromaprint`, `expat`, `ffmpeg`, `fontconfig`, `freetype`, `fribidi`, `giflib`, `gmp`, `gnutls`, `kvazaar`, `lame`, `libaom`, `libass`, `libiconv`, `libilbc`, `libjpeg`, `libjpeg-turbo`, `libogg`, `libpng`, `libtheora`, `libuuid`, `libvorbis`, `libvpx`, `libwebp`, `libxml2`, `nettle`, `opencore-amr`, `opus`, `shine`, `snappy`, `soxr`, `speex`, `tiff`, `vid.stab`, `wavpack`, `x264`, `x265`, `xvidcore`
|
||||
|
||||
- Licensed under LGPL 3.0, can be customized to support GPL v3.0
|
||||
#### 1.1 Android
|
||||
- Supports `arm-v7a`, `arm-v7a-neon`, `arm64-v8a`, `x86` and `x86_64` architectures
|
||||
- Creates Android archive with .aar extension
|
||||
#### 1.2 IOS
|
||||
- Creates IOS dynamic universal (fat) library
|
||||
- Supports `armv7`, `armv7s`, `arm64`, `i386` and `x86_64` architectures
|
||||
- `ARC` enabled library
|
||||
- Built with `-fembed-bitcode` flag
|
||||
- Creates IOS shared/dynamic universal (fat) library
|
||||
- Creates IOS static universal (fat) library
|
||||
- Creates IOS dynamic framework for IOS 8 or later
|
||||
- Supports Xcode 7.3.1 or later
|
||||
|
||||
### 2. Using
|
||||
Prebuilt libraries are available at [Github](https://github.com/tanersener/mobile-ffmpeg/releases), [JCenter](https://bintray.com/bintray/jcenter) and [CocoaPods](https://cocoapods.org). Refer to [Using IOS Universal Binaries](https://github.com/tanersener/mobile-ffmpeg/wiki/Using-IOS-Universal-Binaries) guide to import IOS universal binaries released at [Github](https://github.com/tanersener/mobile-ffmpeg/releases).
|
||||
|
||||
There are eight different prebuilt packages. Below you can see which external libraries are enabled in each of them.
|
||||
|
||||
| min | min-gpl | https | https-gpl | audio | video | full | full-gpl |
|
||||
| :----: | :----: | :----: | :----: | :----: | :----: | :----: | :----: |
|
||||
| - | vid.stab<sup>3</sup> <br/> x264<sup>1</sup> <br/> x265<sup>3</sup> <br/> xvidcore<sup>1</sup> | gnutls | gnutls <br/> vid.stab<sup>3</sup> <br/> x264<sup>1</sup> <br/> x265<sup>3</sup> <br/> xvidcore<sup>1</sup> | chromaprint<sup>3</sup> <br/> lame <br/> libilbc<sup>1</sup> <br/> libvorbis <br/> opencore-amr <br/> opus<sup>1</sup> <br/> shine <br/> soxr<sup>2</sup> <br/> speex <br/> wavpack | fontconfig <br/> freetype <br/> fribidi <br/> kvazaar <br/> libaom<sup>2</sup> <br/> libass <br/> libiconv <br/> libtheora <br/> libvpx <br/> snappy<sup>1</sup> | chromaprint<sup>3</sup> <br/> fontconfig <br/> freetype <br/> fribidi <br/> gmp <br/> gnutls <br/> kvazaar <br/> lame <br/> libaom<sup>2</sup> <br/> libass <br/> libiconv <br/> libilbc<sup>1</sup> <br/> libtheora <br/> libvorbis <br/> libvpx <br/> libwebp <br/> libxml2 <br/> opencore-amr <br/> opus<sup>1</sup> <br/> shine <br/> snappy<sup>1</sup> <br/> soxr<sup>2</sup> <br/> speex <br/> wavpack | chromaprint<sup>3</sup> <br/> fontconfig <br/> freetype <br/> fribidi <br/> gmp <br/> gnutls <br/> kvazaar <br/> lame <br/> libaom<sup>2</sup> <br/> libass <br/> libiconv <br/> libilbc<sup>1</sup> <br/> libtheora <br/> libvorbis <br/> libvpx <br/> libwebp <br/> libxml2 <br/> opencore-amr <br/> opus<sup>1</sup> <br/> shine <br/> snappy<sup>1</sup> <br/> soxr<sup>2</sup> <br/> speex <br/> vid.stab<sup>3</sup> <br/> wavpack <br/> x264<sup>1</sup> <br/> x265<sup>3</sup> <br/> xvidcore<sup>1</sup> |
|
||||
|
||||
<sup>1</sup> - Supported since `v1.1`
|
||||
|
||||
<sup>2</sup> - Supported since `v2.0`
|
||||
|
||||
<sup>3</sup> - Supported since `v2.1`
|
||||
|
||||
### 2. Architectures
|
||||
#### 2.1 Android
|
||||
- arm-v7a
|
||||
- arm-v7a-neon
|
||||
- arm64-v8a
|
||||
- x86
|
||||
- x86_64
|
||||
#### 2.2 IOS
|
||||
- armv7
|
||||
- armv7s
|
||||
- arm64
|
||||
- i386
|
||||
- x86_64
|
||||
1. Add MobileFFmpeg dependency from `jcenter()`
|
||||
```
|
||||
dependencies {`
|
||||
implementation 'com.arthenica:mobile-ffmpeg-full:2.2'
|
||||
}
|
||||
```
|
||||
|
||||
### 3. FFmpeg Support
|
||||
This repository branch contains FFmpeg version 3.4.2 with support for the following external libraries.
|
||||
- fontconfig
|
||||
- freetype
|
||||
- fribidi
|
||||
- gmp
|
||||
- gnutls
|
||||
- kvazaar
|
||||
- libiconv
|
||||
- lame
|
||||
- libass
|
||||
- libtheora
|
||||
- libvorbis
|
||||
- libvpx
|
||||
- libwebp
|
||||
- libxml2
|
||||
- opencore-amr
|
||||
- shine
|
||||
- speex
|
||||
- wavpack
|
||||
|
||||
External libraries and their dependencies are explained in the [External Libraries](https://github.com/tanersener/mobile-ffmpeg/wiki/External-Libraries) page.
|
||||
|
||||
### 4. Using
|
||||
#### 4.1 Android
|
||||
Import `mobile-ffmpeg-1.0.aar` into your project and use the following source code.
|
||||
```
|
||||
2. Execute commands.
|
||||
```
|
||||
import com.arthenica.mobileffmpeg.FFmpeg;
|
||||
|
||||
int rc = FFmpeg.execute("-i", "file1.mp4", "-c:v", "libxvid", "file1.avi");
|
||||
Log.i(Log.TAG, String.format("Command execution %s.", (rc == 0?"completed successfully":"failed with rc=" + rc));
|
||||
```
|
||||
#### 4.2 IOS
|
||||
Use MobileFFmpeg in your project by adding all IOS frameworks from `prebuilt/ios-framework` path or
|
||||
by adding all `ffmpeg` and `mobile-ffmpeg` dylibs with headers from folders inside `prebuilt/ios-universal`.
|
||||
int rc = FFmpeg.execute("-i file1.mp4 -c:v mpeg4 file2.mp4");
|
||||
|
||||
Then run the following Objective-C source code.
|
||||
```
|
||||
#import <mobileffmpeg/mobileffmpeg.h>
|
||||
|
||||
NSString* command = @"-i file1.mp4 -c:v libxvid file1.avi";
|
||||
NSArray* commandArray = [command componentsSeparatedByString:@" "];
|
||||
char **arguments = (char **)malloc(sizeof(char*) * ([commandArray count]));
|
||||
for (int i=0; i < [commandArray count]; i++) {
|
||||
NSString *argument = [commandArray objectAtIndex:i];
|
||||
arguments[i] = (char *) [argument UTF8String];
|
||||
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.", rc));
|
||||
}
|
||||
```
|
||||
|
||||
int result = mobileffmpeg_execute((int) [commandArray count], arguments);
|
||||
3. Stop an ongoing operation.
|
||||
```
|
||||
FFmpeg.cancel();
|
||||
```
|
||||
|
||||
NSLog(@"Process exited with rc %d\n", result);
|
||||
4. Enable log callback.
|
||||
```
|
||||
Config.enableLogCallback(new LogCallback() {
|
||||
public void apply(LogMessage message) {
|
||||
Log.d(Config.TAG, message.getText());
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
5. 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()));
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
6. Set log level.
|
||||
```
|
||||
Config.setLogLevel(Level.AV_LOG_FATAL);
|
||||
```
|
||||
|
||||
7. Register custom fonts directory.
|
||||
```
|
||||
Config.setFontDirectory(this, "<folder with fonts>", Collections.EMPTY_MAP);
|
||||
```
|
||||
|
||||
#### 2.2 IOS
|
||||
1. Add MobileFFmpeg pod to your `Podfile`
|
||||
```
|
||||
pod 'mobile-ffmpeg-full', '~> 2.2'
|
||||
```
|
||||
|
||||
2. Create and execute commands.
|
||||
```
|
||||
#import <mobileffmpeg/MobileFFmpeg.h>
|
||||
|
||||
int rc = [MobileFFmpeg 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.\n", rc);
|
||||
}
|
||||
```
|
||||
|
||||
3. Stop an ongoing operation.
|
||||
```
|
||||
[MobileFFmpeg cancel];
|
||||
```
|
||||
|
||||
4. Enable log callback.
|
||||
```
|
||||
- (void)logCallback: (int)level :(NSString*)message {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
NSLog(@"%@", message);
|
||||
});
|
||||
}
|
||||
...
|
||||
[MobileFFmpegConfig setLogDelegate:self];
|
||||
```
|
||||
|
||||
5. Enable statistics callback.
|
||||
```
|
||||
- (void)statisticsCallback:(Statistics *)newStatistics {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
NSLog(@"frame: %d, time: %d\n", newStatistics.getVideoFrameNumber, newStatistics.getTime);
|
||||
});
|
||||
}
|
||||
...
|
||||
[MobileFFmpegConfig setStatisticsDelegate:self];
|
||||
```
|
||||
|
||||
6. Set log level.
|
||||
```
|
||||
[MobileFFmpegConfig setLogLevel:AV_LOG_FATAL];
|
||||
```
|
||||
|
||||
7. Register custom fonts directory.
|
||||
```
|
||||
[MobileFFmpegConfig setFontDirectory:@"<folder with fonts>" with:nil];
|
||||
```
|
||||
|
||||
free(arguments);
|
||||
```
|
||||
#### 4.3 Test Application
|
||||
You can see how MobileFFmpeg is used inside an application by running test applications in this repository.
|
||||
There is an Android test application under the `android/test-app` folder and an IOS test application under the
|
||||
`ios/test-app` folder.
|
||||
#### 2.3 Test Application
|
||||
You can see how MobileFFmpeg is used inside an application by running test applications provided.
|
||||
There is an Android test application under the `android/test-app` folder and an IOS test application, which requires
|
||||
`Xcode 9.x` or later, under the `ios/test-app` folder. Both applications are identical and supports command
|
||||
execution, video encoding, accessing https, encoding audio, burning subtitles and video stabilization.
|
||||
|
||||
### 5. Building
|
||||
#### 5.1 Prerequisites
|
||||
<img src="https://github.com/tanersener/mobile-ffmpeg/blob/master/docs/assets/ios_test_app.gif" width="240">
|
||||
|
||||
### 3. Versions
|
||||
|
||||
- `MobileFFmpeg v1.x` is the previous stable, includes `FFmpeg v3.4.4`
|
||||
|
||||
- `MobileFFmpeg v2.x` is the current stable, includes `FFmpeg v4.0.3`
|
||||
|
||||
### 4. Building
|
||||
#### 4.1 Prerequisites
|
||||
1. Use your package manager (apt, yum, dnf, brew, etc.) to install the following packages.
|
||||
```
|
||||
autoconf automake libtool pkg-config gcc cmake gperf yasm texinfo
|
||||
```
|
||||
|
||||
```
|
||||
autoconf automake libtool pkg-config curl cmake gcc gperf texinfo yasm nasm bison
|
||||
```
|
||||
Some of these packages are not mandatory for the default build.
|
||||
Please visit [Android Prerequisites](https://github.com/tanersener/mobile-ffmpeg/wiki/Android-Prerequisites) and
|
||||
[IOS Prerequisites](https://github.com/tanersener/mobile-ffmpeg/wiki/IOS-Prerequisites) for the details.
|
||||
|
||||
2. Android builds require these additional packages.
|
||||
- **Android SDK 5.0 Lollipop (API Level 21)** or later
|
||||
- **Android NDK r16b** or later with LLDB and CMake
|
||||
- **gradle 4.4** or later
|
||||
- **Android SDK 5.0 Lollipop (API Level 21)** or later
|
||||
- **Android NDK r16b** or later with LLDB and CMake
|
||||
- **gradle 4.4** or later
|
||||
|
||||
3. IOS builds need these extra packages and tools.
|
||||
- **IOS SDK 7.0.x** or later
|
||||
- **Xcode 8.x** or later
|
||||
- **Command Line Tools**
|
||||
- **curl** and **lipo** utilities
|
||||
- **IOS SDK 7.0.x** or later
|
||||
- **Xcode 7.3.1** or later
|
||||
- **Command Line Tools**
|
||||
|
||||
#### 5.2 Build Scripts
|
||||
#### 4.2 Build Scripts
|
||||
Use `android.sh` and `ios.sh` to build MobileFFmpeg for each platform.
|
||||
After a successful build, compiled FFmpeg and MobileFFmpeg libraries can be found under `prebuilt` directory.
|
||||
|
||||
Both `android.sh` and `ios.sh` can be customized to override default settings,
|
||||
[android.sh](https://github.com/tanersener/mobile-ffmpeg/wiki/android.sh) and
|
||||
[ios.sh](https://github.com/tanersener/mobile-ffmpeg/wiki/ios.sh) wiki pages include all available build options.
|
||||
##### 5.2.1 Android
|
||||
##### 4.2.1 Android
|
||||
```
|
||||
export ANDROID_NDK_ROOT=<Android NDK Path>
|
||||
./android.sh
|
||||
```
|
||||
##### 5.2.2 IOS
|
||||
|
||||
<img src="https://github.com/tanersener/mobile-ffmpeg/blob/master/docs/assets/android_custom.gif" width="600">
|
||||
|
||||
##### 4.2.2 IOS
|
||||
```
|
||||
./ios.sh
|
||||
./ios.sh
|
||||
```
|
||||
|
||||
### 6. API
|
||||
<img src="https://github.com/tanersener/mobile-ffmpeg/blob/master/docs/assets/ios_custom.gif" width="600">
|
||||
|
||||
Below you can find documentation for all APIs exposed.
|
||||
#### 4.3 GPL Support
|
||||
It is possible to enable GPL licensed libraries `x264`, `xvidcore` since `v1.1` and `vid.stab`, `x265` since `v2.1`
|
||||
from the top level build scripts.
|
||||
Their source code is not included in the repository and downloaded when enabled.
|
||||
|
||||
[Android API](https://tanersener.github.io/mobile-ffmpeg/android/javadoc)
|
||||
#### 4.4 External Libraries
|
||||
`build` directory includes build scripts for external libraries. There are two scripts for each library, one for Android
|
||||
and one for IOS. They include all options/flags used to cross-compile the libraries. `ASM` is enabled by most of them,
|
||||
exceptions are listed under the [ASM Support](https://github.com/tanersener/mobile-ffmpeg/wiki/ASM-Support) page.
|
||||
|
||||
[Android Native API](https://tanersener.github.io/mobile-ffmpeg/ios/html)
|
||||
### 5. Documentation
|
||||
|
||||
[IOS API](https://tanersener.github.io/mobile-ffmpeg/android/doc/html)
|
||||
A more detailed documentation is available at [Wiki](https://github.com/tanersener/mobile-ffmpeg/wiki).
|
||||
|
||||
### 7. License
|
||||
### 6. License
|
||||
|
||||
This project is licensed under the LGPL v3.0.
|
||||
This project is licensed under the LGPL v3.0. However, if source code is built using optional `--enable-gpl` flag or
|
||||
prebuilt binaries with `-gpl` postfix are used then MobileFFmpeg is subject to the GPL v3.0 license.
|
||||
|
||||
Source code of FFmpeg and external libraries is included in compliance with their individual licenses.
|
||||
|
||||
Digital assets used in test applications are published in the public domain.
|
||||
`strip-frameworks.sh` script included and distributed is published under the [Apache License version 2.0](https://www.apache.org/licenses/LICENSE-2.0).
|
||||
|
||||
In test applications, fonts embedded 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/mobile-ffmpeg/wiki/License) page for the details.
|
||||
|
||||
### 8. Contributing
|
||||
### 7. Contributing
|
||||
|
||||
This project is stable but far from complete. If you have any recommendations or ideas to improve it, please feel free to submit issues or pull requests. Any help is appreciated.
|
||||
If you have any recommendations or ideas to improve it, please feel free to submit issues or pull requests. Any help is appreciated.
|
||||
|
||||
### 9. See Also
|
||||
### 8. See Also
|
||||
|
||||
- [FFmpeg API Documentation](https://ffmpeg.org/doxygen/3.4/index.html)
|
||||
- [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 License and Legal Considerations](https://ffmpeg.org/legal.html)
|
||||
- [FFmpeg External Library Licenses](https://www.ffmpeg.org/doxygen/4.0/md_LICENSE.html)
|
||||
|
||||
|
||||
@@ -26,24 +26,37 @@ LIBRARY_SHINE=14
|
||||
LIBRARY_SPEEX=15
|
||||
LIBRARY_WAVPACK=16
|
||||
LIBRARY_KVAZAAR=17
|
||||
LIBRARY_GIFLIB=18
|
||||
LIBRARY_JPEG=19
|
||||
LIBRARY_LIBOGG=20
|
||||
LIBRARY_LIBPNG=21
|
||||
LIBRARY_LIBUUID=22
|
||||
LIBRARY_NETTLE=23
|
||||
LIBRARY_TIFF=24
|
||||
LIBRARY_ZLIB=25
|
||||
LIBRARY_MEDIA_CODEC=26
|
||||
LIBRARY_X264=18
|
||||
LIBRARY_XVIDCORE=19
|
||||
LIBRARY_X265=20
|
||||
LIBRARY_LIBVIDSTAB=21
|
||||
LIBRARY_LIBILBC=22
|
||||
LIBRARY_OPUS=23
|
||||
LIBRARY_SNAPPY=24
|
||||
LIBRARY_SOXR=25
|
||||
LIBRARY_LIBAOM=26
|
||||
LIBRARY_CHROMAPRINT=27
|
||||
LIBRARY_GIFLIB=28
|
||||
LIBRARY_JPEG=29
|
||||
LIBRARY_LIBOGG=30
|
||||
LIBRARY_LIBPNG=31
|
||||
LIBRARY_LIBUUID=32
|
||||
LIBRARY_NETTLE=33
|
||||
LIBRARY_TIFF=34
|
||||
LIBRARY_EXPAT=35
|
||||
LIBRARY_ZLIB=36
|
||||
LIBRARY_MEDIA_CODEC=37
|
||||
|
||||
# ENABLE ARCH
|
||||
ENABLED_ARCHITECTURES=(1 1 1 1 1)
|
||||
|
||||
# ENABLE LIBRARIES
|
||||
ENABLED_LIBRARIES=(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)
|
||||
ENABLED_LIBRARIES=(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)
|
||||
|
||||
export BASEDIR=$(pwd)
|
||||
|
||||
export MOBILE_FFMPEG_TMPDIR="${BASEDIR}/.tmp"
|
||||
|
||||
# USING API LEVEL 21 / Android 5.0 (LOLLIPOP)
|
||||
export API=21
|
||||
|
||||
@@ -58,6 +71,7 @@ display_help() {
|
||||
|
||||
echo -e "\n'"$COMMAND"' builds FFmpeg and MobileFFmpeg for Android platform. By default five Android ABIs (armeabi-v7a, armeabi-v7a-neon, arm64-v8a, x86 and x86_64) are built \
|
||||
without any external libraries enabled. Options can be used to disable ABIs and/or enable external libraries. \
|
||||
Please note that GPL libraries (external libraries with GPL license) need --enable-gpl flag to be set explicitly. \
|
||||
When compilation ends an Android Archive (AAR) file is created with enabled platforms inside.\n"
|
||||
|
||||
echo -e "Usage: ./"$COMMAND" [OPTION]...\n"
|
||||
@@ -67,40 +81,62 @@ When compilation ends an Android Archive (AAR) file is created with enabled plat
|
||||
echo -e "Options:"
|
||||
|
||||
echo -e " -h, --help\t\t\tdisplay this help and exit"
|
||||
echo -e " -V, --version\t\t\tdisplay version information and exit\n"
|
||||
echo -e " -V, --version\t\t\tdisplay version information and exit"
|
||||
echo -e " -d, --debug\t\t\tbuild with debug information\n"
|
||||
|
||||
echo -e "Licensing options:"
|
||||
|
||||
echo -e " --enable-gpl\t\t\tallow use of GPL libraries, resulting libs will be licensed under GPLv3.0 [no]\n"
|
||||
|
||||
echo -e "Platforms:"
|
||||
|
||||
echo -e " --disable-arm-v7a\t\tdo not build arm-v7a platform"
|
||||
echo -e " --disable-arm-v7a-neon\tdo not build arm-v7a-neon platform"
|
||||
echo -e " --disable-arm64-v8a\t\tdo not build arm64-v8a platform"
|
||||
echo -e " --disable-x86\t\t\tdo not build x86 platform"
|
||||
echo -e " --disable-x86-64\t\tdo not build x86-64 platform\n"
|
||||
echo -e " --disable-arm-v7a\t\tdo not build arm-v7a platform [yes]"
|
||||
echo -e " --disable-arm-v7a-neon\tdo not build arm-v7a-neon platform [yes]"
|
||||
echo -e " --disable-arm64-v8a\t\tdo not build arm64-v8a platform [yes]"
|
||||
echo -e " --disable-x86\t\t\tdo not build x86 platform [yes]"
|
||||
echo -e " --disable-x86-64\t\tdo not build x86-64 platform [yes]\n"
|
||||
|
||||
echo -e "Libraries:"
|
||||
|
||||
echo -e " --full\t\t\tenables all external libraries"
|
||||
echo -e " --enable-android-media-codec\tbuild with built-in media codec"
|
||||
echo -e " --enable-android-zlib\t\tbuild with built-in zlib"
|
||||
echo -e " --enable-fontconfig\t\tbuild with fontconfig"
|
||||
echo -e " --enable-freetype\t\tbuild with freetype"
|
||||
echo -e " --enable-fribidi\t\tbuild with fribidi"
|
||||
echo -e " --enable-gnutls\t\tbuild with gnutls"
|
||||
echo -e " --enable-gmp\t\t\tbuild with gmp"
|
||||
echo -e " --enable-kvazaar\t\tbuild with kvazaar"
|
||||
echo -e " --enable-lame\t\t\tbuild with lame"
|
||||
echo -e " --enable-libass\t\tbuild with libass"
|
||||
echo -e " --enable-libiconv\t\tbuild with libiconv"
|
||||
echo -e " --enable-libtheora\t\tbuild with libtheora"
|
||||
echo -e " --enable-libvorbis\t\tbuild with libvorbis"
|
||||
echo -e " --enable-libvpx\t\tbuild with libvpx"
|
||||
echo -e " --enable-libwebp\t\tbuild with libwebp"
|
||||
echo -e " --enable-libxml2\t\tbuild with libxml2"
|
||||
echo -e " --enable-opencore-amr\t\tbuild with opencore-amr"
|
||||
echo -e " --enable-shine\t\tbuild with shine"
|
||||
echo -e " --enable-speex\t\tbuild with speex"
|
||||
echo -e " --enable-wavpack\t\tbuild with wavpack"
|
||||
echo -e " --reconf-LIBRARY\t\trun autoreconf before building LIBRARY\n"
|
||||
echo -e " --enable-android-media-codec\tbuild with built-in Android MediaCodec [no]"
|
||||
echo -e " --enable-android-zlib\t\tbuild with built-in zlib [no]"
|
||||
echo -e " --enable-chromaprint\t\tbuild with chromaprint [no]"
|
||||
echo -e " --enable-fontconfig\t\tbuild with fontconfig [no]"
|
||||
echo -e " --enable-freetype\t\tbuild with freetype [no]"
|
||||
echo -e " --enable-fribidi\t\tbuild with fribidi [no]"
|
||||
echo -e " --enable-gmp\t\t\tbuild with gmp [no]"
|
||||
echo -e " --enable-gnutls\t\tbuild with gnutls [no]"
|
||||
echo -e " --enable-kvazaar\t\tbuild with kvazaar [no]"
|
||||
echo -e " --enable-lame\t\t\tbuild with lame [no]"
|
||||
echo -e " --enable-libaom\t\tbuild with libaom [no]"
|
||||
echo -e " --enable-libass\t\tbuild with libass [no]"
|
||||
echo -e " --enable-libiconv\t\tbuild with libiconv [no]"
|
||||
echo -e " --enable-libilbc\t\tbuild with libilbc [no]"
|
||||
echo -e " --enable-libtheora\t\tbuild with libtheora [no]"
|
||||
echo -e " --enable-libvorbis\t\tbuild with libvorbis [no]"
|
||||
echo -e " --enable-libvpx\t\tbuild with libvpx [no]"
|
||||
echo -e " --enable-libwebp\t\tbuild with libwebp [no]"
|
||||
echo -e " --enable-libxml2\t\tbuild with libxml2 [no]"
|
||||
echo -e " --enable-opencore-amr\t\tbuild with opencore-amr [no]"
|
||||
echo -e " --enable-opus\t\t\tbuild with opus [no]"
|
||||
echo -e " --enable-shine\t\tbuild with shine [no]"
|
||||
echo -e " --enable-snappy\t\tbuild with snappy [no]"
|
||||
echo -e " --enable-soxr\t\t\tbuild with soxr [no]"
|
||||
echo -e " --enable-speex\t\tbuild with speex [no]"
|
||||
echo -e " --enable-wavpack\t\tbuild with wavpack [no]\n"
|
||||
|
||||
echo -e "GPL libraries:"
|
||||
|
||||
echo -e " --enable-libvidstab\t\tbuild with libvidstab [no]"
|
||||
echo -e " --enable-x264\t\t\tbuild with x264 [no]"
|
||||
echo -e " --enable-x265\t\t\tbuild with x265 [no]"
|
||||
echo -e " --enable-xvidcore\t\tbuild with xvidcore [no]\n"
|
||||
|
||||
echo -e "Advanced options:"
|
||||
|
||||
echo -e " --reconf-LIBRARY\t\trun autoreconf before building LIBRARY [no]"
|
||||
echo -e " --rebuild-LIBRARY\t\tbuild LIBRARY even it is detected as already built [no]\n"
|
||||
}
|
||||
|
||||
display_version() {
|
||||
@@ -116,12 +152,28 @@ 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."
|
||||
}
|
||||
|
||||
skip_library() {
|
||||
SKIP_VARIABLE=$(echo "SKIP_$1" | sed "s/\-/\_/g")
|
||||
|
||||
export ${SKIP_VARIABLE}=1
|
||||
}
|
||||
|
||||
enable_debug() {
|
||||
export MOBILE_FFMPEG_DEBUG="-d"
|
||||
}
|
||||
|
||||
reconf_library() {
|
||||
RECONF_VARIABLE=$(echo "RECONF_$1" | sed "s/\-/\_/g")
|
||||
|
||||
export ${RECONF_VARIABLE}=1
|
||||
}
|
||||
|
||||
rebuild_library() {
|
||||
REBUILD_VARIABLE=$(echo "REBUILD_$1" | sed "s/\-/\_/g")
|
||||
|
||||
export ${REBUILD_VARIABLE}=1
|
||||
}
|
||||
|
||||
enable_library() {
|
||||
set_library $1 1
|
||||
}
|
||||
@@ -134,15 +186,20 @@ set_library() {
|
||||
android-zlib)
|
||||
ENABLED_LIBRARIES[LIBRARY_ZLIB]=$2
|
||||
;;
|
||||
chromaprint)
|
||||
ENABLED_LIBRARIES[LIBRARY_CHROMAPRINT]=$2
|
||||
;;
|
||||
fontconfig)
|
||||
ENABLED_LIBRARIES[LIBRARY_FONTCONFIG]=$2
|
||||
ENABLED_LIBRARIES[LIBRARY_LIBUUID]=$2
|
||||
set_library "libxml2" $2
|
||||
ENABLED_LIBRARIES[LIBRARY_EXPAT]=$2
|
||||
ENABLED_LIBRARIES[LIBRARY_LIBICONV]=$2
|
||||
set_library "freetype" $2
|
||||
;;
|
||||
freetype)
|
||||
ENABLED_LIBRARIES[LIBRARY_FREETYPE]=$2
|
||||
ENABLED_LIBRARIES[LIBRARY_LIBPNG]=$2
|
||||
ENABLED_LIBRARIES[LIBRARY_ZLIB]=$2
|
||||
set_library "libpng" $2
|
||||
;;
|
||||
fribidi)
|
||||
ENABLED_LIBRARIES[LIBRARY_FRIBIDI]=$2
|
||||
@@ -152,7 +209,8 @@ set_library() {
|
||||
;;
|
||||
gnutls)
|
||||
ENABLED_LIBRARIES[LIBRARY_GNUTLS]=$2
|
||||
ENABLED_LIBRARIES[LIBRARY_NETTLE]=$2
|
||||
ENABLED_LIBRARIES[LIBRARY_ZLIB]=$2
|
||||
set_library "nettle" $2
|
||||
set_library "gmp" $2
|
||||
set_library "libiconv" $2
|
||||
;;
|
||||
@@ -163,23 +221,36 @@ set_library() {
|
||||
ENABLED_LIBRARIES[LIBRARY_LAME]=$2
|
||||
set_library "libiconv" $2
|
||||
;;
|
||||
libaom)
|
||||
ENABLED_LIBRARIES[LIBRARY_LIBAOM]=$2
|
||||
;;
|
||||
libass)
|
||||
ENABLED_LIBRARIES[LIBRARY_LIBASS]=$2
|
||||
ENABLED_LIBRARIES[LIBRARY_LIBUUID]=$2
|
||||
ENABLED_LIBRARIES[LIBRARY_EXPAT]=$2
|
||||
set_library "freetype" $2
|
||||
set_library "fribidi" $2
|
||||
set_library "fontconfig" $2
|
||||
set_library "libiconv" $2
|
||||
ENABLED_LIBRARIES[LIBRARY_LIBUUID]=$2
|
||||
set_library "libxml2" $2
|
||||
;;
|
||||
libiconv)
|
||||
ENABLED_LIBRARIES[LIBRARY_LIBICONV]=$2
|
||||
;;
|
||||
libilbc)
|
||||
ENABLED_LIBRARIES[LIBRARY_LIBILBC]=$2
|
||||
;;
|
||||
libpng)
|
||||
ENABLED_LIBRARIES[LIBRARY_LIBPNG]=$2
|
||||
ENABLED_LIBRARIES[LIBRARY_ZLIB]=$2
|
||||
;;
|
||||
libtheora)
|
||||
ENABLED_LIBRARIES[LIBRARY_LIBTHEORA]=$2
|
||||
ENABLED_LIBRARIES[LIBRARY_LIBOGG]=$2
|
||||
set_library "libvorbis" $2
|
||||
;;
|
||||
libvidstab)
|
||||
ENABLED_LIBRARIES[LIBRARY_LIBVIDSTAB]=$2
|
||||
;;
|
||||
libvorbis)
|
||||
ENABLED_LIBRARIES[LIBRARY_LIBVORBIS]=$2
|
||||
ENABLED_LIBRARIES[LIBRARY_LIBOGG]=$2
|
||||
@@ -191,8 +262,8 @@ set_library() {
|
||||
ENABLED_LIBRARIES[LIBRARY_LIBWEBP]=$2
|
||||
ENABLED_LIBRARIES[LIBRARY_GIFLIB]=$2
|
||||
ENABLED_LIBRARIES[LIBRARY_JPEG]=$2
|
||||
ENABLED_LIBRARIES[LIBRARY_LIBPNG]=$2
|
||||
ENABLED_LIBRARIES[LIBRARY_TIFF]=$2
|
||||
set_library "tiff" $2
|
||||
set_library "libpng" $2
|
||||
;;
|
||||
libxml2)
|
||||
ENABLED_LIBRARIES[LIBRARY_LIBXML2]=$2
|
||||
@@ -201,16 +272,44 @@ set_library() {
|
||||
opencore-amr)
|
||||
ENABLED_LIBRARIES[LIBRARY_OPENCOREAMR]=$2
|
||||
;;
|
||||
opus)
|
||||
ENABLED_LIBRARIES[LIBRARY_OPUS]=$2
|
||||
;;
|
||||
shine)
|
||||
ENABLED_LIBRARIES[LIBRARY_SHINE]=$2
|
||||
;;
|
||||
snappy)
|
||||
ENABLED_LIBRARIES[LIBRARY_SNAPPY]=$2
|
||||
ENABLED_LIBRARIES[LIBRARY_ZLIB]=$2
|
||||
;;
|
||||
soxr)
|
||||
ENABLED_LIBRARIES[LIBRARY_SOXR]=$2
|
||||
;;
|
||||
speex)
|
||||
ENABLED_LIBRARIES[LIBRARY_SPEEX]=$2
|
||||
;;
|
||||
wavpack)
|
||||
ENABLED_LIBRARIES[LIBRARY_WAVPACK]=$2
|
||||
;;
|
||||
giflib | jpeg | libogg | libpng | libuuid | nettle | tiff)
|
||||
x264)
|
||||
ENABLED_LIBRARIES[LIBRARY_X264]=$2
|
||||
;;
|
||||
x265)
|
||||
ENABLED_LIBRARIES[LIBRARY_X265]=$2
|
||||
;;
|
||||
xvidcore)
|
||||
ENABLED_LIBRARIES[LIBRARY_XVIDCORE]=$2
|
||||
;;
|
||||
tiff)
|
||||
ENABLED_LIBRARIES[LIBRARY_TIFF]=$2
|
||||
ENABLED_LIBRARIES[LIBRARY_JPEG]=$2
|
||||
;;
|
||||
nettle)
|
||||
ENABLED_LIBRARIES[LIBRARY_NETTLE]=$2
|
||||
set_library "gmp" $2
|
||||
;;
|
||||
giflib | jpeg | libogg | libpng | libuuid | expat)
|
||||
# THESE LIBRARIES ARE NOT ENABLED DIRECTLY
|
||||
;;
|
||||
*)
|
||||
print_unknown_library $1
|
||||
@@ -288,7 +387,7 @@ print_enabled_libraries() {
|
||||
let enabled=0;
|
||||
|
||||
# FIRST BUILT-IN LIBRARIES
|
||||
for library in {25..26}
|
||||
for library in {36..37}
|
||||
do
|
||||
if [[ ${ENABLED_LIBRARIES[$library]} -eq 1 ]]; then
|
||||
if [[ ${enabled} -ge 1 ]]; then
|
||||
@@ -300,7 +399,7 @@ print_enabled_libraries() {
|
||||
done
|
||||
|
||||
# THEN EXTERNAL LIBRARIES
|
||||
for library in {0..17}
|
||||
for library in {0..27}
|
||||
do
|
||||
if [[ ${ENABLED_LIBRARIES[$library]} -eq 1 ]]; then
|
||||
if [[ ${enabled} -ge 1 ]]; then
|
||||
@@ -338,6 +437,8 @@ EOF
|
||||
# ENABLE COMMON FUNCTIONS
|
||||
. ${BASEDIR}/build/android-common.sh
|
||||
|
||||
GPL_ENABLED="no"
|
||||
|
||||
while [ ! $# -eq 0 ]
|
||||
do
|
||||
|
||||
@@ -350,17 +451,35 @@ do
|
||||
display_version
|
||||
exit 0
|
||||
;;
|
||||
--skip-*)
|
||||
SKIP_LIBRARY=`echo $1 | sed -e 's/^--[A-Za-z]*-//g'`
|
||||
|
||||
skip_library ${SKIP_LIBRARY}
|
||||
;;
|
||||
-d | --debug)
|
||||
enable_debug
|
||||
;;
|
||||
--reconf-*)
|
||||
CONF_LIBRARY=`echo $1 | sed -e 's/^--[A-Za-z]*-//g'`
|
||||
|
||||
reconf_library ${CONF_LIBRARY}
|
||||
;;
|
||||
--rebuild-*)
|
||||
BUILD_LIBRARY=`echo $1 | sed -e 's/^--[A-Za-z]*-//g'`
|
||||
|
||||
rebuild_library ${BUILD_LIBRARY}
|
||||
;;
|
||||
--full)
|
||||
for library in {0..26}
|
||||
for library in {0..37}
|
||||
do
|
||||
enable_library $(get_library_name $library)
|
||||
if [[ $library -ne 18 ]] && [[ $library -ne 19 ]] && [[ $library -ne 20 ]] && [[ $library -ne 21 ]]; then
|
||||
enable_library $(get_library_name $library)
|
||||
fi
|
||||
done
|
||||
;;
|
||||
--enable-gpl)
|
||||
GPL_ENABLED="yes"
|
||||
;;
|
||||
--enable-*)
|
||||
ENABLED_LIBRARY=`echo $1 | sed -e 's/^--[A-Za-z]*-//g'`
|
||||
|
||||
@@ -384,17 +503,43 @@ if [[ -z ${ANDROID_NDK_ROOT} ]]; then
|
||||
fi
|
||||
|
||||
echo -e "Building mobile-ffmpeg for Android\n"
|
||||
echo -e -n "INFO: Building mobile-ffmpeg for Android: " 1>>${BASEDIR}/build.log 2>&1
|
||||
echo -e `date` 1>>${BASEDIR}/build.log 2>&1
|
||||
|
||||
if [[ ${ENABLED_ARCHITECTURES[0]} -eq 0 ]] && [[ ${ENABLED_ARCHITECTURES[1]} -eq 1 ]]; then
|
||||
ENABLED_ARCHITECTURES[0]=1
|
||||
|
||||
echo -e "(*) arm-v7a architecture enabled since arm-v7a-neon will be built\n"
|
||||
echo -e "(*) arm-v7a architecture enabled since arm-v7a-neon will be built\n" 2>>${BASEDIR}/build.log 1>>${BASEDIR}/build.log
|
||||
echo -e "(*) arm-v7a architecture enabled since arm-v7a-neon will be built\n" 1>>${BASEDIR}/build.log 2>&1
|
||||
fi
|
||||
|
||||
print_enabled_architectures
|
||||
print_enabled_libraries
|
||||
|
||||
# CHECKING GPL LIBRARIES
|
||||
for gpl_library in {18..21}
|
||||
do
|
||||
if [[ ${ENABLED_LIBRARIES[$gpl_library]} -eq 1 ]]; then
|
||||
library_name=$(get_library_name ${gpl_library})
|
||||
|
||||
if [ ${GPL_ENABLED} != "yes" ]; then
|
||||
echo -e "\n(*) Invalid configuration detected. GPL library ${library_name} enabled without --enable-gpl flag.\n"
|
||||
echo -e "\n(*) Invalid configuration detected. GPL library ${library_name} enabled without --enable-gpl flag.\n" 1>>${BASEDIR}/build.log 2>&1
|
||||
exit 1
|
||||
else
|
||||
DOWNLOAD_RESULT=$(download_gpl_library_source ${library_name})
|
||||
if [[ ${DOWNLOAD_RESULT} -ne 0 ]]; then
|
||||
echo -e "\n(*) Failed to download GPL library ${library_name} source. Please check build.log file for details. If the problem persists refer to offline building instructions.\n"
|
||||
echo -e "\n(*) Failed to download GPL library ${library_name} source.\n" 1>>${BASEDIR}/build.log 2>&1
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
# CLEANING PREVIOUSLY COPIED c++_shared.so FILES
|
||||
rm -rf ${BASEDIR}/prebuilt/android-cpp-shared 1>>${BASEDIR}/build.log 2>&1
|
||||
|
||||
for run_arch in {0..4}
|
||||
do
|
||||
if [[ ${ENABLED_ARCHITECTURES[$run_arch]} -eq 1 ]]; then
|
||||
@@ -404,22 +549,34 @@ do
|
||||
|
||||
create_toolchain || exit 1
|
||||
|
||||
# COPY libc++_shared.so FROM EACH TOOLCHAIN
|
||||
mkdir -p ${BASEDIR}/prebuilt/android-cpp-shared/${TOOLCHAIN_ARCH}
|
||||
|
||||
if [[ $run_arch -eq 0 ]] || [[ $run_arch -eq 1 ]]; then
|
||||
cp ${ANDROID_NDK_ROOT}/toolchains/mobile-ffmpeg-${TOOLCHAIN}/$(get_target_host)/lib/armv7-a/libc++_shared.so ${BASEDIR}/prebuilt/android-cpp-shared/${TOOLCHAIN_ARCH} 1>>${BASEDIR}/build.log 2>&1
|
||||
elif [[ $run_arch -eq 4 ]]; then
|
||||
cp ${ANDROID_NDK_ROOT}/toolchains/mobile-ffmpeg-${TOOLCHAIN}/$(get_target_host)/lib64/libc++_shared.so ${BASEDIR}/prebuilt/android-cpp-shared/${TOOLCHAIN_ARCH} 1>>${BASEDIR}/build.log 2>&1
|
||||
else
|
||||
cp ${ANDROID_NDK_ROOT}/toolchains/mobile-ffmpeg-${TOOLCHAIN}/$(get_target_host)/lib/libc++_shared.so ${BASEDIR}/prebuilt/android-cpp-shared/${TOOLCHAIN_ARCH} 1>>${BASEDIR}/build.log 2>&1
|
||||
fi
|
||||
|
||||
. ${BASEDIR}/build/main-android.sh "${ENABLED_LIBRARIES[@]}" || exit 1
|
||||
|
||||
# CLEAR FLAGS
|
||||
for library in {1..27}
|
||||
for library in {1..38}
|
||||
do
|
||||
library_name=$(get_library_name $((library - 1)))
|
||||
unset $(echo "OK_${library_name}" | sed "s/\-/\_/g")
|
||||
unset $(echo "DEPENDENCY_REBUILT_${library_name}" | sed "s/\-/\_/g")
|
||||
done
|
||||
fi
|
||||
done
|
||||
|
||||
rm -f ${BASEDIR}/android/build/.neon
|
||||
rm -f ${BASEDIR}/android/build/.neon 1>>${BASEDIR}/build.log 2>&1
|
||||
ANDROID_ARCHITECTURES=""
|
||||
if [[ ${ENABLED_ARCHITECTURES[1]} -eq 1 ]]; then
|
||||
ANDROID_ARCHITECTURES+="$(get_android_arch 0) "
|
||||
mkdir -p ${BASEDIR}/android/build
|
||||
mkdir -p ${BASEDIR}/android/build 1>>${BASEDIR}/build.log 2>&1
|
||||
cat > "${BASEDIR}/android/build/.neon" << EOF
|
||||
EOF
|
||||
elif [[ ${ENABLED_ARCHITECTURES[0]} -eq 1 ]]; then
|
||||
@@ -444,14 +601,13 @@ if [[ ! -z ${ANDROID_ARCHITECTURES} ]]; then
|
||||
MOBILE_FFMPEG_AAR=${BASEDIR}/prebuilt/android-aar/mobile-ffmpeg
|
||||
|
||||
# BUILDING ANDROID ARCHIVE LIBRARY
|
||||
rm -rf ${BASEDIR}/prebuilt/android-aar
|
||||
rm -rf ${BASEDIR}/android/libs
|
||||
rm -rf ${BASEDIR}/android/libs 1>>${BASEDIR}/build.log 2>&1
|
||||
|
||||
mkdir -p ${MOBILE_FFMPEG_AAR}
|
||||
mkdir -p ${MOBILE_FFMPEG_AAR} 1>>${BASEDIR}/build.log 2>&1
|
||||
|
||||
cd ${BASEDIR}/android
|
||||
cd ${BASEDIR}/android 1>>${BASEDIR}/build.log 2>&1
|
||||
|
||||
${ANDROID_NDK_ROOT}/ndk-build -B 2>>${BASEDIR}/build.log 1>>${BASEDIR}/build.log
|
||||
${ANDROID_NDK_ROOT}/ndk-build -B 1>>${BASEDIR}/build.log 2>&1
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "ok"
|
||||
@@ -462,16 +618,21 @@ if [[ ! -z ${ANDROID_ARCHITECTURES} ]]; then
|
||||
|
||||
echo -e -n "\n\nCreating Android archive under prebuilt/android-aar: "
|
||||
|
||||
gradle clean build 2>>${BASEDIR}/build.log 1>>${BASEDIR}/build.log
|
||||
gradle clean build 1>>${BASEDIR}/build.log 2>&1
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo -e "failed\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cp ${BASEDIR}/android/app/build/outputs/aar/mobile-ffmpeg-1.0.aar ${MOBILE_FFMPEG_AAR} || exit 1
|
||||
cp ${BASEDIR}/android/app/build/outputs/aar/mobile-ffmpeg-*.aar ${MOBILE_FFMPEG_AAR}/mobile-ffmpeg.aar 1>>${BASEDIR}/build.log 2>&1
|
||||
|
||||
echo -e "Created mobile-ffmpeg Android archive successfully.\n" >> ${BASEDIR}/build.log
|
||||
if [ $? -ne 0 ]; then
|
||||
echo -e "failed\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -e "Created mobile-ffmpeg Android archive successfully.\n" 1>>${BASEDIR}/build.log 2>&1
|
||||
|
||||
echo -e "ok\n"
|
||||
fi
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
/build
|
||||
/local.properties
|
||||
|
||||
@@ -38,7 +38,7 @@ PROJECT_NAME = "MobileFFmpeg Android API"
|
||||
# could be handy for archiving the generated documentation or if some version
|
||||
# control system is used.
|
||||
|
||||
PROJECT_NUMBER = 1.0
|
||||
PROJECT_NUMBER = 2.2
|
||||
|
||||
# Using the PROJECT_BRIEF tag one can provide an optional one line description
|
||||
# for a project that appears at the top of each page and should give viewer a
|
||||
|
||||
@@ -5,8 +5,8 @@ android {
|
||||
defaultConfig {
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 27
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
versionCode 22
|
||||
versionName "2.2"
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
project.archivesBaseName = "mobile-ffmpeg"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,180 @@
|
||||
apply plugin: 'com.android.library'
|
||||
apply plugin: 'com.github.dcendents.android-maven'
|
||||
apply plugin: 'com.jfrog.bintray'
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.1.4'
|
||||
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.1'
|
||||
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
|
||||
}
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdkVersion 27
|
||||
defaultConfig {
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 27
|
||||
versionCode Integer.parseInt(releaseVersionCode)
|
||||
versionName releaseVersionName
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
project.archivesBaseName = releaseProject
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
main {
|
||||
jniLibs.srcDirs = ["../libs"]
|
||||
}
|
||||
}
|
||||
|
||||
libraryVariants.all { variant ->
|
||||
variant.outputs.all { output ->
|
||||
if (outputFile != null && outputFileName.endsWith('.aar')) {
|
||||
outputFileName = "${archivesBaseName}-${android.defaultConfig.versionName}.aar"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ext {
|
||||
bintrayRepo = 'maven'
|
||||
bintrayName = releaseProject
|
||||
|
||||
publishedGroupId = 'com.arthenica'
|
||||
libraryName = releaseProject
|
||||
artifact = releaseProject
|
||||
|
||||
libraryDescription = releaseProjectDescription
|
||||
|
||||
siteUrl = 'https://github.com/tanersener/mobile-ffmpeg'
|
||||
gitUrl = 'https://github.com/tanersener/mobile-ffmpeg.git'
|
||||
|
||||
libraryVersion = releaseVersionName
|
||||
|
||||
developerId = 'tanersener'
|
||||
developerName = 'Taner Sener'
|
||||
developerEmail = 'tanersener@gmail.com'
|
||||
|
||||
if (Project.hasProperty('releaseGPL')) {
|
||||
licenseName = 'GNU General Public License version 3'
|
||||
licenseUrl = 'https://www.gnu.org/licenses/gpl-3.0.txt'
|
||||
allLicenses = ["GPL-3.0"]
|
||||
} else {
|
||||
licenseName = 'GNU Lesser General Public License, Version 3'
|
||||
licenseUrl = 'https://www.gnu.org/licenses/lgpl-3.0.txt'
|
||||
allLicenses = ["LGPL-3.0"]
|
||||
}
|
||||
}
|
||||
|
||||
group = publishedGroupId
|
||||
version = libraryVersion
|
||||
|
||||
install {
|
||||
repositories.mavenInstaller {
|
||||
pom.project {
|
||||
packaging 'aar'
|
||||
groupId publishedGroupId
|
||||
artifactId artifact
|
||||
|
||||
name libraryName
|
||||
description libraryDescription
|
||||
url siteUrl
|
||||
|
||||
licenses {
|
||||
license {
|
||||
name licenseName
|
||||
url licenseUrl
|
||||
}
|
||||
}
|
||||
developers {
|
||||
developer {
|
||||
id developerId
|
||||
name developerName
|
||||
email developerEmail
|
||||
}
|
||||
}
|
||||
scm {
|
||||
connection gitUrl
|
||||
developerConnection gitUrl
|
||||
url siteUrl
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Properties properties = new Properties()
|
||||
properties.load(project.rootProject.file('local.properties').newDataInputStream())
|
||||
|
||||
bintray {
|
||||
user = properties.getProperty("bintray.user")
|
||||
key = properties.getProperty("bintray.apikey")
|
||||
|
||||
configurations = ['archives']
|
||||
pkg {
|
||||
repo = bintrayRepo
|
||||
name = bintrayName
|
||||
desc = libraryDescription
|
||||
websiteUrl = siteUrl
|
||||
vcsUrl = gitUrl
|
||||
licenses = allLicenses
|
||||
dryRun = false
|
||||
publish = false
|
||||
override = false
|
||||
publicDownloadNumbers = false
|
||||
version {
|
||||
desc = libraryDescription
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
task sourcesJar(type: Jar) {
|
||||
classifier = 'sources'
|
||||
from android.sourceSets.main.java.srcDirs
|
||||
}
|
||||
|
||||
task javadoc(type: Javadoc) {
|
||||
title = 'MobileFFmpeg'
|
||||
source = android.sourceSets.main.java.srcDirs
|
||||
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
|
||||
}
|
||||
|
||||
task javadocJar(type: Jar, dependsOn: javadoc) {
|
||||
classifier = 'javadoc'
|
||||
from javadoc.destinationDir
|
||||
}
|
||||
|
||||
artifacts {
|
||||
archives javadocJar
|
||||
archives sourcesJar
|
||||
}
|
||||
|
||||
afterEvaluate {
|
||||
javadoc.classpath += files(android.libraryVariants.collect { variant ->
|
||||
variant.javaCompile.classpath.files
|
||||
})
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
implementation 'com.android.support:appcompat-v7:27.1.1'
|
||||
testImplementation 'junit:junit:4.12'
|
||||
androidTestImplementation 'com.android.support.test:runner:1.0.2'
|
||||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
}
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Taner Sener
|
||||
*
|
||||
* This file is part of MobileFFmpeg.
|
||||
*
|
||||
* MobileFFmpeg 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.
|
||||
*
|
||||
* MobileFFmpeg 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 MobileFFmpeg. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "cpu-features.h"
|
||||
#include "abidetect.h"
|
||||
|
||||
/** Full name of the Java class that owns native functions in this file. */
|
||||
const char *abiDetectClassName = "com/arthenica/mobileffmpeg/AbiDetect";
|
||||
|
||||
/** Prototypes of native functions defined by this file. */
|
||||
JNINativeMethod abiDetectMethods[] = {
|
||||
{"getAbi", "()Ljava/lang/String;", (void*) Java_com_arthenica_mobileffmpeg_AbiDetect_getAbi}
|
||||
};
|
||||
|
||||
/**
|
||||
* 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.", abiDetectClassName);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
jclass abiDetectClass = (*env)->FindClass(env, abiDetectClassName);
|
||||
if (abiDetectClass == NULL) {
|
||||
LOGE("OnLoad failed to FindClass %s.", abiDetectClassName);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
if ((*env)->RegisterNatives(env, abiDetectClass, abiDetectMethods, 1) < 0) {
|
||||
LOGE("OnLoad failed to RegisterNatives for class %s.", abiDetectClassName);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
return JNI_VERSION_1_6;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns running ABI name.
|
||||
*
|
||||
* \param env pointer to native method interface
|
||||
* \param object reference to the class on which this method is invoked
|
||||
* \return running ABI name as UTF string
|
||||
*/
|
||||
JNIEXPORT jstring JNICALL Java_com_arthenica_mobileffmpeg_AbiDetect_getAbi(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);
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Taner Sener
|
||||
*
|
||||
* This file is part of MobileFFmpeg.
|
||||
*
|
||||
* MobileFFmpeg 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.
|
||||
*
|
||||
* MobileFFmpeg 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 MobileFFmpeg. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef MOBILEFFMPEG_ABIDETECT_H
|
||||
#define MOBILEFFMPEG_ABIDETECT_H
|
||||
|
||||
#include <jni.h>
|
||||
#include "log.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_mobileffmpeg_AbiDetect
|
||||
* Method: getAbi
|
||||
* Signature: ()Ljava/lang/String;
|
||||
*/
|
||||
JNIEXPORT jstring JNICALL Java_com_arthenica_mobileffmpeg_AbiDetect_getAbi(JNIEnv *, jclass);
|
||||
|
||||
#endif /* MOBILEFFMPEG_ABIDETECT_H */
|
||||
@@ -1,670 +0,0 @@
|
||||
/*
|
||||
* 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 03.2018 Taner Sener
|
||||
* --------------------------------------------------------
|
||||
* - Include guards renamed
|
||||
* - log.h included
|
||||
* - Unused headers removed
|
||||
*/
|
||||
|
||||
#ifndef MOBILEFFMPEG_CMDUTILS_H
|
||||
#define MOBILEFFMPEG_CMDUTILS_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "libavcodec/avcodec.h"
|
||||
#include "libavfilter/avfilter.h"
|
||||
#include "libavformat/avformat.h"
|
||||
#include "libswscale/swscale.h"
|
||||
#include "log.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#undef main /* We don't want SDL to override our main() */
|
||||
#endif
|
||||
|
||||
/**
|
||||
* program name, defined by the program for show_version().
|
||||
*/
|
||||
extern const char program_name[];
|
||||
|
||||
/**
|
||||
* program birth year, defined by the program for show_banner()
|
||||
*/
|
||||
extern const int program_birth_year;
|
||||
|
||||
extern AVCodecContext *avcodec_opts[AVMEDIA_TYPE_NB];
|
||||
extern AVFormatContext *avformat_opts;
|
||||
extern AVDictionary *sws_dict;
|
||||
extern AVDictionary *swr_opts;
|
||||
extern AVDictionary *format_opts, *codec_opts, *resample_opts;
|
||||
extern int hide_banner;
|
||||
|
||||
/**
|
||||
* 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(const char *opt);
|
||||
|
||||
int opt_max_alloc(void *optctx, const char *opt, const char *arg);
|
||||
|
||||
int opt_codec_debug(void *optctx, const char *opt, const char *arg);
|
||||
|
||||
#if CONFIG_OPENCL
|
||||
int opt_opencl(void *optctx, const char *opt, const char *arg);
|
||||
|
||||
int opt_opencl_bench(void *optctx, const char *opt, const char *arg);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* 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;
|
||||
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);
|
||||
|
||||
#if CONFIG_OPENCL
|
||||
#define CMDUTILS_COMMON_OPTIONS_OPENCL \
|
||||
{ "opencl_bench", OPT_EXIT, {.func_arg = opt_opencl_bench}, \
|
||||
"run benchmark on all OpenCL devices and show results" }, \
|
||||
{ "opencl_options", HAS_ARG, {.func_arg = opt_opencl}, \
|
||||
"set OpenCL environment options" }, \
|
||||
|
||||
#else
|
||||
#define CMDUTILS_COMMON_OPTIONS_OPENCL
|
||||
#endif
|
||||
|
||||
#if CONFIG_AVDEVICE
|
||||
#define CMDUTILS_COMMON_OPTIONS_AVDEVICE \
|
||||
{ "sources" , OPT_EXIT | HAS_ARG, { .func_arg = show_sources }, \
|
||||
"list sources of the input device", "device" }, \
|
||||
{ "sinks" , OPT_EXIT | HAS_ARG, { .func_arg = show_sinks }, \
|
||||
"list sinks of the output device", "device" }, \
|
||||
|
||||
#else
|
||||
#define CMDUTILS_COMMON_OPTIONS_AVDEVICE
|
||||
#endif
|
||||
|
||||
#define CMDUTILS_COMMON_OPTIONS \
|
||||
{ "L", OPT_EXIT, { .func_arg = show_license }, "show license" }, \
|
||||
{ "h", OPT_EXIT, { .func_arg = show_help }, "show help", "topic" }, \
|
||||
{ "?", OPT_EXIT, { .func_arg = show_help }, "show help", "topic" }, \
|
||||
{ "help", OPT_EXIT, { .func_arg = show_help }, "show help", "topic" }, \
|
||||
{ "-help", OPT_EXIT, { .func_arg = show_help }, "show help", "topic" }, \
|
||||
{ "version", OPT_EXIT, { .func_arg = show_version }, "show version" }, \
|
||||
{ "buildconf", OPT_EXIT, { .func_arg = show_buildconf }, "show build configuration" }, \
|
||||
{ "formats", OPT_EXIT, { .func_arg = show_formats }, "show available formats" }, \
|
||||
{ "muxers", OPT_EXIT, { .func_arg = show_muxers }, "show available muxers" }, \
|
||||
{ "demuxers", OPT_EXIT, { .func_arg = show_demuxers }, "show available demuxers" }, \
|
||||
{ "devices", OPT_EXIT, { .func_arg = show_devices }, "show available devices" }, \
|
||||
{ "codecs", OPT_EXIT, { .func_arg = show_codecs }, "show available codecs" }, \
|
||||
{ "decoders", OPT_EXIT, { .func_arg = show_decoders }, "show available decoders" }, \
|
||||
{ "encoders", OPT_EXIT, { .func_arg = show_encoders }, "show available encoders" }, \
|
||||
{ "bsfs", OPT_EXIT, { .func_arg = show_bsfs }, "show available bit stream filters" }, \
|
||||
{ "protocols", OPT_EXIT, { .func_arg = show_protocols }, "show available protocols" }, \
|
||||
{ "filters", OPT_EXIT, { .func_arg = show_filters }, "show available filters" }, \
|
||||
{ "pix_fmts", OPT_EXIT, { .func_arg = show_pix_fmts }, "show available pixel formats" }, \
|
||||
{ "layouts", OPT_EXIT, { .func_arg = show_layouts }, "show standard channel layouts" }, \
|
||||
{ "sample_fmts", OPT_EXIT, { .func_arg = show_sample_fmts }, "show available audio sample formats" }, \
|
||||
{ "colors", OPT_EXIT, { .func_arg = show_colors }, "show available color names" }, \
|
||||
{ "loglevel", HAS_ARG, { .func_arg = opt_loglevel }, "set logging level", "loglevel" }, \
|
||||
{ "v", HAS_ARG, { .func_arg = opt_loglevel }, "set logging level", "loglevel" }, \
|
||||
{ "report", 0, { (void*)opt_report }, "generate a report" }, \
|
||||
{ "max_alloc", HAS_ARG, { .func_arg = opt_max_alloc }, "set maximum size of a single allocated block", "bytes" }, \
|
||||
{ "cpuflags", HAS_ARG | OPT_EXPERT, { .func_arg = opt_cpuflags }, "force specific cpu flags", "flags" }, \
|
||||
{ "hide_banner", OPT_BOOL | OPT_EXPERT, {&hide_banner}, "do not show program banner", "hide_banner" }, \
|
||||
CMDUTILS_COMMON_OPTIONS_OPENCL \
|
||||
CMDUTILS_COMMON_OPTIONS_AVDEVICE \
|
||||
|
||||
/**
|
||||
* 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 handler. Implemented in each
|
||||
* fftool, called by show_help().
|
||||
*/
|
||||
void show_help_default(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
|
||||
*/
|
||||
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_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 /* MOBILEFFMPEG_CMDUTILS_H */
|
||||
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Taner Sener
|
||||
*
|
||||
* This file is part of MobileFFmpeg.
|
||||
*
|
||||
* MobileFFmpeg 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.
|
||||
*
|
||||
* MobileFFmpeg 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 MobileFFmpeg. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef MOBILEFFMPEG_EXCEPTION_H
|
||||
#define MOBILEFFMPEG_EXCEPTION_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
/** Holds information to implement exception handling. */
|
||||
jmp_buf ex_buf__;
|
||||
|
||||
#endif // MOBILEFFMPEG_EXCEPTION_H
|
||||
@@ -1,719 +0,0 @@
|
||||
/*
|
||||
* 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 03.2018 Taner Sener
|
||||
* --------------------------------------------------------
|
||||
* - Include guards renamed
|
||||
* - log.h included
|
||||
* - mid_pred copied from libavcodec/mathops.h
|
||||
* - ff_dlog copied from libavutil/internal.h
|
||||
* - SWS_BILINEAR and SWS_BITEXACT definitions copied from libswscale/swscale.h
|
||||
*/
|
||||
|
||||
#ifndef MOBILEFFMPEG_FFMPEG_H
|
||||
#define MOBILEFFMPEG_FFMPEG_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "log.h"
|
||||
|
||||
#if HAVE_PTHREADS
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
#include "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/threadmessage.h"
|
||||
|
||||
#include "libswresample/swresample.h"
|
||||
|
||||
/* median of 3 */
|
||||
#ifndef mid_pred
|
||||
#define mid_pred mid_pred
|
||||
static inline av_const int mid_pred(int a, int b, int c)
|
||||
{
|
||||
if(a>b){
|
||||
if(c>b){
|
||||
if(c>a) b=a;
|
||||
else b=c;
|
||||
}
|
||||
}else{
|
||||
if(b>c){
|
||||
if(c>a) b=c;
|
||||
else b=a;
|
||||
}
|
||||
}
|
||||
return b;
|
||||
}
|
||||
#endif
|
||||
|
||||
#define SWS_BILINEAR 2
|
||||
#define SWS_BITEXACT 0x80000
|
||||
|
||||
#ifdef DEBUG
|
||||
# define ff_dlog(ctx, ...) av_log(ctx, AV_LOG_DEBUG, __VA_ARGS__)
|
||||
#else
|
||||
# define ff_dlog(ctx, ...) do { if (0) av_log(ctx, AV_LOG_DEBUG, __VA_ARGS__); } while (0)
|
||||
#endif
|
||||
|
||||
#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_VDPAU,
|
||||
HWACCEL_DXVA2,
|
||||
HWACCEL_VDA,
|
||||
HWACCEL_VIDEOTOOLBOX,
|
||||
HWACCEL_QSV,
|
||||
HWACCEL_VAAPI,
|
||||
HWACCEL_CUVID,
|
||||
HWACCEL_D3D11VA,
|
||||
};
|
||||
|
||||
typedef struct HWAccel {
|
||||
const char *name;
|
||||
int (*init)(AVCodecContext *s);
|
||||
enum HWAccelID id;
|
||||
enum AVPixelFormat pix_fmt;
|
||||
enum AVHWDeviceType device_type;
|
||||
} HWAccel;
|
||||
|
||||
typedef struct HWDevice {
|
||||
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 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;
|
||||
char *hwaccel_device;
|
||||
enum AVPixelFormat hwaccel_output_format;
|
||||
|
||||
/* hwaccel context */
|
||||
enum HWAccelID active_hwaccel_id;
|
||||
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_PTHREADS
|
||||
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_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;
|
||||
|
||||
AVCodecParserContext *parser;
|
||||
AVCodecContext *parser_avctx;
|
||||
|
||||
/* 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 InputStream **input_streams;
|
||||
extern int nb_input_streams;
|
||||
extern InputFile **input_files;
|
||||
extern int nb_input_files;
|
||||
|
||||
extern OutputStream **output_streams;
|
||||
extern int nb_output_streams;
|
||||
extern OutputFile **output_files;
|
||||
extern int nb_output_files;
|
||||
|
||||
extern FilterGraph **filtergraphs;
|
||||
extern int nb_filtergraphs;
|
||||
|
||||
extern char *vstats_filename;
|
||||
extern char *sdp_filename;
|
||||
|
||||
extern float audio_drift_threshold;
|
||||
extern float dts_delta_threshold;
|
||||
extern float dts_error_threshold;
|
||||
|
||||
extern int audio_volume;
|
||||
extern int audio_sync_method;
|
||||
extern int video_sync_method;
|
||||
extern float frame_drop_threshold;
|
||||
extern int do_benchmark;
|
||||
extern int do_benchmark_all;
|
||||
extern int do_deinterlace;
|
||||
extern int do_hex_dump;
|
||||
extern int do_pkt_dump;
|
||||
extern int copy_ts;
|
||||
extern int start_at_zero;
|
||||
extern int copy_tb;
|
||||
extern int debug_ts;
|
||||
extern int exit_on_error;
|
||||
extern int abort_on_flags;
|
||||
extern int print_stats;
|
||||
extern int qp_hist;
|
||||
extern int stdin_interaction;
|
||||
extern int frame_bits_per_raw_sample;
|
||||
extern AVIOContext *progress_avio;
|
||||
extern float max_error_rate;
|
||||
extern char *videotoolbox_pixfmt;
|
||||
|
||||
extern int filter_nbthreads;
|
||||
extern int filter_complex_nbthreads;
|
||||
extern int vstats_version;
|
||||
|
||||
extern const AVIOInterruptCB int_cb;
|
||||
|
||||
extern const OptionDef options[];
|
||||
extern const HWAccel hwaccels[];
|
||||
extern int hwaccel_lax_profile_check;
|
||||
extern AVBufferRef *hw_device_ctx;
|
||||
#if CONFIG_QSV
|
||||
extern char *qsv_device;
|
||||
#endif
|
||||
extern 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 vda_init(AVCodecContext *s);
|
||||
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);
|
||||
|
||||
#endif /* MOBILEFFMPEG_FFMPEG_H */
|
||||
@@ -1,385 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "libavutil/avstring.h"
|
||||
|
||||
#include "ffmpeg.h"
|
||||
|
||||
static int nb_hw_devices;
|
||||
static 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++];
|
||||
}
|
||||
|
||||
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;
|
||||
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 {
|
||||
// Give the device 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.
|
||||
size_t index_pos;
|
||||
int index, index_limit = 1000;
|
||||
index_pos = strlen(type_name);
|
||||
name = av_malloc(index_pos + 4);
|
||||
if (!name) {
|
||||
err = AVERROR(ENOMEM);
|
||||
goto fail;
|
||||
}
|
||||
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) {
|
||||
errmsg = "too many devices";
|
||||
goto invalid;
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
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,
|
||||
device ? device : p, 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;
|
||||
}
|
||||
|
||||
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 enum AVHWDeviceType hw_device_match_type_by_hwaccel(enum HWAccelID hwaccel_id)
|
||||
{
|
||||
int i;
|
||||
if (hwaccel_id == HWACCEL_NONE)
|
||||
return AV_HWDEVICE_TYPE_NONE;
|
||||
for (i = 0; hwaccels[i].name; i++) {
|
||||
if (hwaccels[i].id == hwaccel_id)
|
||||
return hwaccels[i].device_type;
|
||||
}
|
||||
return AV_HWDEVICE_TYPE_NONE;
|
||||
}
|
||||
|
||||
static enum AVHWDeviceType hw_device_match_type_in_name(const char *codec_name)
|
||||
{
|
||||
const char *type_name;
|
||||
enum AVHWDeviceType type;
|
||||
for (type = av_hwdevice_iterate_types(AV_HWDEVICE_TYPE_NONE);
|
||||
type != AV_HWDEVICE_TYPE_NONE;
|
||||
type = av_hwdevice_iterate_types(type)) {
|
||||
type_name = av_hwdevice_get_type_name(type);
|
||||
if (strstr(codec_name, type_name))
|
||||
return type;
|
||||
}
|
||||
return AV_HWDEVICE_TYPE_NONE;
|
||||
}
|
||||
|
||||
int hw_device_setup_for_decode(InputStream *ist)
|
||||
{
|
||||
enum AVHWDeviceType type;
|
||||
HWDevice *dev;
|
||||
int err;
|
||||
|
||||
if (ist->hwaccel_device) {
|
||||
dev = hw_device_get_by_name(ist->hwaccel_device);
|
||||
if (!dev) {
|
||||
char *tmp;
|
||||
type = hw_device_match_type_by_hwaccel(ist->hwaccel_id);
|
||||
if (type == AV_HWDEVICE_TYPE_NONE) {
|
||||
// No match - this isn't necessarily invalid, though,
|
||||
// because an explicit device might not be needed or
|
||||
// the hwaccel setup could be handled elsewhere.
|
||||
return 0;
|
||||
}
|
||||
tmp = av_asprintf("%s:%s", av_hwdevice_get_type_name(type),
|
||||
ist->hwaccel_device);
|
||||
if (!tmp)
|
||||
return AVERROR(ENOMEM);
|
||||
err = hw_device_init_from_string(tmp, &dev);
|
||||
av_free(tmp);
|
||||
if (err < 0)
|
||||
return err;
|
||||
}
|
||||
} else {
|
||||
if (ist->hwaccel_id != HWACCEL_NONE)
|
||||
type = hw_device_match_type_by_hwaccel(ist->hwaccel_id);
|
||||
else
|
||||
type = hw_device_match_type_in_name(ist->dec->name);
|
||||
if (type != AV_HWDEVICE_TYPE_NONE) {
|
||||
dev = hw_device_get_by_type(type);
|
||||
if (!dev) {
|
||||
hw_device_init_from_string(av_hwdevice_get_type_name(type),
|
||||
&dev);
|
||||
}
|
||||
} else {
|
||||
// No device required.
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!dev) {
|
||||
av_log(ist->dec_ctx, AV_LOG_WARNING, "No device available "
|
||||
"for decoder (device type %s for codec %s).\n",
|
||||
av_hwdevice_get_type_name(type), ist->dec->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
enum AVHWDeviceType type;
|
||||
HWDevice *dev;
|
||||
|
||||
type = hw_device_match_type_in_name(ost->enc->name);
|
||||
if (type != AV_HWDEVICE_TYPE_NONE) {
|
||||
dev = hw_device_get_by_type(type);
|
||||
if (!dev) {
|
||||
av_log(ost->enc_ctx, AV_LOG_WARNING, "No device available "
|
||||
"for encoder (device type %s for codec %s).\n",
|
||||
av_hwdevice_get_type_name(type), ost->enc->name);
|
||||
return 0;
|
||||
}
|
||||
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.
|
||||
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;
|
||||
}
|
||||
@@ -0,0 +1,659 @@
|
||||
/*
|
||||
* 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 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 "config.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
|
||||
|
||||
/**
|
||||
* program name, defined by the program for show_version().
|
||||
*/
|
||||
extern const char program_name[];
|
||||
|
||||
/**
|
||||
* program birth year, defined by the program for show_banner()
|
||||
*/
|
||||
extern const int program_birth_year;
|
||||
|
||||
extern AVCodecContext *avcodec_opts[AVMEDIA_TYPE_NB];
|
||||
extern AVFormatContext *avformat_opts;
|
||||
extern AVDictionary *sws_dict;
|
||||
extern AVDictionary *swr_opts;
|
||||
extern AVDictionary *format_opts, *codec_opts, *resample_opts;
|
||||
extern int hide_banner;
|
||||
|
||||
/**
|
||||
* 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(const char *opt);
|
||||
|
||||
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);
|
||||
|
||||
#if CONFIG_AVDEVICE
|
||||
#define CMDUTILS_COMMON_OPTIONS_AVDEVICE \
|
||||
{ "sources" , OPT_EXIT | HAS_ARG, { .func_arg = show_sources }, \
|
||||
"list sources of the input device", "device" }, \
|
||||
{ "sinks" , OPT_EXIT | HAS_ARG, { .func_arg = show_sinks }, \
|
||||
"list sinks of the output device", "device" }, \
|
||||
|
||||
#else
|
||||
#define CMDUTILS_COMMON_OPTIONS_AVDEVICE
|
||||
#endif
|
||||
|
||||
#define CMDUTILS_COMMON_OPTIONS \
|
||||
{ "L", OPT_EXIT, { .func_arg = show_license }, "show license" }, \
|
||||
{ "h", OPT_EXIT, { .func_arg = show_help }, "show help", "topic" }, \
|
||||
{ "?", OPT_EXIT, { .func_arg = show_help }, "show help", "topic" }, \
|
||||
{ "help", OPT_EXIT, { .func_arg = show_help }, "show help", "topic" }, \
|
||||
{ "-help", OPT_EXIT, { .func_arg = show_help }, "show help", "topic" }, \
|
||||
{ "version", OPT_EXIT, { .func_arg = show_version }, "show version" }, \
|
||||
{ "buildconf", OPT_EXIT, { .func_arg = show_buildconf }, "show build configuration" }, \
|
||||
{ "formats", OPT_EXIT, { .func_arg = show_formats }, "show available formats" }, \
|
||||
{ "muxers", OPT_EXIT, { .func_arg = show_muxers }, "show available muxers" }, \
|
||||
{ "demuxers", OPT_EXIT, { .func_arg = show_demuxers }, "show available demuxers" }, \
|
||||
{ "devices", OPT_EXIT, { .func_arg = show_devices }, "show available devices" }, \
|
||||
{ "codecs", OPT_EXIT, { .func_arg = show_codecs }, "show available codecs" }, \
|
||||
{ "decoders", OPT_EXIT, { .func_arg = show_decoders }, "show available decoders" }, \
|
||||
{ "encoders", OPT_EXIT, { .func_arg = show_encoders }, "show available encoders" }, \
|
||||
{ "bsfs", OPT_EXIT, { .func_arg = show_bsfs }, "show available bit stream filters" }, \
|
||||
{ "protocols", OPT_EXIT, { .func_arg = show_protocols }, "show available protocols" }, \
|
||||
{ "filters", OPT_EXIT, { .func_arg = show_filters }, "show available filters" }, \
|
||||
{ "pix_fmts", OPT_EXIT, { .func_arg = show_pix_fmts }, "show available pixel formats" }, \
|
||||
{ "layouts", OPT_EXIT, { .func_arg = show_layouts }, "show standard channel layouts" }, \
|
||||
{ "sample_fmts", OPT_EXIT, { .func_arg = show_sample_fmts }, "show available audio sample formats" }, \
|
||||
{ "colors", OPT_EXIT, { .func_arg = show_colors }, "show available color names" }, \
|
||||
{ "loglevel", HAS_ARG, { .func_arg = opt_loglevel }, "set logging level", "loglevel" }, \
|
||||
{ "v", HAS_ARG, { .func_arg = opt_loglevel }, "set logging level", "loglevel" }, \
|
||||
{ "report", 0, { (void*)opt_report }, "generate a report" }, \
|
||||
{ "max_alloc", HAS_ARG, { .func_arg = opt_max_alloc }, "set maximum size of a single allocated block", "bytes" }, \
|
||||
{ "cpuflags", HAS_ARG | OPT_EXPERT, { .func_arg = opt_cpuflags }, "force specific cpu flags", "flags" }, \
|
||||
{ "hide_banner", OPT_BOOL | OPT_EXPERT, {&hide_banner}, "do not show program banner", "hide_banner" }, \
|
||||
CMDUTILS_COMMON_OPTIONS_AVDEVICE \
|
||||
|
||||
/**
|
||||
* 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 handler. Implemented in each
|
||||
* fftool, called by show_help().
|
||||
*/
|
||||
void show_help_default(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
|
||||
*/
|
||||
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 */
|
||||
@@ -0,0 +1,683 @@
|
||||
/*
|
||||
* 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 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 "config.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 {
|
||||
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_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 InputStream **input_streams;
|
||||
extern int nb_input_streams;
|
||||
extern InputFile **input_files;
|
||||
extern int nb_input_files;
|
||||
|
||||
extern OutputStream **output_streams;
|
||||
extern int nb_output_streams;
|
||||
extern OutputFile **output_files;
|
||||
extern int nb_output_files;
|
||||
|
||||
extern FilterGraph **filtergraphs;
|
||||
extern int nb_filtergraphs;
|
||||
|
||||
extern char *vstats_filename;
|
||||
extern char *sdp_filename;
|
||||
|
||||
extern float audio_drift_threshold;
|
||||
extern float dts_delta_threshold;
|
||||
extern float dts_error_threshold;
|
||||
|
||||
extern int audio_volume;
|
||||
extern int audio_sync_method;
|
||||
extern int video_sync_method;
|
||||
extern float frame_drop_threshold;
|
||||
extern int do_benchmark;
|
||||
extern int do_benchmark_all;
|
||||
extern int do_deinterlace;
|
||||
extern int do_hex_dump;
|
||||
extern int do_pkt_dump;
|
||||
extern int copy_ts;
|
||||
extern int start_at_zero;
|
||||
extern int copy_tb;
|
||||
extern int debug_ts;
|
||||
extern int exit_on_error;
|
||||
extern int abort_on_flags;
|
||||
extern int print_stats;
|
||||
extern int qp_hist;
|
||||
extern int stdin_interaction;
|
||||
extern int frame_bits_per_raw_sample;
|
||||
extern AVIOContext *progress_avio;
|
||||
extern float max_error_rate;
|
||||
extern char *videotoolbox_pixfmt;
|
||||
|
||||
extern int filter_nbthreads;
|
||||
extern int filter_complex_nbthreads;
|
||||
extern int vstats_version;
|
||||
|
||||
extern const AVIOInterruptCB int_cb;
|
||||
|
||||
extern const OptionDef options[];
|
||||
extern const HWAccel hwaccels[];
|
||||
extern AVBufferRef *hw_device_ctx;
|
||||
#if CONFIG_QSV
|
||||
extern char *qsv_device;
|
||||
#endif
|
||||
extern 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();
|
||||
|
||||
#endif /* FFTOOLS_FFMPEG_H */
|
||||
@@ -0,0 +1,485 @@
|
||||
/*
|
||||
* 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 08.2018
|
||||
* --------------------------------------------------------
|
||||
* - fftools_ prefix added to file name and parent header
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "libavutil/avstring.h"
|
||||
|
||||
#include "fftools_ffmpeg.h"
|
||||
|
||||
static int nb_hw_devices;
|
||||
static 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;
|
||||
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) {
|
||||
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,
|
||||
device ? device : p, 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;
|
||||
}
|
||||
@@ -1,175 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Taner Sener
|
||||
*
|
||||
* This file is part of MobileFFmpeg.
|
||||
*
|
||||
* MobileFFmpeg 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.
|
||||
*
|
||||
* MobileFFmpeg 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 MobileFFmpeg. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "log.h"
|
||||
|
||||
/** Global reference to the virtual machine running */
|
||||
static JavaVM *globalVm;
|
||||
|
||||
/** Global reference of Log class in Java side */
|
||||
static jclass logClass;
|
||||
|
||||
/** Global reference of forward log method in Java side */
|
||||
static jmethodID logMethod;
|
||||
|
||||
/** file descriptor of the pipe created */
|
||||
static int pipeFd[2];
|
||||
|
||||
/** log collector thread variable */
|
||||
static pthread_t logThread;
|
||||
|
||||
/** Holds whether log collector thread is enabled or not */
|
||||
static int logThreadEnabled = 1;
|
||||
|
||||
/** Full name of the Java class that owns native functions in this file. */
|
||||
const char *logClassName = "com/arthenica/mobileffmpeg/Log";
|
||||
|
||||
/** Prototypes of native functions defined by this file. */
|
||||
JNINativeMethod logMethods[] = {
|
||||
{"startNativeCollector", "()I", (void*) Java_com_arthenica_mobileffmpeg_Log_startNativeCollector},
|
||||
{"stopNativeCollector", "()I", (void*) Java_com_arthenica_mobileffmpeg_Log_stopNativeCollector}
|
||||
};
|
||||
|
||||
/**
|
||||
* Called when 'ffmpeglog' native library is loaded.
|
||||
*
|
||||
* \param vm pointer to the running virtual machine
|
||||
* \param reserved reserved
|
||||
* \return JNI version needed by 'ffmpeglog' 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.", logClassName);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
(*env)->GetJavaVM(env, &globalVm);
|
||||
|
||||
jclass clazz = (*env)->FindClass(env, logClassName);
|
||||
if (clazz == NULL) {
|
||||
LOGE("OnLoad failed to FindClass %s.", logClassName);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
logMethod = (*env)->GetStaticMethodID(env, clazz, "log", "([B)V");
|
||||
if (logMethod == NULL) {
|
||||
LOGE("OnLoad thread failed to GetMethodID for %s.", "log");
|
||||
(*globalVm)->DetachCurrentThread(globalVm);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
if ((*env)->RegisterNatives(env, clazz, logMethods, 2) < 0) {
|
||||
LOGE("OnLoad failed to RegisterNatives for class %s.", logClassName);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
logClass = (jclass) ((*env)->NewGlobalRef(env, clazz));
|
||||
|
||||
return JNI_VERSION_1_6;
|
||||
}
|
||||
|
||||
/**
|
||||
* Native log collector main thread function.
|
||||
*/
|
||||
static void *logThreadFunction() {
|
||||
int readSize;
|
||||
char buffer[512];
|
||||
|
||||
JNIEnv *env;
|
||||
jint getEnvRc = (*globalVm)->GetEnv(globalVm, (void**) &env, JNI_VERSION_1_6);
|
||||
if (getEnvRc != JNI_OK) {
|
||||
if (getEnvRc != JNI_EDETACHED) {
|
||||
LOGE("Log thread failed to GetEnv for class %s with rc %d.", logClassName, getEnvRc);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
if ((*globalVm)->AttachCurrentThread(globalVm, &env, NULL) != 0) {
|
||||
LOGE("Log thread failed to AttachCurrentThread for class %s.", logClassName);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
LOGI("Native log thread started.");
|
||||
|
||||
while(logThreadEnabled && ((readSize = (int)read(pipeFd[0], buffer, sizeof(buffer) - 1)) > 0)) {
|
||||
if (readSize > 0) {
|
||||
if (buffer[readSize - 1] == '\n') {
|
||||
readSize--;
|
||||
}
|
||||
buffer[readSize] = 0; /* add null-terminator */
|
||||
|
||||
jbyteArray byteArray = (jbyteArray) (*env)->NewByteArray(env, readSize);
|
||||
(*env)->SetByteArrayRegion(env, byteArray, 0, readSize, (jbyte *)buffer);
|
||||
(*env)->CallStaticVoidMethod(env, logClass, logMethod, byteArray);
|
||||
(*env)->DeleteLocalRef(env, byteArray);
|
||||
}
|
||||
}
|
||||
|
||||
(*globalVm)->DetachCurrentThread(globalVm);
|
||||
|
||||
LOGI("Native log thread stopped.");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts native log collector. Native log collector creates a pipe and redirects stdout and stderr to it. Then starts
|
||||
* a thread, reads data written to this pipe and forwards it to the Java side.
|
||||
*
|
||||
* \param env pointer to native method interface
|
||||
* \param object reference to the object on which this method is invoked
|
||||
* \return zero on success, non-zero if an error occurs
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_com_arthenica_mobileffmpeg_Log_startNativeCollector(JNIEnv *env, jobject object) {
|
||||
|
||||
/* make stdout line-buffered and stderr unbuffered */
|
||||
setvbuf(stdout, 0, _IOLBF, 0);
|
||||
setvbuf(stderr, 0, _IONBF, 0);
|
||||
|
||||
/* create the pipe and redirect stdout and stderr */
|
||||
pipe(pipeFd);
|
||||
dup2(pipeFd[1], 1);
|
||||
dup2(pipeFd[1], 2);
|
||||
|
||||
/* spawn the logging thread */
|
||||
int rc = pthread_create(&logThread, 0, logThreadFunction, 0);
|
||||
if (rc != 0) {
|
||||
LOGE("Failed to create native log thread (rc=%d).", rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiates a stop request for native log collector thread. Please note that when this function returns collector
|
||||
* thread might be still alive.
|
||||
*
|
||||
* \param env pointer to native method interface
|
||||
* \param object reference to the object on which this method is invoked
|
||||
* \return zero on success, non-zero if an error occurs
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_com_arthenica_mobileffmpeg_Log_stopNativeCollector(JNIEnv *env, jobject object) {
|
||||
logThreadEnabled = 0;
|
||||
|
||||
LOGI("Stopping native log thread\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Taner Sener
|
||||
*
|
||||
* This file is part of MobileFFmpeg.
|
||||
*
|
||||
* MobileFFmpeg 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.
|
||||
*
|
||||
* MobileFFmpeg 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 MobileFFmpeg. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef MOBILEFFMPEG_LOG_H
|
||||
#define MOBILEFFMPEG_LOG_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
#include <jni.h>
|
||||
#include <android/log.h>
|
||||
|
||||
/** Defines tag used for Android logging. */
|
||||
#define LIB_NAME "mobile-ffmpeg"
|
||||
|
||||
/** 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_mobileffmpeg_Log
|
||||
* Method: startNativeCollector
|
||||
* Signature: ()I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_com_arthenica_mobileffmpeg_Log_startNativeCollector(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_arthenica_mobileffmpeg_Log
|
||||
* Method: stopNativeCollector
|
||||
* Signature: ()I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_com_arthenica_mobileffmpeg_Log_stopNativeCollector(JNIEnv *, jobject);
|
||||
|
||||
#endif /* MOBILEFFMPEG_LOG_H */
|
||||
@@ -17,20 +17,441 @@
|
||||
* along with MobileFFmpeg. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "mobileffmpeg.h"
|
||||
/*
|
||||
* CHANGES 09.2018
|
||||
* --------------------------------------------------------
|
||||
* - Merged with mobileffmpeg_config
|
||||
*
|
||||
* CHANGES 08.2018
|
||||
* --------------------------------------------------------
|
||||
* - Copied methods with avutil_log_ prefix from libavutil/log.c
|
||||
*/
|
||||
|
||||
/** Forward declaration for function defined in ffmpeg.c */
|
||||
#include <pthread.h>
|
||||
|
||||
#include "libavutil/bprint.h"
|
||||
#include "mobileffmpeg.h"
|
||||
#include "fftools_ffmpeg.h"
|
||||
|
||||
/** Callback data structure */
|
||||
struct CallbackData {
|
||||
int type; // 1 (log callback) or 2 (statistics callback)
|
||||
|
||||
int logLevel; // log level
|
||||
char *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;
|
||||
};
|
||||
|
||||
/** Redirection control variables */
|
||||
pthread_mutex_t lockMutex;
|
||||
pthread_mutex_t monitorMutex;
|
||||
pthread_cond_t monitorCondition;
|
||||
|
||||
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;
|
||||
|
||||
/** Full name of the Config class */
|
||||
const char *configClassName = "com/arthenica/mobileffmpeg/Config";
|
||||
|
||||
/** Prototypes of native functions defined by Config class. */
|
||||
JNINativeMethod configMethods[] = {
|
||||
{"enableNativeRedirection", "()V", (void*) Java_com_arthenica_mobileffmpeg_Config_enableNativeRedirection},
|
||||
{"disableNativeRedirection", "()V", (void*) Java_com_arthenica_mobileffmpeg_Config_disableNativeRedirection},
|
||||
{"setNativeLogLevel", "(I)V", (void*) Java_com_arthenica_mobileffmpeg_Config_setNativeLogLevel},
|
||||
{"getNativeLogLevel", "()I", (void*) Java_com_arthenica_mobileffmpeg_Config_getNativeLogLevel}
|
||||
};
|
||||
|
||||
/** Prototypes of native functions defined by FFmpeg class. */
|
||||
JNINativeMethod ffmpegMethods[] = {
|
||||
{"getNativeFFmpegVersion", "()Ljava/lang/String;", (void*) Java_com_arthenica_mobileffmpeg_Config_getNativeFFmpegVersion},
|
||||
{"getNativeVersion", "()Ljava/lang/String;", (void*) Java_com_arthenica_mobileffmpeg_Config_getNativeVersion},
|
||||
{"nativeExecute", "([Ljava/lang/String;)I", (void*) Java_com_arthenica_mobileffmpeg_Config_nativeExecute},
|
||||
{"nativeCancel", "()V", (void*) Java_com_arthenica_mobileffmpeg_Config_nativeCancel}
|
||||
};
|
||||
|
||||
/** Forward declaration for function defined in fftools_ffmpeg.c */
|
||||
int execute(int argc, char **argv);
|
||||
|
||||
/** Full name of the Java class that owns native functions in this file. */
|
||||
const char *ffmpegClassName = "com/arthenica/mobileffmpeg/FFmpeg";
|
||||
/** DEFINES LINE SIZE USED FOR LOGGING */
|
||||
#define LOG_LINE_SIZE 1024
|
||||
|
||||
/** Prototypes of native functions defined by this file. */
|
||||
JNINativeMethod ffmpegMethods[] = {
|
||||
{"getFFmpegVersion", "()Ljava/lang/String;", (void*) Java_com_arthenica_mobileffmpeg_FFmpeg_getFFmpegVersion},
|
||||
{"getVersion", "()Ljava/lang/String;", (void*) Java_com_arthenica_mobileffmpeg_FFmpeg_getVersion},
|
||||
{"execute", "([Ljava/lang/String;)I", (void*) Java_com_arthenica_mobileffmpeg_FFmpeg_execute}
|
||||
};
|
||||
static const char *avutil_log_get_level_str(int level) {
|
||||
switch (level) {
|
||||
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 mutexUnInit() {
|
||||
pthread_mutex_destroy(&lockMutex);
|
||||
}
|
||||
|
||||
void monitorUnInit() {
|
||||
pthread_mutex_destroy(&monitorMutex);
|
||||
pthread_cond_destroy(&monitorCondition);
|
||||
}
|
||||
|
||||
void mutexLock() {
|
||||
pthread_mutex_lock(&lockMutex);
|
||||
}
|
||||
|
||||
void mutexUnlock() {
|
||||
pthread_mutex_unlock(&lockMutex);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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.
|
||||
*/
|
||||
void logCallbackDataAdd(int level, const char *data) {
|
||||
|
||||
// CREATE DATA STRUCT FIRST
|
||||
struct CallbackData *newData = (struct CallbackData*)malloc(sizeof(struct CallbackData));
|
||||
newData->type = 1;
|
||||
newData->logLevel = level;
|
||||
size_t dataSize = strlen(data) + 1;
|
||||
newData->logData = (char*)malloc(dataSize);
|
||||
memcpy(newData->logData, data, dataSize);
|
||||
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*)malloc(sizeof(struct CallbackData));
|
||||
newData->type = 2;
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback function for FFmpeg logs.
|
||||
*
|
||||
* \param pointer to AVClass struct
|
||||
* \param level
|
||||
* \param format
|
||||
* \param arguments
|
||||
*/
|
||||
void mobileffmpeg_log_callback_function(void *ptr, int level, const char* format, va_list vargs) {
|
||||
char line[LOG_LINE_SIZE];
|
||||
AVBPrint part[4];
|
||||
int print_prefix = 1;
|
||||
|
||||
if (level >= 0) {
|
||||
level &= 0xff;
|
||||
}
|
||||
|
||||
avutil_log_format_line(ptr, level, format, vargs, part, &print_prefix);
|
||||
snprintf(line, sizeof(line), "%s%s%s%s", part[0].str, part[1].str, part[2].str, part[3].str);
|
||||
|
||||
avutil_log_sanitize(part[0].str);
|
||||
logCallbackDataAdd(level, part[0].str);
|
||||
avutil_log_sanitize(part[1].str);
|
||||
logCallbackDataAdd(level, part[1].str);
|
||||
avutil_log_sanitize(part[2].str);
|
||||
logCallbackDataAdd(level, part[2].str);
|
||||
avutil_log_sanitize(part[3].str);
|
||||
logCallbackDataAdd(level, part[3].str);
|
||||
|
||||
av_bprint_finalize(part+3, 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 mobileffmpeg_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
|
||||
|
||||
size_t size = strlen(callbackData->logData);
|
||||
|
||||
jbyteArray byteArray = (jbyteArray) (*env)->NewByteArray(env, size);
|
||||
(*env)->SetByteArrayRegion(env, byteArray, 0, size, (jbyte *)callbackData->logData);
|
||||
(*env)->CallStaticVoidMethod(env, configClass, logMethod, callbackData->logLevel, byteArray);
|
||||
(*env)->DeleteLocalRef(env, byteArray);
|
||||
|
||||
// CLEAN LOG DATA
|
||||
free(callbackData->logData);
|
||||
|
||||
} else {
|
||||
|
||||
// STATISTICS CALLBACK
|
||||
|
||||
(*env)->CallStaticVoidMethod(env, configClass, statisticsMethod,
|
||||
callbackData->statisticsFrameNumber, callbackData->statisticsFps,
|
||||
callbackData->statisticsQuality, callbackData->statisticsSize,
|
||||
callbackData->statisticsTime, callbackData->statisticsBitrate,
|
||||
callbackData->statisticsSpeed);
|
||||
|
||||
}
|
||||
|
||||
// CLEAN STRUCT
|
||||
callbackData->next = NULL;
|
||||
free(callbackData);
|
||||
|
||||
} else {
|
||||
monitorWait(100);
|
||||
}
|
||||
}
|
||||
|
||||
(*globalVm)->DetachCurrentThread(globalVm);
|
||||
|
||||
LOGD("Callback thread stopped.\n");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when 'mobileffmpeg' native library is loaded.
|
||||
@@ -42,55 +463,158 @@ JNINativeMethod ffmpegMethods[] = {
|
||||
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.", ffmpegClassName);
|
||||
LOGE("OnLoad failed to GetEnv for class %s.\n", configClassName);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
jclass ffmpegClass = (*env)->FindClass(env, ffmpegClassName);
|
||||
if (ffmpegClass == NULL) {
|
||||
LOGE("OnLoad failed to FindClass %s.", ffmpegClassName);
|
||||
jclass localConfigClass = (*env)->FindClass(env, configClassName);
|
||||
if (localConfigClass == NULL) {
|
||||
LOGE("OnLoad failed to FindClass %s.\n", configClassName);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
if ((*env)->RegisterNatives(env, ffmpegClass, ffmpegMethods, 3) < 0) {
|
||||
LOGE("OnLoad failed to RegisterNatives for class %s.", ffmpegClassName);
|
||||
if ((*env)->RegisterNatives(env, localConfigClass, ffmpegMethods, 4) < 0) {
|
||||
LOGE("OnLoad failed to RegisterNatives for class %s.\n", configClassName);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
if ((*env)->RegisterNatives(env, localConfigClass, configMethods, 4) < 0) {
|
||||
LOGE("OnLoad failed to RegisterNatives for class %s.\n", configClassName);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
(*env)->GetJavaVM(env, &globalVm);
|
||||
|
||||
logMethod = (*env)->GetStaticMethodID(env, localConfigClass, "log", "(I[B)V");
|
||||
if (logMethod == NULL) {
|
||||
LOGE("OnLoad thread failed to GetMethodID for %s.\n", "log");
|
||||
(*globalVm)->DetachCurrentThread(globalVm);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
statisticsMethod = (*env)->GetStaticMethodID(env, localConfigClass, "statistics", "(IFFJIDD)V");
|
||||
if (logMethod == NULL) {
|
||||
LOGE("OnLoad thread failed to GetMethodID for %s.\n", "statistics");
|
||||
(*globalVm)->DetachCurrentThread(globalVm);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
configClass = (jclass) ((*env)->NewGlobalRef(env, localConfigClass));
|
||||
|
||||
redirectionEnabled = 0;
|
||||
|
||||
callbackDataHead = NULL;
|
||||
callbackDataTail = NULL;
|
||||
|
||||
mutexInit();
|
||||
monitorInit();
|
||||
|
||||
return JNI_VERSION_1_6;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns FFmpeg version bundled within the library.
|
||||
* Sets log level.
|
||||
*
|
||||
* \param env pointer to native method interface
|
||||
* \param reference to the class on which this method is invoked
|
||||
* \param log level
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_arthenica_mobileffmpeg_Config_setNativeLogLevel(JNIEnv *env, jclass object, jint level) {
|
||||
av_log_set_level(level);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns current log level.
|
||||
*
|
||||
* \param env pointer to native method interface
|
||||
* \param reference to the class on which this method is invoked
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_com_arthenica_mobileffmpeg_Config_getNativeLogLevel(JNIEnv *env, jclass object) {
|
||||
return av_log_get_level();
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables log and statistics redirection.
|
||||
*
|
||||
* \param env pointer to native method interface
|
||||
* \param reference to the class on which this method is invoked
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_arthenica_mobileffmpeg_Config_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(mobileffmpeg_log_callback_function);
|
||||
set_report_callback(mobileffmpeg_statistics_callback_function);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables log and statistics redirection.
|
||||
*
|
||||
* \param env pointer to native method interface
|
||||
* \param reference to the class on which this method is invoked
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_arthenica_mobileffmpeg_Config_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_mobileffmpeg_FFmpeg_getFFmpegVersion(JNIEnv *env, jclass object) {
|
||||
JNIEXPORT jstring JNICALL Java_com_arthenica_mobileffmpeg_Config_getNativeFFmpegVersion(JNIEnv *env, jclass object) {
|
||||
return (*env)->NewStringUTF(env, FFMPEG_VERSION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns MobileFFmpeg library version.
|
||||
* Returns MobileFFmpeg library version natively.
|
||||
*
|
||||
* \param env pointer to native method interface
|
||||
* \param object reference to the class on which this method is invoked
|
||||
* \return MobileFFmpeg version string
|
||||
*/
|
||||
JNIEXPORT jstring JNICALL Java_com_arthenica_mobileffmpeg_FFmpeg_getVersion(JNIEnv *env, jclass object) {
|
||||
JNIEXPORT jstring JNICALL Java_com_arthenica_mobileffmpeg_Config_getNativeVersion(JNIEnv *env, jclass object) {
|
||||
return (*env)->NewStringUTF(env, MOBILE_FFMPEG_VERSION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Synchronously executes FFmpeg command with arguments provided.
|
||||
* Synchronously executes FFmpeg command 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 FFmpeg command arguments
|
||||
* \return zero on successful execution, non-zero on error
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_com_arthenica_mobileffmpeg_FFmpeg_execute(JNIEnv *env, jclass object, jobjectArray stringArray) {
|
||||
JNIEXPORT jint JNICALL Java_com_arthenica_mobileffmpeg_Config_nativeExecute(JNIEnv *env, jclass object, jobjectArray stringArray) {
|
||||
jstring *tempArray = NULL;
|
||||
int argumentCount = 1;
|
||||
char **argv = NULL;
|
||||
@@ -102,7 +626,7 @@ JNIEXPORT jint JNICALL Java_com_arthenica_mobileffmpeg_FFmpeg_execute(JNIEnv *en
|
||||
tempArray = (jstring *) malloc(sizeof(jstring) * programArgumentCount);
|
||||
}
|
||||
|
||||
/* PRESERVING USAGE FORMAT
|
||||
/* PRESERVE USAGE FORMAT
|
||||
*
|
||||
* ffmpeg <arguments>
|
||||
*/
|
||||
@@ -114,7 +638,9 @@ JNIEXPORT jint JNICALL Java_com_arthenica_mobileffmpeg_FFmpeg_execute(JNIEnv *en
|
||||
if (stringArray != NULL) {
|
||||
for (int i = 0; i < (argumentCount - 1); i++) {
|
||||
tempArray[i] = (jstring) (*env)->GetObjectArrayElement(env, stringArray, i);
|
||||
argv[i + 1] = (char *) (*env)->GetStringUTFChars(env, tempArray[i], 0);
|
||||
if (tempArray[i] != NULL) {
|
||||
argv[i + 1] = (char *) (*env)->GetStringUTFChars(env, tempArray[i], 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,3 +660,13 @@ JNIEXPORT jint JNICALL Java_com_arthenica_mobileffmpeg_FFmpeg_execute(JNIEnv *en
|
||||
|
||||
return retCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels an ongoing operation natively.
|
||||
*
|
||||
* \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_mobileffmpeg_Config_nativeCancel(JNIEnv *env, jclass object) {
|
||||
cancel_operation();
|
||||
}
|
||||
|
||||
@@ -17,38 +17,90 @@
|
||||
* along with MobileFFmpeg. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef MOBILEFFMPEG_H
|
||||
#define MOBILEFFMPEG_H
|
||||
#ifndef MOBILE_FFMPEG_H
|
||||
#define MOBILE_FFMPEG_H
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <jni.h>
|
||||
#include <android/log.h>
|
||||
|
||||
#include "libavutil/log.h"
|
||||
#include "libavutil/ffversion.h"
|
||||
#include "log.h"
|
||||
|
||||
/** Library version string */
|
||||
#define MOBILE_FFMPEG_VERSION "1.0"
|
||||
#define MOBILE_FFMPEG_VERSION "2.2"
|
||||
|
||||
/** Defines tag used for Android logging. */
|
||||
#define LIB_NAME "mobile-ffmpeg"
|
||||
|
||||
/** 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_mobileffmpeg_FFmpeg
|
||||
* Method: getFFmpegVersion
|
||||
* Class: com_arthenica_mobileffmpeg_Config
|
||||
* Method: enableNativeRedirection
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_arthenica_mobileffmpeg_Config_enableNativeRedirection(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: com_arthenica_mobileffmpeg_Config
|
||||
* Method: disableNativeRedirection
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_arthenica_mobileffmpeg_Config_disableNativeRedirection(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: com_arthenica_mobileffmpeg_Config
|
||||
* Method: setNativeLogLevel
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_arthenica_mobileffmpeg_Config_setNativeLogLevel(JNIEnv *, jclass, jint);
|
||||
|
||||
/*
|
||||
* Class: com_arthenica_mobileffmpeg_Config
|
||||
* Method: getNativeLogLevel
|
||||
* Signature: ()I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_com_arthenica_mobileffmpeg_Config_getNativeLogLevel(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: com_arthenica_mobileffmpeg_Config
|
||||
* Method: getNativeFFmpegVersion
|
||||
* Signature: ()Ljava/lang/String;
|
||||
*/
|
||||
JNIEXPORT jstring JNICALL Java_com_arthenica_mobileffmpeg_FFmpeg_getFFmpegVersion(JNIEnv *, jclass);
|
||||
JNIEXPORT jstring JNICALL Java_com_arthenica_mobileffmpeg_Config_getNativeFFmpegVersion(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: com_arthenica_mobileffmpeg_FFmpeg
|
||||
* Method: getVersion
|
||||
* Class: com_arthenica_mobileffmpeg_Config
|
||||
* Method: getNativeVersion
|
||||
* Signature: ()Ljava/lang/String;
|
||||
*/
|
||||
JNIEXPORT jstring JNICALL Java_com_arthenica_mobileffmpeg_FFmpeg_getVersion(JNIEnv *, jclass);
|
||||
JNIEXPORT jstring JNICALL Java_com_arthenica_mobileffmpeg_Config_getNativeVersion(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: com_arthenica_mobileffmpeg_FFmpeg
|
||||
* Method: execute
|
||||
* Class: com_arthenica_mobileffmpeg_Config
|
||||
* Method: nativeExecute
|
||||
* Signature: ([Ljava/lang/String;)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_com_arthenica_mobileffmpeg_FFmpeg_execute(JNIEnv *, jclass, jobjectArray);
|
||||
JNIEXPORT jint JNICALL Java_com_arthenica_mobileffmpeg_Config_nativeExecute(JNIEnv *, jclass, jobjectArray);
|
||||
|
||||
#endif /* MOBILEFFMPEG_H */
|
||||
/*
|
||||
* Class: com_arthenica_mobileffmpeg_Config
|
||||
* Method: nativeCancel
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_arthenica_mobileffmpeg_Config_nativeCancel(JNIEnv *, jclass);
|
||||
|
||||
#endif /* MOBILE_FFMPEG_H */
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Taner Sener
|
||||
*
|
||||
* This file is part of MobileFFmpeg.
|
||||
*
|
||||
* MobileFFmpeg 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.
|
||||
*
|
||||
* MobileFFmpeg 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 MobileFFmpeg. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "cpu-features.h"
|
||||
#include "mobileffmpeg_abidetect.h"
|
||||
|
||||
/** Full name of the Java class that owns native functions in this file. */
|
||||
const char *abiDetectClassName = "com/arthenica/mobileffmpeg/AbiDetect";
|
||||
|
||||
/** Prototypes of native functions defined by this file. */
|
||||
JNINativeMethod abiDetectMethods[] = {
|
||||
{"getAbi", "()Ljava/lang/String;", (void*) Java_com_arthenica_mobileffmpeg_AbiDetect_getAbi}
|
||||
};
|
||||
|
||||
/**
|
||||
* 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, 1) < 0) {
|
||||
LOGE("OnLoad failed to RegisterNatives for class %s.\n", abiDetectClassName);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
return JNI_VERSION_1_6;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns running ABI name.
|
||||
*
|
||||
* \param env pointer to native method interface
|
||||
* \param object reference to the class on which this method is invoked
|
||||
* \return running ABI name as UTF string
|
||||
*/
|
||||
JNIEXPORT jstring JNICALL Java_com_arthenica_mobileffmpeg_AbiDetect_getAbi(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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Taner Sener
|
||||
*
|
||||
* This file is part of MobileFFmpeg.
|
||||
*
|
||||
* MobileFFmpeg 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.
|
||||
*
|
||||
* MobileFFmpeg 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 MobileFFmpeg. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef MOBILE_FFMPEG_ABIDETECT_H
|
||||
#define MOBILE_FFMPEG_ABIDETECT_H
|
||||
|
||||
#include <jni.h>
|
||||
#include "mobileffmpeg.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_mobileffmpeg_AbiDetect
|
||||
* Method: getAbi
|
||||
* Signature: ()Ljava/lang/String;
|
||||
*/
|
||||
JNIEXPORT jstring JNICALL Java_com_arthenica_mobileffmpeg_AbiDetect_getAbi(JNIEnv *, jclass);
|
||||
|
||||
#endif /* MOBILE_FFMPEG_ABIDETECT_H */
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Taner Sener
|
||||
*
|
||||
* This file is part of MobileFFmpeg.
|
||||
*
|
||||
* MobileFFmpeg 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.
|
||||
*
|
||||
* MobileFFmpeg 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 MobileFFmpeg. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef MOBILE_FFMPEG_EXCEPTION_H
|
||||
#define MOBILE_FFMPEG_EXCEPTION_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
/** Holds information to implement exception handling. */
|
||||
jmp_buf ex_buf__;
|
||||
|
||||
#endif // MOBILE_FFMPEG_EXCEPTION_H
|
||||
@@ -29,7 +29,11 @@ package com.arthenica.mobileffmpeg;
|
||||
public class AbiDetect {
|
||||
|
||||
static {
|
||||
System.loadLibrary("abidetect");
|
||||
System.loadLibrary("mobileffmpeg-abidetect");
|
||||
|
||||
/* ALL LIBRARIES LOADED AT STARTUP */
|
||||
Config.class.getName();
|
||||
FFmpeg.class.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,417 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Taner Sener
|
||||
*
|
||||
* This file is part of MobileFFmpeg.
|
||||
*
|
||||
* MobileFFmpeg 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.
|
||||
*
|
||||
* MobileFFmpeg 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 MobileFFmpeg. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.arthenica.mobileffmpeg;
|
||||
|
||||
import android.content.Context;
|
||||
import android.system.ErrnoException;
|
||||
import android.system.Os;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static com.arthenica.mobileffmpeg.FFmpeg.getVersion;
|
||||
|
||||
/**
|
||||
* <p>This class is used to configure MobileFFmpeg library utilities/tools.
|
||||
*
|
||||
* <p>1. {@link LogCallback}: By default this class redirects FFmpeg output to Logcat. As another
|
||||
* option, 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 see/control FFmpeg
|
||||
* log severity.
|
||||
*
|
||||
* <p>3. {@link StatisticsCallback}: It is possible to receive statistics about 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.
|
||||
*
|
||||
* <p>PS: This class is introduced in v2.1 as an enhanced version of older <code>Log</code> class.
|
||||
*
|
||||
* @author Taner Sener
|
||||
* @since v2.1
|
||||
*/
|
||||
public class Config {
|
||||
|
||||
/**
|
||||
* Defines tag used for logging.
|
||||
*/
|
||||
public static final String TAG = "mobile-ffmpeg";
|
||||
|
||||
private static LogCallback logCallbackFunction;
|
||||
|
||||
private static Level activeLogLevel;
|
||||
|
||||
private static StatisticsCallback statisticsCallbackFunction;
|
||||
|
||||
private static Statistics lastReceivedStatistics;
|
||||
|
||||
static {
|
||||
|
||||
Log.i(Config.TAG, "Loading mobile-ffmpeg.");
|
||||
|
||||
/* ALL LIBRARIES LOADED AT STARTUP */
|
||||
String abiName = AbiDetect.getAbi();
|
||||
Abi abi = Abi.from(abiName);
|
||||
FFmpeg.class.getName();
|
||||
|
||||
/*
|
||||
* NEON supported arm-v7a library has a different name
|
||||
*/
|
||||
boolean nativeLibraryLoaded = false;
|
||||
if (abi == Abi.ABI_ARMV7A_NEON) {
|
||||
try {
|
||||
System.loadLibrary("mobileffmpeg-armv7a-neon");
|
||||
nativeLibraryLoaded = true;
|
||||
} catch (final UnsatisfiedLinkError e) {
|
||||
Log.i(Config.TAG, "NEON supported armeabi-v7a library not found. Loading default armeabi-v7a library.", e);
|
||||
abi = Abi.ABI_ARMV7A;
|
||||
}
|
||||
}
|
||||
|
||||
if (!nativeLibraryLoaded) {
|
||||
System.loadLibrary("mobileffmpeg");
|
||||
}
|
||||
|
||||
Log.i(Config.TAG, String.format("Loaded mobile-ffmpeg-%s-%s.", abi.getName(), getVersion()));
|
||||
|
||||
/* NATIVE LOG LEVEL IS RECEIVED ONLY ON STARTUP */
|
||||
activeLogLevel = Level.from(getNativeLogLevel());
|
||||
|
||||
lastReceivedStatistics = new Statistics();
|
||||
|
||||
Config.enableRedirection();
|
||||
}
|
||||
|
||||
/**
|
||||
* Default constructor hidden.
|
||||
*/
|
||||
private Config() {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Enables log and statistics redirection.
|
||||
* <p>When redirection is not enabled FFmpeg 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 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 levelValue log level as defined in {@link Level}
|
||||
* @param logMessage redirected log message
|
||||
*/
|
||||
private static void log(final int levelValue, final byte[] logMessage) {
|
||||
final Level level = Level.from(levelValue);
|
||||
final String text = new String(logMessage);
|
||||
|
||||
if (activeLogLevel == Level.AV_LOG_QUIET || levelValue > activeLogLevel.getValue()) {
|
||||
// LOG NEITHER PRINTED NOR FORWARDED
|
||||
return;
|
||||
}
|
||||
|
||||
if (logCallbackFunction != null) {
|
||||
logCallbackFunction.apply(new LogMessage(level, text));
|
||||
} 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_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 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 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(videoFrameNumber, videoFps, videoQuality, size, time, bitrate, speed);
|
||||
lastReceivedStatistics.update(newStatistics);
|
||||
|
||||
if (statisticsCallbackFunction != null) {
|
||||
statisticsCallbackFunction.apply(lastReceivedStatistics);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <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)
|
||||
* @throws ErrnoException if an error occurs
|
||||
*/
|
||||
public static void setFontconfigConfigurationPath(final String path) throws ErrnoException {
|
||||
Os.setenv("FONTCONFIG_PATH", path, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Registers fonts inside the given path, so they are available to use in FFmpeg filters.
|
||||
*
|
||||
* <p>Note that you need to build <code>MobileFFmpeg</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, ".mobileffmpeg");
|
||||
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 ErrnoException | 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>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
|
||||
*/
|
||||
native static String getNativeFFmpegVersion();
|
||||
|
||||
/**
|
||||
* <p>Returns MobileFFmpeg library version natively.
|
||||
*
|
||||
* @return MobileFFmpeg version
|
||||
*/
|
||||
native static String getNativeVersion();
|
||||
|
||||
/**
|
||||
* <p>Synchronously executes FFmpeg natively with arguments provided.
|
||||
*
|
||||
* @param arguments FFmpeg command options/arguments as string array
|
||||
* @return zero on successful execution, 255 on user cancel and non-zero on error
|
||||
*/
|
||||
native static int nativeExecute(final String[] arguments);
|
||||
|
||||
/**
|
||||
* <p>Cancels an ongoing operation natively.
|
||||
*
|
||||
* <p>This function does not wait for termination to complete and returns immediately.
|
||||
*/
|
||||
native static void nativeCancel();
|
||||
|
||||
}
|
||||
@@ -24,44 +24,21 @@ package com.arthenica.mobileffmpeg;
|
||||
* FFmpeg commands.
|
||||
* <pre>
|
||||
* int rc = FFmpeg.execute("-i", "file1.mp4", "-c:v", "libxvid", "file1.avi");
|
||||
* Log.i(Log.TAG, String.format("Command execution %s.", (rc == 0?"completed successfully":"failed with rc=" + rc));
|
||||
* Log.i(Config.TAG, String.format("Command execution %s.", (rc == 0?"completed successfully":"failed with rc=" + rc));
|
||||
* </pre>
|
||||
* <p>Note that it is recommended to call {@link #shutdown()} method before terminating your
|
||||
* Android app.
|
||||
*
|
||||
* @author Taner Sener
|
||||
* @since v1.0
|
||||
*/
|
||||
public class FFmpeg {
|
||||
|
||||
public static final int RETURN_CODE_SUCCESS = 0;
|
||||
|
||||
public static final int RETURN_CODE_CANCEL = 255;
|
||||
|
||||
static {
|
||||
final Abi abi = Abi.from(AbiDetect.getAbi());
|
||||
String abiName = abi.getName();
|
||||
|
||||
Log.enableCollectingStdOutErr();
|
||||
|
||||
android.util.Log.i(Log.TAG, "Loading mobile-ffmpeg.");
|
||||
|
||||
/*
|
||||
* NEON supported arm-v7a library has a different name
|
||||
*/
|
||||
boolean nativeLibraryLoaded = false;
|
||||
if (abi == Abi.ABI_ARMV7A_NEON) {
|
||||
try {
|
||||
System.loadLibrary("mobileffmpeg-armv7a-neon");
|
||||
android.util.Log.i(Log.TAG, String.format("Loaded mobile-ffmpeg-%s-%s.", abiName, getVersion()));
|
||||
nativeLibraryLoaded = true;
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
android.util.Log.i(Log.TAG, "NEON supported armeabi-v7a library not found. Loading default armeabi-v7a library.", e);
|
||||
abiName = Abi.ABI_ARMV7A.getName();
|
||||
}
|
||||
}
|
||||
|
||||
if (!nativeLibraryLoaded) {
|
||||
System.loadLibrary("mobileffmpeg");
|
||||
|
||||
android.util.Log.i(Log.TAG, String.format("Loaded mobile-ffmpeg-%s-%s.", abiName, getVersion()));
|
||||
}
|
||||
AbiDetect.class.getName();
|
||||
Config.class.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,36 +52,46 @@ public class FFmpeg {
|
||||
*
|
||||
* @return FFmpeg version
|
||||
*/
|
||||
public native static String getFFmpegVersion();
|
||||
public static String getFFmpegVersion() {
|
||||
return Config.getNativeFFmpegVersion();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Returns MobileFFmpeg library version.
|
||||
*
|
||||
* @return MobileFFmpeg version
|
||||
*/
|
||||
public native static String getVersion();
|
||||
public static String getVersion() {
|
||||
return Config.getNativeVersion();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Synchronously executes FFmpeg with arguments provided.
|
||||
*
|
||||
* @param arguments FFmpeg command options/arguments
|
||||
* @return zero on successful execution, non-zero on error
|
||||
* @param arguments FFmpeg command options/arguments as string array
|
||||
* @return zero on successful execution, 255 on user cancel and non-zero on error
|
||||
*/
|
||||
public native static int execute(final String ... arguments);
|
||||
|
||||
/**
|
||||
* <p>Shuts down library capabilities.
|
||||
*/
|
||||
public static void shutdown() {
|
||||
Log.disableCollectingStdOutErr();
|
||||
public static int execute(final String[] arguments) {
|
||||
return Config.nativeExecute(arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Overrides default {@link Object#finalize()} method.
|
||||
* <p>Synchronously executes FFmpeg with arguments provided.
|
||||
*
|
||||
* @param arguments FFmpeg command options/arguments in one string
|
||||
* @return zero on successful execution, 255 on user cancel and non-zero on error
|
||||
*/
|
||||
@Override
|
||||
protected void finalize() {
|
||||
shutdown();
|
||||
public static int execute(final String arguments) {
|
||||
return execute((arguments == null) ? new String[]{""} : arguments.split(" "));
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Cancels an ongoing operation.
|
||||
*
|
||||
* <p>This function does not wait for termination to complete and returns immediately.
|
||||
*/
|
||||
public static void cancel() {
|
||||
Config.nativeCancel();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Taner Sener
|
||||
*
|
||||
* This file is part of MobileFFmpeg.
|
||||
*
|
||||
* MobileFFmpeg 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.
|
||||
*
|
||||
* MobileFFmpeg 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 MobileFFmpeg. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.arthenica.mobileffmpeg;
|
||||
|
||||
/**
|
||||
* <p>Helper enumeration type for log levels.
|
||||
*
|
||||
* @author Taner Sener
|
||||
* @since v2.1
|
||||
*/
|
||||
public enum Level {
|
||||
|
||||
/**
|
||||
* 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_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;
|
||||
} else if (value == AV_LOG_INFO.getValue()) {
|
||||
return AV_LOG_INFO;
|
||||
} else if (value == AV_LOG_VERBOSE.getValue()) {
|
||||
return AV_LOG_VERBOSE;
|
||||
} else if (value == AV_LOG_DEBUG.getValue()) {
|
||||
return AV_LOG_DEBUG;
|
||||
} else {
|
||||
return AV_LOG_TRACE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns level value.
|
||||
*
|
||||
* @return level value
|
||||
*/
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new enum.
|
||||
*
|
||||
* @param value level value
|
||||
*/
|
||||
Level(final int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Taner Sener
|
||||
*
|
||||
* This file is part of MobileFFmpeg.
|
||||
*
|
||||
* MobileFFmpeg 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.
|
||||
*
|
||||
* MobileFFmpeg 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 MobileFFmpeg. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.arthenica.mobileffmpeg;
|
||||
|
||||
import android.arch.core.util.Function;
|
||||
|
||||
/**
|
||||
* <p>This class is used to process stdout and stderr logs from native libraries.
|
||||
*
|
||||
* <p>By default stdout and stderr is redirected to <code>/dev/null</code> in Android. This class
|
||||
* redirects these streams to Logcat in order to view logs printed by FFmpeg native libraries.
|
||||
*
|
||||
* <p>Alternatively, it is possible not to print messages to Logcat and pass them to a callback
|
||||
* function. This function can decide whether to print these logs or ignore them according to its
|
||||
* own rules.
|
||||
*
|
||||
* @author Taner Sener
|
||||
* @since v1.0
|
||||
*/
|
||||
public class Log {
|
||||
|
||||
/**
|
||||
* Defines tag used for logging.
|
||||
*/
|
||||
public static final String TAG = "mobile-ffmpeg";
|
||||
|
||||
private static Function<byte[], Void> callbackFunction;
|
||||
|
||||
static {
|
||||
System.loadLibrary("ffmpeglog");
|
||||
}
|
||||
|
||||
/**
|
||||
* Default constructor hidden.
|
||||
*/
|
||||
private Log() {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Enables redirecting stdout and stderr.
|
||||
*/
|
||||
public static void enableCollectingStdOutErr() {
|
||||
startNativeCollector();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Disables redirecting stdout and stderr.
|
||||
*/
|
||||
public static void disableCollectingStdOutErr() {
|
||||
stopNativeCollector();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Sets a callback function to receive logs from FFmpeg native libraries.
|
||||
*
|
||||
* @param newCallbackFunction callback to receive logs
|
||||
*/
|
||||
public static void enableCallbackFunction(final Function<byte[], Void> newCallbackFunction) {
|
||||
callbackFunction = newCallbackFunction;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Main method called by JNI part to redirect log messages. It is not designed to be called
|
||||
* manually by Java classes.
|
||||
*
|
||||
* @param logMessage log message
|
||||
*/
|
||||
public static void log(final byte[] logMessage) {
|
||||
if (callbackFunction != null) {
|
||||
callbackFunction.apply(logMessage);
|
||||
} else {
|
||||
android.util.Log.d(TAG, new String(logMessage));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Starts native log collector.
|
||||
*
|
||||
* @return zero on success, non-zero if an error occurs
|
||||
*/
|
||||
public static native int startNativeCollector();
|
||||
|
||||
/**
|
||||
* <p>Stops native log collector.
|
||||
*
|
||||
* @return zero on success, non-zero if an error occurs
|
||||
*/
|
||||
public static native int stopNativeCollector();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Taner Sener
|
||||
*
|
||||
* This file is part of MobileFFmpeg.
|
||||
*
|
||||
* MobileFFmpeg 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.
|
||||
*
|
||||
* MobileFFmpeg 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 MobileFFmpeg. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.arthenica.mobileffmpeg;
|
||||
|
||||
/**
|
||||
* <p>Represents a callback function to redirect logs.
|
||||
*
|
||||
* @author Taner Sener
|
||||
* @since v2.1
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface LogCallback {
|
||||
|
||||
void apply(final LogMessage message);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Taner Sener
|
||||
*
|
||||
* This file is part of MobileFFmpeg.
|
||||
*
|
||||
* MobileFFmpeg 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.
|
||||
*
|
||||
* MobileFFmpeg 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 MobileFFmpeg. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.arthenica.mobileffmpeg;
|
||||
|
||||
/**
|
||||
* <p>Represents a redirected log message.
|
||||
*
|
||||
* @author Taner Sener
|
||||
* @since v2.1
|
||||
*/
|
||||
public class LogMessage {
|
||||
|
||||
private final Level level;
|
||||
private final String text;
|
||||
|
||||
public LogMessage(final Level level, final String text) {
|
||||
this.level = level;
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public Level getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Taner Sener
|
||||
*
|
||||
* This file is part of MobileFFmpeg.
|
||||
*
|
||||
* MobileFFmpeg 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.
|
||||
*
|
||||
* MobileFFmpeg 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 MobileFFmpeg. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.arthenica.mobileffmpeg;
|
||||
|
||||
/**
|
||||
* <p>Represents statistics data.
|
||||
*
|
||||
* @author Taner Sener
|
||||
* @since v2.1
|
||||
*/
|
||||
public class Statistics {
|
||||
|
||||
private int videoFrameNumber;
|
||||
private float videoFps;
|
||||
private float videoQuality;
|
||||
private long size;
|
||||
private int time;
|
||||
private double bitrate;
|
||||
private double speed;
|
||||
|
||||
public Statistics() {
|
||||
videoFrameNumber = 0;
|
||||
videoFps = 0;
|
||||
videoQuality = 0;
|
||||
size = 0;
|
||||
time = 0;
|
||||
bitrate = 0;
|
||||
speed = 0;
|
||||
}
|
||||
|
||||
public Statistics(int videoFrameNumber, float videoFps, float videoQuality, long size, int time, double bitrate, double speed) {
|
||||
this.videoFrameNumber = videoFrameNumber;
|
||||
this.videoFps = videoFps;
|
||||
this.videoQuality = videoQuality;
|
||||
this.size = size;
|
||||
this.time = time;
|
||||
this.bitrate = bitrate;
|
||||
this.speed = speed;
|
||||
}
|
||||
|
||||
public void update(final Statistics newStatistics) {
|
||||
if (newStatistics != null) {
|
||||
if (newStatistics.getVideoFrameNumber() > 0) {
|
||||
this.videoFrameNumber = newStatistics.getVideoFrameNumber();
|
||||
}
|
||||
if (newStatistics.getVideoFps() > 0){
|
||||
this.videoFps = newStatistics.getVideoFps();
|
||||
}
|
||||
|
||||
if (newStatistics.getVideoQuality() > 0){
|
||||
this.videoQuality = newStatistics.getVideoQuality();
|
||||
}
|
||||
|
||||
if (newStatistics.getSize() > 0){
|
||||
this.size = newStatistics.getSize();
|
||||
}
|
||||
|
||||
if (newStatistics.getTime() > 0){
|
||||
this.time = newStatistics.getTime();
|
||||
}
|
||||
|
||||
if (newStatistics.getBitrate() > 0){
|
||||
this.bitrate = newStatistics.getBitrate();
|
||||
}
|
||||
|
||||
if (newStatistics.getSpeed() > 0){
|
||||
this.speed = newStatistics.getSpeed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getVideoFrameNumber() {
|
||||
return videoFrameNumber;
|
||||
}
|
||||
|
||||
public void setVideoFrameNumber(int videoFrameNumber) {
|
||||
this.videoFrameNumber = videoFrameNumber;
|
||||
}
|
||||
|
||||
public float getVideoFps() {
|
||||
return videoFps;
|
||||
}
|
||||
|
||||
public void setVideoFps(float videoFps) {
|
||||
this.videoFps = videoFps;
|
||||
}
|
||||
|
||||
public float getVideoQuality() {
|
||||
return videoQuality;
|
||||
}
|
||||
|
||||
public void setVideoQuality(float videoQuality) {
|
||||
this.videoQuality = videoQuality;
|
||||
}
|
||||
|
||||
public long getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public void setSize(long size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public int getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(int time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public double getBitrate() {
|
||||
return bitrate;
|
||||
}
|
||||
|
||||
public void setBitrate(double bitrate) {
|
||||
this.bitrate = bitrate;
|
||||
}
|
||||
|
||||
public double getSpeed() {
|
||||
return speed;
|
||||
}
|
||||
|
||||
public void setSpeed(double speed) {
|
||||
this.speed = speed;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Taner Sener
|
||||
*
|
||||
* This file is part of MobileFFmpeg.
|
||||
*
|
||||
* MobileFFmpeg 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.
|
||||
*
|
||||
* MobileFFmpeg 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 MobileFFmpeg. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.arthenica.mobileffmpeg;
|
||||
|
||||
/**
|
||||
* <p>Represents a callback function to receive statistics of running operation.
|
||||
*
|
||||
* @author Taner Sener
|
||||
* @since v2.1
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface StatisticsCallback {
|
||||
|
||||
void apply(final Statistics statistics);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Taner Sener
|
||||
*
|
||||
* This file is part of MobileFFmpeg.
|
||||
*
|
||||
* MobileFFmpeg 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.
|
||||
*
|
||||
* MobileFFmpeg 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 MobileFFmpeg. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.arthenica.mobileffmpeg.util;
|
||||
|
||||
/**
|
||||
* <p>Represents a callback function to receive run result.
|
||||
*
|
||||
* @author Taner Sener
|
||||
* @since v2.1
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface RunCallback {
|
||||
|
||||
void apply(final int returnCode);
|
||||
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:aapt="http://schemas.android.com/aapt"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportHeight="108"
|
||||
android:viewportWidth="108">
|
||||
<path
|
||||
android:fillType="evenOdd"
|
||||
android:pathData="M32,64C32,64 38.39,52.99 44.13,50.95C51.37,48.37 70.14,49.57 70.14,49.57L108.26,87.69L108,109.01L75.97,107.97L32,64Z"
|
||||
android:strokeColor="#00000000"
|
||||
android:strokeWidth="1">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient
|
||||
android:endX="78.5885"
|
||||
android:endY="90.9159"
|
||||
android:startX="48.7653"
|
||||
android:startY="61.0927"
|
||||
android:type="linear">
|
||||
<item
|
||||
android:color="#44000000"
|
||||
android:offset="0.0" />
|
||||
<item
|
||||
android:color="#00000000"
|
||||
android:offset="1.0" />
|
||||
</gradient>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:fillType="nonZero"
|
||||
android:pathData="M66.94,46.02L66.94,46.02C72.44,50.07 76,56.61 76,64L32,64C32,56.61 35.56,50.11 40.98,46.06L36.18,41.19C35.45,40.45 35.45,39.3 36.18,38.56C36.91,37.81 38.05,37.81 38.78,38.56L44.25,44.05C47.18,42.57 50.48,41.71 54,41.71C57.48,41.71 60.78,42.57 63.68,44.05L69.11,38.56C69.84,37.81 70.98,37.81 71.71,38.56C72.44,39.3 72.44,40.45 71.71,41.19L66.94,46.02ZM62.94,56.92C64.08,56.92 65,56.01 65,54.88C65,53.76 64.08,52.85 62.94,52.85C61.8,52.85 60.88,53.76 60.88,54.88C60.88,56.01 61.8,56.92 62.94,56.92ZM45.06,56.92C46.2,56.92 47.13,56.01 47.13,54.88C47.13,53.76 46.2,52.85 45.06,52.85C43.92,52.85 43,53.76 43,54.88C43,56.01 43.92,56.92 45.06,56.92Z"
|
||||
android:strokeColor="#00000000"
|
||||
android:strokeWidth="1" />
|
||||
</vector>
|
||||
@@ -1,170 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportHeight="108"
|
||||
android:viewportWidth="108">
|
||||
<path
|
||||
android:fillColor="#26A69A"
|
||||
android:pathData="M0,0h108v108h-108z" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M9,0L9,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,0L19,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M29,0L29,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M39,0L39,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M49,0L49,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M59,0L59,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M69,0L69,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M79,0L79,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M89,0L89,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M99,0L99,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,9L108,9"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,19L108,19"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,29L108,29"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,39L108,39"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,49L108,49"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,59L108,59"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,69L108,69"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,79L108,79"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,89L108,89"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,99L108,99"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,29L89,29"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,39L89,39"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,49L89,49"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,59L89,59"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,69L89,69"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,79L89,79"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M29,19L29,89"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M39,19L39,89"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M49,19L49,89"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M59,19L59,89"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M69,19L69,89"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M79,19L79,89"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
</vector>
|
||||
@@ -1,5 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@drawable/ic_launcher_background" />
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||
</adaptive-icon>
|
||||
@@ -1,5 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@drawable/ic_launcher_background" />
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||
</adaptive-icon>
|
||||
|
Before Width: | Height: | Size: 3.0 KiB After Width: | Height: | Size: 5.9 KiB |
|
Before Width: | Height: | Size: 4.9 KiB After Width: | Height: | Size: 7.4 KiB |
|
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 3.0 KiB |
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 3.9 KiB |
|
Before Width: | Height: | Size: 4.5 KiB After Width: | Height: | Size: 7.4 KiB |
|
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 6.3 KiB After Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 9.0 KiB After Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 26 KiB |
|
After Width: | Height: | Size: 66 KiB |
@@ -7,7 +7,7 @@ buildscript {
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.1.2'
|
||||
classpath 'com.android.tools.build:gradle:3.1.4'
|
||||
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
|
||||
@@ -15,28 +15,20 @@ include $(BUILD_SHARED_LIBRARY)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_ARM_MODE := $(MY_ARM_MODE)
|
||||
LOCAL_MODULE := abidetect
|
||||
LOCAL_SRC_FILES := $(MY_PATH)/abidetect.c
|
||||
LOCAL_MODULE := mobileffmpeg-abidetect
|
||||
LOCAL_SRC_FILES := $(MY_PATH)/mobileffmpeg_abidetect.c
|
||||
LOCAL_CFLAGS := -Wall -Wextra -Werror -Wno-unused-parameter -I${LOCAL_PATH}/../../prebuilt/android-$(TARGET_ARCH)/ffmpeg/include -I$(NDK_ROOT)/sources/android/cpufeatures
|
||||
LOCAL_LDLIBS := -llog -lz -landroid
|
||||
LOCAL_SHARED_LIBRARIES := cpufeatures
|
||||
include $(BUILD_SHARED_LIBRARY)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_ARM_MODE := $(MY_ARM_MODE)
|
||||
LOCAL_MODULE := ffmpeglog
|
||||
LOCAL_SRC_FILES := $(MY_PATH)/log.c
|
||||
LOCAL_CFLAGS := -Wall -Wextra -Werror -Wno-unused-parameter
|
||||
LOCAL_LDLIBS := -llog -lz -landroid
|
||||
include $(BUILD_SHARED_LIBRARY)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_ARM_MODE := $(MY_ARM_MODE)
|
||||
LOCAL_MODULE := mobileffmpeg
|
||||
LOCAL_SRC_FILES := $(MY_PATH)/mobileffmpeg.c $(MY_PATH)/cmdutils.c $(MY_PATH)/ffmpeg.c $(MY_PATH)/ffmpeg_opt.c $(MY_PATH)/ffmpeg_hw.c $(MY_PATH)/ffmpeg_filter.c
|
||||
LOCAL_CFLAGS := -I${LOCAL_PATH}/../../prebuilt/android-$(TARGET_ARCH)/ffmpeg/include
|
||||
LOCAL_SRC_FILES := $(MY_PATH)/mobileffmpeg.c $(MY_PATH)/fftools_cmdutils.c $(MY_PATH)/fftools_ffmpeg.c $(MY_PATH)/fftools_ffmpeg_opt.c $(MY_PATH)/fftools_ffmpeg_hw.c $(MY_PATH)/fftools_ffmpeg_filter.c
|
||||
LOCAL_CFLAGS := -Wall -Werror -Wno-unused-parameter -Wno-switch -Wno-sign-compare -I${LOCAL_PATH}/../../prebuilt/android-$(TARGET_ARCH)/ffmpeg/include
|
||||
LOCAL_LDLIBS := -llog -lz -landroid
|
||||
LOCAL_SHARED_LIBRARIES := libavfilter libavformat libavcodec libavutil libswresample libavdevice libswscale
|
||||
LOCAL_SHARED_LIBRARIES := c++_shared libavfilter libavformat libavcodec libavutil libswresample libavdevice libswscale
|
||||
include $(BUILD_SHARED_LIBRARY)
|
||||
|
||||
ifeq ($(TARGET_ARCH_ABI), armeabi-v7a)
|
||||
@@ -45,10 +37,10 @@ ifeq ($(TARGET_ARCH_ABI), armeabi-v7a)
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_ARM_MODE := $(MY_ARM_MODE)
|
||||
LOCAL_MODULE := mobileffmpeg-armv7a-neon
|
||||
LOCAL_SRC_FILES := $(MY_PATH)/mobileffmpeg.c $(MY_PATH)/cmdutils.c $(MY_PATH)/ffmpeg.c $(MY_PATH)/ffmpeg_opt.c $(MY_PATH)/ffmpeg_hw.c $(MY_PATH)/ffmpeg_filter.c
|
||||
LOCAL_CFLAGS := -I${LOCAL_PATH}/../../prebuilt/android-$(TARGET_ARCH)/ffmpeg/include
|
||||
LOCAL_SRC_FILES := $(MY_PATH)/mobileffmpeg.c $(MY_PATH)/fftools_cmdutils.c $(MY_PATH)/fftools_ffmpeg.c $(MY_PATH)/fftools_ffmpeg_opt.c $(MY_PATH)/fftools_ffmpeg_hw.c $(MY_PATH)/fftools_ffmpeg_filter.c
|
||||
LOCAL_CFLAGS := -Wall -Werror -Wno-unused-parameter -Wno-switch -Wno-sign-compare -I${LOCAL_PATH}/../../prebuilt/android-$(TARGET_ARCH)/ffmpeg/include
|
||||
LOCAL_LDLIBS := -llog -lz -landroid
|
||||
LOCAL_SHARED_LIBRARIES := libavcodec-neon libavfilter-neon libswscale-neon libavformat libavutil libswresample libavdevice
|
||||
LOCAL_SHARED_LIBRARIES := c++_shared libavcodec-neon libavfilter-neon libswscale-neon libavformat libavutil libswresample libavdevice
|
||||
LOCAL_ARM_NEON := true
|
||||
include $(BUILD_SHARED_LIBRARY)
|
||||
|
||||
@@ -57,4 +49,4 @@ ifeq ($(TARGET_ARCH_ABI), armeabi-v7a)
|
||||
endif
|
||||
endif
|
||||
|
||||
$(call import-module, ffmpeg)
|
||||
$(call import-module, ffmpeg)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/build
|
||||
/.idea/
|
||||
/gradle/
|
||||
/local.properties
|
||||
|
||||
@@ -6,8 +6,8 @@ android {
|
||||
applicationId "com.arthenica.mobileffmpeg.test"
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 27
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
versionCode 22
|
||||
versionName "2.2"
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
buildTypes {
|
||||
@@ -19,13 +19,13 @@ android {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation project(':app')
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
implementation 'com.android.support:support-v4:27.1.1'
|
||||
implementation 'com.android.support:design:27.1.1'
|
||||
implementation 'com.android.support:appcompat-v7:27.1.1'
|
||||
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
|
||||
implementation 'com.arthenica:mobile-ffmpeg-full:2.2'
|
||||
testImplementation 'junit:junit:4.12'
|
||||
androidTestImplementation 'com.android.support.test:runner:1.0.2'
|
||||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
|
||||
implementation 'com.android.support:support-v4:27.1.1'
|
||||
implementation 'com.android.support:design:27.1.1'
|
||||
implementation 'com.android.support:appcompat-v7:27.1.1'
|
||||
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
|
||||
}
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="com.arthenica.mobileffmpeg.test">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
@@ -9,8 +15,10 @@
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:largeHeap="true"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity android:name="com.arthenica.mobileffmpeg.test.MainActivity">
|
||||
android:theme="@style/AppTheme"
|
||||
tools:replace="android:icon">
|
||||
<activity android:name="com.arthenica.mobileffmpeg.test.MainActivity"
|
||||
android:theme="@style/AppTheme">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
|
||||
@@ -0,0 +1,304 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Taner Sener
|
||||
*
|
||||
* This file is part of MobileFFmpeg.
|
||||
*
|
||||
* MobileFFmpeg 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.
|
||||
*
|
||||
* MobileFFmpeg 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 MobileFFmpeg. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.arthenica.mobileffmpeg.test;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.text.method.ScrollingMovementMethod;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.arthenica.mobileffmpeg.Config;
|
||||
import com.arthenica.mobileffmpeg.FFmpeg;
|
||||
import com.arthenica.mobileffmpeg.LogCallback;
|
||||
import com.arthenica.mobileffmpeg.LogMessage;
|
||||
import com.arthenica.mobileffmpeg.util.RunCallback;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import static com.arthenica.mobileffmpeg.FFmpeg.RETURN_CODE_SUCCESS;
|
||||
import static com.arthenica.mobileffmpeg.test.MainActivity.TAG;
|
||||
|
||||
public class AudioTabFragment extends Fragment implements AdapterView.OnItemSelectedListener {
|
||||
|
||||
private MainActivity mainActivity;
|
||||
private AlertDialog progressDialog;
|
||||
private Button encodeButton;
|
||||
private TextView outputText;
|
||||
private String selectedCodec;
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.fragment_audio_tab, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
if (getView() != null) {
|
||||
Spinner audioCodecSpinner = getView().findViewById(R.id.audioCodecSpinner);
|
||||
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(mainActivity,
|
||||
R.array.audio_codec, R.layout.spinner_item);
|
||||
adapter.setDropDownViewResource(R.layout.spinner_dropdown_item);
|
||||
audioCodecSpinner.setAdapter(adapter);
|
||||
audioCodecSpinner.setOnItemSelectedListener(this);
|
||||
|
||||
encodeButton = getView().findViewById(R.id.encodeButton);
|
||||
encodeButton.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
encodeAudio();
|
||||
}
|
||||
});
|
||||
encodeButton.setEnabled(false);
|
||||
|
||||
outputText = getView().findViewById(R.id.outputText);
|
||||
outputText.setMovementMethod(new ScrollingMovementMethod());
|
||||
}
|
||||
|
||||
progressDialog = mainActivity.createProgressDialog("Encoding audio");
|
||||
|
||||
selectedCodec = getResources().getStringArray(R.array.audio_codec)[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUserVisibleHint(boolean isVisibleToUser) {
|
||||
super.setUserVisibleHint(isVisibleToUser);
|
||||
if (isVisibleToUser) {
|
||||
setActive();
|
||||
}
|
||||
}
|
||||
|
||||
public void setMainActivity(MainActivity mainActivity) {
|
||||
this.mainActivity = mainActivity;
|
||||
}
|
||||
|
||||
public static AudioTabFragment newInstance(final MainActivity mainActivity) {
|
||||
final AudioTabFragment fragment = new AudioTabFragment();
|
||||
fragment.setMainActivity(mainActivity);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
public void enableLogCallback() {
|
||||
Config.enableLogCallback(new LogCallback() {
|
||||
|
||||
@Override
|
||||
public void apply(final LogMessage message) {
|
||||
MainActivity.addUIAction(new Callable() {
|
||||
|
||||
@Override
|
||||
public Object call() {
|
||||
appendLog(message.getText());
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void disableLogCallback() {
|
||||
Config.enableLogCallback(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
selectedCodec = parent.getItemAtPosition(position).toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
// DO NOTHING
|
||||
}
|
||||
|
||||
public void encodeAudio() {
|
||||
File audioOutputFile = getAudioOutputFile();
|
||||
if (audioOutputFile.exists()) {
|
||||
audioOutputFile.delete();
|
||||
}
|
||||
|
||||
final String audioCodec = selectedCodec;
|
||||
|
||||
android.util.Log.d(TAG, String.format("Testing AUDIO encoding with '%s' codec", audioCodec));
|
||||
|
||||
final String ffmpegCommand = generateAudioEncodeScript();
|
||||
|
||||
showProgressDialog();
|
||||
|
||||
clearLog();
|
||||
|
||||
android.util.Log.d(TAG, String.format("FFmpeg process started with arguments\n'%s'", ffmpegCommand));
|
||||
|
||||
MainActivity.executeAsync(new RunCallback() {
|
||||
|
||||
@Override
|
||||
public void apply(final int returnCode) {
|
||||
android.util.Log.d(TAG, String.format("FFmpeg process exited with rc %d", returnCode));
|
||||
|
||||
hideProgressDialog();
|
||||
|
||||
MainActivity.addUIAction(new Callable() {
|
||||
|
||||
@Override
|
||||
public Object call() {
|
||||
if (returnCode == RETURN_CODE_SUCCESS) {
|
||||
Popup.show(mainActivity, "Encode completed successfully.");
|
||||
android.util.Log.d(TAG, "Encode completed successfully.");
|
||||
} else {
|
||||
Popup.show(mainActivity, "Encode failed. Please check log for the details.");
|
||||
android.util.Log.d(TAG, String.format("Encode failed with rc=%d", returnCode));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}, ffmpegCommand);
|
||||
}
|
||||
|
||||
public void createAudioSample() {
|
||||
android.util.Log.d(TAG, "Creating AUDIO sample before the test.");
|
||||
|
||||
File audioSampleFile = getAudioSampleFile();
|
||||
if (audioSampleFile.exists()) {
|
||||
audioSampleFile.delete();
|
||||
}
|
||||
|
||||
String ffmpegCommand = String.format("-y -f lavfi -i sine=frequency=1000:duration=5 -c:a pcm_s16le %s", audioSampleFile.getAbsolutePath());
|
||||
|
||||
android.util.Log.d(TAG, String.format("Sample file is created with '%s'", ffmpegCommand));
|
||||
|
||||
int result = FFmpeg.execute(ffmpegCommand);
|
||||
if (result == 0) {
|
||||
encodeButton.setEnabled(true);
|
||||
android.util.Log.d(TAG, "AUDIO sample created");
|
||||
} else {
|
||||
android.util.Log.d(TAG, String.format("Creating AUDIO sample failed with rc=%d", result));
|
||||
Popup.show(mainActivity, "Creating AUDIO sample failed. Please check log for the details.");
|
||||
}
|
||||
}
|
||||
|
||||
public File getAudioOutputFile() {
|
||||
String audioCodec = selectedCodec;
|
||||
|
||||
String extension;
|
||||
switch (audioCodec) {
|
||||
case "mp3 (liblame)":
|
||||
case "mp3 (libshine)":
|
||||
extension = "mp3";
|
||||
break;
|
||||
case "vorbis":
|
||||
extension = "ogg";
|
||||
break;
|
||||
case "opus":
|
||||
extension = "opus";
|
||||
break;
|
||||
case "amr":
|
||||
extension = "amr";
|
||||
break;
|
||||
case "ilbc":
|
||||
extension = "lbc";
|
||||
break;
|
||||
case "speex":
|
||||
extension = "spx";
|
||||
break;
|
||||
case "wavpack":
|
||||
extension = "wv";
|
||||
break;
|
||||
default:
|
||||
|
||||
// soxr
|
||||
extension = "wav";
|
||||
break;
|
||||
}
|
||||
|
||||
final String audio = "audio." + extension;
|
||||
return new File(mainActivity.getFilesDir(), audio);
|
||||
}
|
||||
|
||||
public File getAudioSampleFile() {
|
||||
return new File(mainActivity.getFilesDir(), "audio-sample.wav");
|
||||
}
|
||||
|
||||
public void setActive() {
|
||||
android.util.Log.i(MainActivity.TAG, "Audio Tab Activated");
|
||||
disableLogCallback();
|
||||
createAudioSample();
|
||||
enableLogCallback();
|
||||
Popup.show(mainActivity, Tooltip.AUDIO_TEST_TOOLTIP_TEXT);
|
||||
}
|
||||
|
||||
public void appendLog(final String logMessage) {
|
||||
outputText.append(logMessage);
|
||||
}
|
||||
|
||||
public void clearLog() {
|
||||
outputText.setText("");
|
||||
}
|
||||
|
||||
protected void showProgressDialog() {
|
||||
progressDialog.show();
|
||||
}
|
||||
|
||||
protected void hideProgressDialog() {
|
||||
progressDialog.dismiss();
|
||||
}
|
||||
|
||||
public String generateAudioEncodeScript() {
|
||||
String audioCodec = selectedCodec;
|
||||
String audioSampleFile = getAudioSampleFile().getAbsolutePath();
|
||||
String audioOutputFile = getAudioOutputFile().getAbsolutePath();
|
||||
|
||||
switch (audioCodec) {
|
||||
case "mp3 (liblame)":
|
||||
return String.format("-y -i %s -c:a libmp3lame -qscale:a 2 %s", audioSampleFile, audioOutputFile);
|
||||
case "mp3 (libshine)":
|
||||
return String.format("-y -i %s -c:a libshine -qscale:a 2 %s", audioSampleFile, audioOutputFile);
|
||||
case "vorbis":
|
||||
return String.format("-y -i %s -c:a libvorbis -b:a 64k %s", audioSampleFile, audioOutputFile);
|
||||
case "opus":
|
||||
return String.format("-y -i %s -c:a libopus -b:a 64k -vbr on -compression_level 10 %s", audioSampleFile, audioOutputFile);
|
||||
case "amr":
|
||||
return String.format("-y -i %s -ar 8000 -ab 12.2k %s", audioSampleFile, audioOutputFile);
|
||||
case "ilbc":
|
||||
return String.format("-y -i %s -c:a ilbc -ar 8000 -b:a 15200 %s", audioSampleFile, audioOutputFile);
|
||||
case "speex":
|
||||
return String.format("-y -i %s -c:a libspeex -ar 16000 %s", audioSampleFile, audioOutputFile);
|
||||
case "wavpack":
|
||||
return String.format("-y -i %s -c:a wavpack -b:a 64k %s", audioSampleFile, audioOutputFile);
|
||||
default:
|
||||
|
||||
// soxr
|
||||
return String.format("-y -i %s -af aresample=resampler=soxr -ar 44100 %s", audioSampleFile, audioOutputFile);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,11 +19,7 @@
|
||||
|
||||
package com.arthenica.mobileffmpeg.test;
|
||||
|
||||
import android.arch.core.util.Function;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
@@ -33,44 +29,20 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.arthenica.mobileffmpeg.Config;
|
||||
import com.arthenica.mobileffmpeg.FFmpeg;
|
||||
import com.arthenica.mobileffmpeg.Log;
|
||||
import com.arthenica.mobileffmpeg.LogCallback;
|
||||
import com.arthenica.mobileffmpeg.LogMessage;
|
||||
import com.arthenica.mobileffmpeg.util.RunCallback;
|
||||
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
public class CommandTabFragment extends Fragment {
|
||||
|
||||
private Context context;
|
||||
private MainActivity mainActivity;
|
||||
private EditText commandText;
|
||||
private TextView logText;
|
||||
private final Queue<String> logQueue;
|
||||
|
||||
public CommandTabFragment() {
|
||||
logQueue = new ConcurrentLinkedQueue<>();
|
||||
|
||||
Log.enableCallbackFunction(new Function<byte[], Void>() {
|
||||
|
||||
@Override
|
||||
public Void apply(byte[] logMessageBytes) {
|
||||
logQueue.add(new String(logMessageBytes));
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static CommandTabFragment newInstance(final Context context) {
|
||||
CommandTabFragment fragment = new CommandTabFragment();
|
||||
fragment.setContext(context);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
public void setContext(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
private TextView outputText;
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) {
|
||||
@@ -84,11 +56,6 @@ public class CommandTabFragment extends Fragment {
|
||||
if (getView() != null) {
|
||||
commandText = getView().findViewById(R.id.commandText);
|
||||
|
||||
// CHANGE LOG TEXT COLOR
|
||||
logText = getView().findViewById(R.id.logText);
|
||||
logText.setBackgroundColor(Color.LTGRAY);
|
||||
logText.setMovementMethod(new ScrollingMovementMethod());
|
||||
|
||||
View runButton = getView().findViewById(R.id.runButton);
|
||||
runButton.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@@ -106,77 +73,107 @@ public class CommandTabFragment extends Fragment {
|
||||
runFFmpegAsync();
|
||||
}
|
||||
});
|
||||
|
||||
outputText = getView().findViewById(R.id.outputText);
|
||||
outputText.setMovementMethod(new ScrollingMovementMethod());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUserVisibleHint(boolean isVisibleToUser) {
|
||||
super.setUserVisibleHint(isVisibleToUser);
|
||||
if (isVisibleToUser) {
|
||||
setActive();
|
||||
}
|
||||
}
|
||||
|
||||
public void setMainActivity(MainActivity mainActivity) {
|
||||
this.mainActivity = mainActivity;
|
||||
}
|
||||
|
||||
public static CommandTabFragment newInstance(final MainActivity mainActivity) {
|
||||
final CommandTabFragment fragment = new CommandTabFragment();
|
||||
fragment.setMainActivity(mainActivity);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
public void enableLogCallback() {
|
||||
Config.enableLogCallback(new LogCallback() {
|
||||
|
||||
@Override
|
||||
public void apply(final LogMessage message) {
|
||||
MainActivity.addUIAction(new Callable() {
|
||||
|
||||
@Override
|
||||
public Object call() {
|
||||
appendLog(message.getText());
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void runFFmpeg() {
|
||||
String command = commandText.getText().toString();
|
||||
String[] split = command.split(" ");
|
||||
|
||||
final CountDownLatch logSync = new CountDownLatch(1);
|
||||
clearLog();
|
||||
waitForLogs(logSync);
|
||||
|
||||
int returnCode = FFmpeg.execute(split);
|
||||
android.util.Log.i(MainActivity.TAG, String.format("Process exited with rc %d.", returnCode));
|
||||
Toast.makeText(context, "Run completed", Toast.LENGTH_SHORT).show();
|
||||
logSync.countDown();
|
||||
final String ffmpegCommand = commandText.getText().toString();
|
||||
|
||||
android.util.Log.d(MainActivity.TAG, "Testing COMMAND synchronously.");
|
||||
|
||||
android.util.Log.d(MainActivity.TAG, String.format("FFmpeg process started with arguments\n\'%s\'", ffmpegCommand));
|
||||
|
||||
int result = FFmpeg.execute(ffmpegCommand);
|
||||
|
||||
android.util.Log.d(MainActivity.TAG, String.format("FFmpeg process exited with rc %d", result));
|
||||
|
||||
if (result != 0) {
|
||||
Popup.show(mainActivity, "Command failed. Please check output for the details.");
|
||||
}
|
||||
}
|
||||
|
||||
public void runFFmpegAsync() {
|
||||
String command = commandText.getText().toString();
|
||||
String[] arguments = command.split(" ");
|
||||
|
||||
final CountDownLatch logSync = new CountDownLatch(1);
|
||||
clearLog();
|
||||
waitForLogs(logSync);
|
||||
|
||||
MainActivity.executeAsync(new Function<Integer, Void>() {
|
||||
final String ffmpegCommand = commandText.getText().toString();
|
||||
|
||||
android.util.Log.d(MainActivity.TAG, "Testing COMMAND asynchronously.");
|
||||
|
||||
android.util.Log.d(MainActivity.TAG, String.format("FFmpeg process started with arguments\n\'%s\'", ffmpegCommand));
|
||||
|
||||
MainActivity.executeAsync(new RunCallback() {
|
||||
|
||||
@Override
|
||||
public Void apply(Integer returnCode) {
|
||||
android.util.Log.i(MainActivity.TAG, String.format("Async process exited with rc %d.", returnCode));
|
||||
logSync.countDown();
|
||||
return null;
|
||||
public void apply(int result) {
|
||||
|
||||
android.util.Log.d(MainActivity.TAG, String.format("FFmpeg process exited with rc %d", result));
|
||||
|
||||
if (result != 0) {
|
||||
MainActivity.addUIAction(new Callable() {
|
||||
@Override
|
||||
public Object call() {
|
||||
Popup.show(mainActivity, "Command failed. Please check output for the details.");
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}, arguments);
|
||||
}, ffmpegCommand);
|
||||
}
|
||||
|
||||
public void setActive() {
|
||||
android.util.Log.i(MainActivity.TAG, "Command Tab Activated");
|
||||
enableLogCallback();
|
||||
Popup.show(mainActivity, Tooltip.COMMAND_TEST_TOOLTIP_TEXT);
|
||||
}
|
||||
|
||||
public void appendLog(final String logMessage) {
|
||||
logText.append(logMessage);
|
||||
logText.append("\n");
|
||||
outputText.append(logMessage);
|
||||
}
|
||||
|
||||
public void clearLog() {
|
||||
logQueue.clear();
|
||||
logText.setText("");
|
||||
}
|
||||
|
||||
public void waitForLogs(final CountDownLatch count) {
|
||||
final Handler handler = new Handler();
|
||||
final Runnable runnable = new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
String logMessage;
|
||||
|
||||
do {
|
||||
logMessage = logQueue.poll();
|
||||
if (logMessage != null) {
|
||||
appendLog(logMessage);
|
||||
}
|
||||
} while (logMessage != null);
|
||||
|
||||
if (count.getCount() < 1) {
|
||||
Toast.makeText(context, "Run completed", Toast.LENGTH_SHORT).show();
|
||||
handler.removeCallbacks(this);
|
||||
|
||||
} else {
|
||||
handler.postDelayed(this, 1000);
|
||||
}
|
||||
}
|
||||
};
|
||||
handler.postDelayed(runnable, 1000);
|
||||
outputText.setText("");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Taner Sener
|
||||
*
|
||||
* This file is part of MobileFFmpeg.
|
||||
*
|
||||
* MobileFFmpeg 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.
|
||||
*
|
||||
* MobileFFmpeg 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 MobileFFmpeg. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.arthenica.mobileffmpeg.test;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.text.method.ScrollingMovementMethod;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.arthenica.mobileffmpeg.Config;
|
||||
import com.arthenica.mobileffmpeg.FFmpeg;
|
||||
import com.arthenica.mobileffmpeg.LogCallback;
|
||||
import com.arthenica.mobileffmpeg.LogMessage;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
public class HttpsTabFragment extends Fragment {
|
||||
|
||||
public static final String HTTPS_TEST_DEFAULT_URL = "https://download.blender.org/peach/trailer/trailer_400p.ogg";
|
||||
|
||||
private MainActivity mainActivity;
|
||||
private EditText urlText;
|
||||
private TextView outputText;
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.fragment_https_tab, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
if (getView() != null) {
|
||||
urlText = getView().findViewById(R.id.urlText);
|
||||
|
||||
View getInfoButton = getView().findViewById(R.id.getInfoButton);
|
||||
getInfoButton.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
getInfo();
|
||||
}
|
||||
});
|
||||
|
||||
outputText = getView().findViewById(R.id.outputText);
|
||||
outputText.setMovementMethod(new ScrollingMovementMethod());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUserVisibleHint(boolean isVisibleToUser) {
|
||||
super.setUserVisibleHint(isVisibleToUser);
|
||||
if (isVisibleToUser) {
|
||||
setActive();
|
||||
}
|
||||
}
|
||||
|
||||
public void setMainActivity(MainActivity mainActivity) {
|
||||
this.mainActivity = mainActivity;
|
||||
}
|
||||
|
||||
public static HttpsTabFragment newInstance(final MainActivity mainActivity) {
|
||||
final HttpsTabFragment fragment = new HttpsTabFragment();
|
||||
fragment.setMainActivity(mainActivity);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
public void enableLogCallback() {
|
||||
Config.enableLogCallback(new LogCallback() {
|
||||
|
||||
@Override
|
||||
public void apply(final LogMessage message) {
|
||||
MainActivity.addUIAction(new Callable() {
|
||||
|
||||
@Override
|
||||
public Object call() {
|
||||
appendLog(message.getText());
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void getInfo() {
|
||||
clearLog();
|
||||
|
||||
String testUrl = urlText.getText().toString();
|
||||
if (testUrl.isEmpty()) {
|
||||
testUrl = HTTPS_TEST_DEFAULT_URL;
|
||||
urlText.setText(testUrl);
|
||||
android.util.Log.d(MainActivity.TAG, String.format("Testing HTTPS with default url '%s'", testUrl));
|
||||
} else {
|
||||
android.util.Log.d(MainActivity.TAG, String.format("Testing HTTPS with url '%s'", testUrl));
|
||||
}
|
||||
|
||||
// HTTPS COMMAND ARGUMENTS
|
||||
final String ffmpegCommand = String.format("-hide_banner -i %s", testUrl);
|
||||
|
||||
android.util.Log.d(MainActivity.TAG, String.format("FFmpeg process started with arguments\n'%s'", ffmpegCommand));
|
||||
|
||||
// EXECUTE
|
||||
int result = FFmpeg.execute(ffmpegCommand);
|
||||
|
||||
android.util.Log.d(MainActivity.TAG, String.format("FFmpeg process exited with rc %d", result));
|
||||
}
|
||||
|
||||
public void setActive() {
|
||||
android.util.Log.i(MainActivity.TAG, "Https Tab Activated");
|
||||
enableLogCallback();
|
||||
Popup.show(mainActivity, Tooltip.HTTPS_TEST_TOOLTIP_TEXT);
|
||||
}
|
||||
|
||||
public void appendLog(final String logMessage) {
|
||||
outputText.append(logMessage);
|
||||
}
|
||||
|
||||
public void clearLog() {
|
||||
outputText.setText("");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,50 +19,140 @@
|
||||
|
||||
package com.arthenica.mobileffmpeg.test;
|
||||
|
||||
import android.arch.core.util.Function;
|
||||
import android.Manifest;
|
||||
import android.app.ActionBar;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.view.PagerTabStrip;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.arthenica.mobileffmpeg.Config;
|
||||
import com.arthenica.mobileffmpeg.FFmpeg;
|
||||
import com.arthenica.mobileffmpeg.util.RunCallback;
|
||||
import com.arthenica.mobileffmpeg.util.AsynchronousTaskService;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
public static final String TAG = "mobile-ffmpeg-test";
|
||||
|
||||
protected static AsynchronousTaskService asynchronousTaskService = new AsynchronousTaskService();
|
||||
public static final int REQUEST_EXTERNAL_STORAGE = 1;
|
||||
public static String[] PERMISSIONS_STORAGE = {
|
||||
Manifest.permission.READ_EXTERNAL_STORAGE,
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE
|
||||
};
|
||||
|
||||
protected static final AsynchronousTaskService asynchronousTaskService = new AsynchronousTaskService();
|
||||
|
||||
protected static final Queue<Callable> actionQueue = new ConcurrentLinkedQueue<>();
|
||||
|
||||
protected static final Handler handler = new Handler();
|
||||
|
||||
protected static final Runnable runnable = new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Callable callable;
|
||||
|
||||
do {
|
||||
callable = actionQueue.poll();
|
||||
if (callable != null) {
|
||||
try {
|
||||
callable.call();
|
||||
} catch (final Exception e) {
|
||||
android.util.Log.e(MainActivity.TAG, "Running UI action received error.", e);
|
||||
}
|
||||
}
|
||||
} while (callable != null);
|
||||
|
||||
handler.postDelayed(this, 250);
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
protected void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
final ViewPager viewPager = findViewById(R.id.pager);
|
||||
android.support.v7.app.ActionBar supportActionBar = getSupportActionBar();
|
||||
if (supportActionBar != null) {
|
||||
supportActionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
|
||||
supportActionBar.setCustomView(R.layout.action_bar);
|
||||
}
|
||||
|
||||
final PagerAdapter adapter = new PagerAdapter(getSupportFragmentManager(), this, 2);
|
||||
viewPager.setAdapter(adapter);
|
||||
PagerTabStrip pagerTabStrip = findViewById(R.id.pagerTabStrip);
|
||||
if (pagerTabStrip != null) {
|
||||
pagerTabStrip.setDrawFullUnderline(false);
|
||||
pagerTabStrip.setTabIndicatorColorResource(R.color.navigationColor);
|
||||
pagerTabStrip.setTextColor(Color.parseColor("#f39c12"));
|
||||
}
|
||||
|
||||
final ViewPager viewPager = findViewById(R.id.pager);
|
||||
viewPager.setAdapter(new PagerAdapter(getSupportFragmentManager(), this, 6));
|
||||
|
||||
waitForUIAction();
|
||||
|
||||
// VERIFY PERMISSIONS
|
||||
int permission = ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
||||
if (permission != PackageManager.PERMISSION_GRANTED) {
|
||||
ActivityCompat.requestPermissions(this,
|
||||
PERMISSIONS_STORAGE,
|
||||
REQUEST_EXTERNAL_STORAGE);
|
||||
}
|
||||
|
||||
try {
|
||||
registerAppFont();
|
||||
Log.d(TAG, "Application fonts registered.");
|
||||
} catch (final IOException e) {
|
||||
Log.e(TAG, "Font registration failed.", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
||||
handler.removeCallbacks(runnable);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Starts a new asynchronous FFmpeg operation with arguments provided.
|
||||
*
|
||||
* @param callbackFunction callback function to receive result of this execution
|
||||
* @param arguments FFmpeg command options/arguments
|
||||
* @param runCallback callback function to receive result of this execution
|
||||
* @param arguments FFmpeg command options/arguments
|
||||
* @return <code>Future</code> instance of asynchronous operation started
|
||||
*/
|
||||
public static Future executeAsync(final Function<Integer, Void> callbackFunction, final String ... arguments) {
|
||||
public static Future executeAsync(final RunCallback runCallback, final String arguments) {
|
||||
return asynchronousTaskService.runAsynchronously(new Callable<Integer>() {
|
||||
|
||||
@Override
|
||||
public Integer call() {
|
||||
int returnCode = FFmpeg.execute(arguments);
|
||||
if (callbackFunction != null) {
|
||||
callbackFunction.apply(returnCode);
|
||||
if (runCallback != null) {
|
||||
runCallback.apply(returnCode);
|
||||
}
|
||||
|
||||
return returnCode;
|
||||
@@ -70,11 +160,97 @@ public class MainActivity extends AppCompatActivity {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
public static void waitForUIAction() {
|
||||
handler.postDelayed(runnable, 250);
|
||||
}
|
||||
|
||||
FFmpeg.shutdown();
|
||||
public static void addUIAction(final Callable callable) {
|
||||
actionQueue.add(callable);
|
||||
}
|
||||
|
||||
public AlertDialog createProgressDialog(final String text) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
if (inflater != null) {
|
||||
View dialogView = inflater.inflate(R.layout.progress_dialog_layout, null);
|
||||
builder.setView(dialogView);
|
||||
|
||||
TextView textView = dialogView.findViewById(R.id.progressDialogText);
|
||||
if (textView != null) {
|
||||
textView.setText(text);
|
||||
}
|
||||
}
|
||||
builder.setCancelable(false);
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
public AlertDialog createCancellableProgressDialog(final String text, final View.OnClickListener onClickListener) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
if (inflater != null) {
|
||||
View dialogView = inflater.inflate(R.layout.cancellable_progress_dialog_layout, null);
|
||||
builder.setView(dialogView);
|
||||
|
||||
TextView textView = dialogView.findViewById(R.id.progressDialogText);
|
||||
if (textView != null) {
|
||||
textView.setText(text);
|
||||
}
|
||||
Button cancelButton = dialogView.findViewById(R.id.cancelButton);
|
||||
if (cancelButton != null) {
|
||||
cancelButton.setOnClickListener(onClickListener);
|
||||
}
|
||||
}
|
||||
builder.setCancelable(false);
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
protected void resourceToFile(final int resourceId, final File file) throws IOException {
|
||||
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), resourceId);
|
||||
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
|
||||
FileOutputStream outputStream = new FileOutputStream(file);
|
||||
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
}
|
||||
|
||||
protected void rawResourceToFile(final int resourceId, final File file) throws IOException {
|
||||
final InputStream inputStream = getResources().openRawResource(resourceId);
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
final FileOutputStream outputStream = new FileOutputStream(file);
|
||||
|
||||
try {
|
||||
final byte[] buffer = new byte[1024];
|
||||
int readSize;
|
||||
|
||||
while ((readSize = inputStream.read(buffer)) > 0) {
|
||||
outputStream.write(buffer, 0, readSize);
|
||||
}
|
||||
} catch (final IOException e) {
|
||||
Log.e(TAG, "Saving raw resource failed.", e);
|
||||
} finally {
|
||||
inputStream.close();
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
}
|
||||
}
|
||||
|
||||
protected void registerAppFont() throws IOException {
|
||||
final File cacheDirectory = getCacheDir();
|
||||
|
||||
// SAVE FONTS
|
||||
rawResourceToFile(R.raw.doppioone_regular, new File(cacheDirectory, "doppioone_regular.ttf"));
|
||||
rawResourceToFile(R.raw.truenorg, new File(cacheDirectory, "truenorg.otf"));
|
||||
|
||||
final HashMap<String, String> fontNameMapping = new HashMap<>();
|
||||
fontNameMapping.put("MyFontName", "Doppio One");
|
||||
Config.setFontDirectory(this, cacheDirectory.getAbsolutePath(), fontNameMapping);
|
||||
// Config.setFontDirectory(this, cacheDirectory.getAbsolutePath(), null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,30 +19,41 @@
|
||||
|
||||
package com.arthenica.mobileffmpeg.test;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
|
||||
public class PagerAdapter extends FragmentPagerAdapter {
|
||||
private Context context;
|
||||
private final MainActivity mainActivity;
|
||||
private int numberOfTabs;
|
||||
|
||||
PagerAdapter(FragmentManager fragmentManager, Context context, int numberOfTabs) {
|
||||
PagerAdapter(final FragmentManager fragmentManager, final MainActivity mainActivity, final int numberOfTabs) {
|
||||
super(fragmentManager);
|
||||
|
||||
this.context = context;
|
||||
this.mainActivity = mainActivity;
|
||||
this.numberOfTabs = numberOfTabs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
public Fragment getItem(final int position) {
|
||||
switch (position) {
|
||||
case 0: {
|
||||
return CommandTabFragment.newInstance(context);
|
||||
return CommandTabFragment.newInstance(mainActivity);
|
||||
}
|
||||
case 1: {
|
||||
return SlideshowTabFragment.newInstance(context);
|
||||
return VideoTabFragment.newInstance(mainActivity);
|
||||
}
|
||||
case 2: {
|
||||
return HttpsTabFragment.newInstance(mainActivity);
|
||||
}
|
||||
case 3: {
|
||||
return AudioTabFragment.newInstance(mainActivity);
|
||||
}
|
||||
case 4: {
|
||||
return SubtitleTabFragment.newInstance(mainActivity);
|
||||
}
|
||||
case 5: {
|
||||
return VidStabTabFragment.newInstance(mainActivity);
|
||||
}
|
||||
default: {
|
||||
return null;
|
||||
@@ -56,13 +67,25 @@ public class PagerAdapter extends FragmentPagerAdapter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getPageTitle(int position) {
|
||||
public CharSequence getPageTitle(final int position) {
|
||||
switch (position) {
|
||||
case 0: {
|
||||
return context.getString(R.string.command_tab);
|
||||
return mainActivity.getString(R.string.command_tab);
|
||||
}
|
||||
case 1: {
|
||||
return context.getString(R.string.slideshow_tab);
|
||||
return mainActivity.getString(R.string.video_tab);
|
||||
}
|
||||
case 2: {
|
||||
return mainActivity.getString(R.string.https_tab);
|
||||
}
|
||||
case 3: {
|
||||
return mainActivity.getString(R.string.audio_tab);
|
||||
}
|
||||
case 4: {
|
||||
return mainActivity.getString(R.string.subtitle_tab);
|
||||
}
|
||||
case 5: {
|
||||
return mainActivity.getString(R.string.vidstab_tab);
|
||||
}
|
||||
default: {
|
||||
return null;
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Taner Sener
|
||||
*
|
||||
* This file is part of MobileFFmpeg.
|
||||
*
|
||||
* MobileFFmpeg 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.
|
||||
*
|
||||
* MobileFFmpeg 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 MobileFFmpeg. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.arthenica.mobileffmpeg.test;
|
||||
|
||||
import android.content.Context;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class Popup {
|
||||
|
||||
public static void show(final Context context, final String message) {
|
||||
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Taner Sener
|
||||
*
|
||||
* This file is part of MobileFFmpeg.
|
||||
*
|
||||
* MobileFFmpeg 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.
|
||||
*
|
||||
* MobileFFmpeg 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 MobileFFmpeg. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.arthenica.mobileffmpeg.test;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* <p>Generates FFmpeg command arguments to create a 640x427 video from provided images
|
||||
*
|
||||
* @author Taner Sener
|
||||
*/
|
||||
public class Slideshow {
|
||||
|
||||
public static String generateScript(final File fileDirectory, final String image1, final String image2, final String image3, final String videoFile) {
|
||||
return
|
||||
"-loop 1 -i " + fileDirectory + "/" + image1 + " " +
|
||||
"-loop 1 -i " + fileDirectory + "/" + image2 + " " +
|
||||
"-loop 1 -i " + fileDirectory + "/" + image3 + " " +
|
||||
"-filter_complex " +
|
||||
"[0:v]setpts=PTS-STARTPTS,scale=w=\'if(gte(iw/ih,640/427),min(iw,640),-1)\':h=\'if(gte(iw/ih,640/427),-1,min(ih,427))\',scale=trunc(iw/2)*2:trunc(ih/2)*2,setsar=sar=1/1,split=2[stream1out1][stream1out2];"+
|
||||
"[1:v]setpts=PTS-STARTPTS,scale=w=\'if(gte(iw/ih,640/427),min(iw,640),-1)\':h=\'if(gte(iw/ih,640/427),-1,min(ih,427))\',scale=trunc(iw/2)*2:trunc(ih/2)*2,setsar=sar=1/1,split=2[stream2out1][stream2out2];"+
|
||||
"[2:v]setpts=PTS-STARTPTS,scale=w=\'if(gte(iw/ih,640/427),min(iw,640),-1)\':h=\'if(gte(iw/ih,640/427),-1,min(ih,427))\',scale=trunc(iw/2)*2:trunc(ih/2)*2,setsar=sar=1/1,split=2[stream3out1][stream3out2];"+
|
||||
"[stream1out1]pad=width=640:height=427:x=(640-iw)/2:y=(427-ih)/2:color=#00000000,trim=duration=3,select=lte(n\\,90)[stream1overlaid];"+
|
||||
"[stream1out2]pad=width=640:height=427:x=(640-iw)/2:y=(427-ih)/2:color=#00000000,trim=duration=1,select=lte(n\\,30)[stream1ending];"+
|
||||
"[stream2out1]pad=width=640:height=427:x=(640-iw)/2:y=(427-ih)/2:color=#00000000,trim=duration=2,select=lte(n\\,60)[stream2overlaid];"+
|
||||
"[stream2out2]pad=width=640:height=427:x=(640-iw)/2:y=(427-ih)/2:color=#00000000,trim=duration=1,select=lte(n\\,30),split=2[stream2starting][stream2ending];"+
|
||||
"[stream3out1]pad=width=640:height=427:x=(640-iw)/2:y=(427-ih)/2:color=#00000000,trim=duration=2,select=lte(n\\,60)[stream3overlaid];"+
|
||||
"[stream3out2]pad=width=640:height=427:x=(640-iw)/2:y=(427-ih)/2:color=#00000000,trim=duration=1,select=lte(n\\,30)[stream3starting];"+
|
||||
"[stream2starting][stream1ending]blend=all_expr=\'if(gte(X,(W/2)*T/1)*lte(X,W-(W/2)*T/1),B,A)\':shortest=1[stream2blended];"+
|
||||
"[stream3starting][stream2ending]blend=all_expr=\'if(gte(X,(W/2)*T/1)*lte(X,W-(W/2)*T/1),B,A)\':shortest=1[stream3blended];"+
|
||||
"[stream1overlaid][stream2blended][stream2overlaid][stream3blended][stream3overlaid]concat=n=5:v=1:a=0,format=yuv420p[video]"+
|
||||
" -map [video] -vsync 2 -async 1 -c:v mpeg4 -r 30 " + fileDirectory + "/" + videoFile;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,201 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Taner Sener
|
||||
*
|
||||
* This file is part of MobileFFmpeg.
|
||||
*
|
||||
* MobileFFmpeg 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.
|
||||
*
|
||||
* MobileFFmpeg 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 MobileFFmpeg. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.arthenica.mobileffmpeg.test;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.arch.core.util.Function;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Color;
|
||||
import android.media.MediaPlayer;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.MediaController;
|
||||
import android.widget.Toast;
|
||||
import android.widget.VideoView;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import static com.arthenica.mobileffmpeg.test.MainActivity.TAG;
|
||||
|
||||
public class SlideshowTabFragment extends Fragment {
|
||||
|
||||
private Context context;
|
||||
private View playButton;
|
||||
private String asyncResult;
|
||||
|
||||
public SlideshowTabFragment() {
|
||||
}
|
||||
|
||||
public static SlideshowTabFragment newInstance(final Context context) {
|
||||
final SlideshowTabFragment fragment = new SlideshowTabFragment();
|
||||
fragment.setContext(context);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
public void setContext(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.fragment_slideshow_tab, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
if (getView() != null) {
|
||||
View createButton = getView().findViewById(R.id.slideshowCreateButton);
|
||||
if (createButton != null) {
|
||||
createButton.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
createSlideshow();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
final VideoView videoView = getView().findViewById(R.id.videoView);
|
||||
videoView.setBackgroundColor(Color.LTGRAY);
|
||||
|
||||
// PLAY BUTTON IS DISABLED AT STARTUP
|
||||
playButton = getView().findViewById(R.id.slideshowPlayButton);
|
||||
if (playButton != null) {
|
||||
playButton.setEnabled(false);
|
||||
playButton.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
MediaController mediaController = new MediaController(context);
|
||||
mediaController.setAnchorView(videoView);
|
||||
videoView.setVideoURI(Uri.parse("file://" + getVideoPath()));
|
||||
videoView.setMediaController(mediaController);
|
||||
videoView.requestFocus();
|
||||
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
|
||||
|
||||
@Override
|
||||
public void onPrepared(MediaPlayer mp) {
|
||||
videoView.setBackgroundColor(0x00000000);
|
||||
}
|
||||
});
|
||||
videoView.start();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getVideoPath() {
|
||||
final String video = "slideshow.mp4";
|
||||
|
||||
return new File(context.getFilesDir(), video).getAbsolutePath();
|
||||
}
|
||||
|
||||
public void createSlideshow() {
|
||||
final String image1 = "colosseum.jpg";
|
||||
final String image2 = "pyramid.jpg";
|
||||
final String image3 = "tajmahal.jpg";
|
||||
|
||||
final ProgressDialog progressDialog = ProgressDialog.show(context, "", "Creating video slideshow");
|
||||
|
||||
try {
|
||||
resourceToFile(R.drawable.colosseum, image1);
|
||||
resourceToFile(R.drawable.pyramid, image2);
|
||||
resourceToFile(R.drawable.tajmahal, image3);
|
||||
|
||||
File file = new File(getVideoPath());
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
|
||||
asyncResult = null;
|
||||
|
||||
final Handler handler = new Handler();
|
||||
final Runnable runnable = new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (asyncResult != null) {
|
||||
String message = (asyncResult.equals("0")) ? "Slideshow created" : "Create failed with rc=" + asyncResult;
|
||||
|
||||
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
|
||||
|
||||
handler.removeCallbacks(this);
|
||||
|
||||
if (asyncResult.equals("0")) {
|
||||
playButton.setEnabled(true);
|
||||
}
|
||||
|
||||
} else {
|
||||
handler.postDelayed(this, 1000);
|
||||
}
|
||||
}
|
||||
};
|
||||
handler.postDelayed(runnable, 1000);
|
||||
|
||||
String script = Slideshow.generateScript(context.getFilesDir(), image1, image2, image3, file.getName());
|
||||
MainActivity.executeAsync(new Function<Integer, Void>() {
|
||||
|
||||
@Override
|
||||
public Void apply(Integer returnCode) {
|
||||
progressDialog.cancel();
|
||||
Log.i(TAG, "Create completed");
|
||||
asyncResult = String.valueOf(returnCode);
|
||||
return null;
|
||||
}
|
||||
}, script.split(" "));
|
||||
|
||||
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Creating slideshow failed", e);
|
||||
Toast.makeText(context, "Creating slideshow failed", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
protected void resourceToFile(final int resourceId, final String fileName) throws IOException {
|
||||
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), resourceId);
|
||||
|
||||
File file = new File(context.getFilesDir(), fileName);
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
|
||||
FileOutputStream outputStream = new FileOutputStream(file);
|
||||
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
Log.d(TAG, String.format("Saved resource %d to file %s.", resourceId, fileName));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,358 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Taner Sener
|
||||
*
|
||||
* This file is part of MobileFFmpeg.
|
||||
*
|
||||
* MobileFFmpeg 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.
|
||||
*
|
||||
* MobileFFmpeg 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 MobileFFmpeg. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.arthenica.mobileffmpeg.test;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.media.MediaPlayer;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.MediaController;
|
||||
import android.widget.TextView;
|
||||
import android.widget.VideoView;
|
||||
|
||||
import com.arthenica.mobileffmpeg.Config;
|
||||
import com.arthenica.mobileffmpeg.FFmpeg;
|
||||
import com.arthenica.mobileffmpeg.LogCallback;
|
||||
import com.arthenica.mobileffmpeg.LogMessage;
|
||||
import com.arthenica.mobileffmpeg.Statistics;
|
||||
import com.arthenica.mobileffmpeg.StatisticsCallback;
|
||||
import com.arthenica.mobileffmpeg.util.RunCallback;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import static com.arthenica.mobileffmpeg.FFmpeg.RETURN_CODE_CANCEL;
|
||||
import static com.arthenica.mobileffmpeg.FFmpeg.RETURN_CODE_SUCCESS;
|
||||
import static com.arthenica.mobileffmpeg.test.MainActivity.TAG;
|
||||
|
||||
public class SubtitleTabFragment extends Fragment {
|
||||
|
||||
private enum State {
|
||||
IDLE,
|
||||
CREATING,
|
||||
BURNING
|
||||
}
|
||||
|
||||
private MainActivity mainActivity;
|
||||
private VideoView videoView;
|
||||
private AlertDialog createProgressDialog;
|
||||
private AlertDialog burnProgressDialog;
|
||||
private Statistics statistics;
|
||||
private State state;
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.fragment_subtitle_tab, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
if (getView() != null) {
|
||||
View burnSubtitlesButton = getView().findViewById(R.id.burnSubtitlesButton);
|
||||
burnSubtitlesButton.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
burnSubtitles();
|
||||
}
|
||||
});
|
||||
|
||||
videoView = getView().findViewById(R.id.videoPlayerFrame);
|
||||
}
|
||||
|
||||
state = State.IDLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUserVisibleHint(boolean isVisibleToUser) {
|
||||
super.setUserVisibleHint(isVisibleToUser);
|
||||
if (isVisibleToUser) {
|
||||
setActive();
|
||||
}
|
||||
}
|
||||
|
||||
public void setMainActivity(MainActivity mainActivity) {
|
||||
this.mainActivity = mainActivity;
|
||||
}
|
||||
|
||||
public static SubtitleTabFragment newInstance(final MainActivity mainActivity) {
|
||||
final SubtitleTabFragment fragment = new SubtitleTabFragment();
|
||||
fragment.setMainActivity(mainActivity);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
public void enableLogCallback() {
|
||||
Config.enableLogCallback(new LogCallback() {
|
||||
|
||||
@Override
|
||||
public void apply(LogMessage message) {
|
||||
android.util.Log.d(MainActivity.TAG, message.getText());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void enableStatisticsCallback() {
|
||||
Config.enableStatisticsCallback(new StatisticsCallback() {
|
||||
|
||||
@Override
|
||||
public void apply(final Statistics newStatistics) {
|
||||
MainActivity.addUIAction(new Callable() {
|
||||
|
||||
@Override
|
||||
public Object call() {
|
||||
SubtitleTabFragment.this.statistics = newStatistics;
|
||||
updateProgressDialog();
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void burnSubtitles() {
|
||||
final File image1File = new File(mainActivity.getCacheDir(), "colosseum.jpg");
|
||||
final File image2File = new File(mainActivity.getCacheDir(), "pyramid.jpg");
|
||||
final File image3File = new File(mainActivity.getCacheDir(), "tajmahal.jpg");
|
||||
final File videoFile = getVideoFile();
|
||||
final File videoWithSubtitlesFile = getVideoWithSubtitlesFile();
|
||||
|
||||
try {
|
||||
|
||||
// IF VIDEO IS PLAYING STOP PLAYBACK
|
||||
videoView.stopPlayback();
|
||||
|
||||
if (videoFile.exists()) {
|
||||
videoFile.delete();
|
||||
}
|
||||
|
||||
if (videoWithSubtitlesFile.exists()) {
|
||||
videoWithSubtitlesFile.delete();
|
||||
}
|
||||
|
||||
Log.d(TAG, "Testing SUBTITLE burning");
|
||||
|
||||
showCreateProgressDialog();
|
||||
|
||||
mainActivity.resourceToFile(R.drawable.colosseum, image1File);
|
||||
mainActivity.resourceToFile(R.drawable.pyramid, image2File);
|
||||
mainActivity.resourceToFile(R.drawable.tajmahal, image3File);
|
||||
mainActivity.rawResourceToFile(R.raw.subtitle, getSubtitleFile());
|
||||
|
||||
final String ffmpegCommand = Video.generateEncodeVideoScript(image1File.getAbsolutePath(), image2File.getAbsolutePath(), image3File.getAbsolutePath(), videoFile.getAbsolutePath(), "mpeg4", "");
|
||||
|
||||
Log.d(TAG, String.format("FFmpeg process started with arguments\n'%s'", ffmpegCommand));
|
||||
|
||||
state = State.CREATING;
|
||||
|
||||
MainActivity.executeAsync(new RunCallback() {
|
||||
|
||||
@Override
|
||||
public void apply(final int returnCode) {
|
||||
Log.d(TAG, String.format("FFmpeg process exited with rc %d", returnCode));
|
||||
|
||||
state = State.IDLE;
|
||||
|
||||
hideCreateProgressDialog();
|
||||
|
||||
MainActivity.addUIAction(new Callable() {
|
||||
|
||||
@Override
|
||||
public Object call() {
|
||||
if (returnCode == RETURN_CODE_SUCCESS) {
|
||||
|
||||
Log.d(TAG, "Create completed successfully; burning subtitles.");
|
||||
|
||||
String burnSubtitlesCommand = String.format("-y -i %s -vf subtitles=%s:force_style='FontName=MyFontName' -c:v mpeg4 %s", videoFile.getAbsolutePath(), getSubtitleFile().getAbsolutePath(), videoWithSubtitlesFile.getAbsolutePath());
|
||||
|
||||
showBurnProgressDialog();
|
||||
|
||||
Log.d(TAG, String.format("FFmpeg process started with arguments\n'%s'", burnSubtitlesCommand));
|
||||
|
||||
state = State.BURNING;
|
||||
|
||||
MainActivity.executeAsync(new RunCallback() {
|
||||
|
||||
@Override
|
||||
public void apply(final int returnCode) {
|
||||
Log.d(TAG, String.format("FFmpeg process exited with rc %d", returnCode));
|
||||
|
||||
state = State.IDLE;
|
||||
|
||||
hideBurnProgressDialog();
|
||||
|
||||
MainActivity.addUIAction(new Callable() {
|
||||
|
||||
@Override
|
||||
public Object call() {
|
||||
if (returnCode == RETURN_CODE_SUCCESS) {
|
||||
Log.d(TAG, "Burn subtitles completed successfully; playing video.");
|
||||
playVideo();
|
||||
} else if (returnCode == RETURN_CODE_CANCEL) {
|
||||
Popup.show(mainActivity, "Burn subtitles operation cancelled.");
|
||||
Log.d(TAG, "Burn subtitles operation cancelled");
|
||||
} else {
|
||||
Popup.show(mainActivity, "Burn subtitles failed. Please check log for the details.");
|
||||
Log.d(TAG, String.format("Burn subtitles failed with rc=%d", returnCode));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}, burnSubtitlesCommand);
|
||||
|
||||
} else if (returnCode == RETURN_CODE_CANCEL) {
|
||||
Popup.show(mainActivity, "Create operation cancelled.");
|
||||
Log.d(TAG, "Create operation cancelled");
|
||||
} else {
|
||||
Popup.show(mainActivity, "Create video failed. Please check log for the details.");
|
||||
Log.d(TAG, String.format("Create failed with rc=%d", returnCode));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}, ffmpegCommand);
|
||||
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Burn subtitles failed", e);
|
||||
Popup.show(mainActivity, "Burn subtitles failed");
|
||||
}
|
||||
}
|
||||
|
||||
protected void playVideo() {
|
||||
MediaController mediaController = new MediaController(mainActivity);
|
||||
mediaController.setAnchorView(videoView);
|
||||
videoView.setVideoURI(Uri.parse("file://" + getVideoWithSubtitlesFile().getAbsolutePath()));
|
||||
videoView.setMediaController(mediaController);
|
||||
videoView.requestFocus();
|
||||
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
|
||||
|
||||
@Override
|
||||
public void onPrepared(MediaPlayer mp) {
|
||||
videoView.setBackgroundColor(0x00000000);
|
||||
}
|
||||
});
|
||||
videoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {
|
||||
|
||||
@Override
|
||||
public boolean onError(MediaPlayer mp, int what, int extra) {
|
||||
videoView.stopPlayback();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
videoView.start();
|
||||
}
|
||||
|
||||
public File getSubtitleFile() {
|
||||
return new File(mainActivity.getCacheDir(), "subtitle.srt");
|
||||
}
|
||||
|
||||
public File getVideoFile() {
|
||||
return new File(mainActivity.getFilesDir(), "video.mp4");
|
||||
}
|
||||
|
||||
public File getVideoWithSubtitlesFile() {
|
||||
return new File(mainActivity.getFilesDir(), "video-with-subtitles.mp4");
|
||||
}
|
||||
|
||||
public void setActive() {
|
||||
android.util.Log.i(MainActivity.TAG, "Subtitle Tab Activated");
|
||||
enableLogCallback();
|
||||
enableStatisticsCallback();
|
||||
Popup.show(mainActivity, Tooltip.SUBTITLE_TEST_TOOLTIP_TEXT);
|
||||
}
|
||||
|
||||
protected void showCreateProgressDialog() {
|
||||
|
||||
// CLEAN STATISTICS
|
||||
statistics = null;
|
||||
Config.resetStatistics();
|
||||
|
||||
createProgressDialog = mainActivity.createCancellableProgressDialog("Creating video", new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
FFmpeg.cancel();
|
||||
}
|
||||
});
|
||||
createProgressDialog.show();
|
||||
}
|
||||
|
||||
protected void updateProgressDialog() {
|
||||
if (statistics == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int timeInMilliseconds = this.statistics.getTime();
|
||||
int totalVideoDuration = 9000;
|
||||
|
||||
String completePercentage = new BigDecimal(timeInMilliseconds).multiply(new BigDecimal(100)).divide(new BigDecimal(totalVideoDuration), 0, BigDecimal.ROUND_HALF_UP).toString();
|
||||
|
||||
if (state == State.CREATING) {
|
||||
TextView textView = createProgressDialog.findViewById(R.id.progressDialogText);
|
||||
if (textView != null) {
|
||||
textView.setText(String.format("Creating video: %% %s", completePercentage));
|
||||
}
|
||||
} else if (state == State.BURNING) {
|
||||
TextView textView = burnProgressDialog.findViewById(R.id.progressDialogText);
|
||||
if (textView != null) {
|
||||
textView.setText(String.format("Burning subtitles: %% %s", completePercentage));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void hideCreateProgressDialog() {
|
||||
createProgressDialog.dismiss();
|
||||
}
|
||||
|
||||
protected void showBurnProgressDialog() {
|
||||
|
||||
// CLEAN STATISTICS
|
||||
statistics = null;
|
||||
Config.resetStatistics();
|
||||
|
||||
burnProgressDialog = mainActivity.createCancellableProgressDialog("Burning subtitles", new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
FFmpeg.cancel();
|
||||
}
|
||||
});
|
||||
burnProgressDialog.show();
|
||||
}
|
||||
|
||||
protected void hideBurnProgressDialog() {
|
||||
burnProgressDialog.dismiss();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Taner Sener
|
||||
*
|
||||
* This file is part of MobileFFmpeg.
|
||||
*
|
||||
* MobileFFmpeg 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.
|
||||
*
|
||||
* MobileFFmpeg 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 MobileFFmpeg. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.arthenica.mobileffmpeg.test;
|
||||
|
||||
public interface Tooltip {
|
||||
|
||||
// COMMAND TEST
|
||||
String COMMAND_TEST_TOOLTIP_TEXT = "Enter an FFmpeg command without 'ffmpeg' at the beginning and click one of the RUN buttons";
|
||||
|
||||
// VIDEO TEST
|
||||
String VIDEO_TEST_TOOLTIP_TEXT = "Select a video codec and press ENCODE button";
|
||||
|
||||
// HTTPS TEST
|
||||
String HTTPS_TEST_TOOLTIP_TEXT = "Enter the https url of a media file and click the button";
|
||||
|
||||
// AUDIO TEST
|
||||
String AUDIO_TEST_TOOLTIP_TEXT = "Select an audio codec and press ENCODE button";
|
||||
|
||||
// SUBTITLE TEST
|
||||
String SUBTITLE_TEST_TOOLTIP_TEXT = "Click the button to burn subtitles. Created video will play inside the frame below";
|
||||
|
||||
// VID.STAB TEST
|
||||
String VIDSTAB_TEST_TOOLTIP_TEXT = "Click the button to stabilize video. Original video will play above and stabilized video will play below";
|
||||
|
||||
}
|
||||
@@ -0,0 +1,313 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Taner Sener
|
||||
*
|
||||
* This file is part of MobileFFmpeg.
|
||||
*
|
||||
* MobileFFmpeg 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.
|
||||
*
|
||||
* MobileFFmpeg 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 MobileFFmpeg. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.arthenica.mobileffmpeg.test;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.media.MediaPlayer;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.MediaController;
|
||||
import android.widget.VideoView;
|
||||
|
||||
import com.arthenica.mobileffmpeg.Config;
|
||||
import com.arthenica.mobileffmpeg.LogCallback;
|
||||
import com.arthenica.mobileffmpeg.LogMessage;
|
||||
import com.arthenica.mobileffmpeg.util.RunCallback;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import static com.arthenica.mobileffmpeg.FFmpeg.RETURN_CODE_SUCCESS;
|
||||
import static com.arthenica.mobileffmpeg.test.MainActivity.TAG;
|
||||
|
||||
public class VidStabTabFragment extends Fragment {
|
||||
|
||||
private MainActivity mainActivity;
|
||||
private VideoView videoView;
|
||||
private VideoView stabilizedVideoView;
|
||||
private AlertDialog createProgressDialog;
|
||||
private AlertDialog stabilizeProgressDialog;
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.fragment_vidstab_tab, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
if (getView() != null) {
|
||||
View stabilizeVideoButton = getView().findViewById(R.id.stabilizeVideoButton);
|
||||
stabilizeVideoButton.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
stabilizeVideo();
|
||||
}
|
||||
});
|
||||
|
||||
videoView = getView().findViewById(R.id.videoPlayerFrame);
|
||||
stabilizedVideoView = getView().findViewById(R.id.stabilizedVideoPlayerFrame);
|
||||
}
|
||||
|
||||
createProgressDialog = mainActivity.createProgressDialog("Creating video");
|
||||
stabilizeProgressDialog = mainActivity.createProgressDialog("Stabilizing video");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUserVisibleHint(boolean isVisibleToUser) {
|
||||
super.setUserVisibleHint(isVisibleToUser);
|
||||
if (isVisibleToUser) {
|
||||
setActive();
|
||||
}
|
||||
}
|
||||
|
||||
public void setMainActivity(MainActivity mainActivity) {
|
||||
this.mainActivity = mainActivity;
|
||||
}
|
||||
|
||||
public static VidStabTabFragment newInstance(final MainActivity mainActivity) {
|
||||
final VidStabTabFragment fragment = new VidStabTabFragment();
|
||||
fragment.setMainActivity(mainActivity);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
public void enableLogCallback() {
|
||||
Config.enableLogCallback(new LogCallback() {
|
||||
|
||||
@Override
|
||||
public void apply(LogMessage message) {
|
||||
android.util.Log.d(MainActivity.TAG, message.getText());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void stabilizeVideo() {
|
||||
final File image1File = new File(mainActivity.getCacheDir(), "colosseum.jpg");
|
||||
final File image2File = new File(mainActivity.getCacheDir(), "pyramid.jpg");
|
||||
final File image3File = new File(mainActivity.getCacheDir(), "tajmahal.jpg");
|
||||
final File shakeResultsFile = getShakeResultsFile();
|
||||
final File videoFile = getVideoFile();
|
||||
final File stabilizedVideoFile = getStabilizedVideoFile();
|
||||
|
||||
try {
|
||||
|
||||
// IF VIDEO IS PLAYING STOP PLAYBACK
|
||||
videoView.stopPlayback();
|
||||
stabilizedVideoView.stopPlayback();
|
||||
|
||||
if (shakeResultsFile.exists()) {
|
||||
shakeResultsFile.delete();
|
||||
}
|
||||
if (videoFile.exists()) {
|
||||
videoFile.delete();
|
||||
}
|
||||
if (stabilizedVideoFile.exists()) {
|
||||
stabilizedVideoFile.delete();
|
||||
}
|
||||
|
||||
android.util.Log.d(TAG, "Testing VID.STAB");
|
||||
|
||||
showCreateProgressDialog();
|
||||
|
||||
mainActivity.resourceToFile(R.drawable.colosseum, image1File);
|
||||
mainActivity.resourceToFile(R.drawable.pyramid, image2File);
|
||||
mainActivity.resourceToFile(R.drawable.tajmahal, image3File);
|
||||
|
||||
final String ffmpegCommand = Video.generateShakingVideoScript(image1File.getAbsolutePath(), image2File.getAbsolutePath(), image3File.getAbsolutePath(), videoFile.getAbsolutePath());
|
||||
|
||||
android.util.Log.d(TAG, String.format("FFmpeg process started with arguments\n'%s'", ffmpegCommand));
|
||||
|
||||
MainActivity.executeAsync(new RunCallback() {
|
||||
|
||||
@Override
|
||||
public void apply(final int returnCode) {
|
||||
android.util.Log.d(TAG, String.format("FFmpeg process exited with rc %d", returnCode));
|
||||
|
||||
hideCreateProgressDialog();
|
||||
|
||||
MainActivity.addUIAction(new Callable() {
|
||||
|
||||
@Override
|
||||
public Object call() {
|
||||
if (returnCode == RETURN_CODE_SUCCESS) {
|
||||
|
||||
android.util.Log.d(TAG, "Create completed successfully; stabilizing video.");
|
||||
|
||||
final String analyzeVideoCommand = String.format("-y -i %s -vf vidstabdetect=shakiness=10:accuracy=15:result=%s -f null -", videoFile.getAbsolutePath(), shakeResultsFile.getAbsolutePath());
|
||||
|
||||
showStabilizeProgressDialog();
|
||||
|
||||
android.util.Log.d(TAG, String.format("FFmpeg process started with arguments\n'%s'", analyzeVideoCommand));
|
||||
|
||||
MainActivity.executeAsync(new RunCallback() {
|
||||
|
||||
@Override
|
||||
public void apply(final int returnCode) {
|
||||
android.util.Log.d(TAG, String.format("FFmpeg process exited with rc %d", returnCode));
|
||||
|
||||
if (returnCode == RETURN_CODE_SUCCESS) {
|
||||
final String stabilizeVideoCommand = String.format("-y -i %s -vf vidstabtransform=smoothing=30:input=%s -c:v mpeg4 %s", videoFile.getAbsolutePath(), shakeResultsFile.getAbsolutePath(), stabilizedVideoFile.getAbsolutePath());
|
||||
|
||||
android.util.Log.d(TAG, String.format("FFmpeg process started with arguments\n'%s'", stabilizeVideoCommand));
|
||||
|
||||
MainActivity.executeAsync(new RunCallback() {
|
||||
|
||||
@Override
|
||||
public void apply(final int returnCode) {
|
||||
android.util.Log.d(TAG, String.format("FFmpeg process exited with rc %d", returnCode));
|
||||
|
||||
hideStabilizeProgressDialog();
|
||||
|
||||
MainActivity.addUIAction(new Callable() {
|
||||
|
||||
@Override
|
||||
public Object call() {
|
||||
if (returnCode == RETURN_CODE_SUCCESS) {
|
||||
android.util.Log.d(TAG, "Stabilize video completed successfully; playing videos.");
|
||||
playVideo();
|
||||
playStabilizedVideo();
|
||||
} else {
|
||||
Popup.show(mainActivity, "Stabilize video failed. Please check log for the details.");
|
||||
android.util.Log.d(TAG, String.format("Stabilize video failed with rc=%d", returnCode));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}, stabilizeVideoCommand);
|
||||
|
||||
} else {
|
||||
hideStabilizeProgressDialog();
|
||||
Popup.show(mainActivity, "Stabilize video failed. Please check log for the details.");
|
||||
android.util.Log.d(TAG, String.format("Stabilize video failed with rc=%d", returnCode));
|
||||
}
|
||||
}
|
||||
}, analyzeVideoCommand);
|
||||
|
||||
} else {
|
||||
Popup.show(mainActivity, "Create video failed. Please check log for the details.");
|
||||
android.util.Log.d(TAG, String.format("Create failed with rc=%d", returnCode));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}, ffmpegCommand);
|
||||
|
||||
} catch (IOException e) {
|
||||
android.util.Log.e(TAG, "Stabilize video failed", e);
|
||||
Popup.show(mainActivity, "Stabilize video failed");
|
||||
}
|
||||
}
|
||||
|
||||
protected void playVideo() {
|
||||
MediaController mediaController = new MediaController(mainActivity);
|
||||
mediaController.setAnchorView(videoView);
|
||||
videoView.setVideoURI(Uri.parse("file://" + getVideoFile().getAbsolutePath()));
|
||||
videoView.setMediaController(mediaController);
|
||||
videoView.requestFocus();
|
||||
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
|
||||
|
||||
@Override
|
||||
public void onPrepared(MediaPlayer mp) {
|
||||
videoView.setBackgroundColor(0x00000000);
|
||||
}
|
||||
});
|
||||
videoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {
|
||||
|
||||
@Override
|
||||
public boolean onError(MediaPlayer mp, int what, int extra) {
|
||||
videoView.stopPlayback();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
videoView.start();
|
||||
}
|
||||
|
||||
protected void playStabilizedVideo() {
|
||||
MediaController mediaController = new MediaController(mainActivity);
|
||||
mediaController.setAnchorView(stabilizedVideoView);
|
||||
stabilizedVideoView.setVideoURI(Uri.parse("file://" + getStabilizedVideoFile().getAbsolutePath()));
|
||||
stabilizedVideoView.setMediaController(mediaController);
|
||||
stabilizedVideoView.requestFocus();
|
||||
stabilizedVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
|
||||
|
||||
@Override
|
||||
public void onPrepared(MediaPlayer mp) {
|
||||
stabilizedVideoView.setBackgroundColor(0x00000000);
|
||||
}
|
||||
});
|
||||
stabilizedVideoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {
|
||||
|
||||
@Override
|
||||
public boolean onError(MediaPlayer mp, int what, int extra) {
|
||||
stabilizedVideoView.stopPlayback();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
stabilizedVideoView.start();
|
||||
}
|
||||
|
||||
public File getShakeResultsFile() {
|
||||
return new File(mainActivity.getCacheDir(), "transforms.trf");
|
||||
}
|
||||
|
||||
public File getVideoFile() {
|
||||
return new File(mainActivity.getFilesDir(), "video.mp4");
|
||||
}
|
||||
|
||||
public File getStabilizedVideoFile() {
|
||||
return new File(mainActivity.getFilesDir(), "video-stabilized.mp4");
|
||||
}
|
||||
|
||||
public void setActive() {
|
||||
android.util.Log.i(MainActivity.TAG, "VidStab Tab Activated");
|
||||
enableLogCallback();
|
||||
Popup.show(mainActivity, Tooltip.VIDSTAB_TEST_TOOLTIP_TEXT);
|
||||
}
|
||||
|
||||
protected void showCreateProgressDialog() {
|
||||
createProgressDialog.show();
|
||||
}
|
||||
|
||||
protected void hideCreateProgressDialog() {
|
||||
createProgressDialog.dismiss();
|
||||
}
|
||||
|
||||
protected void showStabilizeProgressDialog() {
|
||||
stabilizeProgressDialog.show();
|
||||
}
|
||||
|
||||
protected void hideStabilizeProgressDialog() {
|
||||
stabilizeProgressDialog.dismiss();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Taner Sener
|
||||
*
|
||||
* This file is part of MobileFFmpeg.
|
||||
*
|
||||
* MobileFFmpeg 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.
|
||||
*
|
||||
* MobileFFmpeg 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 MobileFFmpeg. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.arthenica.mobileffmpeg.test;
|
||||
|
||||
/**
|
||||
* <p>Generates an FFmpeg command to create a 640x427 video from provided images.
|
||||
*
|
||||
* @author Taner Sener
|
||||
*/
|
||||
public class Video {
|
||||
|
||||
public static String generateEncodeVideoScript(final String image1Path, final String image2Path, final String image3Path, final String videoFilePath, final String videoCodec, final String customOptions) {
|
||||
return
|
||||
"-y -loop 1 -i " + image1Path + " " +
|
||||
"-loop 1 -i " + image2Path + " " +
|
||||
"-loop 1 -i " + image3Path + " " +
|
||||
"-filter_complex " +
|
||||
"[0:v]setpts=PTS-STARTPTS,scale=w=\'if(gte(iw/ih,640/427),min(iw,640),-1)\':h=\'if(gte(iw/ih,640/427),-1,min(ih,427))\',scale=trunc(iw/2)*2:trunc(ih/2)*2,setsar=sar=1/1,split=2[stream1out1][stream1out2];" +
|
||||
"[1:v]setpts=PTS-STARTPTS,scale=w=\'if(gte(iw/ih,640/427),min(iw,640),-1)\':h=\'if(gte(iw/ih,640/427),-1,min(ih,427))\',scale=trunc(iw/2)*2:trunc(ih/2)*2,setsar=sar=1/1,split=2[stream2out1][stream2out2];" +
|
||||
"[2:v]setpts=PTS-STARTPTS,scale=w=\'if(gte(iw/ih,640/427),min(iw,640),-1)\':h=\'if(gte(iw/ih,640/427),-1,min(ih,427))\',scale=trunc(iw/2)*2:trunc(ih/2)*2,setsar=sar=1/1,split=2[stream3out1][stream3out2];" +
|
||||
"[stream1out1]pad=width=640:height=427:x=(640-iw)/2:y=(427-ih)/2:color=#00000000,trim=duration=3,select=lte(n\\,90)[stream1overlaid];" +
|
||||
"[stream1out2]pad=width=640:height=427:x=(640-iw)/2:y=(427-ih)/2:color=#00000000,trim=duration=1,select=lte(n\\,30)[stream1ending];" +
|
||||
"[stream2out1]pad=width=640:height=427:x=(640-iw)/2:y=(427-ih)/2:color=#00000000,trim=duration=2,select=lte(n\\,60)[stream2overlaid];" +
|
||||
"[stream2out2]pad=width=640:height=427:x=(640-iw)/2:y=(427-ih)/2:color=#00000000,trim=duration=1,select=lte(n\\,30),split=2[stream2starting][stream2ending];" +
|
||||
"[stream3out1]pad=width=640:height=427:x=(640-iw)/2:y=(427-ih)/2:color=#00000000,trim=duration=2,select=lte(n\\,60)[stream3overlaid];" +
|
||||
"[stream3out2]pad=width=640:height=427:x=(640-iw)/2:y=(427-ih)/2:color=#00000000,trim=duration=1,select=lte(n\\,30)[stream3starting];" +
|
||||
"[stream2starting][stream1ending]blend=all_expr=\'if(gte(X,(W/2)*T/1)*lte(X,W-(W/2)*T/1),B,A)\':shortest=1[stream2blended];" +
|
||||
"[stream3starting][stream2ending]blend=all_expr=\'if(gte(X,(W/2)*T/1)*lte(X,W-(W/2)*T/1),B,A)\':shortest=1[stream3blended];" +
|
||||
"[stream1overlaid][stream2blended][stream2overlaid][stream3blended][stream3overlaid]concat=n=5:v=1:a=0,scale=w=640:h=424,format=yuv420p[video]" +
|
||||
" -map [video] -vsync 2 -async 1 " + customOptions + "-c:v " + videoCodec.toLowerCase() + " -r 30 " + videoFilePath;
|
||||
}
|
||||
|
||||
public static String generateShakingVideoScript(final String image1Path, final String image2Path, final String image3Path, final String videoFilePath) {
|
||||
return
|
||||
"-y -loop 1 -i " + image1Path + " " +
|
||||
"-loop 1 -i " + image2Path + " " +
|
||||
"-loop 1 -i " + image3Path + " " +
|
||||
"-f lavfi -i color=black:s=640x427 " +
|
||||
"-filter_complex " +
|
||||
"[0:v]setpts=PTS-STARTPTS,scale=w=\'if(gte(iw/ih,640/427),min(iw,640),-1)\':h=\'if(gte(iw/ih,640/427),-1,min(ih,427))\',scale=trunc(iw/2)*2:trunc(ih/2)*2,setsar=sar=1/1[stream1out];" +
|
||||
"[1:v]setpts=PTS-STARTPTS,scale=w=\'if(gte(iw/ih,640/427),min(iw,640),-1)\':h=\'if(gte(iw/ih,640/427),-1,min(ih,427))\',scale=trunc(iw/2)*2:trunc(ih/2)*2,setsar=sar=1/1[stream2out];" +
|
||||
"[2:v]setpts=PTS-STARTPTS,scale=w=\'if(gte(iw/ih,640/427),min(iw,640),-1)\':h=\'if(gte(iw/ih,640/427),-1,min(ih,427))\',scale=trunc(iw/2)*2:trunc(ih/2)*2,setsar=sar=1/1[stream3out];" +
|
||||
"[stream1out]pad=width=640:height=427:x=(640-iw)/2:y=(427-ih)/2:color=#00000000,trim=duration=3[stream1overlaid];" +
|
||||
"[stream2out]pad=width=640:height=427:x=(640-iw)/2:y=(427-ih)/2:color=#00000000,trim=duration=3[stream2overlaid];" +
|
||||
"[stream3out]pad=width=640:height=427:x=(640-iw)/2:y=(427-ih)/2:color=#00000000,trim=duration=3[stream3overlaid];" +
|
||||
"[3:v][stream1overlaid]overlay=x=\'2*mod(n,4)\':y=\'2*mod(n,2)\',trim=duration=3[stream1shaking];" +
|
||||
"[3:v][stream2overlaid]overlay=x=\'2*mod(n,4)\':y=\'2*mod(n,2)\',trim=duration=3[stream2shaking];" +
|
||||
"[3:v][stream3overlaid]overlay=x=\'2*mod(n,4)\':y=\'2*mod(n,2)\',trim=duration=3[stream3shaking];" +
|
||||
"[stream1shaking][stream2shaking][stream3shaking]concat=n=3:v=1:a=0,scale=w=640:h=424,format=yuv420p[video]" +
|
||||
" -map [video] -vsync 2 -async 1 -c:v mpeg4 -r 30 " + videoFilePath;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,374 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Taner Sener
|
||||
*
|
||||
* This file is part of MobileFFmpeg.
|
||||
*
|
||||
* MobileFFmpeg 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.
|
||||
*
|
||||
* MobileFFmpeg 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 MobileFFmpeg. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.arthenica.mobileffmpeg.test;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.media.MediaPlayer;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.MediaController;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
import android.widget.VideoView;
|
||||
|
||||
import com.arthenica.mobileffmpeg.Config;
|
||||
import com.arthenica.mobileffmpeg.LogCallback;
|
||||
import com.arthenica.mobileffmpeg.LogMessage;
|
||||
import com.arthenica.mobileffmpeg.util.RunCallback;
|
||||
import com.arthenica.mobileffmpeg.Statistics;
|
||||
import com.arthenica.mobileffmpeg.StatisticsCallback;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import static com.arthenica.mobileffmpeg.FFmpeg.RETURN_CODE_SUCCESS;
|
||||
import static com.arthenica.mobileffmpeg.test.MainActivity.TAG;
|
||||
|
||||
public class VideoTabFragment extends Fragment implements AdapterView.OnItemSelectedListener {
|
||||
|
||||
private MainActivity mainActivity;
|
||||
private VideoView videoView;
|
||||
private AlertDialog progressDialog;
|
||||
private String selectedCodec;
|
||||
private Statistics statistics;
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.fragment_video_tab, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
if (getView() != null) {
|
||||
Spinner videoCodecSpinner = getView().findViewById(R.id.videoCodecSpinner);
|
||||
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(mainActivity,
|
||||
R.array.video_codec, R.layout.spinner_item);
|
||||
adapter.setDropDownViewResource(R.layout.spinner_dropdown_item);
|
||||
videoCodecSpinner.setAdapter(adapter);
|
||||
videoCodecSpinner.setOnItemSelectedListener(this);
|
||||
|
||||
View encodeButton = getView().findViewById(R.id.encodeButton);
|
||||
if (encodeButton != null) {
|
||||
encodeButton.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
encodeVideo();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
videoView = getView().findViewById(R.id.videoPlayerFrame);
|
||||
}
|
||||
|
||||
progressDialog = mainActivity.createProgressDialog("Encoding video");
|
||||
|
||||
selectedCodec = getResources().getStringArray(R.array.video_codec)[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUserVisibleHint(boolean isVisibleToUser) {
|
||||
super.setUserVisibleHint(isVisibleToUser);
|
||||
if (isVisibleToUser) {
|
||||
setActive();
|
||||
}
|
||||
}
|
||||
|
||||
public void setMainActivity(MainActivity mainActivity) {
|
||||
this.mainActivity = mainActivity;
|
||||
}
|
||||
|
||||
public static VideoTabFragment newInstance(final MainActivity mainActivity) {
|
||||
final VideoTabFragment fragment = new VideoTabFragment();
|
||||
fragment.setMainActivity(mainActivity);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
public void enableLogCallback() {
|
||||
Config.enableLogCallback(new LogCallback() {
|
||||
|
||||
@Override
|
||||
public void apply(LogMessage message) {
|
||||
android.util.Log.d(MainActivity.TAG, message.getText());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void enableStatisticsCallback() {
|
||||
Config.enableStatisticsCallback(new StatisticsCallback() {
|
||||
|
||||
@Override
|
||||
public void apply(final Statistics newStatistics) {
|
||||
MainActivity.addUIAction(new Callable() {
|
||||
|
||||
@Override
|
||||
public Object call() {
|
||||
VideoTabFragment.this.statistics = newStatistics;
|
||||
updateProgressDialog();
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
selectedCodec = parent.getItemAtPosition(position).toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
// DO NOTHING
|
||||
}
|
||||
|
||||
public void encodeVideo() {
|
||||
final File image1File = new File(mainActivity.getCacheDir(), "colosseum.jpg");
|
||||
final File image2File = new File(mainActivity.getCacheDir(), "pyramid.jpg");
|
||||
final File image3File = new File(mainActivity.getCacheDir(), "tajmahal.jpg");
|
||||
final File videoFile = getVideoFile();
|
||||
|
||||
try {
|
||||
|
||||
// IF VIDEO IS PLAYING STOP PLAYBACK
|
||||
videoView.stopPlayback();
|
||||
|
||||
if (videoFile.exists()) {
|
||||
videoFile.delete();
|
||||
}
|
||||
|
||||
final String videoCodec = selectedCodec;
|
||||
|
||||
Log.d(TAG, String.format("Testing VIDEO encoding with '%s' codec", videoCodec));
|
||||
|
||||
showProgressDialog();
|
||||
|
||||
mainActivity.resourceToFile(R.drawable.colosseum, image1File);
|
||||
mainActivity.resourceToFile(R.drawable.pyramid, image2File);
|
||||
mainActivity.resourceToFile(R.drawable.tajmahal, image3File);
|
||||
|
||||
final String ffmpegCommand = Video.generateEncodeVideoScript(image1File.getAbsolutePath(), image2File.getAbsolutePath(), image3File.getAbsolutePath(), videoFile.getAbsolutePath(), getSelectedVideoCodec(), getCustomOptions());
|
||||
|
||||
Log.d(TAG, String.format("FFmpeg process started with arguments\n'%s'", ffmpegCommand));
|
||||
|
||||
MainActivity.executeAsync(new RunCallback() {
|
||||
|
||||
@Override
|
||||
public void apply(final int returnCode) {
|
||||
Log.d(TAG, String.format("FFmpeg process exited with rc %d", returnCode));
|
||||
|
||||
hideProgressDialog();
|
||||
|
||||
MainActivity.addUIAction(new Callable() {
|
||||
|
||||
@Override
|
||||
public Object call() {
|
||||
if (returnCode == RETURN_CODE_SUCCESS) {
|
||||
Log.d(TAG, "Encode completed successfully; playing video.");
|
||||
playVideo();
|
||||
} else {
|
||||
Popup.show(mainActivity, "Encode failed. Please check log for the details.");
|
||||
Log.d(TAG, String.format("Encode failed with rc=%d", returnCode));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}, ffmpegCommand);
|
||||
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Encode video failed", e);
|
||||
Popup.show(mainActivity, "Encode video failed");
|
||||
}
|
||||
}
|
||||
|
||||
protected void playVideo() {
|
||||
MediaController mediaController = new MediaController(mainActivity);
|
||||
mediaController.setAnchorView(videoView);
|
||||
videoView.setVideoURI(Uri.parse("file://" + getVideoFile().getAbsolutePath()));
|
||||
videoView.setMediaController(mediaController);
|
||||
videoView.requestFocus();
|
||||
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
|
||||
|
||||
@Override
|
||||
public void onPrepared(MediaPlayer mp) {
|
||||
videoView.setBackgroundColor(0x00000000);
|
||||
}
|
||||
});
|
||||
videoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {
|
||||
|
||||
@Override
|
||||
public boolean onError(MediaPlayer mp, int what, int extra) {
|
||||
videoView.stopPlayback();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
videoView.start();
|
||||
}
|
||||
|
||||
public String getSelectedVideoCodec() {
|
||||
String videoCodec = selectedCodec;
|
||||
|
||||
// VIDEO CODEC SPINNER HAS BASIC NAMES, FFMPEG NEEDS LONGER AND EXACT CODEC NAMES.
|
||||
// APPLYING NECESSARY TRANSFORMATION HERE
|
||||
switch (videoCodec) {
|
||||
case "x264":
|
||||
videoCodec = "libx264";
|
||||
break;
|
||||
case "x265":
|
||||
videoCodec = "libx265";
|
||||
break;
|
||||
case "xvid":
|
||||
videoCodec = "libxvid";
|
||||
break;
|
||||
case "vp8":
|
||||
videoCodec = "libvpx";
|
||||
break;
|
||||
case "vp9":
|
||||
videoCodec = "libvpx-vp9";
|
||||
break;
|
||||
case "aom":
|
||||
videoCodec = "libaom-av1";
|
||||
break;
|
||||
case "kvazaar":
|
||||
videoCodec = "libkvazaar";
|
||||
break;
|
||||
case "theora":
|
||||
videoCodec = "libtheora";
|
||||
break;
|
||||
}
|
||||
|
||||
return videoCodec;
|
||||
}
|
||||
|
||||
public File getVideoFile() {
|
||||
String videoCodec = selectedCodec;
|
||||
|
||||
final String extension;
|
||||
switch (videoCodec) {
|
||||
case "vp8":
|
||||
case "vp9":
|
||||
extension = "webm";
|
||||
break;
|
||||
case "aom":
|
||||
extension = "mkv";
|
||||
break;
|
||||
case "theora":
|
||||
extension = "ogv";
|
||||
break;
|
||||
case "hap":
|
||||
extension = "mov";
|
||||
break;
|
||||
default:
|
||||
|
||||
// mpeg4, x264, x265, xvid, kvazaar
|
||||
extension = "mp4";
|
||||
break;
|
||||
}
|
||||
|
||||
final String video = "video." + extension;
|
||||
return new File(mainActivity.getFilesDir(), video);
|
||||
}
|
||||
|
||||
public String getCustomOptions() {
|
||||
String videoCodec = selectedCodec;
|
||||
|
||||
switch (videoCodec) {
|
||||
case "x265":
|
||||
return "-crf 28 -preset fast ";
|
||||
case "vp8":
|
||||
return "-b:v 1M -crf 10 ";
|
||||
case "vp9":
|
||||
return "-b:v 2M ";
|
||||
case "aom":
|
||||
return "-crf 30 -strict experimental ";
|
||||
case "kvazaar":
|
||||
return "-preset fast ";
|
||||
case "theora":
|
||||
return "-qscale:v 7 ";
|
||||
case "hap":
|
||||
return "-format hap_q ";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public void setActive() {
|
||||
android.util.Log.i(MainActivity.TAG, "Video Tab Activated");
|
||||
enableLogCallback();
|
||||
enableStatisticsCallback();
|
||||
Popup.show(mainActivity, Tooltip.VIDEO_TEST_TOOLTIP_TEXT);
|
||||
}
|
||||
|
||||
protected void showProgressDialog() {
|
||||
|
||||
// CLEAN STATISTICS
|
||||
statistics = null;
|
||||
Config.resetStatistics();
|
||||
|
||||
progressDialog.show();
|
||||
}
|
||||
|
||||
protected void updateProgressDialog() {
|
||||
if (statistics == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int timeInMilliseconds = this.statistics.getTime();
|
||||
if (timeInMilliseconds > 0) {
|
||||
int totalVideoDuration = 9000;
|
||||
|
||||
String completePercentage = new BigDecimal(timeInMilliseconds).multiply(new BigDecimal(100)).divide(new BigDecimal(totalVideoDuration), 0, BigDecimal.ROUND_HALF_UP).toString();
|
||||
|
||||
TextView textView = progressDialog.findViewById(R.id.progressDialogText);
|
||||
if (textView != null) {
|
||||
textView.setText(String.format("Encoding video: %% %s", completePercentage));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void hideProgressDialog() {
|
||||
progressDialog.dismiss();
|
||||
|
||||
MainActivity.addUIAction(new Callable() {
|
||||
|
||||
@Override
|
||||
public Object call() {
|
||||
VideoTabFragment.this.progressDialog = mainActivity.createProgressDialog("Encoding video");
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:aapt="http://schemas.android.com/aapt"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportHeight="108"
|
||||
android:viewportWidth="108">
|
||||
<path
|
||||
android:fillType="evenOdd"
|
||||
android:pathData="M32,64C32,64 38.39,52.99 44.13,50.95C51.37,48.37 70.14,49.57 70.14,49.57L108.26,87.69L108,109.01L75.97,107.97L32,64Z"
|
||||
android:strokeColor="#00000000"
|
||||
android:strokeWidth="1">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient
|
||||
android:endX="78.5885"
|
||||
android:endY="90.9159"
|
||||
android:startX="48.7653"
|
||||
android:startY="61.0927"
|
||||
android:type="linear">
|
||||
<item
|
||||
android:color="#44000000"
|
||||
android:offset="0.0" />
|
||||
<item
|
||||
android:color="#00000000"
|
||||
android:offset="1.0" />
|
||||
</gradient>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:fillType="nonZero"
|
||||
android:pathData="M66.94,46.02L66.94,46.02C72.44,50.07 76,56.61 76,64L32,64C32,56.61 35.56,50.11 40.98,46.06L36.18,41.19C35.45,40.45 35.45,39.3 36.18,38.56C36.91,37.81 38.05,37.81 38.78,38.56L44.25,44.05C47.18,42.57 50.48,41.71 54,41.71C57.48,41.71 60.78,42.57 63.68,44.05L69.11,38.56C69.84,37.81 70.98,37.81 71.71,38.56C72.44,39.3 72.44,40.45 71.71,41.19L66.94,46.02ZM62.94,56.92C64.08,56.92 65,56.01 65,54.88C65,53.76 64.08,52.85 62.94,52.85C61.8,52.85 60.88,53.76 60.88,54.88C60.88,56.01 61.8,56.92 62.94,56.92ZM45.06,56.92C46.2,56.92 47.13,56.01 47.13,54.88C47.13,53.76 46.2,52.85 45.06,52.85C43.92,52.85 43,53.76 43,54.88C43,56.01 43.92,56.92 45.06,56.92Z"
|
||||
android:strokeColor="#00000000"
|
||||
android:strokeWidth="1" />
|
||||
</vector>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
<stroke android:width="1dp" android:color="#7f8c8d"/>
|
||||
<solid android:color="#bdc3c7"/>
|
||||
<corners
|
||||
android:bottomLeftRadius="6dp"
|
||||
android:bottomRightRadius="6dp"
|
||||
android:topLeftRadius="6dp"
|
||||
android:topRightRadius="6dp" />
|
||||
</shape>
|
||||
@@ -1,170 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportHeight="108"
|
||||
android:viewportWidth="108">
|
||||
<path
|
||||
android:fillColor="#26A69A"
|
||||
android:pathData="M0,0h108v108h-108z" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M9,0L9,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,0L19,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M29,0L29,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M39,0L39,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M49,0L49,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M59,0L59,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M69,0L69,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M79,0L79,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M89,0L89,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M99,0L99,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,9L108,9"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,19L108,19"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,29L108,29"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,39L108,39"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,49L108,49"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,59L108,59"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,69L108,69"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,79L108,79"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,89L108,89"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,99L108,99"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,29L89,29"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,39L89,39"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,49L89,49"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,59L89,59"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,69L89,69"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,79L89,79"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M29,19L29,89"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M39,19L39,89"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M49,19L49,89"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M59,19L59,89"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M69,19L69,89"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M79,19L79,89"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
</vector>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
<stroke android:width="1dp" android:color="#27ae60"/>
|
||||
<solid android:color="#2ecc71"/>
|
||||
<corners
|
||||
android:bottomLeftRadius="6dp"
|
||||
android:bottomRightRadius="6dp"
|
||||
android:topLeftRadius="6dp"
|
||||
android:topRightRadius="6dp" />
|
||||
</shape>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
<stroke android:width="1dp" android:color="#f39c12"/>
|
||||
<solid android:color="#f1c40f"/>
|
||||
<corners
|
||||
android:bottomLeftRadius="6dp"
|
||||
android:bottomRightRadius="6dp"
|
||||
android:topLeftRadius="6dp"
|
||||
android:topRightRadius="6dp" />
|
||||
</shape>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
<stroke android:width="1dp" android:color="#8e44ad"/>
|
||||
<solid android:color="#9b59b6"/>
|
||||
<corners
|
||||
android:bottomLeftRadius="6dp"
|
||||
android:bottomRightRadius="6dp"
|
||||
android:topLeftRadius="6dp"
|
||||
android:topRightRadius="6dp" />
|
||||
</shape>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
<stroke android:width="1dp" android:color="#bdc3c7"/>
|
||||
<solid android:color="#ecf0f1"/>
|
||||
<corners
|
||||
android:bottomLeftRadius="2dp"
|
||||
android:bottomRightRadius="2dp"
|
||||
android:topLeftRadius="2dp"
|
||||
android:topRightRadius="2dp" />
|
||||
</shape>
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/headerColor"
|
||||
android:gravity="top"
|
||||
android:orientation="vertical">
|
||||
|
||||
<android.support.v7.widget.AppCompatTextView
|
||||
android:id="@+id/header"
|
||||
style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="40dp"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
android:text="@string/app_name"
|
||||
android:textAlignment="center"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat"
|
||||
android:textColor="@android:color/white"
|
||||
android:textStyle="bold"
|
||||
app:fontFamily="sans-serif" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -0,0 +1,49 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="60dp"
|
||||
android:layout_marginTop="10dp">
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progressBar"
|
||||
style="?android:attr/progressBarStyle"
|
||||
android:layout_width="46dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:layout_marginStart="30dp"
|
||||
android:gravity="center|start" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/progressDialogText"
|
||||
android:layout_width="200dp"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center|start"
|
||||
android:textColor="@android:color/black"
|
||||
android:textSize="18sp" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="60dp"
|
||||
android:gravity="center">
|
||||
|
||||
<Button
|
||||
android:id="@+id/cancelButton"
|
||||
android:layout_width="80dp"
|
||||
android:layout_height="36dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:background="@drawable/dialog_button"
|
||||
android:fontFamily="sans-serif"
|
||||
android:gravity="center"
|
||||
android:text="@string/dialog_cancel_button_text"
|
||||
android:textAlignment="center"
|
||||
android:textColor="@android:color/black"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="normal" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
@@ -0,0 +1,73 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center"
|
||||
tools:context=".AudioTabFragment">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/audioCodecSpinnerLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="20dp"
|
||||
android:layout_marginTop="40dp"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/audioCodecSpinner"
|
||||
android:background="@drawable/rounded_spinner"
|
||||
android:layout_width="180dp"
|
||||
android:layout_height="54dp"
|
||||
android:layout_marginBottom="0dp"
|
||||
android:layout_marginTop="0dp"
|
||||
android:padding="6dp"
|
||||
android:textAlignment="center"
|
||||
android:gravity="center"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/encodeButtonLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center">
|
||||
|
||||
<Button
|
||||
android:id="@+id/encodeButton"
|
||||
android:layout_width="90dp"
|
||||
android:layout_height="36dp"
|
||||
android:layout_marginBottom="20dp"
|
||||
android:layout_marginTop="20dp"
|
||||
android:background="@drawable/rounded_button"
|
||||
android:fontFamily="sans-serif"
|
||||
android:gravity="center"
|
||||
android:text="@string/audio_encode_button_text"
|
||||
android:textAlignment="center"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold" />
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/outputText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="6dp"
|
||||
android:layout_marginBottom="20dp"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginRight="20dp"
|
||||
android:layout_marginTop="20dp"
|
||||
android:background="@drawable/rounded_output_frame"
|
||||
android:fontFamily="sans-serif"
|
||||
android:gravity="bottom"
|
||||
android:overScrollMode="ifContentScrolls"
|
||||
android:scrollbars="vertical"
|
||||
android:textColor="@android:color/black"
|
||||
android:textSize="14sp"
|
||||
android:typeface="sans" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -4,45 +4,66 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center"
|
||||
tools:context=".CommandTabFragment">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/commandText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="40dp"
|
||||
android:layout_marginBottom="30dp"
|
||||
android:layout_marginBottom="20dp"
|
||||
android:layout_marginEnd="20dp"
|
||||
android:layout_marginStart="20dp"
|
||||
android:layout_marginTop="30dp"
|
||||
android:hint="@string/command_text_hint"
|
||||
android:inputType="text" />
|
||||
android:layout_marginTop="20dp"
|
||||
android:hint="@string/command_text_input_placeholder"
|
||||
android:inputType="text"
|
||||
android:singleLine="true" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/runButton"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="30dp"
|
||||
android:layout_marginEnd="130dp"
|
||||
android:layout_marginStart="130dp"
|
||||
android:text="@string/run_button_text" />
|
||||
android:layout_width="80dp"
|
||||
android:layout_height="36dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:background="@drawable/rounded_button"
|
||||
android:fontFamily="sans-serif"
|
||||
android:gravity="center"
|
||||
android:text="@string/command_run_button_text"
|
||||
android:textAlignment="center"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/runAsyncButton"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="100dp"
|
||||
android:layout_marginStart="100dp"
|
||||
android:text="@string/run_async_button_text" />
|
||||
android:layout_width="140dp"
|
||||
android:layout_height="36dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:background="@drawable/rounded_button"
|
||||
android:fontFamily="sans-serif"
|
||||
android:gravity="center"
|
||||
android:text="@string/command_run_async_button_text"
|
||||
android:textAlignment="center"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/logText"
|
||||
android:id="@+id/outputText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginBottom="30dp"
|
||||
android:padding="6dp"
|
||||
android:layout_marginBottom="20dp"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginRight="20dp"
|
||||
android:layout_marginTop="30dp"
|
||||
android:layout_marginTop="20dp"
|
||||
android:background="@drawable/rounded_output_frame"
|
||||
android:fontFamily="sans-serif"
|
||||
android:gravity="bottom"
|
||||
android:overScrollMode="ifContentScrolls"
|
||||
android:scrollbars="vertical"
|
||||
android:gravity="bottom"/>
|
||||
android:textColor="@android:color/black"
|
||||
android:textSize="14sp"
|
||||
android:typeface="sans" />
|
||||
</LinearLayout>
|
||||
@@ -0,0 +1,55 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center"
|
||||
tools:context=".HttpsTabFragment">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/urlText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="40dp"
|
||||
android:layout_marginBottom="20dp"
|
||||
android:layout_marginEnd="20dp"
|
||||
android:layout_marginStart="20dp"
|
||||
android:layout_marginTop="30dp"
|
||||
android:hint="@string/https_text_input_placeholder"
|
||||
android:inputType="textUri"
|
||||
android:singleLine="true" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/getInfoButton"
|
||||
android:layout_width="120dp"
|
||||
android:layout_height="36dp"
|
||||
android:layout_marginBottom="20dp"
|
||||
android:layout_marginTop="20dp"
|
||||
android:background="@drawable/rounded_button"
|
||||
android:fontFamily="sans-serif"
|
||||
android:gravity="center"
|
||||
android:text="@string/https_get_info_button_text"
|
||||
android:textAlignment="center"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/outputText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="6dp"
|
||||
android:layout_marginBottom="20dp"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginRight="20dp"
|
||||
android:layout_marginTop="40dp"
|
||||
android:background="@drawable/rounded_output_frame"
|
||||
android:fontFamily="sans-serif"
|
||||
android:gravity="bottom"
|
||||
android:overScrollMode="ifContentScrolls"
|
||||
android:scrollbars="vertical"
|
||||
android:textColor="@android:color/black"
|
||||
android:textSize="14sp"
|
||||
android:typeface="sans" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -1,32 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
tools:context=".SlideshowTabFragment">
|
||||
|
||||
<Button
|
||||
android:id="@+id/slideshowCreateButton"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:layout_marginStart="30dp"
|
||||
android:layout_marginTop="30dp"
|
||||
android:text="@string/button_create_slideshow_text" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/slideshowPlayButton"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:layout_marginStart="30dp"
|
||||
android:layout_marginTop="30dp"
|
||||
android:text="@string/button_play_slideshow_text" />
|
||||
|
||||
<VideoView
|
||||
android:id="@+id/videoView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="30dp" />
|
||||
</LinearLayout>
|
||||
@@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center"
|
||||
tools:context=".SubtitleTabFragment">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/burnSubtitlesButtonLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center">
|
||||
|
||||
<Button
|
||||
android:id="@+id/burnSubtitlesButton"
|
||||
android:layout_width="200dp"
|
||||
android:layout_height="36dp"
|
||||
android:layout_marginBottom="40dp"
|
||||
android:layout_marginTop="60dp"
|
||||
android:background="@drawable/rounded_button"
|
||||
android:fontFamily="sans-serif"
|
||||
android:gravity="center"
|
||||
android:text="@string/subtitle_burn_subtitles_button_text"
|
||||
android:textAlignment="center"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold" />
|
||||
</LinearLayout>
|
||||
|
||||
<VideoView
|
||||
android:id="@+id/videoPlayerFrame"
|
||||
android:layout_width="wrap_content"
|
||||
android:background="@drawable/rounded_video_frame"
|
||||
android:layout_height="0dp"
|
||||
android:layout_gravity="bottom"
|
||||
android:layout_marginStart="20dp"
|
||||
android:layout_marginEnd="20dp"
|
||||
android:layout_marginTop="40dp"
|
||||
android:layout_marginBottom="60dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -0,0 +1,63 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
tools:context=".VideoTabFragment">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/videoCodecSpinnerLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="20dp"
|
||||
android:layout_marginTop="40dp"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/videoCodecSpinner"
|
||||
android:background="@drawable/rounded_spinner"
|
||||
android:layout_width="180dp"
|
||||
android:layout_height="54dp"
|
||||
android:layout_marginBottom="0dp"
|
||||
android:layout_marginTop="0dp"
|
||||
android:padding="6dp"
|
||||
android:textAlignment="center"
|
||||
android:gravity="center"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/encodeButtonLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center">
|
||||
|
||||
<Button
|
||||
android:id="@+id/encodeButton"
|
||||
android:layout_width="90dp"
|
||||
android:layout_height="36dp"
|
||||
android:layout_marginBottom="20dp"
|
||||
android:layout_marginTop="20dp"
|
||||
android:background="@drawable/rounded_button"
|
||||
android:fontFamily="sans-serif"
|
||||
android:gravity="center"
|
||||
android:text="@string/video_encode_button_text"
|
||||
android:textAlignment="center"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold" />
|
||||
</LinearLayout>
|
||||
|
||||
<VideoView
|
||||
android:id="@+id/videoPlayerFrame"
|
||||
android:layout_width="wrap_content"
|
||||
android:background="@drawable/rounded_video_frame"
|
||||
android:layout_height="0dp"
|
||||
android:layout_gravity="bottom"
|
||||
android:layout_margin="20dp"
|
||||
android:layout_weight="1" />
|
||||
</LinearLayout>
|
||||
@@ -0,0 +1,51 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center"
|
||||
tools:context=".VidStabTabFragment">
|
||||
|
||||
<VideoView
|
||||
android:id="@+id/videoPlayerFrame"
|
||||
android:layout_width="wrap_content"
|
||||
android:background="@drawable/rounded_video_frame"
|
||||
android:layout_height="0dp"
|
||||
android:layout_gravity="bottom"
|
||||
android:layout_margin="10dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/stabilizeVideoButtonLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center">
|
||||
|
||||
<Button
|
||||
android:id="@+id/stabilizeVideoButton"
|
||||
android:layout_width="160dp"
|
||||
android:layout_height="36dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:background="@drawable/rounded_button"
|
||||
android:fontFamily="sans-serif"
|
||||
android:gravity="center"
|
||||
android:text="@string/vidstab_stabilize_video_button_text"
|
||||
android:textAlignment="center"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold" />
|
||||
</LinearLayout>
|
||||
|
||||
<VideoView
|
||||
android:id="@+id/stabilizedVideoPlayerFrame"
|
||||
android:layout_width="wrap_content"
|
||||
android:background="@drawable/rounded_video_frame"
|
||||
android:layout_height="0dp"
|
||||
android:layout_gravity="bottom"
|
||||
android:layout_margin="10dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="80dp"
|
||||
android:layout_centerInParent="true">
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progressBar"
|
||||
style="?android:attr/progressBarStyle"
|
||||
android:layout_width="46dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:layout_marginStart="30dp"
|
||||
android:gravity="center|start" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/progressDialogText"
|
||||
android:layout_width="200dp"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center|start"
|
||||
android:textColor="@android:color/black"
|
||||
android:textSize="18sp" />
|
||||
</TableRow>
|
||||
</RelativeLayout>
|
||||
@@ -0,0 +1,11 @@
|
||||
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@android:id/text1"
|
||||
android:layout_width="168dp"
|
||||
android:layout_height="40dp"
|
||||
android:gravity="center"
|
||||
android:ellipsize="marquee"
|
||||
android:singleLine="true"
|
||||
android:textAlignment="center"
|
||||
android:textColor="@android:color/black"
|
||||
android:textSize="16sp" />
|
||||
@@ -0,0 +1,13 @@
|
||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@android:id/text1"
|
||||
android:layout_width="180dp"
|
||||
android:layout_height="50dp"
|
||||
android:gravity="center"
|
||||
android:background="@drawable/rounded_spinner"
|
||||
android:ellipsize="marquee"
|
||||
android:singleLine="true"
|
||||
android:fontFamily="sans-serif"
|
||||
android:textColor="@android:color/black"
|
||||
android:textAlignment="center"
|
||||
android:textSize="20sp"/>
|
||||
@@ -1,5 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@drawable/ic_launcher_background" />
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||
</adaptive-icon>
|
||||
@@ -1,5 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@drawable/ic_launcher_background" />
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||
</adaptive-icon>
|
||||
|
Before Width: | Height: | Size: 3.0 KiB After Width: | Height: | Size: 5.9 KiB |
|
Before Width: | Height: | Size: 4.9 KiB After Width: | Height: | Size: 7.4 KiB |
|
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 3.0 KiB |