Tumblelog by Soup.io
Newer posts are loading.
You are at the newest post.
Click here to check if anything new just came in.

March 03 2017

09:40

Concatenate mp4 video files on iOS using Libavformat

I need to merge (i.e. concatenate) multiple video files (using H.264 codec) in an iOS application. The problem is I can't use AVFoundation because it can't handle the video format on iOS (no problem on MacOS). So I tried to use the FFmpeg library, specifically Libavformat for this task. I found C code that looks useful here: http://stackoverflow.com/a/16293046. But i can't get it to work and don't understand it completly. The output video file appears to play only black frames. I'm using the precompiled libraries from the FFmpeg CocoaPod.

I was able to convert a single test video (which has 1GB) using the command line tool on my Mac:

$ ffmpeg -i input.mp4 -vcodec copy output.mp4
ffmpeg version 3.2.4-tessus Copyright (c) 2000-2017 the FFmpeg developers
  built with Apple LLVM version 8.0.0 (clang-800.0.42.1)
  configuration: --cc=/usr/bin/clang --prefix=/opt/ffmpeg --extra-version=tessus --enable-avisynth --enable-fontconfig --enable-gpl --enable-libass --enable-libbluray --enable-libfreetype --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopus --enable-libschroedinger --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzmq --enable-version3 --disable-ffplay --disable-indev=qtkit --disable-indev=x11grab_xcb
  libavutil      55. 34.101 / 55. 34.101
  libavcodec     57. 64.101 / 57. 64.101
  libavformat    57. 56.101 / 57. 56.101
  libavdevice    57.  1.100 / 57.  1.100
  libavfilter     6. 65.100 /  6. 65.100
  libswscale      4.  2.100 /  4.  2.100
  libswresample   2.  3.100 /  2.  3.100
  libpostproc    54.  1.100 / 54.  1.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41isomiso2
    creation_time   : 2016-09-14T14:35:53.000000Z
  Duration: 00:04:32.29, start: 0.000000, bitrate: 30013 kb/s
    Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 29958 kb/s, 50 fps, 50 tbr, 5k tbn, 100 tbc (default)
    Metadata:
      creation_time   : 2016-09-14T14:35:53.000000Z
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      creation_time   : 2016-09-14T14:35:53.000000Z
      handler_name    : SoundHandler
Output #0, mp4, to 'output.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41isomiso2
    encoder         : Lavf57.56.101
    Stream #0:0(eng): Video: h264 (Main) ([33][0][0][0] / 0x0021), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 29958 kb/s, 50 fps, 50 tbr, 10k tbn, 5k tbc (default)
    Metadata:
      creation_time   : 2016-09-14T14:35:53.000000Z
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: aac (LC) ([64][0][0][0] / 0x0040), 48000 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      creation_time   : 2016-09-14T14:35:53.000000Z
      handler_name    : SoundHandler
      encoder         : Lavc57.64.101 aac
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
frame=13577 fps=1280 q=-1.0 Lsize=  997604kB time=00:04:32.28 bitrate=30013.7kbits/s speed=25.7x    
video:993034kB audio:4268kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.030246%
[aac @ 0x7fa849809e00] Qavg: 942.999

This process is very fast (10 seconds) and I can play the resulting video on iOS using AVFoundation frameworks. If i could do the same for each input video using Libavformat in my iOS app i could solve my problem by merging the videos in a second step using AVAssetExportSession.

Any help is appreciated.

09:40

Concatenate mp4 video files on iOS using Libavformat

I need to merge (i.e. concatenate) multiple video files (using H.264 codec) in an iOS application. The problem is I can't use AVFoundation because it can't handle the video format on iOS (no problem on MacOS). So I tried to use the FFmpeg library, specifically Libavformat for this task. I found C code that looks useful here: http://stackoverflow.com/a/16293046. But i can't get it to work and don't understand it completly. The output video file appears to play only black frames. I'm using the precompiled libraries from the FFmpeg CocoaPod.

I was able to convert a single test video (which has 1GB) using the command line tool on my Mac:

