{"id":13400143,"url":"https://github.com/sannies/mp4parser","last_synced_at":"2025-05-13T18:08:50.394Z","repository":{"id":37414473,"uuid":"12853082","full_name":"sannies/mp4parser","owner":"sannies","description":"A Java API to read, write and create MP4 files","archived":false,"fork":false,"pushed_at":"2024-08-15T22:50:11.000Z","size":53567,"stargazers_count":2784,"open_issues_count":272,"forks_count":574,"subscribers_count":109,"default_branch":"master","last_synced_at":"2025-05-13T18:08:42.720Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sannies.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-09-15T21:37:40.000Z","updated_at":"2025-05-13T04:29:16.000Z","dependencies_parsed_at":"2022-07-12T13:00:47.037Z","dependency_job_id":"8db096f8-2d86-4b8b-8c85-45e003daee7d","html_url":"https://github.com/sannies/mp4parser","commit_stats":null,"previous_names":[],"tags_count":143,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sannies%2Fmp4parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sannies%2Fmp4parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sannies%2Fmp4parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sannies%2Fmp4parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sannies","download_url":"https://codeload.github.com/sannies/mp4parser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254000850,"owners_count":21997441,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T19:00:48.937Z","updated_at":"2025-05-13T18:08:45.371Z","avatar_url":"https://github.com/sannies.png","language":"Java","readme":"\n * Build status: [![Build Status](https://travis-ci.org/sannies/mp4parser.svg?branch=master)](https://travis-ci.org/sannies/mp4parser)\n * Current central released version 1.x branch: [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.googlecode.mp4parser/isoparser/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.googlecode.mp4parser/isoparser)\n * Current central released version 2.x branch: [![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.mp4parser/isoparser/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.googlecode.mp4parser/isoparser)\n\n\nJava MP4 Parser\n====================\n\nA Java API to read, write and create MP4 container. Manipulating containers is different from encoding and decoding videos and audio. \n\nUsing the library\n------------------\n\nThe 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. \n\nGradle:\n```gradle\n  compile 'org.mp4parser:isoparser:1.9.27'\n```\nMaven:\n```xml\n  \u003cdependency\u003e\n    \u003cgroupId\u003eorg.mp4parser\u003c/groupId\u003e\n    \u003cartifactId\u003eisoparser\u003c/artifactId\u003e\n    \u003cversion\u003e1.9.27\u003c/version\u003e\n  \u003c/dependency\u003e\n```\n\nFor 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. \n\n\nWhat can you do?\n--------------------\n\nTypical tasks for the MP4 Parser are: \n\n- Muxing audio/video into an MP4 file\n- Append recordings that use same encode settings\n- Adding/Changing metadata\n- Shorten recordings by omitting frames\n\nMy 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. \nThere are also MP4 files with H263/MPEG-2 video tracks but they are no longer used widespread as most android phones. You can also\n\nMuxing Audio/Video\n--------------------\n\nThe API and the process is straight-forward:\n\n1. You wrap each raw format file into an appropriate Track object. \n  ```java\nH264TrackImpl h264Track = new H264TrackImpl(new FileDataSourceImpl(\"video.h264\"));\nAACTrackImpl aacTrack = new AACTrackImpl(new FileDataSourceImpl(\"audio.aac\"));\n  ```\n\n2. These Track object are then added to a Movie object\n  ```java\nMovie movie = new Movie();\nmovie.addTrack(h264Track);\nmovie.addTrack(aacTrack);\n  ```\n\n3. The Movie object is fed into an MP4Builder to create the container. \n  ```java\nContainer mp4file = new DefaultMp4Builder().build(movie);\n  ```\n\n4. Write the container to an appropriate sink.\n  ```java\nFileChannel fc = new FileOutputStream(new File(\"output.mp4\")).getChannel();\nmp4file.writeContainer(fc);\nfc.close();\n  ```\n\nThere 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. \nIn this case you will have to supply it to the constructor. \n\nThere are Track implementations for the following formats: \n\n * H264\n * AAC\n * AC3\n * EC3 \n\nand additionally two subtitle tracks that do not directly wrap a raw format but they are conceptually similar.\n\nTypical Issues\n--------------------\n\nAudio and video are not in sync. Whenever there are problems with timing possible make sure to start \n\nAudio starts before video\n--------------------\n\nIn AAC there are always samplerate/1024 sample/s so each sample's duration is 1000 * 1024 / samplerate milliseconds. \n\n * 48KHz =\u003e ~21.3ms\n * 44.1KHz =\u003e ~23.2ms\n\nBy omitting samples from the start you can easily shorten the audio track. Remove as many as you need. You will not be able \nto match audio and video exactly with that but the human perception is more sensible to early audio than to late audio. \n\nRemember: If someone is only 10 meters away the delay between audio and video is \u003e30ms. The brain is used to that!\n\n```java\nAACTrackImpl aacTrackOriginal = new AACTrackImpl(new FileDataSourceImpl(\"audio.aac\"));\n// removes the first sample and shortens the AAC track by ~22ms\nCroppedTrack aacTrackShort = new CroppedTrack(aacTrackOriginal, 1, aacTrack.getSamples().size());\n```\n\n\n\n\nAppend Recordings with Same Encode Settings \n-------------------------------------------\n\nIt is important to emphasize that you cannot append any two tracks with: \n \n * Different resolutions \n * Different frame-rates\n\nWhat can't you do?\n--------------------\n\nCreate JPEGs from a movie. No - this is no decoder. The MP4 Parser doesn't know how to do that. \nCreate a movie from JPEGs\n","funding_links":[],"categories":["GPU computing","Java","HarmonyOS","Libs","Video Encoding, Transcoding \u0026 Packaging Tools"],"sub_categories":["Windows Manager","\u003cA NAME=\"Media\"\u003e\u003c/A\u003eMedia","Containerization \u0026 Packaging Tools"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsannies%2Fmp4parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsannies%2Fmp4parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsannies%2Fmp4parser/lists"}