Convert series of images to video - ffmpeg

I have series of images with sorted names, like 0000000354 ... 0000008591
I have tried using ffmpeg or MEncoder to convert theme. In ffmpeg the problem is this that it will operate while the names are like 0000000001 ... 00000000009 with %010d syntax.I don't know what syntax i should use for my images names.in mencoder it will cover all images But when i play the output video it doesn't show images,I want to show every image in 5 seconds or somthing like this, any one can help?

ffmpeg can't read in arbitrarily named images. You'll have to rename them or do something clever with symlinks to get ffmpeg to take them as input.
From the man page:
If the pattern contains "%d" or "%0Nd", the first filename of the file
list specified by the pattern must contain a number inclusively
contained between 0 and 4, all the following numbers must be
sequential. This limitation may be hopefully fixed.

Let's say you have:
img000001.jpg
....
img000140.jpg
....
img010040.jpg
....
To encode it into a movie using ffmpeg just use the filename pattern:
ffmpeg -i "img%06d.png" -vcodec libx264 -vpre ipod640 output.mp4

Related

Segment video with FFMPEG using custom filenames for output

I'm trying to segment a video and name the cropped files in a specific way. Right now I'm using
ffmpeg -i input.mp3 -f segment -segment_time 59 output_%03d.wav
and looping over created files, parsing their filenames and renaming them accordingly.
I have an array which contains
array=[1650027545, 1650027300, 1650026502, ...]
and want the output files to be in;
output_1650027545.wav
output_1650027300.wav
output_1650026502.wav
format. Since there's no loop, I can't figure out how to implement such a naming scheme. Any help is appreciated!

Remove a section from the middle of a video without concat

How do I cut a section out of a video with ffmpeg?
Imagine I have a 60 second mp4 A.
I want to remove all the stuff from 0:15 to 0:45.
The result should be a 30-second mp4, which is composed of the first 15 seconds of A directly followed by the last 15 seconds of A.
How can I do this without using concat?
I know how I could do it by creating two intermediary files and then using ffmpeg to concat them. I don't want to have to perform so much manual work for this (simple?) operation.
I have also seen the trim filder used for removing multiple parts from a video. All the usages I've found show that it seems to be very verbose, and I haven't found an example for a case as simple as I would like (just a single section removed).
Do I have to use trim for this operation? Or are there other less verbose solutions?
The ideal would of course be something at least simple as -ss 0:15 -to 0:45 which removes the ends of a video (-cut 0:15-0:45 for example).
I started from
https://stackoverflow.com/a/54192662/3499840 (currently the only answer to "FFmpeg remove 2 sec from middle of video and concat the parts. Single line solution").
Working from that example, the following works for me:
# In order to keep <start-15s> and <45s-end>, you need to
# keep all the frames which are "not between 15s and 45s":
ffmpeg -i input.mp4 \
-vf "select='not(between(t,15,45))', setpts=N/FRAME_RATE/TB" \
-af "aselect='not(between(t,15,45))', asetpts=N/SR/TB" \
output.mp4
This is a one-line linux command, but I've used the bash line-continuation character ('\') so that I can vertically align the equals-signs as this helps me to understand what is going on.
I had never seen ffmpeg's not and between operators before, but I found their documentation here.
Regarding the usual ffmpeg "copy vs re-encode" dichotomy, I was hoping to be able to use ffmpeg's "copy" "codec" (yeah, I know that it's not really a codec) so that ffmpeg would not re-encode my video, but if I specify "copy", then ffmpeg starts and stops at the nearest keyframes which are not sufficiently close to my desired start and stop points. (I want to remove a piece of video that is approximately 20 seconds long, but my source video only has one keyframe every 45 seconds!). Hence I am obliged to re-encode. See https://trac.ffmpeg.org/wiki/Seeking#Seekingwhiledoingacodeccopy for more info.
The setpts/asetpts filters set the timestamps on each frame to the correct values so that your media player will play each frame at the correct time.
HTH.
If you want to use the copy "codec", consider the following approach:
ffmpeg -i input.mp4 -t "$start_cut_section" -c copy part1.mp4&
ffmpeg -i input.mp4 -ss "$end_cut_section" -c copy part2.mp4&
echo "file 'part1.mp4'" > filelist;
echo "file 'part2.mp4'" >> filelist;
wait;
ffmpeg -f concat -i filelist -c copy output.mp4;
rm filelist;
This creates two files from before and after the cut, then combines them into a new trimmed final video. Obviously, this can be used to create as many cuts as you like. It may seem like a longer approach than the accepted answer, but it likely will execute much faster because of the use of the copy codec.

What is the correct command line format for ffmpeg in this case

I apologise if this is a duplicate. I have used ffmpeg in the past to convert .pngs to .mp4 but now I am using it on my own files and I am not sure of the format it should have.
I have some files with the following naming convention:
./profiles_0.png
./profiles_40.png
...
./profiles_400.png
The number of files I have varies, i.e. it isn't always 400 and the interval isn't always going to be 40. I have tried the following:
ffmpeg -framerate 1 -i profiles_%d0.png -r 6 -pix_fmt yuv420p out.mp4
but that only captures one of the images. Is there a flexible format in the 'profiles_%d0.png" argument that captures all of the files in that directory regardless of the number of characters following the underscore or does it require that I change my naming convention?
Cheers for any help,
A
If you only have the images of interest in your folder it's easy. You can use a command similar to yours, examples are given in this other question. Basically you can match the files with a wildcard operator and their extension, *.png in that case.
It could look like this:
ffmpeg -f image2 -pattern_type glob -i '*.png' out.avi
This is only selectable if libavformat was compiled with globbing
support.
According to FFmpeg's documentation on the image2 demuxer.
If you have other files with other numbering or if you have a sequence of files and want to select a subsequence, I see no way to do it automatically but you can specify such sequence. You'll still need to use glob, you can get help on the use of globs in FFmpeg there and more information on glob programming here.

ffmpeg - Converting series of images to video (Ubuntu)

I got pictures named as
pic_0_new.jpg
pic_10_new.jpg
pic_20_new.jpg
...
pic_1050_new.jpg
which I want to turn into a video (Ubuntu ffmpeg). I tried the following
ffmpeg -start_number 0 -i pic_%d_new.jpg -vcodec mpeg4 test.avi
but I don't know how to set the step size and the end number. How to do this?
Thanks for help :)
If your files are named with leading zeroes then you can use the built-in globbing functionality. If not (like your's), you can create a file list and supply that as the input, just like explained here.
The other thing you need to set is the input framerate that tells FFmpeg what framerate should assume for the images (note that the option is ahead of the -i input option).
So the command should look like this:
ffmpeg -framerate 25 -i pic_%04d_new.jpg <encoding_settings> test.avi
Also note that you can use the filename expansion on files with or without leading zeroes (Thanks for #Gyan to pointing it out):
match regularly numbered files: %d (this is what you're using)
img_%d.png // This will match files with any number as a postfix starting from img_0.png
match leading zeroes: %0<number_of_digits>d
img_%03d.png // This will match files ranging from img_000.png to img_999.png
In addition, mpeg4/avi is not the most convenient encoder/container to use...

ffmpeg convert images with name pattern into video [duplicate]

I am trying to make an FFMPEG script that relied on a glob input pattern from Linux to Windows. Unfortunately that is not supported so I am looking for an alternative. I do not want to have to rename or copy the files every time I run the script because the files are used elsewhere and I cannot rename them and I would like to avoid duplication or unnecessary temporary files.
Are globs numerically sequential named images my only option here? Ideally I would like to input a list of image paths to FFMPEG as a substitute for ffmpeg -i *.jpg
The workarounds are to prepare a text file with the names and use the concat demuxer.
Or you can use image2pipe
cat *.jpg | ffmpeg -f image2pipe -framerate 25 -i - out.mp4
The best solution I could find (that's Windows compatible) was to generate a line separated list of files in a text file and pass that through to FFMPEG. For example, to generate a stabilized MP4 from a bunch of JPEGs:
ffmpeg -f concat -safe 0 -i ./files.txt -vf deshake=rx=64:ry=64 ./stabilized.mp4
Where files.txt is a list of the files in the following format. The safe option toggles the ability to have absolute/relative file paths.
# this is a comment
file 'C:/path/to/file1.jpg'
file 'C:/path/to/file2.jpg'
file 'C:/path/to/file3.jpg'

Resources