Animation from large number of jpg files - animation

I have more than 100,000 jpg images in a directory and want to create an animation from these files. These files are sequentially numbered from file1 to file125000. I have tried using ImageMagick and many other free tools, but hasn't worked. After 3 hours, imagemagick gave an error saying that the number of files is too large. Is there any tool (Windows) that can process this?

You can use ffmpeg with a command like this one:
ffmpeg.exe -f image2 -r 30 -i image%06d.jpg -codec:v libx264 -crf 23 video.mp4
ffmpeg command line have a structure like this:
ffmpeg [input params] -i <input> [output params] <output>
Input params are:
-f: is used to force input or output format. In my example is used to indicate that input file is intended to be parsed as image2, an internal ffmpeg format which can be used to specify multiple images using a pattern;
-r: can be used to force frame rate both on input or output. If used only on input, output framerate is inherited.
-i image%06d.jpg: this flag specify to read all image with 6 integer digits, filled with leading zeroes (from image000000.jpg to image999999.jpg). Of course ffmpeg will stop at last existing file.
Other params are used to specify output format and video codec. In particular:
-codec:v libx264: specify video codec (x264 using libx264)
-crf 23: this parameter is peculiar of x264 encoder, used to specify Constant RateFactor, and influences output bitrate and others.
video.mp4: If not specified, FFMpeg try to guess output format from the output file name. In my example I used .mp4, so FFmpeg will encode video using libx264 encoder and MP4 format.
FFMpeg windows build can be download from zeranoe
Edit: if your images names don't have leading zeroes try using file%6d.jpg instead of file%06d.jpg as input filename (without 0).

Related

ffmpeg enforces bitrate value other than what specified

I have a folder containing 1701 image frames named "frame0000.jpg", "frame0001.jpg",..., "frame1700.jpg". When I try to convert them to a video using this command:
ffmpeg -r:1751/61 -b:2400k -i frame%3d.jpg video1.avi
It produces a video with a bitrate of 717kbs and 25 frames/second (so the FPS is also different than what I specified!); hence, it has a poor quality.
I read a lot about this issue such as:
FFMPEG ignores bitrate
But couldn't find the solution to my case.
Any help is appreciated.
Fixed command:
ffmpeg -framerate 1751/61 -i frame%3d.jpg -b:v 2400k video1.avi
Option placement is important
Syntax is:
ffmpeg [input options] -i input [output options] output
Use valid options
-r:1751/61 is incorrect. Use -framerate 1751/61. The image demuxer prefers -framerate, not -r.
-b:2400k is incorrect. Use -b:v 2400k
Refer to the log
It should have provided errors to help you determine the problem:
Invalid stream specifier: 1751/61
Option b (video bitrate (please use -b:v)) cannot be applied to input -- you are trying to apply an input option to an output file or vice versa. Move this option before the file it belongs to.

Is it possible to provide input files list to FFmpeg in a text file instead of on command line?

I need to provide many small file inputs to ffmpeg executable on command line and I am way beyond the maximum command length for the command line. I need to provide the input list as a file. Is it possible?
Yes, just pass input files to -i option:
ffmpeg -f concat -i concat.txt -c:v hevc_nvenc 1.mp4
concat.txt:
file '001.mp4'
file '003.mp4'
Short answer: It's possible, but you'll probably run into other limitations doing it.
Concatenating large numbers of images can be done using FFmpeg's pattern_type "sequence" and "glob" features. Concatenating other media can be done using concat files.
However, these features clump all files into a single concatenated stream. If you want to treat them as separate inputs in -filter_complex, then a different strategy is needed. That said, it's highly unlikely that anyone would use a complex filter with so many inputs for anything other than concatenating files (like what kind of overlay or interleaving or mixing could possibly involve that many files?).
For simplicity, let's use a drawtext filter customized for individual image files (just draw the file number on each image):
ffmpeg -i 0.png -i 1.png -filter_complex "[0]drawtext=text=0[i0];[1]drawtext=text=1[i1];[i0][i1]concat=2" output.mp4
With this format, command-line length gets to >46k at just over 1000 inputs before seeing this error message from FFmpeg:
1020.png: Too many open files
So for me, command-line length isn't the bottleneck (note that I'm on Linux). However, if I wanted to shorten the command-line, then one easy step is to move the complex filter into a file:
ffmpeg -i 0.png -i 1.png -filter_complex_script script_file.txt output.mp4
And this reduces the same command to 11k + a script file. If this is not enough, then the next step is to replace the input files with the movie filter (amovie for audio) as exampled in the concat documentation. In this case, script_file.txt looks like:
movie=0.png,drawtext=text=0[i0];
movie=1.png,drawtext=text=1[i1];
[i0][i1]concat=2
And the command is just:
ffmpeg -filter_complex_script script_file.txt output.mp4
The movie/amovie filters are not perfect replacements for inputs (I ran into this very minor bug), but are close enough for most use-cases.
In any case, this does not get around the limitation of open files, so if you exceed that limit, then you will probably have to generate video segments containing the maximum number of files, and concatenate those segments into a complete video afterwards.
ffmpeg $(ls *.mp4 |sort|xargs -i echo -i {})
Having downloaded many .ts and .aac files I simply used cat to put all the .ts files into one large .ts file
and ditto with the .aac files
I then just used ffmpeg to combine the large .ts and .aac files
ffmpeg -i combined.ts -i combined.aac -c:v copy -c:a copy ouput.mp4

ffmpeg setting ouput option correctly (-r)

I would like to use ffmpeg on Ubuntu with the following command:
ffmpeg -i input_video -vf scale=w=320:h=-1 -y -vcodec libx264 -preset ultrafast -r 60 output_video
For the -r option the documentation says:
-r[:stream_specifier] fps (input/output,per-stream)
Set frame rate (Hz value, fraction or abbreviation).
As an input option, ignore any timestamps stored in the file and
instead generate timestamps assuming constant frame rate fps. This is
not the same as the -framerate option used for some input formats like
image2 or v4l2 (it used to be the same in older versions of FFmpeg).
If in doubt use -framerate instead of the input option -r.
As an output option, duplicate or drop input frames to achieve
constant output frame rate fps.
I would like to use the output option. How can I do this? What is the per-stream option doing (it is not written above)?
Second, is it correct that the -vf scale=w=320:h=-1 option scaled the video to width 320 and keeping the aspect ratio?
I would like to use the -r output option. How can I do this?
Your command is using it as an output option. The location of options is important as it determines what is applied to the input or the output:
ffmpeg [input options] -i input [output options] output
What is the per-stream option doing (it is not written above)?
"per-stream" means that this option can be declared several times to apply to different streams using stream specifiers. Since you have only one video stream in your output you can ignore this.
Second, is it correct that the -vf scale=w=320:h=-1 option scaled the video to width 320 and keeping the aspect ratio?
Yes, but when encoding with libx264 consider using -2 instead of -1. It does the same thing but makes sure the result is divisible by 2 which is required for this encoder (there are exceptions).

Join multiple flv with ffmpeg

i am trying to join two flv files using -concat option in ffmpeg-1.1 . I have created a list named mylist.txt and placed two flv files into it, but the problem i am facing is that the output of first file in mylist.txt streams perfect but video breaks into pieces when it comes to the second file. Looks like i am using the wrong options with -concat, please guide me for suitable commands with -concat option. Following are the commands and configurations i am using for transcoding .flv files:-
mylist.txt
file '/root/1.flv'
file '/root/2.flv'
ffmpeg command :-
ffmpeg -re -f concat -i /root/mylist.txt -acodec copy -vcodec copy output.flv
Following link is the output of ffmpeg command :-
http://pastebin.com/P3uaUDEd
Unless the 2 files were encoded the same (and even if they were it could still be a problem) you would need to transcode the audio and video so that things like time stamps, bitrates, resolutions and other codec internals are correct in both streams. Change you acodec copy and vcodec copy to the codecs of your choice (x264 and mp3/aac are good choices).

ffmpeg -r option

I am trying to use ffmpeg (under linux) to add a small title to a video. So, I use:
ffmpeg -i hk.avi -r 30000/1001 -metadata title="SOF" hk_titled.avi
The addition of title seems to work, but, the problem is the output file is about a 1/3rd of the file size of the input file and I was wondering why this is? Is this at the expense of quality of the video? I am unsure.. How do I preserve the same quality/size as the input file?
The main point I am unable to figure out is the use of -r option. Going through the ffmpeg docs, it seems to suggest that -r is frames per second (The input video is 23.9fps). At the moment, (30000/1001) works out to 29 fps, but I was unsure if I should be using this value.
Thanks for your time.
The default settings for ffmpeg do not always provide a good quality output when you encode, but this depends on your output format and the available encoders. With your output ffmpeg will use the default of -b 200k or -b:v 200k.
However, you can tell ffmpeg to simply copy the input streams without re-encoding and this is recommended if you just want to add or edit metadata. These examples do the same thing but use different syntax depending on your ffmpeg version:
ffmpeg -i hk.avi -vcodec copy -acodec copy -metadata title="SOF" hk_titled.avi
ffmpeg -i hk.avi -c copy -metadata title="SOF" hk_titled.avi

Resources