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 12th May 2010, 22:59   #1  |  Link
RiCON
Registered User
 
RiCON's Avatar
 
Join Date: Jan 2004
Posts: 69
Vfr.py - Auto Chapter & QPFile creator and Audio cutter for VFR video

Vfr.py Github Repo

Inspired on: Daiz's AutoMKVChapters, TheFluff's split_aud, BD_Chapters

Needs: Python 3.1; MkvToolNix

What it does (for now):

Reads the first line of uncommented Trims from an .avs;
Uses timecodes files to get each trim's frame's timestamp;
Offsets the trims accordingly;
Creates a basic xml with Matroska chapters, x264 chapters if ending in 'x264.txt' or OGM chapters if any other extension is used;
Creates a qpfile to use with x264;
Cuts and merges audio (as per split_aud, only using v2 timecodes instead of expecting cfr) (all options work as split_aud);
No longer needs tcConv but converts v1 timecodes to v2 internally;
If requested, can output v2 timecodes from v1 and fps parsing. If --ofps is being used, v2 timecodes will use it.;
Can output a qpfile with converted frames meant to be used for an ivtc'd encode using non-ivtc'd frames (feature inspired by automkvchapters) (not completely accurate, obviously);
Using FFmpegsource's CorrectNTSCRationalFramerate, this is actually more precise in the v2 timecodes it produces than tcConv.
Accepts AutoMKVChapters-like templates.

Only the .avs with trims is required for vfr.py to run. You can use -v and/or --test to debug the script. All other options and arguments are optional.

Usage:
Code:
vfr.py -i audio.aac -o audio.cut.mka -f 30/1.001 -l tRim -c chapters.xml -t template.txt \
-n chnames.txt -q qpfile.qpf -vmr --ofps 24/1.001 --timecodes v2.txt --test trims.avs outtrims.avs

Required:
trims.avs = Gets first uncommented line starting with trims from this Avisynth script

Optional:
-i = Audio to be cut (takes whatever mkvmerge takes)
-o = Cut audio inside .mka
     Default: input.cut.mka
-d = Manually set delay time for input audio (can be negative)
-b = Reverse parsing of .avs (from bottom to top)
-f = Frames per second or timecodes file if vfr input
     (takes "25", "24000/1001", "30000:1001", "24/1.001" and "30:1.001" as cfr input)
     Default: 30000/1001
-l = Look for a line starting with a case-sensitive trim() or case-insensitive comment succeeding the trims, interpreted as a regular expression.
     Default: case insensitive trim
-c = Chapters file. If extension is 'xml', outputs MKV Chapters;
     if extension is 'x264.txt', outputs x264 Chapters; else, outputs OGM Chapters
-n = Text file with chapter names, one per line; assumed to be UTF-8 without BOM
-q = QPFile for use in x264; will use --ofps frames
-t = Template file for advanced Matroska chapters
-v = Verbose mode
-m = Merge split audio files
-r = Remove split audio files after merging
--uid = Set base UID for --template/--chnames
--chnames = Path to basic text containing chapter titles separated by newlines
--ofps = Output FPS (used in qpfile, v2 timecodes and avs export)
         Default: -f
--timecodes = Output v2 timecodes (from fps and v1 parsing) (if using --ofps, outputs v2 timecodes using this)
--sbr = Set this if inputting an .aac and it's SBR/HE-AAC
--test = Test Mode (doesn't create new files)
outtrims.avs = If chapparse.py is present, outputs .avs with offset and converted trims
To do:
- optimize code and/or improve its legibility

Known issues:
- Conversion from a different input fps to output fps is not accurate (probably no way it can ever be fixed)

Any suggestions or issues are gladly welcome.

Archive:
Vfr.py 0.3
Vfr.py 0.4
Vfr.py 0.5
Vfr.py 0.5.1
Vfr.py 0.6
Vfr.py 0.6.1
Vfr.py 0.6.2
Vfr.py 0.6.3

Flattr me if you're feeling generous.

Last edited by RiCON; 28th May 2012 at 05:43. Reason: Changing README for 0.9
RiCON is offline   Reply With Quote
Old 13th May 2010, 03:01   #2  |  Link
RiCON
Registered User
 
RiCON's Avatar
 
Join Date: Jan 2004
Posts: 69
Vfr.py 0.4

Added CFR capabilities and test mode.

New options:
-f = frames per second; accepts int and float input with both ":" and "/" (stoeled from split_aud :V )
--test = doesn't create any new files (best used with -v)
RiCON is offline   Reply With Quote
Old 13th May 2010, 04:16   #3  |  Link
RiCON
Registered User
 
RiCON's Avatar
 
Join Date: Jan 2004
Posts: 69
Vfr.py 0.5

Added v1 timecodes "parsing".
Needs tcConv in path. If not in path, change the tcConv variable to where it's at. You only need it for v1 parsing.

Also added --frames option for use in v1 conversion. If not set, the script estimates the total frame count from the last trimmed frame + 2.

Vfr.py 0.5.1

A few bugs created in 0.5, fixed.

Last edited by RiCON; 13th May 2010 at 13:51.
RiCON is offline   Reply With Quote
Old 27th May 2010, 21:43   #4  |  Link
RiCON
Registered User
 
RiCON's Avatar
 
Join Date: Jan 2004
Posts: 69
Vfr.py 0.6

Ported to Python 3.1.2.
Changed some options so they do exactly the same as split_aud.
Fixed bug with scripts with a single trim.
Added edition to matroska chapter header.
Added tag header (doesn't create tag file yet).
Enabled audio cutting without chapter or qpfile creation (making it syntax-compatible replacement with split_aud.pl)
Moved avs input to arguments, since it's now the only required thing for vfr.py to run.
"Fixed" trims using last frame in timecodes file: will generate a synthetic timecode from the average time per frame of a few previous frames to use in audio cutting (not very accurate).
If timecode file input is used and trims refer to frames not in it, the script tries to generate the timecode from an average of some previous frames (not accurate).

Changed options:
Code:
vfr.py -i audio.aac -o cutaudio.mka -f 30000/1001 -t timecodes.txt -c chapters.xml -q qpfile.qpf -vmr --test --frames 9001 trims.avs

-i = Audio to be cut (takes whatever mkvmerge takes)
-o = Cut audio inside .mka
-f = Frames per second (takes "25", "24000/1001" and "30000:1001" as input)
-t = v1 or v2 timecodes file for vfr capabilities (needs tcConv.exe for v1 parsing)
-c = Chapters file. If extension is xml, outputs MKV Chapters, else it outputs OGM Chapters
-q = QPFile for use in x264
-v = Verbose mode
-m = Merge split audio files
-r = Remove split audio files after merging
--test = Test Mode (doesn't create new files)
--frames = number of frames for v1 to v2 timecodes conversion
trims.avs = Gets first uncommented line starting with trims from this Avisynth script
RiCON is offline   Reply With Quote
Old 28th August 2010, 01:59   #5  |  Link
RiCON
Registered User
 
RiCON's Avatar
 
Join Date: Jan 2004
Posts: 69
Vfr.py 0.6.1

Added x264 Chapters format (hours:minutes:seconds.milliseconds chaptername) introduced with the mp4muxer patch. Use 'x264.txt' as extension to select this format.
Added --label/-l from split_aud.pl. Works the same way (case sensitive). Default is still case insensitive Trim. Good for people who have different Trims and want to select the correct ones for the chapters.

Last edited by RiCON; 28th August 2010 at 02:13. Reason: Quick edit to add --label
RiCON is offline   Reply With Quote
Old 28th August 2010, 18:08   #6  |  Link
mastrboy
Registered User
 
Join Date: Sep 2008
Posts: 287
now this looks interesting, a small request would be a static compiled binary, i usually don't have python installed on my encode computers.
mastrboy is offline   Reply With Quote
Old 7th September 2010, 23:27   #7  |  Link
RiCON
Registered User
 
RiCON's Avatar
 
Join Date: Jan 2004
Posts: 69
I'll look into it.

Heh, haven't managed to find any way to compile it to a single standalone .exe.
Here you go.

Let me know if it even works (?)

Last edited by RiCON; 8th September 2010 at 02:26. Reason: Adding executable.
RiCON is offline   Reply With Quote
Old 15th September 2010, 02:57   #8  |  Link
RiCON
Registered User
 
RiCON's Avatar
 
Join Date: Jan 2004
Posts: 69
Vfr 0.6.2

Bug Fixes:
- fixed crash when vfr.py tried to delete a split that didn't exist

Changes:
- changed verbose output of merging and deleting to more closely resemble split_aud's


Vfr 0.6.3

Bug fixes:

- Script was crashing if mkvmerge returned with code 1.
- Audio delay wasn't working properly. Output should be bit-exact with split_aud.pl, now.
RiCON is offline   Reply With Quote
Old 16th September 2010, 14:22   #9  |  Link
mastrboy
Registered User
 
Join Date: Sep 2008
Posts: 287
Quote:
Originally Posted by RiCON View Post
I'll look into it.

Heh, haven't managed to find any way to compile it to a single standalone .exe.
Here you go.

Let me know if it even works (?)
I'll check it out when i get home
mastrboy is offline   Reply With Quote
Old 2nd October 2010, 15:27   #10  |  Link
RiCON
Registered User
 
RiCON's Avatar
 
Join Date: Jan 2004
Posts: 69
Vfr.py 0.6.4

Bug fixes:
- Regression with OGM and x264 chapters output

New feature:
- Looks for an AssumeFPS in the script, even if commented, and uses it to set the FPS if no --timecodes or --fps was used (still defaults to 30000/1001 if no AssumeFPS is found)
RiCON is offline   Reply With Quote
Old 7th December 2010, 00:43   #11  |  Link
RiCON
Registered User
 
RiCON's Avatar
 
Join Date: Jan 2004
Posts: 69
Vfr.py 0.7.1

Bug fixes:
- Fixed bug in "-o" when "-i" is used with absolute paths and "-o" is omitted

New features:
- Changed QPFile format to "frame K"
- Improved trim search algorithm
- Implement a ConvertFPS like automkvchapter's (useful for encoding IVTC'd TV encodes)
RiCON is offline   Reply With Quote
Old 14th December 2010, 21:17   #12  |  Link
RiCON
Registered User
 
RiCON's Avatar
 
Join Date: Jan 2004
Posts: 69
Vfr.py 0.7.2

Bug fixes:
- Fix regression in 0.7.1 that broke audio cutting
- Fix bug when chapter output was used with verbose mode

New features:
- Changed precision in CFR timestamp generation to mimic x264's (0.1ms precision)
- Added some test timecodes to help prevent regressions
- Added native v1 timecodes parsing (tcConv no longer needed)
- Added tccreator.py to test v2 timecodes generation using either CFR or v1 timecodes input (sort of like tcConv)
RiCON is offline   Reply With Quote
Old 26th December 2010, 17:40   #13  |  Link
RiCON
Registered User
 
RiCON's Avatar
 
Join Date: Jan 2004
Posts: 69
Vfr.py 0.7.3

Bug fixes:
- Fix (probably) rare bug if the input audio didn't have an extension
- Fix for bug when a lot of cuts were made which resulted in loss of sync of audio

New features:
- Add a rudimentary chapter template system (thanks to dj_tjerk)


Vfr.py 0.7.4

Bug fixes:
- Correct bug if there are no overrides in the v1 timecodes file

New features:
- Overhaul of the v1 timecodes parser: it's now much faster and no temporary file is needed


Vfr.py 0.7.4.1

Bug fixes:
- in Windows, only chapter names in the same codepage as the system worked; now both the template file and chapter file are assumed to be UTF-8 (without BOM)

New features:
- Python 2.x support ceased because of above bug fix
- Updated README

If anyone knows how to maintain compatibility with Python 2.7 with this encoding issue you're welcome to submit pull requests in GitHub or patches.
RiCON is offline   Reply With Quote
Old 29th December 2010, 05:56   #14  |  Link
RiCON
Registered User
 
RiCON's Avatar
 
Join Date: Jan 2004
Posts: 69
Vfr.py 0.7.5

New features:
- Ported CorrectNTSCRationalFramerate from FFmpegsource so all framerates are more exact (29.97 != 2997/100 but 30/1.001)
- Ported tcConv's v1 parsing as it's ages faster than mine was
- Added --otimecodes, which outputs v2 timecodes resulting from fps, v1 and --ofps parsing
RiCON is offline   Reply With Quote
Old 1st January 2011, 05:22   #15  |  Link
RiCON
Registered User
 
RiCON's Avatar
 
Join Date: Jan 2004
Posts: 69
Vfr.py 0.7.6

Bug fixes:
- Fix stupid/bad regression I somehow missed.
- Fix and clean tcconv.py

New features:
- Added MIT license
- General cleanups and minor optimizations
- Yet another rewrite of the timecodes parsing code
Code:
v2: 230k fps to 500k fps (2.2x faster)
v1 vfr: 73k fps to 370k fps (5x faster)
v1 cfr: 73k fps to 600k fps (8x faster)
- Joined --fps/-f and --timecodes/-t as --fps/-f and --otimecodes to --timecodes

In order to avoid unwanted behavior, I didn't map -t yet, so change whatever scripts you're using before updating.
RiCON is offline   Reply With Quote
Old 3rd January 2011, 16:32   #16  |  Link
RiCON
Registered User
 
RiCON's Avatar
 
Join Date: Jan 2004
Posts: 69
Vfr 0.7.6.1

New features:
- Moved frame padding to main() so parse_tc and convert_v1_to_v2 work as expected when imported from outside
- parse_tc and convert_v1_to_v2 can now return v2 timecodes from an arbitrary frame number instead of just 0
- If starting frame is not 0, no v2 timecodes header is added to --otc

These features are meant for the multithreaded branch but as they're also useful on their own I added them to trunk. Using the multithreaded script, tcconv vfr v1 parsing is 43% faster, putting it a little faster than tritical's tcconv and as fast as plain v2 parsing, but other than that, not much, so the mt branch is not merged yet.


Vfr.py 0.7.6.2

Bug fixes:
- Fix crash with --ofps
- Fix crash with --chnames
- Fix bug with .xml exporting
- Fix bug with --ofps where the timecodes used for the chapters were using the original fps instead of --ofps making them inaccurate

New features:
- Support running main() as a module (main(args) behaves as sys.argv)
- Created test.py as a fancy test.bat alternative to test for regressions. Not really that fancy, so don't overestimate it.


Is there any need to compile 0.x.x versions of vfr.py and tcconv.py for use in Windows x86/x64 without Python installed?
RiCON is offline   Reply With Quote
Old 8th January 2011, 04:06   #17  |  Link
RiCON
Registered User
 
RiCON's Avatar
 
Join Date: Jan 2004
Posts: 69
Vfr.py 0.7.7

New features:
- Remove AssumeFPS detection. On second thought, it's useless. Let me know if it isn't.
- Implement a few more functions, like avs and trim parsing and qpfile writing.
- Merge templates branch: Implemented AutoMKVChapters templates parser
- Made a few modifications of my own on the specification of amkvc's templates, more information/sample file in test/amkvc.mod.txt (without losing compatibility to amkvc's, afaik)
RiCON is offline   Reply With Quote
Old 8th January 2011, 06:16   #18  |  Link
RiCON
Registered User
 
RiCON's Avatar
 
Join Date: Jan 2004
Posts: 69
Vfr.py 0.8

Bug fix:
- Fix regression with --chnames

New features:
- templates.py works as a CLI interface for automkvchapters

Vfr.py 0.8.1

Bug fix:
- Overlooked something in --uid

New features:
- vfr.py now directly supports templates

Last edited by RiCON; 8th January 2011 at 07:02. Reason: Adding 0.8.1
RiCON is offline   Reply With Quote
Old 21st January 2011, 01:22   #19  |  Link
Ashald
Registered User
 
Join Date: Nov 2009
Posts: 1
Thanks, very useful script! :3

Can I request a feature? It'll be good, if vfr.py can suppress next mkvmerge warning message by default or by additional flag, adding the "--aac-is-sbr 0" to mkvmerge cli parameters:
Quote:
Warning: AAC files may contain HE-AAC / AAC+ / SBR AAC audio. This can NOT be detected automatically. Therefore you have to specifiy '--aac-is-sbr 0' manually for this input file if the file actually contains SBR AAC. The file will be muxed in the WRONG way otherwise. Also read mkvmerge's documentation.
Mkvmerge exited with warnings: 1

Last edited by Ashald; 26th January 2011 at 09:57.
Ashald is offline   Reply With Quote
Old 25th January 2011, 04:44   #20  |  Link
RiCON
Registered User
 
RiCON's Avatar
 
Join Date: Jan 2004
Posts: 69
Sure.

Vfr.py 0.8.2

Bug fixes:
- Correct bug when padding v2 timecodes
- Fix timecode output when using --ofps
- Fix crash when using vfr timecodes (regression in f7d0692)

New features:
- Change behavior a bit if -q is used in vfr.py (-q option will override the QPFile option in the template)
- Quit truncating timestamps

Vfr.py 0.8.3

Bug fixes:
- Fix (another) regression in test.py from f7d0692

New features:
- Add new test2.avs and supporting v1 timecodes
- Implement a new convert_fps algorithm
It's a bit more accurate than the previous one and also works with timecodes now (--ofps timecodes.txt).
It's also quite a bit slower, but shouldn't be too much.

Vfr.py 0.8.3.1

New feature:
- Add "--aac-is-sbr 0" to mkvmerge's cut command

Thanks, Ashald.
If someone ever cuts AAC SBR, let me know and I'll add the flag.

Last edited by RiCON; 25th January 2011 at 04:47. Reason: Add example for --ofps using timecodes
RiCON is offline   Reply With Quote
Reply

Tags
chapters, helper script, python, vfr

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 23:38.


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