Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 14th November 2015, 06:18   #1  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,560
Encoding AVS Script with FFMPEG

I've been encoding AVS scripts with x264.exe successfully. Now I'm trying to do so with FFMPEG, since it contains x264.

Here's my command

ffmpeg -i Source.avs -c:v libx264 -preset veryslow -crf 24 "Output.264"

Here's the output. What's going on here?

Code:
ffmpeg version N-76637-gedd0c1d Copyright (c) 2000-2015 the FFmpeg developers
  built with gcc 5.2.0 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libdcadec --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-decklink --enable-zlib
  libavutil      55.  5.100 / 55.  5.100
  libavcodec     57. 15.100 / 57. 15.100
  libavformat    57. 14.100 / 57. 14.100
  libavdevice    57.  0.100 / 57.  0.100
  libavfilter     6. 15.100 /  6. 15.100
  libswscale      4.  0.100 /  4.  0.100
  libswresample   2.  0.101 /  2.  0.101
  libpostproc    54.  0.100 / 54.  0.100
F:\NaturalGrounding\Temp\Job1_Script.avs: Unknown error occurred
If I instead set the source to the AVI file, then it works.
MysteryX is offline   Reply With Quote
Old 14th November 2015, 07:28   #2  |  Link
qyot27
...?
 
qyot27's Avatar
 
Join Date: Nov 2005
Location: Florida
Posts: 1,445
That points to a bad install or some other situation where FFmpeg can't see that AviSynth is installed. That's exactly the error I get here when I rename AviSynth.dll to AviSynth.dll.bak so that FFmpeg can't load it.

If it was an incorrect version it would tell you because the interface version check would fail and print an error message, and if it was a plugin or other internal issue then it'd be reported like any other demuxer message FFmpeg reports [avisynth @ address] message from FFmpeg or AviSynth.

Code:
>ffmpeg -v 9 -loglevel 99 -i test.avs
ffmpeg version N-76642-g2f90197 Copyright (c) 2000-2015 the FFmpeg developers
  built on Nov 11 2015 14:14:43 with gcc 5.2.0 (GCC)
  libavutil      55.  5.100 / 55.  5.100
  libavcodec     57. 15.100 / 57. 15.100
  libavformat    57. 14.100 / 57. 14.100
  libavdevice    57.  0.100 / 57.  0.100
  libavfilter     6. 15.100 /  6. 15.100
  libavresample   3.  0.  0 /  3.  0.  0
  libswscale      4.  0.100 /  4.  0.100
  libswresample   2.  0.101 /  2.  0.101
  libpostproc    54.  0.100 / 54.  0.100
Splitting the commandline.
Reading option '-v' ... matched as option 'v' (set logging level) with argument '9'.
Reading option '-loglevel' ... matched as option 'loglevel' (set logging level) with argument '99'.
Reading option '-i' ... matched as input file with argument 'test.avs'.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option v (set logging level) with argument 9.
Successfully parsed a group of options.
Parsing a group of options: input file test.avs.
Successfully parsed a group of options.
Opening an input file: test.avs.
[avisynth @ 056936a0] Format avisynth probed with size=2048 and score=50
[avisynth @ 056936a0] Before avformat_find_stream_info() pos: 0 bytes read:55 seeks:0
[avisynth @ 056936a0] All info found
[avisynth @ 056936a0] 0: start_time: 0.000 duration: 0.001
[avisynth @ 056936a0] 1: start_time: 0.000 duration: 2.658
[avisynth @ 056936a0] stream: start_time: 0.000 duration: 60.279 bitrate=0 kb/s
[avisynth @ 056936a0] After avformat_find_stream_info() pos: 0 bytes read:55 seeks:0 frames:3
Guessed Channel Layout for  Input Stream #0.1 : stereo
Input #0, avisynth, from 'test.avs':
  Duration: 00:01:00.28, start: 0.000000, bitrate: 0 kb/s
    Stream #0:0, 2, 1001/24000: Video: rawvideo, 1 reference frame (I420 / 0x30323449), yuv420p, 1920x816, 1001/24000, 23.98 fps, 23.98 tbr, 23.98 tbn, 23.98 tbc
    Stream #0:1, 1, 1/44100: Audio: pcm_f32le, 44100 Hz, 2 channels, flt, 2822 kb/s
Successfully opened the file.
At least one output file must be specified
[AVIOContext @ 0496dc40] Statistics: 55 bytes read, 0 seeks

>
Windows 10 Home 32-bit, AviSynth+ r1825


(note: that build has some extra patches in it, so it's actually maybe one or two commits behind yours, rather than five ahead)

Last edited by qyot27; 14th November 2015 at 07:32.
qyot27 is offline   Reply With Quote
Old 14th November 2015, 08:34   #3  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,560
OMG I have such a brillant idea.

How about using a 32-bit version of FFMPEG?

That works :-)
MysteryX is offline   Reply With Quote
Old 14th November 2015, 15:33   #4  |  Link
Motenai Yoda
Registered User
 
Motenai Yoda's Avatar
 
Join Date: Jan 2010
Posts: 709
or you can pipe from avs2yuv to ffmpeg
Code:
"%~dp0avs2yuv_x86.exe" Source.avs - | "%~dp0ffmpeg.exe" -y -i - -c:v libx264 -preset veryslow -crf 24 "Output.264"
__________________
powered by Google Translator
Motenai Yoda is offline   Reply With Quote
Old 14th November 2015, 17:53   #5  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,560
Yes, that's the next step; I first test it out without pipe first. That's why I had the x64 file there and it slipped by.
MysteryX is offline   Reply With Quote
Old 14th November 2015, 19:27   #6  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,560
Thanks Motenai Yoda for the command, it helped me get the Pipe version working.

I really prefer the progress output of x264.exe than of ffmpeg. Is there a way to get that output? Or any way to get "Estimated time left"? For a 1 hour job, I want to know how much longer it will take.
MysteryX is offline   Reply With Quote
Old 15th November 2015, 06:23   #7  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,560
How do you encode the audio?

Here's my command. It ignores the audio.

cmd /c Encoder\avs2yuv.exe "F:\NaturalGrounding\Temp\Job6_Script.avs" -o - | Encoder\ffmpeg.exe -y -i - -c:a copy -c:v libx264 -preset veryslow -crf 24 "F:\NaturalGrounding\Temp\Job6_Output.mkv" -frames 600

I also tried with "-acodec pcm_s16le", which doesn't help any more.
MysteryX is offline   Reply With Quote
Old 15th November 2015, 06:42   #8  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,992
Quote:
I also tried with "-acodec pcm_s16le", which doesn't help any more
Of course not, you are telling it to convert to PCM (uncompressed, which it probably already is as you used that before)

You could take a look here, until someone can tell you exactly what you want. https://trac.ffmpeg.org/wiki/Encode/AAC
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 15th November 2015, 06:53   #9  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,560
I want to encode the audio with Nero AAC Encoder, which requires a PCM input. How do I get that?
MysteryX is offline   Reply With Quote
Old 15th November 2015, 06:59   #10  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,992
I guess that you need to encode audio separately then, and then mux.
See The nero docs for use.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 15th November 2015, 07:01   #11  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,992
Here:-

Code:
*************************************************************
*                                                           *
*  Nero AAC Encoder                                         *
*  Copyright 2009 Nero AG                                   *
*  All Rights Reserved Worldwide                            *
*                                                           *
*  Package build date: Feb 18 2010                          *
*  Package version:    1.5.4.0                              *
*                                                           *
*  See -help for a complete list of available parameters.   *
*                                                           *
*************************************************************

Usage:
neroaacenc [options] -if <input-file> -of <output-file>
Where:
<input-file>  : Path to source file to encode.
                The file must be in Microsoft WAV format and contain PCM data.
                Specify - to encode from stdin.
                Note that multiple input files can be specified, they will be
                encoded together into a single output file with chapter marks
                indicating source file divisions.
<output-file> : Path to output file to encode to, in MP4 format.

  ==== Available options: ====

Quality/bitrate control:
-q <number>   : Enables "target quality" mode.
                <number> is a floating-point number in 0...1 range.
-br <number>  : Specifies "target bitrate" mode.
                <number> is target bitrate in bits per second.
-cbr <number> : Specifies "target bitrate (streaming)" mode.
                <number> is target bitrate in bits per second.
                When neither of above quality/bitrate options is used,
                the encoder defaults to equivalent of -q 0.5

Multipass encoding:
-2pass        : Enables two-pass encoding mode.
                Note that two-pass more requires a physical file as input,
                rather than stdin.
-2passperiod  : Overrides two-pass encoding bitrate averaging period,
  <number>    : in milliseconds.
              : Specify zero to use least restrictive value possible (default).

Advanced features / troubleshooting:
-lc           : Forces use of LC AAC profile (HE features disabled).
-he           : Forces use of HE AAC profile (HEv2 features disabled).
-hev2         : Forces use of HEv2 AAC profile
                Note that the above switches (-lc, -he, -hev2) should not be
                used; optimal AAC profile is automatically determined from
                quality/bitrate settings when no override is specified.
