Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • Python add audio to video using opencv or other library

    21 avril, par olokelo

    I use python cv2 module to join jpg frames into video, but I can't add audio to it. Is it possible to add audio to video in python without ffmpeg?

  • Python add audio to video opencv

    21 avril, par olokelo

    I use python cv2 module to join jpg frames into video, but I can't add audio to it. Is it possible to add audio to video in python without ffmpeg? P.S. Sorry for my poor English

  • How to get duration a video - laravel

    21 avril, par S.M_Emamian

    I want to get the duration of my videos when I upload them. To do this, I upload my videos like this:

    $video = Carbon::now()->timestamp . '_' .
                $request->file('video')->getClientOriginalName();
    
    
            $request->file('video')->move(
                $this->getCorrectPathOnServerAndLocal('/assets/videos/videos'), $video
            );
    

    My movie is uploaded well. now I want to get the duration of this video. I'm using PHP-FFMpeg:

    composer require php-ffmpeg/php-ffmpeg
    

    $ffprobe = FFProbe::create(); //error
            dd("test");
            $duration = $ffprobe
                ->format($this->getCorrectPathOnServerAndLocal('/assets/videos/videos').$video) // extracts file informations
                ->get('duration');
    

    but I got this error:

      (2/2) ExecutableNotFoundException
    
    Unable to load FFProbe
    in FFProbeDriver.php (line 50)
    at FFProbeDriver::create(array(), null)in FFProbe.php (line 207)
    
  • FFmpeg conversion failed with "Subtitle encoding failed" and "canvas_size is too small" [closed]

    21 avril, par Hillol Talukdar

    I'm converting video files using FFmpeg, but the process fails and shows some errors that I don't fully understand the cause of. How can I avoid the error and fix the issue? Below is the command I used and the output I received.

    FFmpeg Command:

    ffmpeg -y -hide_banner -i saf:12.VOB -map 0:3 -c:s:0 dvdsub -map 0:2 -map 0:1 -f mp4 -vcodec copy -map_metadata 0:g -acodec aac -async 1 saf:13.mp4
    

    ErrorMessage:

    Input #0, mpeg, from 'saf:12.VOB':
      Duration: 00:00:21.99, start: 0.280633, bitrate: 7147 kb/s
      Stream #0:0[0x1bf]: Data: dvd_nav_packet
      Stream #0:1[0x1e0]: Video: mpeg2video, yuv420p(tv, top first), 720x480 [SAR 32:27 DAR 16:9], 29.97 fps, 29.97 tbr, 90k tbn
        Side data:
          cpb: bitrate max/min/avg: 7816000/0/0 buffer size: 1835008 vbv_delay: N/A
      Stream #0:2[0xa0]: Audio: pcm_dvd, 48000 Hz, stereo, s16, 1536 kb/s
      Stream #0:3[0x20]: Subtitle: dvd_subtitle
      Stream #0:4[0x21]: Subtitle: dvd_subtitle
    
    Stream mapping:
      Stream #0:3 -> #0:0 (dvd_subtitle (dvdsub) -> dvd_subtitle (dvdsub))
      Stream #0:2 -> #0:1 (pcm_dvd (native) -> aac (native))
      Stream #0:1 -> #0:2 (copy)
    
    Press [q] to stop, [?] for help
    
    Output #0, mp4, to 'saf:13.mp4':
      Metadata:
        encoder         : Lavf60.3.100
      Stream #0:0: Subtitle: dvd_subtitle (mp4s / 0x7334706D), 720x480
        Metadata:
          encoder         : Lavc60.3.100 dvdsub
      Stream #0:1: Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s
        Metadata:
          encoder         : Lavc60.3.100 aac
      Stream #0:2: Video: mpeg2video (mp4v / 0x7634706D), yuv420p(tv, top first), 720x480 [SAR 32:27 DAR 16:9], q=2-31, 29.97 fps, 29.97 tbr, 90k tbn
        Side data:
          cpb: bitrate max/min/avg: 7816000/0/0 buffer size: 1835008 vbv_delay: N/A
    
    frame=   15 fps=0.0 q=-1.0 size=       0kB time=00:00:00.73 bitrate=   0.5kbits/s speed= 212x    
    frame=  577 fps=0.0 q=-1.0 size=    5120kB time=00:00:19.18 bitrate=2186.2kbits/s speed=38.1x    
    
    [dvdsub @ 0xb400006ffb03dde0] canvas_size(0:0) is too small(719:479) for render
    [sost#0:0/dvdsub @ 0xb400006feaec5730] Subtitle encoding failed
    [aac @ 0xb400006ffb02f500] Qavg: 36253.348
    [aac @ 0xb400006ffb02f500] 2 frames left in the queue on closing
    
    Conversion failed!
    
  • ffmpeg video streaming issue

    20 avril, par Personboiii

    I am trying to embed an adb video stream into an html site with flask, and the code I have keeps on returning this same error:

    FFmpeg: [mjpeg @ 0x156631c10] Could not find codec parameters for stream 0 (Video: mjpeg, none(bt470bg/unknown/unknown)): unspecified size
    FFmpeg: Consider increasing the value for the 'analyzeduration' (1000000) and 'probesize' (5000000) options
    FFmpeg: Input #0, mjpeg, from 'pipe:0':
    FFmpeg:   Duration: N/A, bitrate: N/A
    FFmpeg:   Stream #0:0: Video: mjpeg, none(bt470bg/unknown/unknown), 25 fps, 1200k tbr, 1200k tbn
    FFmpeg: Output #0, mpegts, to 'pipe:1':
    FFmpeg: [out#0/mpegts @ 0x156632110] Output file does not contain any stream
    FFmpeg: Error opening output file pipe:1.
    FFmpeg: Error opening output files: Invalid argument
    

    this is my code:

    
    from flask import Flask, Response
    import subprocess
    import json
    import threading
    
    app = Flask(__name__)
    
    with open("data_file.json", "r") as f:
        config_data = json.load(f)
    
    user = config_data["Users"]["Test User 1"]
    
    
    def log_ffmpeg_errors(proc):
        for line in iter(proc.stderr.readline, b''):
            if line:
                print("FFmpeg:", line.decode(), end='')
    
    
    def connect_device(ip, port):
        try:
            # Reconnect if device is offline
            subprocess.run(["adb", "tcpip", str(port)])
            subprocess.run(["adb", "connect", ip])
            # Check if the device is online
            devices = subprocess.check_output(["adb", "devices"]).decode()
            if "offline" in devices:
                raise Exception("Device is offline")
        except Exception as e:
            print(f"Error connecting device: {e}")
    
    
    def generate_video_stream():
        adb_cmd = ["adb", "exec-out", "screenrecord", "--output-format=mjpeg"]  # Use MJPEG output
        ffmpeg_cmd = [
            "ffmpeg",
            "-f", "mjpeg",
            "-analyzeduration", "1000000", 
            "-probesize", "5000000",  
            "-i", "pipe:0", 
            "-q:v", "5",
            "-r", "10",
            "-vcodec", "mjpeg",  
            "-s", "1280x720", 
            "-f", "mpegts", 
            "pipe:1" 
        ]
    
        adb_proc = subprocess.Popen(adb_cmd, stdout=subprocess.PIPE)
        ffmpeg_proc = subprocess.Popen(ffmpeg_cmd, stdin=adb_proc.stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    
        threading.Thread(target=log_ffmpeg_errors, args=(ffmpeg_proc,), daemon=True).start()
    
        try:
            while True:
                frame = ffmpeg_proc.stdout.read(4096)
                if not frame:
                    break
                yield (b'--frame\r\n'
                       b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')
    
        finally:
            adb_proc.terminate()
            ffmpeg_proc.terminate()
    
    @app.route('/video_feed')
    def video_feed():
        return Response(generate_video_stream(), mimetype='multipart/x-mixed-replace; boundary=frame')
    
    if __name__ == "__main__":
        connect_device(user["IP"], user["port"])
        app.run(debug=True, host='0.0.0.0', port=8080)
    
    

    I also changed it so that it is adb_cmd = ["adb","exec-out","screenrecord", "-output-format=h264","-"] and the error left but now the site header just keeps on loading and the embed in the html shows nothing. (ngrok for the site page says 200 ok)