Initial D World - Discussion Board / Forums
   
Welcome Guest ( Log In | Register )Resend Validation Email

DJ Panel ( Server Stats )   Song History   Initial D World Chat Room (Discord)   Broadband Stream
RADIO BROADCAST » streaming at 96kbps with 6 unique listeners, playing Karen - Fly in the Sky

       

  Important Rules
• Please do NOT post knowingly false information. Violators will be issued an actual warning.
• Please do NOT copy and paste articles from other websites. Link and short description is ok, but please do not copy and paste pages of info. Violator will be issued a verbal warning.
• Do NOT post any torrents and/or links to pirated copies of software here. Violator will be issued a verbal warning.
• Discussions about illegal materials such as ROMs, WAREZ and methods of copying copyrighted materials are not encouraged in this subforum.

» FORUM MODERATOR : FORUM MODERATOR

 

Views: 12,146  ·  Replies: 23 
> Video Encoding: How to make hardsubbed MP4s
Nomake Wan
  Posted: Jan 16 2013, 07:21 AM


ShiMACHaze
**********

Group: Advanced Members
Posts: 19,542
Member No.: 5,394
Joined: Feb 5th 2005
Location: Drydock





Well, enough people have asked me about this topic that I feel like writing about it. Video encoding is a huge, broad topic that I can't possibly dream of covering in a single thread so I'm not going to. This time we're going to deal with creating hardsubbed MP4 files for use on mobile/game devices. Other threads will deal with things like creating lossless clips for video editing tools, converting exotic file formats like MOV and things like that. However, the basics of this guide will be important for later guides, so at the very least I'll be using the prerequisite programs from this guide in future ones.

Before we begin, a caution; this guide is only for those running Windows PCs. If you are using Mac OSX I cannot help you except to point at Handbrake and say "good luck." If you are using Linux then I can't help you at all. I'm a Windows user first and foremost so all my experience will be based on that perspective. The guides should work on everything from XP 32-bit up through Windows 7 64-bit. I don't know if they'll work right on Windows 8 because that OS is garbage I refuse to touch. Be my guest and try it, however!

First off, like any guide there are prerequisites. I'll list what you need, why you need it, and where to get it. Let's begin!

Programs You'll Need
  • AVIsynth 2.5.8. This is the core of every single video re-encode process you'll ever do using any of my guides. If you don't have this installed on your system I cannot help you. It is not actually a program, it is a scripting language and interpreter. So when you install it don't go looking for an EXE to run. There isn't any. Also you can associate AVS files with anything you want but I highly suggest you associate them with notepad for ease of use.
  • MeGUI. We won't actually be using this program for anything since I find it inefficient but there is a wonderful bunch of tools inside it that are very useful. My recommendation is to extract it to C:\megui for purposes of this guide. That's not where I put it but to avoid the whole 32/64-bit problem let's just put it in C:\megui. Once you extract it run the main program at least once to let it update all of its tools. It may take a while and you may have to run it a few times to successfully update everything. Be patient!
  • xy-vsfilter. This is a way more efficient version of VSFilter, the filter we'll need to do hardsubbing. Extract the VSFilter.dll file inside that archive to C:\megui\tools\avisynth_plugin and have it replace the existing file.
  • MKVcleaver. This is a way more efficient front-end for MKVextract than MKVextractGUI's derivatives are. Just put the EXE file itself into C:\megui\tools\mkvmerge. That's it. Now, personally I use the 64-bit version but there's not much of a performance difference so just click the 'Download portable version (direct link)' link on that page.
  • MediaInfo. You'll want this to be able to tell what framerate a file is. Most of the time your files will be 23.976 FPS but that's not always the case. Dropping a file into MediaInfo will tell you exactly what the framerate is, what type of video/audio/subtitles are included, and lots of other cool stuff. I recommend that you use 'Text' output by default since it provides the most information easily. Plus it's easier to copy and paste when you need to ask for help!
  • Nero AAC Encoder Package. Very important! Extract this into the 'Tools' folder in MeGUI's program directory. So it should be something like C:\megui\tools\neroaacenc. Optional: You can enable Nero AAC support in MeGUI by opening MeGUI, going to Options->Settings, clicking the 'External Program Configuration' tab and checking 'Enable NeroAacEnc' while pointing it to the proper folder.
  • Xrecode II. The easiest, most powerful tool I know of to reencode audio. My method assumes that you're starting with a file that has 2.0 AAC audio (like 99% of fansubs nowadays are). If you aren't (for instance if you have FLAC or DTS-HD audio from a bluray rip, or you have 5.1 channel audio) then this tool will let you convert to 2-channel AAC audio in a snap. Extract it anywhere you want, it doesn't matter. Once it's extracted, run the program, wait for the license thing, click the number button that appears to close the license thing, then click the bubble on the bottom next to 'NeroAAC'. Then click the button with the wrench on it with that name. In 'Location of External Tool' point it to C:\megui\tools\neroaacenc\neroAacEnc.exe since that's where it is. Isn't MeGUI's tool folder useful? cool.gif

That's it for the tools you'll need for this part of the how-to. Later parts will require a tool or two more but we'll cross that bridge when we reach it. Okay! So now you've gone and downloaded all those things, installed or extracted them, set them up like I mentioned and you're probably wondering to yourself, "N1! What the heck man, why are you cluttering my computer with this junk? Why can't I just use SUPER or some all-in-one program to do this?" To which I reply: SUPER is garbage!! I have a hatred of all things all-in-one for video encoding because the fact is that there are way too many things you could do than a program can account for. On top of that, most all-in-one programs are coded like shit and run equally shitty. If you want to use SUPER or some other all-in-one encoder then get the hell out of my guide. No, I'm serious. I don't want to talk to you so go away. I'll wait.

...

Okay, now that those people are gone we can get down to brass tacks. 99% of fansubs nowadays use h264 video, AAC audio (except bluray rips which will tend to use FLAC or DTS-HD) and ASS subtitles with embedded fonts. My method is specifically designed to handle this situation and to adapt anything that doesn't quite fit to work. Credit for the core of the method--the batch script--goes to HaniKazmi of DeadFish who was gracious enough to post the important part on his blog. Bits and pieces here and there have been adjusted and adapted but for the most part it's the same script he uses to do DeadFish's releases. smile.gif Huge shout-out to him for that!

We're going to assume here that you're trying to turn a softsubbed MKV into a hardsubbed MP4 to use on an iPhone/iPod/iPad/Android/PS3/360/etc. If instead you have an MP4 and an ASS file (or an MP4 and an SRT, or an MKV and an SRT...etc), please click the spoiler below for how to turn that into a file that our script can actually use. If you already have a softsubbed MKV ready to go, proceed onwards.

SPOILER


All right. Since you have all the programs you need already installed and ready to go, you'll need the super-awesome script we'll be using. To create it, simply copy the code here into notepad and save it as 'All Files' instead of 'Text Document'. Call it something like HARDSUB.bat or whatever, it doesn't matter what you name it as long as it has the .bat extension. It also doesn't matter where you save it. Here you go:

CODE
@echo on
"C:\megui\tools\mkvmerge\MKVcleaver_x64.exe" %1
echo LoadPlugin("C:\megui\tools\ffms\ffms2.dll")>>"C:\Encoding\%~n1.avs"
echo LoadPlugin("C:\megui\tools\avisynth_plugin\VSFilter.dll")>>"C:\Encoding\%~n1.avs"
echo FFVideoSource(%1, threads=1).AssumeFPS(24000,1001)>>"C:\Encoding\%~n1.avs"
echo TextSub("C:\Encoding\%~n1_Subtitles01.ass")>>"C:\Encoding\%~n1.avs"
"C:\megui\tools\x264\x264.exe" --level 4.1 --preset slow --tune animation --crf 20.0 --output "C:\Encoding\%~n1.mp4" "C:\Encoding\%~n1.avs"
"C:\megui\tools\mp4box\MP4Box.exe" -add "C:\Encoding\%~n1.mp4" -add "C:\Encoding\%~n1_Audio01.aac" "C:\Encoding\Finished\%~n1.mp4"
@pause
del "C:\Encoding\%~n1.avs"
del "C:\Encoding\%~n1.mp4"
del %1.ffindex


Now, let me take a moment to explain what each line does so you can have a working understanding of the 'magic' here. The first line '@echo on' simply enables the 'echo' function of outputting text. It's used later in the script (for the four lines that start with 'echo', obviously). The second echoes (outputs the text) 'LoadPlugin("C:\megui\tools\ffms\ffms2.dll")' into a file called FILENAME.avs in C:\. Same goes for the next three lines, they output text into an AVS file in C:\.

