convert music to image and back - converters

i am trying to convert a music file (actually mp3) to a image and then back from image to mp3. It may sound crazy but im editing afterwards parts of the image and then convert it back to mp3.
My actual solution is this way:
MP3 --> convert to wav --> convert to base64 --> convert to pixel's per byte / time (10s) .
then the opposite way to go back.
Because this is depending on the length very resource intensive i am looking for a way to get a graphical output much quicker and render it back much quicker... i dont care about which programming language... im more looking for a better (quicker way) to do it that gets the same result. Most MP3's are songs and between 3-6 Minutes long. So the images are getting very big ;=)
How would you approach this? currently my shell script needs 19 seconds for 1 song which is a way to long. Converting it back takes only 12-14 seconds...
Looking for a solution in Linux with ffmpeg and shell scripts.

Related

Converting image sequence to video with inconsistent frame rate

I recently collected video data where the video was generated as image sequences. However, between different video of the same length, different numbers of frames were acquired, which made me think that the image sequence have varied frame rates between videos. So my question is how do I convert this image sequence back to video with accurate duration between frames. Is there a way to get that information from the date and time it was created using a code? I know ffmpeg seems to be the tools many people use.
I am not sure where to start. I am not very familiar with coding, so already have trouble executing the correct codes.

Split a movie so that each GIF is under a certain file size

Problem
I want to convert a long movie into a series on animated GIFs.
Each GIF needs to be <5MB.
Is there any way to determine how large a GIF will be while it is being encoded?
Progress So Far
I can split the movie into individual frames:
ffmpeg -i movie.ogv -r 25 frameTemp.%05d.gif
I can then use convert from ImageMagick to create GIFs. However, I can't find a way to determine the likely file size before running the command.
Alternatively, I can split the movie into chunks:
ffmpeg -i movie.ogv -vcodec copy -ss 00:00:00 -t 00:20:00 output1.ogv
But I've no way of knowing if, when I convert the file to a GIF it will be under 5MB.
A 10 second scene with a lot of action may be over 5MB (bad!) and a static scene could be under 5MB (not a problem, but not very efficient).
Ideas
I think that what I want to do is convert the entire movie into a GIF, then find a way to split it by file size.
Looking at ImageMagick, I can split a GIF into frames, but I don't see a way to split it into animated GIFs of a certain size / length.
So, is this possible?
There currently is no "Stop at this filesize" option in avconv that i'm aware of. It can, of course, be hacked together quite quickly, but currently libav project doesn't do quick hacks, so it'll likely appear in ffmpeg first.
In addition to this you are facing a problem of animated gif being a very old format, and thus doing some rather strange things. Let me explain the way it normally works:
You create a series of frames from first to last and put them on top of one another.
You make all the "future" frames invisible, and set to appear at the specific time.
In order to make the size of the file smaller, you look "below" the new frames, and if the previous pixel is the same, you set that particular pixel as opaque.
That third step is the only time compression that is done in the animated gif, without it the file size will be much larger (since every pixel must be saved again and again).
However, if you are unsure when was the last break, you cannot determine if the pixel is the same as the previous "frames". After all, this particular frame can be the very first one in the image.
If the limit of 5MiB is soft enough to allow going a little over it, you probably can put something together that just keeps adding frame after frame, and calculating the final file size right away. As soon as one goes over the limit, just stop and use the next frame as the starting point for the next file.

Detect frames that have a given image/logo with FFmpeg

