tanersener / mobile-ffmpeg

FFmpeg for Android, iOS and tvOS. Not maintained anymore. Superseded by FFmpegKit.
https://tanersener.github.io/mobile-ffmpeg
GNU General Public License v3.0
3.87k stars 791 forks source link

Streaming the output file after converting it #404

Closed yiss closed 4 years ago

yiss commented 4 years ago

Description Hi, Thank you guys for the work you did on this framework, I'm having a bit of trouble finding and streaming the output video from HLS here is my code :

val url = "http://videos.rtva.ad:1935/live/web/playlist.m3u8"
            val m = packageManager
            var s = packageName
            val p = m.getPackageInfo(s, 0)
            val localUrl = p.applicationInfo.dataDir + "/out.mp4"
            val asyncExec = AsyncSingleFFmpegExecuteTask("-y -i \"$url\" -c copy -bsf:a aac_adtstoasc \"$localUrl\"") { code, out ->
                println("$code : $out")
            }
            //asyncExec.execute()
            mClingPlayControl.playUrl(localUrl, ClingPlayType.TYPE_VIDEO,object : ControlCallback{

                override fun success(response: Any) {
                    ClingManager.instance.registerAVTransport(this@MainActivity)
                    ClingManager.instance.registerRenderingControl(this@MainActivity)
                }

                override fun fail(response: Exception) {

                    mHandler.sendEmptyMessage(ERROR_ACTION)
                }
            })
            asyncExec.execute()

Any idea ? Expected behavior What you expected to happen.

Current behavior What happened.

Screenshots If applicable, add screenshots to help explain your problem.

Logs