-ignorelength : Ignores length signaled by WAV headers of input file.
                Useful for certain frontends using stdin.
EDIT: Requires WAV input, need to use ffmpeg or TWriteAVI plugin TWriteWAV function to create WAV.

EDIT: Here similar to previously given Bat file to extract to WAV

Code:
setlocal

REM Where to Find ffmpeg
set FFMPEG="C:\BIN\ffmpeg.exe"

REM Where to get input file, No terminating Backslash, "." = current directory
set INDIR="."


REM Where to place output file, No terminating Backslash.
set OUTDIR=".\OUTPUT"


FOR %%A IN (*.wmv *.mpg *.avi *.flv *.mov *.mp4 *.m4v *.RAM *.RM) DO (
  %FFMPEG% -i "%INDIR%\%%A" -vn -acodec pcm_s16le "%OUTDIR%\%%~nxA.WAV"

)

Pause
You can replace "-acodec pcm_s16le" with "-an" in Video to AVI bat to avoid having audio in the AVI.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 15th November 2015 at 07:12.
StainlessS is offline   Reply With Quote
Old 15th November 2015, 09:45   #12  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,560
Another quick question. Can FFMPEG create a MP4 container around the H264 stream in one command? Because with x264, it outputs only the raw stream and it then has to be muxed into a container afterwards.
MysteryX is offline   Reply With Quote
Old 15th November 2015, 16:38   #13  |  Link
Motenai Yoda
Registered User
 
Motenai Yoda's Avatar
 
Join Date: Jan 2010
Posts: 709
for audio I think is an avs2yuv thing, what you can do?
add soundout into the avs to get audio into a wav file when encoding the video
encode it with naac or fdkaac or qaac, both better than naac
then mux the audio using another input argument for ffmpeg as
ffmpeg -i video.h264 -i audio.m4a -map 0:v -map 1:a -c copy output.mp4

but using x86 bin even just encode the audio too as pcm
and using ffmpeg pipe it to naac/fdkaac/qaac
mux
__________________
powered by Google Translator
Motenai Yoda is offline   Reply With Quote
Old 15th November 2015, 17:07   #14  |  Link
vivan
/人 ◕ ‿‿ ◕ 人\
 
Join Date: May 2011
Location: Russia
Posts: 643
Quote:
Originally Posted by MysteryX View Post
Because with x264, it outputs only the raw stream and it then has to be muxed into a container afterwards.
Unless you're using crippled builds from videolan, x264 totally can output mp4.

As for neroaac and ffmpeg http://sound.stackexchange.com/a/23246

Last edited by vivan; 15th November 2015 at 17:18.
vivan is offline   Reply With Quote
Old 15th November 2015, 17:48   #15  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,434
Quote:
Originally Posted by MysteryX View Post
Another quick question. Can FFMPEG create a MP4 container around the H264 stream in one command? Because with x264, it outputs only the raw stream and it then has to be muxed into a container afterwards.
Yes it can, but the "non free" versions have very poor AAC audio. If you build it yourself with --enable-nonfree you can use FDKAAC with --enable-libfdkaac

There are modified old x264 versions that can process audio (look for taro's tmod builds), but none recently, only old ones
poisondeathray is offline   Reply With Quote
Old 15th November 2015, 20:07   #16  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,560
From the search I've done, not only does FFMPEG have to be custom-built to have AAC support (which I did), but Nero also provides better quality. I think FDKAAC then got better but only for low-quality audios?
MysteryX is offline   Reply With Quote
Old 15th November 2015, 20:36   #17  |  Link
Motenai Yoda
Registered User
 
Motenai Yoda's Avatar
 
Join Date: Jan 2010
Posts: 709
Quote:
Originally Posted by poisondeathray View Post
Yes it can, but the "non free" versions have very poor AAC audio. If you build it yourself with --enable-nonfree you can use FDKAAC with --enable-libfdkaac
nope all ffmpeg can output in mp4 mkv ecc containers, even x264 itself can output yet muxed stream but cannot include some encoders
__________________
powered by Google Translator
Motenai Yoda is offline   Reply With Quote
Old 15th November 2015, 20:50   #18  |  Link
qyot27
...?
 
qyot27's Avatar
 
Join Date: Nov 2005
Location: Florida
Posts: 1,445
Quote:
Originally Posted by MysteryX View Post
OMG I have such a brillant idea.

How about using a 32-bit version of FFMPEG?

That works :-)
Or the 64-bit version of AviSynth+ r1825 so that the FFmpeg build matches. May be a little limited on plugins, but there is a running list of compatible ones on the AviSynth+ page on the avisynth.nl wiki.

