1

I have an audiobook which consists of over 700 ra files (RealAudio) which I'm trying to batch convert to mp3 using ffmpeg. RA files are named as chapter-verse.ra (e.g. 13-01.ra)

I run a script and it gets as far as processing 32 files and then stops. For each file it displays an error, but converts it none the less.

Here is my script:

#!/bin/bash
#

outdir=/data/sounds/output
srcdir=/data/sounds

# Cleanup first
rm -f /data/sounds/output/*

ls -1 ${srcdir}/*.ra | while read file
do
    infile=$(basename $file)
    chapter=$(echo $infile | cut -f1 -d"-")
    verse=$(echo $infile | cut -f2 -d"-")
    verse=$(echo $verse | cut -f1 -d".")
    echo "File $file | Target: Chapter $chapter Verse $verse"
    echo
    ffmpeg -i $file -loglevel error -acodec libmp3lame ${outdir}/Chapter${chapter}_Verse${verse}.mp3
done

Here is an extract of the output I'm getting:

[ac3 @ 0x221e520] frame sync error
Error while decoding stream #0:0: Invalid data found when processing input
/data/sounds/13-02.ra: Input/output error
File data/sounds/13-03.ra | Target: Chapter 13 Verse 03
data/sounds/13-03.ra: No such file or directory
File /data/sounds/13-04.ra | Target: Chapter 13 Verse 04
[ac3 @ 0x1a4d520] frame sync error
Error while decoding stream #0:0: Invalid data found when processing input
/data/sounds/13-04.ra: Input/output error
File data/sounds/13-05.ra | Target: Chapter 13 Verse 05
data/sounds/13-05.ra: No such file or directory
File /data/sounds/13-06.ra | Target: Chapter 13 Verse 06

What's puzzling is that it complains about "no such file or directory", but if I simply echo the ffmpeg command (without executing it) the script runs fine all the way till the end.

When the script aborts, I find my output directory has some files in it which all work fine, I just wish it would process all of them?! My environment:

Fedora workstation 21

ffmpeg version 2.4.8 Copyright (c) 2000-2015 the FFmpeg developers

2
  • Could this be caused by some of your input file names containing white space? I would recommend quoting: ffmpeg -i "$file".
    – dhag
    Commented May 5, 2015 at 14:51
  • Thanks for the suggestion but unfortunately, that didn't work either. It's really puzzling me, I always seem to have problems when I try and script with ffmpeg!
    – Aditya K
    Commented May 5, 2015 at 15:03

2 Answers 2

1

Figured this one out. This has already been answered here

The ffmpeg line now reads:

   < /dev/null  ffmpeg -i $file -loglevel error -acodec libmp3lame ${outdir}/Chapter${chapter}_Verse${verse}.mp3

And goes all the way till the end.

1

I believe ffmpeg commands proceeding the first are being interpreted as stdin keystrokes. As such you need to add -nostdin to your ffmpeg calls like:

#!/bin/bash
#

outdir=/data/sounds/output
srcdir=/data/sounds

# Cleanup first
rm -f /data/sounds/output/*

ls -1 ${srcdir}/*.ra | while read file
do
    infile=$(basename $file)
    chapter=$(echo $infile | cut -f1 -d"-")
    verse=$(echo $infile | cut -f2 -d"-")
    verse=$(echo $verse | cut -f1 -d".")
    echo "File $file | Target: Chapter $chapter Verse $verse"
    echo
    ffmpeg -nostdin -i $file -loglevel error -acodec libmp3lame ${outdir}/Chapter${chapter}_Verse${verse}.mp3
done

You must log in to answer this question.

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