Convert FLV video with alpha channel to PNGs with transparency - ffmpeg

I have some FLV videos with alpha channels, and I want to convert each of them to PNG images using ffmpeg but keep the transparency.
So far, I've tried this:
ffmpeg -i input.flv -an -y %d.png
But this outputs the PNG files with black background.
Is there any way to do this?
Alternate acceptable solution: If I can output the images and give the alpha channel a certain color of my choice. I can then remove it later via imagemagick and convert that color to transparency.

I know its quite late for an answer but I was searching for a similar solution and found this : ffmpeg -i video.flv -r 25 -vcodec png -pix_fmt rgb32 %d.png

Related

Colors not accurate in ffmpeg video

I am creating a video with ffmpeg by stringing together a bunch of PNG files. The resulting video has horizontal lines running across it and the colors are not accurate. Here's the command I used:
ffmpeg -framerate 1 -i img%04d.png -pix_fmt yuv420p timer.mp4
I am attaching an example of one of the input PNG files and a frame from the video. Can anyone tell what's wrong?
input file
video frame

FFMPEG color to transparencyq

I am trying to convert a mp4 video with a completely uniform pink color to a mov file seuch that the pink color is transparent.
I have run:
ffmpeg -i input.mp4 -vf "chromakey=0xf25b98:0.01:0" -c copy -c:v png output.mov
I confirmed that #f25b98 is the color I am replacing. This makes absolutely nothing transparent. When I try:
ffmpeg -i input.mp4 -vf "chromakey=0xf25b98:0.02:0" -c copy -c:v png output.mov
I get some weird transparent dots in my pink but still nothing is changed (see attached screenshot from video).
Why would ffmpeg exhibit this behavior?
Short answer is that it is not possible to use FFMPEG to remove a keyframe from an already compressed video stream because the compression introduces bleed which makes for an imprecise transparency.

FFMPEG DNxHR with Alpha to Webm

I'm trying to convert a video file exported from Blackmagic Fusion as DNxHR with Alpha checked to WebM or PNG. FFMPEG seems to ignore the alpha and the background is black. Is there something I need to do? This is what I'm currently using:
ffmpeg -ss 0.5 -i DNxHR444A.mov -vframes 1 test.png
or
ffmpeg -i DNxHR444A.mov -c:v libvpx-vp9 -crf 30 -b:v 0 test.webm
I can upload my test video if that helps. But it's quite large.
FFmpeg's DNXHD/R decoder does not support alpha. Either use another codec on export, or export alpha separately (it will be a grayscale picture). With the 2nd method, ffmpeg can combine the main image and the alpha for onward processing.

ffmpeg: Combine a audio (.wav) and video in (.rgb) format

I want to synchronously play audio (.wav) file and video which is provided to me in rgb format.
The rgb file contains all the rgb images in the video frames. How can I combine rgb file and audio using ffmeg to get output video which can be played on vlc player?
Input 1 : audio.wav
Input 2 : allimages.rgb
Output : A video file which can be played in vlc player.
I was looking at ffmpeg documentation but couldn't find anything for rgb input. It would be great help if you can provide the ffmpeg command for doing above.
Thanks
The closest I got with this is using below command, but I see Green and Pink colors in my video after I play it. I think I am missing something in the ffmpeg command. Can anyone tell me what is wrong in above command and help to improve video quality and remove green and pink colors?
ffmpeg -s 480x270 -r 15 -pix_fmt gbrp -i /Users/sandeep/Downloads/Videos/input.rgb -c:v libx264 -y output.mp4

Create animated gif from a set of jpeg images

