Spaces in variable - bash

I am facing some problems with spaces in variables:
ALBUM=' -metadata album="Peregrinações Alheias"'
This command:
ffmpeg -i $R_IMG -r 1 -b 1800 -i $SOUND -acodec libmp3lame -ab 128k "$ALBUM" -y $OUT
Returns:
Unable to find a suitable output format for ' -metadata album="Peregrinações Alheias"'
And if I take out the "" from the variable:
ffmpeg -i $R_IMG -r 1 -b 1800 -i $SOUND -acodec libmp3lame -ab 128k $ALBUM -y $OUT
Returns:
Unable to find a suitable output format for 'Alheias"'
And I am sure I am missing something in the bash sintax...
UPDATE:
So it looks that the matter is not with spaces but with the "-metadata" argument...
The problem is that I have many metadata and I'd like to put them in just one variable. Like this:
META=' -metadata album="Peregrinações" -metadata title="Passeio ao PETAR" -metadata author="Rogério Madureira" -metadata date="2012" -metadata description="Áudio de um passeio ao PETAR" -metadata comment="Áudio capturado com TACAM DR-07MKII e Foto capturada com Canon PowerShot S5IS" '
And then:
ffmpeg -i $R_IMG -r 1 -b 1800 -i $SOUND -acodec libmp3lame -ab 128k $META -y $OUT

Bash interprets words in quotes as a single argument. Try
ALBUM='album="Peregrinações Alheias"'
ffmpeg -i $R_IMG -r 1 -b 1800 -i $SOUND \
-acodec libmp3lame -ab 128k -metadata "$ALBUM" -y $OUT

Put your command in an array instead.

ALBUM='album=Peregrinações Alheias'
ffmpeg -i $R_IMG -r 1 -b 1800 -i $SOUND -acodec libmp3lame -ab 128k -metadata "$ALBUM" -y $OUT

If you always want to set ALBUM, then Adam's answer is OK. But if you want to optionally set ALBUM then use this:
ALBUM="Peregrinações Alheias"
TITLE="Passeio ao PETAR"
OPTIONAL=
ffmpeg -i $R_IMG -r 1 -b 1800 -i $SOUND \
-acodec libmp3lame -ab 128k \
${ALBUM:+-metadata album="$ALBUM"} \
${TITLE:+-metadata title="$TITLE"} \
${OPTIONAL:+-metadata optional="$OPTIONAL"} \
-y $OUT
When not setting ALBUM the complete ${var:+subst} block is omitted. Other vars are just the same of course-
Of course this scales up to several -metadata options if there is a fixed set of data you want to set.

Using eval can do what you want... Depending on what you have in $R_IMG, $SOUND and $OUT, they may need double-quote escaping, eg. \"$SOUND\" ....
Your $META (which I assume is another name for youur originally named $ALBUM) doesn't need to be laid out like this, but it surely helps (me) ... Just spaces, as in your original works just as well.
META='
-metadata album="Peregrinações"
-metadata title="Passeio ao PETAR"
-metadata author="Rogério Madureira"
-metadata date="2012"
-metadata description="Áudio de um passeio ao PETAR"
-metadata comment="Áudio capturado com TACAM DR-07MKII e Foto capturada com Canon PowerShot S5IS"
'; META="$(echo "$META" |sed 's|"|\\\\"|g' |tr '\n' ' ')"
eval "ffmpeg -i $R_IMG -r 1 -b 1800 -i $SOUND -acodec libmp3lame -ab 128k $META -y $OUT"
If you prefer to not use the sed conversion line, you simply need to change each " in $META to \\" as in this next example:
META=' -metadata album=\\"Peregrinações\\" -metadata title=\\"Passeio ao PETAR\\" -metadata author=\\"Rogério Madureira\\" -metadata date=\\"2012\\" -metadata description=\\"Áudio de um passeio ao PETAR\\" -metadata comment=\\"Áudio capturado com TACAM DR-07MKII e Foto capturada com Canon PowerShot S5IS" '
eval "ffmpeg -i $R_IMG -r 1 -b 1800 -i $SOUND -acodec libmp3lame -ab 128k $META -y $OUT"
I've tested it successfully with the following ffmpeg encoding parameters:
eval "ffmpeg -i ~/input.flv -sameq -acodec libmp3lame -ab 128k $META -y ~/output.mp3"

Related

What are supported ffmpeg rtp_mpegts Muxer options? (mpegts Muxer options are ignored)

