Android: Remove all metadata from video - java

Is there any native/existing/manual way to remove all the metadata of a video file in Android/Java/Kotlin from a (content) URI?
For photos, we can still use ExifInterface and remove the metadata we want by using setAttribute and passing null to delete the given/desired values, however this doesn't work for videos because an mp4 video has it's own metadata format. If there is no native Android class that can do this, is there any algorithm or reference that can be referred in order to implement this?

You can use mp4parser library. Typical tasks for the MP4 Parser are:
Muxing audio/video into an MP4 file
Append recordings that use the same encode settings
Adding/Changing metadata
Shorten recordings by omitting frames
The MetaDataInsert example shows how to write metadata.

Related

Detect video or audio track in a raw MP4 data

is there a way to detect either a Video or Audio track present in a raw MP4 data?
I have downloaded a raw MP4 data (with some size) from a URL with a range request. It is not a full MP4 data.
I am using MP4Parser to do this job.
What I have tried is I am trying to build a Movie object from the above MP4 data. But it throws exception saying that there are no tracks in it.
Any idea would be much appreciated how to construct Movie object from a raw MP4 data.
Thanks
without the original moov box, the file is pretty much worthless. It is possible to locate the frames in the mdat and reconstruct a new moov with some forensic analysis, but its almost certainly not work the effort or cost dot so.

attach timestamp to jpg bytearray

I use sockets to send jpg images from server (android) to client. I want to attach timestamps to these images which are of type long. Since these images are already processed by image filters I don't want to save them before transmission, so using ExifInterface seems impossible. I therefore tried to use IIOMetadata but never got it to work. I dont want to use external libs like senselan.
What is the easiest way to do it? If using IIOMetadata is the best way to do it, could you please provide me with a working example on how to attach this to my byte[] and extract it later?
You can send a jpg file and then add 8 bytes to encode the long timestamp, then
another jpg and 8 bytes of timestam, and so on.
You can detect the end of the jpeg, using what it is commented here
Detect Eof for JPG images
Okay, I did what Pablo suggested, but attached the timestamp to the front of the image.

Jave Reading Video/Audio Codecs From File

I have a folder of mixed video files (multiple formats for web display mp4, ogv, webm). When retrieving those files in Java I can verify the format by pulling the extension from the filename. Is there a way to retrieve other information such as video and audio codec data from the file?
To create the files I am using ffmpeg from within Java to transcode video files to the formats and sizes I need, so when the file is being created I do know the codec information. If its not automatically stored somewhere in the file, is there a way to set metadata or something and store the info manually so I can retrieve it later? I am not using a database to store file locations or other data, just simply scanning and retrieving from the file system.
I think ffmpeg can automatically obtain video and audio formats from the files you specify as a source for ffmpeg utility.
If you need the metadata for other purposes then you can try Red5 server sources (java). There are a lot of readers (including MP4Reader) that can be used to obtain metadata.
For example for mp4 files MP4Reader scans the entire file in class constructor and then you can obtain metadata from the first tag:
reader = new org.red5.io.mp4.impl.MP4Reader(myFile)
String v = reader.getVideoCodecId(); // e.g. "avc1" (for h.254), "VP6F"
String a = reader.getAudioCodecId(); // e.g. "mp4a" (for aac), ".mp3" (for mp3)
...
To the best of my knowledge there is no easy way to determine file type by content. You have to make assumptions and then test those assumptions with code (e.g. I think it's type X so I'll inspect the first Y bytes for the pattern that always is present in files of type X.)
Video and audio data streams (e.g. H.264/AVC video, AAC, Dolby Digital audio, etc.) are multiplexed (or 'muxed') together inside file formats that are known as a container formats. MP4 is one such container format and is designed to be able to hold many different types of video and audio stream (see http://www.mp4ra.org/codecs.html for some of the officially registered types).
The different container formats have metadata that identifies the different media streams that are contained so as to help determine what type of decoder should be used to decode a particular media stream.
If you can (you said you're using Java), try using ffprobe to determine the container, video and audio formats used in a media file (plus other metadata). It may not be 100% reliable for all media types (as it may not recognise some) but given that you are encoding with ffmpeg (ffprobe is an ffmpeg-derived tool) it should do the job.

How to programmatically change filenames on S3 to remove filename extensions?

Lets say you have a bunch of images which you want to host on S3 and they are available in various formats: png, jpg, jpeg, gif ... etc.
Writing or using an image-processing service to normalize all image formats, down to a single one, is one approach ... but I'm wondering if its possible to use a shortcut where you can remove the extension name from a filename (after upload) because the file properties now hold the appropriate mime-type anyway?
So after I upload 1.png, 2.jpg, 3.jpeg and 4.gif ... why not programmatically change all filenames to remove the extensions and access the images as:
/my-bucket/1
/my-bucket/2
/my-bucket/3
/my-bucket/4
So, how can someone programmatically change filenames on S3 to remove filename extensions?
I would love to hack on this using substitutions to remove extensions .<ext> from filenames but I think that programmatically its only available for setting up a job for transferring data from devices that you will actually ship to Amazon.
It's not pretty, but it can be done by calling copyObject() for /myBucket/myFile.jpg and setting the new key to be /myBucket/myFile. After the copy is complete, delete the original. At this time I'm not aware of a proper "rename" method available.

Retrieving EXIF info and video informations from pictures/movies

is there a Java framework that will do the dirty work explained in title for me?
Mainly I just need to retrieve images properties stored inside JPEGs:
size
EXIF
geolocations
shot properties
and to retrieve movie files informations like:
codec name
duration
resolution
and so on
I don't need to be able to show the picture or play the movie, just to get the properties without having to write my own file header parsers..
while for images I mainly need JPEG support for movies it would be nice to be able to open as many formats as possible (avi, mkv, mp4, mpeg, mov, etc)
Thanks in advance!
Found this http://www.drewnoakes.com/code/exif/ to extract EXIF from JPEG.

Categories