I have a folder filled with songs. I would like to make ONE mp3 file containing a mashup of 10 seconds of each song.
I have found that FFMPEG is an easy software to do so.
I found how to cut a single file : ffmpeg -ss 0 -t 10 -i file.mp3 file.wav
And how to write a loop for multiple steps : for i in *.mp3; do ...
But I am not sure how to mix the two into only 1 file. If it's not possible, I guess I can also make a separate 10 sec file for each and then regroup.
In Windows
Step 1 : Go into the folder with the songs
Step 2 : Paste the following line
FOR /F "tokens=*" %G IN ('dir /b *.mp3') DO ffmpeg -ss 15 -t 10 -i "%G" -acodec mp3 "%~nG_10s.mp3"
Step 3 : Put the 10s songs into another folder (or modify the regex) and paste
copy /b *.mp3 E:\combined.mp3
You can avoid the intermediate files by using ffmpeg's concat demuxer
#1 Create the concat text file
FOR /F "tokens=*" %G IN ('dir /b *.mp3') DO (echo file '%G' >> list.txt & echo inpoint X >> list.txt & echo outpoint Y >> list.txt)
X and Y are the start and end times, in seconds.
#2 Combine the selected portions
ffmpeg -f concat -i list.txt -c copy -vn out.mp3
Related
I use this bat script for converting .mp4(x264) files to .mp4(x265)
for %% in ("*.mp4") do ffmpeg -i "%%a" -c:v hevc "%dp0NewFolder\%%~na[HEVC].mp4"
So I'm trying to make another bat script for merging video files(concat).
for %%i in (*.mp4) do echo file '%%i'>> vlist.txt
ffmpeg -f concat -safe 0 -i vlist.txt -c copy %~dp0NewFolder\%%~na.mp4
Files to merge would be like
Vid_1.mp4,
Vid_2.mp4,
Vid_#.mp4
...
I want to keep the part before "_" in the new file name
What should I use instead of %%~na? To make it just Vid.mp4
Currently it creates %~na.mp4
From what I got you don't need a big scheme to create a output filename since we are talking about 1 filename only, or did I get something wrong?
for /f "delims=_" %%a in ('dir /b /a-d *.mp4') do set "NewVideoName=%%a"& goto :Next
:Next
ffmpeg -f concat -safe 0 -i vlist.txt -c copy "NewFolder\%NewVideoName%.mp4"
I have files in two folders like this
Video
record01.mkv
record02.mkv
Audio
audio1.avi
audio2.avi
Merged
I would like to run a loop to combine the files in the folders with one-to-one correspondence based on alphabetical order (es. first file in "Video" folder combines with first file in "Audio" folder and so on)
The command I need to use is simple:
ffmpeg -i "record01.mkv" -i "audio1.avi" -map 0 -map 1 -map -1:v -c copy ".\Merged\record01.mkv"
I tried with the following command but it didn't work (as I expected since files in the two different folders have different names)
FOR /R %%i IN (*.mp4) DO ffmpeg -i ".\Video\%%i" -i ".\Audio\%%i" -map 0 -map 1 -map -1:v -c copy ".\Merged\%%~dni.mkv"
Thank you!
There is a trick to read two files in parallel (or one file and one command output): use a for loop for one input-stream and redirection plus set /p for the other (this one has to be a file):
#echo off
setlocal enabledelayedexpansion
dir /b /s /on audio\*.avi > audioFiles
< audioFiles (for /f %%a in ('dir /on /b /s video\*.mkv') do (
set /p "audio="
echo %%a, !audio!
))
I trust you are able to implement the ffmpeg command yourself.
I've embarked on a mission to get rid of all of my MKV files since the MP4 container works better for me. So to that end, I did some research and wrote a small script that searches my data files for MKVs and stream copies them to MP4. The script works most of the time, but I get the occasional file that fails and since the script deletes the originals, I lose the file completely.
I'd like to modify the script in two ways:
(1) Before deleting the original file, check that the converted file is greater than zero.
(2) If the converted file is zero (failed) then run an FFMPEG command to re-encode the original file using default values utilizing Intel Quick Sync hardware encoding, then delete the original as usual and go on to the next file in the list.
Here's what I have so far...
#ECHO OFF
cls
echo This script automatically converts MKV video files to MP4.
echo.
echo Changing directory to data drive (Z:).
echo.
Z:
echo Retrieving list of MKV files...
echo.
dir /b /s *.mkv > MKV-Files.txt
echo MKV list compiled.
echo.
echo Converting files to MP4...
echo.
FOR /F "delims=;" %%F in (MKV-Files.txt) DO (
echo Converting "%%F"
echo.
C:\FFMPEG\bin\ffmpeg.exe -y -i "%%F" -movflags faststart -codec copy "%%~dF% %~pF%%~nF.mp4"
echo.
echo Conversion successful.
echo.
echo Deleting "%%F"
echo.
del "%%F" /F
)
echo Job completed.
echo.
echo Exiting...
Thanks in advance for your ideas.
You can try this substitution:
ffmpeg.exe -y -i "%%F" -abort_on empty_output -movflags faststart -codec copy "%%~dF% %~pF%%~nF.mp4" || ffmpeg.exe -y -i "%%F" -movflags faststart -c:v h264_qsv -c:a copy "%%~dF% %~pF%%~nF.mp4"
You may want to disable subtitle or data tracks as MP4 has limited support for them. Add -dn and -sn for that.
I would like to concatenate 3 mp4 videos into one avi video for every folder of a directory, with FFMPEG on Windows 7.
I have started this way:
ffmpeg -f concat -i mylist.txt -c copy E:\EA2014\EX14R\EX14R.avi
with mylist.txt being:
file 'E:\EA2014\EX14R\DCIM\100GOPRO\GOPR0001.MP4'
file 'E:\EA2014\EX14R\DCIM\100GOPRO\GP010001.MP4'
file 'E:\EA2014\EX14R\DCIM\100GOPRO\GP020001.MP4'
This works fine. Now, I would like to automate it because I have lots of those folders full of videos to merge.
I tried with this to start with:
printf "file '$s'\n" .E\EA2014\EX14R\DCIM\100GOPRO\*.MP4 >> mylist.txt
But it tells me that
"printf is not recognized as an internal or external command, operable program or batch file"
Is it because I work in Windows? Anyone could help me achieve it in another way?
Needless to say that I am a newbie!
Thanks!
This should process each folder under the E:\EA2014\EX14R tree and create the .avi file in each individual folder, calling it myfile.avi
#echo off
for /d /r "E:\EA2014\EX14R" %%a in (*) do (
if exist "%%a\*.mp4" (
del mylist.txt 2>nul
for %%b in ("%%a\*.mp4") do >>mylist.txt echo file '%%b'
ffmpeg -f concat -i mylist.txt -c copy "%%a\myfile.avi"
del mylist.txt 2>nul
)
)
#echo off
setlocal enabledelayedexpansion
set EXE_FILE=E:\ffmpeg.exe
set INPUT_PATH=C:\folder\
set OUTPUT_PATH=C:\Images\
set COUNT=0
for %%F in (*) do %EXE_FILE% -i %INPUT_PATH% %OUTPUT_PATH%/%%F.jpg
popd
I want to save 1 sec videos to jpg images with this code. This doesnt work. Any solutions?
INPUT_PATH should be a video file, rather than a directory. You need to iterate through the input videos instead of iterating through the output images. ffmpeg will output all the images by itself (without you iterating through them, ie with a single command). Look at this guide for help. Here is an example from that guide:
ffmpeg -i video.mpg -r 1 -f image2 ffmpeg_temp/%05d.png
So what you're really doing in your script is you are making the number of digits in the name of the output images more and more.
%05.png will make image file names look like "00001.png", and %03.png will look like "001.png", etc.
But what you want is to go through the input files, so iterate through for example "video1.mp4", "video2.mp4", etc.
IF EXIST %~d1%~p1%~n1.jpg GOTO exit
setlocal enabledelayedexpansion
set EXE_FILE=E:\ffmpeg.exe
set OUTPUT_PATH=E:\Glasgow\Test
set COUNT=0
for %%F in (*.avi) do %EXE_FILE% -i %~d1%~p1%~n1.avi -r 1 -vframes 1 -ss 00:00:01 -f image2 -y %~d1%~p1%~n1.jpeg
popd