Avidemux Forum

Avidemux => Main version 2.6 => Topic started by: sark on April 03, 2019, 09:43:34 AM

Title: Simple batch convert with .bat file.
Post by: sark on April 03, 2019, 09:43:34 AM
Hi all.

I'm trying to batch convert .m2ts files to .mp4, but I can't get the .bat script below to set the container to .mp4. At the moment although it adds an .mp4 extension, avidemux leaves the container to the default .mkv during processing and the files remain m2ts. They do display as .mp4, but a mediainfo check confirms they're matroska .mkv files.
Anyone know how I set the container to .mp4.

Cheers

sark

set avidemux="C:\Program Files\Avidemux 2.7\avidemux.exe"
set videocodec=Copy
set audiocodec=Copy
for %%f in (*.m2ts) do %avidemux% --video-codec %videocodec% --audio-codec %audiocodec% --force-alt-h264 --load "%%f" --save "%%f.mp4" --quit
Title: Re: Simple batch convert with .bat file.
Post by: eumagga0x2a on April 03, 2019, 11:28:07 AM
--output-format MP4

is missing in the command line.
Title: Re: Simple batch convert with .bat file.
Post by: dosdan on April 03, 2019, 07:57:23 PM
I'd do this in FFMPEG, not ADM. What is the audio stream inside the m2ts container?

Dan.
Title: Re: Simple batch convert with .bat file.
Post by: dosdan on April 03, 2019, 08:13:19 PM
Here's a batchfile I wrote some time ago to batch convert M2TS/MTS AVCHD files from my camcorder to MP4s. 

