What can i use to automate video snapshots - video-processing

What command line util can i use to create a thumbnail preview of a video i made? I do not want a single thumb that windows make, i want a large jpg file that has 30 or less shots so i can preview the movie w/o running it.
I either need an app that can do a batch at once or a command line util so i can loop through a folder or w/e i need and feed it to the util. I was thinking of hacking up ffplay to do this, i dont know what i am getting myself into so is that recommended? (i used SDL many times, never its YUV settings nor with ffmpeg)

You can use ffmpeg to perform frame extraction, here's how I've done something similar
ffmpeg -i my_input_video.flv -y -an -sameq -f image2 -r 1 my_frame_%05d.jpg
-i my_input_video.flv specifies the input file
-y overwrite output files
-an disables audio (we're transcoding a video to a series of jpegs, we don't need audio)
-sameq - use same quality as source
-f image2 sets the output format to image2 (an image sequence)
The -r parameter is the frames per second, so the above command will produce one jpeg per second.
Once you have your collection of jpegs, you can use ImageMagick montage command to build a montage image.

You could use MTN. It can scan whole directories and create thumbnails for every video found.

Use mplayer:
mplayer -vo jpeg -frames 1 your_file
Will extract the first frame.

Media Player Classic can make a collection (it's called save as thumbnail; with matrix i.e. 4x4), but only from a single file.

Potplayer can automatically generate the thumbnails for a batch of videos in folders or even in subfolders. It just takes a few clicks.
Add all the videos you want to get thumbnails from to the playlist (You can do this by go to menu "Open-Open Folder...")
Select all the videos in playlist and right click on them.
Select "Create Thumbnail Image(s)..." in pop-up menu.
Custom the output folder, number of Thumbnails, image size and other setting.
Click "OK".

Related

MLT melt slideshow on Windows: unable to control output video length and problems with using wildcards

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.

How to perform Batch processing to Merge channels

I have two separate folders with equal number of images from microscopy (134 images in each folder). These are two different dyes for a specific cells. What i want to do is merging each image from one folder with its corresponding image from another folder i.e. first image of the folder a with first image of folder b and so on.
i have been trying to do this work, but since each image has a different name, i can not finish this job successfully by Batch processing. Can anyone help?
Thnkas
I need to merge channels from the two images on the left to get the image on the right by using ImageJ --> Image --> Color --> Merge channels
Using C1 (red) and C3 (blue) in the settings.
[1]: https://i.stack.imgur.com/OUKkg.jpg
As you didn't raise any objection to my suggestion of using ImageMagick, I will show you how to do it using that.
As you didn't provide any images, let's assume you have two directories called A and B with PNG files in A that you want to use as the red channel and PNG files in B that you want to use as the blue channel. I'll assume you want a zero/blank green channel.
./A/image1.png
./A/image2.png
./B/image1.png
./B/image2.png
Now, go into A and the basic command for one file is:
cd A
magick image1.png ( +clone -fx 0 ) ../B/image1.png -combine result.png
That says... "load image1.png, make a copy of it and fill the copy with zeroes, load ../B/image1.png and combine them assuming the first is red, the second is green and the third is blue, and save them as result.png".
Hopefully you can get that working. If it does what you want, we can work on a batch version. I don't use Windows, so I would write this on Linux:
#!/bin/bash
for f in *png ; do
echo "Combining $f (as Red), zero (as Green) and ../B/$f (as Blue) to make res-$f"
magick $f \( +clone -fx 0 \) ../B/$f -combine res-$f
done
I know a dangerously small amount of Windows BATCH script, so I'll do my best to guess how it will look. Save it as GO.BAT:
FOR %%G IN (*.png) DO (
ECHO %%G
magick %%G ( +clone -fx 0 ) ../B/%%G -combine res-%%G
)
If I load your "image" into Photoshop and cut out the salient parts and trim the 112 pixels off the second image to make it the same size as the first and then reverse the order and combine them using the commands suggested, I get:

Automating multiple imagemagick commands

I have hundreds of PDFs containing powerpoint handouts (with 6 (2x3) slides on each page) that I want to convert to single slide per page PDF (or PPT, ultimate goal is importing to OneNote properly).
So far I have succeeded in finding the correct commands to create single, nicely cropped JPEG files for each slide:
C:\"Program Files"\ImageMagick-6.8.9-Q16\convert.exe -density 300 C:\Users\matt\Desktop\cmd\5.pdf -gravity Center -crop 80%x+0+0 -quality 100 -sharpen 0x1.0 C:\Users\matt\Desktop\cmd\output.jpg
This split up the PDF pages and crops away page numbers for easier trimming later.
C:\"Program Files"\ImageMagick-6.8.9-Q16\convert.exe -crop 2x3# C:\Users\matt\Desktop\cmd\output-0.jpg C:\Users\matt\Desktop\cmd\output-0%d.jpg
This divides slides up from one page.
C:\"Program Files"\ImageMagick-6.8.9-Q16\convert.exe -trim C:\Users\matt\Desktop\cmd\output-00.jpg C:\Users\matt\Desktop\cmd\output-00%d.jpg
This trims the borders of each slide.
How would I automate all this into a drag and drop script so I can quickly convert a PDF into a collection of JPEGs or from there a full PDF?
After tons of reading I figured it out. I wrote a .bat (batch?) first setting the working directory as the location the .bat was located in. Then I did all the imagemagick operations with proper use of leading zeros to get the right order (if you use *.jpg it will go through 1.jpg, 11.jpg, THEN 2.jpg). The operations basically took any .pdf in the folder and turned it in JPGs, manipulated them as I needed, then when finally in proper order, made a single PDF.
Simple in theory, tricky in practice.

Using only ffmpeg, is it possible to consume a source GIF image and output a video that is a set length > one loop through the input GIF?

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

Adding subtitle from command line MP4Box

I am adding a subtitle file to a video using MP4Box. The following command works perfectly from the command line:
c:/GPAC/MP4Box -add c:/test.m4v#audio -add c:/test.m4v#video -add c:/test_en.srt:hdlr=sbtl:lang=en:group=2:layer=-1 -new c:/test2.m4v
However, what I really want to do is to put the command into a .bat file. The following is my command in the batch file:
%1/GPAC/MP4Box -add %2/%3#audio -add %2/%3#video %4 -new %2/%3
As you can see I am trying to pass in "-add c:/test.m4v#video -add c:/test_en.srt:hdlr=sbtl:lang=en:group=2:layer=-1" as the fourth parameter. The reason I want to do this is there may be many subtitles files being added:
"-add c:/test.m4v#video -add c:/test_en.srt:hdlr=sbtl:lang=en:group=2:layer=-1 -add c:/test.m4v#video -add c:/test_ja.srt:hdlr=sbtl:lang=ja:group=2:layer=-1:disabled"
so I don't know ahead of time how many -add commands there need to be so I want to just pass them all in as one parameter. But, mp4box doesn't like this.
I'm not sure if this is a limitation with mp4box or with batch file parameters in general.
I know this is an old thread, but for anyone searching in future.
I used the following approach in a batch file, combined with filemenu tools to allow for a simple right-click menu function to initiate the batch process:
for %%a in (*.m4v) do mp4box -add "%%~Na.eng.srt":lang=eng:layout=0x60x0x-1:group=2:hdlr="sbtl:tx3g" "%%a"
I ended up solving this by writing/rewriting the batch file from code every time I needed to run it. So I would create the batch file with all my arguments. Run it. Then delete the file. This worked great.
Batch files on Windows are quirky and have limited functionality. What you could do is use Cygwin, which allows you to use a real shell (like Bash for example) on Windows.
A note regarding MP4Box syntax,since both the question and the answers here have it... "suboptimally", let's just say.
If you want MP4Box to rewrite an input file — which is its default mode, unless told otherwise — while adding subtitles (or any other tracks/metadata), you should specify the file to be modified first on the command line, and without using -add. So, to rewrite a video file my_video.mp4 with subtitled added from my_video_English.srt and my_video_German.srt, you'd use:
MP4Box my_video.mp4 \
-add my_video_English.srt \
-add my_video_German.srt
No need to specify tracks, since you want to use all available tracks from all input files. (Here also, that's the default disposition for track data.)
MP4Box will create a new temporary output file, copy the contents of my_video.mp4 into it, remuxing the original tracks with new tracks created for each subtitle file, and then rename the temporary file back to my_video.mp4, overwriting the original. (If you don't want to overwrite, add -out newname.mp4 to the end of the command line.)
The program help (specifically, MP4Box -h import) especially warns against adding subtitle tracks to the output stream before any video tracks are created, so -add foo.srt should never be before the a/v input file on the command line:
$ MP4Box -h import
[...]
Note: When importing SRT or SUB files, MP4Box will choose
default layout options to make the subtitle appear at the
bottom of the video. You SHOULD NOT import such files before
any video track is added to the destination file, otherwise
the results will likely not be useful (default SRT/SUB
importing uses default serif font, fontSize 18 and display
size 400x60). For more details, check TTXT doc.
It's possible this wouldn't affect file rewriting (because, the video track is already in the output stream before it even begins), but it definirely would affect use of -out. In general, placing the input a/v content first in the arguments is just a good habit to get into when using MP4Box.

Resources