VideoHelp Forum




+ Reply to Thread
Results 1 to 19 of 19
  1. 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.
    Last edited by queensoft; 1st Mar 2018 at 08:13.
    Quote Quote  
  2. try...catch is good, there's also (v00.HasAudio && v00.AudioChannels>0 && v00.AudioRate>0)
    Quote Quote  
  3. 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.
    Quote Quote  
  4. 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)
    }
    Is this approach any better than try..catch? I have no idea.

    About DirectShowsource: you have suitable filters installed? (e.g. LAV Filters)
    Quote Quote  
  5. 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....
    Quote Quote  
  6. 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.
    Quote Quote  
  7. Is there some reason you can't use MediaInfo to tell you if there's an audio track, silent or not?
    Quote Quote  
  8. 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)
    }
    Or installing DirectShow filters that let you use DirectShowSource()?
    Quote Quote  
  9. 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.
    Quote Quote  
  10. Originally Posted by queensoft View Post
    So, I don't want any other programs (like medianfo)
    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.
    to stderr.
    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"
    Quote Quote  
  11. 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....
    Quote Quote  
  12. Originally Posted by queensoft View Post
    I need to use AviSynth, to add subtitle overlay text.
    ffmpeg can do that as well.

    If you are dead set on AviSynth I don't see any harm in using try..catch.
    Quote Quote  
  13. 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
    Quote Quote  
  14. You know ffmpeg has scaling filters, right?
    Quote Quote  
  15. 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.
    Quote Quote  
  16. 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.)
    Quote Quote  
  17. 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.
    Quote Quote  
  18. I don't understand. ASS scales automatically.
    Quote Quote  
  19. I'll look into that ,if needed.
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!