Avidemux Forum

Avidemux => Windows => Topic started by: jonwren on March 25, 2018, 10:57:04 AM

Title: Error while batching
Post by: jonwren on March 25, 2018, 10:57:04 AM
Newbie Alert
Am currently learning to Batch MKV to MP4, basic copy video and copy audio
I get an error message, Which is below...
I have to select OK for every file loaded for it to do the conversion, The conversion works great, apart from having to select OK for every file loaded.
I have found this on one website
get_file_size(file)
BUT I don't know what to do with it, or if it will work, I have tried many ways, but I always get the error below

TinyPy: Exception
Exception : (tp_load) cant get filesize
BackTrack: File:py2bc.py,line50


Here are my Bat file Settings

set avidemux="C:\Program Files\Avidemux 2.7 - 64 bits\avidemux.exe"
for %%f in (*.mkv) do %avidemux% --load "%%f" --run pui.py --save "%%~nf.mp4" --quit


Here are my Py file Settings

adm = Avidemux()
adm.setContainer("MP4", "muxerType=0", "useAlternateMp3Tag=True", "forceAspectRatio=False", "aspectRatio=1")


I have no idea what am doing wrong, Am on the current Nightly version 2.7

Any help would be great, as this is making me go crazy :o

Thanks
Title: Re: Error while batching
Post by: jonwren on March 25, 2018, 06:27:53 PM
SOLVED

MKV to MP4
Copy Video
Copy Audio


set avidemux="C:\Program Files\Avidemux 2.7 - 64 bits\avidemux.exe"
set videocodec=Copy set audiocodec=Copy
for %%f in (*.mkv) do %avidemux% --video-codec %videocodec% --audio-codec %audiocodec% --force-alt-h264 --load "%%f" --save "%%~nf.mp4" --quit
Title: Re: Error while batching
Post by: dosdan on March 25, 2018, 08:11:14 PM
I still think you would be better using FFMPEG here. ADM can do this, but it is an over-complex, even a clumsy way to convert a lot of MKVs to MP4s when all you want to do is remux them.  ADM is better suited when you want to cut, crop and/or resize them.

Here is Convert_MKV_to_MP4.bat:

@echo off

cls
set filename=""

:FILES_LOOP
for %%F in (%1) do (
set filename=%%F 
echo Processing %%F
ffmpeg.exe -i %%F -c:v copy -c:a copy  -y -hide_banner -loglevel error "%%~nF.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 occurred in the conversion.
REM del %%F
echo.
shift
)
if not "%1"=="" goto FILES_LOOP
goto FINISHED

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

:FINISHED
echo.
echo.
pause



This has been designed as a general purpose conversion batchfile (and a a template for other FFMPEG batch operations). It's drag-and-drop. You place the icon of this batch file on your desktop and then drag one or more MKVs on to it. It gives you a rough progress indication which is helpful when you're converting a lot of MKVs.

