Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules. |
31st May 2019, 23:02 | #81 | Link |
Registered User
Join Date: May 2011
Posts: 321
|
It's more pythonic question or maybe not, not sure, I try it on windows and I have:
Code:
import subprocess import threading import shutil def process(cmd): subprocess.call(cmd) d2vwitch = shutil.which('d2vwitch') index_file = r'C:\.... path ...\test.d2v' file = r'C:\... path ...\HDV.m2t' cmd = [d2vwitch] + ['--output', index_file] + [file] p = threading.Thread(target=process, args=(cmd,)) p.start() p.join() Is there a way in Python together with d2vwitch.exe to make it work and show cmd prompt (like shell=False running subprocess in Python) wait for process to be done and then cancel that cmd window , script is continuing its further process? For example ffmsindex.exe works with above example, having no problem. Last edited by _Al_; 31st May 2019 at 23:48. |
1st June 2019, 13:45 | #82 | Link |
Registered User
Join Date: Dec 2005
Location: Germany
Posts: 1,795
|
You could try it with os.system:
Code:
return_code = os.system(d2vwitch.exe)
__________________
AVSRepoGUI // VSRepoGUI - Package Manager for AviSynth // VapourSynth VapourSynth Portable FATPACK || VapourSynth Database |
1st June 2019, 17:47 | #83 | Link |
Registered User
Join Date: May 2011
Posts: 321
|
That works, thanks!
Code:
import subprocess import threading import shutil def process(cmd): os.system(cmd) d2vwitch = shutil.which('d2vwitch') index_file = r'C:\.... path ...\test.d2v' file = r'C:\... path ...\HDV.m2t' cmd = f'{d2vwitch} --output "{index_file}" "{file}"' p = threading.Thread(target=process, args=(cmd,)) p.start() p.join() Code:
cmd = f'"{d2vwitch}" --output "{index_file}" "{file}"' only: Code:
cmd = f'{d2vwitch} --output "{index_file}" "{file}"' |
1st June 2019, 19:34 | #84 | Link |
Registered User
Join Date: May 2011
Posts: 321
|
ok not sure what is going on, when I put two commands in a row, it works with quotes, so the whole thing:
Code:
import threading import shutil import os import sys def log_err(): err = str(sys.exc_info()[0])+'\n' err += 'in line ' + str(sys.exc_info()[2].tb_lineno)+'\n' err += str(sys.exc_info()[1])+'\n' return err def process(cmd): try: os.system(cmd) except: print(log_err()) d2vwitch = shutil.which('d2vwitch') index_file= r'C:\... path ...\test.d2v' file = r'C:\... path ...\HDV.m2t' cmd = 'mode con: cols=30 lines=6 | ' + f'"{d2vwitch}" --output "{index_file}" "{file}"' #for windows to set cmd prompt size p = threading.Thread(target=process, args=(cmd,)) p.start() p.join() print('done indexing: ', index_file) Last edited by _Al_; 1st June 2019 at 19:39. |
3rd June 2019, 03:00 | #85 | Link |
Registered User
Join Date: May 2011
Posts: 321
|
just correcting a code above if someone tests that, that error catching is a nonsense there.
os.system returns error like ChaosKing posted, if it is 0, process went well, on linux it is a bit different because return suppose to be in 16bit with two 8 bit values, but just for Windows - and using a list slot to pass a return value from inside a thread. Code:
import threading import shutil import os from vapoursynth import core def process(cmd, result): return_code = os.system(cmd) result[0]=return_code d2vwitch = shutil.which('d2vwitch') index_file= r'C:\... path ...\test.d2v' file = r'C:\... path ...\HDV.m2t' cmd = f'title d2vwitch creating: {index_file} | mode con: cols=60 lines=8 | "{d2vwitch}" --output "{index_file}" "{file}"' results = [None] p = threading.Thread(target=process, args=(cmd,results)) p.start() p.join() #waits for thread to finish #print(results[0]) if results[0]==0: print('indexing went well') clip = core.d2v.Source(index_file) clip.set_output() else: print('indexing failed') Last edited by _Al_; 3rd June 2019 at 03:33. |
3rd June 2019, 10:09 | #86 | Link |
Registered User
Join Date: Dec 2005
Location: Germany
Posts: 1,795
|
Hmm I get only1 value in Ubuntu (wsl) and a debian based distro with this:
Code:
user@live-pc:~$ python3 -c "import sys, os; r = os.system('-ls -a'); print('return: ', r)" return: 0 user@live-pc:~$ python3 -c "import sys, os; r = os.system('ls -a-'); print('return: ', r)" return: 512
__________________
AVSRepoGUI // VSRepoGUI - Package Manager for AviSynth // VapourSynth VapourSynth Portable FATPACK || VapourSynth Database |
4th June 2019, 03:26 | #87 | Link |
Registered User
Join Date: May 2011
Posts: 321
|
One value but packed as two 8bit numbers, https://stackoverflow.com/questions/...python/6466753
I was not sure if return is not zero and still it could be ok, so maybe return >> 8 or use that os.WEXITSTATUS, I will set it up later to try. Last edited by _Al_; 4th June 2019 at 03:28. |
9th June 2019, 05:06 | #88 | Link |
Registered User
Join Date: May 2011
Posts: 321
|
for linux, Ubuntu 18.04 this seems to work, I hope it works on other unix systems, but that --disable-factory looks controversial:
os.system ('gnome-terminal --disable-factory -x .... command.....') that would let terminal to pop up with % information while indexing, and python waits for it to finish, then terminal closes and script goes on. Return code is still zero if terminal is canceled by user so checking if file exists and it is not empty: Code:
import threading import shutil import os from vapoursynth import core def process(cmd): os.system(cmd) d2vwitch = shutil.which('d2vwitch') index_file = '/home/your user name/ ... /test.d2v' file = '/home/your user name/ ... /HDV.m2t' cmd = 'gnome-terminal --disable-factory --hide-menubar --geometry=90x10 ' cmd += f' --title="d2vwitch creating: {index_file}" ' cmd += f' -x "{d2vwitch}" --output "{index_file}" "{file}"' p = threading.Thread(target=process, args=(cmd,)) p.start() p.join() if not (os.path.isfile(index_file) and os.path.getsize(index_file) > 0): print('indexing failed') raise FileNotFoundError("Index file was not created or process was canceled") clip = core.d2v.Source(index_file) clip.set_output() Last edited by _Al_; 9th June 2019 at 05:24. |
4th July 2019, 23:16 | #89 | Link |
Registered User
Join Date: May 2011
Posts: 321
|
sorry I'm back again about d2vwitch output , live readings about continuing progress :-)
using code from this input https://forum.doom9.org/showthread.p...10#post1866410 that worked indeed, thru stderr, but it looks like it does not work under windows , linux only, reading live output from subprocess.Popen. Do I suppose to use dgindex under windows, or do I do something wrong? or this is easier code, again, it works on linux only: Code:
import threading import subprocess class Cmd(threading.Thread): def __init__(self): threading.Thread.__init__(self) process = subprocess.Popen( [d2vwitch, '--output', output, file], stderr=subprocess.PIPE, universal_newlines=True) for line in process.stderr: print(line) file = '09_28-10_29_29.m2t' d2vwitch = shutil.which('d2vwitch') output = 'out.d2v' command = Cmd() command.start() command.join() Last edited by _Al_; 4th July 2019 at 23:24. |
26th July 2019, 09:36 | #90 | Link |
Registered User
Join Date: Sep 2006
Posts: 1,657
|
There's some difference between the default setting for input color range between dgindex and d2v witch, dgindex said to use "pc range" generally while d2v witch said videos are assumed to have limited range. I'm kind of confused.
|
26th July 2019, 17:00 | #91 | Link | |
unsigned int
Join Date: Oct 2012
Location: 🇪🇺
Posts: 760
|
Quote:
In DGIndex the range setting refers to the range of the output video after conversion to RGB. (This must mean that it assumes all input videos will have limited range YUV.) From the DGIndex manual: Code:
PC scale - Map output RGB to full range: YUV [16, 235(Y)/240(UV)] -> RGB [0, 255] TV scale - Map output RGB to clipped range: YUV [16, 235(Y)/240(UV)] -> RGB [16, 235]
__________________
Buy me a "coffee" and/or hire me to write code! |
|
26th July 2019, 22:29 | #93 | Link | |
unsigned int
Join Date: Oct 2012
Location: 🇪🇺
Posts: 760
|
Quote:
If you do encounter a video with full range YUV, you'll need to use the "full range" option in D2V Witch and the "TV range" option in DGIndex. Note that the range you pick doesn't matter at all in Avisynth. In VapourSynth it only tells d2vsource what value to give the _ColorRange frame property, and you can always override that in the script with SetFrameProp.
__________________
Buy me a "coffee" and/or hire me to write code! |
|
27th July 2019, 00:47 | #94 | Link |
Registered User
Join Date: May 2011
Posts: 321
|
limited to full can be changed either manually in d2v file:
line is YUVRGB_Scale=1 or YUVRGB_Scale=0 I think it is properly named, it matters if you convert to RGB (preview on screen). If you just encode to x264, it does not matter. d2vfile: Code:
DGIndexProjectFile16 1 D:\path\tape 34-2013_12_25-09_03_53.m2t Stream_Type=2 MPEG2_Transport_PID=810,814,0 Transport_Packet_Size=188 MPEG_Type=2 iDCT_Algorithm=6 YUVRGB_Scale=1 Luminance_Filter=0,0 Clipping=0,0,0,0 . . Code:
def correct_byte_for_range(d2v_path, input_range): log = '' if input_range == 'full': input_range_number = '0' else: input_range_number = '1' '''find a line with 'YUVRGB_Scale' in d2v file and change byte for YUVRGB_Scale line to '1' or '0' if needed ''' with open(d2v_path, 'r+') as f: offset = 0 try: for line in f: if line.strip().startswith('YUVRGB_Scale'): break offset += len(line) if offset: f.seek(offset+13) #'YUVRGB_Scale=0 or 'YUVRGB_Scale=1' _range = f.read(1) if _range != input_range_number: f.seek(0) f.seek(offset) f.write(f'YUVRGB_Scale={input_range_number}') f.close() log += f"correcting input range byte in d2v file to '{input_range_number}' - '{input_range}'\n" except: raise TypeError("Not dv2 index file or not compatible\n" "correcting input_range byte failed") return log Last edited by _Al_; 27th July 2019 at 00:50. |
27th July 2019, 01:30 | #95 | Link |
Registered User
Join Date: Sep 2006
Posts: 1,657
|
Okay correct me if I get it wrong, so color range is just a flag to tell vs editor to display the right levels on preview, when we're encoding to x264, x264 is just going to ignore that flag and assumed everything to be tv range by default?
|
27th July 2019, 02:16 | #96 | Link |
Registered User
Join Date: May 2011
Posts: 321
|
It has no meaning for x264, x264 uses YUV values that are in your video
but it is used for YUV to RGB conversion previewing video (and converting to RGB) is a tricky business, it can fool you thinking you have different video than you really have :-) |
27th July 2019, 12:12 | #97 | Link | |
unsigned int
Join Date: Oct 2012
Location: 🇪🇺
Posts: 760
|
Quote:
If you're piping the video to x264, the flag gets lost and x264 doesn't know anything about the range. If you're using x264 through a copy of ffmpeg that can open VapourSynth scripts directly, it's possible that the flag makes it to x264. In any case, x264 only cares about the range because it can mark the video it produces with a flag that tells video players how to convert the encoded video to RGB. x264 has a command line parameter for this called "--range". (It also has parameters for the matrix, primaries, transfer, chroma location, etc.) If you don't use the parameter, x264 will not mark the video in any way and video players will just have to guess. They most likely guess TV range.
__________________
Buy me a "coffee" and/or hire me to write code! |
|
14th November 2019, 17:59 | #98 | Link |
Registered User
Join Date: Jul 2019
Location: Russia
Posts: 87
|
When I try to use demux, I get crash to desktop, the empty (0 byte) index file and video in the m2v container.
When I run in the terminal, I get the messages: Code:
kf5.kio.core: We got some errors while running testparm "Load smb config files from /etc/samba/smb.conf\nError loading services.\n" kf5.kio.core: We got some errors while running 'net usershare info' kf5.kio.core: "Can't load /etc/samba/smb.conf - run testparm to debug it\n" qt.qpa.xcb: QXcbConnection: XCB error: 3 (BadWindow), sequence: 11792, resource id: 37058093, major code: 40 (TranslateCoords), minor code: 0 Segmentation error (memory stack flushed to disk) https://aur.archlinux.org/packages/d2vwitch-git/ Still would like support mkv. Last edited by Jukus; 14th November 2019 at 18:53. |
30th November 2019, 15:46 | #99 | Link | |
unsigned int
Join Date: Oct 2012
Location: 🇪🇺
Posts: 760
|
Quote:
__________________
Buy me a "coffee" and/or hire me to write code! |
|
Thread Tools | Search this Thread |
Display Modes | |
|
|