LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-08-2019, 06:52 PM   #16
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: FreeBSD/Slackware-14.2+/ArcoLinux
Posts: 9,337

Rep: Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979

Quote:
Originally Posted by coltson View Post
Do you mean something like this?

......

Tried to run a script with this:
Code:
while read f
do
    ffmpeg -i "$f" -vcodec copy -acodec copy "${f%.*}".avi  
         
done < <(find "$1" -type f -name "*.mp4" )


and received:
.....

Tried it. Received:
ok $1 means what??????????????????????????????
that is a command line directive to take in the 2 argument in a string off the cli (command line interface. ie. terminal emulator)so its trying to use a dead path therefore you will get that response. as in path not valid.
Code:
#!/bin/bash
while read g
do
   echo "$g"
done < <(find $1 -type f)

# Usage

$./scriptName /home
therefore this woud be ran
Code:
#!/usr/bin/env bash


while read f
do
    ffmpeg -i "$f" -vcodec copy -acodec copy "${f%.*}".avi  
         
done < <(find "$1" -type f -name "*.mp4" )
as this
Code:
./script /path/to/my/files
remember
file <path> <type x> ....
man find

Last edited by BW-userx; 11-08-2019 at 06:58 PM.
 
Old 11-08-2019, 10:46 PM   #17
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,587

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
the problem with code examples in forum posts is they tend to lack checks
( I'm guilty of this also )

Code:
#!/bin/bash

[[ -d $1 ]] || {
  echo no dir supplied
  exit 1
} 1>&2

while read f
do
    ffmpeg -i "$f" -vcodec copy -acodec copy "${f%.*}".avi  
         
done < <(find "$1" -type f -name "*.mp4" )
https://mywiki.wooledge.org/BashGuid..._and_.5B.5B.29

or
Code:
#!/bin/bash

[[ -d $1 ]] || {
  echo no dir supplied 
  echo using current working dir ./
} 1>&2

while read f
do
    ffmpeg -i "$f" -vcodec copy -acodec copy "${f%.*}".avi  
         
done < <(find "${1:-./}" -type f -name "*.mp4" )
https://mywiki.wooledge.org/BashGuid...eter_Expansion

you may also like to check that the .mp4 file is actually an mp4

Code:
while read f
do
  [[ $( file -bi "${f}" ) =~ ^video/mp4; ]] \
    && echo \"${f}\" is an mp4 \
    || {
         echo "${f} is not an mp4" >> "${somelogfile}"
         continue # skips this one and continues loop
       }
  ffmpeg -i "$f" -vcodec copy -acodec copy "${f%.*}".avi  
         
done < <(find "${1:-./}" -type f -name "*.mp4" )
 
Old 11-08-2019, 10:58 PM   #18
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: FreeBSD/Slackware-14.2+/ArcoLinux
Posts: 9,337

Rep: Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979
oh now you're doing advance bash, error checking...
Code:
#!/usr/bin/env bash

message()
{
	echo "
	OH Mama you forgot 
	to give me a path to your files!!!!
	usage ./script /path/to/files"
}
	
if [[ $@ -lt 2 ]] ; 
then
	message
	exit
	
fi
echo "
rest of code to do something
goes here"
this is nice, I never seen this one before.
Code:
 [[ $( file -bi "${f}" ) =~ ^video/mp4; ]] \
    && echo \"${f}\" is an mp4 \
do you have to put your \ escape in? I've learned that is not needed. like this
Code:
[[ $@ -lt 2 ]] &&
{ echo "no path given" ; exit ; }
put the && or || before you break the line.
even though -d checks for dir

Last edited by BW-userx; 11-08-2019 at 11:06 PM.
 
Old 11-08-2019, 11:47 PM   #19
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,587

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
yeah
Code:
[[ expr ]] &&
  echo "foo"
works, I just got into the habit of

Code:
[[ expr ]] \
  || error1 \
  && command1 blah foo bar \ 
  && command2 \
  && command3 \
  || for_command1,2,3_chain_error

which I find easier to read than
Code:
[[ expr ]] ||
  error1 &&
  command1 blah foo bar &&
  command2 &&
  command3 ||
  for_command1,2,3_chain_error
although not often that I do something like that


trap is useful

Code:
#!/bin/bash
ErrorReport () {
case $? in
   0) echo "no error";;
   1) echo "error was 1";;
   2) echo "error was 2";;
esac
}
trap ErrorReport EXIT

Foo () {
  E=$(( RANDOM % 3 ))
return $E
}
Foo || exit
Code:
bash traps.sh ; echo $?

Last edited by Firerat; 11-08-2019 at 11:52 PM.
 
Old 11-09-2019, 12:15 AM   #20
tofino_surfer
Member
 
Registered: Aug 2007
Posts: 371