An AVS file is a script that AVIsynth uses to interpret video (and audio, and subtitles, and other things if relevant). Those four lines are all AVIsynth functions. The first two do exactly what they look like--they load plugins for AVIsynth to use. The first one loads FFMS2 while the second loads xy-vsfilter. The third line then calls the function FFVideoSource (used to open the video we'll be using) which is part of FFMS2. The 'threads=1' control tells it to only use a single thread to open the video, which is important since we'll want to save processing threads for the actual encoding process. The 'AssumeFPS(24000,1001)' part tells the filter to assume that the input video is 23.976 FPS. The fourth line calls the TextSub function to open the subtitle and slap it onto the video stream, a function of xy-vsfilter plugin.

The next line with x264.exe is the workhorse. This is what actually takes the output from FFVideoSource and TextSub (a raw video stream with subtitles on it) and turns it into an h264 video stream.

Level used to just be a sentence, but as reader Nivek pointed out it requires more explanation than a single sentence. Please make sure you read this, though I will bold the important parts so that those of you skimming can ignore my rambling and take home the important part. Level is set to 4.1 in the script because the script is designed to work with any input resolution as well as supporting 60FPS files up to 720p. Wikipedia has a wonderful explanation of what each level represents so I won't go over them all here, but here's the important thing to know. For the majority of what you'll be doing with the script you will probably want to leave this at Level 4.1.

If your target device does not support 1080p video and you are encoding 720p video or smaller at 30 FPS or less, set the level to 3.1. If you are attempting to encode 1080p video for a 720p device at level 3.1, add this line after TextSub in the script:
CODE
echo Lanczos4Resize(1280,720)>>"C:\Encoding\%~n1.avs"

If you are encoding 1080p video at over 30 FPS, set the level to 4.2, 5.0 or 5.1 depending on what your target device supports. Most computers will be able to interpret any of those, but many computers may not have the horsepower to play 1080p video at 60 FPS! Not to mention it may run in software decoding mode instead of hardware!

Preset Slow is to disable any speed workarounds that may impact quality/accuracy. Tune Animation is because I'm assuming you're working with Anime. I've used it on live action, however, and it still works. CRF 20.0 is the quality setting and goes from 0 to 51 where 0 is lossless and 51 is garbage, so 20 is a good middle-ground. Output is where it'll put the temporary file being used for the next step. The line after 'output' is actually the input, hilariously.

After that is mp4box, which takes the temporary MP4 file that x264.exe made and mixes it with the AAC audio we'll be extracting to make the final finished product. @pause means that the script will wait for the user to press 'enter' before continuing. The last two lines delete two of the temporary files created by the script so as to not clutter your computer with that junk.

Now, you don't really have to understand what any of those do but you may have to change some of the lines for different input files. For instance, if your input is 29.97 FPS you'll have to change the 'AssumeFPS(24000,1001)' line to 'AssumeFPS(30000,1001)'. If you're using SRT subs instead of ASS, you'll have to change the 'TextSub("C:\Encoding\%~n1_Subtitles1.ass")' to read 'TextSub("C:\Encoding\%~n1_Subtitles1.srt")'. Things like that. There's also a slight bug in the script dealing with input files. It's so important that I'm going to bold it and color it red so people don't miss it.

!!IMPORTANT!!
If the filename of the MKV you're trying to convert to MP4 has spaces in it, either replace the spaces with underscores or change the 'FFVideoSource(%1, threads=1)' to 'FFVideoSource("%1", threads=1)'. So for instance, if the filename is "This Page is Awesome.mkv" then you can either change it to "This_Page_is_Awesome.mkv" or change the script. For compatibility purposes I usually change the filename but it doesn't matter which you do as long as you remember to do it.

Okay, now we have our shiny batch script and our MKV we want to convert. We're almost ready to begin! The first step is to open up MediaInfo and drag the MKV onto it. If you have the shell extension installed you can right-click the MKV and click the 'MediaInfo' menu option too, it'll do the same thing. Now, here's an example output to give you an idea of how to read all the information. I'll spoiler it because it's huge but this isn't a spoiler you should skip so check it out before just closing it and moving on!

SPOILER


Okay, so the important things to look at here are the video framerate and resolution and display aspect ratio, the audio format and channels, and the text format. What we want to see are 23.976 FPS, a Width/Height that match the Display Aspect Ratio (1280x720 is 16:9 so this file works, but a file that's 720x480 and 16:9 will require modifying the script), AAC format audio, 2 channels and ASS format text subtitles. If that's what you have you're good to go so skip ahead. If not then click the spoiler(s) that pertain to your problem.

My file doesn't say 23.976 FPS! / Frame rate mode says 'Variable'!
SPOILER

My resolution and display aspect ratio don't seem to match!
SPOILER

My audio format doesn't say AAC! / My audio channels are more than 2!
SPOILER

My text format doesn't say ASS!
SPOILER

Well, that's it for potential problems. Now we actually get to do stuff. Thanks for sticking with it thusfar. I know it seems like a lot of information to absorb but I'm sorry, that's the reality of working with audiovisual sources. There's no magic bullet to do everything so you need to learn about what you're looking at and adapt. Once you've done this a few times it'll stop seeming so complicated and you'll be able to just drag-and-drop all day long without hardly thinking about it.

Now, because it's written this way in the script, create a folder in C: called 'Encoding'. Then create another folder inside that called 'Finished'. So you should now have two new folders, one "C:\Encoding" and another "C:\Encoding\Finished". Got it? Good! Let's get rolling!

Drag the MKV file you're using on top of the BAT file. When you do two windows will pop open. One is a command prompt, the other is MKVcleaver. In MKVcleaver, check the boxes on the right in the 'Tracks to extract (Batch Mode)' area marked Audio Track 1, Subtitle Track 1 (unless you're working with something like Commie's Girls und Panzer where you really want Subtitle Track 2) and Attachments. In the 'Filename options' box under that, check 'Use 'Video', 'Audio', and 'Subtitle''. Output directory should be "C:\Encoding". Click 'Extract Tracks' but keep MKVcleaver open once it's finished extracting! If you close it the script will run...which is fine if everything is perfect, but not fine if there are more steps you need to do. Trust me, you'll most likely be sad if you close it too early so just leave it open.

Go into the "C:\Encoding" folder and confirm what you have in there. There should be an AAC file, an ASS (or SSA/SRT) file and maybe a folder called (filename)_Attachments. If there is indeed an attachments folder, open it. Inside will be a bunch of custom fonts. Install them. Yes, there's no choice but to install them. There is an alternative to xy-vsfilter that can use embedded fonts but unfortunately it doesn't do color correction properly like xy-vsfilter does. At the moment, the only option is installing any custom fonts. If it pops up saying it's already installed feel free to check 'Do this with remaining items' and click 'No'. You don't need to overwrite any fonts you already have.

If the audio file isn't AAC (or in the MediaInfo step you saw more than 2 channels) you'll need to use Xrecode to fix that. Click the spoiler to learn how. If you already have 2-channel AAC audio, just skip ahead!
SPOILER

Okay, you've installed the fonts, you've made sure the script is right for the file you're using, you've made sure you have 2-channel AAC audio. Now you can go ahead and close MKVcleaver. The script will start running automatically in the command prompt window. It will give you an estimated time remaining and when it finishes it will tell you to press enter to continue. Pressing enter will delete the temporary files the script creates and close the window. If all went well, you'll have a hardsubbed MP4 file in the "C:\Encoding\Finished" folder. If it didn't go well, chances are you missed a step or misread something. Here are the most common errors.
  • The script fails almost the instant I close MKVcleaver!
    This could be one of three things. One, the paths in the script to the plugins and such are wrong. Please make sure that the directories in the script actually match directories on your computer. Two, you missed the huge giant IMPORTANT thing I put up there about what happens if you dump files with spaces in the filename into the script. Replace the spaces with underscores. Three, the subtitle filename didn't match--it expected an ASS and you fed it an SRT or something like that. Just make sure that the subtitle filename matches. These are the top three reasons the script will fail instantly.
  • The script ran for a long time but then right when it looked like it was finished it failed!
    Oh man do I ever feel your pain here. If it ran for a while then failed it means that it tried to put the audio into the finished video and failed. This is likely because you didn't have 2-channel AAC audio in the C:\Encoding folder. Check to make sure it's in there. If you skipped the step about making AAC audio from MP3/FLAC/DTS/etc then this is what happens.
  • Everything went perfectly but the finished file's audio is out of sync with the video!
    You probably skimmed that section on framerates, huh? Go back up to the spoiler marked 'My file doesn't say 23.976 FPS! / Frame rate mode says 'Variable'!' and read it this time. If you're sure you read it and you did it exactly as I told you, it's possible there's something else going on and I may be able to help you personally. Still, chances are it's just an incorrect framerate setting in the script.
  • Everything went perfectly but the finished file's video looks squished/stretched!
    You skipped over the part about resolution and display aspect ratio. Go back, read it, fix the script, try again.
  • Everything went perfectly but the finished file's subtitles are wrong/audio is in English/audio is commentary!
    Most likely what happened here was that the input file had multiple subtitle tracks and the first one wasn't actually the one you wanted. This can happen for instance on files by [OCZ-Anime] where the first subtitle track is only signs/karaoke and the second track is actually the full subtitles. Then again, in the case of OCZ's files you'd also have gotten English dub audio! The problem here is back in the MKVcleaver step when you picked the audio/subtitle track in the Batch Mode box. It just means you need to pick a different one.
  • Everything went perfectly but the finished file doesn't play on my...
    Now, the whole idea of this script is to make a super-compatible file. If you followed the instructions it should be playable on any device that can play 720p video. So sorry, it won't work on a PSP (though it can be tweaked to work for one using resizing!), but it should work perfectly on just about anything else. If it doesn't, first check to see if it plays correctly on your computer. If it does, put it into MediaInfo. Does it have more than 2 channels for audio? Is there something else going on? It's very rare for this problem to come up but if I had to wager a guess it's that the MP4 you made has surround sound audio and you need to go back and make sure you turn it into stereo instead.

That's it. If you have any specific questions lemme know and I can help you out. Relax, though; this is one of the most difficult video encoding things you'll probably ever do. Things like creating lossless clips for video editing or converting MOV files is much easier by comparison. Still, it's the most popular question I get asked so despite being hard I figured I'd get it out of the way first. Hopefully this helps.

Until next time!

This post has been edited by Nomake Wan on May 27 2013, 08:00 AM
Proud Contributor of IDW Forums and the Music Section Revival Project
nivek
Posted: Jan 16 2013, 08:19 AM


IDW God Member
*******

Group: Members
Posts: 165
Member No.: 28,727
Joined: Feb 16th 2008
Location: Philippines





Just finished reading it, gonna try this when I have time, thanks
khat17
Posted: Jan 16 2013, 04:35 PM


IDW SIMPLETON
**********

Group: Advanced Members
Posts: 1,168
Member No.: 17,668
Joined: May 7th 2006
Location: Mandeville, Jamaica





Excellent work N1! This should help out everyone that needs to do this or wants to give it a shot.
Perry
Posted: Jan 16 2013, 05:51 PM


Like an eagle!
Group Icon

Group: SITE OWNER
Posts: 8,014
Member No.: 1
Joined: Sep 15th 2002
Location: San Leandro, California





Thank you sooooo much Nomake Wan (Donz0rz) !! You are the one behind the crucial step for the hardsubs we are releasing for Fifth Stage! I can't give you enough credit. Don walked me through the steps last night when I was very frustrated after fiddling about for couple hours. Under this guide, I was able to do the hardsubs within an hour. Awesome!!
Proud Contributor of the Music Section Revival Project
Nomake Wan
  Posted: Jan 16 2013, 10:51 PM


ShiMACHaze
**********

Group: Advanced Members
Posts: 19,542
Member No.: 5,394
Joined: Feb 5th 2005
Location: Drydock





Please note!! I have changed the scripts in the guide adding a single line to the end. The line is:

del "C:\Encoding\%~n1.mp4"

What this does is deletes the temporary MP4 file that the script creates just before turning it into the finished product. By adding this line you can prevent accidentally muxing two MP4s into one another if the script fails. I normally just delete it manually but it occurred to me just now that you guys probably wouldn't notice and don't know that mp4box wouldn't know to overwrite the temp file instead of mixing it. The extra line prevents that from happening as long as the script gets as far as the user input stage. If you close the script manually before it can complete it won't do anything...but you shouldn't do that anyway. wink2.gif
Proud Contributor of IDW Forums and the Music Section Revival Project
nivek
Posted: Jan 17 2013, 01:12 AM


IDW God Member
*******

Group: Members
Posts: 165
Member No.: 28,727
Joined: Feb 16th 2008
Location: Philippines





Okay so I'm at the part with Xrecode II, after clicking on the bubble NeroAAC, then clicking the wrench icon, then under 'Location of External Tool', I cannot find the C:\megui\tools\neroaacenc folder, I did extract megui to C:\ and checked for updates. neroaacenc folder is just not there.

EDIT: so after a bit of googling found that it can be downloaded directly from nero website, so downloaded it, extracted the ones for win32, then placed neroAacEnc.exe in C:\megui\tools\neroaacenc

This post has been edited by nivek on Jan 17 2013, 01:36 AM
Nomake Wan
  Posted: Jan 17 2013, 01:56 AM


ShiMACHaze
**********

Group: Advanced Members
Posts: 19,542
Member No.: 5,394
Joined: Feb 5th 2005
Location: Drydock





QUOTE (nivek @ 44 minutes, 29 seconds ago)
Okay so I'm at the part with Xrecode II, after clicking on the bubble NeroAAC, then clicking the wrench icon, then under 'Location of External Tool', I cannot find the C:\megui\tools\neroaacenc folder, I did extract megui to C:\ and checked for updates. neroaacenc folder is just not there.

EDIT: so after a bit of googling found that it can be downloaded directly from nero website, so downloaded it, extracted the ones for win32, then placed neroAacEnc.exe in C:\megui\tools\neroaacenc

Interesting. My install of MeGUI came with it. Was there perhaps a question box that came up when you tried to update MeGUI asking if you wanted updates that were not compatible with the software license? If so, did you click 'yes' for you wanted those updates anyway? I'm fairly certain it comes with it, but it may be one of the programs that MeGUI considers 'evil' and asks the user for confirmation before downloading.

In fact, I can confirm this because neroaacenc appears in MeGUI's update manager. If it were a third party tool external to MeGUI it wouldn't appear in the updater. smile.gif

user posted image
Image size reduced, original size: 726 x 351. Click here to view the image in its original dimension.


This post has been edited by Nomake Wan on Jan 17 2013, 01:58 AM
Proud Contributor of IDW Forums and the Music Section Revival Project
nivek
Posted: Jan 17 2013, 02:12 AM


IDW God Member
*******

Group: Members
Posts: 165
Member No.: 28,727
Joined: Feb 16th 2008
Location: Philippines





maybe they removed it from newer revisions? anyway, when I opened MeGUI and checked for updates all it said was "all files are up to date" exactly the screenshot you posted, there was no prompt whether I want to install anything else.

Currently at the part of extracting with MKVcleaver, it did tell me could not find some exe's (I think it was mkvmerge and mkvextract) when I hit "extract tracks" button so I just clicked on the "locate MKVToolnix" button then pointed to C:\megui\tools\mkvmerge, then after that "Extract Tracks" now works.

will post again, hopefully everything goes right cool.gif

EDIT:

okay so I'm having a problem:

This is the file I'm trying to convert:


SPOILER


I've already extracted the contents, installed the necessary fonts, and then converted the flac to 2 channel .aac, I'm getting errors on the command prompt:

SPOILER


can't quite figure out what to do now

EDIT 2:

so I thought the access denied from the command prompt was due to me not running the bat file as an administrator, So I tried running it as administrator and the access denied was gone:

SPOILER


but there seems to be an error confused2.gif

EDIT 3:

So after staring at the script and trying my best to figure it out I edited it to this:

Edit: wrong script, check op post for updated script

changed "Audio1" to "Audio01"
changed "Subtitle1" to Subtitle01"
then changed (%1, threads=1) to ("%1", threads=1)

right now it is encoding, changed the file I'm trying to convert because the previous one was a 1080p anime, right now I'm testing this on a 720p anime.

This post has been edited by nivek on Jan 18 2013, 05:48 AM
nivek
Posted: Jan 18 2013, 03:31 AM


IDW God Member
*******

Group: Members
Posts: 165
Member No.: 28,727
Joined: Feb 16th 2008
Location: Philippines





okay so after doing a bunch of tests, there's something that needs to be changed in the script for this tutorial.

The problem is whatever is written/copied/deleted in C:\ will need administrator rights. Try copying any type of file onto C:\ and windows 7 will prompt you, you need administrator rights to copy this file, likewise this is also the case when you delete a file in C:\ but if you place it in a folder, example C:\Encoding there will no longer be a prompt from windows that you need administrator rights. Now yes I am logged in as administrator, It's just that windows will always prompt you whenever you copy/delete anything in C:\

Now because of that, with the way the previous script was written, which writes the .avs file directly onto C:\ there will be a problem once encoding using the script starts. It will say in the command prompt "access denied" then encoding will fail.

Now what I did was just simply edit the script so that it will write the .avs file in C:\Encoding. Problem solved, plus it keeps it much cleaner since all files related to encoding will be written on that folder. Which anyway gets deleted if encoding is successful thanks to the added line in the script by Nomake Wan.

But there's another problem, I tested the completed mp4 file on my android phone (Xperia Go) it is not compatible with the stock player, and when used with mx player (free video player app that plays most video file types for android) it reverts to software decoding on the phone, so it means that the converted file isn't really compatible. (BTW I really don't watch on my phone just tested it, but I do watch on an android tablet occasionally)

I changed another thing on the script to make it compatible:

changed "level 4.1" to "level 3.0"

after that it worked on the android device using stock player.

here's the script that I used:

Edit: wrong script, check op post for updated script

BTW any tutorial on how to resize videos when converting? I really don't know how to script. I just based all the edit I made on the script by looking at patterns that don't match and some other knowledge I was able to pick up from the net about video encoding. derp.gif

This post has been edited by nivek on Jan 18 2013, 05:45 AM
khat17
Posted: Jan 18 2013, 04:08 AM


IDW SIMPLETON
**********

Group: Advanced Members
Posts: 1,168
Member No.: 17,668
Joined: May 7th 2006
Location: Mandeville, Jamaica





That issue applies to Vista and above. It's the whole UAC issue. Don't think it will be there if UAC is turned off.....
Nomake Wan
  Posted: Jan 18 2013, 05:11 AM


ShiMACHaze
**********

Group: Advanced Members
Posts: 19,542
Member No.: 5,394
Joined: Feb 5th 2005
Location: Drydock





It's not there with UAC turned off. I know that because I don't use UAC and didn't have a problem with the script. derp.gif I keep forgetting that there are actually people out here who use that piece of...meh. Well whatever.

Nivek, because your edits make the output file more compatible with more end-user machines (as I said I hadn't accounted for UAC-enabled machines) and more devices I'll change my script to account for those. However, you shouldn't be using Level 3.0. You should be using Level 3.1. The reason (as explained by Wikipedia) is that 3.0 doesn't support 720p. So either the encoder is actually using 3.1 (check using MediaInfo) or it simply didn't run a sanity check on the level and your phone is actually assuming 3.1. The point is, for 720p content you want Level 3.1. The script uses 4.1 by default because 3.1 does not support 1080p and some people may want to encode bluray rips in full 1080p.

Now, as for resizing, that was covered a little bit in the whole aspect ratio spoiler. You add a single line to the script after TextSub that works like this:
CODE
echo Lanczos4Resize(1280,720)>>"C:\Encoding\%~n1.avs"

Now, where you put it will determine how subtitles end up in the final product. For the aspect ratio correction lesson I had people put it between FFVideoSource and TextSub. This is because many old DVD rips that used anamorphic video and subtitles would assume that the video player had corrected the resolution before displaying the subtitles. As such, the script would resize the video then put on the subtitles the same way. For HD content, however, the subtitles are scaled correctly to begin with so we want to resize the entire stream, subtitles and all. Thus we place it after TextSub.

Now, be careful here. You can't just put anything in here. For instance, 480p video with 16:9 aspect would be 853x480 but that value is invalid. At a minimum the script will want a value divisible by 2. So you'd use 852x480. This will work for most modern devices, but some older ones will require something called 'MOD16', meaning that the resolution has to be divisible by 16. The closest MOD16 resolution to correct would be 848x480. See? This is part of why I didn't cover resizing in the tutorial. However, if you simply want to turn 1080p material into 720p, that is super easy to do and should work perfectly with anything. happy.gif

I have changed the script in the tutorial. Because your script incorrectly calls the x264 function I ask that you please delete it from your post so that others reading the thread will not get confused.

EDIT: I just noticed that you changed the Audio and Subtitle lines in your script as well. Why was this? Has MKVcleaver changed how it handles files? Let me check here real quick...well I'll be damned. Excellent catch, thank you! I'll go ahead and change the script to reflect the change in MKVcleaver's functionality. smile.gif

This post has been edited by Nomake Wan on Jan 18 2013, 05:54 AM
Proud Contributor of IDW Forums and the Music Section Revival Project
nivek
Posted: Jan 18 2013, 05:40 AM


IDW God Member
*******

Group: Members
Posts: 165
Member No.: 28,727
Joined: Feb 16th 2008
Location: Philippines





@khat17

thanks for the info

@Nomake Wan

well forgive me for having UAC on tongue.gif (I didn't even know what it was until khat mentioned it) apologies for my mistake on the scripts, will edit it now. Thanks

This post has been edited by nivek on Jan 18 2013, 05:40 AM
Nomake Wan
  Posted: Jan 18 2013, 05:58 AM


ShiMACHaze
**********

Group: Advanced Members
Posts: 19,542
Member No.: 5,394
Joined: Feb 5th 2005
Location: Drydock





Don't even worry about it man. You caught a change in MKVcleaver's functionality I didn't know had happened and the script is better off. Congrats for trooping through my derp and getting the script working on your own. Thanks to your efforts now anyone else reading can breeze right through. cool.gif
Proud Contributor of IDW Forums and the Music Section Revival Project
Chidoki
Posted: Jan 18 2013, 11:00 AM


Fictional Compiler
**********

Group: Advanced Members
Posts: 1,620
Member No.: 3,699
Joined: Oct 16th 2004
Location: Land of Elysium





Awesome this is great man. It's something I can give a try when I get a chance for any of my video editings, so the explanations saves a lot of my time looking from site to site about information. Many thanks. thanks.gif thanks.gif thanks.gif thanks.gif thanks.gif , etc...
nivek
Posted: Jan 20 2013, 10:27 PM


IDW God Member
*******

Group: Members
Posts: 165
Member No.: 28,727
Joined: Feb 16th 2008
Location: Philippines





@Nomake Wan

Okay so far I've been able to convert things properly cool.gif thanks to your tutorial. There's just one file that's got me puzzled on how to convert it properly, Initial D Fifth Stage episode1v2 by sagesubs.

SPOILER


Problem is with the frame rates:

Frame rate mode - Constant
Frame rate - 23.976 fps
Original frame rate - 29.970 fps

I've already tried using AssumeFPS(24000,1001) and AssumeFPS(30000,1001), both gets out of sync audio, I know you already made an 8 bit encode for this one, I'd just like to know if there's something wrong again with my script specifically for this one.

This post has been edited by nivek on Jan 21 2013, 01:50 AM
Nomake Wan
  Posted: Jan 21 2013, 01:58 AM


ShiMACHaze
**********

Group: Advanced Members
Posts: 19,542
Member No.: 5,394
Joined: Feb 5th 2005
Location: Drydock





QUOTE (nivek @ 3 hours, 30 minutes ago)
@Nomake Wan

Okay so far I've been able to convert things properly cool.gif thanks to your tutorial. There's just one file that's got me puzzled on how to convert it properly, Initial D Fifth Stage episode1v2 by sagesubs.

SPOILER


Problem is with the frame rates:

Frame rate mode - Constant
Frame rate - 23.976 fps
Original frame rate - 29.970 fps

I've already tried using AssumeFPS(24000,1001) and AssumeFPS(30000,1001), both gets out of sync audio, I know you already made an 8 bit encode for this one, I'd just like to know if there's something wrong again with my script specifically for this one.

Ahh, yes. This is because Sage has a very odd way of encoding things. I remember having to go through this while I was doing encodes for Deadfish (I encoded Gundam AGE for 'em for a little bit). The trick is actually what I explained in the variable framerate tutorial even though the MediaInfo lists 'constant'. I'm honestly not sure why their encodes do this but if you use the function 'ConvertFPS(30000,1001)' it should sync up properly. cool.gif

@Chidoki: You're quite welcome.
Proud Contributor of IDW Forums and the Music Section Revival Project
nivek
Posted: Jan 21 2013, 07:38 AM


IDW God Member
*******

Group: Members
Posts: 165
Member No.: 28,727
Joined: Feb 16th 2008
Location: Philippines





just tried using ConvertFPS(30000,1001) but the audio still gets out of sync, the weird thing is at the start of the video (opening song) the audio is synced, then starts to get out of sync, then at the end of the video (ending song) it gets synced again. It's like the opening and ending came from a different frame rate.

This post has been edited by nivek on Jan 21 2013, 08:12 AM
Nomake Wan
  Posted: Jan 21 2013, 09:06 AM


ShiMACHaze
**********

Group: Advanced Members
Posts: 19,542
Member No.: 5,394
Joined: Feb 5th 2005
Location: Drydock





QUOTE (nivek @ 1 hour, 27 minutes ago)
just tried using ConvertFPS(30000,1001) but the audio still gets out of sync, the weird thing is at the start of the video (opening song) the audio is synced, then starts to get out of sync, then at the end of the video (ending song) it gets synced again. It's like the opening and ending came from a different frame rate.

I have absolutely no clue why ConvertFPS didn't work to be perfectly honest, but here's a code change that does. I'll need to do some testing to see if this change would work with all material or if it's only useful for Sage's encodes. If it ends up working for everything I throw at it, I'll go ahead and alter the guide to use internal FPS code rather than a pipe command. So here, try this:

echo FFVideoSource(%1, threads=1, fpsnum = 30000, fpsden = 1001)>>"C:\Encoding\%~n1.avs"

I think you'll find it works properly this time. happy.gif

This post has been edited by Nomake Wan on Jan 21 2013, 09:12 AM
Proud Contributor of IDW Forums and the Music Section Revival Project
nivek
Posted: Jan 22 2013, 02:13 AM


IDW God Member
*******

Group: Members
Posts: 165
Member No.: 28,727
Joined: Feb 16th 2008
Location: Philippines





Works perfectly biggrin.gif thanks man! I'll keep that in mind if I ever encounter another video file similar to that.
FC3SRedSuns
Posted: May 27 2013, 05:49 AM


REDSUNS42 Fansubs
*

Group: Members
Posts: 8
Member No.: 41,449
Joined: May 10th 2013
Location: Update Profile





Do you know how to sync a/v with x264 and lame mp3 codecs in virtualdub?
Nomake Wan
  Posted: May 27 2013, 06:12 AM


ShiMACHaze
**********

Group: Advanced Members
Posts: 19,542
Member No.: 5,394
Joined: Feb 5th 2005
Location: Drydock





QUOTE (FC3SRedSuns @ 23 minutes, 31 seconds ago)
Do you know how to sync a/v with x264 and lame mp3 codecs in virtualdub?

Two things here:

1.) What part of the guide was troubling you? If you can be more specific as to what aspect of the guide was too confusing to follow or simply didn't work on your setup, I can most likely not only help you get it working but can also update the guide to make it more user-friendly. Win-win! So if you can, please do let me know so I can help you with that method instead. smile.gif

2.) I'm cheating a bit on your question since you PM'd me the full text before. So that everyone can benefit (and understand where my oddly specific answer to such a broad question came from), here was the original full question I was PM'd:

QUOTE (FC3SRedSuns)
I decided to go back to using virtualdub and textsub filter, with x264 and lame mp3 conversion, but the audio was not synced with the subs or video. So, I used direct stream copy and it was perfect again, but it's PCM instead of MP3. I think I'll have to extract the audio from the video and convert then rejoin it. If you know how to modify the settings for the mp3 conversion in virtualdub so that it syncs, let me know.

Okay...quite a few problems here actually. First, textsub isn't bad--it was what I used way back when I did Battle Stage--but it doesn't do effects or custom fonts as I recall. If your original source is an SRT file then that point is moot, but I'm pointing it out to those who may be tempted to use it on more modern releases that use ASS styled subtitles with custom fonts, etc. So let's assume you have an SRT and therefore TextSub works fine.

The next problem is that 'DirectStreamCopy' is exactly what it sounds like--it's a direct copy of the input stream with no video encoding whatsoever. At that point what matters is how you actually have the file open in VirtualDub in the first place; if you opened it using an AVIsynth script to serve up raw frames, then your output is going to be raw frames too. If you opened it with VirtualDub's own import filter then your output is going to be whatever the input codec was. It doesn't matter that you selected a compressor in Video...if you're on Direct Stream Copy, you aren't encoding anything. Period.

Now, that you got PCM audio using DirectStreamCopy tells me you were frameserving--unless you for some reason have a file whose audio is originally PCM (not likely!) then the only way you got PCM out was if you frameserved the input. In which case see the above paragraph where your output is raw video frames and not compressed like you think it is. Yikes!

I would never use VirtualDub to do the MP3 part. VirtualDub is, to me, simply a program for confirming synchronization of AVIsynth scripts and trimming clips. I wouldn't even use it to encode video, at least not in this modern age where the AVI container has depreciated so heavily. Any audio conversion is something you'll want to do outside of VirtualDub. Is there a reason you can't drop your original input into XrecodeII and convert it just like that? You shouldn't have to extract anything--it should work perfectly.

And last but not least, even if you were encoding your video--which you aren't since you selected Direct Stream Copy--using x264 with the AVI container is a horrendously dirty hack that isn't compliant with any known standard. Audio Video Interleave was created well before x264 existed and is not actually compatible. Yes, you will see some stupid people who do it anyway, but thankfully most of them have disappeared within the last few years as people knocked sense into them. Do not attempt to put h264 video into an AVI container. Super bad idea. Don't do it. I'm serious. Don't.

Whew! Long-winded answer is long. So the short of it is, while I could try to help you with your VirtualDub issue...the problem with your VirtualDub problem is that you're doing everything wrong. So shall we get back to the guide and get you making a proper MP4? smile.gif
Proud Contributor of IDW Forums and the Music Section Revival Project
FC3SRedSuns
Posted: May 27 2013, 07:31 AM


REDSUNS42 Fansubs
*

Group: Members
Posts: 8
Member No.: 41,449
Joined: May 10th 2013
Location: Update Profile





After the softsub mkv and encoding/finished folder part, I updated megui, but it didn't have the neroacc folder or codec so I had to download and create that folder separately. Then I had to modify the batch for the mkvcleaver path since I was using the 32-bit version. Then I had to copy over the mkvcleaver files over to the megui tools folder because I didn't install it inside that folder. Then I dragged the mkv into the batch and came across errors in outputting the rest of the files after it ran through mkvcleaver.

Errors in hardsub.bat:
SPOILER


As for the avs script:
SPOILER


Then I had to convert ac3 to acc and I think that part went fine, but I had to fix the script errors anyway, but then I got lazy and went back to using virtualdub because I think it requires less clicking. The softsub mkv I had didn't have all my subs and their position when the video is skimmed through, so I assumed it wouldn't work at the end. I didn't mind doing the other stuff because I think your guide was a little outdated. Your tut was 125 days ago, so yeah...


As for virtualdub, using textsub is fine because I tried it and it got all my subs in the avi output with the ass file I had. And yes, I already knew what directstreamcopy does, but I only used full processing mode for video because I was having trouble with the audio so that's why it used directstreamcopy for the audio which allowed it to sync with a trimmed video. I haven't tried the full output yet though. I don't like using avi containers either, which is why I used avidemux at first to get an mp4 output, but the sub filter didn't get all my subs, so I stuck with using virtualdub and it only outputs avi. I didn't mind using it as long as everything works fine, but I do prefer mp4. That wasn't the goal yet though.

Alright, back to the guide then, if you think it will get all my subs.
Nomake Wan
  Posted: May 27 2013, 07:55 AM


ShiMACHaze
**********

Group: Advanced Members
Posts: 19,542
Member No.: 5,394
Joined: Feb 5th 2005
Location: Drydock





The script error is very simple. It in fact tells you exactly where the problem lies and what the problem is. Thankfully I've already seen this error before, and it's a super easy fix. Assuming you're using my code and not your own, in your batch script, change this line:

CODE
echo FFVideoSource(%1, threads=1).AssumeFPS(24000,1001)>>"C:\Encoding\%~n1.avs"


to:

CODE
echo FFVideoSource("%1", threads=1).AssumeFPS(24000,1001)>>"C:\Encoding\%~n1.avs"


The reason being, the original version was designed for modern files which have spaces in them. For instance, something like "[gg] Aku no Hana - 00.mkv" would work properly. However, your original filename has no spaces in it and thus requires a slight change to the script in order to work. No big deal, and I think that's it. smile.gif Of course that assumes you're using my batch script. If you wrote your own (that is, if you put the filename in there manually), then change yours like so:

CODE
FFVideoSource("C:\Users\pcname\Videos\myvideo.mkv", threads=1).AssumeFPS(24000,1001)


On top of that, you are sure that it's 23.976 FPS correct? If your original video file is not 23.976 FPS the audio, video and subtitles will not sync properly. smile.gif

While I understand your desire to use VirtualDub, I must reiterate that putting h264 video into an AVI container is a huge, gigantic no-no. Do not do it, period. Just because a program lets you do something does not mean that it's correct or that it will work properly. So please, do not try using x264 with VirtualDub. wink2.gif

EDIT: Thanks for the note on Nero AAC. I've updated the tools section with a link to the tool package and where to install it. cool.gif

This post has been edited by Nomake Wan on May 27 2013, 08:01 AM
Proud Contributor of IDW Forums and the Music Section Revival Project
FC3SRedSuns
Posted: May 27 2013, 08:51 AM


REDSUNS42 Fansubs
*

Group: Members
Posts: 8
Member No.: 41,449
Joined: May 10th 2013
Location: Update Profile





Alright it's encoding and it's going to take awhile, so I'll get back to you later. Thanks.

EDIT: Thanks alot Nomake, I think it worked fine. It took awhile to reply back because I didn't want to encode the video until I was done with it.

Anyway, to avoid double posting, I just edited this post.

This post has been edited by FC3SRedSuns on May 29 2013, 09:05 AM