Thread: Tech FFmpeg duration
View Single Post
Old 10-27-2017, 06:03 AM  
mikeworks
Confirmed User
 
Join Date: Apr 2010
Posts: 272
Thanks everyone for help.

Problem is made much more difficult due to script being encoded.

I tried this as suggested:
exec('ffprobe -v quiet -loglevel quiet -show_format -show_streams -print_format json %video_file%', $output);
$json = json_decode(implode('', $output));
$duration = $json->format->duration;
$duration = $duration/2;

But whenever I have tried ffprobe it breaks the scripts encoding process for whatever reason. In command line it works perfect.

This works:
duration=$(%ffmpeg_path% -i %video_file% 2>&1 | grep "Duration"| cut -d ' ' -f 4 | sed s/,// | sed 's@..*@@g' | awk '{ split($1, A, ":"); split(A[3], B, "."); print 3600*A[1] + 60*A[2] + B[1] }') ;
%ffmpeg_path% -i %video_file% %video_filters% -vf 'scale=448:trunc(ow/a/vsub)*vsub' -vf drawtext="fontsize=16:[email protected]:fontfile =/usr/local/share/fonts/freefont-ttf/FreeSans.ttf:text='Blah blah blah':y=25:x=w-(t-($duration/2))*w/20" -threads 0 %audio_encoder% -ar 44100 -ab %audio_bitrate%k -vcodec libx264 -preset slower -keyint_min 25 -g 250 -r %video_fps% %video_rotate% -y %video_target%

as does this:
duration=$(%ffmpeg_path% -i %video_file% 2>&1 | grep "Duration"| cut -d ' ' -f 4 | sed s/,// | sed 's@..*@@g' | awk '{ split($1, A, ":"); split(A[3], B, "."); print 3600*A[1] + 60*A[2] + B[1] }') &&
%ffmpeg_path% -i %video_file% %video_filters% -vf 'scale=448:trunc(ow/a/vsub)*vsub' -vf drawtext="fontsize=16:[email protected]:fontfile =/usr/local/share/fonts/freefont-ttf/FreeSans.ttf:text='Blah blah blah':y=25:x=w-(t-($duration/2))*w/20" -threads 0 %audio_encoder% -ar 44100 -ab %audio_bitrate%k -vcodec libx264 -preset slower -keyint_min 25 -g 250 -r %video_fps% %video_rotate% -y %video_target%

and this:
duration=$(%ffmpeg_path% -i %video_file% 2>&1 | grep "Duration"| cut -d ' ' -f 4 | sed s/,// | sed 's@..*@@g' | awk '{ split($1, A, ":"); split(A[3], B, "."); print (3600*A[1] + 60*A[2] + B[1])/2 }') &&
%ffmpeg_path% -i %video_file% %video_filters% -vf 'scale=448:trunc(ow/a/vsub)*vsub' -vf drawtext="fontsize=16:[email protected]:fontfile =/usr/local/share/fonts/freefont-ttf/FreeSans.ttf:text='Blah blah blah':y=25:x=w-(t-($duration))*w/20" -threads 0 %audio_encoder% -ar 44100 -ab %audio_bitrate%k -vcodec libx264 -preset slower -keyint_min 25 -g 250 -r %video_fps% %video_rotate% -y %video_target%

As in it actually create thumbs, encodes video, watermarks video. But, the watermark appears from the start of the video. So I guess the $duration is not being populated with a value.

I have a log being generated now by ffmpeg by adding 2> 'path/to/log.txt' at the end of the command. It would helpful if it showed the ffmpeg command executed, but it only shows the encoding process. I believe I can adjust log to debug level, so will try that next, in case it gives a clue why $duration empty.
mikeworks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote