Fix A/V Sync code : Fix 23.976/25fps A/V Mismatch

Discuss issues related to PS3 Media Server development (only for programmers)

Re: New A/V Sync Plugin : working mod(no plugin support for now)

Postby jaqb » Wed Aug 19, 2009 11:53 pm

Yes the video is getting more out of sync the more it progresses...
HD YouTube on PS3 -> PS3 Youtube :D Are you a F1 fan ? Check out F1Reader.com
jaqb
 
Posts: 163
Joined: Tue Jan 27, 2009 11:50 am

Re: New A/V Sync Plugin : working mod(no plugin support for now)

Postby ExSport » Wed Aug 19, 2009 11:54 pm

What is going on:
CZ audio part is in 25fps
EN audio part and video part is 23.976.
Because that when you will play czech audio(25fps) with video(23.976), movie is jerky or not synced(depending on ALTERNATE METHOD settings).
It will fix -ofps 25 parameter in mencoder or forced 25 fps in metafile of tsMuxeR instead of detected 23.976 fps :mrgreen:
Because that I created this patch which will fix this behavior for 23.976/25fps combined files. Also removing (-noskip -mc 0)=enabled alternate method will help for fixing possible audio delays which PMS can't detect( -mc 0.005 will do the trick)
Last edited by ExSport on Sat Sep 12, 2009 7:53 am, edited 1 time in total.
ExSport
 
Posts: 2168
Joined: Mon Jan 19, 2009 5:40 pm

Re: New A/V Sync Plugin : working mod(no plugin support for now)

Postby jaqb » Thu Aug 20, 2009 12:25 am

ok, I'm giving up for today...maybe another time...I was trying to make this thing standalone...but I'm too tired :P . To get you on the right track and to answer your questions, if you want to disable forcefps (or change anything else) temporarily(read: for the current file) just create an new engine...ie copy mencoder engine, change name and ID and just setup the desired settings, this way you'll only have new classes and you'll not to have to change the existing ones (so plugin will be possible)... to call a Player you use something like
Code: Select all
Player pl = new MEncoderVideoNEW(PMS.getConfiguration());
then the same thing u tried already... make a second transcode folder using your custom engines and you're done. should be quick and easy ;-) hehe
HD YouTube on PS3 -> PS3 Youtube :D Are you a F1 fan ? Check out F1Reader.com
jaqb
 
Posts: 163
Joined: Tue Jan 27, 2009 11:50 am

Re: New A/V Sync Plugin : working mod(no plugin support for now)

Postby ExSport » Thu Aug 20, 2009 12:40 am

Thanks jaqb for leading me to working code. 8-)
This same idea I already had but I don't know how to only change part of code instead of copy whole class.
I think it is only possible with interfaces? I am trying to avoid full copy of class because when some PMS code will change in future, my copied "old" class will not be up to date anymore :?
But I don't know if it is possible in java to change only one method in whole class to avoid future outdated code due to copied whole class...
ExSport
 
Posts: 2168
Joined: Mon Jan 19, 2009 5:40 pm

Re: New A/V Sync Plugin : working mod(no plugin support for now)

Postby ExSport » Mon Sep 07, 2009 10:56 pm

Again I have little bit more "free" time so I will try to optimize this crappy code :mrgreen:
Who already tested it, please don't hesitate to post a comment.
Here is the code and also compiled pms.jar file: viewtopic.php?f=2&t=3336&start=10#p14905
Thanks
ExSport
 
Posts: 2168
Joined: Mon Jan 19, 2009 5:40 pm

Re: New A/V Sync Plugin : working mod(no plugin support for now)

Postby ExSport » Fri Oct 16, 2009 8:39 pm

New version which is not dependent on custom PMS settings/configuration.
This version is working without any special manually modified settings in PMS configuration so it is compatible with any settings :)

Patched FileTranscodeVirtualFolder.java:
Code: Select all
Index: net/pms/dlna/FileTranscodeVirtualFolder.java
===================================================================
--- net/pms/dlna/FileTranscodeVirtualFolder.java   (revision 363)
+++ net/pms/dlna/FileTranscodeVirtualFolder.java   (working copy)
@@ -20,6 +20,7 @@
 
 import net.pms.PMS;
 import net.pms.dlna.virtual.VirtualFolder;
+import net.pms.dlna.virtual.VirtualVideoAction;
 import net.pms.encoders.MEncoderVideo;
 import net.pms.encoders.Player;
 import net.pms.encoders.TSMuxerVideo;
@@ -41,6 +42,16 @@
          if (child.ext.getProfiles() != null) {
             DLNAResource ref = child;
             Player tsMuxer = null;
+            DLNAResource virtfix = child;
+            virtfix = new VirtualVideoAction("  !!-- Fix A/V Sync --!!", PMS.getConfiguration().isMencoderForceFps()) { //$NON-NLS-1$
+                   public boolean enable() {
+                       PMS.getConfiguration().setMencoderForceFps(!PMS.getConfiguration().isMencoderForceFps());
+                       PMS.getConfiguration().setTsmuxerForceFps(PMS.getConfiguration().isMencoderForceFps());
+                       return PMS.getConfiguration().isMencoderForceFps();
+                   }             
+            };
+            children.add(virtfix);
+            virtfix.parent = this;
             for(int i=0;i<child.ext.getProfiles().size();i++) {
                Player pl = PMS.get().getPlayer(child.ext.getProfiles().get(i), child.ext);
                if (pl !=null && !child.player.equals(pl)) {

Patched MEncoderVideo.java:
Code: Select all
Index: net/pms/encoders/MEncoderVideo.java
===================================================================
--- net/pms/encoders/MEncoderVideo.java   (revision 363)
+++ net/pms/encoders/MEncoderVideo.java   (working copy)
@@ -283,6 +283,7 @@
       
        forcefps = new JCheckBox(Messages.getString("MEncoderVideo.4")); //$NON-NLS-1$
        forcefps.setContentAreaFilled(false);
+       forcefps.setEnabled(false);
        if (configuration.isMencoderForceFps())
           forcefps.setSelected(true);
        forcefps.addItemListener(new ItemListener() {
@@ -1266,10 +1267,10 @@
       cmdArray[cmdArray.length-8] = "-quiet"; //$NON-NLS-1$
       cmdArray[cmdArray.length-7] = "-quiet"; //$NON-NLS-1$
       
-      if (configuration.isMencoderForceFps()) {
-         cmdArray[cmdArray.length-8] = "-fps"; //$NON-NLS-1$
-         cmdArray[cmdArray.length-7] = "24000/1001"; //$NON-NLS-1$
-      }
+//      if (configuration.isMencoderForceFps()) {
+//         cmdArray[cmdArray.length-8] = "-fps"; //$NON-NLS-1$
+//         cmdArray[cmdArray.length-7] = "24000/1001"; //$NON-NLS-1$
+//      }
       cmdArray[cmdArray.length-6] = "-ofps"; //$NON-NLS-1$
       cmdArray[cmdArray.length-5] = "24000/1001"; //$NON-NLS-1$
       String frameRate = null;
@@ -1278,8 +1279,11 @@
       }
       if (frameRate != null) {
          cmdArray[cmdArray.length-5] = frameRate;
-         if (configuration.isMencoderForceFps())
-            cmdArray[cmdArray.length-7] = cmdArray[cmdArray.length-5];
+         if (configuration.isMencoderForceFps()) {
+            cmdArray[cmdArray.length-8] = "-mc";
+            cmdArray[cmdArray.length-7] = "0.005";
+            cmdArray[cmdArray.length-5] = "25";
+         }
       }
       
       if (subString != null && !configuration.isMencoderDisableSubs() && !avisynth()) {
@@ -1444,10 +1448,13 @@
       }
       
       if ((pcm || dts || mux) || (PMS.getConfiguration().isMencoderNoOutOfSync() && !noMC0NoSkip)) {
+         if (!PMS.getConfiguration().isMencoderForceFps()) {
          cmdArray = Arrays.copyOf(cmdArray, cmdArray.length +3);
          cmdArray[cmdArray.length-5] = "-mc"; //$NON-NLS-1$
-         cmdArray[cmdArray.length-4] = "0"; //$NON-NLS-1$
-         cmdArray[cmdArray.length-3] = "-noskip"; //$NON-NLS-1$
+         cmdArray[cmdArray.length-4] = "0.005"; //$NON-NLS-1$
+         cmdArray[cmdArray.length-3] = "-quiet"; //$NON-NLS-1$
+      //   cmdArray[cmdArray.length-3] = "-noskip"; //$NON-NLS-1$
+         }
       }
       
       if (params.timeend > 0) {

Patched TSMuxerVideo.java:
Code: Select all
Index: net/pms/encoders/TSMuxerVideo.java
===================================================================
--- net/pms/encoders/TSMuxerVideo.java   (revision 363)
+++ net/pms/encoders/TSMuxerVideo.java   (working copy)
@@ -119,7 +119,7 @@
                }
             }
          }
-         
+      
          if (media != null && configuration.isTsmuxerForceFps()) {
             fps = media.getValidFps(false);
          }
@@ -392,6 +392,9 @@
             String videoparams = "level=4.1, insertSEI, contSPS, track=1"; //$NON-NLS-1$
             if (this instanceof TsMuxerAudio)
                videoparams = "track=224"; //$NON-NLS-1$
+            if (configuration.isTsmuxerForceFps()) {
+               fps = "25";
+            }
             pw.println(videoType + ", \"" + ffVideoPipe.getOutputPipe() + "\", "  + (fps!=null?("fps=" +fps + ", "):"") + videoparams); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
          }
          if (ffAudioPipe != null && ffAudioPipe.length == 1) {
@@ -521,6 +524,7 @@
         
         tsmuxerforcefps = new JCheckBox(Messages.getString("TSMuxerVideo.2")); //$NON-NLS-1$
         tsmuxerforcefps.setContentAreaFilled(false);
+        tsmuxerforcefps.setEnabled(false);
         if (configuration.isTsmuxerForceFps())
            tsmuxerforcefps.setSelected(true);
         tsmuxerforcefps.addItemListener(new ItemListener() {

Here is already compiled pms.jar file + patch file itself (build r363): http://www.megaupload.com/?d=GNWFFN9M

Please post results if you will test it ;) (Working like charm for me 8-) )

Usage:
Download ZIP file and extract it to the installation folder => replace pms.jar file there.

When you will browse #TRANSCODE# folder you will see new file named !!-- Fix A/V Sync --!!

With this you can fix mismatch/synchronization between 23.976fps video and 25fps audio [muxed bluray-rip(23.976fps) with DVD PAL(25fps) audio together]

ExSport
Last edited by ExSport on Tue Oct 20, 2009 11:17 pm, edited 1 time in total.
ExSport
 
Posts: 2168
Joined: Mon Jan 19, 2009 5:40 pm

Re: Fix A/V Sync code : Fix 23.976/25fps A/V Mismatch

Postby reginald » Tue Oct 20, 2009 11:13 pm

I just tested on my Bravia v5500, and it works like a chaaaarm!

Great job man!!!!!
reginald
 
Posts: 7
Joined: Sun Sep 20, 2009 2:59 pm

Re: Fix A/V Sync code : Fix 23.976/25fps A/V Mismatch

Postby ExSport » Wed Oct 21, 2009 1:05 pm

Great :mrgreen:
Thanks for report that it is useful not only for me 8-)
ExSport
 
Posts: 2168
Joined: Mon Jan 19, 2009 5:40 pm

Re: Fix A/V Sync code : Fix 23.976/25fps A/V Mismatch

Postby reginald » Wed Oct 21, 2009 7:27 pm

No thank you!

I was planning to reencode those videos films that were not synchronizing in PMS friendly way. But now I don't have to :)

Works out of Box.

How come this is not part of the main baseline?
reginald
 
Posts: 7
Joined: Sun Sep 20, 2009 2:59 pm

Re: Fix A/V Sync code : Fix 23.976/25fps A/V Mismatch

Postby shagrath » Thu Oct 22, 2009 10:44 pm

Actually I would prefer to get some optional additional code, rather than changing the actual code behavior... for example, the tsmuxer_forcefps option is set to to true by default in the stable release, so all upgrading users will inherit the "-fps 25" setting in the tsmuxer code, ending with a lot of out of sync :p
shagrath
Project Lead
 
Posts: 2667
Joined: Wed Jan 14, 2009 1:39 pm

PreviousNext

Return to Developers

Who is online

Users browsing this forum: Bing [Bot] and 3 guests