Skip to content

fix: video export failing when the source file is already an .mp4 - WPB-26457#5006

Open
jullianm wants to merge 2 commits into
developfrom
fix/video-export-fails
Open

fix: video export failing when the source file is already an .mp4 - WPB-26457#5006
jullianm wants to merge 2 commits into
developfrom
fix/video-export-fails

Conversation

@jullianm

@jullianm jullianm commented Jul 10, 2026

Copy link
Copy Markdown
Contributor
BugWPB-26457 [iOS] Not able to attach video file on opening photos in drive conversation

Issue

Exporting/converting a video to upload format was failing with AVFoundationErrorDomain Code=-11800 (wrapping NSOSStatusErrorDomain Code=-16979) whenever the source video's temp filename already ended in .mp4.

Root cause: convertVideoToUploadFormat/convert(filename:) derive the converted file's output path from the source's basename with the extension swapped to .mp4. When the source was already .mp4, the computed output path was identical to the source path. The code then deleted any "leftover" file at that path before starting the export — which deleted the source file the AVAssetExportSession was still reading from, causing the export to fail.

Fixing that first collision exposed a second, related bug: once the export was made to succeed by writing to a distinct intermediate file and moving it into place, the converted file ended up at the same path as the source. The deleteSourceFile cleanup step in convertVideoToUploadFormat then deleted that path, wiping out the just-converted file before it could be uploaded (NSCocoaErrorDomain Code=260 / ENOENT downstream, e.g. in processWireDriveVideo).

Both are fixed in AVAsset+VideoConvert.swift:

  • convert(filename:) now exports to a uniquely named (UUID) intermediate file, then moves it to the final output path only after the export session has finished reading from the source.
  • convertVideoToUploadFormat now skips deleting the source file if its path is the same as the converted output's path (i.e. when they collided).

Testing

  • Reproduce by sharing/uploading a video via WireDrive (or camera roll) whose temp copy already has a .mp4 extension (e.g. processWireDriveVideo in ConversationInputBarViewController+ImagePickerDriveConversation.swift) — before the fix this failed export with -11800/-16979, and after a partial fix failed upload with ENOENT. After both fixes, conversion and upload succeed.
  • Existing unit test AVURLAsset_conversionTests.testThatVideoIsConvertedToUploadFormat (Wire-iOS Tests/AVAsset/AVURLAsset+conversionTests.swift) still covers the non-colliding case.

Checklist

  • Title contains a reference JIRA issue number like [WPB-XXX].
  • Description is filled and free of optional paragraphs.
  • Adds/updates automated tests.

UI accessibility checklist

If your PR includes UI changes, please utilize this checklist:

  • Make sure you use the API for UI elements that support large fonts.
  • All colors are taken from WireDesign.ColorTheme or constructed using WireDesign.BaseColorPalette.
  • New UI elements have Accessibility strings for VoiceOver.

@jullianm
jullianm requested review from a team, KaterinaWire and netbe and removed request for a team July 10, 2026 15:28
@jullianm
jullianm requested a review from findms July 10, 2026 15:31
@jullianm

Copy link
Copy Markdown
Contributor Author

@findms could you please test it and share info here whether it fixes your issue or not.
Feel free to merge this PR when QA validated and approved while I'm away.

@sonarqubecloud

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Test Results

1 934 tests   1 907 ✅  2m 27s ⏱️
  304 suites     27 💤
    1 files        0 ❌

Results for commit 7889cb6.

Summary: workflow run #29103775233
Allure report (download zip): html-report-31904-fix_video-export-fails

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a Wire iOS video-conversion failure in AVURLAsset.convertVideoToUploadFormat that occurred when the source video already had an .mp4 extension and lived in the temp directory, causing the conversion output path to collide with (and previously delete) the source file mid-export.

Changes:

  • Export conversion output into a uniquely named (UUID) intermediate file, then move it to the final outputURL after export completes.
  • Prevent cleanup from deleting the “source” file when the converted output path collides with the source path.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +166 to +170
} catch let moveError {
WireLogger.ui.error("Cannot move converted video to \(outputURL): \(moveError)")
DispatchQueue.main.async {
completion(nil, self, moveError)
}
Comment on lines +135 to +142
// Export into a uniquely named intermediate file rather than directly to `outputURL`.
// `outputURL`'s name is derived from the source asset's filename with the extension
// swapped to `.mp4`, so when the source is already an `.mp4` it collides with the
// source path itself. Deleting that "leftover" file out from under the export session
// while it's still reading from it caused it to fail.
let exportingURL = URL(fileURLWithPath: NSTemporaryDirectory())
.appendingPathComponent(UUID().uuidString)
.appendingPathExtension(outputURL.pathExtension)
@findms

findms commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

@findms could you please test it and share info here whether it fixes your issue or not. Feel free to merge this PR when QA validated and approved while I'm away.

@jullianm I have tried building with this branch fix/video-export-fails but it’s same for me..Still after selecting a video file from picker it doesn't show as attached(or compressing ).

@netbe netbe left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, it would be good to add tests for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants