baris35
September 5, 2018, 9:28am
1
Hello,
I know it is too simple but I do not know..
#!/bin/bash
for file in *.mp4
do
echo "$file"
ffmpeg -i $file 2>&1 | grep Duration |cut -d ' ' -f 4 | sed s/,//
done
Expected Output:
NF_-_Let_You_Down-fbHbTBP_u7U.mp4 00:03:35.74
NF_-_WHY-zuJV-DAv_wE.mp4 00:03:11.87
Nicki_Minaj_-_Chun-Li-Wpm07-BGJnE.mp4 00:05:09.41
Nicki_Minaj_-_Chun-Li_Vertical_Video-SCq8n_hOcN8.mp4 00:03:21.67
Post_Malone_-_Psycho_ft._Ty_Dolla_ign-au2n7VVGv_c.mp4 00:03:56.64
It gives:
NF_-_Let_You_Down-fbHbTBP_u7U.mp4
00:03:35.74
NF_-_WHY-zuJV-DAv_wE.mp4
00:03:11.87
Nicki_Minaj_-_Chun-Li-Wpm07-BGJnE.mp4
00:05:09.41
Nicki_Minaj_-_Chun-Li_Vertical_Video-SCq8n_hOcN8.mp4
00:03:21.67
Post_Malone_-_Psycho_ft._Ty_Dolla_ign-au2n7VVGv_c.mp4
00:03:56.64
I'd like to do it without transposition or convertion row to column etc.
Many thanks
Boris
sample output of ffmpeg -i $file 2>&1
please.
baris35
September 5, 2018, 9:38am
3
Here you are:
ffmpeg version N-91591-g1581caa Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04.4)
configuration: --prefix=/root/ffmpeg_build --pkg-config-flags=\
--static --extra-cflags=-I/root/ffmpeg_build/include --extra-ldflags=\
-L/root/ffmpeg_build/lib --extra-libs='-lpthread -lm' --bindir=/root/bin --\
enable-gpl --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --\
enable-libopus --enable-libvorbis --enable-openssl --enable-libvpx \
--enable-libx264 --enable-libx265 --enable-nonfree
libavutil 56. 18.102 / 56. 18.102
libavcodec 58. 22.101 / 58. 22.101
libavformat 58. 17.101 / 58. 17.101
libavdevice 58. 4.101 / 58. 4.101
libavfilter 7. 26.100 / 7. 26.100
libswscale 5. 2.100 / 5. 2.100
libswresample 3. 2.100 / 3. 2.100
libpostproc 55. 2.100 / 55. 2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'YG_-_Big_Bank_Audio_ft._2_Chainz_Big_Sean_Nicki_Minaj-scLYjsvrUMk.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.17.101
Duration: 00:03:59.38, start: 0.000000, bitrate: 203 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080 [SAR 1:1 DAR 16:9], 71 kb/s, 23.98 fps, 23.98 tbr, 90k tbn, 47.95 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 125 kb/s (default)
Metadata:
handler_name : SoundHandler
ffmpeg -i $file 2>&1 | awk -F'[ ,]' -v f="${file}" '/Duration/ {print f, $4}'
and remove echo "$file"
from inside the loop.
1 Like
Aia
September 5, 2018, 10:35am
5
baris35:
Hello,
I know it is too simple but I do not know..
#!/bin/bash
for file in *.mp4
do
echo "$file"
ffmpeg -i $file 2>&1 | grep Duration |cut -d ' ' -f 4 | sed s/,//
done
Expected Output:
NF_-_Let_You_Down-fbHbTBP_u7U.mp4 00:03:35.74
NF_-_WHY-zuJV-DAv_wE.mp4 00:03:11.87
Nicki_Minaj_-_Chun-Li-Wpm07-BGJnE.mp4 00:05:09.41
Nicki_Minaj_-_Chun-Li_Vertical_Video-SCq8n_hOcN8.mp4 00:03:21.67
Post_Malone_-_Psycho_ft._Ty_Dolla_ign-au2n7VVGv_c.mp4 00:03:56.64
It gives:
NF_-_Let_You_Down-fbHbTBP_u7U.mp4
00:03:35.74
NF_-_WHY-zuJV-DAv_wE.mp4
00:03:11.87
Nicki_Minaj_-_Chun-Li-Wpm07-BGJnE.mp4
00:05:09.41
Nicki_Minaj_-_Chun-Li_Vertical_Video-SCq8n_hOcN8.mp4
00:03:21.67
Post_Malone_-_Psycho_ft._Ty_Dolla_ign-au2n7VVGv_c.mp4
00:03:56.64
I'd like to do it without transposition or convertion row to column etc.
Many thanks
Boris
The issue of the unwanted format is echo "$file". The echo has an implicit appended newline.
Here's a fix without much change to your code
duration=$(ffmpeg -i $file 2>&1 | grep Duration |cut -d ' ' -f 4 | sed s/,//)
echo "$file $duration"
Another would be to use printf
printf "%s " $file
ffmpeg -i $file 2>&1 | grep Duration |cut -d ' ' -f 4 | sed s/,//
I like not to choose heavier utilities like awk or sed that could do the whole work without any external help if I have committed to use a filtering technique.
duration=$(ffmpeg -i $file 2>&1 | grep Duration |cut -d ' ' -f 4)
printf "%s %s\n" $file ${duration%,}
1 Like
baris35
September 5, 2018, 10:47am
6
Hello Vgersh,
it works as expected.
Thank you so much.
Dear Aia,
I liked below one:
duration=$(ffmpeg -i $file 2>&1 | grep Duration |cut -d ' ' -f 4 | sed s/,//)
echo "$file $duration"
Thank you both
Kind regards
Boris
Aia
September 5, 2018, 11:08am
7
OK, then we can do better in removing the extraneous comma
duration=$(ffmpeg -i $file 2>&1 | grep Duration |cut -d ' ' -f 4)
echo "$file ${duration%,}"
RudiC
September 5, 2018, 12:40pm
8
How about
ffmpeg -i $file 2>&1 | awk -F"[', ]" '/Input/ {printf "%s\t", $(NF-1)} /Duration/ {print $4}'
YG_-_Big_Bank_Audio_ft._2_Chainz_Big_Sean_Nicki_Minaj-scLYjsvrUMk.mp4 00:03:59.38