These AVCHD files contain AC-3 audio streams. These are incompatible with the MP4 container, so the audio stream is converted to AAC.   I also use touch.exe (https://www.binarez.com/touch_dot_exe/) to set the date/time on the new MP4 to be the same as the original M2TS/MTS.

You place the shortcut icon for this batchfile on your Windows desktop and then drag-and-drag one or more MTS/M2TS files onto it. It creates a "converted" subdirectory, if it doesn't already exist, beneath the location of the file(s) you wish to be converted. If FFMPEG.EXE and TOUCH.EXE are not situated in a directory mentioned in your Path list, specify their full pathname in the batchfile e.g. c:\utils\ffmpeg.exe


Convert_MTS_to_MP4.bat
@echo off

cls
set filename=""

:FILES_LOOP
for %%F in (%1) do (
set filename=%%F 
echo Converting    %%F    to    %%~dpFconverted\%%~nF.mp4
if not exist "%%~dpFconverted\" md "%%~dpFconverted\"
ffmpeg.exe -i %%F -c:v copy -c:a aac -y -hide_banner -loglevel error -map_metadata 0 "%%~dpFconverted\%%~nF.mp4"
if errorlevel 1 goto ERROR_OCCURRED
rem Next line sets the MP4's file date/time to the same as the original MP4 file.
touch -r "%%~fF" "%%~dpFconverted\%%~nF.mp4"
rem Next line shows the MP4 after it has been created, so with multiple MP4s it acts as a sort of progress indicator.
dir "%%~dpFconverted\%%~nF.mp4" | find "/"
rem Remove REM from the start of the next line if you wish to delete the original file if no error occurred in the conversion.
rem del %%F
echo.
shift
)
if not "%1"=="" goto FILES_LOOP
goto FINISHED

:ERROR_OCCURRED
echo.
echo An error occurred when trying to process %filename%
echo Aborting...

:FINISHED
echo.
echo.
pause


Dan.
Title: Re: Simple batch convert with .bat file.
Post by: sark on April 04, 2019, 10:18:20 AM
Quote from: eumagga0x2a on April 03, 2019, 11:28:07 AM
--output-format MP4

is missing in the command line.

Does that go in the last line. (before --save "%%f.mp4)? Will give it a go tonight.

Cheers.

Quote from: dosdan on April 03, 2019, 07:57:23 PM
I'd so this in FFMPEG, not ADM. What is the audio stream inside the m2ts container?

Dan.

H264... Avidemux should just change the container, though I will need it to convert from AC3 to AAC, but that shouldn't be an issue.

Quote from: dosdan on April 03, 2019, 08:13:19 PM
Here's a batchfile I wrote some time ago to batch convert M2TS/MTS AVCHD files from my camcorder to MP4s. 


That's really appreciated. Will give that a go tonight. Already have ffmpeg installed and maintaining correct dates would be useful. If, for some reason I wanted to create current dates, would it be a simple matter of removing that one line (beginning touch).

Thanks for the replies. They're really appreciated.

sark
Title: Re: Simple batch convert with .bat file.
Post by: dosdan on April 04, 2019, 07:45:48 PM
Quote from: sark on April 04, 2019, 10:18:20 AM
If, for some reason I wanted to create current dates, would it be a simple matter of removing that one line (beginning touch).

Yes. You can also leave the line in the batchfile, but inactivate it by placing an REM (remark) command at the start of that line.

Dan.
Title: Re: Simple batch convert with .bat file.
Post by: sark on April 05, 2019, 12:51:42 PM
Quote
Yes. You can also leave the line in the batchfile, but inactivate it by placing an REM (remark) command at the start of that line.

Of course, didn't think of that.
Haven't had it running yet, I had an error. I think there is an issue with my ffmpeg, which is actually the "ffmpeg for Audacity" version. I'm going to download a standalone version today and install that tonight. Just one other question in case I still hit a problem.

Quote
If FFMPEG.EXE and TOUCH.EXE are not situated in a directory mentioned in your Path list, specify their full pathname in the batchfile e.g. c:\utils\ffmpeg.exe

What exactly do you mean by Path list, and where in your code would the pathname go. I can see nothing in your code that indicates pointing to ffmpeg.exe or touch.exe. Probly missing something obvious, but would be grateful for some clarification to ensure it's not an issue with my installations.

Cheers

sark
Title: Re: Simple batch convert with .bat file.
Post by: eumagga0x2a on April 05, 2019, 01:28:35 PM
PATH is an environment variable holding a list of directories which get searched for executables with given name so that you may skip specifying the full path to a particular executable.
Title: Re: Simple batch convert with .bat file.
Post by: dosdan on April 05, 2019, 07:20:21 PM
Go to the command prompt, (Type CMD in the Windows Search box and then press Enter). The prompt ending in ">" shows your current drive and the directory you are situated in e.g.
C:\Windows\System32>

When you go to execute a program, e.g. ffmpeg.exe which, let's say, is stored in the C:\Utilities directory, there are 3 ways to do this:


For example, you might have lot of little utility programs and batch files which you want to be able to run from anywhere. Type PATH at the command line. Mine shows:

PATH=C:\Mingw\local64\bin-video;C:\Mingw\local64\bin-audio;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86);C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\GNU\GnuPG\pub;C:\Program Files (x86)\GNU\GnuPG;C:\Program Files (x86)\WinMerge;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\QuickTime\QTSystem\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files (x86)\Common Files\Acronis\VirtualFile\;C:\Program Files (x86)\Common Files\Acronis\VirtualFile64\;C:\Program Files (x86)\Common Files\Acronis\SnapAPI\;C:\Program Files\nodejs\;C:\Program Files\gnuplot\bin;C:\Users\Dan\AppData\Local\Microsoft\WindowsApps;d:\YouTube_dl;C:\Users\Dan\AppData\Roaming\npm;

Say you decide that these small useful programs will be stored in C:\Utilites. We need to add C:\Utilities to the path list. In Windows, go to Control Panel | System | Advanced System Settings | Environment Variables. In the "User Variables for [your user name]" section, highlight the "Path" line and then click on "Edit". Click on "New", type in c:\utilities (case is not important in Windows) and click on OK, and then OK again, and OK again to finish closing all these windows.


(https://dl.dropbox.com/s/622mvi71vw798vx/Editing_path_list.jpg)


We need to load a new instance of CMD, as the current instance will not be aware of the change in the path yet. If the CMD window is still open, close it by typing EXIT, then type CMD again to open as a new instance. Type PATH to check again. I see (scroll to the end of the line below to see the addition):

PATH=C:\Mingw\local64\bin-video;C:\Mingw\local64\bin-audio;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86);C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\GNU\GnuPG\pub;C:\Program Files (x86)\GNU\GnuPG;C:\Program Files (x86)\WinMerge;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\QuickTime\QTSystem\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files (x86)\Common Files\Acronis\VirtualFile\;C:\Program Files (x86)\Common Files\Acronis\VirtualFile64\;C:\Program Files (x86)\Common Files\Acronis\SnapAPI\;C:\Program Files\nodejs\;C:\Program Files\gnuplot\bin;C:\Users\Dan\AppData\Local\Microsoft\WindowsApps;d:\YouTube_dl;C:\Users\Dan\AppData\Roaming\npm;c:\utilities;

Now, from any drive and directory you can just type
ffmpeg


You may also have more than one copy of FFMPEG.EXE in your path list. There is a WHERE command that you can use to see which one will be found first. In the example below, there are 3 instances of the search string found. The second find is the one which will be executed since the first find is not an executable. (Note: I don't have a c:\utilities in my path list):

C:\WINDOWS\system32>where /t ffmpeg
       163   22/03/2019    7:01:02 AM  C:\Mingw\media-autobuild_suite-master\local64\bin-video\ffmpeg
  25594880   22/03/2019    7:01:00 AM  C:\Mingw\media-autobuild_suite-master\local64\bin-video\ffmpeg.exe
  25594880   22/03/2019    7:01:00 AM  d:\YouTube_dl\ffmpeg.exe


Note: the "/t" switch is used here to show the date/time and size of the matches. FFMPEG.EXE is included in a lot of freeware video programs, and you often end up with multiple older copies of it on your HDD.

Dan.

Title: Re: Simple batch convert with .bat file.
Post by: sark on April 10, 2019, 10:52:36 AM
Firstly, thanks for all the input, it really is appreciated and has proved extremely informative.

I've spent the last few days trying to solve some problems that were due to me testing everything on an XP system. I finally realised I was using the wrong ffmpeg version.
As a result of replacing several previous versions with ffmpeg 3.3 win32 static I thought I had everything working. Whilst the bat file converts to mp4 (aac) with original time. I can't get it to do this to more than one file.
If I select more than one file and drag onto the bat file, only one m2ts is converted?
Could this be a Win XP issue perhaps? I'm in the process of switching a Win 7 system over to 64bit, so am currently playing around on an older XP system. Is it possible the cmd line script could differ for versions later than XP. If so, this is fine as I'll be using it on Win 7 64bit ultimately.

Thanks again

sark
Title: Re: Simple batch convert with .bat file.
Post by: dosdan on April 10, 2019, 09:51:02 PM
Quote from: sark on April 10, 2019, 10:52:36 AM
Could this be a Win XP issue perhaps?

Possibly. I'm surprised it works under XP. I think the batch language was significantly enhanced in Win7.

You still have the SHIFT command in the right place? It's what causes the loop to see a different input file each time.

Here is a multi-file test I did under Win10:

I copied/renamed a small .MTS file to test1.mts, test2.mts & test4.mts. I also created an invalid ("corrupted") .MTS, test3.mts, by copy/renaming a text file i.e.

copy copy mylist.txt test3.mts

Here's the 4-file test set:

dir test?.mts

Directory of C:\Filename_test

09/07/2017  08:43 PM        64,296,960 test1.MTS
09/07/2017  08:43 PM        64,296,960 test2.MTS
01/04/2019  06:50 AM               325 test3.mts
09/07/2017  08:43 PM        64,296,960 test4.MTS


Now I ran this set though the conversion batchfile from the command line. (Should give the same result as specifying each file separately on  the command line i.e. "Convert_MTS_to_MP4.bat test1.mts test2.mts test3.mts test4.mts" or using drag-and-drop.)

Convert_MTS_to_MP4.bat test?.mts
Converting    test1.MTS    to    C:\Filename_test\converted\test1.mp4
09/07/2017  08:43 PM        60,840,130 test1.mp4

Converting    test2.MTS    to    C:\Filename_test\converted\test2.mp4
09/07/2017  08:43 PM        60,840,130 test2.mp4

Converting    test3.mts    to    C:\Filename_test\converted\test3.mp4
test3.mts: Invalid data found when processing input

An error occurred when trying to process test3.mts
Aborting...


Press any key to continue . . .



You can see that two files were converted before the bogus .mts caused FFMPEG to throw an errorlevel of 1 or greater and the batchfile detected this and stopped.

By the way, this thread covers similar ground: https://avidemux.org/smif/index.php?topic=18522.0

Dan.
Title: Re: Simple batch convert with .bat file.
Post by: sark on April 11, 2019, 10:07:27 AM
The conversion doesn't abort. Everything runs just fine except there is only one converted file in the folder. I'm pretty certain it's an XP issue. I don't intend using XP so I'm sure all will work fine when I get the Win 7 (64bit) setup.

Thanks again for the input. It's encouraged me to delve a bit deeper to get a grip of the coding and create an opposite version of the script (mp4 to m2ts) for creating HD DVD/BD output.

sark

Title: Re: Simple batch convert with .bat file.
Post by: dosdan on April 11, 2019, 10:34:20 AM
Don't know if this is the cause of your problem, but this version works with spaces in the filenames:

Convert_MTS_to_MP4_v2.bat
@echo off

cls
set filename=""

:FILES_LOOP
for %%F in (%*) do (
set filename="%%F" 
echo Converting    "%%F"    to    "%%~dpFconverted\%%~nF.mp4"
if not exist "%%~dpFconverted\" md "%%~dpFconverted\"
ffmpeg.exe -i "%%F" -c:v copy -c:a aac -y -hide_banner -loglevel error -map_metadata 0 "%%~dpFconverted\%%~nF.mp4"
if errorlevel 1 goto ERROR_OCCURRED

        rem Next line sets the MP4's file date/time to the same as the original MP4 file.
touch -r "%%~fF" "%%~dpFconverted\%%~nF.mp4"

        rem Next line shows the MP4 after it has been created, so with multiple MP4s it acts as a sort of progress indicator.
dir "%%~dpFconverted\%%~nF.mp4" | find "/"

rem Remove REM from the start of the next line if you wish to delete the original file if no error occurred in the conversion.
rem del "%%F"

        echo.
shift
)
if not "%1"=="" goto FILES_LOOP
goto FINISHED

:ERROR_OCCURRED
echo.
echo An error occurred when trying to process %filename%
echo Aborting...

:FINISHED
echo.
echo.
pause


The test set of files was three .MTS files, two of which have spaces in their filenames:

Convert_MTS_to_MP4.bat "new test?.mts" test4.mts
Converting    "new test1.mts"    to    "C:\Filename_test\converted\new test1.mp4"
09/07/2017  08:43 PM        60,840,130 new test1.mp4

Converting    "new test2.mts"    to    "C:\Filename_test\converted\new test2.mp4"
09/07/2017  08:43 PM        60,840,130 new test2.mp4

Converting    "test4.mts"    to    "C:\Filename_test\converted\test4.mp4"
09/07/2017  08:43 PM        60,840,130 test4.mp4



Press any key to continue . . .


Dan.
Title: Re: Simple batch convert with .bat file.
Post by: dosdan on April 11, 2019, 10:47:13 AM
Quote from: sark on April 11, 2019, 10:07:27 AM
create an opposite version of the script (mp4 to m2ts) for creating HD DVD/BD output.

What is encoding format of the audio stream in the .m2ts files (same as .mts) used for BD?  The Mediainfo program (https://mediaarea.net/en/MediaInfo) will tell you.

From memory, for DVD, the video stream is mpeg-2 (M2V) and the audio stream is either pcm16le (.wav) or mp2, so both steams will need to be converted when converting from MP4 to M2TS/MTS.

Dan.
Title: Re: Simple batch convert with .bat file.
Post by: dosdan on April 12, 2019, 12:47:43 AM
This version continues after an error occurs instead of aborting. It keeps a list of the files which generated processing errors and so were not converted. Since you could be processing hundreds of files, the err msgs may otherwise scroll off the screen.

Convert_MTS_to_MP4_v3.bat
@echo off
setlocal EnableDelayedExpansion
cls

if exist conversion_error.txt del /q conversion_error.txt

:FILES_LOOP
for %%F  in (%*) do (
    echo Converting    "%%~fF"    to    "%%~dpFconverted\%%~nF.mp4"
if not exist "%%~dpFconverted\" md "%%~dpFconverted\"
ffmpeg.exe -i "%%~fF" -c:v copy -c:a aac -y -hide_banner -loglevel error -map_metadata 0 "%%~dpFconverted\%%~nF.mp4"
if errorlevel 1 echo error occurred: %%~fF  >> conversion_error.txt

        rem Next line sets the MP4's file date/time to the same as the original MP4 file.
if exist "%%~dpFconverted\%%~nF.mp4" touch -r "%%~fF" "%%~dpFconverted\%%~nF.mp4"

        rem Next line shows the MP4 after it has been created, so with multiple MP4s it acts as a sort of progress indicator.
rem if exist "%%~dpFconverted\%%~nF.mp4" dir "%%~dpFconverted\%%~nF.mp4" | find "/"

        rem Remove REM from the start of the next line if you wish to delete the original file if no error occurred in the conversion.
rem del "%%~fF"

        echo.
shift
)
if not "%1"=="" goto FILES_LOOP
goto FINISHED

:FINISHED
@echo off
if exist conversion_error.txt start /i conversion_error.txt
echo.
echo.
pause


I found using -i "%%F" problematic with files with inverted commas around them. The most consistent results seem to be from using -i "%%~fF".

The file test set consisted of 6 .MTS files, two of which are invalid, and one with a space in its filename:
09/07/2017  08:43 PM        64,296,960 test 1.MTS
09/07/2017  08:43 PM        64,296,960 test2.MTS
01/04/2019  06:50 AM               325 test3.mts


09/07/2017  08:43 PM        64,296,960 test4.MTS
01/04/2019  06:50 AM               325 test5.mts
09/07/2017  08:43 PM        64,296,960 test6.mts


C:\Filename_test\Directory A>Convert_MTS_to_MP4_v3.bat test*.mts

(https://dl.dropbox.com/s/kq5kp4o22bvujj1/processing%20error%20list.jpg)


start /i conversion_error.txt runs the associated program for text files, typically Notepad, and loads the file.

Dan.
Title: Re: Simple batch convert with .bat file.
Post by: dosdan on April 12, 2019, 12:52:57 AM
Quote from: dosdan on April 12, 2019, 12:47:43 AM
This version continues after an error occurs instead of aborting. It keeps a list of the files which generated processing errors and so were not converted. Since you could be processing hundreds of files, the err msgs may otherwise scroll off the screen.

Convert_MTS_to_MP4_v3.bat
@echo off
setlocal EnableDelayedExpansion
cls

if exist conversion_error.txt del /q conversion_error.txt

:FILES_LOOP
for %%F  in (%*) do (
    echo Converting    "%%~fF"    to    "%%~dpFconverted\%%~nF.mp4"
if not exist "%%~dpFconverted\" md "%%~dpFconverted\"
ffmpeg.exe -i "%%~fF" -c:v copy -c:a aac -y -hide_banner -loglevel error -map_metadata 0 "%%~dpFconverted\%%~nF.mp4"
if errorlevel 1 echo error occurred: %%~fF  >> conversion_error.txt

        rem Next line sets the MP4's file date/time to the same as the original MP4 file.
if exist "%%~dpFconverted\%%~nF.mp4" touch -r "%%~fF" "%%~dpFconverted\%%~nF.mp4"

        rem Next line shows the MP4 after it has been created, so with multiple MP4s it acts as a sort of progress indicator.
rem if exist "%%~dpFconverted\%%~nF.mp4" dir "%%~dpFconverted\%%~nF.mp4" | find "/"

        rem Remove REM from the start of the next line if you wish to delete the original file if no error occurred in the conversion.
rem del "%%~fF"

        echo.
shift
)
if not "%1"=="" goto FILES_LOOP
goto FINISHED

:FINISHED
@echo off
if exist conversion_error.txt start /i conversion_error.txt
echo.
echo.
pause


I found using -i "%%F" problematic with files with inverted commas around them. The most consistent results seem to be from using -i "%%~fF".

The file test set consisted of 6 .MTS files, two of which are invalid, and one with a space in its filename. (I also had a space in the current directoryname):
09/07/2017  08:43 PM        64,296,960 test 1.MTS
09/07/2017  08:43 PM        64,296,960 test2.MTS
01/04/2019  06:50 AM               325 test3.mts


09/07/2017  08:43 PM        64,296,960 test4.MTS
01/04/2019  06:50 AM               325 test5.mts
09/07/2017  08:43 PM        64,296,960 test6.mts


C:\Filename_test\Directory A>Convert_MTS_to_MP4_v3.bat test*.mts

(https://dl.dropbox.com/s/kq5kp4o22bvujj1/processing%20error%20list.jpg)


start /i conversion_error.txt runs the associated program for text files, typically Notepad, and loads the file.

Dan.
Title: Re: Simple batch convert with .bat file.
Post by: sark on April 12, 2019, 09:07:17 AM
Quote
Don't know if this is the cause of your problem, but this version works with spaces in the filenames:

Will give it a go tonight. Thanks.

Quote
What is encoding format of the audio stream in the .m2ts files (same as .mts) used for BD?  The Mediainfo program (https://mediaarea.net/en/MediaInfo) will tell you.

I'm pretty certain it's H264. I can use MultiAVCHD to create output from mp4's, but it should be quicker to use m2ts files for BD output and save MultiAVCHD much of the work (That's my thinking).

Quote
From memory, for DVD, the video stream is mpeg-2 (M2V) and the audio stream is either pcm16le (.wav) or mp2, so both steams will need to be converted when converting from MP4 to M2TS/MTS.

Yes DVD is mpeg 2 but I intend creating HD compatible DVDR's (to play in Blu-ray players and HD compatible DVD players) which I believe are the same m2ts as BD output? Standard DVD format is very low resolution compared to HD (about a quarter I believe) although I've produced surprisingly reasonable results with DVDStyler.

sark
Title: Re: Simple batch convert with .bat file.
Post by: dosdan on April 12, 2019, 09:44:43 AM
Quote from: sark on April 12, 2019, 09:07:17 AM

Quote
What is encoding format of the audio stream in the .m2ts files (same as .mts) used for BD?

I'm pretty certain it's H264.


Sank, H.264 is a video codec, but I was asking about the audio stream. So what audio codec is expected for the audio stream in the .m2ts containers destined for BD?

Dan.

Title: Re: Simple batch convert with .bat file.
Post by: sark on April 15, 2019, 10:34:58 AM
Quote from: dosdan on April 12, 2019, 09:44:43 AM
Quote from: sark on April 12, 2019, 09:07:17 AM

Quote
What is encoding format of the audio stream in the .m2ts files (same as .mts) used for BD?

I'm pretty certain it's H264.


Sank, H.264 is a video codec, but I was asking about the audio stream. So what audio codec is expected for the audio stream in the .m2ts containers destined for BD?

Dan.

Firstly, I jumped ahead of myself after reading "What is encoding format"  and missed "audio stream" . Should have said AC3. However, my earlier post was also not as clear as it could have been regarding the DVD output also being HD, which is m2ts-h264-ac3, for playback on compatible players.

Quote from: dosdan on April 11, 2019, 10:34:20 AM
Don't know if this is the cause of your problem, but this version Convert_MTS_to_MP4_v2.bat works with spaces in the filenames:

The spaces are not an issue. It always processed one file, regardless of its naming structure. This example (v2.bat) failed to run, creating an error due to not recognising the file path. See below.

(https://oi277.photobucket.com/albums/kk49/secoast/bat-2.jpg)

Quote from: dosdan on April 12, 2019, 12:47:43 AM
This version continues after an error occurs instead of aborting. It keeps a list of the files which generated processing errors and so were not converted. Since you could be processing hundreds of files, the err msgs may otherwise scroll off the screen.

Convert_MTS_to_MP4_v3.bat

I haven't seen any indication (in the cmd window) of an error occuring with the first version. Just the failure to encode more than one file. However, there may well have been an error as this version (Convert_MTS_to_MP4_v3.bat) works perfectly in XP, converting all the files from m2ts-ac3 to mp4-aac (mediainfo confirmed), with no errors reported. See below. So it appears you have solved it as far as XP is concerned. I suspect the first version will run just fine in Win 7. This version as well probably.

(https://oi277.photobucket.com/albums/kk49/secoast/bat-3.jpg)

Quote from: dosdan on April 12, 2019, 12:47:43 AM

I found using -i "%%F" problematic with files with inverted commas around them. The most consistent results seem to be from using -i "%%~fF".

I don't generally use inverted commas for file names. Don't know if this helped solve the issue. More likely something to do with error reporting perhaps ?

This has been a very useful learning experience. Your help is greatly appreciated. Can't say I understand the cmd code as it's less descriptive than some of the simpler coding languages I've dabbled with in the past, but I intend delving a bit deeper so I can maybe make some adjustments if required in the future. Where did you source the cmd script info to get you this far ?

Thanks again

sark 
Title: Re: Simple batch convert with .bat file.
Post by: dosdan on April 15, 2019, 12:18:46 PM
Quote from: sark on April 15, 2019, 10:34:58 AM
Where did you source the cmd script info to get you this far ?


Yes ago I used to write a few batchfiles using the 4DOS/4OS2 command processors. The Windows version of these (4NT) is now available for free as TCC/LE: https://jpsoft.com/products/tcc-le.html

However, cmd.exe, the command proccessor in Windows has got more powerful over the years and you an do a fair bit in it now.   A good reference for the commands is found at https://ss64.com/nt/

Dan.

Title: Re: Simple batch convert with .bat file.
Post by: dosdan on April 15, 2019, 12:57:22 PM
Quote from: sark on April 15, 2019, 10:34:58 AM

I don't generally use inverted commas for file names. Don't know if this helped solve the issue.

It's not just the filename, but the full pathname.  Your directory name My Videos has a space in it. This is not a problem if working within a directory and just using filenames, but I am using full pathnames as I was working towards drag&dropping multiple directories, i.e. working with directory names, not selecting files within a directory. I think there's a difference in how Windows passes the filenames/pathnames with spaces in them in drag&drop vs via the command line as batch parameters.  That's perhaps why "%%~fF" or just "%%~F" seems a better way than either %%F or "%%F", which can end up with none/too many double-inverted commas when passing a mixture of files with full pathnames with and without spaces.  See "Parameter Extensions" at https://ss64.com/nt/syntax-args.html


BTW, I forget to remove the REM from the start of:
if exist "%%~dpFconverted\%%~nF.mp4" dir "%%~dpFconverted\%%~nF.mp4" | find "/"

So it's inactivated at the moment. If you remove the REM it will add date/time and size details e.g:

Converting    "C:\Filename_test\Directory A\test 1.MTS"    to    "C:\Filename_test\Directory A\converted\test 1.mp4"
09/07/2017  08:43 PM        60,840,130 test 1.mp4

Converting    "C:\Filename_test\Directory A\test2.MTS"    to    "C:\Filename_test\Directory A\converted\test2.mp4"
09/07/2017  08:43 PM        60,840,130 test2.mp4



The piping ("|") of the DIR's screen output of the details of a single file though the Window's FIND.EXE filter which only keeps the line that contains a date because it contains "/" characters i.e. 09/07/2017

Dan.

Title: Re: Simple batch convert with .bat file.
Post by: sark on April 16, 2019, 10:47:21 AM
Quote from: dosdan on April 15, 2019, 12:18:46 PM
Quote from: sark on April 15, 2019, 10:34:58 AM
Where did you source the cmd script info to get you this far ?


Yes ago I used to write a few batchfiles using the 4DOS/4OS2 command processors. The Windows version of these (4NT) is now available for free as TCC/LE: https://jpsoft.com/products/tcc-le.html

However, cmd.exe, the command proccessor in Windows has got more powerful over the years and you an do a fair bit in it now.   A good reference for the commands is found at https://ss64.com/nt/

Dan.

Will take a look at both, thanks.

Quote from: dosdan on April 15, 2019, 12:57:22 PM
Quote from: sark on April 15, 2019, 10:34:58 AM

I don't generally use inverted commas for file names. Don't know if this helped solve the issue.

It's not just the filename, but the full pathname.  Your directory name My Videos has a space in it. This is not a problem if working within a directory and just using filenames, but I am using full pathnames as I was working towards drag&dropping multiple directories, i.e. working with directory names, not selecting files within a directory. I think there's a difference in how Windows passes the filenames/pathnames with spaces in them in drag&drop vs via the command line as batch parameters.  That's perhaps why "%%~fF" or just "%%~F" seems a better way than either %%F or "%%F", which can end up with none/too many double-inverted commas when passing a mixture of files with full pathnames with and without spaces.  See "Parameter Extensions" at https://ss64.com/nt/syntax-args.html


Interestingly DVDStyler fails to encode if it's installed in "Program Files" because of the space in the path name. It has to be installed in C:, or Windows. DVDStyler calls an ffmpeg.bat to encode. Something to do with double quotes not being used on the called path name causing issues.

Quote from: dosdan on April 15, 2019, 12:57:22 PM

BTW, I forget to remove the REM from the start of:
if exist "%%~dpFconverted\%%~nF.mp4" dir "%%~dpFconverted\%%~nF.mp4" | find "/"

Dan.

Yes, I noticed that. I thought I had done it whilst disabling/enabling touch  to check it functioned correctly. When touch is enabled the Modified date in Properties remains the same as the original, when remarked out, the current date displays in Modified. In both cases the Created date is the current date. This is fine, but wasn't sure if that's how it was intended?

sark
Title: Re: Simple batch convert with .bat file.
Post by: dosdan on April 16, 2019, 01:14:46 PM
Quote from: sark on April 16, 2019, 10:47:21 AM
When touch is enabled the Modified date in Properties remains the same as the original, when remarked out, the current date displays in Modified. In both cases the Created date in the current date. This is fine, but wasn't sure if that's how it was intended?

There's an amount of flexibility with both TOUCH & DIR. The reason I added TOUCH to the batchfile was, when converting my camcorder files from AVCHD to MP4, I wanted the file dates to stay the same, as it gives me an external indication of when the video was shot.

Both TOUCH and DIR can work with Created, Modified or Last Accessed date/times so you can set the batchfile up to suit yourself:

TOUCH
Changes files access, modification and creation times.

Usage: touch [-acmpsRvx] [-r REFFILE | -t TIME | -d DATETIME] FILE...

A FILE argument that does not exist is created empty, unless -c or --no-create
is supplied.

  -a, --access-time        Change file access time.
  -c, --no-create          Do not create any new files.
  -m, --modif-time         Change file modification time.
  -p, --pause-exit         Pause on exit.
  -s, -R, --recursive      Recursively touch files in specified directory and
                           all subdirectories.
  -v, --verbose            Output the result of every file processed.
  -x, --creation-time      Change file creation time.

  -r, --reference REFFILE  Use this file's times instead of current time.
  -t, --time TIME          Use [[CC]YY]MMDDhhmm[.ss] instead of current time.
  -d, --date DATETIME      Use YYYY-MM-DDThh:mm:SS[.frac] instead of
                           current time.

  -h, --help               Display this help and exit.
  --version                Display version information and exit.



With DIR, the /TC/TA/TW switches control its date/time display & sorting:
/T          Controls which time field displayed or used for sorting timefield
              C  Creation
              A  Last Access
              W  Last Written


Dan.
Title: Re: Simple batch convert with .bat file.
Post by: dosdan on April 16, 2019, 01:33:35 PM
Quote from: sark on April 16, 2019, 10:47:21 AM
Interestingly DVDStyler fails to encode if it's installed in "Program Files" because of the space in the path name. It has to be installed in C:, or Windows. DVDStyler calls an ffmpeg.bat to encode. Something to do with double quotes not being used on the called path name causing issues.

You could probably place it elsewhere as long as the pathname has no space in it e.g. C:\Video_Utils\DVDStyler.

As well as spaces, you should test for directory or file names containing an inverted coma e.g. Dan's_Holiday_Video.mts and Dan's Holiday Video.mts.

Dan.
Title: Re: Simple batch convert with .bat file.
Post by: sark on April 17, 2019, 09:23:58 AM
Quote from: dosdan on April 16, 2019, 01:33:35 PM
Quote from: sark on April 16, 2019, 10:47:21 AM
Interestingly DVDStyler fails to encode if it's installed in "Program Files" because of the space in the path name. It has to be installed in C:, or Windows. DVDStyler calls an ffmpeg.bat to encode. Something to do with double quotes not being used on the called path name causing issues.

As well as spaces, you should test for directory or file names containing an inverted coma e.g. Dan's_Holiday_Video.mts and Dan's Holiday Video.mts.

Dan.

Will bare that in mind.

Quote from: dosdan on April 16, 2019, 01:14:46 PM
Quote from: sark on April 16, 2019, 10:47:21 AM
When touch is enabled the Modified date in Properties remains the same as the original, when remarked out, the current date displays in Modified. In both cases the Created date in the current date. This is fine, but wasn't sure if that's how it was intended?

There's an amount of flexibility with both TOUCH & DIR. The reason I added TOUCH to the batchfile was, when converting my camcorder files from AVCHD to MP4, I wanted the file dates to stay the same, as it gives me an external indication of when the video was shot.

Both TOUCH and DIR can work with Created, Modified or Last Accessed date/times so you can set the batchfile up to suit yourself:

TOUCH
Changes files access, modification and creation times.

Usage: touch [-acmpsRvx] [-r REFFILE | -t TIME | -d DATETIME] FILE...

A FILE argument that does not exist is created empty, unless -c or --no-create
is supplied.

  -a, --access-time        Change file access time.
  -c, --no-create          Do not create any new files.
  -m, --modif-time         Change file modification time.
  -p, --pause-exit         Pause on exit.
  -s, -R, --recursive      Recursively touch files in specified directory and
                           all subdirectories.
  -v, --verbose            Output the result of every file processed.
  -x, --creation-time      Change file creation time.

  -r, --reference REFFILE  Use this file's times instead of current time.
  -t, --time TIME          Use [[CC]YY]MMDDhhmm[.ss] instead of current time.
  -d, --date DATETIME      Use YYYY-MM-DDThh:mm:SS[.frac] instead of
                           current time.

  -h, --help               Display this help and exit.
  --version                Display version information and exit.



With DIR, the /TC/TA/TW switches control its date/time display & sorting:
/T          Controls which time field displayed or used for sorting timefield
              C  Creation
              A  Last Access
              W  Last Written


Dan.

Will save this for future reference. As long as I have an indicator of the original time, regardless of what it falls under, I'm happy for now.

sark

Sark