Skip to content

Commit fc8ec33

Browse files
detect anamorphic video
1 parent 58c3e6c commit fc8ec33

File tree

25 files changed

+187
-38
lines changed

25 files changed

+187
-38
lines changed

MediaBrowser.Api/Playback/BaseStreamingService.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1788,7 +1788,8 @@ private void ApplyDeviceProfileSettings(StreamState state)
17881788
state.TargetVideoLevel,
17891789
state.TargetFramerate,
17901790
state.TargetPacketLength,
1791-
state.TargetTimestamp);
1791+
state.TargetTimestamp,
1792+
state.IsTargetAnamorphic);
17921793

17931794
if (mediaProfile != null)
17941795
{
@@ -1885,7 +1886,8 @@ protected void AddDlnaHeaders(StreamState state, IDictionary<string, string> res
18851886
state.TargetVideoLevel,
18861887
state.TargetFramerate,
18871888
state.TargetPacketLength,
1888-
state.TranscodeSeekInfo
1889+
state.TranscodeSeekInfo,
1890+
state.IsTargetAnamorphic
18891891
);
18901892
}
18911893

MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ protected override string GetVideoArguments(StreamState state)
313313
// See if we can save come cpu cycles by avoiding encoding
314314
if (codec.Equals("copy", StringComparison.OrdinalIgnoreCase))
315315
{
316-
return IsH264(state.VideoStream) ? "-codec:v:0 copy -bsf h264_mp4toannexb" : "-codec:v:0 copy";
316+
return IsH264(state.VideoStream) ? "-codec:v:0 copy -bsf h264_mp4toannexb -bsf dump_extra" : "-codec:v:0 copy";
317317
}
318318

319319
var keyFrameArg = state.ReadInputAtNativeFramerate ?

MediaBrowser.Api/Playback/Hls/VideoHlsService.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ protected override string GetVideoArguments(StreamState state)
160160
// See if we can save come cpu cycles by avoiding encoding
161161
if (codec.Equals("copy", StringComparison.OrdinalIgnoreCase))
162162
{
163-
return IsH264(state.VideoStream) ? "-codec:v:0 copy -bsf h264_mp4toannexb" : "-codec:v:0 copy";
163+
return IsH264(state.VideoStream) ? "-codec:v:0 copy -bsf h264_mp4toannexb -bsf dump_extra" : "-codec:v:0 copy";
164164
}
165165

166166
var keyFrameArg = state.ReadInputAtNativeFramerate ?

MediaBrowser.Api/Playback/Progressive/VideoService.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ private string GetVideoArguments(StreamState state, string codec)
140140
// See if we can save come cpu cycles by avoiding encoding
141141
if (codec.Equals("copy", StringComparison.OrdinalIgnoreCase))
142142
{
143-
return state.VideoStream != null && IsH264(state.VideoStream) ? args + " -bsf h264_mp4toannexb" : args;
143+
return state.VideoStream != null && IsH264(state.VideoStream) ? args + " -bsf h264_mp4toannexb -bsf dump_extra" : args;
144144
}
145145

146146
const string keyFrameArg = " -force_key_frames expr:if(isnan(prev_forced_t),gte(t,.1),gte(t,prev_forced_t+5))";

MediaBrowser.Api/Playback/StreamState.cs

+12-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using MediaBrowser.Controller.LiveTv;
33
using MediaBrowser.Model.Dlna;
44
using MediaBrowser.Model.Drawing;
5-
using MediaBrowser.Model.Dto;
65
using MediaBrowser.Model.Entities;
76
using MediaBrowser.Model.IO;
87
using MediaBrowser.Model.Logging;
@@ -330,5 +329,17 @@ public string TargetVideoProfile
330329
}
331330
}
332331

332+
public bool? IsTargetAnamorphic
333+
{
334+
get
335+
{
336+
if (Request.Static)
337+
{
338+
return VideoStream == null ? null : VideoStream.IsAnamorphic;
339+
}
340+
341+
return false;
342+
}
343+
}
333344
}
334345
}

MediaBrowser.Controller/MediaEncoding/MediaEncoderHelpers.cs

