Batch file to use FFMPEG to generate single "PIP" video from Front/Read

First time user. Trying to merge Front and Rear of one section of video, and then combine that with just front of next 2 sections. I have the 900s, so since you asked about that, here is the Blackvue viewer...

1548724309282.png

And here is the setting of 3.0

1548724384211.png

vs. 2.0...

1548724425956.png

vs. 1.5...

1548724458178.png

A setting a little higher than 1.5 seems to be closest to the default viewer, but I was happy enough with 1.5
 
A setting a little higher than 1.5 seems to be closest to the default viewer, but I was happy enough with 1.5
Thanks for that. I added that note to the comment in the .cmd file for the next release if there is one.
 
Hello,

I finally able to understand and utilized your code.

However after joining the videos i still see the repeat footage from blackvue. For some reason I counted and my camera it re-record for at least 5 second from the previous videos

Is there anyway I could increase the cutting time?

Thank you so much
 
Hello,

I finally able to understand and utilized your code.

However after joining the videos i still see the repeat footage from blackvue. For some reason I counted and my camera it re-record for at least 5 second from the previous videos

Is there anyway I could increase the cutting time?

Thank you so much
Easiest way is to add an extra step to cut the first few seconds off all the files before you perform the join step so that there is no duplicate video, can be done quickly and without recompressing.

This line removes the first 3 seconds of every .mp4 file in the current folder and puts the cut down copy in the parent folder:
(for %%i in (*.MP4) do @ffmpeg -ss 00:03 -i %%i -safe 0 -c copy -y ..\%%i)

or trim the end of the files so that they are all 3 minutes long instead of 3 minutes and 3 seconds, then you loose the last 3 seconds recorded instead of the first 3, depending on the camera it is more likely to work without needing recompression:
(for %%i in (*.MP4) do @ffmpeg -t 03:00 -i %%i -safe 0 -c copy -y ..\%%i)

or use a camera that doesn't waste card space by recording duplicate video! Most of the good cameras don't have any overlap.

Obviously you will need to modify your join file to use the new cut down files, not the originals.
 
Last edited:
Coincidentally I was playing with the batch files just this weekend, because I noticed a bit of a problem when you use time-lapse for parking mode (no audio) and then merge with normal/event files. I found that if the *first* video in the sequence was parking, then ffmpeg will decide to omit the audio for the entire thing. But if the first video had sound, then you were okay.
I ended up with this:
Code:
ffmpeg -hide_banner -nostats -v fatal -probesize 4294M -analyzeduration 4294M -f concat -safe 0 -i "%folder%\tslist.txt" -c copy -bsf:a aac_adtstoasc "%folder%\%range%.mp4"
Adding the probesize & anaylzeduration didn't negatively effect the time spent doing the concat, but told it to look far ahead to determine the correct encodings.

Nigel's suggestion above may help with the trimming, but you likely want to not do that with Parking Mode files, especially if using time-lapse, because the file lengths may not be consistent (the last one before switching to Normal may not be an even minute length).

What I'm finding with my 750S is that the Normal/Event files show a length of exactly 1 minute (not 1 minute + 3 seconds) (or 3 minutes + 3 seconds for lower-res), So you'd want to trim to 0:57 or 2:57. I haven't tried that yet.

Another thing I see is that when I PIP the Front & Rear, sometimes the timing gets out of sync by a couple of seconds (watch the clock displays). But not always, which is curious. I need to play with that a bit too.

Definitely there are enough minor variations in the files grabbed from the camera that this is never going to be an exact science. I'm coming to the conclusion that some "glitches" may be unavoidable.
 
Nigel's suggestion above may help with the trimming, but you likely want to not do that with Parking Mode files, especially if using time-lapse, because the file lengths may not be consistent (the last one before switching to Normal may not be an even minute length).
I would assume that taking it off the beginning would normally work, although I don't have a Blackvue camera. I used my suggestion with a Blueskysea camera where it worked perfectly, but then I asked Blueskysea to remove the overlap, which they did, so now there is no issue, same with Viofo cameras :)
 
I am trying to understand the batch file. My filename format is REC_2019_05_31_11_41_51_F.MP4 using underscores for every element from a Thinkware camera. Where can I adjust the filename format to find the files.

C:\Apps\ffmpeg\bin>pip C:\Apps\ffmpeg\bin\cont_rec\REC_2019_05_31_11_41_51_F.MP4
Not finding "C:\Apps\ffmpeg\bin\cont_rec\REC_2019_05_31_F.mp4"

Stephen
 
The batch was written specifically for Blackvue files, which omit the underscores. Does your camera naming just use an _R for Rear cameras? If so, you may have some luck tweaking the line near the top "set filename=%input:~0,15%, which basically means to take the substring of the name starting at character zero, and 15 characters from that. So for a Blackvue file named 20190531_001423_PF.mp4, it'd end up with "20190531_001423".
In your case, "%input:0,23%" might yield the desired results. Then from there you'll need to tweak the lines below where if looks for %filename%_NF to just %filename%_F. There may also be other tweaking required, but hopefully this'll get you on track.

Brad.
 
Thanks for quick reply, After I sent I did that for the 0,23 and that worked :) Thanks for the other info...

My wife is from St John's :)
 
First off Big Thanks to Brad for putting this together and all of other folks adding bits of wisdom. Secondly, I'm trying to add Nigel's code noted in quotes to remove five seconds of overlap between the clips. I'm also open to running this in a separate script/command for the selected files (I cannot seem to figure this out despite there being so much documented online). I'm totally new to this so I simply added the blow line as follows:

or trim the end of the files so that they are all 3 minutes long instead of 3 minutes and 3 seconds, then you loose the last 3 seconds recorded instead of the first 3, depending on the camera it is more likely to work without needing recompression:
(for %%i in (*.MP4) do @ffmpeg -t 03:00 -i %%i -safe 0 -c copy -y ..\%%i)

(I added where directly before the PIP statement.)
Code:
(for %%i in (*.MP4) do @ffmpeg -t 00:55 -i %%i -safe 0 -c copy -y ..\%%i)
echo ...Performing PIP combining of Front/Rear
FOR /f "usebackq" %%G in ("%folder%\vidlist.txt") DO (
    CALL PIP.cmd %folder%\%%G
)
if ERRORLEVEL 1 pause
 
To answer my own question above - do not insert Nigel's line into Brad's code. Run a batch file prior using Nigel's code prior to running brad's cmd file. Here is a youtube video that describes the first step:
 
To answer my own question above
I was going to answer your question, but I couldn't see a question mark?
Also you didn't give much info on what was going wrong.
I'm guessing the batch file couldn't find ffmpeg.exe since you didn't give the path to it.
 
Back
Top