clinnebur Posted February 29, 2008 Posted February 29, 2008 We have an ASP.NET web application (C#) that copies videos from a CCTV truck to a Linux server. What I am trying to do is convert the .AVI videos(which is how they are created on the truck) to .WMV in my C# code using Windows Media Encoder. I have a virtual directory to the truck location of the videos. I also have a virtual directory created to the Linux box. The application resides on a Windows Server 2003 and I am using VS 2005, .NET framework 2.0. The method calling the conversion function uses impersonation and all virtual directories are set up to connect with the impersonated user. When I use the application to copy the videos without converting, it works perfectly. When I try to implement the conversion code I receive the following error: Attempted to read or write protected memory. This is often an indication that other memory has been corrupted The line that fails is: m_Encoder.PrepareToEncode(true); I have been Googling this error for days now and have found few solutions. I have tried some of the solutions I did manage to find, but nothing has helped. I'm thinking it's a permissions issue, but I can't figure out what! Any help would be greatly appreciated and please let me know if you need any more information. I am totally new to WME so I could even be doing this all wrong! Thanks in Advance, Carmen Here is the code I'm using for the conversion and then the method where I am calling the ConvertFile function: private static string ConvertFile(string mediaFile) { UtilDaoOracle oraDao = new UtilDaoOracle(); oraDao.LogError(mediaFile, "ConvertFile", 500321); WMEncoder m_Encoder = new WMEncoder(); IWMEncSourceGroup SrcGrp = (IWMEncSourceGroup)m_Encoder.SourceGroupCollection.Add("SG_1"); IWMEncVideoSource SrcVid = (IWMEncVideoSource)SrcGrp.AddSource(WMENC_SOURCE_TYPE.WMENC_VIDEO); SrcVid.SetInput(mediaFile, "", ""); const string ProfileName = "Screen Video Medium (CBR)"; foreach (IWMEncProfile aProfile in m_Encoder.ProfileCollection) { if (aProfile.Name == ProfileName) { SrcGrp.set_Profile(aProfile); oraDao.LogError(aProfile.Name.ToString(), "ConvertFileLoop", 500321); break; } } m_Encoder.File.LocalFileName = Regex.Replace(mediaFile, ".avi", ".wmv"); oraDao.LogError(m_Encoder.File.LocalFileName, "ConvertFileREturn", 500321); m_Encoder.AutoStop = true; try { m_Encoder.PrepareToEncode(true); } catch (Exception exp) { oraDao.LogError(exp.Message, "Preparetoencode", 500321); m_Encoder.Flush(); } try { m_Encoder.Start(); } catch (Exception exp) { oraDao.LogError(exp.Message, "encoderstart", 500321); m_Encoder.Flush(); } return m_Encoder.File.LocalFileName; } private static bool CopyFile(string srcDir, string destDir, string fileName, bool ignoreIfInParentDir) { UtilDaoOracle oraDao = new UtilDaoOracle(); FileInfo destFile = new FileInfo(CombinePath(destDir, fileName)); //Only copy if the file does not already exist. if (!destFile.Exists) { if (ignoreIfInParentDir && File.Exists(CombinePath(destFile.Directory.Parent.FullName, fileName))) { // Return if the files already exists in the parent directory. return false; } FileInfo srcFile = new FileInfo(CombinePath(srcDir, fileName)); if (srcFile.Exists) { // Create the destination directory if not there already. if (!destFile.Directory.Exists) { destFile.Directory.Create(); } if (srcFile.Extension == ".avi") { string convertedFile = ConvertFile(srcFile.ToString()); FileInfo convertedFileDone = new FileInfo(convertedFile); convertedFileDone.CopyTo(destFile.FullName); } else { srcFile.CopyTo(destFile.FullName); } return true; } else { Logger.LogWarning(string.Format("Source file not found on machine: {0}", srcFile.FullName)); } } return false; } Quote
Administrators PlausiblyDamp Posted March 1, 2008 Administrators Posted March 1, 2008 If you copy the file locally and try the convert does it work then? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
clinnebur Posted March 1, 2008 Author Posted March 1, 2008 Thank you for responding! Yes, I have taken the ConvertFile code and made a stand-alone web app, and passed it in an AVI file on the local C drive and wrote the WMV back to the local C drive and it works perfectly (this is still on the Server 2003). It's just when I try to use it in the app with the impersonation and virtual directories that I'm getting the error. That's why I'm thinking permissions, but I could be wrong.... Quote
Administrators PlausiblyDamp Posted March 6, 2008 Administrators Posted March 6, 2008 Can you create a file under the virtual directory direct from code? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
clinnebur Posted March 6, 2008 Author Posted March 6, 2008 Good question! I had not thought to do that. If I use the little stand-alone web app and pass it in a file on the virtual directory ("\\server\drive\directory\filename.avi") I receive this error on the SrcVid.SetInput line of code: 0xC00D002B By Googling this error code, it seems like this translates to: NS_E_INVALID_REQUEST Does this help? I will try and see if I can come up with any hits on this new error. Quote
Recommended Posts