I am trying to package some videos on an ubuntu-ec2 machine using shaka packager and following official tutorial.
So I have a list of multi resolution files i.e. original=x.mp4
, converted are x_480p.mp4, x_360p.mp4
and so on. My lowest resolution is 360p.
My bash script automatically detects the height and converts lower than that automatically. Using ffmpeg it’s done nicely. Now the problem is, I need to automatically package the files in converted
directory (all of them) using shaka.
If I run the script in a single line it works.
sudo packager in=dpnd_comp.mp4,stream=video,out=test/video.mp4 in=dpnd_comp.mp4,stream=audio,out=test/audio.mp4
For automatic process I am saving the paths in the vairable inputs
. when I run this using variable, it just processes the last video, here 360p
only.
This is the part –
# using a for loop here
inputs="$inputs in="$output_path"/"$content_id"_"$height"p.mp4,stream=video,output="$packaged_out"/"$content_id"_"$height"p.mp4 "
done
echo "$inputs"
sudo packager "$inputs"
Note, `echo "$inputs" returns this
in=../bin/converted/0001_720p.mp4,stream=video,output=../bin/packaged/0001_720p.mp4 in=../bin/converted/0001_480p.mp4,stream=video,output=../bin/packaged/0001_480p.mp4 in=../bin/converted/0001_360p.mp4,stream=video,output=../bin/packaged/0001_360p.mp4
Any kind of help would be highly appreciated. If anyone ever worked with shaka and made the process automatic, please help.
Edit:
Need to add more arguments after the inputs like this –
sudo packager "$inputs"
--enable_widevine_encryption
--key_server_url "$key_server"
--content_id "$content_id"
--signer "$signer_uname"
--aes_signing_key "$signing_key"
--aes_signing_iv "$signing_iv"
--mpd_output "$packaged_out"/"$content_id".mpd
--hls_master_playlist_output "$packaged_out"/"$content_id".m3u8"
2
Answers
Ok I solved this problem (workaround) by running bash commands from python.
This worked and with python I have more control.
Your first command (the one you tried manually and that works) pass 2 arguments to "packager" (both starting with
in=...
). Your second,packager "$input"
passes only one argument (containg a space,in=... in=...
in a signle string).So either you just drop the double quotes around
$input
when calling, in the last line:sudo packager $input
. It will work if you are sure that none of yourin=...
strings ever contain spaces. But that is not advisable. Because if ever one of your file contains a space, such as "vid 720.mp4", then input will look likein=vid 720.mp4,output=packaged/vid 720.mp4 in=other.mp4,output=pack.mp4
And then running with quotes (
sudo packager "$input"
) is wong, because pakager will be run with a single argumentin=vid 720.mp4,output=packaged/vid 720.mp4 in=other.mp4,output=pack.mp4
that means nothing coherent to it.Running without quotes (
sudo packager $input
) is also wrong, because then packager will be run with 4 arguments,in=vid
,720.mp4,output=packaged/vid
,720.mp4
andint=other.mp4,output=pack.mp4
. Which is not what you want neither.So again, if you are positive that never any space can find its way in your file names, go ahead, run without double quotes around input, and stop reading 🙂
Otherwise, I would use arrays.
Note1: if you want to see how args ars split, use printf rather that echo.
Because you can’t see difference between
echo "one two"
andecho one two
. Whereasprintf "(%s) " one two
andprintf "(%s) " "one two"
shows what are the args.Note2: You don’t need to end double quotes each time you want to add a variable. Variables are expanded inside double quotes
So
(Not all
${...}
are necessary here. But taking the habit of using${...}
each times avoids problems, for example for your${height}p.mp4
: it avoids p to be taken as part of the variable name)Addendum: some experiments
To understand what happen here, see
Edit
To take into account your edit to your question: it should really change nothing. What is the failure? Are you sure it was not there before, but couldn’t see it because of previous problem now solved.
Just to experiment (without your "packager" program, but replacing it, again, with printf)
Displays
Which is exactly what is expected.