-
Notifications
You must be signed in to change notification settings - Fork 0
Home
CodecMedia Java is a Java 17 library for inspecting and handling media files.
The project focuses on practical media workflows that are implemented in Java or through JDK APIs:
- Media probing
- File validation
- Basic metadata read/write
- Limited conversion routes
- Playback workflow routing
CodecMedia is not a complete transcoding framework. Unsupported routes fail explicitly instead of invoking external tools.
Current version: 1.2.1
Minimum Java version: 17
Build tool: Maven
Runtime dependencies: none declared in pom.xml
Important notes:
- The default implementation class is currently named
StubCodecMediaEngine. - The implementation contains real parser, metadata, playback, and conversion behavior, but the engine is still being consolidated.
- MP3 decoding through
decoder=pure-javaordecoder=layer3is experimental. - General-purpose transcoding is not implemented.
- Some image conversion routes depend on ImageIO reader/writer support available in the runtime.
<dependency>
<groupId>me.tamkungz.codecmedia</groupId>
<artifactId>codecmedia</artifactId>
<version>1.2.1</version>
</dependency>dependencies {
implementation("me.tamkungz.codecmedia:codecmedia:1.2.1")
}import java.nio.file.Path;
import me.tamkungz.codecmedia.CodecMedia;
import me.tamkungz.codecmedia.CodecMediaEngine;
import me.tamkungz.codecmedia.options.ValidationOptions;
public class Example {
public static void main(String[] args) throws Exception {
CodecMediaEngine media = CodecMedia.createDefault();
Path input = Path.of("src/test/resources/png_test.png");
var probe = media.probe(input);
System.out.println(probe.mimeType());
System.out.println(probe.mediaType());
System.out.println(probe.primaryCodec().orElse("unknown"));
var validation = media.validate(input, ValidationOptions.defaults());
System.out.println("valid=" + validation.valid());
}
}The public entry point is:
CodecMediaEngine media = CodecMedia.createDefault();Main methods:
-
get(Path)- alias forprobe(Path) -
probe(Path)- detects media type, MIME type, extension, duration, streams, and tags -
validate(Path, ValidationOptions)- validates file existence, size limits, and optional strict parser checks -
readMetadata(Path)- reads base probe metadata plus supported embedded or sidecar metadata -
writeMetadata(Path, Metadata)- writes supported embedded metadata or sidecar metadata -
extractAudio(Path, Path, AudioExtractOptions)- copies supported audio input into an output directory -
convert(Path, Path, ConversionOptions)- runs an implemented conversion route -
play(Path, PlaybackOptions)- runs dry-run, Java sampled playback, or desktop-open playback
Audio:
mp3oggwavaifaiffaifcflacm4a
Images:
pngjpgjpegwebpbmptiftiffheicheifavif
Video and containers:
movmp4webm
Validation supports:
- File existence checks
- Maximum file size checks
- Optional strict parser checks
Strict validation is available for:
mp3oggwavaifaiffaifcflacpngjpgjpegmovmp4m4awebmwebpbmptiftiffheicheifavif
Strict validation currently reads the full file and is limited to files up to 32 MiB.
readMetadata always includes base probe fields:
mimeTypeextensionmediaType
Embedded metadata support:
- WAV: read/write RIFF
LIST/INFO - AIFF/AIF/AIFC: read/write
NAME,AUTH,(c), andANNOtext chunks - MP3: read/write ID3v1
- OGG: read Vorbis/Opus comments
- FLAC: read Vorbis comments
Sidecar metadata support:
- Formats without embedded write support use
<file>.codecmedia.properties. - Embedded metadata is treated as canonical where supported.
- Sidecar values are merged as fallback values for non-core keys.
Implemented conversion routes:
- Same-format copy when source and target extensions match
- Image-to-image conversion for
png,jpg,jpeg,webp,bmp,tif,tiff,heic,heif, andavif wav -> pcmpcm -> wavmp3 -> pcmmp3 -> wav- Java Sound audio output to
wav,aif,aiff,aifc, orauwhen supported by the runtime -
mp4 -> m4aandmov -> m4aremux when an M4A-compatible audio track is present
Runtime-dependent behavior:
- WebP image decode/encode requires ImageIO WebP support.
- TIFF image decode/encode may require ImageIO TIFF support.
- HEIF, HEIC, and AVIF image decode/encode require compatible ImageIO support.
- Java Sound audio conversion depends on audio service providers available in the runtime.
Playback supports:
- Dry-run mode for known media types
- Java sampled playback for WAV/AIFF-family audio when Java Sound can open the file
- Desktop-open fallback through
java.awt.Desktopwhen enabled and supported by the platform
- Probe output is technical media information, not a complete metadata catalog.
- ID3v2, album art/APIC extraction, and advanced tag families are not fully supported.
- General compressed audio transcoding, such as
mp3 -> ogg, is not implemented. - Generic video-to-audio conversion is not implemented, except MP4/MOV to M4A remux.
- Video-to-video conversion is not implemented.
- Audio-to-image album-art extraction is not implemented.
-
extractAudiodoes not transcode and does not select arbitrary streams. - TIFF probing reads the first IFD/image only.
- WebP probing reports an assumed bit depth for VP8, VP8L, and VP8X when deeper profile metadata is not parsed.
- Strict validation is limited to files up to 32 MiB.
git clone https://github.com/CodecMediaLib/codecmedia-java.git
cd codecmedia-java
mvn -Dgpg.skip=true clean verify-Dgpg.skip=true is recommended for local development because the project signs release artifacts during verify.
Run the full test suite:
mvn -Dgpg.skip=true testRun the same verify phase used by CI:
mvn -Dgpg.skip=true clean verifyRun focused tests:
mvn -Dgpg.skip=true -Dtest=CodecMediaFacadeTest test
mvn -Dgpg.skip=true -Dtest=CodecMediaPlayTest test
mvn -Dgpg.skip=true -Dtest=Mp3PcmWavConverterTest testCI currently verifies Java 17 and Java 21.
Implemented:
- Media probing for supported formats
- Strict parser validation for supported formats
- Embedded metadata read/write for WAV, AIFF-family files, and MP3 ID3v1
- Embedded metadata read for OGG and FLAC comments
- Sidecar metadata fallback
- Limited conversion routes
- Dry-run, Java sampled, and desktop-open playback workflows
Planned:
- Generic video-to-audio conversion route
- Audio-to-image album-art extraction route
- Video-to-video conversion route
- Broader audio transcoding support beyond Java Sound, WAV/PCM, and MP3 decode routes
TODO:
- Document exact metadata key mapping for each embedded metadata format.
- Document supported ImageIO plugin combinations for WebP, TIFF, HEIF, HEIC, and AVIF conversion.
- Document release and publishing steps for maintainers.
- Decide whether
StubCodecMediaEngineshould be renamed.
- Repository: https://github.com/CodecMediaLib/codecmedia-java
- Maven Central: https://central.sonatype.com/artifact/me.tamkungz.codecmedia/codecmedia
- MvnRepository: https://mvnrepository.com/artifact/me.tamkungz.codecmedia/codecmedia
- Issues: https://github.com/CodecMediaLib/codecmedia-java/issues
- Changelog: https://github.com/CodecMediaLib/codecmedia-java/blob/main/CHANGELOG.md
CodecMedia Java is licensed under the Apache License 2.0.