VideoHelp Forum

Try DVDFab and download streaming video, copy, convert or make Blu-rays,DVDs! Download free trial !
+ Reply to Thread
Results 1 to 12 of 12
Thread
  1. Freelance scientist Chemist116's Avatar
    Join Date
    May 2017
    Location
    Perú
    Search Comp PM
    Hello. this is my first post. Can you guys help me?. I am trying to insert a time stamp below the screen capture of a video using ffmpeg. I was only able to produce a screenshot at an specified time using vframes example from their documentation page using the code below
    Code:
    ffmpeg -i input.flv -ss 00:00:14.435 -vframes 1 out.png
    However I dont know how to add that '00:00:14.435' time which was specified with the seek command in a black box positioned below the screencapture. I need the fontface to be arial and yellow color. I've also tried other examples like the one using this code:
    Code:
    ffmpeg -i input -vf "drawtext=fontfile=/usr/share/fonts/TTF/Vera.ttf: timecode='00\:00\:00\:00': r=25: x=(w-tw)/2: y=h-(2*lh): fontcolor=white: box=1: boxcolor=0x00000000@1" image%03d.pn
    but the problem with that approach it is that it generates a sequence of images (which also lack the timecode in a black frame) and not a desired time. Can this procedure be done using ffmpeg?.
    Quote Quote  
  2. Member Budman1's Avatar
    Join Date
    Jul 2012
    Location
    NORTHWEST ILLINOIS, USA
    Search Comp PM
    Is what you want , a black, 640x60 area under a 640x480 screen capture, with time in yellow arial letters? Or do you want the black area posted over ther bottom of te screen capture so the pictue remains the same 640x480 size.

    I just used 640 x 480 as a possible but any size can be substituted in the questions.
    Quote Quote  
  3. Freelance scientist Chemist116's Avatar
    Join Date
    May 2017
    Location
    Perú
    Search Comp PM
    Originally Posted by Budman1 View Post
    Is what you want , a black, 640x60 area under a 640x480 screen capture, with time in yellow arial letters? Or do you want the black area posted over ther bottom of te screen capture so the pictue remains the same 640x480 size.

    I just used 640 x 480 as a possible but any size can be substituted in the questions.
    What i'm trying to do is to reproduce something like this picture.



    In similar fashion to that of a contact print. I am not trying to create one, what i need is to make just a single capture but with the time that i specified at the input. In other words to tell ffmpeg to find that 00:00:04:04 (as in the example or any other desired time) and label it like the picture such the output be yellowcolor fontface instead of white as in the picture and that the fontface to be courier new.
    Quote Quote  
  4. combine both your lines; ie. add both -vf drawtext and -ss

    %03d is sprintif notation and will give an image sequence. Use -vframes 1 and don't use the "%" notation in the output filename

    eg. arial, yellow

    Code:
    ffmpeg -i input.ext -vf "drawtext=fontfile=arial.ttf:fontsize=28:fontcolor=yellow:box=1:boxcolor=0x000000CC:x=(w-tw)/2:y=h-(2*lh):timecode='00\:00\:00\:00:rate=30'" -c:v png -ss 00:00:14.435 -vframes 1 -an output.png
    Important that you get the framerate correct for the drawtext overlay, in that example above, it was rate=30 . It might be different for your video

    Note the drawtext notation is hours:minec:frames ; not ms , but your seek notation is in ms.
    Quote Quote  
  5. Member Budman1's Avatar
    Join Date
    Jul 2012
    Location
    NORTHWEST ILLINOIS, USA
    Search Comp PM
    If you already have the Image , an alternate method is:

    Code:
    ffmpeg -i C:\PathToVideo\Video.jpg -vf "drawtext=fontfile=c:\windows\fonts\arial.ttf:text='00\:00\:14,140':fontsize=30:fontcolor=yellow:box=1:boxcolor=black@0.7:x=232: y=400" C:\PathToVideo\000Video.jpg
    Click image for larger version

Name:	subtitletext.jpg
Views:	88
Size:	62.6 KB
ID:	41775

    Bear in mind, Timecode useage results in SMPTE time with a format of HH:MM:SS:frame, so the 14:12 is the 12th frame of the 14th second. Using poisondeathray excellent script gives the following image:
    Click image for larger version

Name:	14_12.jpg
Views:	73
Size:	82.2 KB
ID:	41783

    This corresponds exactly with the First 'B' Frame after 14:435 (14:400)
    Click image for larger version

