Transcoding with python bindings; result won't play.

This forum is about all development around libVLC.
Timothy Grove
Blank Cone
Blank Cone
Posts: 33
Joined: 07 Sep 2011 13:17

Transcoding with python bindings; result won't play.

Postby Timothy Grove » 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.

Timothy Grove
Blank Cone
Blank Cone
Posts: 33
Joined: 07 Sep 2011 13:17

Re: Transcoding with python bindings; result won't play. [SOLVED]

Postby Timothy Grove » 26 Apr 2017 21:20

Okay, I seem to have SOLVED this. After the transcoding finished, I needed to release the media player. My amended method looks something like below:

import vlc

def transcode(self, source, destination):
args = [
"--sout=#transcode{venc=x264,vcodec=h264}:std{access=file,mux=mp4,dst=%s}" % destination,
"-I dummy",
"--dummy-quiet"
]

instance = vlc.Instance(*args)
transcoder = instance.media_player_new()
transcoder.set_mrl(source)
media = transcoder.get_media()

transcoder.play()

while True:
state = media.get_state()
if str(state) == 'State.Ended':
break

while True:
try:
transcoder.release()
except:
print('reference count 0')
break
else:
print('Decrement the reference count of the media player object')


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 22 guests