Is it possible to pull (at a minimum, the creation date) out of a MOV file and generate an SRT from that?
I'm working on replacing my trusty 1080p camcorder with an iPhone 16. One of the things I like about the camcorder, it embeds the date/time into the AVCHD MPEG files. And when I'm playing the video back, if I turn on sub-titles, I can see the date/time the video was created on the screen.
If this is possible, I can convert my MOV files to MKV and attach an SRT file that has the date/time from the original MOV file and I'm good to go.
+ Reply to Thread
Results 1 to 19 of 19
-
-
Assuming Windows x64. (Helps forum members if you edit your profile to include your OS. Ta.)
Needs the path to your copy of the command line version of MediaInfo.exe.
https://mediaarea.net/download/binary/mediainfo/24.12/MediaInfo_CLI_24.12_Windows_x64.zip
Code:@echo off set mediainfo=C:\VidAud\MediaInfoCLI\MediaInfo.exe for %%a in (*.mov) do "%mediainfo%" "--Output=General;%%Encoded_Date%%" "%%a" > "%%~na.srt" pause
Instead of Encoded_Date, other options you might try:
Recorded_Date
Tagged_Date
Written_Date
Mastered_Date
File_Created_Date
Cheers.Last edited by pcspeak; 27th Dec 2024 at 22:41.
-
I updated my computer details
I created a bat file with that and it produced a SRT file and it -did- give me the meta data....
Code:2024-12-25 18:30:06 UTC
Code:1 00:00:00,000 --> 00:00:01,024 December 25, 2024 1:00pm 2 00:00:01,024 --> 00:00:02,048 December 25, 2024 1:01pm 3 00:00:02,048 --> 00:00:03,072 December 25, 2024 1:03pm 4 00:00:03,072 --> 00:00:04,096 December 25, 2024 1:04pm
I recorded my kids opening their gifts on Christmas this year so I thought I'd be smart and created a single entry for a SRT file that was basically like this:
Code:1 00:00:00,000 --> 01:03:07,445 Christmas 2024
Having a program rip through a MOV file and auto-generate those lines based off the date/time stamp from the MOV meta data is the goal. -
try this. Works for windows with seq, grep, sed, awk and mediainfo. All available for free on the internet. (Google is your friend)
You will need to set up your file path.
set "file_path=C:\xxxxxxxxxx\test01.mp4" ... line 2
program is set up for mp4 file. If mov is used then change line 3 to
for /f "tokens=*" %%e in (' dir %file_path% ^| awk "BEGIN{FS=\" \"} /mov/ {print $5,$1,$2,$3}"') do set "Event_Info=%%e"
Program will output the srt file in this template
1
00:00:00 --> 00:00:05
test01.mp4 10/24/2024 08:51 PM
2
00:00:05 --> 00:00:10
test01.mp4 10/24/2024 08:51 PM
3
00:00:10 --> 00:00:15
test01.mp4 10/24/2024 08:51 PM
The srt time refresh is every 5 seconds.
Program has been thoroughly debugged, hence if it does not work then the challenge lies with you.
Code:@echo off set "file_path=C:\xxxxxxxxxx\test01.mp4" for /f "tokens=*" %%e in (' echo %file_path% ^| sed -e "s#mp4#srt#" ') do set "srt_path=%%e" for /f "tokens=*" %%e in (' dir %file_path% ^| awk "BEGIN{FS=\" \"} /mp4/ {print $5,$1,$2,$3}"') do set "Event_Info=%%e" for /f "tokens=*" %%e in (' mediainfo %file_path% ^| grep "Duration" ^| awk "BEGIN{FS=\" \"} NR==1 {print int((($3*60+$5)*12)+0)}" ') do set "Event_Count=%%e" seq 1 %Event_Count% | awk "BEGIN{hh1=0;mm1=0;ss1=0;x=0; \" echo %Event_Info%\" | getline EvInfo;} { x++; ss2=ss1; mm2=mm1; hh2=hh1; ss1=ss1+5; if (ss1 > 59) mm1=mm1+1;if (ss1 > 59) ss1=ss1-60; if (mm1 > 59) hh1=hh1+1;if (mm1 > 59) mm1=mm1-60; hh1 <10? phh1=\"0\"hh1 : phh1=hh1; hh2 <10? phh2=\"0\"hh2 : phh2=hh2; mm1 <10? pmm1=\"0\"mm1 : pmm1=mm1; mm2 <10? pmm2=\"0\"mm2 : pmm2=mm2; ss1 <10? pss1=\"0\"ss1 : pss1=ss1; ss2 <10? pss2=\"0\"ss2 : pss2=ss2; print x; print phh2\"\072\"pmm2\"\072\"pss2 \" --\076 \"phh1\"\072\"pmm1\"\072\"pss1; print EvInfo\"\n\" } " > %srt_path% echo+ echo Program Complete echo+
-
I Googled up those programs and tried installing them in Windows but when I ran my batch file, it complained that it couldn't find any of them. I looked at my drive and don't see the binaries.
I guess I stink at this?
BUT, I have WSL installed in Windows and I also have a Linux box if need be and all of those individual commands worked in both places when I typed them out. Now, I just need a batch file (that is Linux friendly) to bring it all together. Would you happen to have that? When I tried, it freaked out and threw errors about \r this and \blah that.
I'll try to figure it out tomorrow......nearly midnight and I'm exhausted. -
A batch file.
MediaInfo, ffprobe and a lot of other programs rely on the meta-data in a file.
I usually delete 99.99% of meta-data, so this makes it hard to test.
The batch file works on a sample MOV video I downloaded.
I also ran it against a couple of MP4 videos. That worked, too.
The batch file should handle MOV, MP4 and MKV files.
Obviously this will depend on what meta-data is available to MediaInfo.exe.
meta2subs01.batCode:@echo off set counter=0 set mediainfo=C:\VidAud\MediaInfoCLI\MediaInfo.exe :start for %%a in (*.mp4, *.mkv, *.mov) do call :process "%%a" goto :end :process if exist "%~n1.srt" del /q "%~n1.srt" set video=%~1 :: Set the Encoded_Date variable. Set the clock variables c_hours, c_mins. "%mediainfo%" "--Output=General;%%Encoded_Date%%" "%video%" > "%~n1-clock.txt" setlocal enabledelayedexpansion for /F "usebackq tokens=1-5 delims=^:^ " %%a in ("%~n1-clock.txt") do ( set Encoded_Date=%%a set c_hours=%%b set c_mins=%%c ) :: Set the video duration in milliseconds "%mediainfo%" "--Output=General;%%Duration%%" "%video%" > "%~n1-duration.txt" set /p duration= < "%~n1-duration.txt" ::set the subs variables in_hours:in_mins:in_secs --^> out_hours:out_mins:out_secs. set in_hours=00 set in_mins=0 set in_secs=00,000 set out_hours=00 set out_mins=1 set out_secs=00,000 :update-srt if not %duration% gtr 0 goto :eof set /a duration=%duration%-60000 if not %c_mins% gtr 59 set /a c_mins=%c_mins%+1 if %c_mins% gtr 59 set c_mins=0 && set set /a c_hours=%c_hours%+1 set /a counter=%counter%+1 echo %counter% >> "%~n1.srt" set subs_input=%in_hours%:%in_mins%:%in_secs% set subs_output=%out_hours%:%out_mins%:%out_secs% echo %subs_input% --^> %subs_output% >> "%~n1.srt" if not %in_mins% gtr 59 set /a in_mins=%in_mins%+1 if %in_mins% gtr 59 set in_mins=00 && set /a in_hours=%out_hours%+1 set subs_input=%out_hours%:%out_mins%:%out_secs% if not %out_mins% gtr 59 set /a out_mins=%out_mins%+1 if %out_mins% gtr 59 set out_mins=00 && set /a out_hours=%out_hours%+1 set subs_output=%out_hours%:%out_mins%:%out_secs% echo %~n1 - %c_hours%:%c_mins% >> "%~n1.srt" echo. >> "%~n1.srt" goto :update-srt :end del *.txt pause
1
00:0:00,000 --> 00:1:00,000
Christmas 2024 - 10:48
2
00:1:00,000 --> 00:2:00,000
Christmas 2024 - 10:49
3
00:2:00,000 --> 00:3:00,000
Christmas 2024 - 10:50
4
00:3:00,000 --> 00:4:00,000
Christmas 2024 - 10:51
.
.
.
Cheers. (I now have a slight headache. And I too, am tired.)
p.s. I'm not sure what will happen when the video is more than an hour long. I had nothing to test with.
I hope the in_hours and out_hours fields get incremented.Last edited by pcspeak; 29th Dec 2024 at 03:22. Reason: Improve my explanation. It was bleah!
-
-
First, let me thank you and subscript2 for your help!
Sadly, something seems amiss with you bat file. I tried it on a 3 minute MOV file and imported the SRT it created into Subtitle Edit and get this:
[Attachment 84463 - Click to enlarge]
... the resulting SRT file has each entry lasting for an hour:
Code:1 00:0:00,000 --> 00:1:00,000 IMG_8229 - 18:31 2 00:1:00,000 --> 00:2:00,000 IMG_8229 - 18:32 3 00:2:00,000 --> 00:3:00,000 IMG_8229 - 18:33 4 00:3:00,000 --> 00:4:00,000 IMG_8229 - 18:34
-
Interesting. Your post of the srt file above shows nothing in the hours field. I know the minutes field only shows a single number and not the preceding zero, as it also does here. The srt still displays correctly here. I'll look into having just the Encoded_Date displayed.
YES, it does make things easier.
Cheers. -
Did you play through the file to verify? It's working on my end. The subtitles changes every minute. My Subtitle Edit looks like yours and when I click on a line it says the duration is 60s.
As for the date all you'll have to do is change line 54 (7th to last line) to:
Code:echo %Encoded_Date% - %c_hours%:%c_mins% >> "%~n1.srt"
-
As Subscript2 says, except:
Code:echo %~n1 %Encoded_Date% - %c_hours%:%c_mins% >> "%~n1.srt"
@Subscript2. Thanks for testing. Much appreciated. Cheers. -
@pcspeak and @Subscript2 Thank you both so very much!!!
Ignore my comment about the 1 hour length, I was wrong.
I edited the 54th line and it now does just the date and it's working perfectly, exactly what I was looking for!
Hmmmm, I wonder if the author of Subtitle Edit could bake this functionality into that tool? Have it auto-generate an SRT file based off of user select-able metadata fields it pulls from MOV files and at an interval you pick?
.... eh, in the mean time, this batch file will do the job! -
Updated to script to display an extra 0 for the minutes when it's less than 10
Added a conversion from UTC to the PC's timezone with AM/PM
Changed date from YYYY-MM-DD to e.g. Sunday, December 29, 2024
Code:@echo off set counter=0 set mediainfo=C:\VidAud\MediaInfoCLI\MediaInfo.exe :start for %%a in (*.mp4, *.mkv, *.mov) do call :process "%%a" goto :end :process if exist "%~n1.srt" del /q "%~n1.srt" set video=%~1 :: Set the Encoded_Date variable. Set the clock variables c_hours, c_mins. %mediainfo% "--Output=General;%%Encoded_Date%%" "%video%" > "%~n1-clock.txt" setlocal enabledelayedexpansion for /F "usebackq tokens=1-5 delims=^:^ " %%a in ("%~n1-clock.txt") do ( set Encoded_Date=%%a set c_hours=%%b set c_mins=%%c set c_secs=%%d set Date_Time=%%aT%%b:%%c:%%d+0 ) powershell Get-Date "%Date_Time%" > "%~n1-localTime.txt" setlocal enabledelayedexpansion for /F "usebackq tokens=1-8 delims=^:^,^-^ " %%a in ("%~n1-localTime.txt") do ( set c_DayofWeek=%%a set c_Month=%%b set c_Day=%%c set c_Year=%%d set c_hours=%%e set c_mins=%%f set c_sec=%%g set c_AMPM=%%h set c_Date=%%a, %%b %%c, %%d ) :: Set the video duration in milliseconds %mediainfo% "--Output=General;%%Duration%%" "%video%" > "%~n1-duration.txt" set /p duration= < "%~n1-duration.txt" ::set the subs variables in_hours:in_mins:in_secs --^> out_hours:out_mins:out_secs. set in_hours=00 set in_mins=0 set in_secs=00,000 set out_hours=00 set out_mins=1 set out_secs=00,000 :update-srt if not %duration% gtr 0 goto :eof set /a duration=%duration%-60000 if not %c_mins% gtr 59 set /a c_mins=%c_mins%+1 if %c_mins% gtr 59 set c_mins=0 && set set /a c_hours=%c_hours%+1 set /a counter=%counter%+1 echo %counter% >> "%~n1.srt" set subs_input=%in_hours%:%in_mins%:%in_secs% set subs_output=%out_hours%:%out_mins%:%out_secs% echo %subs_input% --^> %subs_output% >> "%~n1.srt" if not %in_mins% gtr 59 set /a in_mins=%in_mins%+1 if %in_mins% gtr 59 set in_mins=00&& set /a in_hours=%out_hours%+1 set subs_input=%out_hours%:%out_mins%:%out_secs% if not %out_mins% gtr 59 set /a out_mins=%out_mins%+1 if %out_mins% gtr 59 set out_mins=00&& set /a out_hours=%out_hours%+1 set subs_output=%out_hours%:%out_mins%:%out_secs% if %c_mins% lss 10 echo %c_Date% - %c_hours%:0%c_mins%%c_AMPM% >> "%~n1.srt" if not %c_mins% lss 10 echo %c_Date% - %c_hours%:%c_mins%%c_AMPM% >> "%~n1.srt" echo. >> "%~n1.srt" goto :update-srt :end del *.txt
-
@Subscript2
EXCELLENT! Your additions to the batch file are very well done.
Sorry for the delay in responding. Life got in the way.
I must spend more time learning about PowerShell. -
-
@Subscript2
Sorry to necro this thread but as I use your amazing bat file more and more, I was wondering if you could make another change?
Every now and then, I have to extract the date/time from LOTS of .mov files and then, mash all those .mov files into a single file. The problem I'm having is combining all the SRT files into a single file and marrying it with the mashed together .mov file.
Along with creating individual SRT files from multiple .mov files, could your bat file be updated to create a single SRT file that is generated from all those individual ones?
Hope I'm explaining that correctly. -
If you are always going to display the subs then the most simple way would be to hard code the subs into the videos and then 'mash' them into a single file.
-
Similar Threads
-
Time & Date Subtitle File Generator (.srt) - Testers Required
By time2innov8 in forum SubtitleReplies: 108Last Post: 5th Feb 2024, 17:31 -
Date time change program
By Budman1 in forum Video ConversionReplies: 24Last Post: 8th May 2023, 20:29 -
Shift times of multiple .srt files at once with the same time length given
By rby03 in forum SubtitleReplies: 3Last Post: 31st Mar 2023, 18:58 -
Update date and time of a DV file
By Jaxson2198 in forum EditingReplies: 0Last Post: 24th Mar 2021, 15:52 -
Add time and date to 4k video?
By David22 in forum Video ConversionReplies: 1Last Post: 20th Feb 2021, 11:58