Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

processing .mp4 file generates a black screen video with audio. #79

Open
han4wluc opened this issue Nov 22, 2017 · 5 comments
Open

processing .mp4 file generates a black screen video with audio. #79

han4wluc opened this issue Nov 22, 2017 · 5 comments

Comments

@han4wluc
Copy link

I am processing this video:

screen shot 2017-11-22 at 12 07 51

  NSURL *inputUrl = [NSURL fileURLWithPath:inputPath];
  AVURLAsset *inputUrlAsset = [AVURLAsset assetWithURL:inputUrl];

  NSURL *outputUrl = [NSURL fileURLWithPath:outputPath];
  
  SDAVAssetExportSession *encoder = [SDAVAssetExportSession.alloc initWithAsset:inputUrlAsset];
  encoder.outputFileType = AVFileTypeMPEG4;
  encoder.outputURL = outputUrl;
  //  1280x720
  encoder.videoSettings = @
  {
  AVVideoCodecKey: AVVideoCodecH264,
  AVVideoWidthKey: @720,
  AVVideoHeightKey: @1280,
  AVVideoCompressionPropertiesKey: @
    {
    AVVideoAverageBitRateKey: @512000,
    AVVideoProfileLevelKey: AVVideoProfileLevelH264High40,
    },
  };
  encoder.audioSettings = @
  {
  AVFormatIDKey: @(kAudioFormatMPEG4AAC),
  AVNumberOfChannelsKey: @2,
  AVSampleRateKey: @44100,
  AVEncoderBitRateKey: @96000,
  };
  
  [encoder exportAsynchronouslyWithCompletionHandler:^
  {
    if (encoder.status == AVAssetExportSessionStatusCompleted)
    {
      NSLog(@"Video export succeeded");
    }
    else if (encoder.status == AVAssetExportSessionStatusCancelled)
    {
      NSLog(@"Video export cancelled");
    }
    else
    {
      NSLog(@"Video export failed with error: %@ (%d)", encoder.error.localizedDescription, encoder.error.code);
    }
  }];

The output video is a black screen with the audio.
I am able to process .mov files without problem.
Does anyone know where the problem lies?

@newacct
Copy link

newacct commented Nov 29, 2017

I encountered this with some video tracks whose preferredTransform had a rotation but which didn't have an appropriate translation to shift it back into view, for some unknown reason. The following seems to fix it:

After the line CGAffineTransform transform = videoTrack.preferredTransform; in -[SDAVAssetExportSession buildDefaultVideoComposition], add the following lines:

  CGRect rect = {{0, 0}, naturalSize};
  CGRect transformedRect = CGRectApplyAffineTransform(rect, transform);
  // transformedRect should have origin at 0 if correct; otherwise add offset to correct it
  transform.tx -= transformedRect.origin.x;
  transform.ty -= transformedRect.origin.y;

@Shebuka
Copy link

Shebuka commented Jan 22, 2018

I was investigating the same problem with a video shared to our app from WhatsApp that produced a black video with audio. The buildDefaultVideoComposition method was one of the possible causes on my list and I've planned to debug into today. Now will try @newacct fix and report back.

@Shebuka
Copy link

Shebuka commented Jan 22, 2018

It's working correctly now with @newacct fix.

I'm attaching the incriminated video file so you can test with it: WhatsApp Video 2018-01-18 at 17.48.32.mp4.zip

@JasonPrenger
Copy link

I was also encountering this issue and the fix by @newacct worked well.

jnavarrom added a commit to meganz/SDAVAssetExportSession that referenced this issue Jul 27, 2018
shyela pushed a commit to RiplApp/SDAVAssetExportSession that referenced this issue Sep 13, 2019
@imdatceleste
Copy link

@newacct thanks, that helped me a lot

ghost pushed a commit to SlinkyLab/SDAVAssetExportSession that referenced this issue Nov 5, 2020
QiushiZhao added a commit to QiushiZhao/SDAVAssetExportSession that referenced this issue Apr 20, 2021
jungiebook added a commit to discord/SDAVAssetExportSession that referenced this issue Nov 3, 2022
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

No branches or pull requests

5 participants