So i have a folder with only mp4 files. I just want to get specific frames for every mp4 files automatically. I tried the below command, but it tried overwriting the mp4 file, is there any error with the below command? So i expect to input a mp4 file and to get 3 frames in .jpg format.
for i in *.mp4; do
ffmpeg -i *.mp4 -vf select='eq(n\,10)+eq(n\,17)+eq(n\,21)' -vsync 0 frames%d.jpg
done
I am no expert on ffmpeg but you have some fairly fundamental issues in your script. Hopefully, this will get you started:
for i in *.mp4; do
ffmpeg -i "$i" -vf select='eq(n\,10)+eq(n\,17)+eq(n\,21)' -vsync 0 "${i%.*}_frames%d.jpg"
done
Related
I have ubuntu 20.04 and in past days I did this job(merge video and audio) well in terminal and with ffmpeg:
ffmpeg -i input.mp4 -i input2.mp3 -c copy output.mp4
so fast I have recived output.mp4, but now I tried this one and get output without any sound!
I try another ways to merge this ones(also with ffmpeg) but there are no diffrent...
ffmpeg -f concat -safe 0 -i <(for f in ./input*.mp4; do echo "file '$PWD/$f'"; done) -c copy output.mp4
Note -f concat will select a demuxer. This alters the way -i nput files are read.
So instead video-files 'concat expects a txt-file listing the files to concatenate.
However we somehow omit the creation of that text file and use process substitution to generate and pass that list on the fly to demux.
For more details go here:
https://trac.ffmpeg.org/wiki/Concatenate#demuxer
If you want to merge several video files, you can use these command.
merge two video files.
ffmpeg -f concat -i 1.mp4 -1 2.mp4 -codec copy out.mp4
merge multiple video files.
ffmpeg -i 1.mp4 -i 2.mp4 -i 3.mpt -vcodec copy -acodec copy out.mp4
I have a full directory of 40-50 audio files that I am trying to "concat" into one long mp3.
I was able to do this just testing around with 2 files using the command shown below, but I need an easy way to do this with a script that I can make if I have a folder of many files with complicated file names. This is something I'm going to be doing frequently so if I had a script or something I could use quickly that would be most helpful.
ffmpeg -i a.webm -i b.webm -filter_complex "[0:a] [1:a] concat=n=2:v=0:a=1 [a]" -map [a] -c:a mp3 testfull.mp3
The simplest solution is to use the concat demuxer, but all inputs must be the same format and have the same attributes (sample rate, sample format, channel layout).
printf "file '%s'\n" *.webm > input.txt
ffmpeg -f concat -safe 0 -i input.txt -map 0:a output.mp3
-safe 0 is only needed if your input file names contain special characters.
I am trying to batch convert a folder of .mov's into .gif's.
Input .mov's are 1920x1080 resolution and I would like to convert to 720x480 (to save file size). I have the following code, but not sure how to add the -vf scale=720 into this code:
for i in *.mov; do ffmpeg -ss 1 -i "$i" "${i%.*}.gif"; done
The above code works, just running it through terminal. Any help on adding the scale or any other optimizations to reduce file size would be greatly appreciated.
Thanks
for i in *.mov; do ffmpeg -ss 1 -i "$i" -vf "fps=10,scale=720:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -loop 0 "${i%.*}.gif"; done
Combination of:
How do I convert a video to GIF using ffmpeg, with reasonable quality?
How do you convert an entire directory with ffmpeg?
I'm using ffmpeg to convert files to .mp3 and extract cover images from the metadata.
This works fine for files that have cover images, files that don't throw the error:
Output #1 does not contain any stream
ffmpeg -i kalimba.mp3 -y test.mp3 -acodec copy test.jpg
How can I tell ffmpeg to just ignore streams if they don't exist and continue converting to .mp3 if no cover image exists in the metadata?
First you should check what streams are provided in the file. You can do it with tool ffprobe. Then you run ffmpeg to copy one or two streams.
if [ -n "`ffprobe -show_streams -v quiet kalimba.mp3 | grep '^\[streams\.stream\.1\]'`" ] ; then
# the file has 2 streams
ffmpeg -i kalimba.mp3 -y test.mp3 -acodec copy test.jpg
else
# no cover image
ffmpeg -i kalimba.mp3 -y test.mp3 -acodec copy
fi
I have an array of audio and video clips, where each audio clip has a 1:1 correlation with it's video clip. The encoding of each video and each audio clip are the same. How can I concat all of the audio clips, and all the video clips, then merge them together to output a video. As of now I only figured out how to merge 1 audio clip with 1 video clip:
$ ffmpeg -i video_1.webm -i audio_1.wav -acodec copy -vcodec copy output.mkv
Update
I just came across mkvmerge would this possibly be a better option?
If all the files are encoded with the same codecs then it's easy to do. First merge the audio and video files as you have already done so each pair of files is contained in one mkv. Then you can concatenate them with the concat demuxer like this:
ffmpeg -f concat -i <(printf "file '%s'\n" ./file1.mkv ./file2.mkv ./file3.mkv) -c copy merged.mkv
or:
ffmpeg -f concat -i <(printf "file '%s'\n" ./*.mkv) -c copy merged.mkv
You could also list one file per line in a text file called mergelist.txt (or whatever you want to call it), i.e.:
file './file1.mkv'
file './file2.mkv'
file './file3.mkv'
Then use that as the input, a la:
ffmpeg -f concat -i mergelist.txt -c copy merged.mkv
This is by far the easiest and fastest way to do what you want since it won't re-encode the files, just line them up one after another.
You can find your answer here in this old question:
Concatenate two mp4 files using ffmpeg
This answer is not restricted to MP4. But it will depend on the file format you wanna concatenate!
Once you have your new VIDEO file and AUDIO file, to merge them together:
ffmpeg -i AUDIO -i VIDEO -acodec copy -vcodec copy OUTPUT