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. Domains: forum.doom9.org / forum.doom9.net / forum.doom9.se |
|
|
#1 | Link | |
|
Registered User
Join Date: Apr 2006
Posts: 225
|
Joints 1.0.2: joining files with unequal audio/video
I'm (neuron2) adding a link to Joints here to make it easy to find for newcomers to the thread:
http://neuron2.net/misc/joints102.zip ----- Quote:
Clip1: Video Frames: 3780 (126.126 sec) Audio Frames: 3942 (126.144 sec) Excess Audio: ~18ms <-Greater than 16ms (half of one frame) so DROP one audio frame! Audio is now ~14ms too short. Clip2: Video Frames: 1290 (43.043 sec) Audio Frames: 1346 (43.072 sec) Excess Audio: ~28ms <-WAIT! Audio is already 14ms behind. Adjust for previous clip: ~14ms <-Less than 16ms (half of one frame) so Leave this one alone! Audio is now ~14ms too long. Clip3: Video Frames: 810 (27.027 sec) Audio Frames: 845 (27.040 sec) Excess Audio: ~13ms <-WAIT! Audio is already 14ms ahead. Adjust for previous clip: ~27ms <-Greater than 16ms (half of one frame) so DROP one audio frame! Audio is now ~5ms too short Presto! Your clips are never more than 16ms out of sync either way. I've been doing this for a little over a year now with my camcorder's footage, and it works great. In fact, I just finished a trip that had about 271 clips. I use a spreadsheet in Excel to help me set everything up, including using DGAVCIndex to index all my clips and produce an audio file for each one. Using the .dga file for each clip, I can determine the number of video frames. I then run AC3 Cutter on all the audio clips, and it reports the number of audio frames. Once I have this information, all the information I posted above can be calculated. I then have tsMuxeR join all my clips together (with unsyncronized audio) and then have AC3 Cutter go in and trim out all the audio frames that I determined need to be cut out. I can then run tsMuxeR again, but this time have it not use the audio in my clips, but instead use the audio file created by AC3 Cutter. I now have a .M2TS file with all my videos joined together, and with syncronized audio. If this sounds like a complicated process, well yes it is. I consider it more of a proof-of-concept. Eventually, I'd like to either make up a little tool that would be able to generate the synced audio track, given a series of clips, or else hope that someone like Neuron2 would be willing to add code to his tools to create the synced audio track. All you need to know to do the calculations is: 1. Number of video frames per clip (Indexer already knows this) 2. Video frame rate (Indexer already knows this) 3. Number of audio frames per clip (this could be trickier) 4. Audio frame rate (31.25 fps for AC3 audio, the most common in AVCHD camcorders). By creating a "camcorder mode" in the indexer, AC3 audio can be assumed for now until more codecs start showing up. That might help figuring out #3. What do you think Neuron2? I'm willing to help you on this if you need any more info. Matt Last edited by Guest; 13th September 2009 at 23:36. |
|
|
|
|
|
|
#2 | Link |
|
Guest
Join Date: Jan 2002
Posts: 21,901
|
Yes, I understand that cutting audio is an option, but I assumed it may create objectionable pops.
But anyway, sure, it's possible. First, I'd prefer to do this with a preprocessing tool rather than in the DGNV tools. But second, as I said, it's very low on the priority list for me, especially since I have an acceptable (to me) workaround that doesn't involve the massive effort you are going through. |
|
|
|
|
|
#3 | Link | ||
|
Registered User
Join Date: Apr 2006
Posts: 225
|
Quote:
One other thing, I can think of a couple different types of "pops." One is caused by having a complete audio frame missing, which simply results in missing data. This can be tricky to hear if the audio is quiet. Even if it is loud, it may take careful listening to hear. These "pops" are not too bad, but should probably still be avoided. The other kind of "pop" occurs when a program blindly trims audio data as if it were LPCM. This can result in a very loud pop or chirp, since the compressed data has now been altered significantly. These types of "pops" should definitely be avoided. This is why I suggested the "camcorder mode" option. My method works for camcorder files, like the ones posted, but should not be used for seamless branching Blu Rays. Quote:
EDIT: BTW, it was only a massive effort creating the Excel file that I use as a template. Now, it's just a moderate effort.
Last edited by Turtleggjp; 9th September 2009 at 19:28. |
||
|
|
|
|
|
#5 | Link | |
|
Registered User
Join Date: Mar 2006
Posts: 1,538
|
Quote:
For example: RANGE 1110441 4582562 |
|
|
|
|
|
|
#7 | Link |
|
Registered User
Join Date: Apr 2006
Posts: 225
|
Found it:
http://forum.doom9.org/showthread.php?t=92325 I actually use a modified version that fixes a couple issues with his parsing of the cut list. I've been using it for a couple years now to cut the audio on my captured TV shows. Basically, it takes a VirtualDub style .vcf file as its cut list, which my Excel spreadsheet generates for me. For example, here is the one it generated for those 3 sample clips: Code:
VirtualDub.subset.AddRange(0,3941); VirtualDub.subset.AddRange(3942,1346); VirtualDub.subset.AddRange(5288,844); |
|
|
|
|
|
#8 | Link |
|
Guest
Join Date: Jan 2002
Posts: 21,901
|
Reading that thread, the author says it's buggy and shouldn't be used!
Who made your modifed version of it? Is it also buggy? Can we have the source code? What is the syntax of the AddRange() function? I'm sure people will ask: What about AAC, LPCM, and MPEG audio?
Last edited by Guest; 9th September 2009 at 21:37. |
|
|
|
|
|
#9 | Link | ||
|
Registered User
Join Date: Apr 2006
Posts: 225
|
Quote:
Quote:
AddRange(StartFrame, NumberOfFrames), just like VirtualDub. Good question. Do you know of any camcorders that use these? As I said, my method is so far only for AVCHD camcorder clips, not Blu Rays. Bottom line, AC3 cutter does have a lot of extra stuff in it that I never need, like patching bitrates to a higher one in order to maintain constant bitrate. I basically threw this method together with what I had and filled in the gaps where needed. I figured your tools already know how to pull the audio files out of .M2TS files, so it's just a matter of looking at the audio and counting how many frames are in it. With a little analysis, you can determine when to throw out a frame when joining files together. Really bottom line, this works great for me, and I would be happy to share what I know to get it working for others as well. EDIT: Most of my modifications to the code are in the "parseVCF" function in the "ac3functions.c" file. I seem to have commented it pretty well, so I hope you can follow what I did. Last edited by Turtleggjp; 9th September 2009 at 22:17. |
||
|
|
|
|
|
#11 | Link |
|
Registered User
Join Date: Apr 2006
Posts: 225
|
Absolutely. That's basically what my Excel spreadsheet does is generate that cut list. Prior to that though, it also creates a batch file that calls DGAVCIndex for each clip, and then another batch file that runs AC3 Cutter on all the audio clips created by the first batch file (to have it report number of audio frames for each one). Once the data from these two runs is gathered into my spreadsheet, it can make the cutlist. After that, AC3 Cutter does the actual cutting after tsMuxeR has (blindly) joined all the clips together and then demuxed the audio track.
|
|
|
|
|
|
#12 | Link |
|
Guest
Join Date: Jan 2002
Posts: 21,901
|
OK, first phase completed. I have a working GUI that takes a file list and determines the info needed for the cuts. Tested it successfully on the camcorder files and on Ratatouille M2TS files. The app is tentatively named "Joints".
Next step: integrate the cutter code so that the GUI app can directly correct the already demuxed audio file. Of course that will make the whole thing open source. Last edited by Guest; 10th September 2009 at 23:01. |
|
|
|
|
|
#13 | Link |
|
Guest
Join Date: Jan 2002
Posts: 21,901
|
Matt, I've run into a problem with your code. The syntax you give above for your AddRange calls passes the audio frame numbers, e.g. 3942 as the start of the second range. But it appears that these are interpreted as video frame numbers in the code:
Code:
FrameTime = 1 / vfps; Time = ((sFrame + nFrames) * FrameTime) - dDelay + Sync; RoundUp = ((Time / AC3Time) - (long)(Time / AC3Time)) >= .5; tPtr->endFrame = ((long)(Time / AC3Time)) + RoundUp; So, please explain. I do not see any reason for the cutter to know about the video frame rate if it is receiving cut data referred to audio frame numbering. I can fix it to use the audio frame numbering as it should but thought I better mention it so you are aware that you may have been doing things wrongly. Last edited by Guest; 11th September 2009 at 01:40. |
|
|
|
|
|
#14 | Link | |
|
Registered User
Join Date: Apr 2006
Posts: 225
|
Quote:
I made my fixes to the code in order to cut audio on HD captures long before I had my AVCHD camcorder. When I finally got my camcorder and realized what was happening when I tried to merge my clips together, I realized I needed a way to cut frames out. This led me back to AC3 Cutter. So as you can see, it's a classic case of using a program for something that it was not exactly intended to be used for. Anyway, to answer your question, you can probably ignore the code that seems to be converting video frames to audio frames. Whenever I run this program for this purpose, the two are the same. Matt EDIT: Here is a sample of one of my command lines: Code:
"E:\Apps\AC3 Cutter v0.4\AC3 Cutter.exe" -fr 31.25 -vcf "E:\Video Camera\AVCHD\090828 - Lake Basin\090828 \ - Lake Basin.vcf" -o "E:\Video Camera\AVCHD\090828 - Lake Basin\090828 - Lake Basin.txt" \ "Q:\090828 - Lake Basin.track_4352.ac3" "E:\Video Camera\AVCHD\090828 - Lake Basin\090828 - Lake Basin.ac3" Last edited by Guest; 11th September 2009 at 02:12. |
|
|
|
|
|
|
#16 | Link | |
|
Registered User
Join Date: Apr 2006
Posts: 225
|
Quote:
Like I said, this program was not designed for this particular application. Turned out, I was able to get it to work pretty well, and then it turned out that my fixes made it work perfectly. I've been meaning to write a tool like you are doing, but I feel fortunate that I was able to port my "code" over from Excel into a C++ program. As you have guessed, no I am not a professional software developer (yet...). |
|
|
|
|
|
|
#17 | Link |
|
Guest
Join Date: Jan 2002
Posts: 21,901
|
OK, I have fixed up the cutter. It is still separate and my GUI writes a cut list.
I applied it to the Ratatouille BD and the result was perfect sync. The process removed 512ms (16 frames) of audio as needed. I will integrate the cutter into the GUI and then make a beta release. Matt, I want to commend you and thank you for bringing this idea and process to the fore. Last edited by Guest; 11th September 2009 at 07:15. |
|
|
|
|
|
#18 | Link |
|
Guest
Join Date: Jan 2002
Posts: 21,901
|
It's all done and integrated into one convenient GUI.
You first demux the AC3 audio as usual. Then you open Joints, specify the source transport files, select the AC3 file, set your PIDs and frame rate, and then hit Process. When it finishes you have a trimmed AC3 file. A cut list is also written. I just have to write the help file and then you can have it. Last edited by Guest; 11th September 2009 at 15:01. |
|
|
|
|
|
#19 | Link |
|
Guest
Join Date: Jan 2002
Posts: 21,901
|
Joints 1.0.0
Here is the first version. Source code will be released after some initial feedback.
http://neuron2.net/misc/joints100.zip |
|
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|