1

I have about a hundred home video files that I am recompressing for archival purposes. I want to convert them all to x264 using HandBrake, but I have a problem with the audio. They all follow this format:

  • Video track: interlaced DV-PAL 720x576
  • Audio track: 16-bit Integer Mono (Left), 48kHz
  • Audio track: 16-bit Integer Mono (Right), 48kHz

When I add them into HandBrake, it can only choose one of these audio tracks to include in the conversion, so one audio channel gets lost. I need a way to either:

  • pair the two audio tracks as stereo so that HandBrake recognises both tracks as two halves of a whole, or
  • replace both tracks with one stereo track.

I need to automate this process without recompressing the video unless it performs the same function as HandBrake, as many of the videos are very long so it would take up too much time to compress them twice.

So far I'm leaning towards the second option. I have managed to batch output all of the audio as stereo WAV files, so I have a folder full of the original videos with corresponding audio files of the same name.

I've been using QuickTime Pro 7 on Mac OS 10.10, but I can boot into Windows 7 if necessary. I don't have any AV processing software installed on the Windows side. I'm not command-line savvy but willing to learn if it will help solve the problem. What should my next steps be?

EDIT: For anyone reading this with a similar problem, my solution involved using LordNeckbeard's code below to batch create stereo WAVs from the source files, and then using QuickTime Player 7 Pro to add these WAVs to the source files and delete the original audio tracks. This resulted in the MOVs having one video track and one stereo audio track. However HandBrake would still only allow me to output mono audio from these source files, for reasons I can't make out, so I'm still stuck.

2
  • With "batch" I assume you're using Windows, right? Answer depends on OS.
    – llogan
    Commented Mar 17, 2018 at 17:17
  • Good question! Forgot to include that information. I've been using QuickTime Pro 7 on Mac OS 10.10, but I can boot into Windows 7 if necessary. I don't have any AV processing software installed on the Windows side.
    – Dion
    Commented Mar 18, 2018 at 19:20

1 Answer 1

2

You can do a bash for loop in macOS:

    mkdir outputs
    for f in *.mov; do 
        ffmpeg -i "$f" -filter_complex "[0:a:0][0:a:1]amerge=inputs=2[a]" \
            -map 0:v -map "[a]" -c:v copy -ac 2 "outputs/$f"; 
    done
  • This assumes the current directory contains all of the videos to be processed.

  • The amerge filter is used to merge both audio streams into one.

  • The -ac 2 option is superfluous in this case, but it will downmix the output to stereo if the input audio streams were stereo. Otherwise a 4-channel output would be created.

  • The video is stream copied.

4
  • Thanks! Is this method non-destructive? I.e. if it does something I don't want or I mess it up somehow, are the original files preserved? Can you recommend a reliable resource for reading up on the functions you've used here so I can make sure I understand what's going on? (I'm about to check the ffmpeg man page now)
    – Dion
    Commented Mar 19, 2018 at 12:44
  • @Dion Yes, it is non-destructive. mkdir outputs makes a new directory in the current directory and new videos will be located in this directory. See documentation on -map on the remaining option I didn't provide a link to in the answer.
    – llogan
    Commented Mar 19, 2018 at 16:18
  • Thanks @LordNeckbeard! Your method seems to have worked, with very few problems. Some of the files report Concealing bitstream errors. One of the files failed: Error while filtering: Cannot allocate memoryme=00:00:18.94 bitrate=28229.2kbits/s speed= 5.4xFailed to inject frame into filter network: Cannot allocate memory Error while processing the decoded data for stream #0:3 [aac @ 0x7faf93824200] Qavg: 849.189 [aac @ 0x7faf93824200] 2 frames left in the queue on closing Conversion failed!` Any idea what could be behind this?
    – Dion
    Commented Mar 20, 2018 at 14:49
  • @Dion Hard to say without more info (command, console output, and sample input file). Try a build from current git master branch. See download page for links.
    – llogan
    Commented Mar 22, 2018 at 17:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .