-1

I'm trying to concatenate multiple video files. They all use the same codec and frame rate. Anyway concatenation isn't a problem. I've done it before.

The problem is to automate it?

The answer here shows method 2 to be used in windows to concatenate files. It's really easy:

(echo file 'first file.mp4' & echo file 'second file.mp4' )>list.txt
ffmpeg -safe 0 -f concat -i list.txt -c copy output.mp4

First, we make a list of video files (by manually tying them out). Second, we execute.

The problem is that I have multiple video files located in a single directory. The video files are named similar to this:

\450_01_videoName.mp4
\450_02_videoNameFoo.mp4
\450_04_videoNameMoo.mp4
\451_01_videoNameRoo.mp4
\451_02_videoNameHoo.mp4

Now look at the above list and imagine that it's 200 lines big in a single folder. I'm trying to concatenate video 450 into 1, then video 451 into 1 file, etc.

I'm trying to automate this process with a good thousand video files.

I can do it semi manually. Use cmd to create a list of file and folder path. But then I would manually, file by file, have to copy and paste it to create that list.txt.

Is there a way to automate this? I've done this manually with 20 video files and it was painful (but better then using a stand alone software, as all the videos were done in a batch after all was set up).

Cheers.

I've done the process semi manually. It worked, but took more time that it needs to take.

------UPDATE

This is how I tackled the problem. It was slow and painful.

Firslty, I used cmd "dir /b > file.txt" to extract all the names of video files in that directory.

Then I painfully wrote the BAT file manually (for videos up to 500) for each video I wanted to merge. I used a few notepad++ shortcuts, for example, replacing the number '45' with 'echo file 45', this ensured I didn't need to type 'echo file' manually for every line. Then I also copy-pasted manually for every line '>>list.txt'. I painfully had to write out the output file name 50 different times.

h:
cd "h:\video directory"
echo file 450_01_video.mp4 > list.txt
echo file 450_02_videoMoo.mp4 >> list.txt
echo file 450_03_videoFoo.mp4 >> list.txt
echo file 450_04_videoLoo.mp4 >> list.txt
ffmpeg -safe 0 -f concat -i list.txt -c copy 450Video.mp4
echo file 451_01_video.mp4 > list.txt
echo file 451_02_videoMoo.mp4 >> list.txt
ffmpeg -safe 0 -f concat -i list.txt -c copy 451Video.mp4

Now imagine a line for every single video file that I had to do manually.

There has to be a simple for loop solution.

ANSWER - SOLVED

I've used Armali's solution.

h:
cd "h:\video directory"

SETLOCAL ENABLEDELAYEDEXPANSION
set number=999
for %%f in (???_*.mp4) do (
    set name=%%f
    set before=!number!
    set number=!name:~0,3!
    if !number! gtr !before! call :concat
    echo file !name! >>list.txt
)

:concat
    ffmpeg -safe 0 -f concat -i list.txt -c copy %before%Video.mp4
    del list.txt

The output video files were named 412Video.mp4. I used the dir /b file.txt command to extract the list of original files. I then copied them into excel, delimited them and used the tricks to extract the number, name, and remove duplicates etc. I then combined each record with output video as a ren command. E.g. ren 412video.mp4 412.name.location.mp4. I copied that into cmd for a fast rename.

1 Answers1

0

There has to be a simple for loop solution.

leading number have three digits

You were right, it's indeed not too complicated with a for loop and some sideshow around it:

h:
cd "h:\video directory"

SETLOCAL ENABLEDELAYEDEXPANSION
set number=999
for %%f in (???_*.mp4) do (
    set name=%%f
    set before=!number!
    set number=!name:~0,3!
    if !number! gtr !before! call :concat
    echo file !name! >>list.txt
)

:concat
    ffmpeg -safe 0 -f concat -i list.txt -c copy %before%Video.mp4
    del list.txt
Armali
  • 18,255
  • 14
  • 57
  • 171
  • 1
    I was already using excel tricks, deleting duplicates, merge cells, copying back, insert a new line. Was such a screw-around! – bunnyisblack Apr 05 '23 at 13:20