Name:	14_400.jpg
Views:	65
Size:	89.3 KB
ID:	41784
    Last edited by Budman1; 31st May 2017 at 23:42. Reason: Clarification
    Quote Quote  
  6. Freelance scientist Chemist116's Avatar
    Join Date
    May 2017
    Location
    Perú
    Search Comp PM
    Originally Posted by poisondeathray View Post
    combine both your lines; ie. add both -vf drawtext and -ss

    %03d is sprintif notation and will give an image sequence. Use -vframes 1 and don't use the "%" notation in the output filename

    eg. arial, yellow

    Code:
    ffmpeg -i input.ext -vf "drawtext=fontfile=arial.ttf:fontsize=28:fontcolor=yellow:box=1:boxcolor=0x000000CC:x=(w-tw)/2:y=h-(2*lh):timecode='00\:00\:00\:00:rate=30'" -c:v png -ss 00:00:14.435 -vframes 1 -an output.png
    Important that you get the framerate correct for the drawtext overlay, in that example above, it was rate=30 . It might be different for your video

    Note the drawtext notation is hours:minec:frames ; not ms , but your seek notation is in ms.
    I followed the code that you posted with some minor modifications as requested in the initial question, however as you mentioned the result i got is not exactly what i expected as there is an offset between the time that is used with the seek command and the one which appears in the box.



    How do I know what is the framerate of my video with ffmpeg?. In your code i see you use CC at the end of the zeros for the black colour (boxcolor=0x000000CC). Is this setting for transparency?, overall how do i get accuracy in the resulting screenshot?
    Quote Quote  
  7. Originally Posted by Chemist116 View Post

    How do I know what is the framerate of my video with ffmpeg?.


    You can use ffmpeg -i input.ext and read the console, that will tell you what ffmpeg "thinks" the framerate is. It might be correct, or not



    In your code i see you use CC at the end of the zeros for the black colour (boxcolor=0x000000CC). Is this setting for transparency?,
    You don't need the CC, that was just a copy paste from somewhere. To control transparency use @somevalue from 0 to 1, where 1 is 100% opaque
    eg. boxcolor=0x000000@0.25 would be 25% opaque, 75% transparent



    overall how do i get accuracy in the resulting screenshot?
    It can be tricky -


    Seeking is not necessarily frame accurate in ffmpeg . It's worse with some filetypes and compressions. It's usually worse with long gop compression and large gop intervals

    The timebase might not allow for your selected seekpoint representation . For example if a certain video had 29.97 framerate, each frame only 0.03336 s accuracy. You wouldn't be able to get a "0.5" represented

    There can be "jitter" in time base and rounding issues resulting in differences. For example "29.97" is really rounded from 30000/1001, and some containers have a different timebase

    flv is often variable frame rate , this adds an additional layer of complexity because the presentation timestamps might be slightly off
    Quote Quote  
  8. Member Budman1's Avatar
    Join Date
    Jul 2012
    Location
    NORTHWEST ILLINOIS, USA
    Search Comp PM
    If i may add to poisondeathrays descriptive explaination. The cc when used as the 4th byte of the color (after 0x) is used as the alpha or transparencg setting, 0-255. Cc in hexadecimal=204 in decimal or almost opaque (255). If you use only 3 bytes instead of 4 then you should use poisondeathrays method.

    The only safe way of knowing the correct time or nearly correct time in hh:mms.ms, is to play the video with the time frame displayed ( above with avisynth "showtime" ) extract your image and then place the correct time as in the the image of my niece violin previously. This would also help if your movie is in VFR variable frame rate mentioned earlier but may still not be exact.

    Having explained how the time may be off due to many reasons, If you want to extract an image with the Frame time instead of Timecode, you can use the following script. It is a little overkill but it contains everything you might want to change.

    Code:
    "c:\PathToFFmpeg\ffmpeg" -ss 00:00:02.293 -i "C:\PathToVideo\004 NO subs.mp4" -vf drawtext=fontfile=Lucida.ttf:fontsize=30:fontcolor=white:box=1:boxcolor=black:x=(W-tw)/2:y=H-th-10:text=%{'pts\:hms'}  -vframes 1 -s 640:264 -vsync vfr out%02d.jpg
    Click image for larger version

