Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • ffmpeg overlay endless concat list loop layer on another rtmp & get one merged rtmp link

    8 février 2020, par yolov3

    Question is : how to feed ffmpeg1 output as overlay endless loop layer on another rtmp & get one merged rtmp link in output , all in one ffmpeg command ?

    base knowledge :

    test.txt :

    file 'video1.mp4'
    file 'video2.mp4'
    file 'video3.mp4'
    file 'test.txt'
    

    ffmpeg1 command: ffmpeg -re -f concat -i ./test.txt -c copy -f flv rtmp://....

    Overlay two live streams with ffmpeg:

       -filter_complex "overlay=70:70"
       -vcodec libx264 -preset ultrafast -f flv rtmp://out.com:1935/outrtmp
    
  • video overlay on another video with rounded corner, transparency, opacity, scaling, and border all together with FFMPEG in PHP

    8 février 2020, par Avan Shrivastava

    I am trying to change a video with Rotation, rounded corner, transparent, scaling, and border all with together and overlay on a video; I am trying to do this with FFMPEG in PHP but getting issue in transparent background; I am getting green background please help;

    ffmpeg -i empt_vid_5891581054410.mp4 -i merged-571580302534.mp4 -filter_complex "[1:v] rotate=- 30*PI/180:ow=rotw(iw):oh=roth(ih):c=none [rotate];[0:v][rotate] overlay=40:10:enable='between(t,2,7)', colorchannelmixer=aa=0.5" -auto-alt-ref 0 -pix_fmt yuv420p -c:a copy overlayavatar.mp4

  • Multiple RTSPs receive method

    8 février 2020, par CDY

    I am trying to code a project which I have at least 20 rtsp CCTV URL going to access at same time.

    I tried to use ffmpeg to reach out my goal via multiple input method. However, there is a problem.

    ffmpeg -i URL_1 -i URL_2 -
    

    The command above is the example I tried. I wish that I can access two rtsps via ffmpeg and output them into two different queues for the future use. If I use this command and read bytes after that, I can not distinguish which bytes belongs to which input rtsp.

    Is there any other way which I can access more rtsp at same time?

    Edit: Adding Code

    import ffmpeg
    import numpy as np
    import subprocess as sp
    import threading
    import queue
    import time
    class CCTVReader(threading.Thread):
        def __init__(self, q, in_stream, name):
            super().__init__()
            self.name = name
            self.q = q
            self.command = ["ffmpeg",
                            "-c:v", "h264",     # Tell ffmpeg that input stream codec is h264
                            "-i", in_stream,    # Read stream from file vid.264
                            "-c:v", "copy",     # Tell ffmpeg to copy the video stream as is (without decding and encoding)
                            "-an", "-sn",       # No audio an no subtites
                            "-f", "h264",       # Define pipe format to be h264
                            "-"]                # Output is a pipe
    
        def run(self):
            pipe = sp.Popen(self.command, stdout=sp.PIPE, bufsize=1024**3)  # Don't use shell=True (you don't need to execute the command through the shell).
    
            # while True:
            for i in range(1024*10):  # Read up to 100KBytes for testing
                data = pipe.stdout.read(1024)  # Read data from pip in chunks of 1024 bytes
                self.q.put(data)
    
                # Break loop if less than 1024 bytes read (not going to work with CCTV, but works with input file)
                if len(data) < 1024:
                    break
    
            try:
                pipe.wait(timeout=1)  # Wait for subprocess to finish (with timeout of 1 second).
            except sp.TimeoutExpired:
                pipe.kill()           # Kill subprocess in case of a timeout (there should be a timeout because input stream still lives).
    
            if self.q.empty():
                print("There is a problem (queue is empty)!!!")
            else:
                # Write data from queue to file vid_from_queue.264 (for testingg)
                with open(self.name+".h264", "wb") as queue_save_file:
                    while not self.q.empty():
                        queue_save_file.write(self.q.get())
    
    
    # Build synthetic video, for testing begins:
    ################################################
    # width, height = 1280, 720
    # in_stream = "vid.264"
    # sp.Popen("ffmpeg -y -f lavfi -i testsrc=size=1280x720:duration=5:rate=1 -c:v libx264 -crf 23 -pix_fmt yuv420p " + in_stream).wait()
    ################################################
    
    #Use public RTSP Streaming for testing
    readers = {}
    queues = {}
    dict = {
            "name1":{"ip":"rtsp://xxx.xxx.xxx.xxx/"},
            "name2":{"ip":"rtsp://xxx.xxx.xxx.xxx/"},
            "name3":{"ip":"rtsp://xxx.xxx.xxx.xxx/"},
            "name4":{"ip":"rtsp://xxx.xxx.xxx.xxx/"},
            "name5":{"ip":"rtsp://xxx.xxx.xxx.xxx/"},
            "name6":{"ip":"rtsp://xxx.xxx.xxx.xxx/"},
            "name7":{"ip":"rtsp://xxx.xxx.xxx.xxx/"},
            "name8":{"ip":"rtsp://xxx.xxx.xxx.xxx/",
            "name9":{"ip":"rtsp://xxx.xxx.xxx.xxx/"},
            "name10":{"ip":"rtsp://xxx.xxx.xxx.xxx/"},
            "name11":{"ip":"rtsp://xxx.xxx.xxx.xxx/"},
            "name12":{"ip":"rtsp://xxx.xxx.xxx.xxx/"},
            "name13":{"ip":"rtsp://xxx.xxx.xxx.xxx/"},
            "name14":{"ip":"rtsp://xxx.xxx.xxx.xxx/"},
            "name15":{"ip":"rtsp://xxx.xxx.xxx.xxx/"},
            }
    
    for key in dict:
        ip = dict[key]["ip"]
        name = key
        q = queue.Queue()
        queues[name] = q
        cctv_reader = CCTVReader(q, ip, name)
        readers[name] = cctv_reader
        cctv_reader.start()
        cctv_reader.join()
    
  • FFMPEG Generate video clips and concatenate them all

    8 février 2020, par lms702

    I have a bunch of images (.png) and audio files (.wav) that I want to combine and concatenate. For example, if I have a1.wav, i1.png, a2.wav, and i2.png, I want to output a video that is a1.wav overlayed onto i1.png, then (concatenated to a2.wav overlayed onto i2.png.

    Currently, my approach is to save each individual clip and then concatenate them all at the end.

    To save each clip, I use this command (in a loop for all of my clips):

    ffmpeg -i {imageFile} -i {audioFile} -nostdin -qscale:v 1 -vcodec libx264 -pix_fmt yuv420p {outputFile.mp4}``
    

    It outputs an mp4 that kind of works - the playback is really buggy but works in full screen.

    My current approach to concatenating has not been at all successful. I create a list of the clip names and put it into {filename} then call this command:

    ffmpeg -f concat -i {filename} -c copy clips/finalOutput.mp4
    

    This outputs a pretty jumbled video and this error repeated:

    [mp4 @ 000001cdec110740] Non-monotonous DTS in output stream 0:1; previous: 1045041, current: 604571; changing to 1045042. This may result in incorrect timestamps in the output file.
    

    So, a few questions.

    What is the best way to go about this process?

    Should I be saving each clip or is there a better way to do it all in one command?

    If I do save each clip, is there a better file format I should use?

    Plz help with the concatenation command.

    Also note that because I am automating this with python I can build arbitrarily large commands, though that might not be ideal.

    I am very new to this and I would really appreciate any help!

  • ffmpeg : Audio input device not recognized

    8 février 2020, par shrimpwidget

    What is needed for my ffmpeg command to recognize my audio input device?

    The following reference has not helped resolve my problem: enter link description here

    I want to record me talking (to my Windows laptop) while my screen activity is captured. While I have succeeded in capturing what's on the screen (by removing all mention of audio from my command), I have been unable to capture audio, as the device I mention is not recognized by ffmpeg. (I routinely use the default laptop for audio input to Audacity...surely there's some way to use it in this ffmpeg command, too.)

    My audio devices:

    ffmpeg -list_devices true -f dshow -i dummy
    
        [dshow @ 000000000044a940] DirectShow audio devices
        [dshow @ 000000000044a940]  "Microphone Array (IDT High Defi"
        [dshow @ 000000000044a940]     Alternative name "@device_cm_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\Microphone Array (IDT High Defi"
        [dshow @ 000000000044a940]  "Dock Mic (IDT High Definition A"
        [dshow @ 000000000044a940]     Alternative name "@device_cm_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\Dock Mic (IDT High Definition A"
        [dshow @ 000000000044a940]  "Jack Mic (IDT High Definition A"
        [dshow @ 000000000044a940]     Alternative name "@device_cm_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\Jack Mic (IDT High Definition A"
        [dshow @ 000000000044a940]  "Rec. Playback (IDT High Definit"
        [dshow @ 000000000044a940]     Alternative name "@device_cm_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\Rec. Playback (IDT High Definit"
    

    The full name is found via regedit: Microphone Array (IDT High Definition Audio CODEC)

    Why isn't the audio input device found?

    ffmpeg -y -f gdigrab -i desktop -framerate 10 -f dshow -i audio="Microphone Array (IDT High Definition Audio CODEC)" -vcodec libx264 "C:\jed\ffmpeg\_mydata\clip.mp4"
    
        [gdigrab @ 0000000000498540] Capturing whole desktop as 1366x768x32 at (0,0)
        [gdigrab @ 0000000000498540] Stream #0: not enough frames to estimate rate; consider increasing probesize
        Input #0, gdigrab, from 'desktop':
          Duration: N/A, start: 1575576239.093815, bitrate: 1006131 kb/s
            Stream #0:0: Video: bmp, bgra, 1366x768, 1006131 kb/s, 29.97 fps, 1000k tbr, 1000k tbn, 1000k tbc
        [dshow @ 000000000049a5e0] Could not find audio only device with name [Microphone Array (IDT High Definition Audio CODEC)] among source devices of type audio.
        [dshow @ 000000000049a5e0] Searching for audio device within video devices for Microphone Array (IDT High Definition Audio CODEC)
        [dshow @ 000000000049a5e0] Could not find audio only device with name [Microphone Array (IDT High Definition Audio CODEC)] among source devices of type video.
        audio=Microphone Array (IDT High Definition Audio CODEC): I/O error