Author Topic: How to Batch process Audio tracks on avi files?  (Read 3255 times)

Ogriv

  • Newbie
  • *
  • Posts: 8
How to Batch process Audio tracks on avi files?
« on: May 23, 2016, 11:41:58 PM »
HI Everyone,

I'm new to this program and have a ton of avi files that I'd like to batch process.  These files all have Italian for the first Audio Track and English on the Second Audio Track so to save space and select the correct Audio track I'd like to batch process all files to delete track audio 2 and select Track 1 for Track 1 English.

Since I'm new to this, it would be much appreciated if step by step instructions could be provided - Any help would be greatly appreciated, Thanks in advance!
« Last Edit: May 24, 2016, 11:36:48 AM by Ogriv »

Jan Gruuthuse

  • Hero Member
  • *****
  • Posts: 5579
Re: How to Batch process Audio tracks on avi files?
« Reply #1 on: May 24, 2016, 06:56:07 AM »
You can only batch process on similar video files
If you are certain all video files have
track 0 (1st track) Italian audio
track 1 (1st track) English audio
Simple Command line usage with Tinpy Project

in addition to that you would need to edit this block:
Quote
adm.audioClearTracks()
adm.setSourceTrackLanguage(0,"und")
adm.setSourceTrackLanguage(1,"und")
adm.audioAddTrack(0)
adm.audioCodec(0, "LavAAC");
adm.audioSetDrc(0, 0)
adm.audioSetShift(0, 0,0)
adm.audioAddTrack(1)
adm.audioCodec(1, "copy");
adm.audioSetDrc(1, 0)
adm.audioSetShift(1, 0,0)

the strikethrough lines should be deleted
you would end up with block simular to this
Code: [Select]
adm.audioClearTracks()
adm.setSourceTrackLanguage(0,"und")adm.audioAddTrack(0)
adm.audioCodec(0, "LavAAC");
adm.audioSetDrc(0, 0)
adm.audioSetShift(0, 0,0)

this only example, you need to load a video in to avidemux and then save in Tinypy Project and edit to reflect your settings. Best you set the Language label to italian.

If one video has an English track as track 0 and Italian in track 1, the batch processing would leave the English audio track and delete track 1 the italian one.
« Last Edit: May 28, 2016, 05:49:05 AM by Jan Gruuthuse »

Ogriv

  • Newbie
  • *
  • Posts: 8
Re: How to Batch process Audio tracks on avi files?
« Reply #2 on: May 24, 2016, 06:23:06 PM »
Hi Jan,

Thanks for your response.  Unfortunately I'm missing the basic knowledge of how to even use the script. When I search the forums it's too advanced. Plus, as I understand starting from a certain time the scripting in Avidemux also changed... no luck on Avidemux wiki or Youtube either..

Is there are step-by-step tutorial on how to batch process?
ie: 
how do I load the script? 
how do I choose the folder I want to batch process? 
How do I choose where it'll will output or if it can simply replace the file?
once all settings are set, how do I get the batch processing to start?

I'm using the mac version of Avidemux v2.6.

Any help would be greatly appreciated - Thanks in advance!

Jan Gruuthuse

  • Hero Member
  • *****
  • Posts: 5579
Re: How to Batch process Audio tracks on avi files?
« Reply #3 on: May 25, 2016, 04:51:32 AM »
Sorry, I have no clue how to convert this to Mac.

Quote
how do I load the script?
tinypy script is loaded from command line like avidemux --run "x264-aac(lav).py"
see windows: --run "x264-aac(lav).py"
Quote
how do I choose the folder I want to batch process?
on command line you would change directory into the folder you want to process
windows:
Code: [Select]
cd \Videos
Quote
How do I choose where it'll will output or if it can simply replace the file?
you would add the output folder name in front of the filename.

Can't answer the other questions as they related specific to MAC OS, and no information was found on my side regarding this.

Ogriv

  • Newbie
  • *
  • Posts: 8
Re: How to Batch process Audio tracks on avi files?
« Reply #4 on: May 28, 2016, 02:13:43 AM »
HI Jan,

Thanks for your response and help.  I managed to get the windows version working via virtual pc on my mac.

I managed to save a project script as batch.py and it looks like this:

#PY  <- Needed to identify #
#--automatically built--

adm = Avidemux()
adm.loadVideo("Z:/MEDIA1/MEDIA1 TV SHOWS/Frasier Complete/Frasier Season 05/Frasier 5x02 - The
Gift Horse dvdmux ITA-ENG.avi")
adm.clearSegments()
adm.addSegment(0, 0, 1277400000)
adm.markerA = 0
adm.markerB = 1277400000
adm.videoCodec("Copy")
adm.audioClearTracks()
adm.setSourceTrackLanguage(0,"unknown")
adm.setSourceTrackLanguage(1,"und")
adm.audioAddTrack(1)
adm.audioCodec(0, "copy");
adm.audioSetDrc(0, 0)
adm.audioSetShift(0, 0,0)
adm.setContainer("AVI", "odmlType=1")

How do I have it process the entire folder as apposed to just the one file?

Where will it save the file to?

Can you help me write the proper code to do the above?

Your help is greatly appreciated!

Jan Gruuthuse

  • Hero Member
  • *****
  • Posts: 5579
Re: How to Batch process Audio tracks on avi files?
« Reply #5 on: May 28, 2016, 07:44:42 AM »
not tested:
- test with a few short videos (1 minute) in one folder
- copy MyJob.bat into folder with videos to process
- windows is case sensitive (Aa)!
- in file and path names:
-- avoid spaces and none US ascii (éèõ ....)
-- keep names and paths short

OneTrack.py
Code: [Select]
#PY  <- Needed to identify #
#--automatically built--

adm = Avidemux()

adm.videoCodec("Copy")
adm.audioClearTracks()
adm.setSourceTrackLanguage(0,"unknown")
adm.setSourceTrackLanguage(1,"und")
adm.audioAddTrack(1)
adm.audioCodec(0, "copy");
adm.audioSetDrc(0, 0)
adm.audioSetShift(0, 0,0)
adm.setContainer("AVI", "odmlType=1")

Windows batch file:
MyJob.bat:
Code: [Select]
SETLOCAL

set avidemux="C:\Program Files\Avidemux 2.6\avidemux3.exe"
set outputfolder="D:\video\
set myjob="OneTrack.py"
for %%f in (*.avi) do %avidemux% --force-alt-h264 --load "%%f" --run OneTrack.py --save "%1%outputfolder%\%%f.avi" --quit

ENDLOCAL

these must reflect exactly
- where avidemux is on your system (location): set avidemux
- where you want to save the modified avi's: set outputfolder

hope I did not produce any errors

perhaps windows users could have a look at this? and verify what I've done ;)
« Last Edit: May 28, 2016, 07:46:24 AM by Jan Gruuthuse »

Ogriv

  • Newbie
  • *
  • Posts: 8
Re: How to Batch process Audio tracks on avi files?
« Reply #6 on: March 01, 2017, 01:33:50 AM »
Hi Jan,

Sorry for taking this long to respond.  I took a break from trying to get this going and forgot about it until recently when trying to watch these files again.

If you're still around, I tried the script again.  Running Avidemux 2.6.12 in Windows 7.  In Avidemux under File/Project Script/Run Project: selected "OneTrack" and I got the following error msg:

Quote
Assert failed :0 at line 16, file/home/fx/hudson/workspace/mingw32QT5/avidemux/qt4/common/ADM_editor/src/audio/ADM_edPoolOfAudioTracks.cpp

Quote
The application has encountered a fatal problem
The current editing has been saved and will be reloaded at next start

Quote
ADM_setCrashHook  [libADM_core6.dll]
ADM_backTrack  [libADM_core6.dll]
unknown function  [libADM_script_tinyPy.dll]
unknown function  [libADM_script_tinyPy.dll]
unknown function  [libADM_script_tinyPy.dll]
unknown function  [libADM_script_tinyPy.dll]

Quote
This application has requested the Runtime to terminate in an unusual way.  Please contact the application's support team for more information

Quote
TinyPy:Exception

Exception: (_tp_dict_get) KeyError: nud BackTrack:
File:py2bc.py, line 51
File:py2bc.py, line 10
File:py2bc.py, line 424
File:py2bc.py, line 414
File:py2bc.py, line 199
File:py2bc.py, line 80
File:py2bc.py, line 63

Here's my OneTrack code:

Quote
#PY
#--automatically built--



adm = Avidemux()


adm.videoCodec("Copy")
adm.audioClearTracks()
adm.setSourceTrackLanguage(0,"unknown")
adm.setSourceTrackLanguage(1,"und")
adm.audioAddTrack(1)
adm.audioCodec(0, "copy");
adm.audioSetDrc(0, 0)
adm.audioSetShift(0, 0,0)
adm.setContainer("AVI", "odmlType=1")

and my MyJob.bat code:

Quote
SETLOCAL

set avidemux="C:\Program Files\Avidemux 2.6 - 32 bits

\avidemux.exe"
set outputfolder="C:\video\"
set myjob="OneTrack.py"
for %%f in (*.avi) do %avidemux% --force-alt-h264 --load "%%f" --

run OneTrack.py --save "%1%outputfolder%\%%f.avi" --quit

ENDLOCAL

I don't get what I'm doing wrong, any help would be greatly appreciated - thanks again!
« Last Edit: March 01, 2017, 01:43:44 AM by Ogriv »

Jan Gruuthuse

  • Hero Member
  • *****
  • Posts: 5579
Re: How to Batch process Audio tracks on avi files?
« Reply #7 on: March 01, 2017, 08:09:24 AM »
Sorry, I can't help you any further with (virtual) windows / Mac OS.

Ogriv

  • Newbie
  • *
  • Posts: 8
Re: How to Batch process Audio tracks on avi files?
« Reply #8 on: March 01, 2017, 05:30:06 PM »
I'm no longer using virtual windows.  The results posted above were from an actual pc.... 

eumagga0x2a

  • Hero Member
  • *****
  • Posts: 1391
Re: How to Batch process Audio tracks on avi files?
« Reply #9 on: March 01, 2017, 07:43:17 PM »
Running Avidemux 2.6.12 in Windows 7.

You should generally use at least the latest release (2.6.18), better the most recent nightly.

Quote
In Avidemux under File/Project Script/Run Project: selected "OneTrack" and I got the following error msg:

Quote
Assert failed :0 at line 16, file/home/fx/hudson/workspace/mingw32QT5/avidemux/qt4/common/ADM_editor/src/audio/ADM_edPoolOfAudioTracks.cpp

This means you request from Avidemux an audio track with number exceeding the number of available audio tracks in the current video.

Quote
Here's my OneTrack code:

Code: [Select]
#PY

[...]
adm.audioAddTrack(1)

If the current video has only a single audio track, requesting a second one as above will crash Avidemux in the way you experience it.

edit: for clarity, tracks count starting with zero.
« Last Edit: March 01, 2017, 07:47:24 PM by eumagga0x2a »

Ogriv

  • Newbie
  • *
  • Posts: 8
Re: How to Batch process Audio tracks on avi files?
« Reply #10 on: March 02, 2017, 02:30:31 PM »
Hi eumagga0x2a, thanks for your speedy response.  I grabbed the newer version of Avidemux v2.6.18.

The files I'm trying to process all have Italian on Audio Track 1 and English on Audio Track 2 so to save space I'd like to batch delete Audio track 1 (Italian) and keep Audio Track 2 (English).  I'm a newbie when it comes to programming so I'm not sure what code will do this

« Last Edit: March 02, 2017, 03:00:04 PM by Ogriv »

eumagga0x2a

  • Hero Member
  • *****
  • Posts: 1391
Re: How to Batch process Audio tracks on avi files?
« Reply #11 on: March 02, 2017, 07:42:22 PM »
Please post the output of MediaInfo or ffprobe for a file which triggers this crash (I'd like to verify that there are really two tracks).

Ogriv

  • Newbie
  • *
  • Posts: 8
Re: How to Batch process Audio tracks on avi files?
« Reply #12 on: March 02, 2017, 08:32:33 PM »
okay, I'm assuming I just hit the icon with the "i" for info, if so, here it is:

Properties:

video

Code4CC: XVID
Image Size: 512x384
Aspect Ratio: 1:1 (1:1)
Frame Rate: 25.000 fps
total duration: 00:21:18:400

Extra video properties

ExtraDataSize: 00

Extra Data:

Audio

Codec: MP3
Channels Stereo
Bitrate: 1600Bps / s28 kbps
Viriable Bitrate:
Frequency: 48000 Hz
Total Duration: 00:21:18:408


eumagga0x2a

  • Hero Member
  • *****
  • Posts: 1391
Re: How to Batch process Audio tracks on avi files?
« Reply #13 on: March 02, 2017, 09:01:00 PM »
Avidemux prints info only about the first audio track, which is useless here. Please post the output of MediaInfo (or ffprobe) I have requested.

Ogriv

  • Newbie
  • *
  • Posts: 8
Re: How to Batch process Audio tracks on avi files?
« Reply #14 on: March 03, 2017, 12:06:30 AM »
okay sorry, and how do I obtain this info in avidemux?  (sorry for my newbiness!)