VideoHandler.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using MediaBrowser.Model.Entities;
  5. namespace MediaBrowser.Api.HttpHandlers
  6. {
  7. /// <summary>
  8. /// Supported output formats: mkv,m4v,mp4,asf,wmv,mov,webm,ogv,3gp,avi,ts,flv
  9. /// </summary>
  10. class VideoHandler : BaseMediaHandler<Video>
  11. {
  12. /// <summary>
  13. /// We can output these files directly, but we can't encode them
  14. /// </summary>
  15. protected override IEnumerable<string> UnsupportedOutputEncodingFormats
  16. {
  17. get
  18. {
  19. return new string[] { "mp4", "wmv" };
  20. }
  21. }
  22. protected override bool RequiresConversion()
  23. {
  24. if (base.RequiresConversion())
  25. {
  26. return true;
  27. }
  28. AudioStream audio = LibraryItem.AudioStreams.FirstOrDefault();
  29. if (audio != null)
  30. {
  31. // If the number of channels is greater than our desired channels, we need to transcode
  32. if (AudioChannels.HasValue && AudioChannels.Value < audio.Channels)
  33. {
  34. return true;
  35. }
  36. }
  37. // Yay
  38. return false;
  39. }
  40. private string GetFFMpegOutputFormat(string outputFormat)
  41. {
  42. if (outputFormat.Equals("mkv", StringComparison.OrdinalIgnoreCase))
  43. {
  44. return "matroska";
  45. }
  46. else if (outputFormat.Equals("ts", StringComparison.OrdinalIgnoreCase))
  47. {
  48. return "mpegts";
  49. }
  50. else if (outputFormat.Equals("ogv", StringComparison.OrdinalIgnoreCase))
  51. {
  52. return "ogg";
  53. }
  54. return outputFormat;
  55. }
  56. /// <summary>
  57. /// Creates arguments to pass to ffmpeg
  58. /// </summary>
  59. protected override string GetCommandLineArguments()
  60. {
  61. List<string> audioTranscodeParams = new List<string>();
  62. string outputFormat = GetConversionOutputFormat();
  63. return string.Format("-i \"{0}\" {1} {2} -f {3} -",
  64. LibraryItem.Path,
  65. GetVideoArguments(),
  66. GetAudioArguments(),
  67. GetFFMpegOutputFormat(outputFormat)
  68. );
  69. }
  70. private string GetVideoArguments()
  71. {
  72. return "-vcodec copy";
  73. }
  74. private string GetAudioArguments()
  75. {
  76. return "-acodec copy";
  77. }
  78. }
  79. }