This next version creates a "converted" sub-directory beneath the original files' location, if it doesn't already exist.  Also it uses a Win32 version of "touch" (http://www.binarez.com/touch_dot_exe/) so that the converted MP4s will have the same date/timestamps as the MKVs.

@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 copy -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 MKV file
touch -r "%%~fF" "%%~dpFconverted\%%~nF.mp4"
rem  Next line shows the MP4 after it has been created, so with
        rem 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
rem  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 occured when trying to process %filename%
echo Aborting...

:FINISHED
echo.
echo.
pause


To test the error handling, use a non-media file. For example, rename readme.doc or hello.txt to test.mkv, and drop it onto the icon.

Dan.


Title: Re: Error while batching
Post by: eumagga0x2a on March 25, 2018, 08:40:40 PM
I second Dan's recommendation for ffmpeg for this task. Furthermore, I seriously doubt (http://avidemux.org/smif/index.php/topic,18268.msg83675.html#msg83675) that your command works as you expect.
Title: Re: Error while batching
Post by: jonwren on March 26, 2018, 08:04:12 AM
Thanks
Will give it a try, as I said am new to this and today is my 3rd day of learning, if  Dan's way is better I will def use that  ;D
Title: Re: Error while batching
Post by: jonwren on March 26, 2018, 08:37:21 AM
I've just tried both bat and both didn't do anything apart from creating a folder, Is there something that I have to input myself?
Title: Re: Error while batching
Post by: eumagga0x2a on March 26, 2018, 10:49:10 AM
Is ffmpeg installed and in PATH?

(Alternatively, you can correct the mistakes outlined in http://avidemux.org/smif/index.php/topic,18268.msg83675.html#msg83572 and use Avidemux.)
Title: Re: Error while batching
Post by: eumagga0x2a on March 26, 2018, 11:49:48 AM
By the way, testing scripted saving as MP4 helped to identify and fix (https://github.com/mean00/avidemux2/commit/8aab187a4fcaf02e90cd6df5d029ff5cf1a587f5) a bug which resulted in broken MP4 files when relative path was supplied via command line.
Title: Re: Error while batching
Post by: jonwren on March 26, 2018, 12:07:09 PM
ffmpeg is installed, but where do I input the path ?
Title: Re: Error while batching
Post by: jonwren on March 26, 2018, 12:11:23 PM
The Error message I get is

Processing "C:\Users\jonwr\Desktop\New folder (3)\Instinct.S01E02.720p.HDTV.2CH.x265.HEVC-PSA - Copy.mkv"
'ffmpeg.exe' is not recognized as an internal or external command,
operable program or batch file.

An error occured when trying to process "C:\Users\jonwr\Desktop\New folder (3)\Instinct.S01E02.720p.HDTV.2CH.x265.HEVC-PSA - Copy.mkv"
Aborting...


Press any key to continue . . .
Title: Re: Error while batching
Post by: eumagga0x2a on March 26, 2018, 12:16:20 PM
https://www.google.com/search?q=windows+edit+path+environment+variable (https://www.google.com/search?q=windows+edit+path+environment+variable)
Title: Re: Error while batching
Post by: jonwren on March 26, 2018, 12:35:36 PM
What am I suppose to do?
I have selected Java and did what it said and returned to the bat file and get the same error
Title: Re: Error while batching
Post by: eumagga0x2a on March 26, 2018, 12:41:10 PM
Java???

set PATH="%PATH%;DriveLetter:\path\to\the\folder\where\ffmpeg.exe\is\located"

In general, https://stackoverflow.com/questions/9546324/adding-directory-to-path-environment-variable-in-windows

(added quotation marks to deal with spaces in the path)
Title: Re: Error while batching
Post by: jonwren on March 26, 2018, 12:55:36 PM
Sorry was meant to say ffmpeg not java

I did this but still nothing
set PATH=%PATH%;C:\Program Files\ffmpeg\bin\ffmpeg.exe
Title: Re: Error while batching
Post by: eumagga0x2a on March 26, 2018, 01:01:59 PM
It should be the folder containing the executable. Not the path to the executable.

And please mind quotation marks.
Title: Re: Error while batching
Post by: jonwren on March 26, 2018, 01:12:10 PM
you mean like this
set PATH=%PATH%;C:\Program Files\ffmpeg\
Title: Re: Error while batching
Post by: jonwren on March 26, 2018, 01:50:30 PM
still not working
Title: Re: Error while batching
Post by: eumagga0x2a on March 26, 2018, 02:17:31 PM
You forgot quotation marks.
Title: Re: Error while batching
Post by: jonwren on March 26, 2018, 02:39:18 PM
where abouts?
Title: Re: Error while batching
Post by: jonwren on March 26, 2018, 02:43:55 PM
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
/"<>
Title: Re: Error while batching
Post by: eumagga0x2a on March 26, 2018, 03:00:39 PM
Well, I'll have to try out myself where quotation marks belong to once I get to a PC running Windows.
Title: Re: Error while batching
Post by: jonwren on March 26, 2018, 03:01:21 PM
ok cheers
Title: Re: Error while batching
Post by: eumagga0x2a on March 26, 2018, 03:23:23 PM
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.
Title: Re: Error while batching
Post by: jonwren on March 26, 2018, 03:34:18 PM
I read that Setx was permanent
If it's not working in the current session, how will it work with setx
Title: Re: Error while batching
Post by: eumagga0x2a on March 26, 2018, 03:56:38 PM
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.
Title: Re: Error while batching
Post by: jonwren on March 26, 2018, 04:53:16 PM
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
Title: Re: Error while batching
Post by: dosdan on March 27, 2018, 04:15:34 AM
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.
Title: Re: Error while batching
Post by: jonwren on March 27, 2018, 06:41:39 AM
Great Thanks Dan