View Full Version : Can't create mp4 from avs with ffmpeg


Starduster
5th October 2020, 21:57
I'm just trying to include a blank slide with a subtitle between clips using same size, fps,audio, etc.. I'm using the following (with and without the tone and audiodub):


fa=Tone(length=3.0, type="Silence", samplerate=30, channels=2)
v=BlankClip(90,1280,720)
sld=audiodub(v,fa)
sld=Subtitle(sld,"This is a test", align=5, size=24)
sld=sld.convertFPS(30)
sld=sld.ConvertToRGB32()
sld=sld.SSRC(22050, fast = True)
sld


It works fine in Media Player but when I try to save it as an mp4 with the following it's just a black screen.

ffmpeg -i clip.avs clip.mp4

Does anyone know what I'm doing wrong?

poisondeathray
6th October 2020, 15:16
What does the ffmpeg console output say ?

What format are the clips ? Ideally you'd want to match them. When I run that script and commandline I get AVC YUV444 and AAC audio

How are you checking the output video ? Some programs might not be able to play AVC in YUV444 configuration

Do you have x86 / x64 mismatch between ffmpeg, avisynth ?

You're sending RGB32, but by default ffmpeg will convert to YUV444 unless you use -c:v libx264rgb . Or you can add ConvertToYV12(matrix="rec709") in the script for typical usage 4:2:0

Selur
6th October 2020, 16:49
try changing the last line from 'sld' to 'return sld'

StainlessS
6th October 2020, 19:59
try changing the last line from 'sld' to 'return sld'

Dont think would make any difference at all.
Last line "sld" == "Last=sld", and implied "Return Last" at end of script, exactly same effect as "Return sld".

Think PDR got it all covered in his post.

Gavino
6th October 2020, 23:54
Dont think would make any difference at all.
Last line "sld" == "Last=sld", and implied "Return Last" at end of script, exactly same effect as "Return sld".
Yes, you're right, it makes no difference - but your reason is slightly off.
"sld" as the final statement in a block is simply defined to mean "return sld" - there is no implied "return last".
(It is a myth that "return last" is the default action, and there are some cases when 'last' is not returned, such as when the final expression is not a clip. See here (http://forum.doom9.org/showthread.php?p=1642079#post1642079).)

StainlessS
7th October 2020, 10:09
I stand corrected,
tis reassuring but also slightly disconcerting to know that you are constantly on 'my case',
waiting to spank me at the 1st opportunity. :)

Nice to see that you are still alive [comment on covid, not your age, but also nice for that too].

Starduster
9th October 2020, 18:35
Thanks guys, sorry about the delay... out of the office for a while. I started to answer PoisonDeathRay's questions but I thought I'd try to narrow things down first and found something... again that I don't understand. I set up a test to create an .mp4 from a single .avs with that code. I found that if I comment out the line, sld=sld.SSRC(22050, fast = True), it works! That's there to match all the other clips audio. So, why would that stop the subtitle from showing??

qyot27
9th October 2020, 20:27
It shouldn't, and I couldn't reproduce any of this here. The script as given, with or without the SSRC line commented out, when converted as demonstrated in the OP, still produces a video clip with the subtitle visible.

When it doesn't, is when trying to preview the script using ffplay (or mpv using the default vo=gpu), but that's a known quirk of how the alpha channel is initialized (https://github.com/AviSynth/AviSynthPlus/issues/171) and how libavformat responds to it.

BlankClip defaults to generating RGB32 clips, so omit ConvertToRGB32 entirely. You don't need it. You can fix the alpha issue by using RGBAdjust(ab=255).

You could also tell BlankClip to generate RGB24 using pixel_type="RGB24" and then follow it with AddAlphaPlane(), which makes it bgra but gives it the correct opacity value so that you can see what the video looks like:
fa=Tone(length=3.0, type="Silence", samplerate=22050, channels=2)
v=BlankClip(90,1280,720,pixel_type="RGB24",fps=30).AddAlphaPlane()
AudioDub(v,fa).Subtitle("This is a test", align=5, size=24)

Starduster
9th October 2020, 21:20
Get error... no function named AddAlphaPlane

qyot27
9th October 2020, 21:51
Then you need to upgrade. (https://forum.doom9.org/showthread.php?t=181351)

Starduster
10th October 2020, 13:46
I'm on 2.6.0... I thought that was the latest official build from http://avisynth.nl/index.php/Main_Page. is that not the right place?

Starduster
10th October 2020, 17:41
Ok, I uninstalled 2.6.0 and installed Avisynth+ 3.6.1, ran the code you posted in a file called gs_10.avs, and double-clicked the .avs, and it displays correctly. Then I used the following:

ffmpeg -i gs_10.avs gs_10.mp4

I have a black, blank screen. gyot27, I know you didn't have any trouble doing this so I'm not sure what I'm doing wrong!

qyot27
10th October 2020, 17:44
ffplay -i test.avs

If it doesn't show the subtitle, adjust the script.

Starduster
10th October 2020, 18:27
Oddly enough, ffplay works...

poisondeathray
11th October 2020, 05:02
what about ffplay to test playback of the output file ?

ffplay -i gs_10.mp4

Starduster
11th October 2020, 12:18
WTH?? Poisondeathray, that works! What does that mean?

poisondeathray
11th October 2020, 14:11
WTH?? Poisondeathray, that works! What does that mean?

see post #2

Your player that you used initially probably does not support YUV444

Add ConvertToYV12(matrix="rec709") in the script for "regular" 4:2:0 video that is more universally supported

Starduster
11th October 2020, 15:37
PDR, that worked! Was playing with WMP. Shame on me for not following ALL your instructions from the beginning. Humble thanks!!