Segment video with FFMPEG using custom filenames for output - go

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!

Related

ffmpeg segment command flac output broken 'length' metadata

I am trying to use this ffmpeg command:
ffmpeg -i "full_lowq.flac" -c copy -map 0 -f segment -segment_times "302.825,552.017" "%03d_output.flac"
to take my flac file input "full_lowq.flac" and split it at specific points 302.825,552.017 into output audio files like so:
%01d_output.flac
%02d_output.flac
%03d_output.flac
And this command does work at the moment, except that my three outputted flac files display the wrong 'length' metadata number when viewed in the win10 file browser. like in this example every outputted file has the same length as 11:16
But if i view the audio files in audacity i can see the correct file length such as file 0 have a length of 05:02
Is it possible my input file (https://file.io/oof3eykKwXiI) is corrupted? or my command is making a mistake here? wrong codec?

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'

Input parameters to FFMPEG

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'

Convert image sequence to video using ffmpeg and list of files

I have a camera taking time-lapse shots every 2–3 seconds, and I keep a rolling record of a few days' worth. Because that's a lot of files, I keep them in subdirectories by day and hour:
images/
2015-05-02/
00/
2015-05-02-0000-02
2015-05-02-0000-05
2015-05-02-0000-07
01/
(etc.)
2015-05-03/
I'm writing a script to automatically upload a timelapse of the sunrise to YouTube each day. I can get the sunrise time from the web in advance, then go back after the sunrise and get a list of the files that were taken in that period using find:
touch -d "$SUNRISE_START" sunrise-start.txt
touch -d "$SUNRISE_END" sunrise-end.txt
find images/"$TODAY" -type f -anewer sunrise-start.txt ! -anewer sunrise-end.txt
Now I want to convert those files to a video with ffmpeg. Ideally I'd like to do this without making a copy of all the files (because we're talking ~3.5 GB per hour of images), and I'd prefer not to rename them to something like image000n.jpg because other users may want to access the images. Copying the images is my fallback.
But I'm getting stuck sending the results of find to ffmpeg. I understand that ffmpeg can expand wildcards internally, but I'm not sure that this is going to work where the files aren't all in one directory. I also see a few people using find's --exec option with ffmpeg to do batch conversions, but I'm not sure if this is going to work with image sequence input (as opposed to, say, converting 1000 images into 1000 single-frame videos).
Any ideas on how I can connect the two—or, failing that, a better way to get files in a date range across several subdirectories into ffmpeg as an image sequence?
Use the concat demuxer with a list of files. The list format is:
file '/path/to/file1'
file '/path/to/file2'
file '/path/to/file3'
Basic ffmpeg usage:
`ffmpeg -f concat -i mylist.txt ... <output>`
Concatenate [FFmpeg wiki]
use pattern_type glob for this
ffmpeg -f image2 -r 25 -pattern_type glob -i '*.jpg' -an -c:v libx264 -r 25 timelapse.mp4
ffmpeg probably uses the same file name globbing facility as the shell, so all valid file name globbing patterns should work. Specifically in your case, a pattern of images/201?-??-??/??/201?-??-??-????-?? will expand to all files in question e.g.
ls -l images/201?-??-??/??/201?-??-??-????-??
ffmpeg ... 'images/201?-??-??/??/201?-??-??-????-??' ...
Note the quotes around the pattern in the ffmpeg invocation: you want to pass the pattern verbatim to ffmpeg to expand the pattern into file names, not have the shell do the expansion.

Convert series of images to video

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

Resources