Programmatically convert flv to mp4 on iOS
Asked Answered
P

1

6

In our iOS app, we will receive flv**(Container)** file having video and audio streaming something like this

Input #0, flv, from 'test.flv':

  Metadata:
    streamName      : flvLiveStream
    encoder         : Lavf55.12.100
  Duration: 00:00:48.00, start: 66064.401000, bitrate: 632 kb/s
    Stream #0:0, 41, 1/1000: **Video: h264 (Baseline)**, 1 reference frame, yuv420p(progressive, left), 1280x720, 0/1, 15 fps, 1k tbr, 1k tbn
    Stream #0:1, 14, 1/1000: **Audio: pcm_alaw,** 8000 Hz, mono, s16, 64 kb/s

and this needs to be converted to mp4 container and format as well, I am trying using ffmpeg, I believe thats only the way , using transcoding.c file but failed at this stage

Impossible to convert between the formats supported by the filter 'in' and the filter 'auto_scaler_0'

I am trying to learn from OSX command like ffmpeg -I test.flv test.mp4 ,

is that feasible to port to iOS will it work in all different scenarios,

In Summary

--- What is the best possible way to convert flv to mp4 on the iOS device where video will be in h264 and audio will be in swf codec ?

Policewoman answered 28/7, 2018 at 19:46 Comment(3)
I'm facing the exact same issue, also on iOS. All I know is that the function avfilter_graph_config is returning error -78: Function not implemented. Have you gotten it to work yet?Pasol
(1) Is the "impossible to convert..." error coming from your shown command? (2) Also not sure if made a typo (with capital "I") but it should be ffmpeg -i test.flv -c:v copy test.mp4 (3) Is your FLV a saved file? Otherwise what's the logic of putting a live stream (duration unknown) into an MP4 (its header expects duration)?...Duong
PS: Show your code of ffmpeg export settings (via transcoding.c). How do you actually define input & output formats?Duong
A
1
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"MyVideo.mp4"];
NSURL *outputURL = [NSURL fileURLWithPath:filePath];

[self convertVideoToLowQuailtyWithInputURL:localUrl outputURL:outputURL handler:^(AVAssetExportSession *exportSession)
{
    if (exportSession.status == AVAssetExportSessionStatusCompleted) {
        // Video conversation completed
    }          
}];

- (void)convertVideoToLowQuailtyWithInputURL:(NSURL*)inputURL outputURL:(NSURL*)outputURL handler:(void (^)(AVAssetExportSession*))handler {
    [[NSFileManager defaultManager] removeItemAtURL:outputURL error:nil];
    AVURLAsset *asset = [AVURLAsset URLAssetWithURL:inputURL options:nil];
    AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetPassthrough];
    exportSession.outputURL = outputURL;
    exportSession.outputFileType = AVFileTypeMPEG4;
    [exportSession exportAsynchronouslyWithCompletionHandler:^(void) {
         handler(exportSession);
     }];
}
Averett answered 13/8, 2018 at 7:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.