Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • Is it possible to add an outline in a chroma-key video ? [closed]

    20 juillet, par Mouaad Abdelghafour AITALI

    Is it possible with FFmpeg to add an outline to a chroma-keyed video? My goal is to blend a background video with a foreground video, where the foreground has a white outline:

    enter image description here

    enter image description here

    My code blends the background and foreground videos by removing the chroma key and replacing it with the background. I want to keep this functionality but add a white outline around the foreground video.

    public static String overlayVideo(String backgroundCroppedPath,
                                      String foregroundVideoPath,
                                      String overlayedVideoPath,
                                      double fgDurationSec,
                                      OutputAudioSource audioSource) {
    
        // Format duration to 2 decimal places
        String duration = String.format(Locale.US, "%.2f", fgDurationSec);
    
        String bgInput = "-stream_loop -1 -i \"" + backgroundCroppedPath + "\"";
        String fgInput = "-i \"" + foregroundVideoPath + "\"";
    
        String filterComplex =
                "[0:v]trim=duration=" + duration + ",setpts=PTS-STARTPTS[bg];" +
                        "[1:v]colorkey=0x01fe01:0.3:0.2,setpts=PTS-STARTPTS[fg];" +
                        "[bg][fg]overlay=format=auto[outv]";
    
        String audioMap = (audioSource == OutputAudioSource.FOREGROUND)
                ? "-map [outv] -map 1:a?"
                : "-map [outv] -map 0:a?";
    
        return "-y " + bgInput + " " + fgInput +
                " -filter_complex \"" + filterComplex + "\" " +
                audioMap + " " +
                "-t " + duration + " " +
                "-c:v libx264 -crf 18 -preset ultrafast -pix_fmt yuv420p " +
                "\"" + overlayedVideoPath + "\"";
    }
    
  • Configure and Build OpenCV to Custom FFMPEG Install

    20 juillet, par enderland

    I cannot seem to configure OpenCV to link to a non-/usr/lib set of FFMPEG libraries.

    My LD_LIBRARY_PATH contains a direct link to the folder for the custom install of FFMPEG:

    LD_LIBRARY_PATH=/pathto/ffmpeg-0.10.2/lib

    Additionally, I've configured pkgconfig as:

    PKG_CONFIG_PATH=/samepathto/ffmpeg-0.10.2/lib/pkgconfig/

    Within CMake however I cannot find any setting for path to FFMPEG - either in basic or custom. The only setting related to FFMPEG appears to be WITH_FFMPEG type setting (set to ON).

    I can build OpenCV but it seems to link to the system libraries for libavcodec - this causes a conflict as the system libraries are version .52 and the version in my install of FFMPEG are .53. Linking an app on a machine without the same system libraries seems to NOT link to my custom install of OpenCV (specifically the libavcodec) because of this (I'm installing these libraries on a shared network folder).

    I am not sure if my problem is with building and linking to the wrong version of FFMPEG or if it is something with my environment after building (and then linking to the wrong ffmpeg).

    I am building on Linux, Redhat 6, OpenCV 2.3.1.

  • x265 encrypts video with fps=25 instead of 24 [closed]

    19 juillet, par Peter Irich

    When I had AMD FX-8350 and Ryzen 5 3600 and used x264, I can recode mkv-files to size decreasing succesfully.

    1st, I got all audio-tracks and transformed its to ac3.

    2nd, I decoded video-track to *.y4m by command

    /usr/bin/ffmpeg -i name.mkv -an -sn -map 0 -fps_mode vfr
    -f yuv4mpegpipe name.y4m > name_y4m.err 2>&1

    3rd, I again encrypt video from *.y4m by command

    /usr/bin/x264 --log-level warning --input-res ${nw}x${nh}
    --preset veryslow -o cmpr_v.mkv name.y4m > cmpr_v.err 2>& 1

    and then merged audio-track and cmpr_v.mkv. It worked right.

    When I going to x265 and AMD Ryzen 7500F, x265 in p.3 becames code video with fps=25 instead of 24,000. I tried change some options, but not succesfully. What is the reason of hte this behavior and how achieve the right coding?

  • Is it possible to add an outline/border/edge to a person in a chroma-key video ? [closed]

    19 juillet, par Mouaad Abdelghafour AITALI

    I hope you're doing well. Is it possible to use FFmpeg to add an outline to a chroma-keyed video, like in the images below? My goal is to blend a background video with a foreground video, where the foreground has a white outline.

    enter image description here

    enter image description here

    Here’s my current code that blends the background and foreground videos by removing the chroma key and replacing it with the background. I want to keep this functionality but add a white outline effect around the foreground video.

    Thank you so much in advance for your help.

    public static String overlayVideo(String backgroundCroppedPath,
                                      String foregroundVideoPath,
                                      String overlayedVideoPath,
                                      double fgDurationSec,
                                      OutputAudioSource audioSource) {
    
        // Format duration to 2 decimal places
        String duration = String.format(Locale.US, "%.2f", fgDurationSec);
    
        String bgInput = "-stream_loop -1 -i \"" + backgroundCroppedPath + "\"";
        String fgInput = "-i \"" + foregroundVideoPath + "\"";
    
        String filterComplex =
                "[0:v]trim=duration=" + duration + ",setpts=PTS-STARTPTS[bg];" +
                        "[1:v]colorkey=0x01fe01:0.3:0.2,setpts=PTS-STARTPTS[fg];" +
                        "[bg][fg]overlay=format=auto[outv]";
    
        String audioMap = (audioSource == OutputAudioSource.FOREGROUND)
                ? "-map [outv] -map 1:a?"
                : "-map [outv] -map 0:a?";
    
    
        return "-y " + bgInput + " " + fgInput +
                " -filter_complex \"" + filterComplex + "\" " +
                audioMap + " " +
                "-t " + duration + " " +
                "-c:v libx264 -crf 18 -preset ultrafast -pix_fmt yuv420p " +
                "\"" + overlayedVideoPath + "\"";}
    
  • How do I get duration of an In Memory Video in Python / Django ?

    19 juillet, par Lucas Tonon

    So I was successfully using the following code to get the duration of a saved video in Django.

    def get_video_length(file_path):
    command = [
        'ffprobe',
        '-v',
        'error',
        '-show_entries',
        'format=duration',
        '-of',
        'default=noprint_wrappers=1:nokey=1',
        file_path
      ]
    
    try:
        output = check_output( command, stderr=STDOUT ).decode()
    except CalledProcessError as e:
        output = e.output.decode()
    
    return output
    

    But now I need to get the duration of an uploaded file before saving it. I have a serializer with a FileField and on validate method I should check the video duration. For instance:

    class VideoSerializer(serializers.Serializer):
    video = serializers.FileField(required=True, validators=[validate_media_extension, validate_video_duration])
    

    Then on validate_video_duration I needed to call some method like get_video_length, but I need an alternative to get the duration from the video in memory. The object that I have is an instance of InMemoryUploadedFile (https://docs.djangoproject.com/en/2.2/_modules/django/core/files/uploadedfile/)