Announcement

Collapse
No announcement yet.

Bulk Operations Using shopt -s globstar?

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Bulk Operations Using shopt -s globstar?

    I've run into an issue trying to do a bulk conversion. I posted a complete question on SO (https://stackoverflow.com/questions/...r-using-ffmpeg) and someone answered in a comment thread, but hasn't posted again and his code doesn't run aparrantly.

    I'm trying to visit all files in a 'master' directory and convert them to .mp4 for space-saving on an external HDD. This can be accomplished using ffmped somefile.vob somefile.mp4. This is described in more detail in the post. The code that he suggested o do this is

    Code:
    [FONT=monospace][COLOR=#000000]shopt -s globstar; for v1 in **/*.vob; do v2=$(awk -F'/' '{print "/media/sa[/COLOR]rah/SENTINEL/Videos/NewMaster" $(NF-1) " - " $NF ".mp4"}' <<< "$v1"); ffmpeg -i "$v1" "$v2"; done
    [/FONT]
    But this gives the error message:
    Code:
    [FONT=monospace][COLOR=#54FF54][B]sarah@ConvergentRefuge[/B][/COLOR][COLOR=#000000]:[/COLOR][COLOR=#5454FF][B]/media/sarah/SENTINEL/MEA[/B][/COLOR][COLOR=#000000]$ shopt -s globstar; for v1 in **/*.vob; do v2=$(awk -F'/' '{print "/media/sa[/COLOR]
    rah/SENTINEL/Videos/NewMaster" $(NF-1) " - " $NF ".mp4"}' <<< "$v1"); ffmpeg -i "$v1" "$v2"; done
    ffmpeg version N-91290-g6129b13 Copyright (c) 2000-2018 the FFmpeg developers
     built with gcc 7 (Ubuntu 7.3.0-16ubuntu3)
     configuration: --prefix=/home/sarah/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/sarah/ffmpeg_build/incl
    ude --extra-ldflags=-L/home/sarah/ffmpeg_build/lib --extra-libs='-lpthread -lm' --bindir=/home/sarah/bin --enable-gpl --enabl
    e-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis 
    --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree
     libavutil      56. 18.102 / 56. 18.102
     libavcodec     58. 20.102 / 58. 20.102
     libavformat    58. 17.100 / 58. 17.100
     libavdevice    58. 4.101 / 58. 4.101
     libavfilter     7. 25.100 /  7.
    
    25.100
     libswscale      5. 2.100 /  5. 2.100
     libswresample   3. 2.100 /  3. 2.100
     libpostproc    55. 2.100 / 55. 2.100
    [COLOR=#ff0000]**/*.vob: No such file or directory[/COLOR]
    [/FONT]
    I'm not sure if anyone here is familiar with this type of format, but at worst I could just go and make a custom java program to do it.

    #2
    The error message "**/*.vob: No such file or directory" indicates that the command wasn't run where the files are, that you need to cd to the right place first for it to work. (The globstar shell option is just set so that the **/ construct will work.)

    I think the awk command needs work. That awk command takes a file name, splits it into fields on /, and outputs a prefix, the second last field, a " - ", the last field, and ".mp4". So, if one of the files was "master/Assault on the Control Room/Video 1.vob" it would produce

    /media/sarah/SENTINEL/Videos/NewMasterAssault on the Control Room - Video 1.vob.mp4

    It appears to me that there is a / missing, that the .vob should be removed, and the "Video" should be removed.
    But...

    My approach to this kind of renaming exercise is to proceed in small steps, building confidence in the results before making changes.
    Code:
    # 1. make a list of the file names to work with, in some file somewhere convenient:
    cd /media/sarah/master # or whereever
    dir **/*.vob > ~/files
    # 3. check the list
    # 4. work on the list
    awk  -F/ '{print "ffmpeg -i \"" $0 "\" \"newmaster/" $(NF - 1) " - " $NF "\""}' ~/files > ~/work1
    sed 's/mp4"$/vob"/' ~/work1 > ~/work2
    sed 's#/Video ##/' ~/work2 > ~/work3
    # check out ~/work3
    # use it
    . ~/work3
    Now I'd tend to use my favourite editor, vim, to do step 4, and I looked into using kate (this is a Kubuntu, and hence KDE, forum) but it was too hard to give simple instructions, I struggled to get a result. I've done a lot of search and replace in vim, but someone with, say, spreadsheet formula skills could to the same text manipulations in that tool.
    Regards, John Little

    Comment


      #3
      Yeah, I wrote a program to do it the way that I wanted it done. It went alright.

      The conversions finished after about a day, which is reasonable for about 500GB

      Comment

      Working...
      X