Newest 'ffmpeg' Questions - Stack Overflow

http://stackoverflow.com/questions/tagged/ffmpeg

Les articles publiés sur le site

  • ffmpeg python error when adding subtitles

    13 mai, par Clara Ogalla

    When I run it I think there is an error with the subtitle path, but I can't solve it.

    The error in terminal:

    [Parsed_subtitles_0 @ 0000019bcc509780] Unable to parse option value "UsersclaraDocumentsProyectosSubtitulossubtitulosDoctor Who - 1x05 The Keys Of Marinus - Part 6 The Keys Of Marinus_track4_spa.srt" as image size Error applying option 'original_size' to filter 'subtitles': Invalid argument [vost#0:0/libx264 @ 0000019bce220480] Error initializing a simple filtergraph Error opening output file C:\Users\clara\Documents\Proyectos\Subtitulos\videos_con_subtitulos\Doctor Who - 01x05f - The Keys of Marinus (The Keys of Marinus).mkv. Error opening output files: Invalid argument

    My code:

    import os
    from fuzzywuzzy import fuzz
    import ffmpeg
    
    for video_file, (video, subtitle) in video_subtitle_mapping.items():
        print(f"Video: {video_file}, Subtitle: {subtitle}")
    
        folder_path = r"C:\Users\clara\Documents\Proyectos\Subtitulos\subtitulos"
        subtitulo_file = os.path.join(folder_path, subtitle)
    
        folder_path = r"C:\Users\clara\Documents\Proyectos\Subtitulos\videos"
        video_path = os.path.join(folder_path, video_file)
    
        folder_path = r"C:\Users\clara\Documents\Proyectos\Subtitulos\videos_con_subtitulos"
        output_video_file = os.path.join(folder_path, video_file)  # Output video file should have the same name as the input video
    
        try:
            ffmpeg.input(video_path).output(output_video_file, vf=f"subtitles='{subtitulo_file}'").run()
        except ffmpeg.Error as e:
            print(f"Error processing video {video_file}: {e.stderr}")
    

    Add subtitles to MKVs

  • sending video issue whatsapp-web.js

    13 mai, par Shahar

    I'm trying to send an mp4 video as a sticker but i get an error, here's my code

    client.on("message", (message) => {
        const media = MessageMedia.fromFilePath("./vid.mp4");
        client.sendMessage(message.from, media, { sendMediaAsSticker: true });
    }
    

    but I get this error

    handleExit(new Error('ffmpeg exited with code ' + code));
                         ^
    
    Error: ffmpeg exited with code 1: pipe:0: Invalid data found when processing input
    Cannot determine format of input stream 0:0 after EOF
    Error marking filters as finished
    Conversion failed!
    

    its working with other mp4 files but with this one it doesnt, this is a good working mp4 file I generated with ffmpeg using the concat method.

  • Flutter : How to use "ffmpeg_kit_flutter" to merge videos ?

    13 mai, par Hani Kanakri

    i am using "ffmpeg_kit_flutter" to merge two videos with code

    
    import 'dart:io';
    
    import 'package:ffmpeg_kit_flutter/ffmpeg_kit.dart';
    import 'package:ffmpeg_kit_flutter/abstract_session.dart';
    import 'package:ffmpeg_kit_flutter/return_code.dart';
    import 'package:flutter/material.dart';
    import 'package:flutter_bloc/flutter_bloc.dart';
    import 'package:wechat_assets_picker/wechat_assets_picker.dart';
    
    import '/features/merge_videos/cubit/merge_videos_state.dart';
    
    class MergeVideosCubit extends Cubit {
      MergeVideosCubit(this.originalFile) : super(InitialMergeVideos());
      final File? originalFile;
    
      Future selectVideo(BuildContext context) async {
        final List? videos = await AssetPicker.pickAssets(
          context,
          pickerConfig: const AssetPickerConfig(requestType: RequestType.video),
        );
    
        if (videos != null && videos.isNotEmpty) {
          for (AssetEntity asset in videos) {
            File? videoFile = await asset.file;
            if (videoFile != null) {
              print('Selected Asset Path: ${videoFile.path}');
              mergeVideos(originalFile!.path, videoFile.path);
            }
          }
        }
      }
    
      Future mergeVideos(String inputPath1, String inputPath2) async {
        final String outputPath = "/storage/emulated/0/merged_video_${now()}.mp4";
        // final String command =
        //     '-i $inputPath1 -i $inputPath2 -filter_complex "[0:v][0:a][1:v][1:a] concat=n=2:v=1:a=1[outv][outa]" -map "[outv]" -map "[outa]" -y $outputPath';
        final String command =
            '-i $inputPath1 -i $inputPath2 -filter_complex "[0:v][1:v]concat=n=2:v=1:a=0[outv]" -map "[outv]" -y $outputPath';
        print("FFmpeg process starting with command: $command");
        print(command);
        print("LOADING LOADING LOADING LOADING LOADING LOADING LOADING MERGE");
        emit(LoadMergeVideos());
        await FFmpegKit.execute(command).then((value) async {
          await value.getDuration();
          var id = await value.getSessionId();
    
          print(value);
          print(id);
          print(await value.getDuration());
        });
        await FFmpegKit.executeAsync(command, (session) async {
          final returnCode = await session.getReturnCode();
          await session.getSessionId();
          print(await session.getSessionId());
    
          if (ReturnCode.isSuccess(returnCode)) {
            print("SUCCESS: Video merged successfully at $outputPath");
            print("SUCCESS SUCCESS SUCCESS SUCCESS SUCCESS SUCCESS MERGE");
            emit(SuccessMergeVideos());
    
          } else if (ReturnCode.isCancel(returnCode)) {
            print("CANCELLED: Video merging was cancelled.");
            print("CANCEL CANCEL CANCEL CANCEL CANCEL CANCEL CANCEL MERGE");
            emit(CancelMergeVideos());
    
          } else {
            print("ERROR: Failed to merge videos.");
            print("ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR MERGE");
            emit(ErrorMergeVideos());
    
            final failLog = await session.getFailStackTrace();
    
            print("FFmpeg Failure Log: $failLog");
          }
        });
      }
    
      String now() {
        final DateTime now = DateTime.now();
        return "${now.year}${now.month}${now.day}_${now.hour}${now.minute}${now.second}";
      }
    }
    

    The console when i run the code

    
    D/EGL_emulation(23858): app_time_stats: avg=2379.66ms min=5.87ms max=23160.09ms count=10
    I/PhotoManager(23858): uri: content://media/external/file
    I/PhotoManager(23858): projection: _display_name, _data, _id, title, bucket_id, bucket_display_name, width, height, orientation, date_added, date_modified, mime_type, datetaken, duration, media_type, relative_path
    I/PhotoManager(23858): selection: _id = ?
    I/PhotoManager(23858): selectionArgs: 1000000039
    I/PhotoManager(23858): sortOrder: null
    I/PhotoManager(23858): sql: _id = 1000000039
    I/PhotoManager(23858): cursor count: 1
    I/flutter (23858): Selected Asset Path: /storage/emulated/0/Movies/VID_20240512_115116.mp4
    I/flutter (23858): FFmpeg process starting with command: -i /storage/emulated/0/Movies/VID_20240512_115128.mp4 -i /storage/emulated/0/Movies/VID_20240512_115116.mp4 -filter_complex "[0:v][1:v]concat=n=2:v=1:a=0[outv]" -map "[outv]" -y /storage/emulated/0/merged_video_2024513_122719.mp4
    I/flutter (23858): -i /storage/emulated/0/Movies/VID_20240512_115128.mp4 -i /storage/emulated/0/Movies/VID_20240512_115116.mp4 -filter_complex "[0:v][1:v]concat=n=2:v=1:a=0[outv]" -map "[outv]" -y /storage/emulated/0/merged_video_2024513_122719.mp4
    I/flutter (23858): LOADING LOADING LOADING LOADING LOADING LOADING LOADING MERGE
    I/flutter (23858): Instance of 'FFmpegSession'
    I/flutter (23858): 1
    I/flutter (23858): 246
    I/flutter (23858): 2
    I/flutter (23858): ERROR: Failed to merge videos.
    I/flutter (23858): ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR MERGE
    D/EGL_emulation(23858): app_time_stats: avg=87.27ms min=4.92ms max=319.92ms count=13
    I/flutter (23858): FFmpeg Failure Log: null
    

    In "mergeVideos" function the "returnCode" it return value "1" when i look in the package code

    getState() async {
        try {
          return _platform
              .abstractSessionGetState(this.getSessionId())
              .then((state) {
            switch (state) {
              case 0:
                return SessionState.created;
              case 1:
                return SessionState.running;
              case 2:
                return SessionState.failed;
              case 3:
              default:
                return SessionState.completed;
            }
          });
        } on PlatformException catch (e, stack) {
          print("Plugin getState error: ${e.message}");
          return Future.error("getState failed.", stack);
        }
    }
    

    Which mean its keep running but in my code it does not wait until complete merging

    how can i fix that??!

    but i think my problem is in command(concat)

    
    -i /storage/emulated/0/Movies/VID_20240512_115128.mp4 -i /storage/emulated/0/Movies/VID_20240512_115116.mp4 -filter_complex "[0:v][1:v]concat=n=2:v=1:a=0[outv]" -map "[outv]" -y /storage/emulated/0/merged_video_2024513_122719.mp4
    

    (This is my command when i run the code)??

  • "fixing" RTL texts from logical to visual, before embedding in video as subtitles with ffmpeg

    13 mai, par Berry Tsakala

    I'm searching for the correct way to pre-process my subtitles files before hard-coding them into video clips.

    Currently, ffmpeg does not process RTL (right-to-left) languges properly; I have detailed the problem here: https://superuser.com/questions/1679536/how-to-embed-rtl-subtitles-in-a-video-hebrew-arabic-with-the-correct-lan

    However, there could be 2 programmatic solutions:

    1. adding certain unicode control characters can fix (or partially fix) the text, which is then fed into ffmpeg, giving good results.
    • character 0x200F at the end of a hebrew clause, after punctuation
    • character 0x202B, I haven't yet learned its usage.
    1. I can edit the text so that it will produce the correct results on ffmpeg. But that requires smart BiDi algorithm.

    Do you know how to preprocess such text?

    (this is NOT an encoding question. It is about RTL/LTR algorithm to use.)

    Thank you

  • How do I add environment variables to path in python ?

    13 mai, par JustThisWeeb

    I made a python script to install FFmpeg and add it to path in Windows, but it seemed to have no effect at all. It doesn't give me any errors or anything. It literally just does nothing at all.

    This was the code I used:

    os.environ["Path"] += f"{os.getcwd()}/ffmpeg-7.0-essentials_build/bin"
    os.environ.update()
    

    and I tried several iterations of "path" including "PATH", "Path", "path" and none of them made a difference. I also tried making a new variable:

    new_environ = os.environ["Path"] + f"{os.getcwd()}/ffmpeg-7.0-essentials_build/bin"
    os.environ["Path"] = new_environ
    os.environ.update()
    

    Which again made no difference.

    I know there are other questions like that, but to be honest none of the ones I saw were helpful.