$ ffmpeg -i input.mp4 -vcodec copy output.mp4
ffmpeg version 3.2.4-tessus Copyright (c) 2000-2017 the FFmpeg developers
  built with Apple LLVM version 8.0.0 (clang-800.0.42.1)
  configuration: --cc=/usr/bin/clang --prefix=/opt/ffmpeg --extra-version=tessus --enable-avisynth --enable-fontconfig --enable-gpl --enable-libass --enable-libbluray --enable-libfreetype --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopus --enable-libschroedinger --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzmq --enable-version3 --disable-ffplay --disable-indev=qtkit --disable-indev=x11grab_xcb
  libavutil      55. 34.101 / 55. 34.101
  libavcodec     57. 64.101 / 57. 64.101
  libavformat    57. 56.101 / 57. 56.101
  libavdevice    57.  1.100 / 57.  1.100
  libavfilter     6. 65.100 /  6. 65.100
  libswscale      4.  2.100 /  4.  2.100
  libswresample   2.  3.100 /  2.  3.100
  libpostproc    54.  1.100 / 54.  1.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41isomiso2
    creation_time   : 2016-09-14T14:35:53.000000Z
  Duration: 00:04:32.29, start: 0.000000, bitrate: 30013 kb/s
    Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 29958 kb/s, 50 fps, 50 tbr, 5k tbn, 100 tbc (default)
    Metadata:
      creation_time   : 2016-09-14T14:35:53.000000Z
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      creation_time   : 2016-09-14T14:35:53.000000Z
      handler_name    : SoundHandler
Output #0, mp4, to 'output.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41isomiso2
    encoder         : Lavf57.56.101
    Stream #0:0(eng): Video: h264 (Main) ([33][0][0][0] / 0x0021), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 29958 kb/s, 50 fps, 50 tbr, 10k tbn, 5k tbc (default)
    Metadata:
      creation_time   : 2016-09-14T14:35:53.000000Z
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: aac (LC) ([64][0][0][0] / 0x0040), 48000 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      creation_time   : 2016-09-14T14:35:53.000000Z
      handler_name    : SoundHandler
      encoder         : Lavc57.64.101 aac
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
frame=13577 fps=1280 q=-1.0 Lsize=  997604kB time=00:04:32.28 bitrate=30013.7kbits/s speed=25.7x    
video:993034kB audio:4268kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.030246%
[aac @ 0x7fa849809e00] Qavg: 942.999

This process is very fast (10 seconds) and I can play the resulting video on iOS using AVFoundation frameworks. If i could do the same for each input video using Libavformat in my iOS app i could solve my problem by merging the videos in a second step using AVAssetExportSession.

Any help is appreciated.

October 12 2016

15:59

Comment by Felix on Swift: Disappearing views from a stackView

The text "First" is actually visible at the bottom in your animation, so it is not hidden. Are you sure you have set a fixed height constraint on the segment control?

October 03 2016

14:45

Custom Subscript in Swift not working with Implicitly Unwrapped Optional [duplicate]

Consider the following Swift struct:

struct A {
    var data: [Int] = [1, 2, 3]

    subscript(index: Int) -> Int {
        get {
            return data[index]
        }
        set {
            data[index] = newValue
        }
    }
}

This is working as expected:

var x = A()
x[0] = 5
x.data[1] = 7
print(x.data) // prints [5, 7, 3]

But when I declare the variable as implicitly unwrapped optional the subscipt setter doesn't seem to work:

var y: A! = A()
y[0] = 5
y.data[1] = 7
print(y.data) // prints [1, 7, 3]

What is happening here? Shouldn't the subscript work the same way with implicitly unwrapped optionals?

September 16 2016

09:22

Answer by Felix for Xcode 8 cannot run on device, provisioning profile problems mentioning Apple Watch

This did work for me:

  • Disable bluetooth on the iPhone
  • Disconnect & reconnect iPhone
  • Build and Run
  • Enable bluetooth again when you are finished with the debugging session

September 06 2016

10:28

Comment by Felix on Is there a library or framework for creating and modifying contacts in iOS ? - Swift

iOS provides UI in the ContactsUI framework. There is CNContactPickerViewController and CNContactViewController.

June 23 2016

14:43

Answer by Felix for Is it possible to tell when a user update the app?

The app gets terminated before the update starts and I guess there is no notification sent to the app before that happens.

June 17 2016

14:39

Answer by Felix for How to stop an animation from resetting when adding a subview in Swift.?

Move the code in viewDidLayoutSubviews to viewDidLoad. That should resolve your issue.

The method viewDidLayoutSubviews is called every time you add new subviews.

June 02 2016

12:36

Comment by Felix on How do I identify player without a Game Center's ID?

You can use NSUbiquitousKeyValueStore to store the data or user id . It is always available, even if the user does not have an iCloud account (in this case, NSUbiquitousKeyValueStore is just a simple local storage).
10:58

Answer by Felix for How do I identify player without a Game Center's ID?

You can save game data using iCloud. This might help:

https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/GameKit_Guide/SavedGames/SavedGames.html

If you need to store the data on your own server instead you could only store the user ID in iCloud to identify the user on your server. The ID could be generated by your server or by the app itself by using NSUUID.

May 24 2016

09:06

March 24 2016

11:08

Answer by Felix for Swift show a different result with Objective-C in convert NSString to NSDate?

The results are actually the same. Only the output formatting is different.

Change the swift code at the end to get the same result (so both use NSDate's description method under the hood):

let date = fmt.dateFromString(string)!
print(date)

March 16 2016

18:06

Comment by Felix on How many if statements can be executed in 1 sec approximately

i think you should be more concerned about the work that is done in the body of the for-loops. And besides if-statements incrementing loop counters and memory access also takes time. It also depends on the programming language you choose.

February 11 2016

18:12

Comment by Felix on How can we display number values in UILabels in iOS?

@Mr.T other answer might also work, but localizedStringWithFormat creates a localized string with the current locale and it would also work if the object is actually a string already
16:14

Answer by Felix for How can we display number values in UILabels in iOS?

The problem is you are assigning an NSNumber instance instead of an NSString. You should format the number to a string like this:

NSNumber* number = [McoIdArray objectAtIndex:indexPath.row];
cell.mcoId.text = [NSString localizedStringWithFormat:@"%@", number];

If you want to have more control over number formatting you can use NSNumberFormatter.

January 28 2016

11:16

Answer by Felix for How to programmatically open Apple Watch companion app from iOS app

I guess it's not possible to programmatically launch the watch companion app from iOS. The opposite way would be possible: to launch the iOS app in the background upon receiving a message from the watch. See WWDC talk Introducing Watch Connectivity.

You could check WCSession.defaultSession().watchAppInstalled and ask the user to launch the app if it is true.

October 03 2015

15:32

Answer by Felix for NSAppTransportSecurity option not listed in Xcode plist editor

Xcode 7.1 lists the option in the dropdown (App Transport Security Settings). In earlier versions you need to type the raw key NSAppTransportSecurity and set the type to dictionary.

July 14 2015

22:14

Comment by Felix on Can I save an NSData object to a file as binary?

BinaryFormat_v1_0 is not XML. how do you examine the file?

July 06 2015

13:26

Comment by Felix on How can I display a viewpager for one size class, and a regular layout for another?

you could create just a container view in IB and lazily create the ITViewPager when the "regular width" size class becomes active and manually add it to the container view. also (de-)activate layout constraints appropriately.

July 03 2015

20:35

Comment by Felix on When assigning focus via becomeFirstResponder to UISearchController's UISearchBar, the keyboard does not appear

does not work for me. didPresentSearchController is called, but keyboard does not appear.
Older posts are this way If this message doesn't go away, click anywhere on the page to continue loading posts.
Could not load more posts
Maybe Soup is currently being updated? I'll try again automatically in a few seconds...
Just a second, loading more posts...
You've reached the end.

Don't be the product, buy the product!

Schweinderl