Author Topic: Hardsubbing video using Avisynth  (Read 1054 times)

Offline Bob2004

  • Member
  • Posts: 2562
Hardsubbing video using Avisynth
« on: August 14, 2012, 09:34:45 PM »
I'm trying to burn a bunch of anime to DVD at the moment for some friends, and am having a bit of trouble with the subtitles. Since its all full of typesetting and overlapping timestamps, my only realistic option for getting them onto DVD is hardsubbing them, but I've been having no end of problems getting it to work.

I've managed to solve most of them (I had a lot of problems finding a working version of VSFilter, and then there was no real documentation on how to use it, but I'm fairly sure I've figured it out), but now I can't get the resulting script to actually open in MPC (to check it actually works before burning it).

Firstly, this is my AVS script:

(click to show/hide)

As you can see the video has flac audio (24 bit 5 channel flac, to be precise), but as I understand it (and useful documentation for Avisynth seems to be few and far between, so I'm not 100% sure), so long as I have a decoder installed which allows FFDShow to decode flac (and I do), then it should be able to be decoded using DirectShowSource in Avisynth. However, when I try and run the script as above, MPC spends ages loading it, then throws up an error saying that it could not render some of the pins in the graph - specifically "ACM Wrapper::Output". It also gives a huge load of details, which look like this:

(click to show/hide)

The only useful documentation I've found on how to open flac files with Avisynth is to install madflac, but even after manually doing so, the problem still persists.

If I uncomment the two commented out lines and try that, the script just throws out an unspecified error for both DirectShowSource() commands.

Does anyone here have any experience with Avisynth, and maybe have any idea of how to fix this? It doesn't seem like it should be a particularly difficult thing to do, but it's caused me hours of frustration already, and I'm no closer to fixing it. I've tried to use Avisynth a few times now, and never once have I ever managed to get anything other than the most basic of scripts to work. It's really quite annoying.

Ooh, also, here's the mediainfo output for the file, if that makes it easier to identify the problem. I've extracted the only audio track I want (Audio #1), and the only sub track I want (Text #1), to separate files, to make life easier:

(click to show/hide)

Offline RedSuisei

  • Member
  • Posts: 326
Re: Hardsubbing video using Avisynth
« Reply #1 on: August 14, 2012, 09:45:18 PM »
I personally don't use directshowsource since it's known not to be frame-accurate, and I'm not in a position to try out how dss loads flac file with my computer, so I'd recommend trying out ffmpegsource2 to load the video and audio in avisynth. I've been using that for a while and it loads flac audio just fine. One issue is that when you first open the script, it'll create an index of the file which may take a few minutes (but it's what makes ffms2 frame-accurate).

Just to be sure, what's your avisynth version, and is it x86 or x64?
« Last Edit: August 14, 2012, 09:47:00 PM by RedSuisei »

Offline Bob2004

  • Member
  • Posts: 2562
Re: Hardsubbing video using Avisynth
« Reply #2 on: August 14, 2012, 10:25:47 PM »
2.5.8.5, and it's x86. Thanks for the suggestion, I'll give ffmpegsource2 a go now.

EDIT: Unfortunately, when I do "A = FFAudioSource(Clip+".flac")", it just gives me an error saying "FFAudioSource: Can't Parse File". Maybe there's something wrong with the audio, it wouldn't at all surprise me if THORA encoded it with some settings that go way beyond the specification or something. Maybe I'll try and transcode it into AC3 or something myself tomorrow and give that a go.
« Last Edit: August 14, 2012, 10:37:01 PM by Bob2004 »

Offline Temuthril

  • Member
  • Posts: 1140
Re: Hardsubbing video using Avisynth
« Reply #3 on: August 16, 2012, 08:53:33 AM »
Give eac3to a try if you're re-encoding audio to something else.

Offline revo

  • Member
  • Posts: 682
  • I Can Only Carry 50 Loli's at a Time
Re: Hardsubbing video using Avisynth
« Reply #4 on: August 16, 2012, 12:27:57 PM »
Give eac3to a try if you're re-encoding audio to something else.
yeah
eac3to rules :D
and FFvideosource is a must :)

Offline Bob2004

  • Member
  • Posts: 2562
Re: Hardsubbing video using Avisynth
« Reply #5 on: August 16, 2012, 03:54:29 PM »
Well, I've clearly found the root of the problem now - eac3to just tells me that "The format of the source file could not be detected", and when I try Clementine's transcoder it tells me "Could not initialise supporting library" (in fact, it turns out Clementine can't play the audio file at all).

So there's definitely something wrong with the audio track - MPC plays it absolutely fine, with no problems whatsoever, but it refuses to play nice with everything else. I guess I ought to try a few more encoders and see if any of them work. Since eac3to seems capable of demuxing MKV files, I'm giving that a go as well to see if it's a problem with mkvextract breaking the file (wouldn't be the first time, though it usually just truncates them at random when it does so, so I think it's unlikely).

Thanks for your help so far guys, I originally assumed it was a problem with Avisynth, but obviously not.

EDIT: After demuxing it again, eac3to now gives me this error: "The AC3 encoder received a non-supported data format (pcm, 5, 24, -)". So I guess it definitely is something to do with the way THORA encoded it.
« Last Edit: August 16, 2012, 04:05:28 PM by Bob2004 »

Offline Temuthril

  • Member
  • Posts: 1140
Re: Hardsubbing video using Avisynth
« Reply #6 on: August 16, 2012, 06:27:23 PM »
EDIT: After demuxing it again, eac3to now gives me this error: "The AC3 encoder received a non-supported data format (pcm, 5, 24, -)". So I guess it definitely is something to do with the way THORA encoded it.
eac3to has command line options to change bit depth, channel numbers, etc.

Offline revo

  • Member
  • Posts: 682
  • I Can Only Carry 50 Loli's at a Time
Re: Hardsubbing video using Avisynth
« Reply #7 on: August 16, 2012, 06:31:41 PM »
if you don't like CLI you can use Useac3to GUI (it's very good)

Offline Bob2004

  • Member
  • Posts: 2562
Re: Hardsubbing video using Avisynth
« Reply #8 on: August 16, 2012, 06:44:43 PM »
EDIT: After demuxing it again, eac3to now gives me this error: "The AC3 encoder received a non-supported data format (pcm, 5, 24, -)". So I guess it definitely is something to do with the way THORA encoded it.
eac3to has command line options to change bit depth, channel numbers, etc.

That's the thing - it understood the file type, number of channels, etc correctly. I guess I should have posted the entire output:

Quote
E:\Util\eac3to>eac3to "From_Up_On_Poppy_Hi ll_(2011)_[1080p,BluRay,flac,x264]_-_THORA - 2 - FLAC, Japanese, 5.0 channels, 13051, 24 bits, 48kHz.flac" audio.ac3 -320 -down2 -mixlfe
FLAC, 5.0 channels, 1:30:51, 24 bits, 3163kbps, 48kHz
Decoding FLAC...
The AC3 encoder received a non-supported data format (pcm, 5, 24, -).
Aborted at file position 262144.

I've bolded the key bit - that line is absolutely correct, and matches the output from mediainfo I posted in the OP. So even though it can tell what kind of file it is, it just can't decode it properly. Trying to encode it into MP3 or ogg instead just gives a "This audio conversion is not supported." error.

Offline Temuthril

  • Member
  • Posts: 1140
Re: Hardsubbing video using Avisynth
« Reply #9 on: August 16, 2012, 11:49:57 PM »
Try -down2 -down16 just in case.

Also try making the following AviSynth script:
Code: [Select]
DirectShowSource("video.mkv")
Then open it in VirtualDub for example and save the audio track as wav.
If you're using CCCP, by default ffdshow should output the audio as 16 bit stereo.

Online Pentium100

  • Member
  • Posts: 528
Re: Hardsubbing video using Avisynth
« Reply #10 on: August 18, 2012, 01:50:22 AM »
As I understand, you have video, audio and subtitles all as separate files.

In that case, why not just process the video and subtitles and mux in the audio later?

If you are making an actual DVD-Video (not HD), resize the video and add subs, saving it as mpeg2 file, then convert the audio to LPCM (.wav) and then leave it as is or convert it to Dolby Digital or DTS. Now mux the video and audio and record to DVD.
BBT Ika Musume Fanclub Member #080586
Misaka Mikoto Fanclub Member:080586

Offline Bob2004

  • Member
  • Posts: 2562
Re: Hardsubbing video using Avisynth
« Reply #11 on: August 18, 2012, 12:28:00 PM »
Well, I need to make an actual DVD-video, and therein lies the problem - I obviously need to convert the audio to a supported format, regardless of whether I do it through Avisynth or a separate encoder. The problem is that neither is working.

That said, I guess I'll try encoding it to DTS and LPCM as well. Since no other format I've tried has worked, I'm assuming they won't either, but it's worth a try I suppose.

EDIT: Yep, DTS didn't work either.

EDIT 2: Weirdly, encoding to a wav file actually did work! I can play the resulting audio fine in Windows Media Player and Clementine, which I couldn't with the original flac file. Unfortunately, FFAudioSource doesn't like it, and just outputs a load of static when I load it thrugh my AVS script. On the other hand, just loading the video file through AVS and having MPC load the audio itself works perfectly. So I guess my next step is to try and encode it to DVD like this, and see if it works.
« Last Edit: August 18, 2012, 12:37:49 PM by Bob2004 »

Online Pentium100

  • Member
  • Posts: 528
Re: Hardsubbing video using Avisynth
« Reply #12 on: August 18, 2012, 04:17:41 PM »
I can play the resulting audio fine in Windows Media Player and Clementine, which I couldn't with the original flac file.
So, you do not have a flac source filter, which is probably why DirectShowSource failed.

Quote
Unfortunately, FFAudioSource doesn't like it, and just outputs a load of static when I load it thrugh my AVS script.
Most likely the file got encoded to DTS format, so it appears as stereo to software that does not support DTS. If you have FFDshow (CCCP), you can set the audio decoder to process .wav files and it should make it work in Windows Media Player or as DirectShowSource.
BBT Ika Musume Fanclub Member #080586
Misaka Mikoto Fanclub Member:080586

Offline Bob2004

  • Member
  • Posts: 2562
Re: Hardsubbing video using Avisynth
« Reply #13 on: August 18, 2012, 06:01:50 PM »
I can play the resulting audio fine in Windows Media Player and Clementine, which I couldn't with the original flac file.
So, you do not have a flac source filter, which is probably why DirectShowSource failed.

No, I do. And I can play other flac files fine; it was just that one.

Quote
Quote
Unfortunately, FFAudioSource doesn't like it, and just outputs a load of static when I load it thrugh my AVS script.
Most likely the file got encoded to DTS format, so it appears as stereo to software that does not support DTS. If you have FFDshow (CCCP), you can set the audio decoder to process .wav files and it should make it work in Windows Media Player or as DirectShowSource.

FFDShow is already set to process LPCM files, and it already works in WMP. It's only when loaded through Avisynth that it fails to work - whether using FFDAudioSource or DirectShowSource.

EDIT: Finally had a chance to try encoding the DVD, and lo and behold, it failed when it got to the audio (using the wav file). Didn't give me a particularly helpful error message, just "Unable to encode audio". I then tried converting the wav to another format, and it had the same problems as the original flac file - except for when I tried converting it back into flac, which worked fine.

So I then tried encoding the DVD audio again using this flac file, and it didn't work either. It got as far as calculating the audio delay, then I got a Windows error message telling me that it was unable to find the file C:\Program Files (x86)\DVD Flick\delaycut\delaycut.exe because "Access Denied, or File Not Found". Of course, that file is right there, and both me and DVD Flick have complete access to it, so I have no idea what caused it.

Anyway, TL;DR: It still won't work. I'm at the point where I figure it'd be easier just to give up and download a 480p release without this stupid flac audio and burn that instead.
« Last Edit: August 21, 2012, 12:40:10 PM by Bob2004 »