0

How can I convert m3u8 file to mp4 file in React Native Expo? I have tried to convert m3u8 file to mp4 using FFmpegKit but I have this errors:

'Cannot read property 'getLogLevel' of null' and 'Cannot read property 'ffmpegSession' of null'

Also building with this package failing (Could not determine the dependencies of task ':ffmpeg-kit-react-native:compileDebugAidl'.).

Is there a simple and easy way to convert m3u8 file in React Native Expo?

Code I have used:

import { FFmpegKit } from 'ffmpeg-kit-react-native';
export async function converterToMp4() {
    try {
        await FFmpegKit.executeAsync(`-i ${m3u8FileUri} ${mp4FileUri}`)

    } catch(err) {
        console.log(err)
    }
}
DRx
  • 21
  • 4
  • During compilation or during the application execution? – luk2302 Aug 06 '23 at 10:41
  • Do you have some code to share with us? – Lajos Arpad Aug 06 '23 at 10:55
  • @luk2302 during the application execution, I want to convert file when I just click the button – DRx Aug 06 '23 at 11:02
  • @LajosArpad I added code to the question – DRx Aug 06 '23 at 11:04
  • Is the request involved in this code sent? – Lajos Arpad Aug 06 '23 at 11:07
  • @LajosArpad I don't use request library – DRx Aug 06 '23 at 11:09
  • I did not assume that. But I see you are using some URI, which strongly suggests that you request the file either online or on your OS. You get an error. The question is: is this error happening before you are requesting the file, or after. – Lajos Arpad Aug 06 '23 at 11:36
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/254821/discussion-between-drx-and-lajos-arpad). – DRx Aug 06 '23 at 11:39
  • @DRx **(1)** Does it work (or progress) if you setup your code structure in the same way as [their example](https://github.com/arthenica/ffmpeg-kit/tree/main/react-native#3-using)? **(2)** Open the m3u8 as a text file and check if it gets `.mp4` chunks or else it gets `.ts` chunks. If it has MP4 then you could try "stitching" the bytes of each downloaded chunk to make one long output MP4 file. – VC.One Aug 06 '23 at 20:52
  • @VC.One my m3u8 file look like this: #EXTM3U #EXT-X-VERSION:4 #EXT-X-ALLOW-CACHE:NO #EXT-X-STREAM-INF:PROGRAM-ID=0,BANDWIDTH=1318906,CODECS="avc1.64001f,mp4a.40.2",RESOLUTION=1280x720,FRAME-RATE=23.974,VIDEO-RANGE=SDR https://fazhzcezbdi.takedwn.ws/03_01_19/03/01/02/gsogv1dB/1080_JEab8xQk.mp4/index-v1-a1.m3u8?x-cdn=10551403. I setup my code in the same way as https://github.com/expo/config-plugins/blob/main/packages/ffmpeg-kit-react-native/README.md Because I use Expo and it doesn't have default .android .ios folders. How can I "stitch" the bytes of m3u8 file or fix errors? – DRx Aug 07 '23 at 08:27
  • @DRx Your video is in `.ts` format. It cannot be stitched. That process would have been to read each MP4 fragment file (_eg:_ using Fetch or similar) into an Array/Buffer. You could then have a new `output` Array that is filled (joined) with each piece of the bytes result (data) from the URL requesting of the current MP4 file. See example of [using Spread Operator](https://www.programiz.com/javascript/spread-operator) to join Arrays together. That is your required stitching to make one large Array of MP4 bytes from each file read. When finished you have an MP4 file in memory (for play/storage) – VC.One Aug 08 '23 at 13:41
  • @DRx PS: Since you have MPEG-TS files in your M3U8 playlist, then maybe try using this tool: [Mux.js - TS remux into Fragmented MP4](https://github.com/videojs/mux.js#mpeg2-ts-to-fmp4-transmuxer). It should help you towards getting an MP4 file output. You'll have to experiment with it... I've never used it (I write my own code for such audio/video processing). – VC.One Aug 08 '23 at 13:51
  • As I understand you have a multiple problems here. According to the log level and session errors from you question, maybe you're calling the `executeAsync` method incorrectly. It seems that it at least requires a callback. So I would resolve that first, ideally trying to execute it like in the example, with all 3 callbacks (session, log, statistics). Try with a synchronous `execute`, gives the same error? If you've solved that part, please update the question, cause it seems like you're stuck in the initial phase. – mortalis Aug 19 '23 at 09:08

0 Answers0