FFmpeg iOS -> output file is invalid

Nat

I'm using following library to convert mkv to mp4: https://github.com/SterlingOnLoop/FFmpegWrapper.

- (void)convertUsingFFmpegWrapper {
    NSString *mp4Extension = @"mp4";
    NSString *mkvExtension = @"mkv";

    NSString *videoName = @"file1";
//    NSString *videoName = @"file2";

    NSString *mkvVideoFilePath = [[NSBundle mainBundle] pathForResource:videoName ofType:mkvExtension];
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = paths[0];
    NSString *mp4VideoFilePath = [NSString stringWithFormat:@"%@/%@.%@", documentsDirectory, videoName, mp4Extension];

    FFmpegWrapper *ffmpegWrapper = [[FFmpegWrapper alloc] init];
    NSDictionary *options = @{kFFmpegInputFormatKey: mkvExtension, kFFmpegOutputFormatKey: mp4Extension};
    [ffmpegWrapper convertInputPath:mkvVideoFilePath outputPath:mp4VideoFilePath options:options progressBlock:nil completionBlock:^(BOOL success, NSError *error) {
        if (success && !error) {
            // delete mp4 file
        } else if (error) {
            NSLog(@"Error during .MKV -> .MP4 conversion occured: %@", error.localizedDescription);
        } else {
            NSLog(@"Unknown error during .MKV -> .MP4 conversion occured.");
        }
    }];
}

Here are the values from LLDB about the automatically detected codec types:

(lldb) po inputStream.codecName
aac

(lldb) po outputStream.codecName
aac

I should mention here, that originally the file is generated on Linux with following codecs: vaapiencode_h264 for video and faac for sound.

The issue is that the file simply does not work. I get huge amount of logs in the console, where most important is:

[aac @ 0x7f7f65019200] Format aac detected only with low score of 1, misdetection possible!

Inside the library, the following function is used:

int streamInfoValue = avformat_find_stream_info(inputFormatContext, NULL);

And exactly this line does the whole mess with the logs. Obviously, without this line I receive an error with invalid argument.

When that line is turned on, the .mp4 file is generated. It lasts > 5 minutes, while input file is 11 seconds long. It cannot be played using VLC on my mac (seems to be broken). I get following errors (I'm pasting few of them, full track can be found here, it's too long to quote it here):

[aac @ 0x7ff07c00b000] More than one AAC RDB per ADTS frame is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
[aac @ 0x7ff07c00b000] channel element 0.0 is not allocated
[aac @ 0x7ff07c00b000] Sample rate index in program config element does not match the sample rate index configured by the container.
[aac @ 0x7ff07c00b000] Inconsistent channel configuration.
[aac @ 0x7ff07c00b000] get_buffer() failed
[aac @ 0x7ff07c00b000] channel element 3.10 is not allocated
[aac @ 0x7ff07c00b000] Reserved bit set.
[aac @ 0x7ff07c00b000] invalid band type
[aac @ 0x7ff07c00b000] Number of scalefactor bands in group (50) exceeds limit (41).
[aac @ 0x7ff07c00b000] Reserved bit set.
[aac @ 0x7ff07c00b000] Number of bands (7) exceeds limit (4).
[aac @ 0x7ff07c00b000] Reserved bit set.
[aac @ 0x7ff07c00b000] Dependent coupling is not supported together with LTP

Any idea how to simply convert mkv to mp4? I don't have any idea why the errors occurs. I'd claim that the file is not aac, but the linux uses this encoding, so it should be valid.

VC.One

I've checked your file. The main issues I can see is that :

  • There is no audio bitrate (ie: 128kbps should be set)
  • Somehow the metadata lists the AAC version as 4 (what does that even mean??).
  • The codec ID should be 40 but in the MKV's metadata it's listed as A_AAC/MPEG4/LC
  • There is no flag for Channel Position in the bytes (ie: Front L+R)

Anyways ffmpeg (command line) converted your MKV without any errors.
Let me know if this new re-encoded MP4 version works okay on your side.

The ffmpeg settings were simply : ffmpeg -i mkv_demo.mkv -c:v copy demo_new.mp4