Name:	02294.jpg
Views:	1897
Size:	35.5 KB
ID:	41788

    Notice the time is off but by 20 seconds it is back in sync. That is as close as I know how to get 'Frame Time' embedded in an extracted image. The other methods work great for 'Timecode' also. You will have to decide which is best for you.
    Last edited by Budman1; 2nd Jun 2017 at 01:46.
    Quote Quote  
  9. Freelance scientist Chemist116's Avatar
    Join Date
    May 2017
    Location
    Perú
    Search Comp PM
    Originally Posted by poisondeathray View Post
    You can use ffmpeg -i input.ext and read the console, that will tell you what ffmpeg "thinks" the framerate is. It might be correct, or not
    Here's what I did, I used ffprobe command from ffmpeg

    Code:
    ffprobe -v error -select_streams v:0 -show_entries stream=avg_frame_rate -of default=noprint_wrappers=1:nokey=1 "kbs_u20_extras.mp4"
    and i got an 'average' of the framerate which for my video was 140970000/5875441 and the resulting screenshot was more accurate but not as exact i thought it would be.



    This was for the -ss 00:00:14.435 as requested.

    Originally Posted by poisondeathray View Post
    Seeking is not necessarily frame accurate in ffmpeg . It's worse with some filetypes and compressions. It's usually worse with long gop compression and large gop intervals

    The timebase might not allow for your selected seekpoint representation . For example if a certain video had 29.97 framerate, each frame only 0.03336 s accuracy. You wouldn't be able to get a "0.5" represented

    There can be "jitter" in time base and rounding issues resulting in differences. For example "29.97" is really rounded from 30000/1001, and some containers have a different timebase

    flv is often variable frame rate , this adds an additional layer of complexity because the presentation timestamps might be slightly off
    So, from what i understand seeking is not too precise. I have also found that it takes sometime until ffmpeg find the specified time but from their documentation ss is faster than other methods.

    By the way, is it possible to modify the code so i do not have to use the command as many times for each frame i want?. In other words to expand it to be like this:

    Code:
    ffmpeg -i video1.mp4 -vf "drawtext=fontfile=/windows/fonts/courbd.ttf:fontsize=80:fontcolor=yellow:box
    =1:boxcolor=black:x=(w-tw)/2:y=h-(2*lh):timecode='00\:00\:00\:00:rate=140970000/5875441'"-c:v png 
    -ss 00:0:00.435, 00:00:50.000, 00:01:20.000 -vframes 1 -an image1.jpg, image2.jpg, image3.jpg
    I want seek to find individual frames at once instead of doing the same operation three times and naming each file by separate, can this be done?
    Quote Quote  
  10. Originally Posted by Chemist116 View Post
    I want seek to find individual frames at once instead of doing the same operation three times and naming each file by separate, can this be done?
    I don't think it's possible with ffmpeg, each instance will require "re-seeking" and take a long time. It doesn't start from where it left off


    Another option mentioned earlier is avisynth . It is possible to get more accurate times , even from VFR sources, by converting to CFR. A GUI of sorts is avspmod and you "see" the preview , and can drag the slider and find the time without the delay or having extra time to re-seek from the beginning. You have to option to show STMPE time (hh:mms:frames) or ms time (hh:mms.ms). You can take screenshots directly from avspmod. That's the way I would do it
    Quote Quote  
  11. Freelance scientist Chemist116's Avatar
    Join Date
    May 2017
    Location
    Perú
    Search Comp PM
    Originally Posted by Budman1 View Post
    If i may add to poisondeathrays descriptive explaination. The cc when used as the 4th byte of the color (after 0x) is used as the alpha or transparencg setting, 0-255. Cc in hexadecimal=204 in decimal or almost opaque (255). If you use only 3 bytes instead of 4 then you should use poisondeathrays method.
    Thanks i had a hunch that it was related to the transparency. In my example i replaced the hex values by the word 'black' however i will try doing so with FF if i am correct.

    Originally Posted by Budman1 View Post

    The only safe way of knowing the correct time or nearly correct time in hh:mms.ms, is to play the video with the time frame displayed ( above with avisynth "showtime" ) extract your image and then place the correct time as in the the image of my niece violin previously. This would also help if your movie is in VFR variable frame rate mentioned earlier but may still not be exact.

    Having explained how the time may be off due to many reasons, If you want to extract an image with the Frame time instead of Timecode, you can use the following script. It is a little overkill but it contains everything you might want to change.

    Code:
    "c:\PathToFFmpeg\ffmpeg" -ss 00:00:02.293 -i "C:\PathToVideo\004 NO subs.mp4" -vf drawtext=fontfile=Lucida.ttf:fontsize=30:fontcolor=white:box=1:boxcolor=black:x=(W-tw)/2:y=H-th-10:text=%{'pts\:hms'}  -vframes 1 -s 640:264 -vsync vfr out%02d.jpg
    Image
    [Attachment 41788 - Click to enlarge]


    Notice the time is off but by 20 seconds it is back in sync. That is as close as I know how to get 'Frame Time' embedded in an extracted image. The other methods work great for 'Timecode' also. You will have to decide which is best for you.
    I have vlc i am not sure if it has the same capabilities of avisynth but ill look into that. For the rest of what you mentioned it might be too long or some problematic to find as the code will result into a long list of captured images, however i acknowledge that's another option but too much to process.
    Quote Quote  
  12. Member Budman1's Avatar
    Join Date
    Jul 2012
    Location
    NORTHWEST ILLINOIS, USA
    Search Comp PM
    For the rest of what you mentioned it might be too long or some problematic to find as the code will result into a long list of captured images,
    Not sure what you mean but the code only captures 1 frame because of the '-vframes 1' statement.
    Quote Quote  



Similar Threads