Author Topic: Error while batching  (Read 306 times)

jonwren

  • Jr. Member
  • **
  • Posts: 59
Error while batching
« 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

jonwren

  • Jr. Member
  • **
  • Posts: 59
Re: Error while batching
« Reply #1 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

dosdan

  • Jr. Member
  • **
  • Posts: 92
Re: Error while batching
« Reply #2 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:

Code: [Select]
@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.

Code: [Select]
@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.


« Last Edit: March 25, 2018, 08:56:11 PM by dosdan »

eumagga0x2a

  • Hero Member
  • *****
  • Posts: 1830
Re: Error while batching
« Reply #3 on: March 25, 2018, 08:40:40 PM »
I second Dan's recommendation for ffmpeg for this task. Furthermore, I seriously doubt that your command works as you expect.

jonwren

  • Jr. Member
  • **
  • Posts: 59
Re: Error while batching
« Reply #4 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

jonwren

  • Jr. Member
  • **
  • Posts: 59
Re: Error while batching
« Reply #5 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?

eumagga0x2a

  • Hero Member
  • *****
  • Posts: 1830
Re: Error while batching
« Reply #6 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.)

eumagga0x2a

  • Hero Member
  • *****
  • Posts: 1830
Re: Error while batching
« Reply #7 on: March 26, 2018, 11:49:48 AM »
By the way, testing scripted saving as MP4 helped to identify and fix a bug which resulted in broken MP4 files when relative path was supplied via command line.

jonwren

  • Jr. Member
  • **
  • Posts: 59
Re: Error while batching
« Reply #8 on: March 26, 2018, 12:07:09 PM »
ffmpeg is installed, but where do I input the path ?

jonwren

  • Jr. Member
  • **
  • Posts: 59
Re: Error while batching
« Reply #9 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 . . .

eumagga0x2a

  • Hero Member
  • *****
  • Posts: 1830

jonwren

  • Jr. Member
  • **
  • Posts: 59
Re: Error while batching
« Reply #11 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

eumagga0x2a

  • Hero Member
  • *****
  • Posts: 1830
Re: Error while batching
« Reply #12 on: March 26, 2018, 12:41:10 PM »
Java???

Code: [Select]
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)
« Last Edit: March 26, 2018, 12:52:11 PM by eumagga0x2a »

jonwren

  • Jr. Member
  • **
  • Posts: 59
Re: Error while batching
« Reply #13 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
« Last Edit: March 26, 2018, 01:01:00 PM by jonwren »

eumagga0x2a

  • Hero Member
  • *****
  • Posts: 1830
Re: Error while batching
« Reply #14 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.