Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • Is it possible to embed ffplay ?

    18 mars, par EthanL

    ffmpeg's viewer, ffplay, has a lot of great options for optimizing viewing experience. I've been able to get it to nicely display an RTSP stream at low latency. However, it's been difficult to include it in a GUI.

    Is that possible? Is there a GUI that does that?

    Note: I am NOT trying to embed in a browser, or just toss the window on top of a GUI.

    Best solution: desktop GUI that includes ffplay in a widget

    First alternative: desktop GUI that has variable opacity. If the ffplay window is layered below the GUI, and the GUI is transparent, it could look decent. However, some buttons would have to be visible, so the entire window can't be transparent.

    Second alternative: disable the possibility of user interaction with the ffplay window. Then, the ffplay window could just be tossed to the side of the screen, and it would remain there as a split screen, without concern that a user could minimize it or move it.

  • How to have a clean transition when concat MTS files using ffmpeg ?

    18 mars, par pho

    I have been struggling for a while and I hope someone can help me. What I want to do: 1- seek MTS files 2- conact them without re-encoding them

    How I do that: I write a file concatList.txt

    file 'file1.MTS'
    file 'file1_cut.MTS'
    

    I execute

    ffmpeg -y -i file1.MTS -ss 11.5 -c copy -copyts file1_cut.MTS
    ffmpeg -y -f concat -i concatList.txt -c copy output.MTS
    

    (11.5s corresponds to an I-frame)

    The transition between the two videos in output.MTS is very buggy during more than 1s

    To dig in, I tried to analyse the streams but it rises many questions:

    ffprobe -select_streams v -show_entries frame=pict_type,pts_time,pic_type,pts -skip_frame nokey -of compact -i file1.MTS
    
    pts;pts_time;pict_type
    147600;1.640000;I
    100800;1.120000;I
    1083600;12.040000;I
    1036800;11.520000;I ==> I cut the file here
    2019600;22.440000;I
    1972800;21.920000;I
    2955600;32.840000;I
    2908800;32.320000;I
    

    ==> Why not all I-frames are found by the -skip_frame nokey option ?

    ffmpeg -y -i file1_cut.MTS -map v:0 -c copy -copyts -f framemd5 file1_cut.md5
    

    combined with the following command output

    ffprobe -select_streams v -show_entries frame=pict_type,pts_time,pic_type,pts -of compact -i file1_cut.MTS
    
    stream;dts;diff_dts;pts;duration;size;hash;pts_time;pict_type
    0;163800;0;174600;1800;197323;7e228dfab2cb38922cab06844d67bf8c;1.94;I ==> This is the correct I-frame
    0;165600;1800;176400;1800;28860;80ef4505813b99bb4484c969f589fa35;;
    0;167400;1800;167400;1800;30289;d172722d01631a13caed81fc6be5b828;; ==> Why no frame type found by ffprobe ??
    0;169200;1800;169200;1800;23338;e22eb396408abbf66bd6ef4f8893d102;;
    0;171000;1800;171000;1800;24414;1a4f128017e8fc239b6c728f0c6d45b2;; ==> Why no frame type found by ffprobe ??
    0;172800;1800;172800;1800;28872;acd07b2f3ccbddd072c380bee709a2dc;;
    0;174600;1800;181800;1800;42872;eb225b253ebd427f2af01c2861d684c7;2.02;P
    0;176400;1800;183600;1800;35942;58a238b781b1bfe720aa6de61830e3b1;;
    0;178200;1800;178200;1800;22080;c6b43fbf1083d40499d908f0f02bd3dd;1.98;B
    0;180000;1800;180000;1800;24896;4481d088ad425da908daa83220111fd2;;
    0;181800;1800;189000;1800;40733;1294f59fe24d17aa8ca34fc327631d80;2.1;P
    0;183600;1800;190800;1800;37904;095f7be43c90e97d66fb8427a17cb4c3;;
    0;185400;1800;185400;1800;25808;a9d4e63c7607fcf9cd491084cce556ba;2.06;B
    0;187200;1800;187200;1800;24874;834117a8d7e106a2278c412ec0acd1df;;
    
    ffmpeg -y -i output.MTS -map v:0 -c copy -copyts -f framemd5 output.md5
    

    combined with the following command output

    ffprobe -select_streams v -show_entries frame=pict_type,pts_time,pic_type,pts -of compact -i output.MTS
    
    stream;dts;diff_dts;pts;duration;size;hash;pts_time;pict_type
    0;3106800;1800;3114000;1800;45853;7d5c2b6c9f4e1da8f93782b1de7de3a7;34.6;P;
    0;3108600;1800;3115800;1800;43213;b07554ad625850e3a4b8de54be6af1dd;;;
    0;3110400;1800;3110400;1800;25764;85c4aa6e62db831617a13bf5e6e08dda;34.56;B;
    0;3112200;1800;3112200;1800;24328;2e6bac4090917f2bc6ccedc8841612c5;;;
    0;3114000;1800;3121200;1800;46802;dfac0337af77c1a895e900048fc757c5;34.68;P; ==> Why pts larger than pts of first file1_cut.MTS frames ??
    0;3115800;1800;3123000;1800;41795;b33af7f2e6ca04c3179ef52c37df4fe5;;;
    0;3117600;1800;3117600;1800;23488;41a48cd53a2400d9331766ce3565c55c;34.64;B;
    0;3119400;1800;3119400;1800;23222;cc85ec074b62a0c51ac8e4e1196db079;;; ==> Last frame of file1.MTS
    0;3162240;42840;3173040;1800;197323;7e228dfab2cb38922cab06844d67bf8c;;; ==> First frame of file1_cut.MTS, ==> Why a lag of 42840 (0.4s) between two successive dts ??
    0;3164040;1800;3174840;1800;28860;80ef4505813b99bb4484c969f589fa35;;;
    0;3165840;1800;3165840;1800;30289;d172722d01631a13caed81fc6be5b828;;; ==> Why all these frames are not detected by ffprobe ??
    0;3167640;1800;3167640;1800;23338;e22eb396408abbf66bd6ef4f8893d102;;;
    0;3169440;1800;3169440;1800;24414;1a4f128017e8fc239b6c728f0c6d45b2;;;
    0;3171240;1800;3171240;1800;28872;acd07b2f3ccbddd072c380bee709a2dc;;;
    0;3173040;1800;3180240;1800;42872;eb225b253ebd427f2af01c2861d684c7;;;
    0;3174840;1800;3182040;1800;35942;58a238b781b1bfe720aa6de61830e3b1;;;
    0;3176640;1800;3176640;1800;22080;c6b43fbf1083d40499d908f0f02bd3dd;;;
    0;3178440;1800;3178440;1800;24896;4481d088ad425da908daa83220111fd2;;;
    0;3180240;1800;3187440;1800;40733;1294f59fe24d17aa8ca34fc327631d80;35.416;P;
    0;3182040;1800;3189240;1800;37904;095f7be43c90e97d66fb8427a17cb4c3;;;
    0;3183840;1800;3183840;1800;25808;a9d4e63c7607fcf9cd491084cce556ba;;; ==> Why ffprobe did not recognize the B-frame ??
    0;3185640;1800;3185640;1800;24874;834117a8d7e106a2278c412ec0acd1df;;;
    0;3187440;1800;3194640;1800;42645;13e6b4afb26734f0515303a5332dec32;35.496;P;
    0;3189240;1800;3196440;1800;39393;cfd5bdc15737562fc40ac4527057a034;;;
    0;3191040;1800;3191040;1800;25822;01b0d03c710f526c805c7aeaa54a39fb;35.456;B;
    0;3192840;1800;3192840;1800;25089;8306d0ab9a0cbaf16283b2019337973e;;;
    0;3194640;1800;3201840;1800;44593;1efb42bf015bbd71a54de2999ece272b;35.576;P;
    0;3196440;1800;3203640;1800;40391;e6ff5568c1b019250ecd9d3568a7e7b5;;;
    0;3198240;1800;3198240;1800;25354;c047b70a8a0725c4d60db8c92ea99706;35.536;B;
    

    So here is my main question: is there a "smart" concat command that cuts the frames of the first file that will never display (pts larger that the first frames of the second file), that anticipates the dts of I-frames of the second files, and that reduces the lag of dts to get a continuous stream?

    Thank you if anyone can answer.

  • Ffmpeg to duplicate an audio stream and encode this new stream

    18 mars, par sion

    I have some video files that I need to re-encode due to compatibility issues. They are currently mkv files with h.264 video and ac3-a52 audio. I want to keep the h.264 video, convert the container to m4v and create two audio tracks, one with the original ac3-a52 and one copied from that but in aac stereo.

    I assume there has to be some sort of audio stream mapping command but I don't know how to map and re-encode at the same time. What command should I enter into ffmpeg to achieve this?

    Also, what is the difference between ac3 and ac3-a52? Will an apple TV still be able to pass through ac3-a52 or does that have to be converted to ac3?

  • How to load file in ffmpeg in chunks ?

    18 mars, par developer1

    I'm having a problem when loading a larger file with ffmpeg in safari mobile, it crashes while doing that.

    Currently I'm loading the whole file at once await ffmpeg.writeFile(inputFileName, await fetchFile(file)); and to my understanding safari tries to load it in-memory in one go and fails.

    How can I work around this issue? Maybe split the file to chunks? Maybe streaming?

    Thank you.

  • Decoding the h.264 stream from a serial port

    18 mars, par Peter

    I would like to know if there is a reliable way to decode an H.264 NAL stream coming through a serial port using software.

    So far, I have managed to decode a single frame using a python script. In this script, I first write the incoming data to a file, and when the end-of-frame marker 00_00_00_01 appears, I display the frame using ffplay.

    import serial
    import subprocess
    import os
    import time
    
    ser = serial.Serial('COM3', 115200, timeout=1)
    output_file = "output.264"
    
    # Variable to store the ffplay process
    ffplay_process = None
    
    # Open the file for writing in binary mode
    with open(output_file, "wb") as file:
    
        print("Writing bytes to output.264. Waiting for the end-of-frame marker 0x00000001.")
    
        buffer = bytearray()
        marker = b'\x00\x00\x00\x01'
    
        try:
            while True:
                if ser.in_waiting:  # If there is data in the buffer
                    data = ser.read(ser.in_waiting)  # Read all available bytes
                    buffer.extend(data)
    
                    # Check if the end-of-frame marker is in the buffer
                    while marker in buffer:
                        index = buffer.index(marker) + len(marker)  # Position after the marker
                        frame = buffer[:index]  # Extract the frame
                        buffer = buffer[index:]  # Keep the remaining data
    
                        print(f"Frame recorded: {len(frame)} bytes")
                        file.write(frame)  # Write the frame to the file
                        file.flush()  # Force writing to disk
    
                        # Close the ffplay window if it is already open
                        if ffplay_process and ffplay_process.poll() is None:
                            ffplay_process.terminate()
                            ffplay_process.wait()  # Wait for the process to terminate
    
                        # Play the recorded frame, reopening the window
                        ffplay_process = subprocess.Popen(["ffplay", "-f", "h264", "-i", output_file])
    
        except KeyboardInterrupt:
            print("\nRecording stopped.")
        finally:
            # Close the serial port and the ffplay process
            ser.close()
    

    However, each time a new end-of-frame marker is detected, the ffplay window closes and reopens to show the next frame. It will flicker when transferring the video. Is there a way to display the frames in the same window for seamless playback when streaming video?

    Or is there a better approach or software that is more suited for this task? I do not know where to start, so I will be glad for any hints.