+3
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ private static MediaStream GetMediaStream(MediaStreamInfo streamInfo, MediaForma
126126
stream.RealFrameRate = GetFrameRate(streamInfo.r_frame_rate);
127127

128128
stream.BitDepth = GetBitDepth(stream.PixelFormat);
129+
130+
stream.IsAnamorphic = string.Equals(streamInfo.sample_aspect_ratio, "0:1",
131+
StringComparison.OrdinalIgnoreCase);
129132
}
130133
else
131134
{

MediaBrowser.Dlna/ConnectionManager/ControlHandler.cs

-2
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66
using MediaBrowser.Model.Logging;
77
using System;
88
using System.Collections.Generic;
9-
using System.Globalization;
109

1110
namespace MediaBrowser.Dlna.ConnectionManager
1211
{
1312
public class ControlHandler : BaseControlHandler
1413
{
15-
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
1614
private readonly DeviceProfile _profile;
1715

1816
public ControlHandler(ILogger logger, DeviceProfile profile, IServerConfigurationManager config)

MediaBrowser.Dlna/Didl/DidlBuilder.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ private void AddVideoResource(XmlElement container, Video video, string deviceId
179179
streamInfo.TargetVideoLevel,
180180
streamInfo.TargetFramerate,
181181
streamInfo.TargetPacketLength,
182-
streamInfo.TargetTimestamp);
182+
streamInfo.TargetTimestamp,
183+
streamInfo.IsTargetAnamorphic);
183184

184185
var filename = url.Substring(0, url.IndexOf('?'));
185186

@@ -203,7 +204,8 @@ private void AddVideoResource(XmlElement container, Video video, string deviceId
203204
streamInfo.TargetVideoLevel,
204205
streamInfo.TargetFramerate,
205206
streamInfo.TargetPacketLength,
206-
streamInfo.TranscodeSeekInfo);
207+
streamInfo.TranscodeSeekInfo,
208+
streamInfo.IsTargetAnamorphic);
207209

208210
res.SetAttribute("protocolInfo", String.Format(
209211
"http-get:*:{0}:{1}",

MediaBrowser.Dlna/PlayTo/PlayToController.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,8 @@ private string GetDlnaHeaders(PlaylistItem item)
514514
streamInfo.TargetVideoLevel,
515515
streamInfo.TargetFramerate,
516516
streamInfo.TargetPacketLength,
517-
streamInfo.TranscodeSeekInfo);
517+
streamInfo.TranscodeSeekInfo,
518+
streamInfo.IsTargetAnamorphic);
518519
}
519520

520521
return null;

MediaBrowser.Dlna/Profiles/WdtvLiveProfile.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public WdtvLiveProfile()
8383
Container = "ts",
8484
Type = DlnaProfileType.Video,
8585
VideoCodec = "mpeg1video,mpeg2video,h264,vc1",
86-
AudioCodec = "ac3,dca,mp2,mp3"
86+
AudioCodec = "ac3,dca,mp2,mp3,aac"
8787
},
8888

8989
new DirectPlayProfile

MediaBrowser.Dlna/Profiles/WindowsPhoneProfile.cs

+14
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,20 @@ public WindowsPhoneProfile()
9393

9494
CodecProfiles = new[]
9595
{
96+
new CodecProfile
97+
{
98+
Type = CodecType.Video,
99+
Conditions = new []
100+
{
101+
new ProfileCondition
102+
{
103+
Condition = ProfileConditionType.NotEquals,
104+
Property = ProfileConditionValue.IsAnamorphic,
105+
Value = "true"
106+
}
107+
}
108+
},
109+
96110
new CodecProfile
97111
{
98112
Type = CodecType.Video,

MediaBrowser.Dlna/Profiles/Xml/WDTV Live.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
<DirectPlayProfile container="avi" audioCodec="ac3,dca,mp2,mp3,pcm" videoCodec="mpeg1video,mpeg2video,mpeg4,h264,vc1" type="Video" />
3535
<DirectPlayProfile container="mpeg" audioCodec="ac3,dca,mp2,mp3,pcm" videoCodec="mpeg1video,mpeg2video" type="Video" />
3636
<DirectPlayProfile container="mkv" audioCodec="ac3,dca,aac,mp2,mp3,pcm" videoCodec="mpeg1video,mpeg2video,mpeg4,h264,vc1" type="Video" />
37-
<DirectPlayProfile container="ts" audioCodec="ac3,dca,mp2,mp3" videoCodec="mpeg1video,mpeg2video,h264,vc1" type="Video" />
37+
<DirectPlayProfile container="ts" audioCodec="ac3,dca,mp2,mp3,aac" videoCodec="mpeg1video,mpeg2video,h264,vc1" type="Video" />
3838
<DirectPlayProfile container="mp4,mov" audioCodec="ac3,aac,mp2,mp3" videoCodec="h264,mpeg4" type="Video" />
3939
<DirectPlayProfile container="asf" audioCodec="wmav2,wmapro" videoCodec="vc1" type="Video" />
4040
<DirectPlayProfile container="asf" audioCodec="mp2,ac3" videoCodec="mpeg2video" type="Video" />

MediaBrowser.Dlna/Service/BaseControlHandler.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ private ControlResponse ProcessControlRequestInternal(ControlRequest request)
9292
Xml = xml,
9393
IsSuccessful = true
9494
};
95-
Logger.Debug(xml);
95+
96+
//Logger.Debug(xml);
97+
9698
controlResponse.Headers.Add("EXT", string.Empty);
9799

98100
return controlResponse;

MediaBrowser.Model/Dlna/ConditionProcessor.cs

+29-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ public bool IsVideoConditionSatisfied(ProfileCondition condition,
1717
double? videoLevel,
1818
double? videoFramerate,
1919
int? packetLength,
20-
TransportStreamTimestamp? timestamp)
20+
TransportStreamTimestamp? timestamp,
21+
bool? isAnamorphic)
2122
{
2223
switch (condition.Property)
2324
{
@@ -27,6 +28,8 @@ public bool IsVideoConditionSatisfied(ProfileCondition condition,
2728
case ProfileConditionValue.Has64BitOffsets:
2829
// TODO: Implement
2930
return true;
31+
case ProfileConditionValue.IsAnamorphic:
32+
return IsConditionSatisfied(condition, isAnamorphic);
3033
case ProfileConditionValue.VideoFramerate:
3134
return IsConditionSatisfied(condition, videoFramerate);
3235
case ProfileConditionValue.VideoLevel:
@@ -147,6 +150,31 @@ private bool IsConditionSatisfied(ProfileCondition condition, string currentValu
147150
throw new InvalidOperationException("Unexpected ProfileConditionType");
148151
}
149152
}
153+
154+
private bool IsConditionSatisfied(ProfileCondition condition, bool? currentValue)
155+
{
156+
if (!currentValue.HasValue)
157+
{
158+
// If the value is unknown, it satisfies if not marked as required
159+
return !condition.IsRequired;
160+
}
161+
162+
bool expected;
163+
if (BoolHelper.TryParseCultureInvariant(condition.Value, out expected))
164+
{
165+
switch (condition.Condition)
166+
{
167+
case ProfileConditionType.Equals:
168+
return currentValue.Value == expected;
169+
case ProfileConditionType.NotEquals:
170+
return currentValue.Value != expected;
171+
default:
172+
throw new InvalidOperationException("Unexpected ProfileConditionType");
173+
}
174+
}
175+
176+
return false;
177+
}
150178

151179
private bool IsConditionSatisfied(ProfileCondition condition, double? currentValue)
152180
{

MediaBrowser.Model/Dlna/ContentFeatureBuilder.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ public string BuildVideoHeader(string container,
108108
double? videoLevel,
109109
double? videoFramerate,
110110
int? packetLength,
111-
TranscodeSeekInfo transcodeSeekInfo)
111+
TranscodeSeekInfo transcodeSeekInfo,
112+
bool? isAnamorphic)
112113
{
113114
// first bit means Time based seek supported, second byte range seek supported (not sure about the order now), so 01 = only byte seek, 10 = time based, 11 = both, 00 = none
114115
string orgOp = ";DLNA.ORG_OP=" + DlnaMaps.GetOrgOpValue(runtimeTicks.HasValue, isDirectStream, transcodeSeekInfo);
@@ -145,7 +146,8 @@ public string BuildVideoHeader(string container,
145146
videoLevel,
146147
videoFramerate,
147148
packetLength,
148-
timestamp);
149+
timestamp,
150+
isAnamorphic);
149151

150152
string orgPn = mediaProfile == null ? null : mediaProfile.OrgPn;
151153

MediaBrowser.Model/Dlna/DeviceProfile.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ public ResponseProfile GetVideoMediaProfile(string container,
269269
double? videoLevel,
270270
double? videoFramerate,
271271
int? packetLength,
272-
TransportStreamTimestamp timestamp)
272+
TransportStreamTimestamp timestamp,
273+
bool? isAnamorphic)
273274
{
274275
container = (container ?? string.Empty).TrimStart('.');
275276

@@ -303,7 +304,7 @@ public ResponseProfile GetVideoMediaProfile(string container,
303304
var anyOff = false;
304305
foreach (ProfileCondition c in i.Conditions)
305306
{
306-
if (!conditionProcessor.IsVideoConditionSatisfied(c, audioBitrate, audioChannels, width, height, bitDepth, videoBitrate, videoProfile, videoLevel, videoFramerate, packetLength, timestamp))
307+
if (!conditionProcessor.IsVideoConditionSatisfied(c, audioBitrate, audioChannels, width, height, bitDepth, videoBitrate, videoProfile, videoLevel, videoFramerate, packetLength, timestamp, isAnamorphic))
307308
{
308309
anyOff = true;
309310
break;

MediaBrowser.Model/Dlna/ProfileConditionValue.cs

+14-13
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22
{
33
public enum ProfileConditionValue
44
{
5-
AudioChannels,
6-
AudioBitrate,
7-
AudioProfile,
8-
Width,
9-
Height,
10-
Has64BitOffsets,
11-
PacketLength,
12-
VideoBitDepth,
13-
VideoBitrate,
14-
VideoFramerate,
15-
VideoLevel,
16-
VideoProfile,
17-
VideoTimestamp
5+
AudioChannels = 0,
6+
AudioBitrate = 1,
7+
AudioProfile = 2,
8+
Width = 3,
9+
Height = 4,
10+
Has64BitOffsets = 5,
11+
PacketLength = 6,
12+
VideoBitDepth = 7,
13+
VideoBitrate = 8,
14+
VideoFramerate = 9,
15+
VideoLevel = 10,
16+
VideoProfile = 11,
17+
VideoTimestamp = 12,
18+
IsAnamorphic = 13
1819
}
1920
}

MediaBrowser.Model/Dlna/StreamBuilder.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ private DirectPlayProfile GetVideoDirectPlayProfile(DeviceProfile profile,
370370
double? videoLevel = videoStream == null ? null : videoStream.Level;
371371
string videoProfile = videoStream == null ? null : videoStream.Profile;
372372
float? videoFramerate = videoStream == null ? null : videoStream.AverageFrameRate ?? videoStream.AverageFrameRate;
373+
bool? isAnamorphic = videoStream == null ? null : videoStream.IsAnamorphic;
373374

374375
int? audioBitrate = audioStream == null ? null : audioStream.BitRate;
375376
int? audioChannels = audioStream == null ? null : audioStream.Channels;
@@ -381,7 +382,7 @@ private DirectPlayProfile GetVideoDirectPlayProfile(DeviceProfile profile,
381382
// Check container conditions
382383
foreach (ProfileCondition i in conditions)
383384
{
384-
if (!conditionProcessor.IsVideoConditionSatisfied(i, audioBitrate, audioChannels, width, height, bitDepth, videoBitrate, videoProfile, videoLevel, videoFramerate, packetLength, timestamp))
385+
if (!conditionProcessor.IsVideoConditionSatisfied(i, audioBitrate, audioChannels, width, height, bitDepth, videoBitrate, videoProfile, videoLevel, videoFramerate, packetLength, timestamp, isAnamorphic))
385386
{
386387
return null;
387388
}
@@ -403,7 +404,7 @@ private DirectPlayProfile GetVideoDirectPlayProfile(DeviceProfile profile,
403404

404405
foreach (ProfileCondition i in conditions)
405406
{
406-
if (!conditionProcessor.IsVideoConditionSatisfied(i, audioBitrate, audioChannels, width, height, bitDepth, videoBitrate, videoProfile, videoLevel, videoFramerate, packetLength, timestamp))
407+
if (!conditionProcessor.IsVideoConditionSatisfied(i, audioBitrate, audioChannels, width, height, bitDepth, videoBitrate, videoProfile, videoLevel, videoFramerate, packetLength, timestamp, isAnamorphic))
407408
{
408409
return null;
409410
}
@@ -520,6 +521,7 @@ private void ApplyTranscodingConditions(StreamInfo item, IEnumerable<ProfileCond
520521
break;
521522
}
522523
case ProfileConditionValue.AudioProfile:
524+
case ProfileConditionValue.IsAnamorphic:
523525
case ProfileConditionValue.Has64BitOffsets:
524526
case ProfileConditionValue.PacketLength:
525527
case ProfileConditionValue.VideoTimestamp:

MediaBrowser.Model/Dlna/StreamInfo.cs

+13
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,19 @@ public int? TargetTotalBitrate
348348
}
349349
}
350350

351+
public bool? IsTargetAnamorphic
352+
{
353+
get
354+
{
355+
if (IsDirectStream)
356+
{
357+
return TargetVideoStream == null ? null : TargetVideoStream.IsAnamorphic;
358+
}
359+
360+
return false;
361+
}
362+
}
363+
351364
public int? TargetWidth
352365
{
353366
get

MediaBrowser.Model/Entities/MediaStream.cs

+8-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class MediaStream
3333
/// </summary>
3434
/// <value>The channel layout.</value>
3535
public string ChannelLayout { get; set; }
36-
36+
3737
/// <summary>
3838
/// Gets or sets the bit rate.
3939
/// </summary>
@@ -155,11 +155,17 @@ public bool IsTextSubtitleStream
155155
/// </summary>
156156
/// <value>The pixel format.</value>
157157
public string PixelFormat { get; set; }
158-
158+
159159
/// <summary>
160160
/// Gets or sets the level.
161161
/// </summary>
162162
/// <value>The level.</value>
163163
public double? Level { get; set; }
164+
165+
/// <summary>
166+
/// Gets a value indicating whether this instance is anamorphic.
167+
/// </summary>
168+
/// <value><c>true</c> if this instance is anamorphic; otherwise, <c>false</c>.</value>
169+
public bool? IsAnamorphic { get; set; }
164170
}
165171
}

0 commit comments

Comments
 (0)