3

Vapoursynth officially added audio support in September, and had it in testing before then. Since it now supports audio, I'm looking to convert over some old Avisynth projects to Vapoursynth. Part of this is driven by my familiarity with Python, and part of it is that it's far easier to set up Vapoursynth with QTGMC in my linux distro of choice.

Anyway, my problem is that when I run the script and pipe the result over to FFMPEG, FFMPEG only gets the video stream and not the audio stream. From a script standpoint, it looks like I should be doing everything right, but there is so little documentation on working with audio that I can't be sure. I'm leaning toward an issue with my vspipe command, but I'm not sure what needs to be done to say "There is audio in this stream"

Here is the script followed by the vspipe/ffmpeg command:

import vapoursynth as vs
import havsfunc as haf
import math
core = vs.core

# Assume NTSC standard framerate and 48kHz as default
def framesToSamples(frameNum, framerate=29.97, samplerate=48000):
    return math.floor((samplerate/framerate)*frameNum)  

video = core.ffms2.Source(r'Home Movies 1 - 1989.avi', format=vs.YUV422P8)
audio = core.bas.Source(r'Home Movies 1 - 1989.avi', track=1)

video = video[71:217640]
audio = audio[framesToSamples(71):framesToSamples(217640)]

video = core.cnr2.Cnr2(video,"ooo",8,16,191,100,255,32,255,False) #VHS
video = haf.QTGMC(video, Preset="Very Slow", EZDenoise=2.0, TrueMotion=True, ChromaMotion=True, TFF=False)
video = core.std.Crop(video,4,0,4,6)
video = core.resize.Lanczos(video, 352, 240, format=vs.YUV422P10)

video.set_output(0)
audio.set_output(1)

And the command to convert:

vspipe -c y4m "Home Movies 1 - 1989.vpy" - | ffmpeg -i pipe: -c:v libx265 -preset fast -crf 24 -c:a libopus -b:a 96k -ac 1 Test.mkv
Katherine1
  • 195
  • 1
  • 2
  • 14
  • At the moment, I'm finding that I can select one output stream from the script, but I can't pass both out at the same time, so I'm experimenting with processing the audio into its own file, and then pulling the audio in as a second input file when processing the video. If there is a better way, please say so, otherwise, I'll probably answer my own question once I have the final result to judge if it worked as expected. – Katherine1 Jan 05 '22 at 00:33

1 Answers1

3

From what I have been able to find, vspipe can select one output stream, but it can't output both at the same time. The result is that you end up having to do something like this:

vspipe -o 1 -c wav "Home Movies 1 - 1989.vpy" - | ffmpeg -i pipe: -c:a libopus -b:a 96k -ac 1 audio.opus
vspipe -o 0 -c y4m "Home Movies 1 - 1989.vpy" - | ffmpeg -i pipe: -i audio.opus -c:v libx265 -preset ultrafast -crf 24 -c:a copy "Home Movies 1 - 1989.mkv"
rm audio.opus

The first run produces the audio and places it into a temporary file. Then the second run processes the video and copies the audio into the final video file. Once that's done, the temporary audio file can be deleted.

Katherine1
  • 195
  • 1
  • 2
  • 14