[Résolu]La JMF et Manager.createDataSource()

La JMF et Manager.createDataSource() [Résolu] - Java - Programmation

Marsh Posté le 04-05-2007 à 18:52:49    

Je cherche à récupérer les informations contenues dans un avi (xvid) : j'utilise pour cela la JMF, sous Linux et l'IDE Netbeans.
Je n'ai encore jamais utilisé la JMF, je m'y essai. L'installation est réussie, tout compile bien. Ma classe est simplement un constructeur qui crée un DataSource() a partir d'une string pointant vers un fichier avi existant.
 

Code :
  1. package vdubsharing;
  2. import java.io.IOException;
  3. import javax.media.*;
  4. import javax.media.protocol.DataSource;
  5. public class MediaInfos {
  6.     private DataSource movie;
  7.     private MediaLocator source;
  8.    
  9.     /** Creates a new instance of MediaInfos */
  10.     public MediaInfos(String path){
  11.         this.source = new MediaLocator(path);
  12.         System.out.println(this.source.toString());
  13.         try {
  14.             this.movie = Manager.createDataSource(this.source);
  15.         } catch (IOException e) {
  16.             System.out.println("Erreur d'entree sortie : fichier "+path+" introuvable" );
  17.         } catch(NoDataSourceException e){
  18.             System.out.println("NoDataSourceException : fichier "+path);
  19.         }
  20.     }
  21.    
  22.     public String getInfos()
  23.     {
  24.         if(this.movie!=null)
  25.             return this.movie.getContentType();
  26.         else return new String("Erreur : initialisation non effectuee !" );
  27.     }
  28.    
  29.     public static void main(String[] args)  //pour tester la classe
  30.     {
  31.         String path = new String("/media/data/Mule/love.avi" );
  32.         System.out.println("path "+path);
  33.         MediaInfos infos = new MediaInfos(path);
  34.         System.out.println(infos.getInfos());
  35.     }
  36.    
  37. }


 
La console me renvoi ceci :  

Code :
  1. path /media/data/Mule/love.avi
  2. /media/data/Mule/love.avi
  3. NoDataSourceException : fichier /media/data/Mule/love.avi
  4. Erreur : initialisation non effectuee !


 
Apparemment la ligne this.movie = Manager.createDataSource(this.source); renvoi une exception... mais pourquoi donc ? Je n'effectue pas les opérations dans l'ordre, il me faut utiliser ces classes autrement ?? Parce qu'un petit mplayer /media/data/Mule/love.avi fonctionne tres bien  :D  
La seule chose qui peut peut etre gener, c'est que le fichier est sur une partition fat32.. mais bon  :sarcastic:  
 
Avez-vous une idée ? Merci.


Message édité par guepe le 16-05-2007 à 18:14:35

---------------
Un blog qu'il est bien
Reply

Marsh Posté le 04-05-2007 à 18:52:49   

Reply

Marsh Posté le 05-05-2007 à 00:44:52    

Et la réponse est ...

Code :
  1. package vdubsharing;
  2. import java.io.IOException;
  3. import java.net.MalformedURLException;
  4. import javax.media.*;
  5. import javax.media.protocol.DataSource;
  6. import java.net.URL;
  7. import java.io.File;
  8. public class MediaInfos {
  9.     private DataSource movie;
  10.     private MediaLocator source;
  11.     private URL url_source=null;
  12.    
  13.     /** Creates a new instance of MediaInfos */
  14.     public MediaInfos(String path){
  15.         File f = new File(path);
  16.         try {
  17.             this.url_source = f.toURL();
  18.         } catch (MalformedURLException ex) {
  19.             ex.printStackTrace();
  20.         }
  21.        
  22.         this.source = new MediaLocator(this.url_source);
  23.        
  24.         try {
  25.             this.movie = Manager.createDataSource(this.source);
  26.         } catch (IOException e) {
  27.             System.out.println("Erreur d'entree sortie : fichier "+path+" introuvable" );
  28.         } catch(NoDataSourceException e){
  29.             System.out.println("NoDataSourceException : fichier "+path);
  30.         }
  31.     }
  32.    
  33.     public String getInfos()
  34.     {
  35.         if(this.movie!=null)
  36.             return this.movie.getContentType();
  37.         else return new String("Erreur : initialisation non effectuee !" );
  38.     }
  39.    
  40.     public static void main(String[] args)  //pour tester la classe
  41.     {
  42.         String path = new String("/media/data/Mule/love.avi" );
  43.         System.out.println("path "+path);
  44.         MediaInfos infos = new MediaInfos(path);
  45.         System.out.println(infos.getInfos());
  46.     }
  47.    
  48. }


 
Works  [:jayz]


---------------
Un blog qu'il est bien
Reply

Marsh Posté le 05-05-2007 à 16:28:02    

Mouais bah... j'essai via DataSource de capturer la longueur du fichier avi... pourtant ce n'est pas un stream, donc la durée doit etre connue, mais il renvoie DURATION_UNKNOWN. Voila a quoi ressemble la classe maintenant  
 

Code :
  1. package vdubsharing;
  2. import java.io.IOException;
  3. import java.net.MalformedURLException;
  4. import javax.media.*;
  5. import javax.media.protocol.DataSource;
  6. import java.net.URL;
  7. import java.io.File;
  8. public class MediaInfos {
  9.     private DataSource movie;
  10.     private MediaLocator source;
  11.     private URL url_source=null;
  12.    
  13.     /** Constructeur de la classe
  14.      * @param path chemin complet du fichier recherche
  15.      */
  16.     public MediaInfos(String path){
  17.         File f = new File(path);
  18.         try {
  19.             this.url_source = f.toURL();
  20.         } catch (MalformedURLException ex) {
  21.             ex.printStackTrace();
  22.         }
  23.        
  24.         this.source = new MediaLocator(this.url_source);
  25.        
  26.         try {
  27.             this.movie = Manager.createDataSource(this.source);
  28.         } catch (IOException e) {
  29.             System.out.println("Erreur d'entree sortie : fichier "+path+" introuvable" );
  30.         } catch(NoDataSourceException e){
  31.             System.out.println("NoDataSourceException : fichier "+path);
  32.         }
  33.     }
  34.    
  35.     /**
  36.      * Renvois le type de video, une erreur si le fichier n'est pas trouvé
  37.      **/
  38.     public String getInfos()
  39.     {
  40.         if(this.movie!=null)
  41.             return this.movie.getContentType();
  42.         else return new String("Erreur : initialisation non effectuee !" );
  43.     }
  44.    
  45.     /**
  46.      * Renvoi la longueur de la video, null si le fichier n'est pas trouvé. Appeler la méthode getNanoseconds() pour utiliser la structure Time.
  47.      * @see Time
  48.      **/
  49.     public Time getDuration()
  50.     {
  51.         if(movie.getDuration()==Duration.DURATION_UNKNOWN)
  52.             System.out.println("Duree inconnue" );
  53.         else if(movie.getDuration()==Duration.DURATION_UNBOUNDED)
  54.             System.out.println("Duree non accrochée" );
  55.         System.out.println(movie.getDuration().getNanoseconds());
  56.         if(this.movie!=null)
  57.             return this.movie.getDuration();
  58.         else return null;
  59.     }
  60. }


 
Je sais que ca n'a pas l'air de soulever les foules... mais sait-on jamais !


---------------
Un blog qu'il est bien
Reply

Marsh Posté le 11-05-2007 à 00:44:38    

Salut,
si JMF n'arrive pas à déterminer la durée de ton flux, c'est pt-ê pq ton codecn'est pas suffisamment performant.
 
Essaye d'installer jffmpeg(plante tt le tps chez moi) ou Fobs4JMF(un autre wrapper de ffmpeg pr JMF mais qui marche celui là) pour traiter tes fichiers.
 
 :hello:


---------------
Voir les RAW sous Android: https://market.android.com/details? [...] .RawVision Blog Photo: http://photouch.me Applications mobiles: http://caketuzz.com Wapcam Project: http://wapcam.mobi
Reply

Marsh Posté le 16-05-2007 à 18:14:18    

Bon la solution la plus efficace c'a été pour moi d'installer Fobs4JMF... ca marche TROP BIEN  :jap:


---------------
Un blog qu'il est bien
Reply

Marsh Posté le 16-05-2007 à 18:34:13    

Ben je dirais pas que ca marche trop bien pq les plantages de dll ont tendance à provoquer des arrêts brutaux de la JVM chez moi.
Mais c'est clair que ça marche déjà beaucoup mieux que le JMF de base.


---------------
Voir les RAW sous Android: https://market.android.com/details? [...] .RawVision Blog Photo: http://photouch.me Applications mobiles: http://caketuzz.com Wapcam Project: http://wapcam.mobi
Reply

Marsh Posté le 16-05-2007 à 19:26:35    

wapcamer a écrit :

Ben je dirais pas que ca marche trop bien pq les plantages de dll ont tendance à provoquer des arrêts brutaux de la JVM chez moi.
Mais c'est clair que ça marche déjà beaucoup mieux que le JMF de base.


Pour ce que je fais aussi... je récupère juste la longueur d'un fichier avi... et je bosse sous linux  :o


---------------
Un blog qu'il est bien
Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed