mainThe GNU Bourne-Again SHell - Support: sr #111045, path trimmed during iteration

 
 

sr #111045: path trimmed during iteration

Submitter:  LGTR <lgtr>
Submitted:  Tue 02 Apr 2024 06:14:52 AM UTC
   
 
Category:  None Priority:  5 - Normal
Severity:  4 - Important Status:  Works For Me
Privacy:  Public Assigned to:  None
Open/Closed:  Open Operating System:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Wed 03 Apr 2024 03:03:00 PM UTC, comment #3: 

Since the buggy behavior doesn't occur unless ffmpeg is in the mix, this doesn't appear to be a bug in bash.

I agree with the approach of forcing ffmpeg to ignore stdin.

Chet Ramey <chet>
Group administrator
Tue 02 Apr 2024 11:54:50 PM UTC, comment #2: 

I just checked the manual for ffmpeg, and (if it is new enough) it also has a -nostdin option, equivalent to adding </dev/null.

Martin D Kealey <kurahaupo>
Tue 02 Apr 2024 11:48:03 PM UTC, comment #1: 

ffmpeg is notorious for reading from stdin even when it doesn't appear to do so. This means that it winds up reading parts of the filenames that you're reading from "find".

Please change:

ffmpeg -y -hide_banner -loglevel error -ss "$randomTime" -i "$file" -vframes 1 -q:v 2 "$screencapPath"

to:

ffmpeg -y -hide_banner -loglevel error -ss "$randomTime" -i "$file" -vframes 1 -q:v 2 "$screencapPath" </dev/null


And for consistency, change:

rm -rf snap.jpg

to:

rm -f "$screencapPath"

(Do not get into the habit of always using the -r flag with rm; only use it when you intend to remove an entire directory, otherwise it will bite you some day.)

Martin D Kealey <kurahaupo>
Tue 02 Apr 2024 06:14:52 AM UTC, original submission:  

GNU bash, version 5.2.26. Happens on GNU/Linux distros, Cygwin, macOS.

When iterating over several items sent to ffmpeg, the path it receives has characters missing from the left, may vary on each iteration.

Example: CWD is "/Volumes/STORAGE/a/bbbbbbbb/copy/", but ffmpeg received trimmed strings:


root@gnulinux:/Volumes/STORAGE/a/bbbbbbbb/copy# bash capture.sh
olumes/STORAGE/a/bbbbbbbb/copy/fileout5.mp4: No such file or directory
[in#0 @ 0x5625645eacc0] Error opening input: No such file or directory
Error opening input file olumes/STORAGE/a/bbbbbbbb/copy/fileout5.mp4.
Error opening input files: No such file or directory
Volumes/STORAGE/a/bbbbbbbb/copy/fileout4.mp4: No such file or directory
[in#0 @ 0x564771245d80] Error opening input: No such file or directory
Error opening input file Volumes/STORAGE/a/bbbbbbbb/copy/fileout4.mp4.
Error opening input files: No such file or directory
Volumes/STORAGE/a/bbbbbbbb/copy/fileout-abcdefg.mp4: No such file or directory
[in#0 @ 0x55e6f2936d80] Error opening input: No such file or directory
Error opening input file Volumes/STORAGE/a/bbbbbbbb/copy/fileout-abcdefg.mp4.
Error opening input files: No such file or directory
Volumes/STORAGE/a/bbbbbbbb/copy/fileout-abcd.mp4: No such file or directory
[in#0 @ 0x55cedcc18cc0] Error opening input: No such file or directory
Error opening input file Volumes/STORAGE/a/bbbbbbbb/copy/fileout-abcd.mp4.
Error opening input files: No such file or directory


The attachment includes a sample script and few mp4 files. Decompress to "/" but could work in any "/home". Contains:


$ tar -tvf Volumes.tar.bz2
tar: Removing leading `/' from member names
drwxr-xr-x root/root         0 2024-03-30 02:14 /Volumes/
drwxr-xr-x root/root         0 2024-03-30 02:43 /Volumes/STORAGE/
drwxr-xr-x root/root         0 2024-03-30 02:44 /Volumes/STORAGE/a/
drwxr-xr-x root/root         0 2024-03-30 02:44 /Volumes/STORAGE/a/bbbbbbbb/
drwxr-xr-x root/root         0 2024-03-30 10:04 /Volumes/STORAGE/a/bbbbbbbb/copy/
-rw-r--r-- root/root     10648 2024-03-30 10:03 /Volumes/STORAGE/a/bbbbbbbb/copy/fileout-abcdefg,1234567890.mp4
-rw-r--r-- root/root      8279 2024-03-30 02:45 /Volumes/STORAGE/a/bbbbbbbb/copy/fileout5.mp4
-rw-r--r-- root/root      8279 2024-03-30 02:45 /Volumes/STORAGE/a/bbbbbbbb/copy/fileout2.mp4
-rw-r--r-- root/root      8279 2024-03-30 02:45 /Volumes/STORAGE/a/bbbbbbbb/copy/fileout4.mp4
-rw-r--r-- root/root     10648 2024-03-30 02:46 /Volumes/STORAGE/a/bbbbbbbb/copy/fileout1.mp4
-rw-r--r-- root/root     10648 2024-03-30 10:03 /Volumes/STORAGE/a/bbbbbbbb/copy/fileout-abcdefg.mp4
-rw-r--r-- root/root      8279 2024-03-30 02:45 /Volumes/STORAGE/a/bbbbbbbb/copy/fileout3.mp4
-rw-r--r-- root/root       423 2024-03-30 02:48 /Volumes/STORAGE/a/bbbbbbbb/copy/capture.sh
-rw-r--r-- root/root     10648 2024-03-30 10:02 /Volumes/STORAGE/a/bbbbbbbb/copy/fileout-abcd.mp4


$ cat capture.sh
#!/bin/sh
find "$(pwd)" -type f -name "*.mp4" | while read -r file; do
  duration=$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$file")
  randomTime=$(awk -v duration="$duration" 'BEGIN{srand(); print int(rand() * duration)}')
  screencapPath=snap.jpg
  ffmpeg -y -hide_banner -loglevel error -ss "$randomTime" -i "$file" -vframes 1 -q:v 2 "$screencapPath"
  rm -rf snap.jpg
done


LGTR <lgtr>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #55915:  Volumes.tar.bz2 added by lgtr (3KiB - application/x-bzip - sample script and mp4 files)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by chet (Posted a comment)
  • -email is unavailable- added by kurahaupo (Posted a comment)
  • -email is unavailable- added by lgtr (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2024-04-03 chet StatusNone Works For Me
    2024-04-02 lgtr Attached File- Added Volumes.tar.bz2, #55915

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code