[FFmpeg-user] Extracting starting timecode info using ffmpeg/ffprobe
Francois Visagie
francois.visagie at gmail.com
Thu Sep 3 14:02:07 CEST 2015
> -----Original Message-----
> From: ffmpeg-user [mailto:ffmpeg-user-bounces at ffmpeg.org] On Behalf Of
> Kieran O Leary
> Sent: 03 September 2015 10:26
> To: FFmpeg user questions
> Subject: Re: [FFmpeg-user] Extracting starting timecode info using
> ffmpeg/ffprobe
>
> On Wed, Sep 2, 2015 at 10:03 AM, Francois Visagie
> <francois.visagie at gmail.com> wrote:
>
> >
> > What is the exact command-line that works better for you now, along with
> some sample output?
>
> Here's the script, by the way, can you send me yours?
> https://github.com/kieranjol/ifi-ffv1
> Here's what the console looks like when it's executing that part of my script.
>
> + framerate=($(ffprobe -v error -select_streams v:0 -show_entries
> stream=avg_frame_rate -of default=noprint_wrappers=1:nokey=1 "$1"))
>
> ++ ffprobe -v error -select_streams v:0 -show_entries
> stream=avg_frame_rate -of default=noprint_wrappers=1:nokey=1
> 'augtest/v210 space.mov'
>
> + IFS=:
>
> + read -a timecode
>
> ++ ffprobe -v error -show_entries stream_tags=timecode -of
> default=noprint_wrappers=1:nokey=1 '/augtest/v210 space.mov'
>
> + printf -v timecode ''\''%s\:%s\:%s\:%s'\''' 01 00 00 00
>
> + echo ''\''01\:00\:00\:00'\'''
>
> '01\:00\:00\:00'
>
> + drawtext_options=(fontsize=45 fontfile="/Library/Fonts/Arial
> Black.ttf" fontcolor=white timecode="$timecode" rate="$framerate"
> boxcolor=0x000000AA box=1 x=360-text_w/2 y=480)
>
> ++ IFS=:
>
> ++ echo 'fontsize=45:fontfile=/Library/Fonts/Arial
> Black.ttf:fontcolor=white:timecode='\''01\:00\:00\:00'\'':rate=2997/100:boxc
> olor=0x000000AA:box=1:x=360-text_w/2:y=480'
>
> + drawtext_options='fontsize=45:fontfile=/Library/Fonts/Arial
> Black.ttf:fontcolor=white:timecode='\''01\:00\:00\:00'\'':rate=2997/100:boxc
> olor=0x000000AA:box=1:x=360-text_w/2:y=480'
>
> + ffmpeg -i '//augtest/v210 space.mov' -c:v libx264 -crf 23 -pix_fmt
> yuv420p -vf 'drawtext=fontsize=45:fontfile=/Library/Fonts/Arial
> Black.ttf:fontcolor=white:timecode='\''01\:00\:00\:00'\'':rate=2997/100:boxc
> olor=0x000000AA:box=1:x=360-text_w/2:y=480'
> '/augtest/v210 space/proxy/v210 space_BITC.mov'
>
> ffmpeg version 2.7.2 Copyright (c) 2000-2015 the FFmpeg developers
>
> built with Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM
> 3.6.0svn)
>
> configuration: --prefix=/usr/local/Cellar/ffmpeg/2.7.2_1
> --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-
> hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-
> ldflags= --enable-opencl --enable-libx264 --enable-libmp3lame --enable-
> libvo-aacenc --enable-libxvid --enable-libfreetype --enable-libfaac --enable-
> libass --enable-ffplay --enable-libopenjpeg --disable-decoder=jpeg2000
> --extra-cflags='-I/usr/local/Cellar/openjpeg/1.5.2_1/include/openjpeg-1.5
> ' --enable-nonfree --enable-vda
>
> libavutil 54. 27.100 / 54. 27.100
>
> libavcodec 56. 41.100 / 56. 41.100
>
> libavformat 56. 36.100 / 56. 36.100
>
> libavdevice 56. 4.100 / 56. 4.100
>
> libavfilter 5. 16.101 / 5. 16.101
>
> libavresample 2. 1. 0 / 2. 1. 0
>
> libswscale 3. 1.101 / 3. 1.101
>
> libswresample 1. 2.100 / 1. 2.100
>
> libpostproc 53. 3.100 / 53. 3.100
>
> Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/augtest/v210 space.mov':
>
> Metadata:
>
> major_brand : qt
>
> minor_version : 512
>
> compatible_brands: qt
>
> encoder : Lavf56.36.100
>
> Duration: 00:00:01.02, start: 0.021333, bitrate: 219045 kb/s
>
> Stream #0:0(eng): Video: v210 (v210 / 0x30313276), yuv422p10le, 720x486,
> 223724 kb/s, SAR 10:11 DAR 400:297, 29.97 fps, 29.97 tbr,
> 11988 tbn, 11988 tbc (default)
>
> Metadata:
>
> handler_name : DataHandler
>
> encoder : Lavc56.41.100 v210
>
> timecode : 01:00:00:00
>
> Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo,
> fltp, 110 kb/s (default)
>
> Metadata:
>
> handler_name : DataHandler
>
> Stream #0:2(eng): Data: none (tmcd / 0x64636D74), 0 kb/s
>
> Metadata:
>
> handler_name : DataHandler
>
> timecode : 01:00:00:00
>
> [libx264 @ 0x7fa2f382f000] using SAR=10/11
>
> [libx264 @ 0x7fa2f382f000] using cpu capabilities: MMX2 SSE2Fast SSSE3
> SSE4.2 AVX
>
> [libx264 @ 0x7fa2f382f000] profile High, level 3.1
>
> [libx264 @ 0x7fa2f382f000] 264 - core 146 r2555 0c21480 - H.264/MPEG-4 AVC
> codec - Copyleft 2003-2015 - http://www.videolan.org/x264.html -
> options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7
> psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1
> 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2
> threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1
> interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2
> b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250
> keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf
> mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40
> aq=1:1.00
>
> Output #0, mov, to '/augtest/v210 space/proxy/v210 space_BITC.mov':
>
> Metadata:
>
> major_brand : qt
>
> minor_version : 512
>
> compatible_brands: qt
>
> encoder : Lavf56.36.100
>
> Stream #0:0(eng): Video: h264 (libx264) (avc1 / 0x31637661), yuv420p,
> 720x486 [SAR 10:11 DAR 400:297], q=-1--1, 29.97 fps, 11988 tbn, 29.97 tbc
> (default)
>
> Metadata:
>
> handler_name : DataHandler
>
> timecode : 01:00:00:00
>
> encoder : Lavc56.41.100 libx264
>
> Stream #0:1(eng): Audio: aac (libfaac) (mp4a / 0x6134706D), 48000 Hz,
> stereo, s16, 128 kb/s (default)
>
> Metadata:
>
> handler_name : DataHandler
>
> encoder : Lavc56.41.100 libfaac
>
> Stream mapping:
>
> Stream #0:0 -> #0:0 (v210 (native) -> h264 (libx264))
>
> Stream #0:1 -> #0:1 (aac (native) -> aac (libfaac))
>
> Press [q] to stop, [?] for help
>
> frame= 31 fps=0.0 q=-1.0 Lsize= 517kB time=00:00:01.02
> bitrate=4134.2kbits/s dup=1 drop=0
>
> video:500kB audio:14kB subtitle:0kB other streams:0kB global headers:0kB
> muxing overhead: 0.562701%
>
> [libx264 @ 0x7fa2f382f000] frame I:2 Avg QP:30.83 size: 50676
>
> [libx264 @ 0x7fa2f382f000] frame P:29 Avg QP:27.50 size: 14149
>
> [libx264 @ 0x7fa2f382f000] mb I I16..4: 16.4% 47.1% 36.5%
>
> [libx264 @ 0x7fa2f382f000] mb P I16..4: 16.8% 23.6% 6.6% P16..4:
> 28.8% 6.3% 4.0% 0.0% 0.0% skip:13.9%
>
> [libx264 @ 0x7fa2f382f000] 8x8 transform intra:49.9% inter:82.5%
>
> [libx264 @ 0x7fa2f382f000] coded y,uvDC,uvAC intra: 52.3% 72.6% 42.9%
> inter: 20.4% 60.6% 12.3%
>
> [libx264 @ 0x7fa2f382f000] i16 v,h,dc,p: 59% 35% 4% 3%
>
> [libx264 @ 0x7fa2f382f000] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 41% 20% 30% 2% 1%
> 1% 1% 2% 2%
>
> [libx264 @ 0x7fa2f382f000] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 19% 64% 11% 1% 1%
> 1% 1% 1% 2%
>
> [libx264 @ 0x7fa2f382f000] i8c dc,h,v,p: 25% 43% 24% 9%
>
> [libx264 @ 0x7fa2f382f000] Weighted P-Frames: Y:3.4% UV:0.0%
>
> [libx264 @ 0x7fa2f382f000] ref P L0: 57.9% 10.1% 22.4% 9.5% 0.1%
>
> [libx264 @ 0x7fa2f382f000] kb/s:3957.32
>
> + break
Pretty tidy script, that :-).
It appears we're looking for different information - you for a (single) stream-level timecode tag, and me for the per-frame one. I calibrate the camera timecode to absolute time and intend to use frame timecodes for time synchronisation during editing.
FWIW:
1. exiftool's per-frame output looks as follows:
...
Time Code : 17:51:41:22
Date/Time Original : 2014:01:30 17:51:42+02:00
Aperture Setting : 1.8
Gain : 0 dB
Exposure Program : Program AE
White Balance : Auto
Focus : Auto (0)
Image Stabilization : Off
Exposure Time : 1/50
Make : Canon
Recording Mode : Unknown (8)
Capture Frame Rate : 50
Video Frame Rate : 50
Audio Sample Rate : 48000
Time Code : 17:51:41:21
...
2. The file rename script MU_TC2name (the BELL character displays as a round dot):
@echo off
setlocal
setlocal ENABLEDELAYEDEXPANSION
goto INIT
:HELP
echo.
echo Metadata Utilities TC2name v1.0 (c) F. Visagie 2014/06/14
echo Function: rename video file to creation time of earliest frame, i.e. CCYYMMDDHHMMSSFF.ext
echo.
echo Usage:
echo MU_TC2name file [TCabsolute [TCspaired]] [frames]]]
echo.
echo where:
echo file video file to rename
echo TCabsolute 1=TimeCodes contain absolute HH:MM:SS:FF value used directly for new filename
echo 0=TimeCodes contain relative frame count added to DateTimeOriginal for new filename
echo (default %TCSABSLT%)
echo TCspaired 1=pairs of consecutive frames share the same TimeCode, e.g. Canon HF G30 AVCHD @50p
echo 0=individual frames have unique TimeCode values
echo (default %TCSPAIRD%)
echo frames number of frames at start of video to inspect for earliest TimeCode (default %READFRMS%)
rem Version History
rem v1.0 2014/06/14: Initial creation
:ERRPAUSE
echo
pause
goto END
:INIT
rem Control settings
rem ----------------
set READFRMS=5
rem Pairs of consecutive frames sharing same TimeCode, e.g. Canon HF G30 AVCHD @50p
set TCSPAIRD=1
rem No specific reference offset to TCs (i.e. relative) vs. referencing time of recording (i.e. absolute)
set TCSABSLT=1
rem Set to 'rem' to disable debug logging
set DSABLDBG=rem
rem Tag values used
rem ---------------
set TCTAG=TimeCode
set DTTAG=DateTimeOriginal
rem Parse input file
if [%1] == [] goto HELP
if [%1] == [?] goto HELP
if [%1] == [-?] goto HELP
if [%1] == [/?] goto HELP
if /i [%1] == [h] goto HELP
if /i [%1] == [-h] goto HELP
if /i [%1] == [/h] goto HELP
if /i [%1] == [help] goto HELP
if /i [%1] == [-help] goto HELP
if /i [%1] == [/help] goto HELP
if exist %1. goto GETTCABS
echo.
echo Invalid input file %1!
echo HINT: If it contains spaces, enclose input filename in quotes
goto ERRPAUSE
:GETTCABS
if [%2] equ [] goto MAIN
if [%2] equ [0] goto SETTCABS
if [%2] equ [1] goto SETTCABS
echo.
echo Invalid TCabsolute flag %2!
goto ERRPAUSE
:SETTCABS
set TCSABSLT=%2
if [%3] equ [] goto MAIN
if [%3] equ [0] goto SETTCPAR
if [%3] equ [1] goto SETTCPAR
echo.
echo Invalid TCspaired flag %3!
goto ERRPAUSE
:SETTCPAR
set TCSPAIRD=%3
if not [%4] equ [] set READFRMS=%4
:MAIN
%DSABLDBG% echo READFRMS: %READFRMS%&echo.
set TCOLD=23:59:59:999
set TC=%TCOLD%
set TCUPDATD=0
set DT=
set FRMSREAD=0
rem Even for relative TCs, look for earliest TC in case file had been cut
for /f "usebackq tokens=1* delims=: " %%i in (`exiftool -%TCTAG% -%DTTAG% -g0 -n -s2 -e -ee %1`) do (
%DSABLDBG% echo Read %%i: %%j
if /i %%i equ %TCTAG% (
if %%j lss !TC! (
set TC=%%j
rem Flag TimeCode updated in this frame
set TCUPDATD=1
)
) else (
if /i %%i equ %DTTAG% (
if !TCUPDATD! equ 1 (
rem Strip off any trailing timezone information
for /f "tokens=1* delims=+" %%I in ("%%j") do set DT=%%I
%DSABLDBG% echo ^> Updated TC: !TC!, DT: !DT!
set TCUPDATD=0
)
set /a FRMSREAD+=1
if !FRMSREAD! equ %READFRMS% goto GOTFRAMS
)
)
)
echo.
echo Found only %FRMSREAD% of required %READFRMS% occurrences of tag %DTTAG%
goto ERRPAUSE
:GOTFRAMS
%DSABLDBG% echo.&echo Final TCOLD: %TCOLD%, TC: %TC%, DT: %DT%
if %TC% equ %TCOLD% (
echo.
echo Failed to find %TCTAG% tag in first %READFRMS% frames
goto ERRPAUSE
)
for /f "tokens=1-4 delims=:" %%i in ("%TC%") do (
set HH=%%i
set MM=%%j
set SS=%%k
set FF=%%l
)
if %TCSPAIRD% equ 1 set /a FF*=2
%DSABLDBG% echo TCSPAIRD=%TCSPAIRD%: HH:MM:SS:FF=%HH%:%MM%:%SS%:%FF%
%DSABLDBG% echo TCSABSLT=%TCSABSLT%
if %TCSABSLT% equ 1 (
for /f "tokens=1-3 delims=: " %%i in ("%DT%") do set FILENAME=%%i%%j%%k%HH%%MM%%SS%
) else (
for /f "tokens=1-6 delims=: " %%i in ("%DT%") do set FILENAME=%%i%%j%%k%%l%%m%%n
)
set FILENAME=%FILENAME%%FF%
%DSABLDBG% echo Filename=%FILENAME%
for /f %%i in ("%1") do ren %1 %FILENAME%%%~xi
:END
set READFRMS=
set TCSPAIRD=
set TCSABSLT=
set DSABLDBG=
set TCTAG=
set DTTAG=
set TCOLD=
set TC=
set TCUPDATD=
set DT=
set FRMSREAD=
set HH=
set MM=
set SS=
set FF=
set FILENAME=
setlocal DISABLEDELAYEDEXPANSION
endlocal
> _______________________________________________
> ffmpeg-user mailing list
> ffmpeg-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
More information about the ffmpeg-user
mailing list