public Transcode(MediaSource source) { Source = source; FileInfo file = new FileInfo(source.GetTranscodingFileName()); if (file.Exists) { file.Delete(); _stream = File.Open(file.FullName, FileMode.Create, FileAccess.Write, FileShare.ReadWrite); } _mencoderlogname = source.GetTranscodingFileName() + ".log"; _mencoderloglevel = MEncoderLogging.All; //.InfoOnly; }
public string GetArguments(MEncoderLogging MEncoderLogLevel) { string outputFile = _source.GetTranscodingFileName(); if (outputFile == null) { throw new Exception(string.Format("OutputFile not set for {0}", _source)); } StringBuilder strBuilder = new StringBuilder(); // from TGB: // -oac copy -ovc lavc -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=4900:keyint=15:vstrict=0:autoaspect=1, harddup -of mpeg -mpegopts format=dvd:tsaf // input location // from Vlader's page (http://iandixon.co.uk/cs/wikis/mediacenter/dvd-library-on-extenders-using-vader-s-transcoder.aspx): // -dvd-device "{0}" dvd://{2} -alang en -slang en -oac copy -ovc lavc // NTSC: -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=5000:keyint=18:vstrict=0:aspect=16/9 // -vf scale=720:480,harddup // -ofps 30000/1001 // PAL: -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=4900:keyint=15:vstrict=0:aspect=16/9 // -vf scale=720:576,harddup // -ofps 25 // -of mpeg -mpegopts format=dvd:tsaf -o "{1}" -quiet if (IsDVD) { strBuilder.Append(@" dvd://"); if (_source.Title != null) { strBuilder.Append(_source.Title.Value.ToString()); } else { strBuilder.Append(_source.DVDDiskInfo.GetMainTitle().TitleNumber); } strBuilder.AppendFormat(@" -dvd-device ""{0}""", _source.VIDEO_TS_Parent); // chapter start (optional) if (_source.StartChapter != null) { if (_source.EndChapter != null) { strBuilder.AppendFormat(" -chapter {0}-{1}", _source.StartChapter, _source.EndChapter); } else { strBuilder.AppendFormat(" -chapter {0}", _source.StartChapter); } } // audio format OMLGetDVDInfo.AudioEncoding audioFormat = OMLGetDVDInfo.AudioEncoding.AC3; if (_source.DVDTitle.AudioTracks.Count > 0) { audioFormat = _source.DVDTitle.AudioTracks[0].Format; } if (_source.AudioStream != null) { audioFormat = _source.AudioStream.Format; } strBuilder.AppendFormat(@" -oac {0} -lavcopts acodec=mp2", audioFormat != OMLGetDVDInfo.AudioEncoding.DTS ? "copy" : "lavc"); if (AudioEncoderFormat == MEncoder.AudioFormat.NoAudio) { strBuilder.Append(@" -nosound"); } //subtitles if (_source.Subtitle != null && _source.Subtitle.SubtitleID != null) { strBuilder.AppendFormat(@" -font c:\windows\fonts\arial.ttf -sid {0}", _source.Subtitle.SubtitleID.Value - 1); } else { if (_source.AudioStream != null && _source.AudioStream.AudioID != null) { strBuilder.AppendFormat(@" -aid {0}", _source.AudioStream.AudioID); } } strBuilder.Append(" -ovc lavc"); // old options: -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=4900:keyint=15:vstrict=0:autoaspect=1,harddup if (IsNTSC) { strBuilder.Append(" -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=5000:keyint=18:vstrict=0:aspect=16/9"); strBuilder.Append(" -vf scale=720:480,harddup"); strBuilder.Append(" -ofps 30000/1001"); } else { strBuilder.Append(" -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=4900:keyint=15:vstrict=0:aspect=16/9"); strBuilder.Append(" -vf scale=720:576,harddup"); strBuilder.Append(" -ofps 25"); } strBuilder.Append(" -mpegopts format=dvd:tsaf"); } else { // We are not playing a dvd, we are playing a movie file (avi etc) strBuilder.AppendFormat(@"""{0}""", _source.MediaPath); DIFeature df = null; DIAudioStream das = null; DIVideoStream dvs = null; try { bool recode_audio; // Try to find the technical details of the movie file. // Assume one feature and one video/audio stream for now df = _source.Disk.DiskFeatures[0]; das = df.AudioStreams[0]; dvs = df.VideoStreams[0]; Utilities.DebugLine(string.Format("[Transcode] Movie details. Resolution {0}x{1} @ {2} fps.", dvs.Resolution.Width, dvs.Resolution.Height, dvs.FrameRate)); // audio format if ((das.Encoding == DIAudioEncoding.AC3) || (das.EncodingProfile == DIAudioEncodingProfile.Layer1) || (das.EncodingProfile == DIAudioEncodingProfile.Layer2)) { strBuilder.Append(@" -oac copy"); recode_audio = false; } else { strBuilder.Append(@" -oac lavc"); recode_audio = true; } // Add the frame rate if (dvs.FrameRateString != "") { strBuilder.Append(@" -ofps " + dvs.FrameRateString); } // Video scaling string AspectRatio = dvs.AspectRatio; strBuilder.AppendFormat(BuildVF_String(dvs.Resolution.Width, dvs.Resolution.Height, ref AspectRatio)); //video codec strBuilder.AppendFormat(@" -ovc lavc"); // Build the lavcopts strBuilder.Append(@" -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=4900:keyint=15:vstrict=0"); if (dvs.AspectRatio != "") { strBuilder.AppendFormat(@":aspect=" + AspectRatio); } if (recode_audio == true) { strBuilder.Append(@":acodec=ac3"); } strBuilder.AppendFormat(" -mpegopts format=mpeg"); //:muxrate=9800"); if (dvs.AspectRatio != "") { strBuilder.AppendFormat(@":vaspect=" + AspectRatio); } } catch { //video format strBuilder.AppendFormat(@" -ovc lavc"); // Build the lavcopts strBuilder.Append(@" -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=4900:keyint=15:vstrict=0"); } } // these are the same for dvds and non-dvds strBuilder.Append(@" -of mpeg"); switch (MEncoderLogLevel) { case MEncoderLogging.All: break; case MEncoderLogging.InfoOnly: strBuilder.Append(@" -quiet"); break; case MEncoderLogging.None: strBuilder.Append(@" -really-quiet"); break; } //output strBuilder.AppendFormat(@" -o ""{0}""", outputFile); string completedArguments = strBuilder.ToString(); Utilities.DebugLine("[MEncoderCommandBuilder] Arguments: {0}", completedArguments); return(completedArguments); }
public string GetArguments(MEncoderLogging MEncoderLogLevel) { string outputFile = _source.GetTranscodingFileName(); if (outputFile == null) throw new Exception(string.Format("OutputFile not set for {0}", _source)); StringBuilder strBuilder = new StringBuilder(); // from TGB: // -oac copy -ovc lavc -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=4900:keyint=15:vstrict=0:autoaspect=1, harddup -of mpeg -mpegopts format=dvd:tsaf // input location // from Vlader's page (http://iandixon.co.uk/cs/wikis/mediacenter/dvd-library-on-extenders-using-vader-s-transcoder.aspx): // -dvd-device "{0}" dvd://{2} -alang en -slang en -oac copy -ovc lavc // NTSC: -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=5000:keyint=18:vstrict=0:aspect=16/9 // -vf scale=720:480,harddup // -ofps 30000/1001 // PAL: -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=4900:keyint=15:vstrict=0:aspect=16/9 // -vf scale=720:576,harddup // -ofps 25 // -of mpeg -mpegopts format=dvd:tsaf -o "{1}" -quiet if (IsDVD) { strBuilder.Append(@" dvd://"); if (_source.Title != null) strBuilder.Append(_source.Title.Value.ToString()); else strBuilder.Append(_source.DVDDiskInfo.GetMainTitle().TitleNumber); strBuilder.AppendFormat(@" -dvd-device ""{0}""", _source.VIDEO_TS_Parent); // chapter start (optional) if (_source.StartChapter != null) { if (_source.EndChapter != null) strBuilder.AppendFormat(" -chapter {0}-{1}", _source.StartChapter, _source.EndChapter); else strBuilder.AppendFormat(" -chapter {0}", _source.StartChapter); } // audio format OMLGetDVDInfo.AudioEncoding audioFormat = OMLGetDVDInfo.AudioEncoding.AC3; if (_source.DVDTitle.AudioTracks.Count > 0) audioFormat = _source.DVDTitle.AudioTracks[0].Format; if (_source.AudioStream != null) audioFormat = _source.AudioStream.Format; strBuilder.AppendFormat(@" -oac {0} -lavcopts acodec=mp2", audioFormat != OMLGetDVDInfo.AudioEncoding.DTS ? "copy" : "lavc"); if (AudioEncoderFormat == MEncoder.AudioFormat.NoAudio) strBuilder.Append(@" -nosound"); //subtitles if (_source.Subtitle != null && _source.Subtitle.SubtitleID != null) strBuilder.AppendFormat(@" -font c:\windows\fonts\arial.ttf -sid {0}", _source.Subtitle.SubtitleID.Value - 1); else { if (_source.AudioStream != null && _source.AudioStream.AudioID != null) strBuilder.AppendFormat(@" -aid {0}", _source.AudioStream.AudioID); } strBuilder.Append(" -ovc lavc"); // old options: -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=4900:keyint=15:vstrict=0:autoaspect=1,harddup if (IsNTSC) { strBuilder.Append(" -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=5000:keyint=18:vstrict=0:aspect=16/9"); strBuilder.Append(" -vf scale=720:480,harddup"); strBuilder.Append(" -ofps 30000/1001"); } else { strBuilder.Append(" -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=4900:keyint=15:vstrict=0:aspect=16/9"); strBuilder.Append(" -vf scale=720:576,harddup"); strBuilder.Append(" -ofps 25"); } strBuilder.Append(" -mpegopts format=dvd:tsaf"); } else { // We are not playing a dvd, we are playing a movie file (avi etc) strBuilder.AppendFormat(@"""{0}""", _source.MediaPath); DIFeature df = null; DIAudioStream das = null; DIVideoStream dvs= null; try { bool recode_audio; // Try to find the technical details of the movie file. // Assume one feature and one video/audio stream for now df = _source.Disk.DiskFeatures[0]; das = df.AudioStreams[0]; dvs = df.VideoStreams[0]; Utilities.DebugLine(string.Format("[Transcode] Movie details. Resolution {0}x{1} @ {2} fps.", dvs.Resolution.Width, dvs.Resolution.Height, dvs.FrameRate)); // audio format if ((das.Encoding == DIAudioEncoding.AC3) || (das.EncodingProfile == DIAudioEncodingProfile.Layer1) || (das.EncodingProfile == DIAudioEncodingProfile.Layer2)) { strBuilder.Append(@" -oac copy"); recode_audio = false; } else { strBuilder.Append(@" -oac lavc"); recode_audio = true; } // Add the frame rate if (dvs.FrameRateString != "") { strBuilder.Append(@" -ofps " + dvs.FrameRateString); } // Video scaling string AspectRatio = dvs.AspectRatio; strBuilder.AppendFormat(BuildVF_String(dvs.Resolution.Width, dvs.Resolution.Height, ref AspectRatio)); //video codec strBuilder.AppendFormat(@" -ovc lavc"); // Build the lavcopts strBuilder.Append(@" -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=4900:keyint=15:vstrict=0"); if (dvs.AspectRatio != "") { strBuilder.AppendFormat(@":aspect=" + AspectRatio); } if (recode_audio == true) { strBuilder.Append(@":acodec=ac3"); } strBuilder.AppendFormat(" -mpegopts format=mpeg"); //:muxrate=9800"); if (dvs.AspectRatio != "") { strBuilder.AppendFormat(@":vaspect=" + AspectRatio); } } catch { //video format strBuilder.AppendFormat(@" -ovc lavc"); // Build the lavcopts strBuilder.Append(@" -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=4900:keyint=15:vstrict=0"); } } // these are the same for dvds and non-dvds strBuilder.Append(@" -of mpeg"); switch (MEncoderLogLevel) { case MEncoderLogging.All: break; case MEncoderLogging.InfoOnly: strBuilder.Append(@" -quiet"); break; case MEncoderLogging.None: strBuilder.Append(@" -really-quiet"); break; } //output strBuilder.AppendFormat(@" -o ""{0}""", outputFile); string completedArguments = strBuilder.ToString(); Utilities.DebugLine("[MEncoderCommandBuilder] Arguments: {0}", completedArguments); return completedArguments; }