Quote:
Originally Posted by Motenai Yoda View Post
for audio I think is an avs2yuv thing, what you can do?
add soundout into the avs to get audio into a wav file when encoding the video
encode it with naac or fdkaac or qaac, both better than naac
then mux the audio using another input argument for ffmpeg as
ffmpeg -i video.h264 -i audio.m4a -map 0:v -map 1:a -c copy output.mp4

but using x86 bin even just encode the audio too as pcm
and using ffmpeg pipe it to naac/fdkaac/qaac
mux
The -map parameter is completely unnecessary when there's only one video and one audio input. Just saying.

Quote:
Originally Posted by poisondeathray View Post
Yes it can, but the "non free" versions have very poor AAC audio. If you build it yourself with --enable-nonfree you can use FDKAAC with --enable-libfdkaac

There are modified old x264 versions that can process audio (look for taro's tmod builds), but none recently, only old ones
Quote:
Originally Posted by MysteryX View Post
From the search I've done, not only does FFMPEG have to be custom-built to have AAC support (which I did), but Nero also provides better quality. I think FDKAAC then got better but only for low-quality audios?
I've not done any listening tests, but I would assume that given enough bitrate, the quality issues that the free encoders might be subject to would eventually disappear. Basically, if you use vo_aacenc or the native aac encoder, just use 320kbps or whatever the upper limit on AAC is. And there have been a lot of recent (July-October of this year) commits to the native AAC encoder, but where all of those put the native encoder in the rankings now I don't know.

Although if you're not married to the idea of requiring AAC in the final encode, you could always use Vorbis or Opus and output to an MKV file instead.
qyot27 is offline   Reply With Quote
Old 15th November 2015, 21:16   #19  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,560
Quote:
Originally Posted by qyot27 View Post
Or the 64-bit version of AviSynth+ r1825 so that the FFmpeg build matches. May be a little limited on plugins, but there is a running list of compatible ones on the AviSynth+ page on the avisynth.nl wiki.
AviSynth+ doesn't yet have a MT version that is functional. The performance loss of not using MT would nullify any benefit to using x64 processing.

I was wondering why they couldn't just get the MT version working until I tried creating some threads in C++, at which point I realized that multi-threaded programming in C++, especially when you don't want to create locks, is a huge mess that even experts get lost with. Because the C++ compiler has no awareness of threads, when it compiles multi-threaded code, the order of operations is random, what you see happening is random, memory data gets corrupted and the behavior is "undefined". Working your way to fix bugs from there is extremely hard. Some C++ experts even say that there is no such thing as bug-free multi-threaded C++ programs.

Let's hope someone will make AviSynth+ MT work some day; without crashing on NNEDI3 plugin.


Quote:
Originally Posted by qyot27 View Post
I've not done any listening tests, but I would assume that given enough bitrate, the quality issues that the free encoders might be subject to would eventually disappear. Basically, if you use vo_aacenc or the native aac encoder, just use 320kbps or whatever the upper limit on AAC is. And there have been a lot of recent (July-October of this year) commits to the native AAC encoder, but where all of those put the native encoder in the rankings now I don't know.
Of course if you encode low-quality audio with a bitrate way too high, you won't get as much quality loss. To compare 2 encoders, it has to be compared at the same bitrate.

Quote:
Originally Posted by qyot27 View Post
Although if you're not married to the idea of requiring AAC in the final encode, you could always use Vorbis or Opus and output to an MKV file instead.
If I'm not married to using AAC audio in a MP4 container, then I'll muxe the original audio back into the processed video into a MKV container. No re-encoding = best quality.

If I want to have a standard MP4 file, however, then that's where re-encoding becomes useful.
MysteryX is offline   Reply With Quote
Old 15th November 2015, 21:21   #20  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,560
Quote:
Originally Posted by StainlessS View Post
Requires WAV input, need to use ffmpeg or TWriteAVI plugin TWriteWAV function to create WAV.
Using TWriteWAV is the simplest option. How convenient that you just got it done last week!

Edit: ah great... it doesn't support MT

Edit2: Is this the right way to do it? Removing MT code and appending to the end of the script file
Code:
TWriteWAV("F:\NaturalGrounding\Temp\Job1_Output.wav", true)
ForceProcessWAV()
and then call
Code:
avs2yuv.exe "Job1_Script.avs" -o -
It returns an error because there is no output video, but the WAV file is there.

Edit3: Got it working. All that's left is to encode WAV into AAC before muxing.

Last edited by MysteryX; 15th November 2015 at 23:07.
MysteryX is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:50.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.