VideoHandler.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using MediaBrowser.Model.Entities;
  5. namespace MediaBrowser.Api.HttpHandlers
  6. {
  7. class VideoHandler : BaseMediaHandler<Video>
  8. {
  9. private IEnumerable<string> UnsupportedOutputFormats = new string[] { "mp4" };
  10. public IEnumerable<string> VideoFormats
  11. {
  12. get
  13. {
  14. return QueryString["videoformats"].Split(',');
  15. }
  16. }
  17. /// <summary>
  18. /// Gets the format we'll be converting to
  19. /// </summary>
  20. protected override string GetOutputFormat()
  21. {
  22. return VideoFormats.First(f => !UnsupportedOutputFormats.Any(s => s.Equals(f, StringComparison.OrdinalIgnoreCase)));
  23. }
  24. protected override bool RequiresConversion()
  25. {
  26. // If it's not in a format we can output to, return true
  27. if (UnsupportedOutputFormats.Any(f => LibraryItem.Path.EndsWith(f, StringComparison.OrdinalIgnoreCase)))
  28. {
  29. return true;
  30. }
  31. // If it's not in a format the consumer accepts, return true
  32. if (!VideoFormats.Any(f => LibraryItem.Path.EndsWith(f, StringComparison.OrdinalIgnoreCase)))
  33. {
  34. return true;
  35. }
  36. AudioStream audio = LibraryItem.AudioStreams.FirstOrDefault();
  37. if (audio != null)
  38. {
  39. // If the number of channels is greater than our desired channels, we need to transcode
  40. if (AudioChannels.HasValue && AudioChannels.Value < audio.Channels)
  41. {
  42. return true;
  43. }
  44. }
  45. // Yay
  46. return false;
  47. }
  48. /// <summary>
  49. /// Creates arguments to pass to ffmpeg
  50. /// </summary>
  51. protected override string GetCommandLineArguments()
  52. {
  53. List<string> audioTranscodeParams = new List<string>();
  54. string outputFormat = GetOutputFormat();
  55. outputFormat = "matroska";
  56. return "-i \"" + LibraryItem.Path + "\" -vcodec copy -acodec copy -f " + outputFormat + " -";
  57. }
  58. }
  59. }