IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Framework .NET Discussion :

[Multimedia] Encoder une vidéo : aucune info trouvable


Sujet :

Framework .NET

  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Février 2003
    Messages
    837
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France, Meurthe et Moselle (Lorraine)

    Informations forums :
    Inscription : Février 2003
    Messages : 837
    Points : 377
    Points
    377
    Par défaut [Multimedia] Encoder une vidéo : aucune info trouvable
    Bonjour à tous,

    Je cherche désesperement depuis 3 jours une methode pour encoder une vidéo sur un codec précis. Je ne trouve aucune info, mais vraiment rien du tout pour pouvoir faire cela.
    Comment procéder... rien de rien !

    Quelqu'un a-t-il des infos à ce sujet ?

    Merci d'avance car là je patauge severement

    @ bientot

  2. #2
    Membre expérimenté Avatar de Mose
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    1 143
    Détails du profil
    Informations personnelles :
    Âge : 47
    Localisation : France

    Informations forums :
    Inscription : Janvier 2006
    Messages : 1 143
    Points : 1 379
    Points
    1 379
    Par défaut
    Ca existe les API .Net de compression/décompression vidéo ?
    Sinon en COM c'est à peu près sûr, après faudra te renseigner sur l'interopérabilité...

  3. #3
    Membre averti
    Profil pro
    Inscrit en
    Février 2003
    Messages
    837
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France, Meurthe et Moselle (Lorraine)

    Informations forums :
    Inscription : Février 2003
    Messages : 837
    Points : 377
    Points
    377
    Par défaut
    Salut,

    Justement, je suis tombé sur un code nickel chrome ! il se sert de DirectShow et est capable d'encoder la vidéo sans programme tiers. Par contre j'ai beau faire je ne sais combien d'essais je n'arrive pas à ce que je cherche.
    Voici le source en question :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;
    using System.IO;
    using System.Runtime.InteropServices;
     
    using DirectShowLib;
     
    public class M2Mkv : Form
    {
        private Button button1;
        private RadioButton MkvRadioButton;
        private RadioButton WmvRadioButton;
        private GroupBox groupBox1;
        private Label label1;
     
        private Container components = null;
     
        // The main com object
        FilterGraph fg = null;
        // The graphbuilder interface ref
        IGraphBuilder gb = null;
        // The mediacontrol interface ref
        IMediaControl mc = null;
        // The mediaevent interface ref
        IMediaEventEx me = null;
     
        // Matroska support filter interface
        IBaseFilter matroska_mux = null;
     
        // variable to store the filename and extension
        string fName, fExt;
        // one "global" hr
        int hr;
     
        public M2Mkv()
        {
            InitializeComponent();
        }
     
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if (components != null) 
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }
     
    		#region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.button1 = new System.Windows.Forms.Button();
            this.label1 = new System.Windows.Forms.Label();
            this.MkvRadioButton = new System.Windows.Forms.RadioButton();
            this.WmvRadioButton = new System.Windows.Forms.RadioButton();
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.groupBox1.SuspendLayout();
            this.SuspendLayout();
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(16, 16);
            this.button1.Name = "button1";
            this.button1.TabIndex = 0;
            this.button1.Text = "Convert";
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // label1
            // 
            this.label1.Location = new System.Drawing.Point(24, 120);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(80, 24);
            this.label1.TabIndex = 1;
            // 
            // MkvRadioButton
            // 
            this.MkvRadioButton.Checked = true;
            this.MkvRadioButton.Location = new System.Drawing.Point(8, 16);
            this.MkvRadioButton.Name = "MkvRadioButton";
            this.MkvRadioButton.TabIndex = 2;
            this.MkvRadioButton.TabStop = true;
            this.MkvRadioButton.Text = "Convert to mkv";
            // 
            // WmvRadioButton
            // 
            this.WmvRadioButton.Location = new System.Drawing.Point(8, 40);
            this.WmvRadioButton.Name = "WmvRadioButton";
            this.WmvRadioButton.TabIndex = 3;
            this.WmvRadioButton.TabStop = true;
            this.WmvRadioButton.Text = "Convert to wmv";
            // 
            // groupBox1
            // 
            this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                                    this.WmvRadioButton,
                                                                                    this.MkvRadioButton});
            this.groupBox1.Location = new System.Drawing.Point(16, 40);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(128, 72);
            this.groupBox1.TabIndex = 4;
            this.groupBox1.TabStop = false;
            // 
            // M2Mkv
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(232, 150);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.label1,
                                                                          this.button1,
                                                                          this.groupBox1});
            this.MaximizeBox = false;
            this.Name = "M2Mkv";
            this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
            this.Text = "m2mkv";
            this.groupBox1.ResumeLayout(false);
            this.ResumeLayout(false);
     
        }
    		#endregion
     
        [STAThread]
        static void Main() 
        {
            Application.Run(new M2Mkv());
        }
     
        //
        // method to ask the user the filename
        //
        private void button1_Click(object sender, System.EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            if( ofd.ShowDialog() == DialogResult.OK ) 
            {
                FileInfo fi = new FileInfo( ofd.FileName );
                fExt = fi.Extension;
                fName = fi.FullName.Substring( 0, fi.FullName.Length - fExt.Length );
                CloseInterfaces();
                InitInterfaces();
                if( MkvRadioButton.Checked )
                  Convert2Mkv( fName );
                else
                  Convert2Wmv( fName );
            }
        }
     
        // 
        // This method create the filter graph
        //
        void InitInterfaces() 
        {
            try 
            {   
                fg = new FilterGraph();
                gb = (IGraphBuilder)fg;  
                mc = (IMediaControl)fg;
                me = (IMediaEventEx)fg;                
            }
            catch(Exception) 
            {
                MessageBox.Show( "Couldn't start" );
            }
        }  
     
        //
        //This method stop the filter graph and ensures that we stop
        //sending messages to our window
        //
        void CloseInterfaces() 
        {   
            if( me != null ) 
            {
                hr = mc.Stop();
                DsError.ThrowExceptionForHR( hr );
     
                hr = me.SetNotifyWindow( IntPtr.Zero , WM_GRAPHNOTIFY, IntPtr.Zero ); 
                DsError.ThrowExceptionForHR( hr );
            }  
            mc = null;
            me = null;
            gb = null;
            if( matroska_mux != null )
              Marshal.ReleaseComObject( matroska_mux );
            matroska_mux = null;
            if( fg != null ) 
                Marshal.ReleaseComObject( fg );
            fg = null;
        }   
     
     
        //
        // This method convert the input file to an mkv file
        //
        void Convert2Mkv( string fileName ) 
        {
            try 
            {
                label1.Text = "processing";
                button1.Enabled = false;
     
                hr = me.SetNotifyWindow( this.Handle , WM_GRAPHNOTIFY, IntPtr.Zero );
                DsError.ThrowExceptionForHR( hr );
     
                // we want to add a filewriter filter to the filter graph
                FileWriter file_writer = new FileWriter();
     
                // make sure we access the IFileSinkFilter interface to
                // set the file name
                IFileSinkFilter fs = (IFileSinkFilter)file_writer;
     
                fs.SetFileName( fileName + ".mkv", null );
                DsError.ThrowExceptionForHR( hr );
     
                // add the filter to the graph
                hr = gb.AddFilter( (IBaseFilter)file_writer, "File Writer" );
                DsError.ThrowExceptionForHR( hr );
     
                // create an instance of the matroska multiplex filter and add it
                // Matroska Mux Clsid = {1E1299A2-9D42-4F12-8791-D79E376F4143}	
                Guid guid = new Guid( "1E1299A2-9D42-4F12-8791-D79E376F4143" );
                Type comtype = Type.GetTypeFromCLSID( guid );
                matroska_mux = (IBaseFilter)Activator.CreateInstance( comtype );
     
                hr = gb.AddFilter( (IBaseFilter)matroska_mux, "Matroska Muxer" );
                DsError.ThrowExceptionForHR( hr );
     
                // use Intelligent connect to build the rest of the graph
                hr = gb.RenderFile( fileName + fExt, null );
                DsError.ThrowExceptionForHR( hr );
     
                // we are ready to convert
                hr = mc.Run();          
                DsError.ThrowExceptionForHR( hr );
            }
            catch( Exception ex ) 
            {
                MessageBox.Show( "Error converting to mvk: " + ex.Message );
            }
        }
     
        //
        // This method convert the input file to an wmv file
        //
        void Convert2Wmv( string fileName ) 
        {
            try 
            {
                label1.Text = "processing";
                button1.Enabled = false;
     
                hr = me.SetNotifyWindow( this.Handle , WM_GRAPHNOTIFY, IntPtr.Zero );
                DsError.ThrowExceptionForHR( hr );
     
                // here we use the asf writer to create wmv files
                WMAsfWriter asf_filter = new WMAsfWriter();
                IFileSinkFilter fs = (IFileSinkFilter)asf_filter;
     
                hr = fs.SetFileName( fileName + ".wmv", null );
                DsError.ThrowExceptionForHR( hr );
     
                hr = gb.AddFilter( (IBaseFilter)asf_filter, "WM Asf Writer" );
                DsError.ThrowExceptionForHR( hr );
     
                hr = gb.RenderFile( fileName + fExt, null );
                DsError.ThrowExceptionForHR( hr );
     
                hr = mc.Run();          
                DsError.ThrowExceptionForHR( hr );
            }
            catch( Exception ex ) 
            {
                MessageBox.Show( "Error converting to wmv: " + ex.Message );
            }        
        }
     
     
        int WM_GRAPHNOTIFY	= 0x00008001;
     
        protected override void WndProc( ref Message m )
        {
            if( m.Msg == WM_GRAPHNOTIFY )
            {
                int p1, p2;
                EventCode code;
     
                if( me == null )
                    return;
                while( me.GetEvent( out code, out p1, out p2, 0 ) == 0 ) 
                {                                                 
                    if( code == EventCode.Complete ) 
                    {                        
                        label1.Text = "done";
                        button1.Enabled = true;
                        mc.Stop();
                    }
     
                    me.FreeEventParams( code, p1, p2 );                                 
                 }
                return;
            }
            base.WndProc( ref m );
        }
    }
    Moi je cherche à encoder ma vidéo en Xvid et mp3 (format Psp). Le truc c'est qu'il faut que je lui précise ces codecs. Donc ni une ni deux, je lance graphedit et je chope les clsid des codecs en question.
    Problèmes rencontrés :
    - meme clsid entre xvid et mp3
    - en testant ca plante
    - comment on lie le tout ?
    - bref comment on se sert de ce code pour des cas particuliers comme le mien quoi.

    J'ai beau chercher y'a vraiment rien sur le web à ce propos

    Merci d'avance
    @++

Discussions similaires

  1. [DF]comment exprimer une DF x,y-> aucune info
    Par patdez dans le forum Merise
    Réponses: 1
    Dernier message: 28/01/2013, 00h01
  2. Encoder une vidéo pour iPhone avec ffmpeg
    Par ssayen dans le forum Vidéo
    Réponses: 1
    Dernier message: 04/01/2011, 16h58
  3. coment lire une vidéo .mp4 encodée avec du H264!
    Par ase707 dans le forum ActionScript 3
    Réponses: 0
    Dernier message: 21/07/2008, 14h31
  4. [MPEG] encoder une vidéo
    Par poukill dans le forum Bibliothèques
    Réponses: 5
    Dernier message: 31/07/2007, 16h25
  5. [Composants][Animation] Lire une vidéo compressée
    Par femtosa dans le forum Composants VCL
    Réponses: 6
    Dernier message: 03/09/2002, 08h03

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo