Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • How to stream Windows desktop audio as RTSP/HTTP with ffmpeg ?

    3 janvier 2019, par Valya

    I'd love to stream desktop audio so I could listen to it in AIMP Android app. The app understands "http" links and I could successfully stream it with VLC HTTP streaming, however I could not get latency lower than 3 seconds.

    How can I do the same thing with ffmpeg with lowest latency possible?

  • Where to store the .mpd file on django to play on a dash player ?

    3 janvier 2019, par enigmaVada

    I am trying to build a video player on django. I am using MPEG-DASH for adaptive streaming of the video file. I have chosen a sample video in the beginning. Then, using ffmpeg commands, I have encoded the video into 240p, 360p, 480p and 720p videos. Also have encoded audio separately.

    Then, using mp4box, I have generated the .mpd file. I have read that mpd files cannot be run from the local file system and need to be hosted on a server. I have a dash player setup as follows:

    
    
      
        
        
        <script src="https://cdn.dashjs.org/latest/dash.all.min.js"></script>
        
      
      
        

    The url in the src field is a random manifest file that i used to test the player out. It works fine.

    Then, on my django project, I have created a media folder which stores the media files uploaded via a form(root included in settings.py). My question is where do i store the video, audio and .mpd file so that i can play them using the html code which resides in the templates folder. I have tried using the media url of .mpd file in the source but I am unable to play the video.

    Here is the generated mpd file for reference:

    <?xml version="1.0"?>
    
    
     
      
     
    
     
      
       
        
        sample_audio_dashinit.mp4
        
          
        
       
      
      
       
        sample_video_240_dashinit.mp4
        
          
        
       
      
      
       
        sample_video_360_dashinit.mp4
        
          
        
       
       
        sample_video_480_dashinit.mp4
        
          
        
       
      
      
       
        sample_video_720_dashinit.mp4
        
          
        
       
      
     
    
    
  • ffmpeg Add watermark/text in video on react native

    3 janvier 2019, par R F

    Right now i'm stuck on android part,here is my code

    I don't want to define font styling or box it just i found this code somewhere so i just copy pasted it as i don't have any knowledge of ffmpeg, I just want a simple text of right aligned in 2 lines on top of right of the video like this. Expected output

    I am getting the error in this part of code as the video is getting generated but it does not play and it is of always 262B size

     String[] cmd = new String[] {
                "-i", path, "-vf", String.format("drawtext=\"fontfile=/systems/fonts/DroidSans.ttf: text='%s': " + "box=1: boxcolor=black@0.5: boxborder=5: x=(w-text_w)/t: y=(h-text_h)/2\"", text), "-codec:a", "aac", out.getAbsolutePath()
        };
    

    This is the full code

    @ReactMethod
    public void embedTextOnVideo(String text, String path, int fontSize, String fontColor, final Callback successCallback, final Callback errorCallback)
    {
     FFmpeg ffmpeg = FFmpeg.getInstance(_reactContext);
     try
     {
      ffmpeg.loadBinary(new LoadBinaryResponseHandler() {
    
        @Override
        public void onStart() {}
    
        @Override
        public void onFailure() {}
    
        @Override
        public void onSuccess() {}
    
        @Override
        public void onFinish() {}
      });
    } catch (FFmpegNotSupportedException e) {
      // Handle if FFmpeg is not supported by device
    }
    
    File out = getOutputFile(TYPE_VIDEO);
    
    String[] cmd = new String[] {
            "-i", path, "-vf", String.format("drawtext=\"fontfile=/systems/fonts/DroidSans.ttf: text='%s': " + "box=1: boxcolor=black@0.5: boxborder=5: x=(w-text_w)/t: y=(h-text_h)/2\"", text), "-codec:a", "aac", out.getAbsolutePath()
    };
    try {
      ffmpeg.execute(cmd, new ExecuteBinaryResponseHandler() {
    
        @Override
        public void onStart() {}
    
        @Override
        public void onProgress(String message) {}
    
        @Override
        public void onFailure(String message) {
          errorCallback.invoke("Error ffmpeg executing with message:\n\t" + message);
        }
    
        @Override
        public void onSuccess(String message) {
          successCallback.invoke("Successfully output file with message:\n\t");
        }
    
        @Override
        public void onFinish() {}
      });
    } catch (FFmpegCommandAlreadyRunningException e) {
      // Handle if FFmpeg is already running
    }
    }
    
    @Nullable
    private Throwable writeDataToFile(byte[] data, File file) {
    try {
      FileOutputStream fos = new FileOutputStream(file);
      fos.write(data);
      fos.close();
    } catch (FileNotFoundException e) {
      return e;
    } catch (IOException e) {
      return e;
    }
    
    return null;
    }
    @Nullable
    private File getOutputFile(int type) {
    File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM;
    
    // Create storage dir if it does not exist
    if (!storageDir.exists()) {
      if (!storageDir.mkdirs()) {
        Log.e(TAG, "Failed to create directory:" + storageDir.getAbsolutePath());
        return null;
      }
    }
    
    // media file name
    String fileName = String.format("%s", new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()));
    
    
    enter code hereif (type == TYPE_VIDEO) {
      fileName = String.format("VID_%s.mp4", fileName);
    } else {
      Log.e(TAG, "Unsupported media type:" + type);
      return null;
    }
    
    return new File(String.format("%s%s%s", storageDir.getPath(), File.separator, fileName));
    }
    
  • Use ffmpeg to sequentially add multiple audio tracks and pin a specific track to the end

    3 janvier 2019, par kraftydevil

    I have a single video with no audio tracks and want to add several audio tracks sequentially (each track starts immediately after the other).

    The basic case might look something like this:

    |-----------VIDEO-----------VIDEO-------------VIDEO-----------VIDEO-----------|  
    |---FULL AUDIO TRACK 1---|---FULL AUDIO TRACK 2---|---PARTIAL AUDIO TRACK 3---|
    

    Here is my attempt to achieve this:

    ffmpeg -i video.mov -i audio1.mp3 -i audio2.mp3 -i audio3.mp3 -map 0:0 -map 1:0 -map 2:0 -map 3:0 out.mp4
    

    Of course it doesn't produced the desired result. It only uses the first music clip in out.mp4, and no other audio tracks are started when it ends.

    Question 1
    What am I missing in order to add multiple audio tracks sequentially? I assume it's specifying starting and end points of audio clips but I'm coming up short on locating the syntax.

    ...

    In addition, I'm looking for a way to ensure that the video ends with the full duration of AUDIO TRACK 3, as seen below:

    |-----------VIDEO-----------VIDEO-------------VIDEO-----------VIDEO-----------|  
    |---FULL AUDIO TRACK 1---|---PARTIAL AUDIO TRACK 2---|---FULL AUDIO TRACK 3---|
    

    In this case, AUDIO TRACK 2 gets trimmed so that the full AUDIO TRACK 3 is pinned to the end.

    Question 2
    Can this type of audio pinning be done in FFmpeg, or would I have to trim AUDIO TRACK 2 with another program first?

  • ffmpeg watermarking with overlay not working for gif

    2 janvier 2019, par Ariza

    I am using ffmpeg for adding a watermark to my MP4 video.

    With this code :

    ffmpeg -i video.mp4 -i watermark.png -filter_complex "[0][1]overlay=15:H-80" output.mp4

    It does work for adding a png image to video ,

    But when i use it for adding a gif to my video, i do not see any watermark on the output

    Like this :

    ffmpeg -i video.mp4 -i watermark.gif -filter_complex "[0][1]overlay=15:H-80" output.mp4

    Is there anything wrong with my code?


    I just need to add an animated gif to bottom left of my video! that's all i need, if you have better code please share. i'm newbie.