Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • Bash script to recursive find and convert movies

    24 mars, par Jacco

    in my large movie collection I would like to search for movies with the primary (first) audio track with DTS coding to be converted to Dolby.

    My problem would be the first track I think. My current bash script will list any movie containing a DTS track, but does not specify which track.

    #!/bin/bash
    # My message to create DTS list
    find /home/Movies -name '*.mkv' | while read f
    do
    if mediainfo "$f" | grep A_DTS; then
    echo $f 
    fi
    done
    

    After that I would like to run this command

    ffmpeg -i $f -map 0:v -map 0:a:0 -map 0:a -map 0:s -c:v copy -c:a copy -c:s copy -c:a:0 ac3 -b:a:0 640k $f
    

    or is there a way to move all the audio tracks down and adding the new AAC track?

    ###Progress

    Thanks to @llogan I have finetuned the bash to find the required files.

    #!/bin/bash
    # My DTS conversion script
    # credits to llogan
    
    find /Mymovies -name '*.mkv' | while read f
    do
     if ffprobe -v error -select_streams a:0 -show_entries stream=codec_name -of csv=p=0 "$f" | grep dts; then
     echo "$f"
    fi
    done
    

    Now digging into the command I think I may have a working command. Anybody spot a problem?

    ffmpeg -i $f
          -map 0:v -c:v copy
          -map 0:a:0? -c:a:0 ac3
          -map 0:a:0? -c:a:1 copy
          -map 0:a:1? -c:a:2 copy
          -map 0:a:2? -c:a:3 copy
          -map 0:a:3? -c:a:4 copy
          -map 0:a:4? -c:a:5 copy
          -map 0:a:5? -c:a:6 copy
          -map 0:a:6? -c:a:7 copy
          -map 0:a:7? -c:a:8 copy
          -map 0:a:8? -c:a:9 copy
          -map 0:s? -c copy
          -b:a:0 640k
    /tmp/output.mkv
    mv $f /home/DTS_BACKUP/
    mv /tmp/output.mkv $f
    rm /tmp/output.mkv
    

    So the end result would look like:

    #!/bin/bash
    # My DTS conversion script
    # credits to llogan
    find /Mymovies -name '*.mkv' | while read f
    do
     if ffprobe -v error -select_streams a:0 -show_entries stream=codec_name -of csv=p=0 "$f" | grep dts; then
    
    ffmpeg -i $f
              -map 0:v -c:v copy
              -map 0:a:0? -c:a:0 ac3
              -map 0:a:0? -c:a:1 copy
              -map 0:a:1? -c:a:2 copy
              -map 0:a:2? -c:a:3 copy
              -map 0:a:3? -c:a:4 copy
              -map 0:a:4? -c:a:5 copy
              -map 0:a:5? -c:a:6 copy
              -map 0:a:6? -c:a:7 copy
              -map 0:a:7? -c:a:8 copy
              -map 0:a:8? -c:a:9 copy
              -map 0:s? -c copy
              -b:a:0 640k
    /tmp/output.mkv
    mv $f /home/DTS_BACKUP/
    mv /tmp/output.mkv $f
    rm /tmp/output.mkv
    
    fi
    done
    
  • Convert DTS to AC3 but only if there is no AC3 track already present in container

    24 mars, par Domagoj

    I have sound system that does not support DTS only AC3. I'm automating the process using bash that detects when movie was added to folder, downloads subtitles and converts audio track to AC3 using this command (one part of it):

    ffmpeg -i "{{episode}}" -map 0:v -map 0:a:0 -map 0:a -map 0:s -c:v copy -c:a copy -c:s copy -c:a:0 ac3 -b:a:0 640k "{{directory}}"/{{episode_name}}temp2.mkv

    This works without issue and I end up with a .mkv file that contains original DTS audio track and newly created AC3 audio track. The issue is that some files already contain both AC3 and DTS tracks and in those cases I end up with two AC3 tracks and one DTS track. Another issue is that this command is triggered every time there is update to subtitles. So it's possible that the command will execute multiple times in a period of a few days and the container will have X number of the AC3 tracks.

    I need a way to detect if file already contains AC3 track before I initiate command from above, but I'm not sure what the command would be. Any help is appreciated!

  • Why is using ffmpeg to convert MXF files failing ?

    24 mars, par Marinaio

    I have an MXF video

    I googled syntax to convert to mov and ran it in Mobaxterm on Win10.

    "/drives/c/Program Files (x86)/ffmpeg/bin/ffmpeg.exe" -i Clip0001.MXF -c:v libx264 -c:a aac -ab 384k -sn -strict -2 output.mov
    

    I view it in VideoLan and it looks great.

    I load it into Magix Movie Studio 15 and audio is fine, but video is green!

    ffmpeg output.mov....shows me:

    Stream #0:0(eng): Video: h264 (High 4:2:2) (avc1 / 0x31637661), yuv422p, 1920x1080 [SAR 1:1 DAR 16:9], 4530 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
    

    Even this does not work:

    ffmpeg.exe -i Clip0001.MXF output.mov
    

    Any suggestions on converting this?

    Edit1:

    Here is what it looks like in the editor: enter image description here

    Edit2: Try this and it works, but quality is terrible.

    ffmpeg.exe" -i Clip0001.MXF -c:v mpeg4 -c:a aac -ab 384k -sn -strict -2 output.mov
    
  • Convert audio files to mp3 using ffmpeg [closed]

    24 mars, par Hrishikesh -Rishi- Choudhari

    I need to convert audio files to mp3 using ffmpeg.

    When I write the command as ffmpeg -i audio.ogg -acodec mp3 newfile.mp3, I get the error:

    FFmpeg version 0.5.2, Copyright (c) 2000-2009 Fabrice Bellard, et al.
      configuration: 
      libavutil     49.15. 0 / 49.15. 0
      libavcodec    52.20. 1 / 52.20. 1
      libavformat   52.31. 0 / 52.31. 0
      libavdevice   52. 1. 0 / 52. 1. 0
      built on Jun 24 2010 14:56:20, gcc: 4.4.1
    Input #0, mp3, from 'ZHRE.mp3':
      Duration: 00:04:12.52, start: 0.000000, bitrate: 208 kb/s
        Stream #0.0: Audio: mp3, 44100 Hz, stereo, s16, 256 kb/s
    Output #0, mp3, to 'audio.mp3':
        Stream #0.0: Audio: 0x0000, 44100 Hz, stereo, s16, 64 kb/s
    Stream mapping:
      Stream #0.0 -> #0.0
    Unsupported codec for output stream #0.0
    

    I also ran this command:

     ffmpeg -formats | grep mp3
    

    and got this in response:

    FFmpeg version 0.5.2, Copyright (c) 2000-2009 Fabrice Bellard, et al.
      configuration: 
      libavutil     49.15. 0 / 49.15. 0
      libavcodec    52.20. 1 / 52.20. 1
      libavformat   52.31. 0 / 52.31. 0
      libavdevice   52. 1. 0 / 52. 1. 0
      built on Jun 24 2010 14:56:20, gcc: 4.4.1
     DE mp3             MPEG audio layer 3
     D A    mp3             MP3 (MPEG audio layer 3)
     D A    mp3adu          ADU (Application Data Unit) MP3 (MPEG audio layer 3)
     D A    mp3on4          MP3onMP4
     text2movsub remove_extra noise mov2textsub mp3decomp mp3comp mjpegadump imxdump h264_mp4toannexb dump_extra
    

    I guess that the mp3 codec isn't installed. Am I on the right track here?

  • FFmpeg.js in React/Vite : Worker.js 504 Error and Loading Stalls After load()

    24 mars, par METHESWAR S R

    I'm trying to implement video compression in a React application using @ffmpeg/ffmpeg with Vite, but I'm encountering issues with loading the FFmpeg core files. The loading process stalls after calling load(), and I'm getting a 504 error for the worker.js file.

    When initializing FFmpeg in my React component, the loading process hangs after calling ffmpeg.load(). In the network tab, I see a 504 Gateway Timeout error for worker.js?type=module&worker_file.

    const loadFFmpeg = async () => {
      try {
        setIsLoading(true);
        const ffmpegInstance = new FFmpeg();
        
        ffmpegInstance.on('log', ({ message }) => {
          console.log(message);
        });
    
        ffmpegInstance.on('progress', ({ progress: prog }) => {
          setProgress(prog * 100);
        });
    
        // Attempting to load FFmpeg
        await ffmpegInstance.load(); // Stalls here
        // Also tried with explicit URLs:
        // await ffmpegInstance.load({
        //   coreURL: 'https://unpkg.com/.../ffmpeg-core.js',
        //   wasmURL: 'https://unpkg.com/.../ffmpeg-core.wasm',
        //   workerURL: 'https://unpkg.com/.../ffmpeg-core.worker.js'
        // });
    
        setFFmpeg(ffmpegInstance);
        setIsReady(true);
      } catch (err) {
        console.error('FFmpeg load error:', err);
        setError('Failed to initialize FFmpeg');
      } finally {
        setIsLoading(false);
      }
    };