I need something that can be scripted on windows 7. This image will be used in banners.
Simon P Stevens' answer almost got me there:
ffmpeg -f image2 -i image%d.jpg video.avi
ffmpeg -i video.avi -pix_fmt rgb24 -loop_output 0 out.gif
Let's see if we can neaten this up.
Going via an avi is unnecessary. A -pix_fmt of rgb24 is invalid, and the -loop_output option prevents looping, which I don't want. We get:
ffmpeg -f image2 -i image%d.jpg out.gif
My input pictures are labeled with a zero-padded 3-digit number and I have 30 of them (image_001.jpg, image_002.jpg, ...), so I need to fix the format specifier
ffmpeg -f image2 -i image_%003d.jpg out.gif
My input pictures are from my phone camera, they are way too big! I need to scale them down.
ffmpeg -f image2 -i image_%003d.jpg -vf scale=531x299 out.gif
I also need to rotate them 90 degrees clockwise
ffmpeg -f image2 -i image_%003d.jpg -vf scale=531x299,transpose=1 out.gif
This gif will play with zero delay between frames, which is probably not what we want. Specify the framerate of the input images
ffmpeg -f image2 -framerate 9 -i image_%003d.jpg -vf scale=531x299,transpose=1 out.gif
The image is just a tad too big, so I'll crop out 100 pixels of sky. The transpose makes this tricky, I use the post-rotated x and y values:
ffmpeg -f image2 -framerate 9 -i image_%003d.jpg -vf scale=531x299,transpose=1,crop=299,431,0,100 out.gif
The final result - I get to share my mate's awesome facial expression with the world:
You can do this with ffmpeg
First convert the images to a video:
ffmpeg -f image2 -i image%d.jpg video.avi
(This will convert the images from the current directory (named image1.jpg, image2.jpg...) to a video file named video.avi.)
Then convert the avi to a gif:
ffmpeg -i video.avi -pix_fmt rgb24 -loop_output 0 out.gif
You can get windows binaries for ffmpeg here.
You can also do a similar thing with mplayer. See Encoding from multiple input image files.
I think the command line would be something like:
mplayer mf://*.jpg -mf w=800:h=600:type=jpg -vf scale=160:120 -vo gif89a:fps=3:output=out.gif
(Where 800 & 600 are your source width and height and 160 & 120 are the target width and height.out.gif is your target file name)
I've just tested both of these and they both work fine. However I got much better results from mplayer as I was able to specify the resolution and framerate. Your milage may vary and I'm sure you could find more options for ffmpeg if you looked.
With ImageMagick:
convert *.png a.gif
The ffmpeg to .avi and .avi to .gif worked, but the only thing to note is that your images must be named in perfect increasing numeric order to work, with no gaps. I cooked up a quick python script to rename all of my images accordingly so that this ffmpeg recipe would work:
import os
files = [ f for f in os.listdir('.') if os.path.isfile(os.path.join('.',f)) and f.endswith('.jpg') ]
for i, file in enumerate(sorted(files)):
os.rename(file, 'image%03d.jpg' % i)
And then I stumbled upon a much simpler approach than ffmpeg for doing the conversion, which is simply using ImageMagick's command line convert tool like this
convert image%03d.jpg[0-198] animated_gif.gif
Doesn't get much simpler than that folks.
Gist here: https://gist.github.com/3289840
Based on the answers of Simon P Stevens and dwurf I came up with this simplified solution:
ffmpeg -f image2 -framerate 1 -i image%d.jpg video.gif
This results in a rate of 1 second per image. Adjust the framerate value according to your needs.
I'd just like to add to dwurf's answer, that this will generate a gif with the standard 256-colors palette, which does not look very visually pleasing.
I've found two blog-posts and adapted them to my needs, in order to improve the visual quality by using a custom palette for your animation:
Generate the color palette:
ffmpeg -f image2 -i image%d.jpg -vf scale=900:-1:sws_dither=ed,palettegen palette.png
Convert images into a regular video with the desired framerate, because the third command only worked with a single input video and not a bunch of images
ffmpeg -f image2 -framerate 1.2 -i image%d.jpg video.flv
Now convert the generated video with the generated palette into a more beautiful gif:
ffmpeg -i video.flv -i palette.png -filter_complex "fps=1.2,scale=900:-1:flags=lanczos[x];[x][1:v]paletteuse" video.gif

Resources