AviSynth+ r2580
Various MP4 H264 input videos - some have audio track (usually aac), some don't.
I need to detect which videos do not have audio, so I can generate audio track using BlankClip.
I do not have any demuxers/splitters/decoders installed (like Halli or similar).
Tried the following source filters - test using a video with no audio track:
DirectShowsource = cannot read file: The source filter could not be loaded (for both video and audio).
LSMASHSource = LSMASHAudioSource = error, script break/stop: Failed to find first audio track
FFMS2
v00 = FFmpegSource2("video.mp4")
HasAudio(v00) = always False (even if video has audio track)
v00 = FFAudioSource("video.mp4") = error, script break/stop: No audio track found
So, how do I open any video (with sound, without sound) and detect audio track ?
PS: I just discovered try..catch statement , I'll try that.
PS2: try..catch + FFAudioSource worked, but I'm still waiting for other suggestions.
+ Reply to Thread
Results 1 to 19 of 19
-
Last edited by queensoft; 1st Mar 2018 at 08:13.
-
try...catch is good, there's also (v00.HasAudio && v00.AudioChannels>0 && v00.AudioRate>0)
-
Yes, I know about all Audio clip properties.
But none of them work.
Either I cannot open the file at all (LSMASHAudioSource, FFAudioSource)
Or when I open the file (FFmpegSource2), everything Audio related is False or zero, regardless of file having audio or not.
And I cannot find another source filter that can open a video like FFmpegSource2 (all tracks at once, NOT 2 separate command, one for video and one for audio).Last edited by queensoft; 1st Mar 2018 at 08:36.
-
Old ffms2 versions implemented it this way:
Code:function FFmpegSource2(string source, int "vtrack", int "atrack", bool "cache", \ string "cachefile", int "fpsnum", int "fpsden", int "threads", \ string "timecodes", int "seekmode", bool "overwrite", int "width", int "height", \ string "resizer", string "colorspace", int "rffmode", int "adjustdelay", \ bool "utf8", string "varprefix") { vtrack = default(vtrack,-1) atrack = default(atrack,-2) cache = default(cache,true) cachefile = default(cachefile,source+".ffindex") fpsnum = default(fpsnum,-1) fpsden = default(fpsden,1) threads = default(threads,-1) timecodes = default(timecodes,"") seekmode = default(seekmode,1) overwrite = default(overwrite,false) width = default(width,-1) height = default(height,-1) resizer = default(resizer,"BICUBIC") colorspace = default(colorspace,"") rffmode = default(rffmode,0) adjustdelay = default(adjustdelay,-1) utf8 = default(utf8,false) varprefix = default(varprefix, "") ((cache == true) && (atrack <= -2)) ? ffindex(source=source, cachefile=cachefile, \ indexmask=0, overwrite=overwrite, utf8=utf8) : (cache == true) ? ffindex(source=source, \ cachefile=cachefile, indexmask=-1, overwrite=overwrite, utf8=utf8) : nop v = ffvideosource(source=source, track=vtrack, cache=cache, cachefile=cachefile, \ fpsnum=fpsnum, fpsden=fpsden, threads=threads, timecodes=timecodes, \ seekmode=seekmode, rffmode=rffmode, width=width, height=height, resizer=resizer, \ colorspace=colorspace, utf8=utf8, varprefix=varprefix) a = (atrack <= -2) ? blankclip(audio_rate=0) : ffaudiosource(source=source, \ track=atrack, cache=cache, cachefile=cachefile, adjustdelay=adjustdelay, \ utf8=utf8, varprefix=varprefix) return audiodubex(v,a) }
About DirectShowsource: you have suitable filters installed? (e.g. LAV Filters) -
a = (atrack <= -2) ? blankclip(audio_rate=0)
return audiodubex(v,a)
Maybe that's why it always reported audio, even where there was none presnt.
I'm using latest versions or all programs/plugins.... -
Current versions have moved the FFmpegSource2() function from the avsi to the c plugin itself. I don't know if it still works like this.
Looking closer I think I may have read the code wrong anyways. I though atrack was coming from ffindex() but it is actually set by user. So it wouldn't work anyways. -
What's wrong with using try/catch?
Code:function GetVideoAndAudio(string filename) { v=LSMashVideoSource(filename) try { a=LSmashAudioSource(filename) } catch (e) { a=ColorBars() } AudioDub(v,a) }
-
Eventually, the script will be used under Linux (hopefully).
And processing speed is very important.
Already I'm loosing a few precious seconds with indexing (I'm 99% sure I don't need the indexing).
So, I don't want any other programs (like medianfo) or directshowsource filters.
I will eventually try to use AvxSynth, it already has FFMS2 included.
Yes, now I'm using try..catch. -
Why not MediaInfo? By default it only probes a very small part of the file. Same with ffmpeg or mkvmerge.
You could do something like:
ffmpeg -y -loglevel fatal -i "INPUT" -map 0:a:0 -to 00:00:05 -f wav /devl/null/
If there is no audio stream it will output
Code:Stream map '0:a:0' matches no streams. To ignore this, add a trailing '?' to the map.
Then second step is to add audio:
ffmpeg -i "INPUT" -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=48000 -shortest -c:v copy -c:a aac "OUTPUT"
If you are fine with PCM audio or re-encoding the audio you could do it in one step without testing first.
ffmpeg -i "INPUT" -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=48000 -shortest -c:v copy -c:a copy "OUTPUT" -
Good: mediainfo has linux version
Bad: I'm not sure me or my client have enough Linux knowledge to install/use it
I'm trying to avoid any other software, for speed and, why not, elegant coding.
I need to use AviSynth, to add subtitle overlay text.
I'm also adding original/new audio using AviSynth, not ffmpeg.
It looks like try..catch is the solution.
But I wonder why isn't there an elegant solution from AviSynth directly - I already posted problems above.... -
Yes, using ffmpeg only was my first choise, for version 1 of the script.
Plus imagemagick to create the overlay PNG (different input video resolutions meant I could not properly scale the size of the text directly from ffmpeg).
But AviSynth + ffmpeg is faster, much faster sometimes.
For example:
imagemagick + ffmpeg = 4.8x processing speed
avisynth + ffmpeg = 6.9x -
Yes, I know, don't worry.
I tried several versions of the script, but none of them worked properly.
Basically, it's like this: add a text overlay (multiple lines, across entire video), at an angle, same number of text lines, regardless of video resolution.
That means font size and line spacing are tied to input video resolution.
I was unable to get the input video resolution and use it to calculate everything else.
I ended up creating a huge overlay PNG with imagemagick.
Then scale2ref based on input video resolution, overlay (and cropped automatically), compress using ffmpeg.
Anyway, that's ancient history, it was solved, now problem is processing speed. -
Lots of text overlay can be done in ASS subtitle format. Then it should be scaled to video res automatically. (Just saying. Not trying to convince you.)
-
Yesh, I know about that too.
But, again, I had to know the input video resolution in advance, to set the video resolution and font size in ASS file.
Similar Threads
-
Avisynth for interlace problem
By lordsmurf in forum RestorationReplies: 5Last Post: 3rd Jan 2018, 08:08 -
Trim problem with AVISynth
By smike in forum EditingReplies: 5Last Post: 9th Aug 2016, 09:20 -
ImageSource Avisynth problem
By arthurm in forum Video ConversionReplies: 42Last Post: 17th Jun 2015, 22:12 -
AviSynth problem
By yaston in forum Video ConversionReplies: 16Last Post: 5th Jan 2015, 07:26 -
Avisynth Hysteria problem
By beav in forum Newbie / General discussionsReplies: 15Last Post: 3rd May 2013, 19:30