D
D
Dev_nab2021-05-19 23:28:31
fmpeg
Dev_nab, 2021-05-19 23:28:31

How to fix the audio problem and overwrite the original video?

The final video has no sound at all, and if output.mp4 is replaced with my_video.mp4 , then you get a broken video .
As I understand it, ffmpeg does not put the video in the buffer, but immediately renders it, and therefore it turns out a broken video at the end, i.e. he renders it and immediately writes it down.

How then to process the video my_video.mp4 and immediately save it under the same name ?

import ffmpeg
def watermark(path):  # для примера path = 'my_video.mp4'
    watermark = ffmpeg.input('watermark.png') # картинка вотермарк
    # asyn
    (
        ffmpeg
        .input(
            'my_video.mp4',
            ss='00:00:00', t='00:00:15',
        ) # даю путь к исходному видео и обрезаю его первых 15 сек
        .overlay(watermark, x=23, y=23) # накладываю вотермарк с отступами 23px
       # если убрать .overlay(...), то звук появляется
        .output(
            'output.mp4',
            acodec='copy',
            aspect='9:16',  # соотношение сторон 9:16 (ширина : высота)
            s='hd1080' # разрешение 1080p
        )
        .global_args('-y') # перезапись полученного видео
        .run()
    )


PS Also, if you come across a video with an aspect ratio not 9:16 (width : height), but vice versa 16:9 , then the vidos narrows with distortion. How to make it automatically fit 9:16 and where it should be vice versa 16:9 ?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question