Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • How to encode mp4 so that Apple devices can stream VP9 encoded Videos via fmp4 HLS ? [closed]

    13 mai, par Leon S

    The question is in the title...

    I have not figured it out, obviously Youtube has achieved that, but how could i do it in my own app so that i can effectively stream vp9 encoded content in my app.

    Would be great to get a solution, maybe some ffmpeg settings or something like that? I know that it is officially not supported, but everywhere i look they say that it is still possible, and even "quite easy", e.g. here: https://www.streamingmedia.com/Articles/ReadArticle.aspx?ArticleID=133907

    Trief multiple fmp4 encodings so far for vp9 but neither my app player nor safari play the videos, even though VLC and co do.

  • piping data into an ffmpeg subprocess. Why does write() get stuck ? [closed]

    12 mai, par Tebyy

    It displays the number of frames at the beginning and shows that there are over 300, but when I count all the frames in the loop, the last one I see is 53, and then it only displays the value of 'ret', which is always true. I'm wondering what could be causing this issue of not reading all the frames, resulting in the file not being closed after reading. From what I've read, 'ret' should return false when there are no more frames to read, but because it's not reading all the frames, this isn't happening. Does anyone have any idea what could be causing this?

    Edit: I solved the problem by adding a Thread. Thanks everyone for the help!

    I changed those lines of code:

    recogniteAndPushFramesToFfmpeg("video-979257305707693982.mp4", ffmpeg_process)
    # In function "recogniteAndPushFramesToFfmpeg"
    process.stdin.write(frame)
    

    to these:

    ffmpeg_thread = Thread(target=recogniteAndPushFramesToFfmpeg, args=("video-979257305707693982.mp4", ffmpeg_process))
    ffmpeg_thread.start()
    # In function "recogniteAndPushFramesToFfmpeg"
    process.stdin.write(frame.tobytes())
    

    Code:

    import subprocess
    import cv2
    
    def recogniteAndPushFramesToFfmpeg(video_path, process):
        cap = cv2.VideoCapture(video_path)
        i = 1
        print('Frames:', cap.get(cv2.CAP_PROP_FRAME_COUNT))
        while cap.isOpened():
            ret, frame = cap.read()
            print(ret)
            if not ret:
                break
    
            process.stdin.write(frame)
            process.stdin.flush()
            print('Frame:', i)
            i += 1
    
        cap.release()
        process.stdin.close()
        #process.wait()
        return
        
    
    ffmpeg_command = [
        'ffmpeg', '-f', 'rawvideo', '-s:v', '1920x1080', '-r', '60',
        '-i', '-', '-vf', 'setpts=2.5*PTS',
        '-c:v', 'libvpx-vp9', '-g', '60',
        '-f', 'webm', '-'
    ]
    ffmpeg_process = subprocess.Popen(ffmpeg_command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=-1)
    recogniteAndPushFramesToFfmpeg("video-979257305707693982.mp4", ffmpeg_process)
    

    Python Logs:

    Frames: 328.0
    ...
    True
    Frame 50
    True
    Frame 51
    True
    Frame 52
    True
    Frame 53
    True
    

    I placed cap.isOpened() in the loop to check if it always returns true, and when I printed it, it always showed true

    Link to video: Tested Video

  • Adding Dynamic Progress Bar to FFMpeg Video Output (Mac) [closed]

    12 mai, par saurav tripathi

    I'm trying to add a dynamic progress bar to the bottom of a video using ffmpeg on my Mac. Here's the command I'm currently using:

    ffmpeg -i "/Volumes/hard-drive/Auto-pilot-video/upload-ready-video/one-two-ka-four.mp4" -filter_complex \
    "[0:v]drawbox=y=ih-20:color=yellow@0.5:width=iw*(t/606.15):height=20:t=fill[v]" \
    -map "[v]" -map 0:a -c:a copy -preset fast output.mp4
    

    Question:

    enter image description here

    As you can see in the image right now, it just a fixed yellow bar at the bottom of the screen. But instead of just fixed at bottom I want a dynamically moving bar at the bottom.

    Is it possible to create a dynamic progress bar using ffmpeg filters on macOS? If so, could you please suggest the appropriate filter(s) and their configuration for achieving this effect?

  • I am unable to decode the frames in python using ffmpeg [closed]

    12 mai, par Saail Chavan
    import pylwdrone
    import cv2
    import numpy as np
    
    # Initialize the LWDrone object
    drone = pylwdrone.LWDrone()
    
    # Start the video stream
    for packet in drone.start_video_stream():
        try:
            # Print the size of the frame data
            print("Packet frame bytes size:", len(packet.frame_bytes))
    
            # Print a portion of the frame data (first 100 bytes)
            print("First 100 bytes of frame data:", packet.frame_bytes[:100])
    
            # Convert the frame data to numpy array
            frame = np.frombuffer(packet.frame_bytes, dtype=np.uint8)
    
            # Get the actual frame shape
            frame_shape = frame.shape
            print("Actual frame shape:", frame_shape)
    
            # Reshape the frame data
            frame = frame.reshape((frame_shape[0]//3, 3))
    
            # Display the frame
            cv2.imshow("Debug Frame", frame)
    
            # Check for 'q' key to exit
            if cv2.waitKey(1) & 0xFF == ord('q'):
                break
    
        except ValueError as ve:
            print("ValueError:", ve)
            # Skip this frame and continue to the next one
            continue
        except Exception as e:
            print("An error occurred:", e)
            break
    
    # Clean up
    cv2.destroyAllWindows()
    drone.stop_video_stream()
    

    error::

    Actual frame shape: (31621,) ValueError: cannot reshape array of size 31621 into shape (10540,3) Packet frame bytes size: 45509 First 100 bytes of frame data: bytearray(b"\x00\x00\x00\x01A\x9a\x00\x10\x00 #\xbf\xf4 \xb7\xe8\xe0\xd3\xb5\x87\xe3\xb8\x0c\xc8\xecN\xe1C\xb4p\x18\xb682 \xb4ef\x15\xc3B\t\xd3^z\x94iF\x05\x89\x1f\xd0\xd3\x1f\xa1\xe7\x12 \\\'\x8f2\t\x017[`l\x1c{[TA\x8eL\xb6\xf7\xd0/\xc9\xb1\xfa\xa2\xc1\xbdw\x98fd\x86\x84\xbcB$\x1d*q\xf7\x02\x1c") Actual frame shape: (45509,) ValueError: cannot reshape array of size 45509 into shape (15169,3) Packet frame bytes size: 20981 First 100 bytes of frame data: bytearray(b"\x00\x00\x00\x01A\x9a\x00\x12\x00$!\x0f\xe2\xb8\xe0\xfd\x0c\xfbR\xd5.\x18\x94L>\xc6\xaf\xa6\xbaN\xf7\x83^M\xff`Q\xc1\xf7\x95u\xb2\xe00\x14\x92z\x94\xf2V\xafe~\xc4\xaa\xa0;,^\x8b*\x14\x00\xa9\xea\xb8=\xc0t\xd3a\xbe. \'\xbf\xac\xd7\xf7\x84\x83\x11\xe2\xc9\x80\x1a\xe1G\x89\xf9\xc4\xd1\xdfX\xfc\xcd\x98\xe3u\xed") Actual frame shape: (20981,) ValueError: cannot reshape array of size 20981 into shape (6993,3) Packet frame bytes size: 23269

    i am trying to stream the video from my drone using ffmpeg-python and opencv

  • Convert m3u8 file to mp4 file in React Native Expo

    12 mai, par DRx

    How can I convert m3u8 file to mp4 file in React Native Expo? I have tried to convert m3u8 file to mp4 using FFmpegKit but I have this errors:

    'Cannot read property 'getLogLevel' of null' and 'Cannot read property 'ffmpegSession' of null'

    Also building with this package failing (Could not determine the dependencies of task ':ffmpeg-kit-react-native:compileDebugAidl'.).

    Is there a simple and easy way to convert m3u8 file in React Native Expo?

    Code I have used:

    import { FFmpegKit } from 'ffmpeg-kit-react-native';
    export async function converterToMp4() {
        try {
            await FFmpegKit.executeAsync(`-i ${m3u8FileUri} ${mp4FileUri}`)
    
        } catch(err) {
            console.log(err)
        }
    }