I am working on a script that searches for all media files in the current directory and subdirectories and then batch encodes them to H.265. I was hoping to put in some max frame sizes to make things that are 1080p to be 720p. That is the straightforward part but I have some that are 480p and I don't want those to end up as 720p. How can I modify my ffmpeg filters to take that into account?
The command:
ffmpeg -i input -c:v hevc_nvenc -preset medium -crf 28 -c:a copy output.mp4
Use:
-vf "scale=-2:min'(720,ih)'"
or
-vf "scale=min'(1280,iw)':-2"
See :
FFmpeg Arithmetic Expression for a list of accepted functions
FFmpeg Filters: Scale for more info on the scale filter
Related
I have 30 clips which are different in aspect ratio(like some videos are 10801920(they are vertical) and some are 1280720(horizontal aspect ratio videos). I want to merge all of them but also have a static background image that is of 1920x1080 aspect ratio. The video would be such that all the clips are concatenated but they have a background image(just like those tiktok compilation videos on youtube). Can someone please help me with this program?
Example using 3 videos. It can easily be expanded to 30 videos. I broke the command into multiple lines so you can see the syntax better. Make it one line before executing.
ffmpeg -i 1.mp4 -i 2.mp4 -i 3.mp4 -i image.png -filter_complex
"[0:v]scale=1280:720:force_original_aspect_ratio=increase,crop=1280:720,setsar=1,fps=25,format=yuv420p[v0];
[1:v]scale=1280:720:force_original_aspect_ratio=increase,crop=1280:720,setsar=1,fps=25,format=yuv420p[v1];
[2:v]scale=1280:720:force_original_aspect_ratio=increase,crop=1280:720,setsar=1,fps=25,format=yuv420p[v2];
[0:a]aformat=sample_rates=44100:channel_layouts=stereo[a0];
[1:a]aformat=sample_rates=44100:channel_layouts=stereo[a1];
[2:a]aformat=sample_rates=44100:channel_layouts=stereo[a2];
[v0][a0][v1][a1][v2][a2]concat=n=3:v=1:a=1[vid][a];
[3][vid]overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2[v]"
-map "[v]" -map "[a]" -c:v libx264 -c:a aac -movflags +faststart output.mp4
References:
How to concatenate videos in ffmpeg with different attributes?
How to center overlay in ffmpeg?
Resizing videos with ffmpeg to fit specific size
Anyone knows the fastest way to add image into video at first 20 seconds?
I have tried it, but it seemed like FFMPEG re-encoded the whole video even after 20 seconds which took a long time..
here my code:
ffmpeg -i input.mp4 -i logo.png -filter_complex "overlay=5:5:enable='between(t,0,20)'" output.mp4
Fast
Use a faster -preset and stream copy (re-mux) the audio instead of re-encoding it:
ffmpeg -i input.mp4 -i logo.png -filter_complex "overlay=5:5:enable='between(t,0,20)'" -preset fast -c:a copy output.mp4
Faster
You could encode the ~20 segment conforming to the same parameters as the main input, then concatenate with the concat demuxer in stream copy mode. However, this will be troublesome because conforming parameters is not trivial for most users, the concat inpoint directive is not guaranteed to seek accurately with non-intra inputs, and you could end up with timestamp issues anyway.
Fastest
The most fastest way is to use a player to overlay the logo:
mpv --lavfi-complex="[vid1][vid2]overlay=5:5:enable='between(t,0,20)[vo]" video.mp4 --external-file=image.png
I know how to combine a single image with an mp3 to create a video like this
"ffmpeg.exe" -loglevel 0 -loop 1 -i c:\path\foo.jpg -i c:\path\foo.mp3 -c:v libx264 -pix_fmt yuv420p -crf 0 -c:a copy -shortest c:\path\foo.mkv
How can I make ffmpeg create a video using multiple images that it cycles through at regular intervals, or even randomly? Basically I want to use more than one image in a video rather than just 1.
You can use the examples from the wiki to create a slideshow from images.
For example:
ffmpeg -framerate 1/3 -pattern_type glob -i '*.jpg' -c:v libx264 out.mp4
Keep in mind that all images must have the same size!
In my test the resulting mp4 file was approximately the same size as the sum of the input files;
> du out.mp4
768 out.mp4
> du -c *.jpg|grep total
648 total
Note that photos from a digital camera are generally a lot bigger than even a HD movie, so you might want to scale the images.
This can be done using the scale filter, or with an external program like ImageMagick. In my example I scaled the images before making a movie out of them.
I have a huge MP4 file (4GB) an hour long video. I want to extract port of the file. So I used the following command to extract 70 seconds(00:01:10) of video starting from 11 minutes
ffmpeg -i INPUT.mp4 -ss 00:11:00 -t 00:01:10 -c:v copy -c:a copy OUTPUT.mp4
Now I got a small file extracted from Input.MP4
The output.mp4 file size is still big(90 MB). So I used the following command
ffmpeg -i OUTPUT.mp4 -c:v libx264 -crf 30 SmallSizeVideo.avi
I got SmallSizeVideo.avi file which is approximately 6MB.
I am using Powerpoint 2010. I want to insert the video in Powerpoint and play.
Unfortunately when I embed SmallSizeVideo.avi Powerpoint is unable to play
1) Is my approach correct?
2) What is the best way to situation like me to play small portion of clips in powerpoint
Thank you
Last I heard, h.264 in avi was nonstandard. Try instead to output as mp4 and see if that plays in PowerPoint:
ffmpeg -i OUTPUT.mp4 -c:v libx264 -crf 30 SmallSizeVideo.mp4
If it works, I believe it may work in Windows 7 or later and also OS X.
I had the same issue and had to stay for PowerPoint 2010 at Windows 10. Thus, PowerPoint is unable to play MP4, cf. https://support.office.com/en-gb/article/Video-and-audio-file-formats-supported-in-PowerPoint-d8b12450-26db-4c7b-a5c1-593d3418fb59. Finally, I come up with this command:
ffmpeg.exe -i input.mp4 -c:v wmv2 -b:v 12024k -c:a wmav2 -b:a 128k output.wmv
This command based on https://stackoverflow.com/a/34851916/2258393 by Reinhard Behrens.
By means of this command, I am able to archive the same file size and approx. the same quality as with MP4.
How to convert image and music to video? I would like YouTube video. I like FFMPEG command or other Ubuntu free software. I would like: *.mp3 + *.jpg = *.flv
Here is an example using a recent ffmpeg syntax:
ffmpeg -loop 1 -i image.jpg -i music.mp3 -shortest -c:v libx264 -crf 20 -tune stillimage -c:a copy output.mkv
This example will copy the audio instead of re-encoding to preserve quality. Adjust quality if desired with the CRF option. See the FFmpeg and x264 Encoding Guide for more information.
Super User (another StackExchange site) is a better place for ffmpeg usage questions since Stack Overflow is programming specific.
Today I was in need of merging an image and an audio file into a video file. Since none of the answers that I found on SO worked for me, I'm leaving here what worked for me after trial and error:
ffmpeg -loop 1 -t 205 -i audio.mp3 -i image.jpg -crf 20 test.flv
Where 205 is the duration of the input mp3 file in seconds -> 3:25 minutes.
(Tested with FFmpeg SVN-r13582)