RxMp4Parser for Android App Developers

More and more Android apps provide video editing based features. This library is not a complete wrapper for the most recent Mp4Parser library. However, it provides a few useful features that are usually used by these apps. If it does fit your application’s needs, feel free to implement those features based on the current implementation. The implemented features’ restrictions are the same as the base library’s restrictions. See: https://github.com/sannies/mp4parser

Android RxMp4Parser from Wanari


The base class of the library is RxMp4Parser. This provides the basic functionality for:

  • Loading files into Movie objects
  • Concatenation
  • Crop
  • Extract track specified by their handlers (Audio/Video/etc.)
  • Muxing tracks into Movie
  • Save Movie to output file

Static Functions of RxMp4Parser

Functions Return Type  Description
from(File input)
from(String inputFilePath)
Observable<Movie> Reads the specified file and creates a Movie instance from it. The result types are Observable<Movie> for both functions.
extractVideoTrack(Movie movie)
extractAudioTrack(Movie movie)
extractTrackWithHandler(Movie movie, String handler)
Observable<Track> As the method names show, these methods extract a specific Track from the input Movie object, if it has one. If it has more than one, the first occurrence will be returned. If the passed Movie doesn’t contain a Track matching the given handler type, the Observable will return null.
concatenate(Observable<Movie>… input)
concatenate(Iterable<? extends Observable<Movie>> input)
 Observable<Movie> Concatenates the given Observable<Movie> instances according to the parameter order. The returned Movie instance contains the concatenated output.
concatenateInto(File outputFile, Observable<Movie>… input)
concatenateInto(File outputFile, Iterable<? extends Observable<Movie>> input)
Observable<File> Does the same as the previous methods, but you can specify the output file for the result. After the concatenation it will write out the Movie object and return the File reference pointing on it. (Which you specified in the parameters.)
crop(String filePath, double fromTime, double toTime)
crop(File inputFile, double fromTime, double toTime)
 Observable<Movie> This method returns a Movie instance which contains a cropped part of the original Movie. The cropped part is specified by the fromTime and toTime parameters in seconds! The accuracy of the cropping points is determined by the number and distribution of sync samples.
output(Movie movie, File outputFile)
output(Movie movie, String outputPath)
Observable<File> The given Movie object will be written out to the specified output file. The returned File reference points to the resulting file.


These classes can be used with the Observable.lift() function on the specified Observable<T> types. Most of the built in functions in the RxMp4Parser class also uses these operators.

  • AppendTracks:
    This can be used on an Observable which wraps an Iterable<Track> instance. It produces an Observable which wraps a Track implementation (AppendTrack) which contains the received Tracks appended according to their original order.
  • CropMovie:
    Calling this on an Observable<Movie> instance will produce a new Observable<Movie> object which contains only part of the original Movie specified by the Operators constructor:

    The first parameter is the start time and the second one is the end time in seconds. The output will contain the Movie part between the two time marker.
  • MuxTracks:
    This operator is used to mix the supplied Tracks into a Movie instance. It can be used on an Observable<Iterable<Track>> instance and will return an Observable<Movie> object.


Final thoughts

This is not a final, nor a complete implementation of a wrapper, but it is useful for video editing basics. Also, it helps to implement a project specific version when other features are needed. The base library mainly uses synchronous calls for its tasks. In my opinion, the wrapper helps a lot to eliminate the thread handling overhead from an Android App’s base code.


The code used in this post is provided as is. If I’ll have time and need other use-cases from the base library, I’ll extend the functionality. Feel free to contribute to it…



URL: https://github.com/TeamWanari/RxMp4Parser