I have a video and few images. I know two places in the video where I want to paste these images. But they shouldn't have fixed position and size. On the contrary, images should move, change their tilt angle and scale. For example you may imagine closed book and you want to overlay its name when the book is slowly opens.
I read FFMPEG documentation but didn't found anything about this. Can FFMPEG do this? If not, which libraries or methodics can do that?
The FFMPEG overlay filter can overlay one stream atop another.
It takes an expression which is evaluated per frame to determine the position.
https://ffmpeg.org/ffmpeg-filters.html#overlay-1
You may consider creating a filter chain to do the following.
1) Create a transparent image with the title of your book.
2) Use a 3D rotate filter to convert the single image into an animated sequence
3) Use the overlay filter to apply the animated stream atop your book video.
Related
With ffmpeg, you can:
create a video from a list of images
create an image with tiles representing frames of a video
but, how is it possible to create a video from tiles, in a picture, representing frames of a video?
if I have this command line:
ffmpeg -i test.mp4 -vf "scale=320:240,tile=12x25" out.png
I will get an image (out.png) made of 12x25 tiles of 320x240 pixels each.
I am trying to reverse the process and, from that image, generate a video.
Is it possible?
Edit with more details:
What am I really trying to achieve is to convert a video into a gif preview. But in order to make an acceptable gif, I need to build a common palette. So, either I scan the movie twice, but it would be very long since I have to do it for a large batch, or I make a tiled image with all the frames in a single image, then make a gif with a palette computed from all the frames, which would be significantly faster... if possible.
Is it possible to do something like this purely with ffmpeg?
Lets say we have a text file with the frame by frame coordinates for the 4 corners where the image should go. ffmpeg has a perspective filter, but how would one get ffmpeg to pull the frame coordinates from the text file? I'm guessing with a pipe of sorts?
The perspective filter corrects the input's perspective, it doesn't apply a perspective effect. Applied to an overlay it results in a rectangular overlay with a corrected perspective.
The closest you can get with the already implemented filters is via the frei0r perspective module.
You can write your own filter for ffmpeg or a frei0r module.
Update: using #Mulvya's tip you can use timeline editing with perspective:
perspective=enable='eq(n,0)':x0=...,perspective=enable='eq(n,1)':x0=...
where n is the current frame number.
This will result in an impossibly long command line which may go over the system limit. You're still better writing your own filter.
You can alternatively do one frame at a time with a different command, save the output as an image and re-assemble the video at the end.
I'm trying to want to know the P-frame at mpeg.
I have a query about reference image.
Why not we use original image instead decoded image to make P-frame?
I-frame, B-frame and P-frame allows to compress the video.
Indeed, in a video you have a lot of redundant information.
Think about a car moving across the screen: all the pixels in the background do not change from a picture to another, only those around the car are "moving". With the I-B-P frame truck, you give the code of the background and then, you just signalling slight changes (the car moving) through vectors.
This way you have to carry less information than if you have to repeat the entire picture each time.
See also:
Video compression
https://stackoverflow.com/a/24084121/3194340
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.
I am generating series of images for text scrolling, I need to overlay those images on a video at specific interval (for example from 10-15sec), how can we do that using ffmpeg?
According to FFmpeg developer Stefano Sabatini, this cannot currently be done.
Right now you can't do that by using the overlay, you need a multi-steps
process, where you need to split the file, overlay just in the interested
segments and merge again the modified segments, or create an ad-hoc video to
overlay which shows the image only in the interested intervals.
ffmpeg.org/pipermail/ffmpeg-user/2012-January/004062.html