Recherche avancée

Médias (91)

Sur d’autres sites (333)

  • FFMPEG on AWS Lambda Only outputs half a second of video when converting video from mobile safari

    18 août 2023, par user1825257

    I am running FFMPEG on AWS Lambda using nodejs and fluent-ffmpeg. I am able to convert videos recorded on most devices / browsers, but when I attempt to convert videos recorded on Mobile Safari, the length of the output video is 1/2 a second regardless of the input length.

    


    My Typescript code is :

    


        import * as ffmpeg from &#x27;fluent-ffmpeg&#x27;;&#xA;    public static StandardizeVideoFormat(&#xA;      inputSignedUrl: string,&#xA;      filename: string,&#xA;    ): Promise<string> {&#xA;      const localFilePath = `/tmp/${Date.now()}_${filename}.mp4`;&#xA;    &#xA;      return new Promise((resolve, reject) => {&#xA;        ffmpeg(inputSignedUrl)&#xA;          .outputOptions([&#xA;            &#x27;-crf&#x27;,&#xA;            &#x27;18&#x27;,&#xA;            &#x27;-vcodec&#x27;,&#xA;            &#x27;libx264&#x27;,&#xA;            &#x27;-codec:a&#x27;,&#xA;            &#x27;aac&#x27;,&#xA;            &#x27;-preset&#x27;,&#xA;            &#x27;medium&#x27;,&#xA;          ])&#xA;          .output(localFilePath)&#xA;          .on(&#x27;start&#x27;, function (commandLine) {&#xA;            console.log(&#x27;Spawned Ffmpeg with command: &#x27; &#x2B; commandLine);&#xA;          })&#xA;          .on(&#x27;error&#x27;, function (err) {&#xA;            reject(err);&#xA;          })&#xA;          .on(&#x27;progress&#x27;, function (progress) {&#xA;            console.log(&#x27;progress&#x27;, progress);&#xA;          })&#xA;          .on(&#x27;end&#x27;, function () {&#xA;            resolve(localFilePath);&#xA;          })&#xA;          .run();&#xA;      });&#xA;    }&#xA;</string>

    &#xA;

    Using FFprobe, The metadata of the input file is :

    &#xA;

    {&#xA;  streams: [&#xA;    {&#xA;      index: 0,&#xA;      codec_name: &#x27;h264&#x27;,&#xA;      codec_long_name: &#x27;H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10&#x27;,&#xA;      profile: &#x27;Baseline&#x27;,&#xA;      codec_type: &#x27;video&#x27;,&#xA;      codec_tag_string: &#x27;avc1&#x27;,&#xA;      codec_tag: &#x27;0x31637661&#x27;,&#xA;      width: 1920,&#xA;      height: 1080,&#xA;      coded_width: 1920,&#xA;      coded_height: 1080,&#xA;      closed_captions: 0,&#xA;      film_grain: 0,&#xA;      has_b_frames: 0,&#xA;      sample_aspect_ratio: &#x27;N/A&#x27;,&#xA;      display_aspect_ratio: &#x27;N/A&#x27;,&#xA;      pix_fmt: &#x27;yuvj420p&#x27;,&#xA;      level: 40,&#xA;      color_range: &#x27;pc&#x27;,&#xA;      color_space: &#x27;unknown&#x27;,&#xA;      color_transfer: &#x27;unknown&#x27;,&#xA;      color_primaries: &#x27;unknown&#x27;,&#xA;      chroma_location: &#x27;left&#x27;,&#xA;      field_order: &#x27;progressive&#x27;,&#xA;      refs: 1,&#xA;      is_avc: &#x27;true&#x27;,&#xA;      nal_length_size: 4,&#xA;      id: &#x27;0x1&#x27;,&#xA;      r_frame_rate: &#x27;30000/1001&#x27;,&#xA;      avg_frame_rate: &#x27;60000/1991&#x27;,&#xA;      time_base: &#x27;1/600&#x27;,&#xA;      start_pts: 26,&#xA;      start_time: 0.043333,&#xA;      duration_ts: 4008,&#xA;      duration: 6.68,&#xA;      bit_rate: 10175170,&#xA;      max_bit_rate: &#x27;N/A&#x27;,&#xA;      bits_per_raw_sample: 8,&#xA;      nb_frames: &#x27;N/A&#x27;,&#xA;      nb_read_frames: &#x27;N/A&#x27;,&#xA;      nb_read_packets: &#x27;N/A&#x27;,&#xA;      extradata_size: 31,&#xA;      side_data_type: &#x27;Display Matrix&#x27;,&#xA;      displaymatrix: &#x27;&#x27;,&#xA;      rotation: &#x27;-90&#x27;,&#xA;      tags: [Object],&#xA;      disposition: [Object]&#xA;    },&#xA;    {&#xA;      index: 1,&#xA;      codec_name: &#x27;aac&#x27;,&#xA;      codec_long_name: &#x27;AAC (Advanced Audio Coding)&#x27;,&#xA;      profile: &#x27;LC&#x27;,&#xA;      codec_type: &#x27;audio&#x27;,&#xA;      codec_tag_string: &#x27;mp4a&#x27;,&#xA;      codec_tag: &#x27;0x6134706d&#x27;,&#xA;      sample_fmt: &#x27;fltp&#x27;,&#xA;      sample_rate: 48000,&#xA;      channels: 1,&#xA;      channel_layout: &#x27;mono&#x27;,&#xA;      bits_per_sample: 0,&#xA;      initial_padding: 0,&#xA;      id: &#x27;0x2&#x27;,&#xA;      r_frame_rate: &#x27;0/0&#x27;,&#xA;      avg_frame_rate: &#x27;0/0&#x27;,&#xA;      time_base: &#x27;1/48000&#x27;,&#xA;      start_pts: 0,&#xA;      start_time: 0,&#xA;      duration_ts: 319488,&#xA;      duration: 6.656,&#xA;      bit_rate: 181302,&#xA;      max_bit_rate: &#x27;N/A&#x27;,&#xA;      bits_per_raw_sample: &#x27;N/A&#x27;,&#xA;      nb_frames: &#x27;N/A&#x27;,&#xA;      nb_read_frames: &#x27;N/A&#x27;,&#xA;      nb_read_packets: &#x27;N/A&#x27;,&#xA;      extradata_size: 2,&#xA;      tags: [Object],&#xA;      disposition: [Object]&#xA;    }&#xA;  ],&#xA;  format: {&#xA;    filename: &#x27;input.mp4&#x27;,&#xA;    nb_streams: 2,&#xA;    nb_programs: 0,&#xA;    format_name: &#x27;mov,mp4,m4a,3gp,3g2,mj2&#x27;,&#xA;    format_long_name: &#x27;QuickTime / MOV&#x27;,&#xA;    start_time: 0,&#xA;    duration: 6.723333,&#xA;    size: 8651792,&#xA;    bit_rate: 10294646,&#xA;    probe_score: 100,&#xA;    tags: {&#xA;      major_brand: &#x27;iso5&#x27;,&#xA;      minor_version: &#x27;1&#x27;,&#xA;      compatible_brands: &#x27;isomiso5hlsf&#x27;,&#xA;      creation_time: &#x27;2023-08-05T19:03:15.000000Z&#x27;&#xA;    }&#xA;  },&#xA;  chapters: []&#xA;}&#xA;

    &#xA;

    Any ideas on why the output of my command on this file always results in a 0.5 second long output ?

    &#xA;

  • How to resolve Electron ffmpeg error opening input file ?

    26 août 2023, par 3V1LXD

    I have an Electron app with ffmpeg.exe inside the project's bin folder. When i try to use ffmpeg to make a new video I get an error reading the input file.

    &#xA;

    FFmpeg error: [in#0 @ 000002667f2ab9c0] Error opening input: No such file or directory&#xA;&#xA;Error opening input file C:/Users/xxxx/Videos/Powder/2023.08.19%2017.30.37_Apex_Legends/Powder_2023.08.19%2021.00.48.mp4&#xA;

    &#xA;

    const ffmpeg = spawn(ffmpegPath, [&#xA;  &#x27;-i&#x27;, videoFile,&#xA;  &#x27;-filter_complex&#x27;, filterComplex,&#xA;  &#x27;-map&#x27;, &#x27;[out]&#x27;,&#xA;  &#x27;-c:v&#x27;, &#x27;libx264&#x27;,&#xA;  &#x27;-crf&#x27;, &#x27;18&#x27;,&#xA;  &#x27;-preset&#x27;, &#x27;veryfast&#x27;,&#xA;  &#x27;-y&#x27;,&#xA;  path.join(outputDir, outputName)&#xA;]);&#xA;&#xA;ffmpeg.stdout.on(&#x27;data&#x27;, (data) => {&#xA;  console.log(`FFmpeg output: ${data}`);&#xA;});&#xA;&#xA;ffmpeg.stderr.on(&#x27;data&#x27;, (data) => {&#xA;  console.error(`FFmpeg error: ${data}`);&#xA;});&#xA;&#xA;ffmpeg.on(&#x27;close&#x27;, (code) => {&#xA;  console.log(`FFmpeg process exited with code ${code}`);&#xA;  event.reply(&#x27;ffmpeg-export-done&#x27;); // Notify the renderer process&#xA;});&#xA;

    &#xA;

    How can i resolve this path issue ?

    &#xA;

  • FileNotFoundError when extracting audio from recently saved video using FFMPEG"

    3 août 2023, par Peter Long

    Scenario : I'm using this tool to record tiktok live. I write another script to call the main.pytool because I want to add some additional options, for example, to extract the audio of the live video that is recorded

    &#xA;

    FFMPEG is used to extract the audio. First the video is saved (with FFMPEG) and after I want to extract the audio of that video (again with FFMPEG). The path where the video is recorded and saved is C:\Users\Administrator\Desktop\tiktok

    &#xA;

    The problem is that I see the file and it is saved, but this error is generated as output : FileNotFoundError: [WinError 2] The system cannot find the file specified

    &#xA;

    I can't figure out why it doesn't detect the last saved video file in general

    &#xA;

    I try with this

    &#xA;

    import os&#xA;import subprocess&#xA;import time&#xA;from moviepy.editor import VideoFileClip&#xA;&#xA;def main():&#xA;    # Command to run main.py and record the video&#xA;    cmd = &#x27;python main.py -user ryzebenny -output "C:\\Users\\Administrator\\Desktop\\tiktok" -ffmpeg -duration 30 --auto-convert&#x27;&#xA;    subprocess.run(cmd, shell=True)&#xA;&#xA;    # Wait for the video file to appear in the folder&#xA;    wait_for_video("C:\\Users\\Administrator\\Desktop\\tiktok")&#xA;&#xA;    # Extract audio from recorded video&#xA;    video_filename = find_latest_file("C:\\Users\\Administrator\\Desktop\\tiktok", ".mp4")&#xA;    if video_filename:&#xA;        video_path = os.path.join("C:\\Users\\Administrator\\Desktop\\tiktok", video_filename)&#xA;        audio_filename = video_filename.replace(".mp4", ".mp3")&#xA;        audio_path = os.path.join("C:\\Users\\Administrator\\Desktop\\tiktok", audio_filename)&#xA;&#xA;        video_clip = VideoFileClip(video_path)&#xA;        audio_clip = video_clip.audio&#xA;        audio_clip.write_audiofile(audio_path)&#xA;        audio_clip.close()&#xA;        video_clip.close()&#xA;        print(f"Audio extraction completed: {audio_filename}")&#xA;    else:&#xA;        print("No video files found.")&#xA;&#xA;def wait_for_video(directory):&#xA;    max_wait_time = 60  # Maximum time to wait in seconds&#xA;    start_time = time.time()&#xA;    while time.time() - start_time &lt; max_wait_time:&#xA;        if find_latest_file(directory, ".mp4"):&#xA;            break&#xA;        time.sleep(1)&#xA;&#xA;def find_latest_file(directory, extension):&#xA;    list_of_files = [f for f in os.listdir(directory) if f.endswith(extension) and os.path.isfile(os.path.join(directory, f))]&#xA;    if list_of_files:&#xA;        return max(list_of_files, key=os.path.getctime)&#xA;    return None&#xA;&#xA;if __name__ == "__main__":&#xA;    main()&#xA;

    &#xA;

    but i get this error

    &#xA;

    [*] 2023-08-03 15:57:09 - INFO - START RECORDING FOR 30 SECONDS&#xA;[*] 2023-08-03 15:57:09 - INFO - [PRESS &#x27;q&#x27; TO STOP RECORDING]&#xA;[*] 2023-08-03 15:57:31 - INFO - FINISH: C:\Users\Administrator\Desktop\tiktok\TK_ryzebenny_2023.08.03_15-57-09_flv.mp4&#xA;&#xA;Traceback (most recent call last):&#xA;  File "C:\Users\Administrator\Desktop\tiktok\TikTok-Live-Recorder\run_main.py", line 45, in <module>&#xA;    main()&#xA;  File "C:\Users\Administrator\Desktop\tiktok\TikTok-Live-Recorder\run_main.py", line 12, in main&#xA;    wait_for_video("C:\\Users\\Administrator\\Desktop\\tiktok")&#xA;  File "C:\Users\Administrator\Desktop\tiktok\TikTok-Live-Recorder\run_main.py", line 34, in wait_for_video&#xA;    if find_latest_file(directory, ".mp4"):&#xA;       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^&#xA;  File "C:\Users\Administrator\Desktop\tiktok\TikTok-Live-Recorder\run_main.py", line 41, in find_latest_file&#xA;    return max(list_of_files, key=os.path.getctime)&#xA;           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^&#xA;  File "<frozen genericpath="genericpath">", line 65, in getctime&#xA;FileNotFoundError: [WinError 2] The system cannot find the file specified: &#x27;TK_ryzebenny_2023.08.03_15-57-09.mp4&#x27;&#xA;</frozen></module>

    &#xA;

    Instead, I expect that once I save the video (in .mp4) the audio of that video will be extracted afterwards

    &#xA;