Transcoding with python bindings; result won't play.
Posted: 22 Apr 2017 22:57
Originally posted to a different forum, but no responses there and seems more appropriate here...
I already use the python bindings for VLC in a PyQt5 Windows application for displaying video, and I've started to experiment with using the same bindings for transcoding. I'm using the following code to transcode various videos into mp4. The code seems to run and I end up with video files which seem about the correct size, but they will not play:
def transcode(source_path, destination_path):
"""transcode video files with varying formats to mp4 video files"""
cmd = "--sout=#transcode{venc=x264,vcodec=h264}:std{access=file,mux=mp4,dst=%s}" % destination_path
instance = vlc.Instance(cmd)
transcoder = instance.media_player_new()
transcoder.set_mrl(source_path)
transcoder.play()
The same cmd line will work fine when run from a console window, which puzzles me as to why my other code doesn't. Any suggestions? Thanks.
I'm starting to think that transcoding 'may' be working okay but that something is holding onto the video files and/or the destination file isn't being closed properly; I can't delete the file until I've closed my application, which is making me think this way. Sorry if anyone is reading this for a second time, but if anyone has any ideas I would be grateful to hear them. Thank you.
I already use the python bindings for VLC in a PyQt5 Windows application for displaying video, and I've started to experiment with using the same bindings for transcoding. I'm using the following code to transcode various videos into mp4. The code seems to run and I end up with video files which seem about the correct size, but they will not play:
def transcode(source_path, destination_path):
"""transcode video files with varying formats to mp4 video files"""
cmd = "--sout=#transcode{venc=x264,vcodec=h264}:std{access=file,mux=mp4,dst=%s}" % destination_path
instance = vlc.Instance(cmd)
transcoder = instance.media_player_new()
transcoder.set_mrl(source_path)
transcoder.play()
The same cmd line will work fine when run from a console window, which puzzles me as to why my other code doesn't. Any suggestions? Thanks.
I'm starting to think that transcoding 'may' be working okay but that something is holding onto the video files and/or the destination file isn't being closed properly; I can't delete the file until I've closed my application, which is making me think this way. Sorry if anyone is reading this for a second time, but if anyone has any ideas I would be grateful to hear them. Thank you.