Unfortunately I don't code in iOS so I couldn't show you a "fixed" code. Maybe someone can help later on. Look at this other Answer for extra hints (make it work like shown command line snippet above)...

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

FFmpeg iOS -> output file is invalid

From Dev

FFMPEG - Unable to find a suitable output format for 'ffmpeg' ffmpeg: Invalid argument

From Dev

Invalid File Output AVAssetExport

From Java

ffmpeg override output file if exists

From Dev

ffmpeg output file is too large

From Dev

FFMPEG MOV to MP4 error {Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument}

From Dev

ffmpeg Could not write header for output file #0

From Dev

ffmpeg deocde without producing output file

From Dev

ffmpeg command line write output to a text file

From Dev

libav / ffmpeg output optimisation for small file sizes

From Dev

subprocess not creating output file of ffmpeg command

From Dev

ffmpeg deocde without producing output file

From Dev

Creating a log file for my ffmpeg output

From Dev

Prevent ffmpeg from overwriting existing output file

From Dev

libav / ffmpeg output optimisation for small file sizes

From Dev

Newer version of ffmpeg does not output playable file

From Dev

ffmpeg/batch file: input format stays in output file name

From Dev

How to include input file name in output file name in ffmpeg

From Dev

Can I transcode a file with FFmpeg and read the output file on-the-fly?

From Dev

FFmpeg "movflags" > "faststart" causes invalid MP4 file to be written

From Dev

What is the bitrate of my audio file based on ffmpeg output?

From Dev

Can I use ffmpeg to output JPEGs to a memory stream instead of a file?

From Dev

ffmpeg capture current frame and overwrite the image output file

From Dev

ffmpeg error: at least one output file must be specified

From Dev

How to add suffix to duplicate filenames output by ffmpeg in Windows batch file?

From Dev

Incorrect Codec Parameters, Could not write header for output file: FFMPEG - Android

From Dev

How do I encode the FLV to a temporary file and then output that to stdout with FFMpeg?

From Dev

How to add suffix to duplicate filenames output by ffmpeg in Windows batch file?

From Dev

How do I get ffmpeg to correctly output this wav file?

Related Related

  1. 1

    FFmpeg iOS -> output file is invalid

  2. 2

    FFMPEG - Unable to find a suitable output format for 'ffmpeg' ffmpeg: Invalid argument

  3. 3

    Invalid File Output AVAssetExport

  4. 4

    ffmpeg override output file if exists

  5. 5

    ffmpeg output file is too large

  6. 6

    FFMPEG MOV to MP4 error {Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument}

  7. 7

    ffmpeg Could not write header for output file #0

  8. 8

    ffmpeg deocde without producing output file

  9. 9

    ffmpeg command line write output to a text file

  10. 10

    libav / ffmpeg output optimisation for small file sizes

  11. 11

    subprocess not creating output file of ffmpeg command

  12. 12

    ffmpeg deocde without producing output file

  13. 13

    Creating a log file for my ffmpeg output

  14. 14

    Prevent ffmpeg from overwriting existing output file

  15. 15

    libav / ffmpeg output optimisation for small file sizes

  16. 16

    Newer version of ffmpeg does not output playable file

  17. 17

    ffmpeg/batch file: input format stays in output file name

  18. 18

    How to include input file name in output file name in ffmpeg

  19. 19

    Can I transcode a file with FFmpeg and read the output file on-the-fly?

  20. 20

    FFmpeg "movflags" > "faststart" causes invalid MP4 file to be written

  21. 21

    What is the bitrate of my audio file based on ffmpeg output?

  22. 22

    Can I use ffmpeg to output JPEGs to a memory stream instead of a file?

  23. 23

    ffmpeg capture current frame and overwrite the image output file

  24. 24

    ffmpeg error: at least one output file must be specified

  25. 25

    How to add suffix to duplicate filenames output by ffmpeg in Windows batch file?

  26. 26

    Incorrect Codec Parameters, Could not write header for output file: FFMPEG - Android

  27. 27

    How do I encode the FLV to a temporary file and then output that to stdout with FFMpeg?

  28. 28

    How to add suffix to duplicate filenames output by ffmpeg in Windows batch file?

  29. 29

    How do I get ffmpeg to correctly output this wav file?

HotTag

Archive