Recherche avancée

Médias (91)

Sur d’autres sites (114)

  • how to extract a metadata track from MP4 file

    30 août 2019, par ravi

    I need to extract metadata track from a MP4 file and save as separate file. I see that, using ffmpeg I can extract standard tracks like Audio or Video or Subtitle track and save it as a new file. For ex : to save audio track I use the command below :

    ffmpeg -i input-video.avi -vn -acodec copy output-audio.aac

    But my need is to save a proprietary metadata track. Any pointers will be helpful.

    Here is output of ffmpeg to know different traks that are present in the file. Particuarly, I am interested in extracting track corresponding to Stream #0:3(eng)...

    C:\Users\rkumar\Documents\work\tools\ffmpeg\bin>ffmpeg.exe -i input.MP4
    ffmpeg version N-57176-g64b3aaf Copyright (c) 2000-2013 the FFmpeg developers
    built on Oct 15 2013 21:32:52 with gcc 4.8.1 (GCC)

    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.MP4':
    Metadata:
    major_brand     : mp41
    minor_version   : 538120216
    compatible_brands: mp41
    creation_time   : 1970-01-01 00:00:09
    Duration: 00:00:10.52, start: 0.000000, bitrate: 834 kb/s

    Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuvj420p(pc, bt709),
    854x480 [SAR 1:1 DAR 427:240], 679 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc (default)
    Metadata:
    creation_time   : 1970-01-01 00:00:09
    handler_name    : AVC
    timecode        : 00:00:13:22

    Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
    creation_time   : 1970-01-01 00:00:09
    handler_name    : AAC
    timecode        : 00:00:13:22

    Stream #0:2(eng): Data: none (tmcd / 0x64636D74), 0 kb/s (default)
    Metadata:
    creation_time   : 1970-01-01 00:00:09
    handler_name    : TCD
    timecode        : 00:00:13:22

    Stream #0:3(eng): Data: none (ssmd / 0x646D7067), 5 kb/s (default)
    Metadata:
    creation_time   : 1970-01-01 00:00:09
    handler_name    : MET

    Stream #0:4(eng): Data: none (fdsc / 0x63736466), 10 kb/s (default)
    Metadata:
    creation_time   : 1970-01-01 00:00:09
    handler_name    : SOS
  • Can you put the result of a blackdetect filter in a textfile using ffmpeg ?

    18 novembre 2020, par Gijserman

    I'm testing out the "blackdetect" filter in ffmpeg. I want to have the times when the video is black to be read by a script (like actionscript or javascript). I tried :

    



    ffmpeg -i video1.mp4 -vf "blackdetect=d=2:pix_th=0.00" -an -f null -


    



    And I get a nice result in the ffmpeg log :

    



    ffmpeg version N-55644-g68b63a3 Copyright (c) 2000-2013 the FFmpeg developers
  built on Aug 19 2013 20:32:00 with gcc 4.7.3 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-av
isynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enab
le-iconv --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetyp
e --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --ena
ble-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-l
ibopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libsp
eex --enable-libtheora --enable-libtwolame --enable-libvo-aacenc --enable-libvo-
amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --
enable-libxvid --enable-zlib
  libavutil      52. 42.100 / 52. 42.100
  libavcodec     55. 28.100 / 55. 28.100
  libavformat    55. 13.103 / 55. 13.103
  libavdevice    55.  3.100 / 55.  3.100
  libavfilter     3. 82.100 /  3. 82.100
  libswscale      2.  5.100 /  2.  5.100
  libswresample   0. 17.103 /  0. 17.103
  libpostproc    52.  3.100 / 52.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video1.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    creation_time   : 1970-01-01 00:00:00
    encoder         : Lavf53.13.0
  Duration: 00:02:01.54, start: 0.000000, bitrate: 275 kb/s
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 768x432 [
SAR 1:1 DAR 16:9], 211 kb/s, 25 fps, 25 tbr, 25 tbn, 50 tbc
    Metadata:
      creation_time   : 1970-01-01 00:00:00
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 59
 kb/s
    Metadata:
      creation_time   : 1970-01-01 00:00:00
      handler_name    : SoundHandler
Output #0, null, to 'pipe:':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf55.13.103
    Stream #0:0(eng): Video: rawvideo (I420 / 0x30323449), yuv420p, 768x432 [SAR
 1:1 DAR 16:9], q=2-31, 200 kb/s, 90k tbn, 25 tbc
    Metadata:
      creation_time   : 1970-01-01 00:00:00
      handler_name    : VideoHandler
Stream mapping:
  Stream #0:0 -> #0:0 (h264 -> rawvideo)