I'm trying to split a video by detecting the presence of a marker (an image) in the frames. I've gone over the documentation and I see removelogo but not detectlogo.
Does anyone know how this could be achieved? I know what the logo is and the region it will be on.
I'm thinking I can extract all frames to png's and then analyse them one by one (or n by n) but it might be a lengthy process...
Any pointers?
ffmpeg doesn't have any such ability natively. The delogo filter simply works by taking a rectangular region in its parameters and interpolating that region based on its surroundings. It doesn't care what the region contained previously; it'll fill in the region regardless of what it previously contained.
If you need to detect the presence of a logo, that's a totally different task. You'll need to create it yourself; if you're serious about this, I'd recommend that you start familiarizing yourself with the ffmpeg filter API and get ready to get your hands dirty. If the logo has a distinctive color, that might be a good way to detect it.
Since what you're after is probably going to just be outputting information on which frames contain (or don't contain) the logo, one filter to look at as a model will be the blackframe filter (which searches for all-black frames).
You can write a detect-logo module, Decode the video(YUV 420P FORMAT), feed the raw frame to this module, Do a SAD(Sum of Absolute Difference) on the region where you expect a logo,if SAD is negligible its a match, record the frame number. You can split the videos at these frames.
SAD is done only on Y(luma) frames. To save processing you can scale the video to a lower resolution before decoding it.
I have successfully detect logo using a rpi and coral ai accelerator in conjunction with ffmeg to to extract the jpegs. Crop the image to just the logo then apply to your trained model. Even then you will need to sample a minute or so of video to determine the actual logos identity.

Still images to video for storage - But back to still images for viewing

Using ffmpeg I can take a number of still images and turn them into a video. I would like to do this to decrease the total size of all my timelapse photos. But I would also like to extract the still images for use at a later date.
In order to use this method:
- I will need to correlate the original still image against a frame number in the video.
- And I will need to extract a thumbnail of a given frame number in a
video.
But before I go down this rabbit hole, I want to know if the requirements are possible using ffmpeg, and if so any hints on how to accomplish the task.
note: The still images are timelapse from a single camera over a day, so temporal compression will be measurable compared to a stack of jpegs.
When you use ffmpeg to create a video from a sequence of images, the images aren't affected in any way. You should still be able to use them for what you're trying to do, unless I'm misunderstanding your question.
Edit: You can use ffmpeg to create images from an existing video. I'm not sure how well it will work for your purposes, but the images are pretty high quality, if not the same as the originals. You'd have to play around with it to make sure the extracted images are exactly the same as the input images as far as sequential order and naming, but if you take fps into account, it should work.
The command to do this (from the ffmpeg documentation) is as follows:
ffmpeg -i movie.mpg movie%d.jpg

How can you hide information inside a jpg or gif photo?

