Open cbitterfield opened 4 years ago
I've the exact same problem and after some research I think that this kind of filters (judging by their syntax in vanilla ffmpeg) are only operating on inputs (-i parameter). Here is an example usage for such filter:
ffmpeg -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=44100 -i video.mov \ -shortest -c:v copy -c:a aac output.mov
Basically when you use audio.filter() you operate on some input that is defined as audio stream. That stream can only be a file from your PC that you provide file path for, or a stream taken out of your video.
It is worth to mention that there is #62 that I think would solve that problem but somehow it got stuck. It would be really nice if @kkroening could say anything about that.
I think the best way to solve that for now is to provide some dummy audio file and expanding its range to fit the video length.
Hmm, yeah we really should get #62 mergeable since it's a commonly requested feature. There are a few changes that are still needed on that branch, so I'll bump up the priority of it in my TODO list and try to get to it soon 🙂
Hey @kkroening! Any updates on this? Having issues using anullsrc
too.
@kkroening @jbitton here is a code snippet for adding null audio
def generate_empty_audio(duration):
"""
it is used to generate an empty audio
Parameters
----------
duration : int/float
duration for the blank audio
Return
------
string
it will return the path of the generated empty audio
"""
try:
path = settings.MEDIA_ROOT + f"{str(uuid4())}_audio.aac"
stream = ffmpeg.input("anullsrc=cl=stereo:r=44100").output(path)
compiled = ffmpeg.compile(stream.audio, overwrite_output=True)
ffmpegargs = patch_audio(compiled, duration)
subprocess.run(ffmpegargs, stdout=subprocess.PIPE)
empty_audio.append(path)
return path
except ffmpeg.Error as e:
print(e.stderr)
raise Exception(str(e))
def patch_audio(arglist, duration):
"""
to make the command of ffmpeg for creation of blank audio
Parameters
----------
arglist : list
list of commands created by the python-ffmpeg
duration : int/float
duration for the blank audio
Return
------
list
it will return the list of command that would be compiled in the process.run
"""
try:
for i, arg in enumerate(arglist):
if arg == 'anullsrc=cl=stereo:r=44100':
return arglist[:i-1] + ['-f', 'lavfi'] + ['-t', f"{duration}"] + arglist[i-1:]
return arglist
except Exception as identifier:
raise Exception(str(identifier))
If you guys just want to add the pause in the start you can use for video set_pts(f"PTS-STARTPTS"+{<time in seconds here>/TB})
and for audio filter_('adelay', <time in miliseconds>)
audio_cmd = 'anullsrc=r=16000:cl=mono:d={}'.format(duration)
audio_stream = ffmpeg.input(audio_cmd, f='lavfi')
I add anullsrc
in ffmpeg-python like above and works for me, in case anyone is still looking for solution to this in 2022
I am trying to convert DVD (VOB) files into an MP4. The first 2 files, don't have an audio track.
What is the proper syntax for adding an "anullsrc" audio track to video streams that do not have one, prior to concatenation?
ffmpeg command generate:
This produces the following errors.