Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ To note a change, add a line under Unreleased, in a group such as Added, Changed
### Fixed

- Frames rendered from a file whose timestamps don't start at 0, such as an MPEG transport stream, come from the time asked for. Before, times counted from timestamp 0, so frames came from too early and their actual times were off by the file's start, and a rough seek could land a keyframe or more late.
- Frames render from interlaced video, such as a DVD's MPEG-2. FFmpeg's scaler refused to turn an interlaced frame into a progressive image, so every render of one had no image.

## 0.1.0 - 2026-11-19

Expand Down
4 changes: 4 additions & 0 deletions CoreZen.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
CC00000228860A0000000006 /* TestDomainObject.m in Sources */ = {isa = PBXBuildFile; fileRef = CC00000128860A0000000009 /* TestDomainObject.m */; };
0313158D2D7374094EFBE6DC /* MediaTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D27F0ECF10C39A3A06669EF /* MediaTests.m */; };
030EFFD5692EA63A973B2FE9 /* video.mp4 in Resources */ = {isa = PBXBuildFile; fileRef = 7C383F9E59E944DEF41405A3 /* video.mp4 */; };
90A1511436EE99CABA7C9CA0 /* interlaced.mpg in Resources */ = {isa = PBXBuildFile; fileRef = 2029B56C07490693742A1C38 /* interlaced.mpg */; };
CCD9DDD06C5517F511A366AC /* start-offset.ts in Resources */ = {isa = PBXBuildFile; fileRef = 2431BF153CB5C75BE727866E /* start-offset.ts */; };
3A881C011BDBA50B90143879 /* audio.m4a in Resources */ = {isa = PBXBuildFile; fileRef = 318D307DF615F0093C6C9C47 /* audio.m4a */; };
7C83D0F62FF8F1D1569E4B13 /* silent.mp4 in Resources */ = {isa = PBXBuildFile; fileRef = 75E34DE8F29716419674A2D5 /* silent.mp4 */; };
Expand Down Expand Up @@ -301,6 +302,7 @@
CC00000128860A0000000009 /* TestDomainObject.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TestDomainObject.m; sourceTree = "<group>"; };
7D27F0ECF10C39A3A06669EF /* MediaTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MediaTests.m; sourceTree = "<group>"; };
7C383F9E59E944DEF41405A3 /* video.mp4 */ = {isa = PBXFileReference; lastKnownFileType = file; path = video.mp4; sourceTree = "<group>"; };
2029B56C07490693742A1C38 /* interlaced.mpg */ = {isa = PBXFileReference; lastKnownFileType = file; path = interlaced.mpg; sourceTree = "<group>"; };
2431BF153CB5C75BE727866E /* start-offset.ts */ = {isa = PBXFileReference; lastKnownFileType = file; path = "start-offset.ts"; sourceTree = "<group>"; };
318D307DF615F0093C6C9C47 /* audio.m4a */ = {isa = PBXFileReference; lastKnownFileType = file; path = audio.m4a; sourceTree = "<group>"; };
75E34DE8F29716419674A2D5 /* silent.mp4 */ = {isa = PBXFileReference; lastKnownFileType = file; path = silent.mp4; sourceTree = "<group>"; };
Expand Down Expand Up @@ -846,6 +848,7 @@
isa = PBXGroup;
children = (
7C383F9E59E944DEF41405A3 /* video.mp4 */,
2029B56C07490693742A1C38 /* interlaced.mpg */,
2431BF153CB5C75BE727866E /* start-offset.ts */,
318D307DF615F0093C6C9C47 /* audio.m4a */,
75E34DE8F29716419674A2D5 /* silent.mp4 */,
Expand Down Expand Up @@ -1221,6 +1224,7 @@
buildActionMask = 2147483647;
files = (
030EFFD5692EA63A973B2FE9 /* video.mp4 in Resources */,
90A1511436EE99CABA7C9CA0 /* interlaced.mpg in Resources */,
CCD9DDD06C5517F511A366AC /* start-offset.ts in Resources */,
3A881C011BDBA50B90143879 /* audio.m4a in Resources */,
7C83D0F62FF8F1D1569E4B13 /* silent.mp4 in Resources */,
Expand Down
4 changes: 3 additions & 1 deletion CoreZen/Media/FrameRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ typedef NS_ENUM(NSInteger, ZENFrameRequestType) {
/// The frame's image, or nil if it couldn't be rendered.
///
/// It fits within the width and height asked for, in the shape the video is
/// shown in: stretched to its pixel aspect ratio and turned upright.
/// shown in: stretched to its pixel aspect ratio and turned upright. An
/// interlaced frame's two fields are scaled together, as one picture, the way a
/// player shows it without deinterlacing.
@property (nonatomic, strong, nullable) NSImage *image;

/// Whether the frame was asked for by time or by fraction of the duration.
Expand Down
4 changes: 4 additions & 0 deletions CoreZen/Media/LibAV/LibAVRenderController.m
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@ - (BOOL)resizeRawFrame:(AVFrame **)frame

if (result >= 0) {
ZENGuessUnspecifiedColorspace(sourceFrame);
// The scaler won't turn an interlaced frame into a progressive one, so scale
// its two fields together, as one picture, the way a player shows it without
// deinterlacing. Motion between the fields can show as combing.
sourceFrame->flags &= ~(AV_FRAME_FLAG_INTERLACED | AV_FRAME_FLAG_TOP_FIELD_FIRST);
if (!_scaler) {
_scaler = sws_alloc_context();
if (_scaler) {
Expand Down
15 changes: 15 additions & 0 deletions CoreZenTests/MediaTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,21 @@ - (void)testRenderTimesCountFromTheStartOfTheFile {
XCTAssertEqual(again.actualTimestamp, exact.actualTimestamp);
}

// interlaced.mpg is MPEG-2 at 128x96, with every frame interlaced, top field first
- (void)testRenderInterlacedFrames {
ZENMediaFile *mediaFile = [self mediaFileNamed:@"interlaced.mpg"];

ZENRenderedFrame *keyframe = [self renderFrameAtPercentage:0.5 ofMediaFile:mediaFile];
XCTAssertNotNil(keyframe.image);
XCTAssertEqual(keyframe.image.size.width, 32);
XCTAssertEqual(keyframe.image.size.height, 24);

ZENRenderedFrame *exact = [self renderFrameAtSeconds:0.5 exact:YES ofMediaFile:mediaFile];
XCTAssertNotNil(exact.image);
XCTAssertGreaterThanOrEqual(exact.actualSeconds, 0.49);
XCTAssertLessThan(exact.actualSeconds, 0.54, @"Should render the first frame at or after 0.5 s");
}

#pragma mark - Rotation

// The red, green and blue values of image, from 0 to 255 in sRGB, at a point given
Expand Down
Binary file added CoreZenTests/Resources/interlaced.mpg
Binary file not shown.