Here are the steps I went through in getting ffmpeg to work on Android:
- Build static libraries of ffmpeg for Android. This was achieved by building olvaffe's ffmpeg android port (libffmpeg) using the Android Build System. Simply place the sources under /external and
make
away. You'll need to extract bionic(libc) and zlib(libz) from the Android build as well, as ffmpeg libraries depend on them.
Create a dynamic library wrapping ffmpeg functionality using the Android NDK. There's a lot of documentation out there on how to work with the NDK. Basically you'll need to write some C/C++ code to export the functionality you need out of ffmpeg into a library java can interact with through JNI. The NDK allows you to easily link against the static libraries you've generated in step 1, just add a line similar to this to Android.mk: LOCAL_STATIC_LIBRARIES := libavcodec libavformat libavutil libc libz
Use the ffmpeg-wrapping dynamic library from your java sources. There's enough documentation on JNI out there, you should be fine.
Regarding using ffmpeg for playback, there are many examples (the ffmpeg binary itself is a good example), here's a basic tutorial. The best documentation can be found in the headers.
Good luck :)
FFmpeg has three concatenation methods:
Use this method if your inputs do not have the same parameters (width, height, etc), or are not the same formats/codecs, or if you want to perform any filtering.
Note that this method performs a re-encode of all inputs. If you want to avoid the re-encode, you could re-encode just the inputs that don't match so they share the same codec and other parameters, then use the concat demuxer to avoid re-encoding everything.
ffmpeg -i opening.mkv -i episode.mkv -i ending.mkv \
-filter_complex "[0:v] [0:a] [1:v] [1:a] [2:v] [2:a] \
concat=n=3:v=1:a=1 [v] [a]" \
-map "[v]" -map "[a]" output.mkv
Use this method when you want to avoid a re-encode and your format does not support file-level concatenation (most files used by general users do not support file-level concatenation).
$ cat mylist.txt
file '/path/to/file1'
file '/path/to/file2'
file '/path/to/file3'
$ ffmpeg -f concat -safe 0 -i mylist.txt -c copy output.mp4
For Windows:
(echo file 'first file.mp4' & echo file 'second file.mp4' )>list.txt
ffmpeg -safe 0 -f concat -i list.txt -c copy output.mp4
Use this method with formats that support file-level concatenation
(MPEG-1, MPEG-2 PS, DV). Do not use with MP4.
ffmpeg -i "concat:input1|input2" -codec copy output.mkv
This method does not work for many formats, including MP4, due to the nature of these formats and the simplistic concatenation performed by this method.
If in doubt about which method to use, try the concat demuxer.
Also see
Best Answer
Use the drawtext filter for simple text on video. If you need more complex timing, formatting, or dynamic text see the subtitles filter. This answer focuses on the drawtext filter.
Example
Print
Stack Overflow
in white text onto center of video, with black background box of 50% opacity:@0.5
controls background box opacity. 0.5 is 50%. Remove@0.5
if you do not want any transparency.Preview
You can use
ffplay
to preview your text without having to wait for a file to encode:Alternatively you can use
mpv
but the syntax is slightly different:Multiple texts
You can chain multiple drawtext filters:
Position
x
andy
determine text position:x
:y
x=0:y=0
x=10:y=10
x=(w-text_w)/2:y=0
x=(w-text_w)/2:y=10
x=w-tw:y=0
x=w-tw-10:y=10
x=(w-text_w)/2:y=(h-text_h)/2
x=0:y=h-th
x=10:y=h-th-10
x=(w-text_w)/2:y=h-th
x=(w-text_w)/2:y=h-th-10
x=w-tw:y=h-th
x=w-tw-10:y=h-th-10
Repositioning text on demand
You can reposition the text with the sendcmd and zmq filters:
Moving / animated / looping / scrolling text
See:
Timing
Use the
enable
option to control when the text appears.Show text between 5-10 seconds:
Show text after 3 seconds:
Blinking text. For every 10 seconds show text for 5 seconds:
Random position every 30 seconds:
See ffmpeg - Dynamic letters and random position watermark to video?
Changing / updating text
Add the
textfile
andreload
options for drawtext:text.txt
every time you want the text to change.mv
command on Linux or macOS..ass
file via Aegisub) and using the subtitles filter.Font family instead of font file
You can declare the font family, such as Times New Roman, instead of having to point to a font file. See How to include font in FFMPEG command without using the fontfile option?
Requirements
The drawtext filter requires
ffmpeg
to be compiled with--enable-libfreetype
. If you getNo such filter: 'drawtext'
it is missing--enable-libfreetype
. Most of theffmpeg
static builds available support this: see the FFmpeg Download page for links.