Mobile-ffmpeg: [Swift] callback delegate not called

Created on 20 Nov 2019  ·  2Comments  ·  Source: tanersener/mobile-ffmpeg

I am using ffmpeg to convert image to video and I dont get any statistick callback.

In viewDidLoad() I am seting delegate:

override func viewDidLoad() {
        super.viewDidLoad()

        setup()
        MobileFFmpegConfig.setStatisticsDelegate(self)
    }

Here is the execution:

func generate(withImageURL url: URL, duration: Double, fileName: String) {
        if let path = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first {
            let documentDirectory = URL(fileURLWithPath: path)
            let newPath = documentDirectory.appendingPathComponent("\(fileName).mov")
            MobileFFmpeg.execute("-loop 1 -i \(url.absoluteString) -pix_fmt yuv420p -t \(duration) \(newPath.absoluteString)")

        }
    }

And here is the delegate:

extension ImageCuttingVC: StatisticsDelegate {
    func statisticsCallback(_ statistics: Statistics!) {
        DispatchQueue.main.async {
            print(statistics.getTime())
        }
    }
}

Log:

2019-11-20 20:53:44.327708+0100 VideoDiary[9215:1974604] INFO: ffmpeg version v4.3-dev-1181
2019-11-20 20:53:44.327862+0100 VideoDiary[9215:1974604] INFO:  Copyright (c) 2000-2019 the FFmpeg developers
2019-11-20 20:53:44.327954+0100 VideoDiary[9215:1974604] INFO:
2019-11-20 20:53:44.328075+0100 VideoDiary[9215:1974604] INFO:   built with Apple clang version 11.0.0 (clang-1100.0.33.8)
2019-11-20 20:53:44.328173+0100 VideoDiary[9215:1974604] INFO:   configuration: --sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.1.sdk --prefix=/Users/taner/Projects/mobile-ffmpeg/prebuilt/ios-x86_64-apple-darwin/ffmpeg --enable-version3 --arch=x86_64 --cpu=x86_64 --target-os=darwin --ar=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ar --cc=clang --cxx=clang++ --as='clang -arch x86_64 -target x86_64-ios-darwin -march=x86-64 -msse4.2 -mpopcnt -m64 -mtune=intel -DMOBILE_FFMPEG_X86_64 -Wno-unused-function -Wno-deprecated-declarations -fstrict-aliasing -DIOS -DMOBILE_FFMPEG_BUILD_DATE=20191026 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.1.sdk -O2 -mios-simulator-version-min=12.1 -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.1.sdk/usr/include' --ranlib=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib --strip=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/strip --disable-neon --enable-cross-compile --enable-pic --enable-asm --enable-inline-asm --enable-optimizations --enable-swscale --enable-static --disable-shared --enable-small --disable-v4l2-m2m --disable-outdev=v4l2 --disable-outdev=fbdev --disable-indev=v4l2 --disable-indev=fbdev --disable-openssl --disable-xmm-clobber-test --disable-debug --disable-neon-clobber-test --disable-programs --disable-postproc --disable-doc --disable-htmlpages --disable-manpages --disable-podpages --disable-txtpages --disable-sndio --disable-schannel --disable-securetransport --disable-xlib --disable-cuda --disable-cuvid --disable-nvenc --disable-vaapi --disable-vdpau --disable-appkit --disable-alsa --disable-cuda --disable-cuvid --disable-nvenc --disable-vaapi --disable-vdpau --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-gmp --enable-gnutls --enable-libmp3lame --enable-libass --enable-iconv --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libxml2 --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libshine --enable-libspeex --enable-libwavpack --enable-libkvazaar --enable-libilbc --enable-libopus --enable-libsnappy --enable-libsoxr --enable-libaom --enable-libtwolame --disable-sdl2 --enable-zlib --enable-audiotoolbox --enable-coreimage --enable-bzlib --enable-videotoolbox --enable-avfoundation
2019-11-20 20:53:44.373221+0100 VideoDiary[9215:1974604] INFO:   libavutil      56. 35.101 / 56. 35.101
2019-11-20 20:53:44.373337+0100 VideoDiary[9215:1974604] INFO:   libavcodec     58. 59.102 / 58. 59.102
2019-11-20 20:53:44.373427+0100 VideoDiary[9215:1974604] INFO:   libavformat    58. 33.100 / 58. 33.100
2019-11-20 20:53:44.373515+0100 VideoDiary[9215:1974604] INFO:   libavdevice    58.  9.100 / 58.  9.100
2019-11-20 20:53:44.373590+0100 VideoDiary[9215:1974604] INFO:   libavfilter     7. 65.100 /  7. 65.100
2019-11-20 20:53:44.373655+0100 VideoDiary[9215:1974604] INFO:   libswscale      5.  6.100 /  5.  6.100
2019-11-20 20:53:44.373733+0100 VideoDiary[9215:1974604] INFO:   libswresample   3.  6.100 /  3.  6.100
2019-11-20 20:53:44.373801+0100 VideoDiary[9215:1974604] INFO: Input #0, image2, from 'file:///Users/mike/Library/Developer/CoreSimulator/Devices/1F047EED-439C-4A5E-9E6A-2953E9B57FE2/data/Media/DCIM/100APPLE/IMG_0005.JPG':
2019-11-20 20:53:44.374102+0100 VideoDiary[9215:1974604] INFO:   Duration:
2019-11-20 20:53:44.374317+0100 VideoDiary[9215:1974604] INFO: 00:00:00.04
2019-11-20 20:53:44.374516+0100 VideoDiary[9215:1974604] INFO: , start:
2019-11-20 20:53:44.374787+0100 VideoDiary[9215:1974604] INFO: 0.000000
2019-11-20 20:53:44.375010+0100 VideoDiary[9215:1974604] INFO: , bitrate:
2019-11-20 20:53:44.375236+0100 VideoDiary[9215:1974604] INFO: 370452 kb/s
2019-11-20 20:53:44.375587+0100 VideoDiary[9215:1974604] INFO:
2019-11-20 20:53:44.375847+0100 VideoDiary[9215:1974604] INFO:     Stream #0:0
2019-11-20 20:53:44.376133+0100 VideoDiary[9215:1974604] INFO: : Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 3000x2002 [SAR 72:72 DAR 1500:1001]
2019-11-20 20:53:44.376430+0100 VideoDiary[9215:1974604] INFO: ,
2019-11-20 20:53:44.376727+0100 VideoDiary[9215:1974604] INFO: 25 fps,
2019-11-20 20:53:44.376994+0100 VideoDiary[9215:1974604] INFO: 25 tbr,
2019-11-20 20:53:44.377251+0100 VideoDiary[9215:1974604] INFO: 25 tbn,
2019-11-20 20:53:44.377570+0100 VideoDiary[9215:1974604] INFO: 25 tbc
2019-11-20 20:53:44.377791+0100 VideoDiary[9215:1974604] INFO:
2019-11-20 20:53:44.378029+0100 VideoDiary[9215:1974604] INFO: Stream mapping:
2019-11-20 20:53:44.378309+0100 VideoDiary[9215:1974604] INFO:   Stream #0:0 -> #0:0
2019-11-20 20:53:44.378658+0100 VideoDiary[9215:1974604] INFO:  (mjpeg (native) -> mpeg4 (native))
2019-11-20 20:53:44.379003+0100 VideoDiary[9215:1974604] INFO:
2019-11-20 20:53:44.379363+0100 VideoDiary[9215:1974604] INFO: Press [q] to stop, [?] for help
2019-11-20 20:53:44.379699+0100 VideoDiary[9215:1974604] WARNING: deprecated pixel format used, make sure you did set range correctly
2019-11-20 20:53:44.449246+0100 VideoDiary[9215:1974604] INFO: Output #0, mov, to 'file:///Users/mike/Library/Developer/CoreSimulator/Devices/1F047EED-439C-4A5E-9E6A-2953E9B57FE2/data/Containers/Data/Application/EC3E3E3E-5C0D-4976-BDB7-4090A4E96C86/Documents/12_18_2019.mov':
2019-11-20 20:53:44.451248+0100 VideoDiary[9215:1974604] INFO:   Metadata:
2019-11-20 20:53:44.452480+0100 VideoDiary[9215:1974604] INFO:     encoder         :
2019-11-20 20:53:44.452578+0100 VideoDiary[9215:1974604] INFO: Lavf58.33.100
2019-11-20 20:53:44.452664+0100 VideoDiary[9215:1974604] INFO:
2019-11-20 20:53:44.452737+0100 VideoDiary[9215:1974604] INFO:     Stream #0:0
2019-11-20 20:53:44.452808+0100 VideoDiary[9215:1974604] INFO: : Video: mpeg4 (mp4v / 0x7634706D), yuv420p, 3000x2002 [SAR 1:1 DAR 1500:1001], q=2-31, 200 kb/s
2019-11-20 20:53:44.453457+0100 VideoDiary[9215:1974604] INFO: ,
2019-11-20 20:53:44.453525+0100 VideoDiary[9215:1974604] INFO: 25 fps,
2019-11-20 20:53:44.453664+0100 VideoDiary[9215:1974604] INFO: 12800 tbn,
2019-11-20 20:53:44.453765+0100 VideoDiary[9215:1974604] INFO: 25 tbc
2019-11-20 20:53:44.453873+0100 VideoDiary[9215:1974604] INFO:
2019-11-20 20:53:44.454014+0100 VideoDiary[9215:1974604] INFO:     Metadata:
2019-11-20 20:53:44.454344+0100 VideoDiary[9215:1974604] INFO:       encoder         :
2019-11-20 20:53:44.455099+0100 VideoDiary[9215:1974604] INFO: Lavc58.59.102 mpeg4
2019-11-20 20:53:44.456429+0100 VideoDiary[9215:1974604] INFO:
2019-11-20 20:53:44.456889+0100 VideoDiary[9215:1974604] INFO:     Side data:
2019-11-20 20:53:44.457248+0100 VideoDiary[9215:1974604] INFO:
2019-11-20 20:53:44.457589+0100 VideoDiary[9215:1974604] INFO: cpb:
2019-11-20 20:53:44.457961+0100 VideoDiary[9215:1974604] INFO: bitrate max/min/avg: 0/0/200000 buffer size: 0
2019-11-20 20:53:44.458507+0100 VideoDiary[9215:1974604] INFO: vbv_delay: N/A
2019-11-20 20:53:44.458809+0100 VideoDiary[9215:1974604] INFO:
2019-11-20 20:53:44.888102+0100 VideoDiary[9215:1974604] INFO: frame=    8 fps=0.0 q=17.2 size=    1024kB time=00:00:00.28 bitrate=29952.0kbits/s speed=0.555x
2019-11-20 20:53:45.427841+0100 VideoDiary[9215:1974604] INFO: frame=   20 fps= 19 q=31.0 size=    1024kB time=00:00:00.76 bitrate=11036.9kbits/s speed=0.727x
2019-11-20 20:53:45.697953+0100 VideoDiary[9215:1974604] :
2019-11-20 20:53:45.698276+0100 VideoDiary[9215:1974604] INFO: frame=   25 fps= 18 q=24.8 Lsize=    1270kB time=00:00:00.96 bitrate=10840.2kbits/s speed=0.706x
2019-11-20 20:53:45.698360+0100 VideoDiary[9215:1974604] INFO: video:1269kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead:
2019-11-20 20:53:45.698455+0100 VideoDiary[9215:1974604] INFO: 0.074771%
2019-11-20 20:53:45.698551+0100 VideoDiary[9215:1974604] INFO:
2019-11-20 20:53:45.718568+0100 VideoDiary[9215:1974604] :

Thank you for your help

question

Most helpful comment

It began to work after I set logDelegate to the same class. Thank you

All 2 comments

Unfortunately, I don't have a Swift project to test this. Can you provide me a sample Swift project to reproduce this issue?

It began to work after I set logDelegate to the same class. Thank you

Was this page helpful?
0 / 5 - 0 ratings