I want to have the output file to have same name from source ( for eg first filename from list.txt), how can I do it?
This is the code I have which converts the all the .avi in folder to a single files and renames it to output.avi.
Instead of output.avi I want the filename to be same as first filename from source folder or first filename from list.txt.
for %%f in (*.avi) do (
echo file %%f >> list.txt
)
ffmpeg -f concat -safe 0 -i list.txt -c copy output.avi
del list.txt
One more thing I want to know, is it possible to flip video horizontal or mirror it without re-encoding?
I don't think ffmpeg supports "backreferencing" the input filenames. I suggest handling that in bash or some through other means of scripting. E.g. you can use the first line of list.txt as the output filename like this (untested):
ffmpeg -f concat -i list.txt -c copy output/$(head -1 list.txt)
In this example if the first line is foo.avi, the output will be saved at output/foo.avi.
is it possible to flip video horizontal or mirror it without re-encoding
Apparently you can set rotation metadata without re-encoding to hint video players to play it back with the given rotation. Maybe there are metadata flags for mirroring or flipping, but I couldn't find any.
If this does not work for you, I don't believe there is a built-in solution to do this without re-encoding.
Is it possible to flip video horizontal or mirror it without re-encoding?
No, not when using filters (such as hflip, vflip, rotate, etc). Filtering requires re-encoding.
Rotation metadata as mentioned in another answer may suffice this use case, but support among players is not universal. There is no metadata for mirroring or flipping: only rotation.
If that is not acceptable then the player itself may have mirroring/flipping capabilities. Example:
mpv -vf hflip video.mp4
Related
I am using the following command within a batch script to, hopefully, eventually programmatically create simple video slideshows with transitions:
melt 131.jpg 132.jpg 133.jpg ttl=75 -attach crop center=1 -filter luma cycle=75 duration=25 -transition mix -consumer avformat:out.mp4 frame_rate_num=30 frame_rate_den=1
Most of this command is an adaptation for Windows of this command on the MLT website blog (with the exception of the part that scales and transforms the image). For some reason when I run this, however, the output video file is 25 minutes long!
I have two main questions:
a. How do I properly control the duration of each image in the video? I have experimented quite a bit with changing the parameters and I have a semi-decent understanding of what they all mean (I am a newbie to MLT but I figured that there's no way to do something like this easily in FFMPEG alone). The only way I have found to decrease the duration with any amount of control is to increase the output framerate to absurd numbers (which, of course, is not ideal as it's a massive waste of time and energy and still doesn't really solve the issue).
b. How do I use a wildcard to input all the .jpg files in a folder on Windows? I tried adding *.jpg but that didn't work and I don't know how else to do it within a batch script (I tried using the following code to get the file names as a variable, but I wasn't able to get string concatenation working correctly because it only outputs the final file name)
set files=
for /r %%i in (*.jpg) do (
echo %%i
set files=%files% "%%i"
)
echo %files%
Thank you for any suggestions!
When you specify a .jpg file, melt automatically chooses a producer internally. Depending on your environment and version, that producer will either be the qimage or pixbuf producer.
Both producers offer a "ttl" parameter to specify the duration of the image (in frames) for image sequences
https://mltframework.org/plugins/ProducerQimage/#ttl
https://mltframework.org/plugins/ProducerPixbuf/#ttl
In the example you linked, an image sequence is created by using the special syntax: photos/.all.jpg ttl=75
In your example, you specify a specific file name. So an image sequence is not created. Instead, a new producer is created for each file. The default length for a producer is 15000 frames.
https://github.com/mltframework/mlt/blob/master/src/framework/mlt_producer.c#L102
The length can be specified in the command line.
melt 131.jpg length=100 132.jpg length=100 133.jpg length=100
Change
set files=%files% "%%i"
to
CALL set "files=%%files%% "%%i""
This uses a subsidiary process to concatenate your filenames.
I have no idea about the solution to your other question.
I need help with FFmpeg/batch. I have a couple of large batches of images (+14000 files each batch, +5 MB each image, .TIFF all of them) and I'm stringing them together into a .mp4 video using FFmpeg.
The date in the metadata is broken because of the way they're stored upon creation, so the time and date (T/D) are on the file_name. I need each frame to have its respective T/D (so its File_Name) burnt onto them for accurate measurements (scientific purpose).
With the help of google and reddit, I've managed to semi-automate it like so:
Master.bat:
forfiles /p "D:\InputPath" /m "*.TIFF" /S /C "cmd /c C:\SlavePath\slave.bat #file #fname"
Slave.bat:
ffmpeg -i "%~1" -vf "drawtext=text=%~2: fontcolor=white: fontsize=30: fontfile='C\:\\FontPath\\OpenSans-Regular.ttf'" "D:\OutputPath\mod_%~1"
Running Master.bat will output each individual image with the text burnt onto them and change the File_Name to mod_'File_name'.TIFF
Real example: 2018-06-05--16-00-01.0034.TIFF turns into mod_2018-06-05--16-00-01.0034.TIFF
The problem is that FFmpeg doesn't like it when my files have "--" in them ("date--time.miliseconds.TIFF") and doesn't like the miliseconds either, so I have to change the name of all files "manually" using Bulk Rename Utility (BRU). So, using BRU I rename all files to 00001.TIFF, 00002.TIFF, etc. and FFmpeg likes me again. It works great, but it means I can't be AFK.
After that, I have to go back to cmd and manually start the image to video conversion.
Also, FFmpeg doesn't seem to be using all cores.
I need help finding a way to:
Change master.bat's output to 00001.TIFF etc. automatically in order of processing (i.e. first to be processed is 1.TIFF, 2nd is 2.TIFF)
Add ffmpeg's img-to-vid function to the automating system
Get my CPU to use all the cores effectively if possible. 2014/15 posts found on google make it seem as though FFmpeg doesn't support multi-core or hyperthreading.
64bit Windows, i7 7700hq, gtx 1050 4Gb, C: SSD, D: HDD
Try this:
ffmpeg -i "2018-06-05--16-00-01.%4d.TIFF" -threads 4 out.mp4
https://en.wikibooks.org/wiki/FFMPEG_An_Intermediate_Guide/image_sequence
I am using gdalsrsinfo to extract the projection details of vector files in multiple folders using the code mentioned below:
for /R .\ %%f IN ("*.tab") DO gdalsrsinfo -o wkt "%%f" >>U:\srsinfo.csv
Though the output file has been created with the projection details, it's not listing the filenames. Output e.g.:
GEOGCS["unnamed",DATUM["North_American_Datum_1983",SPHEROID["GRS 80",6378137,298.257222101],TOWGS84[0,0,0,-0,-0,-0,0]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433]]
GEOGCS["unnamed",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563],TOWGS84[0,0,0,-0,-0,-0,0]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433]]
Without filenames, I can't use this code. Is it possible to extract the respective filenames?
I've got a number of files I'm trying to sort through for my PhD research. I'm not familiar with using Batch files but I do have some coding experience.
I'm trying to move the files based on part of their filename into folders generated automatically for them in the directory they're currently in.
The files were generated as part of a series of pXRF analyses on brass objects held at a museum.
Some examples of the file structure:
01-64.1007-1-LID.pdz
01-64.1007-2-BASE.pdz
02-67.1765-1.pdz
02-67.1765-2.pdz
02-67.1765-3.pdz
etc.
Basically the file structure works like this:
The first number is my unique identifier for the object, then a hyphen, then the museums unique identifier, then a hyphen, then a number to show which analysis of the object. Finally, there may or may not be a small descriptor (i.e. BASE or LID) which helps me identify where I performed the scan.
So to break it down 01-64.1007-1-LID means Object 1 - Museum Accession Number 64.1007 - First Analysis - Performed on the lid of the object - .pdz is the file extension.
02-67.1765-2 means Object 2 - Museum Accession Number 67.1765 - Second Analysis etc.
What I want to do is move:
01-64.1007-1-LID.pdz
01-64.1007-2-BASE.pdz
into a folder called:
01-64.1007
and
02-67.1765-1.pdz
02-67.1765-2.pdz
02-67.1765-3.pdz
into a folder called:
02-67.1765
etc.
I've seen a few scripts which may help with this but I'm unsure how to tweak them for my purposes. If anyone can help I'd really appreciate it!
Thanks,
Mike
Test this batch file in a folder of sample files: call it movepdz.bat so the name doesn't clash with another executable.
#echo off
for %%a in (*.pdz) do (
echo processing "%%a"
for /f "tokens=1,2 delims=-" %%b in ("%%~nxa") do (
md "%%b-%%c" 2>nul
move "%%a" "%%b-%%c" >nul
)
)
pause
If you really mean a bash script, you can use something like this:
for file in *.pdz; do
dir=${echo "$file"|cut -d- -f -2}
mkdir -p "$dir"
mv "$file" "$dir"
done
The cut command will cut out the part before the second hyphen to determine the directory name. Then we create the directory in case it is not already present. Finally simply move the file in that directory.
Update: Thanks for clarifying your environment. (I was sure the question mentioned bash before...) - If you want to use this solution you could install git which comes with a nice git-bash.
Let's say I have an 8 frame animated GIF that is 2 seconds long. I would like to build a video file (codec not important at this point) that is 30 seconds long that consists of the source GIF repeating over and over.
Is it possible to do this using only ffmpeg? Answers that use convert or some other pre-processing utility do not count [The reason being that I would like to use this on PandaStream, which does not have that utility]. Let's also assume that shell scripts are out of the question as well, though it can be multiple ffmpeg commands.
Things I have tried that did not work (though maybe I did them wrong, I'm not terribly familiar with ffmpeg):
Using the -loop_input, -loop_output options present in the ffmpeg docs. Using both ffmpeg 1.2 and 2.0, I get a Unrecognized option 'loop_[input|output]' error message. I might be using this wrong though since the error is about not recognizing the option, though the docs say it is deprecated.
-loop option. Does not seem to do anything with GIF -> Video. I think this flag and the above flag are related to generating animated GIFs as the output.
Concat. Doing something like:
ffmpeg -i "concat:image.gif|image.gif|image1.gif|image2.gif|image3.gif|image4.gif" image-long.gif
Results in a 16 frame gif (so two gifs are concatenated) which is progress, though the output gif is of much lower quality.
I'm a bit at my wits end here (I have tried many other permutations of the above concepts), I'm at the point now of 'poking it with a stick', hopefully someone out there has done this!
Is it possible? Yes.
Looking at How to concatenate (join, merge) media files, we can take the gif and transcode to mpeg streams (you could copy the first one twice):
ffmpeg -i image.gif -f mpegts image1.ts
ffmpeg -i image.gif -f mpegts image2.ts
ffmpeg -i image.gif -f mpegts image3.ts
then concatenate them, outputting as a gif
ffmpeg -i "concat:image1.ts|image2.ts|image3.ts" -pix_fmt rgb24 output.gif
Starting with an mp4 or similar seems to give better results; replace the first step with
ffmpeg -i image.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts image1.ts
and repeat for the other copies.
I create multiple copies of the same because if I try to concat: the same file multiple times (concat:image1.ts|image1.ts|image1.ts) it doesn't work.
Enjoy