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?
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"))
When i try to evaluate that I get "Exception :(_tp_dict_get) KeyError: path"
Get the same error when incorporated into the script
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
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
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.
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.
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.
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.
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.