News:

--

Main Menu

Error while batching

Started by jonwren, March 25, 2018, 10:57:04 AM

Previous topic - Next topic

jonwren

you mean like this
set PATH=%PATH%;C:\Program Files\ffmpeg\

jonwren


eumagga0x2a

You forgot quotation marks.

jonwren


jonwren

set PATH="%PATH%;C:\Program Files\ffmpeg"

will not allow me to do so

A path component cannot contain any control character nor any of the following
/"<>

eumagga0x2a

Well, I'll have to try out myself where quotation marks belong to once I get to a PC running Windows.

jonwren


eumagga0x2a

It should be

set PATH=%PATH%;"C:\Program Files\ffmpeg\bin"

Don't forget that this has effect only in the current cmd.exe session. Use setx if you want the addition to be persistent.

jonwren

I read that Setx was permanent
If it's not working in the current session, how will it work with setx

eumagga0x2a

It works in the same cmd.exe session (not Windows session!). Or be creative and modify Dan's script so that it uses the absolute path to ffmpeg.exe, it takes so much less time than to type in a forum post.

jonwren

I ended up making a Batch file

for %%a in ("*.mkv") do ffmpeg -i "%%a" -vcodec copy -acodec copy "newfiles\%%~na.mp4"
pause

I made a new folder and then placed the Bat file inside and I also copied and pasted ffmpeg inside the same folder
then made a subfolder called newfiles.

I then placed a few MKV files inside and all converted fine and all new MP4 files where inside the folder newfiles

dosdan

#26
Note FFMPEG doesn't have to be in the PATH EV, although it makes it more convenient to use. You can hard-wire its path into the batchfile:

e.g c:\program\files\utilities\ffmpeg.exe instead of just ffmpeg.exe.

In Windows Explorer, when you want to get the filename with the full path, use Shift-R.Click instead of just R.clicking on FFMPEG.EXE. Then you will see a "Copy as path" command.

The problem in the original batch file seems to occur when using a directory with a space in its name.   The new version works correctly.

For example, from either the cmd line (assuming this batch file is in the path or the current directory): 
Convert_MKV_to_MP4.bat "D:\MKV test\test100.mkv" "D:\MKV test\test200.mkv" "D:\MKV test\test300.mkv"

where test200.mkv is just a renamed copy of test100.mkv, and test300.mkv is an invalid mkv (a renamed text file),

or by dragging-and-dropping these 3 MKVs onto the batch icon, shows this on the screen:


Converting    "D:\MKV test\test100.mkv"    to    "D:\MKV test\test100.mp4"
27/03/2018  02:05 PM       594,813,410 test100.mp4

Converting    "D:\MKV test\test200.mkv"    to    "D:\MKV test\test200.mp4"
27/03/2018  02:05 PM       594,813,410 test200.mp4

Converting    "D:\MKV test\test300.mkv"    to    "D:\MKV test\test300.mp4"
Truncating packet of size 7245 to 47
[matroska,webm @ 000002626bf2cec0] EBML header parsing failed
D:\MKV test\test300.mkv: Invalid data found when processing input

An error occured when trying to process "D:\MKV test\test300.mkv"
Aborting...


Press any key to continue . . .



Convert_MKV_to_MP4.bat
@echo off
cls
set filename=""

:FILES_LOOP
for %%F in (%*) do (
set filename=%%F 
echo Converting    %%F    to    "%%~dpnF.mp4"
ffmpeg.exe -i %%F -c:v copy -c:a copy  -y -hide_banner -loglevel error "%%~dpnF.mp4"
if errorlevel 1 goto ERROR_OCCURRED
dir "%%~nF.mp4" | find "/"
rem Remove REM from the start of the next line if you wish to delete the original file if no error occured in the conversion.
REM del %%F
echo.
shift
)

goto FINISHED

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

:FINISHED
echo.
echo.
pause


Dan.

jonwren