📜 ⬆️ ⬇️

Media Analysis

Sometimes, if you find yourself in a situation where it is not clear what kind of file a video or sound is, there is a need or desire to extract useful content from a media file.

Here, more often, YouTube comes to the rescue. Just load the file there and it does everything right. But youtube is not omnipotent.

It is clear that frank garbage fell into my hands, but curiosity took its toll and I decided to dig deeper. To begin with, I tried to do the simplest thing: I changed extensions, tried to open it with different programs, but it would not be interesting to write about it.
')
Then I tried to feed the file to the ffprobe program:

ffprobe -v quiet -print_format ini -show_format -show_streams "in" > "in.ini" 

Nothing.

 ffprobe -v quiet -print_format ini -show_format -show_streams "in.avi" > "in.avi.ini" 

Conversely, silence.

Armed with my favorite tool AutoIt.

 #include <Array.au3> #include <File.au3> RunWait("cmd /c ""ffmpeg -formats > formats.txt""") Sleep(100) $f = FileOpen("formats.txt") $s = " " $file = "in" $prev = "" $sFile = $file $descriptionFile = $sFile & ".ini" $cmd_info = "cmd /c ""ffprobe -v quiet -print_format ini -show_format -show_streams " & $sFile & " > """ & $descriptionFile & """" RunWait($cmd_info) Sleep(100) If FileGetSize($descriptionFile) > 20 Then $cmd_video = "ffmpeg -i " & $sFile & " -target dvvideo " & $sFile & ".avi" RunWait($cmd_video) Sleep(100) $cmd_audio = "ffmpeg -i " & $sFile & " -vn -c:a pcm_s16le " & $sFile & ".wav" RunWait($cmd_audio) Sleep(100) Else FileDelete($descriptionFile) EndIf While $s <> "" $s = FileReadLine($f) $ext = "." & StringMid($s, 5, StringInStr(StringMid($s, 5), " ") - 1) FileMove($file & $prev, $file & $ext, $FC_OVERWRITE) $sFile = $file & $ext $descriptionFile = $sFile & ".ini" $cmd_info = "cmd /c ""ffprobe -v quiet -print_format ini -show_format -show_streams " & $sFile & " > """ & $descriptionFile & """" RunWait($cmd_info) $prev = $ext Sleep(500) If FileGetSize($descriptionFile) > 20 Then $cmd_video = "ffmpeg -i " & $sFile & " -target dvvideo " & $sFile & ".avi" RunWait($cmd_video) Sleep(100) $cmd_audio = "ffmpeg -i " & $sFile & " -vn -c:a pcm_s16le " & $sFile & ".wav" RunWait($cmd_audio) Sleep(100) Else FileDelete($descriptionFile) EndIf WEnd FileClose($f) 

From the format description file we get codecs, substitute them as an extension, feed ffprobe. If the output of ffprobe was a file longer than 20 bytes, then we try to convert the source to dvvideo or to sound.

So, I did it all, in half an hour I already had a bunch of files with which I could already work.

Source: https://habr.com/ru/post/326754/


All Articles