0

I'm trying to convert all of my music library in various folders (mp3 / wav / m4a) to aif. I also need to:

  1. Convert files in all nested subdirectories
  2. Convert to 44khz 16 bit aif
  3. Copy meta data to new file
  4. Copy embedded artwork
  5. Put all new files in the same output directory

I have spent some time going through answers on here but can only convert to aif so far;

find ./ -type f \( -name "*.wav" -o -name "*.aac" -o -name "*.m4a" -o -name "*.mp3" \) -exec ffmpeg -i '{}' '{}.aif' \;

Can someone help me update the script to do all of the things I need?

Any help mucho appreciated :)

(I've been through multiple posts explaining how to do each of these things but I can't get this to work on batch processing!)

3
  • Do you know the other command to covert the files?
    – Jetchisel
    Commented Feb 18, 2023 at 15:05
  • Hiya, this command does convert the files. The bits I can't figure out is how to copy the ID3v2 tags and artwork to the new files and output them to a single directory. Commented Feb 18, 2023 at 16:12
  • 2
    "multiple posts explaining how to do each of these things" If I read this correctly, you have found posts that explain each feature separately. Please edit your question to show one command line per feature. We don't need the find for each feature, just the ffmpeg command . Your find command looks reasonable, but I would try adding the /full/path/to/new/aifStorage prepended to '{}.aif' at the end. Good luck.
    – shellter
    Commented Feb 18, 2023 at 17:57

1 Answer 1

3

I am unable to get to add artwork to file. Also, only Title and Comment fields are mapped/preserved (on my version). All others lost or not mapped.

Issue is with the format as target output.

Feature/Bug reported.

Confirmed no problem adding artwork, mp3 -> mp3, and preserving all tags (except comment !!!).

My command:

ffmpeg \
    -i "${fullpathfile}" \
    -i "${startDIR}/${fileroot}.png" \
    -map 0:a \
    -map 1:0 \
    -c:0 copy \
    -c:1 copy \
    -id3v2_version 4 \
    "${libraryDIR}/${fileroot}.${sufOut}"

My environment:

Ubuntu MATE 20.04
Linux 5.4.0-135-generic 
#152-Ubuntu SMP Wed Nov 23 20:19:22 UTC 2022
ffmpeg version 4.2.7-0ubuntu0.1
libavutil      56. 31.100 / 56. 31.100
libavcodec     58. 54.100 / 58. 54.100
libavformat    58. 29.100 / 58. 29.100
libavdevice    58.  8.100 / 58.  8.100
libavfilter     7. 57.100 /  7. 57.100
libavresample   4.  0.  0 /  4.  0.  0
libswscale      5.  5.100 /  5.  5.100
libswresample   3.  5.100 /  3.  5.100
libpostproc    55.  5.100 / 55.  5.100

My test script:

#!/bin/bash
    
doTransform()
{    
    cd "${libraryDIR}" ;

    skip_start=0
    time_end=unknown

    while read line
    do
        #sufIn=mp3
        sufIn=`echo "${line}" | awk '{ n=split( $0, val, "." ) ; print val[n] ; }' `

        fileroot=`basename "${line}" ".${sufIn}" `
        rm -f "${libraryDIR}/${fileroot}.${sufOut}"

        ffprobe -hide_banner "${line}"

        echo -e "\n sufIn = ${sufIn} ..."
        echo " Hit return to continue ..." >&2
        read k <&2 

        case "${sufOut}" in
            "${sufIn}" )
                #codec="-codec copy" ;;
                codec="-c:0 copy -c:1 copy" ;;
            * )
                case "${SufIn}" in
                    mp3 )   
                        #codec="-codec copy" ;;
                        codec="-c:0 copy -c:1 copy" ;;
                    * )     
                        # Issues with AIC/AIF format and codec specificaiton
                        codec="-c:0 copy -c:1 copy" ;;
                esac
                ::
        esac

        #-to ${time_end} \
        #-b:a 192k \
        #-i "${fullpathfile}" \

        ffmpeg \
            -i "${line}" \
            -i "${startDIR}/${fileroot}.png" \
            -map 0:a \
            -map 1:0 \
            ${codec} \
            -ss ${skip_start} \
            -id3v2_version 4 \
            "${libraryDIR}/${fileroot}.${sufOut}"

        ### MP3 -> MP3 :    metadata is preseved (except comment) for  
        ### MP3 -> MP3 :    only Title and Comment preserved, all others lost

        ###  Try these again after upgrade to 22.04
        #           -metadata title="Album cover" \
        #           -metadata comment="Cover (front)" \
        #           -metadata:s:a:0 title="Album cover" \
        #           -metadata:s:a:0 comment="Cover (front)" \
    done
}


startDIR=`pwd`
sourceDIR=${startDIR}/FFMPEG_Test
libraryDIR=${startDIR}/Output

sufOut=mp3
sufOut=aif

    #-ipath "${libraryDIR}" \
    #\( -ipath "${libraryDIR}" \) \
find "${sourceDIR}" \
    -type f \( -name "*.wav" -o -name "*.aac" -o -name "*.m4a" -o -name "*.mp3" \) \
    -print      |
grep -v '/Output' |
doTransform
3
  • 1
    Great stuff! Maybe it is possible to save the artwork with the same path/name.jpg (or what ever)? Then it is all in the same place and ready to merge in, if ffmpeg adds that feature? Good luck to all.
    – shellter
    Commented Feb 19, 2023 at 0:45
  • 1
    @shellter, you are correct, and that is what I already do. Also, Audacious will show one of the images in that folder (oldest of alphabetical ???) as the artwork when any file is played. Commented Feb 19, 2023 at 22:32
  • thanks so much for your help @EricMarceau. I have discovered that if I output to .wav instead of .aif all of the meta data is copied except the artwork. This is very helpful as it is a big improvement and I can use wav or aif for my library. I'll update here if I have any progress on the artwork Commented Feb 20, 2023 at 9:59

Not the answer you're looking for? Browse other questions tagged or ask your own question.