Author Topic: Need help with TinyPy script  (Read 387 times)

Yev001

  • Newbie
  • *
  • Posts: 5
Need help with TinyPy script
« 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"

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

Jan Gruuthuse

  • Hero Member
  • *****
  • Posts: 6022
Re: Need help with TinyPy script
« Reply #1 on: June 06, 2018, 04:03:06 AM »
stackoverflow: https://stackoverflow.com/a/678242


Quote
Getting the name of the file without the extension :

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

Code: [Select]
# now you can call it directly with basename
print(basename("/a/b/c.txt"))

Yev001

  • Newbie
  • *
  • Posts: 5
Re: Need help with TinyPy script
« Reply #2 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

Jan Gruuthuse

  • Hero Member
  • *****
  • Posts: 6022
Re: Need help with TinyPy script
« Reply #3 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 by I12learn
follow the link:  small script

Easier would be  handling files in shell script, and the media stream in tinypy avidemux
Code: [Select]
#!/bin/bash
for FIL in `ls *mp4 | sort` ; do
  /usr/bin/avidemux3_qt5 --load "$FIL" --run something.py --save ${FIL%.*}.mkv --quit
don
« Last Edit: June 07, 2018, 08:55:35 AM by Jan Gruuthuse »

Yev001

  • Newbie
  • *
  • Posts: 5
Re: Need help with TinyPy script
« Reply #4 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

eumagga0x2a

  • Hero Member
  • *****
  • Posts: 2059
Re: Need help with TinyPy script
« Reply #5 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.

Yev001

  • Newbie
  • *
  • Posts: 5
Re: Need help with TinyPy script
« Reply #6 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.

eumagga0x2a

  • Hero Member
  • *****
  • Posts: 2059
Re: Need help with TinyPy script
« Reply #7 on: June 09, 2018, 07:13:56 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.

Yev001

  • Newbie
  • *
  • Posts: 5
Re: Need help with TinyPy script
« Reply #8 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.

eumagga0x2a

  • Hero Member
  • *****
  • Posts: 2059
Re: Need help with TinyPy script
« Reply #9 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

Quote
Also 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.