Press [q] to stop, [?] for help
[null @ 00000000003279a0] Encoder did not produce proper pts, making some up.
[blackdetect @ 0000000004d5e800] black_start:0 black_end:17.08 black_duration:17
.08
[blackdetect @ 0000000004d5e800] black_start:62.32 black_end:121.48 black_durati
on:59.16
frame= 3038 fps=2317 q=0.0 Lsize=N/A time=00:02:01.52 bitrate=N/A
video:285kB audio:0kB subtitle:0 global headers:0kB muxing overhead -100.007543%


    



    And I'm particularly interested in this part :

    



    [blackdetect @ 0000000004e2e340] black_start:0 black_end:17.08 black_duration:17.08
[blackdetect @ 0000000004e2e340] black_start:62.32 black_end:121.48 black_duration:59.16


    



    So my question :

    



      

    1. Is there a way to only take the blackdetect filter output and put it in a .txt file ?
    2. 


    3. And if this is possible, is there a way to do this in a statement with multiple video inputs ? Like in this example
    4. 


    




    



    example :

    



    ffmpeg -f concat -i mylist.txt -c copy concat.mp4


    



    Where mylist.txt is a list of videos :

    



    file 'video1.mp4'
file 'video2.mp4'
file 'video3.mp4'
file 'video4.mp4'


    




    



    Basically what I want to have is one or more text files containing information about the black frames in every video in this list to be used by another program

    


  • RTP Timestamps Are Not Monotonically increasing

    25 août 2019, par Fr0sty

    I am finding it a bit difficult trying to understand whether or not the hack around with FFmpeg and OpenCV really provided a RTP timestamp. My last post helped a little bit but got me stuck in trying to validate the timestamps obtained through this work around by modifying ffmpeg and opencv.

    FFmpeg version : 4.1.0
    OpenCV version : 3.4.1

    import cv2
    import time
    from datetime import datetime, date

    uri = 'rtsp://admin:password@192.168.1.66:554/Streaming/Channels/101'
    cap = cv2.VideoCapture(uri)
    '''One is the offset between the two epochs. Unix uses an epoch located at 1/1/1970-00:00h (UTC) and NTP uses 1/1/1900-00:00h.
    This leads to an offset equivalent to 70 years in seconds (there are 17 leap years between the two dates so the offset is'''
    time_offset = 2208988800 # (70*365 + 17)*86400 = 2208988800 (in seconds)
    # offset = 3775484294
    days = 43697
    pdat = "1900-01-01 00:00:00:00"
    mdat = "2019-08-23 22:02:44:00" # str(datetime.now()) + str(datetime.now().time())
    pdate = datetime.strptime(pdat, "%Y-%m-%d %H:%M:%S:%f").date()
    mdate = datetime.strptime(mdat, "%Y-%m-%d %H:%M:%S:%f").date()
    delta = (mdate - pdate).days
    offset = delta * 86400
    def time_delta(s):
       return (s - time_offset)

    while True:
       frame_exists, curr_frame = cap.read()
       if frame_exists:
           seconds = cap.getRTPTimeStampSeconds()
           fraction = cap.getRTPTimeStampFraction()
           timestamp = cap.getRTPTimeStampTs()
           unix_offset = seconds - time_offset
           msec = int((int(fraction) / 0xFFFFFFFF) * 1000.0)
           ts = float(str(unix_offset) + "." + str(msec))
           # print("Timestamp per Frame:%i" % timestamp)
           print((datetime.fromtimestamp(float(ts) + offset)))
    cap.release()

    My Output :

    On August 23, 2019 at 22:02

    ...
    2019-08-23 13:59:52.781000
    2019-08-23 13:59:52.726000
    2019-08-23 13:59:52.671000
    2019-08-23 13:59:52.616000
    2019-08-23 13:59:52.561000
    2019-08-23 13:59:52.506000
    2019-08-23 13:59:52.451000
    2019-08-23 13:59:52.396000
    2019-08-23 13:59:52.342000
    2019-08-23 13:59:52.287000
    2019-08-23 13:59:52.232000
    2019-08-23 13:59:52.177000
    2019-08-23 13:59:52.122000
    2019-08-23 13:59:52.067000
    2019-08-23 13:59:52.012000
    2019-08-23 13:59:53.570000
    2019-08-23 13:59:53.020000
    2019-08-23 13:59:53.847000
    2019-08-23 13:59:53.792000

    I’ve noticed how the time increments weirdly (that’s not suppose to happen in the real, current time), such as the last two lines and a few others in between in the output. A bit flabbergasted as to what went wrong. Also trying this out on multiple IP cameras, with each showing a different timestamp probably related to when they were turned on.