Rep: Reputation: 104Reputation: 104
Quote:
Tried it. Received:
Quote:
./script2.sh: line 6: unexpected EOF while looking for matching `"'
./script2.sh: line 8: syntax error: unexpected end of file
There was an extra " at the end of one line. Try this:

Code:
find . -type f -name '*.mp4' | while read file; 
do
  echo "File: ${file}"
  NEW_FILE=$(printf %q "$file")
  echo "New file: $NEW_FILE"
  ffmpeg -i $NEW_FILE -c copy "${NEW_FILE}.mkv";
done
 
Old 11-09-2019, 01:04 AM   #21
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,587

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
Quote:
Originally Posted by tofino_surfer View Post
There was an extra " at the end of one line. Try this:

Code:
find . -type f -name '*.mp4' | while read file; 
do
  echo "File: ${file}"
  NEW_FILE=$(printf %q "$file")
  echo "New file: $NEW_FILE"
  ffmpeg -i $NEW_FILE -c copy "${NEW_FILE}.mkv";
done
as long as the filename/path is wrapped with "" you do not need to worry about word-splitting

the problem you will have with your code is it will output literal \
Code:
touch foo\ bar
touch "foo\ bar"
ls

the best way to debug is to execute the script like this

Code:
bash -x yourscript.sh args
to capture stderr to file
Code:
 
bash -x yourscript.sh args 2>debug.log
 
Old 11-09-2019, 02:55 AM   #22
tofino_surfer
Member
 
Registered: Aug 2007
Posts: 371

Rep: Reputation: 104Reputation: 104
Quote:
as long as the filename/path is wrapped with "" you do not need to worry about word-splitting
You don't understand the point of the test. There is a possibility that ffmpeg itself is confused by spaces inside filenames.

Quote:
and once, it said
Quote:
Parse error, at least 3 arguments were expected, only 1 given in string 't to Taylor Swift - We Are Never Ever Getting Back Together-bQCLSuNNzbM.mp4'
(the full filename it is: "BONUS - Teens React to Taylor Swift - We Are Never Ever Getting Back Together-1yJMI-O_iR0")
 
Old 11-09-2019, 03:48 AM   #23
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,587

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
Quote:
Originally Posted by tofino_surfer View Post
You don't understand the point of the test. There is a possibility that ffmpeg itself is confused by spaces inside filenames.
you are incorrect
Code:
file="with space.foo"
echo "File: ${file}"
NEW_FILE=$(printf %q "$file")
echo "New file: $NEW_FILE"
touch "${NEW_FILE}"
you will end up with a file called
with\ space.foo
and not
with space.foo


I can assure you there is no problem with ffmpeg and spaces

Code:
ffmpeg -i "input file containing spaces.mp4" -c copy "output file containing spaces.mkv"
Code:
Parse error, at least 3 arguments were expected, only 1 given in string 't to Taylor Swift - We Are Never Ever Getting Back Together-bQCLSuNNzbM.mp4'
(the full filename it is: "BONUS - Teens React to Taylor Swift - We Are Never Ever Getting Back Together-1yJMI-O_iR0")
something is wrong, but it has nothing to do with spaces

to start with, look at the ends of those files

Code:
Together-bQCLSuNNzbM.mp4
Together-1yJMI-O_iR0
they are not the same
so some human error

re-look at the error
Code:
Parse error, at least 3 arguments were expected, only 1 given in string
that string containing spaces is being considered as 1 argument

now, it could be that that file has some strange character encoding that is messing with read

I would pipe the find to cat -A -
Code:
find . -type f -name '*.mp4' | cat -A -
but the correct way to "debug" the script is

Code:
bash -x ffmpegscript.sh 2> debug.log
-x Print commands and their arguments as they are executed.

and as people have already suggested prefix the ffmpeg with echo
 
Old 11-09-2019, 08:07 AM   #24
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: FreeBSD/Slackware-14.2+/ArcoLinux
Posts: 9,337

Rep: Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979
if you for spaces in the name that is what the double quotes are for. To keep everything together. it is when the name itself has the / or \ within the name itself is where you need to check and fix it.

Where I just run it trough some code first to remove that / slash first before moving on to doing whatever else I want to it.

But still it is a double quoted variable that is used to manipulate the string.
example
Code:
$ song="A big bell rings for dead people - ac/dc.mp3" ; echo $song ; song=${song////-} ; echo $song
A big bell rings for dead people - ac/dc.mp3
A big bell rings for dead people - ac-dc.mp3
should follow bash rule 12(ish) when in doubt, double quote.
 
  


Reply

Tags
ffmpeg; video


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] I am trying to write a very simple recursive bash script to chmod 644 all files and chmod 755 all directories in a given directory Astral Axiom Programming 23 05-31-2019 08:44 AM
How to extract all files on a directory and delete all files? moisespedro Slackware 9 01-21-2014 12:55 PM
Reencode avi files funnsoup Linux - Software 8 08-07-2013 01:59 AM
move all files in current directory into a subdirectory in the current directory jakykong Linux - Newbie 8 07-17-2013 12:46 AM
shell script: delete all directories named directory.# except directory.N brian0918 Programming 3 07-13-2005 07:54 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration