This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
tinypy:examples [2013/04/27 10:32] fx |
tinypy:examples [2016/06/20 08:00] (current) mean |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ===== Complex exampple ===== | + | ===== Skeleton for batch processing ===== |
| - | ext="mpg" | + | |
| - | inputFolder="/tmp/ts" | + | Here is a simple tinypy script that will load all files with a mp4 extension in a folder. |
| # | # | ||
| - | Small function that converts the file given as parameter, just remuxing it. | + | # Load all the files in c:\tmp with .mp4 extension. |
| - | A file video.in will be converted to video.in.convert.ps | + | # That's it. |
| - | def convert(filein): | + | # |
| - | fileout=filein+".converted.ps" | + | ext="mp4" |
| - | print(filein+"=>"+fileout) | + | inputFolder="c:\\tmp\\" |
| - | if(0 == adm.loadVideo(filein)): | + | # |
| - | ui.displayError("oops","cannot load "+filein) | + | def convert(filein): |
| - | raise | + | if(0 == adm.loadVideo(filein)): |
| - | adm.save(fileout) | + | ui.displayError("oops","cannot load "+filein) |
| - | print("Done") | + | raise |
| - | + | print("Done") | |
| + | |||
| # | # | ||
| # Main | # Main | ||
| # | # | ||
| - | Initialize everything in copy mode, we just set up the output container to be mpeg PS | ||
| ui=Gui() | ui=Gui() | ||
| adm=Avidemux() | adm=Avidemux() | ||
| - | adm.audioReset() | ||
| - | adm.audioCodec("copy",28152032) | ||
| - | adm.videoCodec("Copy") | ||
| - | adm.setContainer("ffPS","muxingType=3","acceptNonCompliant=False","muxRatekBits=30000", | ||
| - | "videoRatekBits=25000"," bufferSizekBytes=500") | ||
| # | # | ||
| - | Get the content of the input folder | ||
| - | That folder could have been selected using gui.dirSelect() in a graphical mode | ||
| list=get_folder_content(inputFolder,ext) | list=get_folder_content(inputFolder,ext) | ||
| if(list is None): | if(list is None): | ||
| - | raise | + | raise |
| for i in list: | for i in list: | ||
| - | convert(i) | + | convert(i) |
| print("Done") | print("Done") | ||
| - | ---- | + | The first part is the initialization. We set the input folder (beware, on windows the \ must be put twice, so c:\tmp\ becomes c:\\tmp\\) and extension '.mp4' here. |
| - | + | Ending the path with a '\\' is a good idea. | |
| - | [[using:tinypy|Go back to tinypy]] | + | ext="mp4" |
| + | inputFolder="c:\\tmp\\" | ||
| + | |||
| + | The we create the object that enables tinypy to interact with avidemux | ||
| + | ui=Gui() | ||
| + | adm=Avidemux() | ||
| + | All avidemux commands will be performed on the 'adm' object. | ||
| + | Next, get the list of files with the given extension and call the 'convert' function for all of them | ||
| + | |||
| + | list=get_folder_content(inputFolder,ext) | ||
| + | if(list is None): | ||
| + | raise | ||
| + | for i in list: | ||
| + | convert(i) | ||
| + | print("Done") | ||
| + | |||
| + | You'll note that "list" is the list of files with full path to them, i.e. c:\\tmp\\foobar.mp4 | ||
| + | |||
| + | def convert(filein): | ||
| + | if(0 == adm.loadVideo(filein)): | ||
| + | ui.displayError("oops","cannot load "+filein) | ||
| + | raise | ||
| + | print("Done") | ||
| + | |||
| + | That's where everything happens. For this simple example, we just load the file, and raise an error if we cannot. | ||
| + | |||
| + | If you try this script, it will load all files ending with mp4 from the c:\\tmp\\ folder. | ||
| + | |||
| + | [[tinypyBatch2|Using the skeleton]] | ||