-1

i need to use a ffmpeg command in a shellscript

The command is the next one

(ffmpeg -hide_banner -hwaccel cuvid -c:v h264_cuvid -f hls -i $(youtube-dl -f 95 -g $ylink) -c:v h264_nvenc -r 50 -c:a pcm_s16le -ac 2 -ar 48000 -f hls -hls_list_size 0 /home/build/MSS-ONE/temp/cache/project-$intnumber/$project.m3u8 2>/home/build/MSS-ONE/temp/logs/$project-$intnumber/$project-$intnumber-cache.log) &

I need to get the result of the embeded command $(youtube-dl -f 95 -g $ylink) with quotes so the result in shellscript must be something like this

ffmpeg -hide_banner -hwaccel cuvid -c:v h264_cuvid -f hls -i "https://manifest.googlevideo.com/api/manifest/hls_playlist/expire/1566607293/ei/XTNgXdq4B8O-gwP_7Kn4CA/ip/158.50.77.241/id/-1xif50QMr4.365/itag/95/source/yt_live_broadcast/requiressl/yes/ratebypass/yes/live/1/goi/160/sgoap/gir%3Dyes%3Bitag%3D140/sgovp/gir%3Dyes%3Bitag%3D136/hls_chunk_host/r2---sn-p5qs7nek.googlevideo.com/playlist_type/DVR/initcwndbps/6590/mm/44/mn/sn-p5qs7nek/ms/lva/mv/m/mvi/1/pl/20/dover/11/keepalive/yes/beids/9466588/mt/1566585624/disable_polymer/true/sparams/expire,ei,ip,id,itag,source,requiressl,ratebypass,live,goi,sgoap,sgovp,playlist_type/sig/ALgxI2wwRQIhANz10pUs-d4j0UXRSjzBYPXfyX4ud8mJMMbr9atpDZK_AiBzHkWNXpg2ALK0mnAZPiF_c_U6wQ6Kl5sIUwPlFoNm1A%3D%3D/lsparams/hls_chunk_host,initcwndbps,mm,mn,ms,mv,mvi,pl/lsig/AHylml4wRAIgddN210SkarxEUx0auCxF6miMbA4XLtVo9-G89HDI8bYCIGraEMZ7VL9cvMLlVKifc5pVB6EbAOq8-PqmMES4dpWG/playlist/index.m3u8" -c:v h264_nvenc -r 50 -c:a pcm_s16le -ac 2 -ar 48000 -f hls -hls_list_size 0 /home/build/MSS-ONE/temp/cache/TN-4474fe64/TN.m3u8 

I dont know how to do it.

Can someone help me?

Thanks in advance.


Nope, is not working, putting double quotes send this to the console

ffmpeg -hide_banner -hwaccel cuvid -c:v h264_cuvid -f hls -i https://manifest.googlevideo.com/api/manifest/hls_playlist/expire/1566609044/ei/NDpgXer1Htnlhwa4vp-oDg/ip/158.50.77.241/id/-1xif50QMr4.365/itag/95/source/yt_live_broadcast/requiressl/yes/ratebypass/yes/live/1/goi/160/sgoap/gir%3Dyes%3Bitag%3D140/sgovp/gir%3Dyes%3Bitag%3D136/hls_chunk_host/r2---sn-p5qlsndz.googlevideo.com/playlist_type/DVR/initcwndbps/4760/mm/44/mn/sn-p5qlsndz/ms/lva/mv/m/mvi/1/pl/20/dover/11/keepalive/yes/beids/23806817/mt/1566587361/disable_polymer/true/sparams/expire,ei,ip,id,itag,source,requiressl,ratebypass,live,goi,sgoap,sgovp,playlist_type/sig/ALgxI2wwRQIhANzUWftly6fgAs-gftCO1M43sYH0onbO_bUDKNzspTkgAiB6V595Uxr0lfPVvyziI-goB5l547cW9JVqQ39qtOLjJw%3D%3D/lsparams/hls_chunk_host,initcwndbps,mm,mn,ms,mv,mvi,pl/lsig/AHylml4wRQIgaTR8rH6lv5snP84oaRxyDHbN2CYKc-A03aQSGHpZRs4CIQDzZdGeSXbcdm9OGethv32zwX4rvzHB7saxdrAiIXNWng%3D%3D/playlist/index.m3u8 -c:v h264_nvenc -r 50 -c:a pcm_s16le -ac 2 -ar 48000 -f hls -hls_list_size 0 /home/build/MSS-ONE/temp/cache/TN-c21df74c/TN.m3u8

You can see the quotes are not in the command.

Edit:

i tested with chamorros suggestion and get some news, it works in the console, but not in the shellscript (i don know why).

#!/bin/bash
read -p "Project Name: " project
read -p "Enter Youtube Link Name: "  ylink
intnumber=$(cat /dev/urandom | tr -cd 'a-f0-9' | head -c 8)
hlslink=$(echo \"$(youtube-dl -f 95 -g $ylink)\")
ffmpeg -hide_banner -hwaccel cuvid -c:v h264_cuvid -f hls -i $hlslink -c:v h264_nvenc -r 50 -c:a pcm_s16le -ac 2 -ar 48000 -f hls -hls_list_size 0 /home/build/MSS-ONE/temp/cache/$project-$intnumber/$project.m3u8

This gives me an error saying "No such file or directory".

I think the problem is from ffmpeg and variables.

Thanks for trying.

1 Answers1

3

You just put the double quotes around the command substitution:

… -i "$(youtube-dl -f 95 -g $ylink)" -c:v …

As I explain in detail in this answer, double quotes don’t preserve the literal value of $, so the command substitution is evaluated although it’s quoted. That’s not the case for single quotes – let’s look at a simple example:

$ echo "$(whoami)"
dessert
$ echo '$(whoami)'
$(whoami)

In the first case with double quotes the command substitution is evaluated and echo prints my username dessert, in the second with single quotes the command substitution is not evaluated and the string is printed as-is.


When I run youtube-dl -f 95 -g followed by a youtube video link, for some I get:

ERROR: requested format not available

You could add a test for that, e.g.:

if ! hlslink=$(youtube-dl -gf22 "$file"); then
  exit
fi
ffmpeg … -i "$hlslink" …

This sets the hlslink variable and if that’s unsuccessful exits the script. I didn’t add an error message because the one youtube-dl prints is quite good.

dessert
  • 39,982