mp4parser


Source link: https://github.com/sannies/mp4parser

  • Build status:
  • Current central released version 1.x branch:
  • Current central released version 2.x branch:

Java MP4 Parser

A Java API to read, write and create MP4 container. Manipulating containers is different from encoding and decoding videos and audio.

Using the library

The library is published to Maven repositories. Each release is pushed to a staging repository which is published on the release page. On request specific releases can be pushed to maven central.

Gradle:

  compile 'com.googlecode.mp4parser:isoparser:1.1.21'

Maven:

  <dependency>
  <groupId>org.mp4parser</groupId>
  <artifactId>isoparser</artifactId>
  <version>1.9.27</version>
</dependency>

For projects that do not use a dependency management tool each release's artifacts (jar, javadoc-jar, source-jar) are attached to the release page. Please be aware that the project requires the aspectj-rt.jar library.

What can you do?

Typical tasks for the MP4 Parser are:

  • Muxing audio/video into an MP4 file
  • Append recordings that use same encode settings
  • Adding/Changing metadata
  • Shorten recordings by omitting frames

My examples will all use H264 and AAC as these two codecs are most typical for MP4 files. AC-3 is also not uncommon as the codec is well known from DVD. There are also MP4 files with H263/MPEG-2 video tracks but they are no longer used widespread as most android phones. You can also

Muxing Audio/Video

The API and the process is straight-forward:

  1. You wrap each raw format file into an appropriate Track object.
H264TrackImpl h264Track = new H264TrackImpl(new FileDataSourceImpl("video.h264"));
 AACTrackImpl aacTrack = new AACTrackImpl(new FileDataSourceImpl("audio.aac"));
  1. These Track object are then added to a Movie object
Movie movie = new Movie();
 movie.addTrack(h264Track);
 movie.addTrack(aacTrack);
  1. The Movie object is fed into an MP4Builder to create the container.
Container mp4file = new DefaultMp4Builder().build(movie);
  1. Write the container to an appropriate sink.
FileChannel fc = new FileOutputStream(new File("output.mp4")).getChannel();
 mp4file.writeContainer(fc);
 fc.close();

There are cases where the frame rate is signalled out of band or is known in advance so that the H264 doesn't contain it literally. In this case you will have to supply it to the constructor.

There are Track implementations for the following formats:

  • H264
  • AAC
  • AC3
  • EC3

and additionally two subtitle tracks that do not directly wrap a raw format but they are conceptually similar.

Typical Issues

Audio and video are not in sync. Whenever there are problems with timing possible make sure to start

Audio starts before video

In AAC there are always samplerate/1024 sample/s so each sample's duration is 1000 * 1024 / samplerate milliseconds.

  • 48KHz => ~21.3ms
  • 44.1KHz => ~23.2ms

By omitting samples from the start you can easily shorten the audio track. Remove as many as you need. You will not be able to match audio and video exactly with that but the human perception is more sensible to early audio than to late audio.

Remember: If someone is only 10 meters away the delay between audio and video is >30ms. The brain is used to that!

AACTrackImpl aacTrackOriginal = new AACTrackImpl(new FileDataSourceImpl("audio.aac"));
 // removes the first sample and shortens the AAC track by ~22ms CroppedTrack aacTrackShort = new CroppedTrack(aacTrackOriginal, 1, aacTrack.getSamples().size());

Append Recordings with Same Encode Settings

It is important to emphasize that you cannot append any two tracks with:

  • Different resolutions
  • Different frame-rates

What can't you do?

Create JPEGs from a movie. No - this is no decoder. The MP4 Parser doesn't know how to do that. Create a movie from JPEGs

Resources

ASNE library allows you to make simple integration with different social networks:

  • Twitter
  • LinkedIn
  • Facebook
  • Google Plus
  • Vkontakte
  • Odnoklassniki

LoadingEverywhere is an Android library that makes it easy to create and manage a loading mask over any view.

It supports android versions 2.3 (gingerbread) and above.

Sample code that shows how to make ListView or other views support the swipe-to-dismiss Android UI pattern.

A native Java class library, which provides your Android application with rich capabilities for creating, editing and visualizing graphs, networks, flowcharts, algorithms, genealogy trees and much more.

'Path' has a very attractive menu sitting on the left bottom corner of the screen. Satellite Menu is the open version of this menu.

Python script to highlight adb logcat output in console.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes