2 Replies - 5315 Views - Last Post: 21 November 2011 - 08:58 AM Rate Topic: -----

#1 ravikoneru9  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 28-June 10

Converting JPG into WMV or AVI format Using Windows Media SDK 9.0

Posted 30 June 2010 - 10:56 PM

I'm working on Converting JPG|JPEG, GIF|GIFF, TIF|TIFF Pictures into WMV or AVI format (WEB

APPLICATION) which are supported by YouTube(NOT FLV Format) . can any

One provide me code for that . I'm Using Windows Media SDK 9.0

and I don't Know who to create profiles for WMEncoder

this is the Code I'm Using
________________________________________________________________________
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using WMEncoderLib;
using WMPREVIEWLib;
using System.IO;

namespace ConvertImagesToMovie
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{

public static string profileName = Environment.CurrentDirectory + "\\imageencoder4.wme";
public static string picture_source1 =Environment.CurrentDirectory + "\\clock_02.jpg";
//public static string movie_dest = Environment.CurrentDirectory +"\\dest.avi";
public static string movie_dest = Environment.CurrentDirectory +"\\dest.wmv";

WMEncoder glbEncoder = new WMEncoder();
IWMEncSourceGroupCollection SrcGrpColl=null;
private System.Windows.Forms.Timer timer1;
private System.ComponentModel.IContainer components;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
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.components = new System.ComponentModel.Container();
this.timer1 = new System.Windows.Forms.Timer(this.components);
//
// timer1
//
this.timer1.Interval = 1000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Enabled = false;
this.Name = "Form1";
this.Opacity = 0;
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
if ( args.Length >0 && !"".Equals(args[0]) )
picture_source1 =args[0];
if (args.Length >1 && !"".Equals(args[1]) )
{
movie_dest=args[1];
}

Application.Run(new Form1());
Console.ReadLine();
}

private void Form1_Load(object sender, System.EventArgs e)
{
this.Visible = false;
EncodeFromConsole();
this.Visible = false;

}
private FileInfo [] getFiles (string sourceImageName)
{
FileInfo file = new FileInfo(sourceImageName);
string initialStr = file.Name.Substring(0, file.Name.LastIndexOf("_"));

System.IO.DirectoryInfo dir = file.Directory;
System.IO.FileInfo [] f = dir.GetFiles(initialStr+"*"+file.Extension );

return f;
}
/// <summary>
/// DOESNOT WORK
/// </summary>
/// <returns></returns>
public IWMEncProfile getProfile1()
{
WMEncProfile2 Pro = new WMEncProfile2();
try
{
Pro.LoadFromFile(@"C:\Program Files\Windows Media Components\Encoder\Profiles\scmeda.prx");
}
catch (Exception ex)
{
Console.Error.WriteLine ( ex.Message);
return null;
}
return Pro;
}
/// <summary>
/// DOESNOT WORK
/// </summary>
/// <returns></returns>
public IWMEncProfile getProfile ()
{
IWMEncProfileCollection ProColl;
IWMEncProfile Pro=null;
int i;
long lLength;
ProColl = glbEncoder.ProfileCollection;
lLength = ProColl.Count;
for (i = 0; i <= lLength - 1; i++)
{
Pro = ProColl.Item(i);
if (Pro.Name == "Multiple bit rates video (CBR)")
{
break;
}
}
//IWMEncBroadcast broadcast = glbEncoder.Broadcast;
//broadcast.set_PortNumber(WMENC_BROADCAST_PROTOCOL.WMENC_PROTOCOL_HTTP,9091);
return Pro;
}


/// <summary>
/// The below method/imageencoder4.wme and idea has been taken from a post in microsoft.public.windowsmedia.encoder group "Create WMV files from images (JPG)"
///
/// Although this is published in a public forum and is therefore open source,
/// I would like due attribution to be retained in any derivative works using or adapting this code -
/// please retain this message in your source files, thanks (p) Neil Smith / WM Digital Media MVP 2005
///
/// Thanks to Rehan Ahmad and Dean Rowe for the suggestion to use a broadcast profile to counter the
/// non-encoding of image sequences. This overcomes a limitation in the encoder,
/// which won't encode any images unless the profile is set to broadcast as well as file archive
/// </summary>
/// <returns></returns>

public IWMEncProfile getProfileByTrick()
{

glbEncoder.Load(profileName);

IWMEncSourceGroup SourceItem=SrcGrpColl.Item(0);
IWMEncProfile SourceProfile=SourceItem.get_Profile();
SrcGrpColl.Remove(SourceItem);

return SourceProfile;
}
private bool sEncodeFile(string sourceImageName,string destinationFileName)
{
try
{
FileInfo [] files = getFiles(sourceImageName);

totalFiles = files.Length;
IWMEncProfile SourceProfile=null;
SrcGrpColl=glbEncoder.SourceGroupCollection;
//SourceProfile = getProfile();
SourceProfile = getProfileByTrick();
//SourceProfile = getProfile1();


string previousId = "";
IWMEncSourceGroup2 SrcGrp=null;
for (int i=0; i<files.Length; i++)
{
SrcGrp=(IWMEncSourceGroup2)SrcGrpColl.Add("ImageFileSource_"+i);
previousId = "ImageFileSource_"+i;
SrcGrp.set_Profile(SourceProfile);
//SrcGrp.SetAutoRollover ( -1,previousId);
IWMEncVideoSource2 SrcVid=(IWMEncVideoSource2)SrcGrp.AddSource(WMENC_SOURCE_TYPE.WMENC_VIDEO);
SrcVid.SetInput(files[i].FullName,"","" );
}
glbEncoder.File.LocalFileName=destinationFileName;


try
{
glbEncoder.PrepareToEncode(true);
}
catch (Exception ex)
{
Console.Error.WriteLine ( ex.Message);
return false;
}
try
{
timer1.Start();
finished=false;
glbEncoder.Start();
Console.WriteLine ("Started making File ");
}
catch (Exception ex)
{
Console.Error.WriteLine ( ex.Message);
return false;
}
return true;
}
catch(Exception ex){
Console.Error.WriteLine ( ex.Message);
}
return false;
}


public void EncodeFromConsole()
{
bool boolEncodeStart = sEncodeFile(picture_source1,movie_dest );
while (!finished)
{
Application.DoEvents();
}
Console.WriteLine ("Finished making File ");
Application.Exit ();
}
int currentFileProcessed=0;
int totalFiles=0;
private void timer1_Tick(object sender, System.EventArgs e)
{

// window.status="Processing : "+currentFileProcessed;

if (currentFileProcessed < totalFiles)
{
if(SrcGrpColl.Item(currentFileProcessed)!=null)
{
IWMEncSourceGroup selectedSource=SrcGrpColl.Item(currentFileProcessed);
if (selectedSource.Name.StartsWith("ImageFileSource") )
{
glbEncoder.SourceGroupCollection.Active = selectedSource;
}
}

}
else
{
stopEncoder();
}
currentFileProcessed++;
}

bool finished=true;
private void stopEncoder()
{
glbEncoder.Stop();
timer1.Stop();
finished=true;

}

}


}

________________________________________________________________________
I found this code at

http://www.koders.co...l+Smith%22#L164[^]

The Error Triggering at
glbEncoder.PrepareToEncode(true);

Actually, they provided 12 images of JPG with an imageencoder4.wme file profile
Here is the Profiles code:

________________________________________________________________________

<?xml version="1.0"?>
<WMEncoder major_version="9"
    minor_version="0"
    Name="WMEncoder30307219731796"
    SynchroniesOperation="0" >
    <Description />
    <SourceGroups >
        <SourceGroup Name="Source1"
            RolloverType="-1"
            RolloverSourceGroup="WMENC_SOURCEGROUP_AUTOROLLOVER_TO_NEXT" >
            <Source Type="WMENC_VIDEO"
                Scheme="file"
                InputSource="C:\Documents and Settings\raviteja.koneru\Desktop\YouTube_ImagConverter\Image2Movie\ConvertImagesToMovie\bin\Debug\clock_03.jpg"
                PixelAspectRatioX="1"
                PixelAspectRatioY="1" >
                <UserData >
                </UserData>
            </Source>
            <EncoderProfile id="Multiple bit rates video (CBR)" />
            <UserData >
                <WMENC_LONG Name="Video0\CropMethod" Value="0" />
                <WMENC_LONG Name="Video0\CropCustomT" Value="0" />
                <WMENC_LONG Name="Video0\CropCustomL" Value="0" />
                <WMENC_LONG Name="Video0\CropCustomR" Value="0" />
                <WMENC_LONG Name="Video0\CropCustomB" Value="0" />
            </UserData>
        </SourceGroup>
    </SourceGroups>
    <File LocalFileName="C:\test.wmv" />
    <Broadcast Http="9091" />
    <WMEncoder_Profile id="Multiple bit rates video (CBR)" >
    <![CDATA[        <profile version="589824"
             storageformat="1"
             name="Multiple bit rates video (CBR)"
             description="">
                   <streamconfig majortype="{73646976-0000-0010-8000-00AA00389B71}"
                   streamnumber="1"
                   streamname="Video Stream"
                   inputname="Video809"
                   bitrate="291000"
                   bufferwindow="50000"
                   reliabletransport="0"
                   decodercomplexity="AU"
                   rfc1766langid="en-gb"
 >
                     <videomediaprops maxkeyframespacing="70000000"
                                     quality="70"/>
             <wmmediatype subtype="{33564D57-0000-0010-8000-00AA00389B71}"
                   bfixedsizesamples="0"
                   btemporalcompression="1"
                   lsamplesize="0">
       <videoinfoheader dwbitrate="291000"
                        dwbiterrorrate="0"
                        avgtimeperframe="400000">
        <rcsource left="0"
                  top="0"
                  right="720"
                  bottom="620"/>
        <rctarget left="0"
                  top="0"
                  right="720"
                  bottom="620"/>
            <bitmapinfoheader biwidth="1028"
                              biheight="943"
                              biplanes="1"
                              bibitcount="24"
                              bicompression="WMV3"
                              bisizeimage="0"
                              bixpelspermeter="0"
                              biypelspermeter="0"
                              biclrused="0"
                              biclrimportant="0"/>
       </videoinfoheader>
            </wmmediatype>
            </streamconfig>
    </profile>
    ]]>
    </WMEncoder_Profile>
    <UserData >
        <WMENC_LONG Name="Encoding\Dest" Value="2" />
        <WMENC_LONG Name="VideoSize\ResizeMethod" Value="3" />
        <WMENC_LONG Name="Encoding\Type" Value="1" />
        <WMENC_LONG Name="Encoding\Bitrate0\Video0\CustomW" Value="0" />
        <WMENC_LONG Name="Encoding\Bitrate0\Video0\CustomH" Value="0" />
        <WMENC_STRING Name="Encoding\Video0" />
        <WMENC_STRING Name="Encoding\Audio0" />
        <WMENC_STRING Name="Encoding\Script0" />
    </UserData>
</WMEncoder>



________________________________________________________________________
When I'm using it with out changing any pictures it working fine. when I tried to change with any other Images it show error
"Invalid Input file"
Please Help Me...

Thank You
Ravi Teja

Is This A Good Question/Topic? 0
  • +

Replies To: Converting JPG into WMV or AVI format Using Windows Media SDK 9.0

#2 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1010
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: Converting JPG into WMV or AVI format Using Windows Media SDK 9.0

Posted 01 July 2010 - 05:55 AM

Gak! Use code tags!

Did you try opening the files in something like Paint and resaving them? I've had images that would open in some software but not other until I resaved them.
Was This Post Helpful? 0
  • +
  • -

#3 bushby207  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 21-November 11

Re: Converting JPG into WMV or AVI format Using Windows Media SDK 9.0

Posted 21 November 2011 - 08:58 AM

I'm working on something similar and have mistakenly posted elsewhere..

i have only found info using ffmpeg but can't get my head around it.. this might be usefull

if not.. sorry...

http://ffmpeg.org/fa...nto-movies_003f
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1