I/mobile-ffmpeg: Loading mobile-ffmpeg.
I/mobile-ffmpeg: Loaded mobile-ffmpeg-full-arm64-v8a-4.3.2-20200415.
D/mobile-ffmpeg: Callback thread started.
I/mobile-ffmpeg: ffmpeg version v4.3-dev-2955
     Copyright (c) 2000-2020 the FFmpeg developers
      built with Android (5900059 based on r365631c) clang version 9.0.8 (https://android.googlesource.com/toolchain/llvm-project 207d7abc1a2abf3ef8d4301736d6a7ebc224a290) (based on LLVM 9.0.8svn)
      configuration: --cross-prefix=aarch64-linux-android- --sysroot=/files/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/sysroot --prefix=/home/taner/Projects/mobile-ffmpeg/prebuilt/android-arm64/ffmpeg --pkg-config=/usr/bin/pkg-config --enable-version3 --arch=aarch64 --cpu=armv8-a --cc=aarch64-linux-android24-clang --cxx=aarch64-linux-android24-clang++ --target-os=android --enable-neon --enable-asm --enable-inline-asm --enable-cross-compile --enable-pic --enable-jni --enable-optimizations --enable-swscale --enable-shared --enable-v4l2-m2m --disable-outdev=fbdev --disable-indev=fbdev --enable-small --disable-openssl --disable-xmm-clobber-test --disable-debug --enable-lto --disable-neon-clobber-test --disable-programs --disable-postproc --disable-doc --disable-htmlpages --disable-manpages --disable-podpages --disable-txtpages --disable-static --disable-sndio --disable-schannel --disable-securetransport --disable-xlib --disable-cuda --disable-cuvid --disable-nvenc --disable-vaapi --disable-vdpau --
      libavutil      56. 42.102 / 56. 42.102
      libavcodec     58. 78.102 / 58. 78.102
      libavformat    58. 42.100 / 58. 42.100
      libavdevice    58.  9.103 / 58.  9.103
      libavfilter     7. 77.101 /  7. 77.101
      libswscale      5.  6.101 /  5.  6.101
      libswresample   3.  6.100 /  3.  6.100
I/mobile-ffmpeg: [hls @ 0x79aba1f200] Skip ('#EXT-X-VERSION:3')
I/mobile-ffmpeg: [hls @ 0x79aba1f200] Opening 'http://videos.rtva.ad:1935/live/web/chunklist_w1963529185.m3u8' for reading
I/mobile-ffmpeg: [hls @ 0x79aba1f200] Skip ('#EXT-X-VERSION:3')
    [hls @ 0x79aba1f200] Skip ('#EXT-X-DISCONTINUITY-SEQUENCE:0')
    [hls @ 0x79aba1f200] Opening 'http://videos.rtva.ad:1935/live/web/media_w1963529185_146517.ts' for reading
I/mobile-ffmpeg: [hls @ 0x79aba1f200] Opening 'http://videos.rtva.ad:1935/live/web/media_w1963529185_146518.ts' for reading
I/mobile-ffmpeg: Input #0, hls, from 'http://videos.rtva.ad:1935/live/web/playlist.m3u8':
      Duration: 
    N/A
    , start: 
    33504.427667
    , bitrate: 
    N/A
      Program 0 
        Metadata:
          variant_bitrate : 
    1368850
        Stream #0:0
    : Data: timed_id3 (ID3  / 0x20334449)
        Metadata:
          variant_bitrate : 
    1368850
        Stream #0:1
    : Video: h264 ([27][0][0][0] / 0x001B), yuv420p(tv), 854x480 [SAR 1:1 DAR 427:240]
    , 
    50 tbr, 
    90k tbn, 
    60 tbc
        Metadata:
          variant_bitrate : 
    1368850
        Stream #0:2
    : Audio: aac ([15][0][0][0] / 0x000F), 44100 Hz, stereo, fltp
        Metadata:
          variant_bitrate : 
    1368850
I/mobile-ffmpeg: Output #0, mp4, to '/data/user/0/com.lizhiweik.clinglib/out.mp4':
      Metadata:
        encoder         : 
    Lavf58.42.100
        Stream #0:0
    : Video: h264 (avc1 / 0x31637661), yuv420p(tv), 854x480 [SAR 1:1 DAR 427:240], q=2-31
    , 
    50 tbr, 
    90k tbn, 
    90k tbc
        Metadata:
          variant_bitrate : 
    1368850
        Stream #0:1
    : Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp
        Metadata:
          variant_bitrate : 
    1368850
    Stream mapping:
      Stream #0:1 -> #0:0
     (copy)
      Stream #0:2 -> #0:1
     (copy)
    Press [q] to stop, [?] for help
I/mobile-ffmpeg: frame=  168 fps=0.0 q=-1.0 size=     768kB time=00:00:05.61 bitrate=1120.3kbits/s speed=10.8x    
I/mobile-ffmpeg: frame=  279 fps=266 q=-1.0 size=    1280kB time=00:00:09.26 bitrate=1132.2kbits/s speed=8.84x    
I/mobile-ffmpeg: [http @ 0x7a0d642c00] Opening 'http://videos.rtva.ad:1935/live/web/media_w1963529185_146519.ts' for reading
I/mobile-ffmpeg: frame=  377 fps=243 q=-1.0 size=    1792kB time=00:00:12.58 bitrate=1166.8kbits/s speed= 8.1x    
I/mobile-ffmpeg: frame=  438 fps=186 q=-1.0 size=    2048kB time=00:00:14.60 bitrate=1149.0kbits/s speed=6.21x    
I/mobile-ffmpeg: frame=  521 fps=182 q=-1.0 size=    2304kB time=00:00:17.34 bitrate=1088.4kbits/s speed=6.05x    
I/mobile-ffmpeg: frame=  595 fps=176 q=-1.0 size=    2816kB time=00:00:19.80 bitrate=1164.9kbits/s speed=5.86x    
I/mobile-ffmpeg: frame=  778 fps=200 q=-1.0 size=    3584kB time=00:00:25.95 bitrate=1131.1kbits/s speed=6.66x    
I/mobile-ffmpeg: frame=  843 fps=189 q=-1.0 size=    3840kB time=00:00:28.09 bitrate=1119.8kbits/s speed= 6.3x    
I/mobile-ffmpeg: [http @ 0x7a0d613400] Opening 'http://videos.rtva.ad:1935/live/web/chunklist_w1963529185.m3u8' for reading
I/mobile-ffmpeg: [hls @ 0x79aba1f200] Skip ('#EXT-X-VERSION:3')
    [hls @ 0x79aba1f200] Skip ('#EXT-X-DISCONTINUITY-SEQUENCE:0')
    [http @ 0x7a0d642c00] Opening 'http://videos.rtva.ad:1935/live/web/media_w1963529185_146520.ts' for reading
I/mobile-ffmpeg: frame=  904 fps=100 q=-1.0 size=    4096kB time=00:00:30.09 bitrate=1115.1kbits/s speed=3.33x    
I/mobile-ffmpeg: frame= 1023 fps=107 q=-1.0 size=    4608kB time=00:00:34.08 bitrate=1107.5kbits/s speed=3.55x    
I/mobile-ffmpeg: frame= 1177 fps=116 q=-1.0 size=    5376kB time=00:00:39.23 bitrate=1122.4kbits/s speed=3.88x    
I/mobile-ffmpeg: [http @ 0x7a0d613400] Opening 'http://videos.rtva.ad:1935/live/web/chunklist_w1963529185.m3u8' for reading
I/mobile-ffmpeg: [hls @ 0x79aba1f200] Skip ('#EXT-X-VERSION:3')
    [hls @ 0x79aba1f200] Skip ('#EXT-X-DISCONTINUITY-SEQUENCE:0')
    [http @ 0x7a0d642c00] Opening 'http://videos.rtva.ad:1935/live/web/media_w1963529185_146521.ts' for reading
I/mobile-ffmpeg: frame= 1203 fps= 63 q=-1.0 size=    5632kB time=00:00:40.07 bitrate=1151.3kbits/s speed=2.09x    
I/mobile-ffmpeg: frame= 1314 fps= 67 q=-1.0 size=    6144kB time=00:00:43.78 bitrate=1149.4kbits/s speed=2.23x    
I/mobile-ffmpeg: frame= 1480 fps= 73 q=-1.0 size=    6912kB time=00:00:49.33 bitrate=1147.6kbits/s speed=2.44x    
I/mobile-ffmpeg: [http @ 0x7a0d613400] Opening 'http://videos.rtva.ad:1935/live/web/chunklist_w1963529185.m3u8' for reading
I/mobile-ffmpeg: [hls @ 0x79aba1f200] Skip ('#EXT-X-VERSION:3')
    [hls @ 0x79aba1f200] Skip ('#EXT-X-DISCONTINUITY-SEQUENCE:0')
    [http @ 0x7a0d642c00] Opening 'http://videos.rtva.ad:1935/live/web/media_w1963529185_146522.ts' for reading
I/mobile-ffmpeg: frame= 1541 fps= 51 q=-1.0 size=    7168kB time=00:00:51.33 bitrate=1143.8kbits/s speed=1.68x    
I/mobile-ffmpeg: frame= 1704 fps= 55 q=-1.0 size=    7936kB time=00:00:56.79 bitrate=1144.7kbits/s speed=1.83x    
I/mobile-ffmpeg: frame= 1819 fps= 58 q=-1.0 size=    8448kB time=00:01:00.62 bitrate=1141.6kbits/s speed=1.92x    
I/mobile-ffmpeg: [http @ 0x7a0d613400] Opening 'http://videos.rtva.ad:1935/live/web/chunklist_w1963529185.m3u8' for reading
I/mobile-ffmpeg: [hls @ 0x79aba1f200] Skip ('#EXT-X-VERSION:3')
    [hls @ 0x79aba1f200] Skip ('#EXT-X-DISCONTINUITY-SEQUENCE:0')
    [http @ 0x7a0d642c00] Opening 'http://videos.rtva.ad:1935/live/web/media_w1963529185_146523.ts' for reading
I/mobile-ffmpeg: frame= 1823 fps= 46 q=-1.0 size=    8448kB time=00:01:00.78 bitrate=1138.5kbits/s speed=1.52x    
I/mobile-ffmpeg: frame= 1962 fps= 48 q=-1.0 size=    9216kB time=00:01:05.33 bitrate=1155.5kbits/s speed=1.61x    
I/mobile-ffmpeg: frame= 2099 fps= 51 q=-1.0 size=    9728kB time=00:01:09.95 bitrate=1139.1kbits/s speed= 1.7x    
I/mobile-ffmpeg: [http @ 0x7a0d613400] Opening 'http://videos.rtva.ad:1935/live/web/chunklist_w1963529185.m3u8' for reading
I/mobile-ffmpeg: [hls @ 0x79aba1f200] Skip ('#EXT-X-VERSION:3')
    [hls @ 0x79aba1f200] Skip ('#EXT-X-DISCONTINUITY-SEQUENCE:0')
    [http @ 0x7a0d642c00] Opening 'http://videos.rtva.ad:1935/live/web/media_w1963529185_146524.ts' for reading
I/mobile-ffmpeg: frame= 2130 fps= 42 q=-1.0 size=    9728kB time=00:01:11.02 bitrate=1122.0kbits/s speed=1.41x    
I/mobile-ffmpeg: frame= 2227 fps= 44 q=-1.0 size=   10240kB time=00:01:14.20 bitrate=1130.4kbits/s speed=1.46x    
I/mobile-ffmpeg: frame= 2295 fps= 45 q=-1.0 size=   10496kB time=00:01:16.48 bitrate=1124.2kbits/s speed=1.49x    
I/mobile-ffmpeg: frame= 2413 fps= 46 q=-1.0 size=   11264kB time=00:01:20.40 bitrate=1147.6kbits/s speed=1.55x    
I/mobile-ffmpeg: [http @ 0x7a0d613400] Opening 'http://videos.rtva.ad:1935/live/web/chunklist_w1963529185.m3u8' for reading
I/mobile-ffmpeg: [hls @ 0x79aba1f200] Skip ('#EXT-X-VERSION:3')
    [hls @ 0x79aba1f200] Skip ('#EXT-X-DISCONTINUITY-SEQUENCE:0')
    [http @ 0x7a0d642c00] Opening 'http://videos.rtva.ad:1935/live/web/media_w1963529185_146525.ts' for reading

Environment

Other Add any other context about the problem here.

tanersener commented 4 years ago

I don't understand what is the question? You are saving an hls stream into an mp4 file and trying to play that file using a player. Output file is a local mp4 file. You are not streaming it. Do you want to stream it again?

If you can't play the file try adding -movflags faststart before the output file name. It will move the header to the beginning of the file.

yiss commented 4 years ago

@tanersener thank you for your response, probably I didn't make my question clear. The problem for me is that ffmpeg keeps running and the command to run the file in player doesn't get executed. I'm looking for a way to run ffmpeg in the background and run command to play the converted file just after the ffmpeg command (while ffmpeg is still running)

tanersener commented 4 years ago

AsyncSingleFFmpegExecuteTask is an async task. So running execute() or the following execute variant shouldn't be blocking your main thread. You should be doing something wrong.

Take a look at this method. I use that one in my test application.

asyncExec.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);

github-actions[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.