Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Video with sound #100

Closed
storeman opened this issue Aug 2, 2017 · 3 comments
Closed

Video with sound #100

storeman opened this issue Aug 2, 2017 · 3 comments

Comments

@storeman
Copy link

storeman commented Aug 2, 2017

I like your program. Although I found it quite difficult to find good documentation, I had to try a lot, but it seems to do everything what I want, except for one thing.

Video's are played, but without sound. It would be great to be able to play the complete video + sound. Am I missing something or why is this?

Another great feature, would be to add sounds to pictures. If there is a file with the same name, but another extension (say .wav, .mp3), it is played when the picture is shown.

Keep up the good work!

@phillipberndt
Copy link
Owner

I like your program. Although I found it quite difficult to find good documentation, I had to try a lot, but it seems to do everything what I want, except for one thing.

Let me know if you have any suggestions on how to improve the man page!

Video's are played, but without sound. It would be great to be able to play the complete video + sound. Am I missing something or why is this?

pqiv is an image viewer. Video support is only meant for animations, since it has become customary to replace animated gifs with mp4 and/or webm on the web. There are great video players out there. So great in fact that I won't dare to try and compete with them. → If you need videos with sound, and want a GUI similar to pqiv, use mpv!

Another great feature, would be to add sounds to pictures. If there is a file with the same name, but another extension (say .wav, .mp3), it is played when the picture is shown.

I won't add this, but I am willing to improve pqiv's extendibility towards this end. Let me know if you have a good suggestion for how this can be simplified. It is however already possible to achieve this. Try the following script:

#!/usr/bin/env python
# encoding: utf-8
import os
import subprocess
import sys

pqiv_process = subprocess.Popen(["pqiv", "--action=set_status_output(1)"] + sys.argv[1:], stdout=subprocess.PIPE)
mp3_player = False

while True:
    if pqiv_process.poll() != None:
        break
    status_line = pqiv_process.stdout.readline().strip()
    if status_line.startswith("CURRENT_FILE_NAME="):
        file_name = status_line[19:-1]

        if mp3_player and mp3_player.poll() is None:
            mp3_player.terminate()

        mp3_name = "%s.mp3" % os.path.splitext(file_name)[0]

        if os.path.isfile(mp3_name):
            mp3_player = subprocess.Popen(["mpv", "-loop", mp3_name])

if mp3_player and mp3_player.poll() is None:
    mp3_player.terminate()

and run pqiv using this script, passing any arguments you'd normally pass to pqiv to it instead. It'll play any file named as the image, but with extension mp3, using mpv.

@storeman
Copy link
Author

storeman commented Aug 7, 2017

Thanks for your answer. This will do. I had a hard time getting everything to work as I wanted. Because your script starts and stops the audio for every file, which causes a delay on my Windows system using a network drive where the programs and files are located.

We are using this to create awesome presentations with hi-res photo's. Lots of programs can't handle about 100 pictures on Full-HD. So just watching images is a good solution for this, but we would like to enrich it a little.

I noticed the video quality is not very good on the pqiv native play back. It also looks like it's a bit slower than mpv. For the intro movie I tried to use MPV started and stopped by pqiv, but this is a hard thing to do.

Now i've got this, I use a pipe to give command to MPV, this gives instant results when playing back audio. Now it also plays the audio from a movie. This is not good for lip-synced content, but just for some music, it is good enough.

#!/usr/bin/env python
# encoding: utf-8
import os
import subprocess
import time
import sys

pqivPath = os.path.dirname(os.path.abspath(__file__)) + '\pqiv.exe'
mpvPath = os.path.dirname(os.path.abspath(__file__)) + '\MPV\mpv.exe'
mpvSocketPath = os.path.dirname(os.path.abspath(__file__)) + '\mpvcmd.bat'
video = os.path.dirname(os.path.abspath(__file__)) + '\..\Videos\Timescapes.mp4'

# The named pipe on windows, use the bat file to control this. Don't know how to write to named pipe on windows using python.
FIFO = "\\\\.\\pipe\\mpvsocket"

# Start core processes, also start mpv, so it should instantanously start the audio/movie file
pqiv_process = subprocess.Popen([pqivPath, "--action=set_status_output(1)", "--actions-from-stdin"] + sys.argv[1:], stdout=subprocess.PIPE)
mpv = subprocess.Popen([mpvPath, "--idle", "--no-video", "--input-ipc-server=" + FIFO], stdout=subprocess.PIPE)

# Start the video later, so it will be above the presentation
time.sleep(2)
mpvVideo = subprocess.Popen([mpvPath, "--fullscreen", video], stdout=subprocess.PIPE)

while True:
    if pqiv_process.poll() != None:
        print "breaking"
        break
        
    status_line = pqiv_process.stdout.readline().strip()
    
    if status_line.startswith("CURRENT_FILE_NAME="):
        subprocess.Popen([mpvSocketPath, 'stop'], stdout=subprocess.PIPE)
        file_name = status_line[19:-1]
        
        mp3_name = "%s.mp3" % os.path.splitext(file_name)[0]
        
        if os.path.isfile(mp3_name):
            subprocess.Popen([mpvSocketPath, 'loadfile', mp3_name, 'replace'], stdout=subprocess.PIPE)
        
        if file_name[-4:] == '.mp4' or file_name[-4:] == '.avi' or file_name[-4:] == '.mkv':
            subprocess.Popen([mpvSocketPath, 'loadfile', file_name, 'replace'], stdout=subprocess.PIPE)

mpvVideo.terminate()
mpv.terminate()

Where the "mpvcmd.bat" looks like this:
@>\\.\pipe\mpvsocket echo %*

An example to control pqiv and a script like above, are nice to see and could really get people started easier with somewhat more complex things.

@phillipberndt
Copy link
Owner

I noticed the video quality is not very good on the pqiv native play back. It also looks like it's a bit slower than mpv. For the intro movie I tried to use MPV started and stopped by pqiv, but this is a hard thing to do.

Yes, that can happen. pqiv uses a rendering pipeline that is uncommon for video (ffmpeg renders to an offscreen buffer, that buffer is scaled using cairo and then drawn). This is a consequence of pqiv being focused on displaying images and unfortunately something that won't change in the near future.

An example to control pqiv and a script like above, are nice to see and could really get people started easier with somewhat more complex things.

Good idea. I'll add something to the manpage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants