jonghwanhyeon / python-ffmpeg

A python binding for FFmpeg which provides sync and async APIs
MIT License
302 stars 52 forks source link

Request : output of cmd to get correct duration of a video #62

Closed sosie-js closed 4 months ago

sosie-js commented 4 months ago

Hello @jonghwanhyeon , big thanks for your project !

I saw someone already request duration and you answered with ffprobe here unfortunately result is not reliable.

To have a safe and reliable one, we have to use the Get Duration by decoding example which is a method that reports the correct duration in case the methods shown above using ffprobe are incorrect or missing due to corrupt, truncated, or damaged files

Maybe you can help me. I just need to read the output when triggered stdout to have the result line of "ffmpeg -i input -f null -"

The command is running well , I enjoyed your doc but get no final output line. Thanks a lot..


from ffmpeg import FFmpeg, FFmpegFileNotFound, FFmpegInvalidCommand
import subprocess
from ffmpeg import Progress

ffmpeg_cmd =None

def ffmpeg_full(input):
    global ffmpeg_cmd 
    ffmpeg_cmd = (
        FFmpeg()
        .option("y")
        .input(input)
        .output(
            "pipe:1",
            f="null"
        )
    )

    @ffmpeg_cmd.on("progress")
    def on_progress(progress: Progress):
        print(progress,  flush=True)

    @ffmpeg_cmd.on("completed")
    def on_completed():
        #grab stdout??
        print("completed",  flush=True)

    @ffmpeg_cmd.on("terminated")
    def on_terminated():
        print("terminated", flush=True)
    try:
        ret=ffmpeg_cmd.execute()
        print(ret)
    except FFmpegFileNotFound as exception:
        print("An exception has been occurred!")
        print("- Message from ffmpeg:", exception.message)
        print("- Arguments to execute ffmpeg:", exception.arguments)

ffmpeg_full("foo.mp4")
`
sosie-js commented 4 months ago

Issue solved, ffmpeg output is sent to stderr not stdout ^^'