I created a UDP stream with -f mpegts and some options like -mpegts_transport_stream_id.
I received the stream with "StreamXpert - Real-time stream analyzer" that shows all options are in the output. See my ffmpeg parameters and the StreamXpert at the end.
The same Muxer options seem to be ignored with -f rtp_mpegts.
I have tried to use -f mpegts and pipe it to -f rtp_mpegts like so:
ffmpeg -i ... -f mpegts pipe: | ffmpeg pipe: -c copy -f rtp_mpegts "rtp://239.1.1.9:1234?pkt_size=1316"
The options are still ignored.
This ticket "support options for MPEGTS muxer when using RTP_MPEGTS" also notices the ignored option. Furthermore in this comment, "thovo" gives an analysis and suggests a solution.
Obviously the problem still exists. Anybody found a workaround for this?
My additional question: I have not questioned if my project really needs rtp in the first place. Maybe my coworker didn't know better and requested rtp when udp would be sufficient as well.
The aim was to receive the RTP stream with a TV using DVB via IP. This was successful an a Panasonic TV.
The SAT>IP Specification on page 10 requires rtp for Media Transport:
The SAT>IP protocol makes use of:
UPnP for Addressing, Discovery and Description,
RTSP or HTTP for Control,
RTP or HTTP for Media Transport.
Is udp out of the equation?
ffmpeg: (all options are in the output with -f mpegts)
(HEX to decimal: 0x005A = 90, 0x005B = 91 0x005C = 92, 0x005D = 93, 0x005E= 94)
ffmpeg -f lavfi -i testsrc \
-r 25 \
-c:v libx264 \
-pix_fmt yuv420p \
-profile:v main -level 3.1 \
-preset veryfast \
-vf scale=1280:720,setdar=dar=16/9 \
-an \
-bsf:v h264_mp4toannexb \
-flush_packets 0 \
-b:v 4M \
-muxrate 8M \
-pcr_period 20 \
-pat_period 0.10 \
-sdt_period 0.25 \
-metadata:s:a:0 language=nya \
-mpegts_flags +pat_pmt_at_frames \
-mpegts_transport_stream_id 0x005A \
-mpegts_original_network_id 0x005B \
-mpegts_service_id 0x005C \
-mpegts_pmt_start_pid 0x005D \
-mpegts_start_pid 0x005E \
-mpegts_service_type advanced_codec_digital_hdtv \
-metadata service_provider='WI' \
-metadata service_name='W' \
-mpegts_flags system_b -flush_packets 0 \
-f mpegts "udp://239.1.1.10:1234?pkt_size=1316"
StreamXpert Output:
-mpegts_transport_stream_id = Transport Stream ID (yellow text highlight)
-mpegts_original_network_id = Original Network ID, onw (green text highlight)
-mpegts_service_id = Program, service (pink text highlight)
-mpegts_pmt_start_pid = PMT PID, Table PID (turquoise text highlight)
-mpegts_start_pid = PID, PCR PID (red text highlight)
-mpegts_service_type = service type (blue text)
service_name = Service name (orange text)
service_provider = Service provider (pink text)

concat two video using ffmpeg working on local but not working on server why?

Here the code is for concat two video and adding watermark to that video but this code working perfectly in local but not in server.
The code is as follows:
$videoFileName = rand('111111', '999999').'_'.time().'.'.$request->file('video1')->getClientOriginalExtension();
$intermediateVideo1 = rand('1111111', '9999999').'_'.time().'.ts';
$intermediateVideo2 = rand('1111111', '9999999').'_'.time().'.ts';
$concatVideoFileName = rand('111111', '999999').'_'.time().'.'.$request->file('video1')->getClientOriginalExtension();
exec('ffmpeg -i '.$request->file('video1').' -c copy -bsf:v h264_mp4toannexb -f mpegts '.$intermediateVideo1);
exec('ffmpeg -i '.$request->file('video2').' -c copy -bsf:v h264_mp4toannexb -f mpegts '.$intermediateVideo2);
exec('ffmpeg -i "concat:'.$intermediateVideo1.'|'.$intermediateVideo2.'" -c copy -bsf:a aac_adtstoasc '.public_path('uploads/videos/'.$concatVideoFileName));
exec('ffmpeg -i '.public_path('uploads/videos/'.$concatVideoFileName).' -i '.storage_path("assets/image/watermark.png").' -filter_complex "overlay" '.public_path('uploads/videos/'.$videoFileName));
File::delete($intermediateVideo1);
File::delete($intermediateVideo2);
File::delete(public_path('uploads/videos/'.$concatVideoFileName));

ffmpeg live stream only outputting 240p

I am having trouble rescaling the resolution of a video with complex filters to 720p, adding the scale to reference the video seems to cause an error
ffmpeg -re -i "https://mnmedias.api.telequebec.tv/m3u8/29880.m3u8" -i
./public/images/ACE.png -i ./public/images/logo2.jpg -i
./public/images/crunchy.png -i ./public/images/red.jpg -filter_complex "
[0]scale=1280:720[ovrl0], [va][ovrl0][v0];[1]scale=40:40[ovrl1], [v0]
[ovrl1] overlay=580:10:enable='lt(mod(t,40),10)'[v1];[2]scale=40:40[ovrl2],
[v1][ovrl2] overlay=580:10:enable='between(mod(t,40),10,20)'[v2];
[3]scale=40:40[ovrl3], [v2][ovrl3]
overlay=580:10:enable='gt(mod(t,40),20)'[v3];[4]scale=40:40[ovrl4], [v3]
[ovrl4] overlay=580:10:enable='gt(mod(t,40),30)'" -acodec aac -vcodec
libx264 -f flv "rtmp://a.rtmp.youtube.com/live2/2222-2222-2222-2222"
error output is [AVFilterGraph # 0x7f964163e9a0] No such filter: ''
Your filtergraph is malformed:
, [va][ovrl0][v0] appears to be a typo and is not applied to any filter.
Your first scale filter is referencing [v0] but [v0] does not exist (other than the orphaned declaration in the typo).
, is use to join linear filters to create a filterchain. ; is used to separate distinct filterchains. You're using , instead of ; in some locations. See FFmpeg Filter Syntax.
I'm guessing you want something like:
-filter_complex \
"[0]scale=1280:720[ovrl0]; \
[1]scale=40:40[ovrl1]; \
[2]scale=40:40[ovrl2]; \
[3]scale=40:40[ovrl3]; \
[4]scale=40:40[ovrl4]; \
[ovrl0][ovrl1] overlay=580:10:enable='lt(mod(t,40),10)'[v1]; \
[v1][ovrl2] overlay=580:10:enable='between(mod(t,40),10,20)'[v2]; \
[v2][ovrl3] overlay=580:10:enable='gt(mod(t,40),20)'[v3]; \
[v3][ovrl4] overlay=580:10:enable='gt(mod(t,40),30)'"

FFMPEG | AVFilterGraph error WINDOWS and DEBIAN

I trying to use FFMPEG for modify a vidéo.
I have this command on this forum but I have some error
ffmpeg -i input -filter_complex \
"[0:v]crop=iw/2:ih/2:0:0[lt]; \
[0:v]crop=iw/2:ih/2:ow:0[rt]; \
[0:v]crop=iw/2:ih/2:0:oh[lb]; \
[0:v]crop=iw/2:ih/2:ow:oh[rb]; \
[lb][lt]hstack[top]; \
[rt][rb]hstack[bottom]; \
[top][bottom]vstack" \
-c:a copy output
Error windows : [AVFilterGraph # 00000000035ecc20] No such filter: '\'
Error Debian : [AVFilterGraph # 0xe152ceab4e0] No such filter: ' '
Any solution to fix it ? Thx !
I have the solution ! Just remove all \ an all in single line !
ffmpeg -i big_buck_bunny.mp4 -filter_complex "[0:v]crop=iw/2:ih/2:0:0[lt]; [0:v]crop=iw/2:ih/2:ow:0[rt]; [0:v]crop=iw/2:ih/2:0:oh[lb]; [0:v]crop=iw/2:ih/2:ow:oh[rb]; [lb][lt]hstack[top]; [rt][rb]hstack[bottom]; [top][bottom]vstack" -c:a copy test.mp4

Audio convertion using ffmpeg on exec() php function

any body explain why exec(),shell_exec(), system() can not return any return value while executing ffmpeg commands.
ie:
exec("Who am i", $output = array());
//here execution is success and $output is set an array value
$output= shell_exec("Who am i");
//here execution is success and $output is set an array value
system("Who am i", $output = array());
//here execution is success and $output is set an array value
but
exec('ffmpeg -i "$sourcepath/Test.mp3" -vn -acodec libvorbis -ab 128k -y $desnpath/TestTest.ogg"', $output = array());
//here execution is success but $output is not set an array value
$output= shell_exec('ffmpeg -i "$sourcepath/Test.mp3" -vn -acodec libvorbis -ab 128k -y $desnpath/TestTest.ogg"');
//here execution is success but $output is not set an array value
system('ffmpeg -i "$sourcepath/Test.mp3" -vn -acodec libvorbis -ab 128k -y $desnpath/TestTest.ogg"', $output = array());
//here execution is success but $output is not set an array value
i don't know why..!?
please any body help me.
It is because ffmpeg does not output anything to stdout. Its output is printed to stderr.
If you are on a non windows system you can do exec('ffmpeg -i "$sourcepath/Test.mp3" -vn -acodec libvorbis -ab 128k -y $desnpath/TestTest.ogg 2>&1"', $output = array()); or you can use proc_open()

Resources