Avidemux Forum

Avidemux => Main version 2.6 => Topic started by: Yev001 on June 05, 2018, 07:47:19 PM

Title: Need help with TinyPy script
Post by: Yev001 on June 05, 2018, 07:47:19 PM
Hi,

I've been tearing my hair out trying to figure out how to change the file extension only... I cant strip the file extension from a file using TinyPy.

I've tried

root, ext = splitext(filename)

and

import os
root, ext = os.path.splitext(filename)

Always get compiling errors.

Here is the full working script, but the end result is "Something.MP4.MKV" and I need "Something.MKV"


gui = Gui()
adm = Avidemux()
ext = "mp4"

inputFolder = gui.dirSelect("Select the source folder")

#
def convert(filein):

start, ext = path.splitext('lib.x')

filename = basename(filein)
dir = dirname(filein)


adm.loadVideo(filein)
   
if(0 == adm.loadVideo(filein)):
        ui.displayError("oops","cannot load "+filein)
        raise



adm.videoCodec("Copy")

adm.setSourceTrackLanguage(0,"unknown")

adm.audioAddTrack(0)

adm.audioCodec(0, "copy");

adm.audioSetDrc(0, 0)

adm.audioSetShift(0, 0,0)

adm.setContainer("MKV", "forceDisplayWidth=False", "displayWidth=1280")

adm.save(dir + "\\" + filename + ".MKV")

print("Done")
   
#
# Main
#

#
list = get_folder_content(inputFolder,ext)
if(list is None):
    raise
for i in list:
        convert(i)
print("Done")


Can anyone help?
Title: Re: Need help with TinyPy script
Post by: Jan Gruuthuse on June 06, 2018, 04:03:06 AM
stackoverflow: https://stackoverflow.com/a/678242 (http://howtogetthefilenamewithouttheextensionfromapathinpython?)


QuoteGetting the name of the file without the extension :

import os
print(os.path.splitext("path_to_file")[0])


As for your import problem, you solve it this way :

from os.path import basename

# now you can call it directly with basename
print(basename("/a/b/c.txt"))
Title: Re: Need help with TinyPy script
Post by: Yev001 on June 06, 2018, 08:06:47 PM
When i try to evaluate that I get "Exception :(_tp_dict_get) KeyError: path"

Get the same error when incorporated into the script
Title: Re: Need help with TinyPy script
Post by: Jan Gruuthuse on June 07, 2018, 05:26:41 AM
Mean recommends viewing the youtube demo by DasTactic
https://avidemux.org/admWiki/doku.php?id=using:tinypy


also interesting could be (#!/bin/bash)  Shell script to convert files from a directory, with some flexibility (http://avidemux.org/smif/index.php/topic,11390.msg59638.html#msg59638) by I12learn
follow the link:  small script

Easier would be  handling files in shell script, and the media stream in tinypy avidemux
#!/bin/bash
for FIL in `ls *mp4 | sort` ; do
  /usr/bin/avidemux3_qt5 --load "$FIL" --run something.py --save ${FIL%.*}.mkv --quit
don

Title: Re: Need help with TinyPy script
Post by: Yev001 on June 09, 2018, 11:39:13 AM
The tutorials do not show how to do this. And I don't understand the error, TinyPy should allow you to do this without error, but it's like I don't have the libraries installed.

I tried writing a shell script but couldn't get it to work either. Downloaded and installed Git, but not clear whhat your code is doing.

/usr/bin/avidemux3_qt5

Is that supposed to point to avidemux executable? Or something else?

Do I need to run the script using Git Bash inside the folder with the files?

Thanks
Title: Re: Need help with TinyPy script
Post by: eumagga0x2a on June 09, 2018, 01:10:34 PM
tinyPy in Avidemux implements a very limited subset of the language. I was not very much in touch with Avidemux scripting yet, but basename(filein) will always return file name with extension, so I am not aware of a way to accomplish the task in tinyPy alone (I may be mistaken).

Yev001, what operating system do you run Avidemux on? If you use Linux or macOS, it is trivial to rename resulting files using a shell script. If you use Windows, the user "dosdan" could help.
Title: Re: Need help with TinyPy script
Post by: Yev001 on June 09, 2018, 05:20:57 PM
I'm running win10

Also just discovered when using the script that works it messes the audio and video streams up. They become choppy and faster. So I'm resorting to doing it manually for now, which seems to be the only way it works successfully for me.
Title: Re: Need help with TinyPy script
Post by: eumagga0x2a on June 09, 2018, 07:13:56 PM
Quote from: Yev001 on June 09, 2018, 05:20:57 PM
Also just discovered when using the script that works it messes the audio and video streams up. They become choppy and faster.

Do you use the 2.7.1 release? The script is missing audioClearTracks() anyway and the number of arguments for the MKV muxer is wrong.
Title: Re: Need help with TinyPy script
Post by: Yev001 on June 09, 2018, 07:40:48 PM
I just updated to 2.7.1 so yes. I recorded the main script, not sure how many arguments that method should have.

I just what it to do what i do manually, open the file, use saved preferences, save the file. Doing it manually its just a 2 button operation.
Title: Re: Need help with TinyPy script
Post by: eumagga0x2a on June 09, 2018, 10:49:26 PM
The script you posted was not created with Avidemux. It might have been taken from Wiki or some old forum posts.

I refer to

QuoteAlso just discovered when using the script that works it messes the audio and video streams up. They become choppy and faster.

This is what I would like to troubleshoot, because 1) this should not happen and 2) I can't reproduce this issue with 2.7.1 using videos available and a correct script. So please post the "script that works" if it is different from what you already posted.