How can I write some information inside a photo file like jpg or gif without destroying the image? and of course without showing it on the photo since the whole idea is to send information in the file of photo undetected by anyone (to provide security/privacy to some extent)!
You can concatenate a gif and a zip (the information you want to hide) into one file. Gifs are read from the start of the file, while zips are read from the end of the file.
To create such a file in linux:
$ cat file1.gif >> outfile.gif
$ cat file2.zip >> outfile.gif
The resulting file should have the size of file1.gif and file2.zip together and should be openable by any gif viewer and zip file handler.
I'm sure there are many ways. Here's one:
In a photograph, minor variations in color would often be unnoticable to the naked eye, or even if noticed, might easily be mistaken for flaws in the quality of the picture.
So to take a simple example, suppose you had a gray-scale GIF image where the pallette is arranged in order from white to black with a smooth range of grays in between. I'm not sure how much you know about graphic file formats, but in GIF you have one byte per pixel, with each possible byte value mapping to some specific color. So in this case we could say pallette #0=RGB(0,0,0), pallette #1=RGB(1,1,1), ... palette #255=RGB(255,255,255).
Then you take an ordinary, real photograph. Break your secret message into individual bits. Set the last bit of each pallette index number to successive bits of your message.
For example, suppose the first eight pixels of the original photo are, say, 01 00 C9 FF FF C8 42 43. Your message begins with the letter "C", ascii code 0110 0111. So you change the last bit of the first byte to 0, changing the byte from 01 to 00. You change the last bit of the second byte to 1, changing the byte from 00 to 01. You change the last bit of the third byte to 1. It's already 1, so that makes no difference. Etc. You end up with the coded 8 bytes being 00 01 C9 FE FF C9 43 43.
The changes to the colors would be so subtle that it's unlikely that anyone looking at the picture would notice. Even if they did notice, unless they had a reason to be suspicious, they would likely just conclude that the picture was of less-than-perfect quality.
Of course nothing says you have to use 1 bit per byte for the secret message. Depending on how much degradation in quality you think you can get away with, you could use 2 bits per byte, or just change 1 bit in every other byte, etc.
Of course the same technique can be used with color photos: change the last bit in each of the RGB components to encode 3 bits per pixel, etc.
Hey that method is called as Steganography. With that we can hide messages in not just images but also in audio,vedeo and other formats.
Here is an opensouce Steganography software called steganotool This project is an open source steganography tool that can be used to hide and extract text to/ from Bitmap images.
About Steganography Mediums
Steganography in images
This type of steganography is very effective against discovery and can serve a variety of purposes. These purposes can include authentication, concealing of messages, and transmission of encryption keys. The most effective method for this type of steganography is normally the least significant bit method. This simply means that the hidden message will alter the last bit of a byte in a picture. By altering that last bit, there will be relatively no change to the color of that pixel within the carrier image. This keeps the message from being easily detected. The best type of image file to hide information inside of is a 24 bit Bitmap. This is due the large file size and high quality.
Steganography in Audio
In audio files, the most prominent method for concealing information is the low bit encoding method. The low bit encoding method is somewhat similar to the least significant bit method used in image files. The secret information is attached to the end of the file. One of the issues with low bit encoding is that it can be noticeable to the human ear. If someone is trying to hide information, this could be risky, since it is so easily detectable. The spread spectrum method is another method that has been used in the concealment of information in audio files. What this method does, is it adds random noise to the audio broadcast. This method enables for the information to be spread accross the frequency spectrum and remain hiddden under the random noise. The last method seen in audio steganography is echo hiding data. This method seeks to hide information by using the echos that occur naturally within sound files. Then, extra sound can be added to these echos, extra sound being the concealed message. This is a sufficient way to hide information, expecially since it even improves the sound of the original audio file in some cases.
Steganography In Video
Steganography in Videos is basically hiding of information in each frame of video. Only a small amount of information is hidden inside of video it generally isn’t noticeable at all, however the more information that is hidden the more noticeable it will become. This method is effective as well, but must be done right or else reveal more information instead of hiding.
Steganography In Documents
This is basically adding white space and tabs to the ends of the lines of a document. This type of
Steganography is extremely effective, because the use white space and tabs is not visible to the human eye in most text/document editors.
You can also refer to this open source project
This article can be very useful.
You can store some information in image metadata. In fact that's how man digital cameras 'tag' the photos their making (camera model, date and time, GPS coords etc.).
This data format is called EXIF (Exchangeable Image File Format). There are a lot of examples how to use it in programming languages. Here's the example in Java.
If you want to prevent users from reading this data you can encrypt them somehow, but they will always be able to remove it from your picture (by opening in Photoshop and using Save As for example).
If you want to hide data (text, another image, whatever) in a jpeg file, you can simply append it to the end of the file. When the image is viewed, you'll only see the original image and your added data will be ignored.
While not a super-duper way of hiding data, this is a good way of hiding another jpeg, as if anyone opens the file in notepad or a hex editor, they will probably not notice that there are two jpegs and not one because the end of the second image will just look like the first anyway.
In windows you can use simple command to hide archive in image : copy /b cat.jpg + Documents.rar cat_new.jpg.
And then use for example winrar to extract data ftom image as from archive.
But better way is to use Steganography.
simple program for it for linux and windows : http://linux01.gwdg.de/~alatham/stego.html
using this program you will use pass phrase, without it nobody even will know, that you hided some data in picture ))
compressed data in gif files is in variable sized chunks. each chunk starts with a length byte. Usually these chunks are 255 bytes of data (and the length byte says 255) except for the last two chunks (the last one is 0)
But you could re-code the gif with chunks whose size spells out the message
eg using characters for ASCII text or bytes 1 2 3 4 representing 00 01 10 11 binary data,
byte-frequency analysis on the gif would reveal fewer than expected 255 bytes.
and the size would be larger than the original, but the image would look exactly the same.
You don't need any type of advanced tool to hide a file in an image –– you just you need to know some basic DOS commands… just follow the link below, to see how to do this (it’s a short description of image steganography):
https://www.youtube.com/watch?v=ox9ArqXtaWw&list=PLqEKOAKK4IbSTfDJZE_lH-DiOjOzZUczx&index=2

Resources