Recherche avancée

Médias (0)

Mot : - Tags -/alertes

Aucun média correspondant à vos critères n’est disponible sur le site.

Autres articles (50)

Sur d’autres sites (9112)

  • Haskell - Turning multiple image-files into one video-file using the ffmpeg-light package

    25 avril 2021, par oRole

    Background
    
I wrote an application for image-processing which uses the ffmpeg-light package to fetch all the frames of a given video-file so that the program afterwards is able to apply grayscaling, as well as edge detection alogrithms to each of the frames.

    


    Now I'm trying to put all of the frames back into a single video-file.

    


    Used Libs
    
ffmpeg-light-0.12.0
    
JuicyPixels-3.2.8.3
    
...

    


    What have I tried ?
    
I have to be honest, I didn't really try anything because I'm kinda clueless where and how to start. I saw that there is a package called Command which allows running processes/commands using the command line. With that I could use ffmpeg (not ffmpeg-light) to create a video out of image-files which I would have to save to the hard drive first but that would be kinda hacky.

    
Within the documentation of ffmpeg-light on hackage (ffmpeg-light docu) I found the frameWriter function which sounds promising.

    


    frameWriter :: EncodingParams -> FilePath -> IO (Maybe (AVPixelFormat, V2 CInt, Vector CUChar) -> IO ()) 


    


    I guess FilePath would be the location where the video file gets stored but I can't really imagine how to apply the frames as EncodingParams to this function.

    


    Others
    
I can access :

    


      

    • r, g, b, a as well asy. a values
    • 


    • image width / height / format
    • 


    


    Question
    
Is there a way to achieve this using the ffmpeg-light package ?

    


    As the ffmpeg-light package lacks of documentation when it comes to conversion from images to video, I really would appreciate your help. (I do not expect a fully working solution.)

    


    Code
    
The code that reads the frames :

    


    -- Gets and returns all frames that a given video contains
getAllFrames :: String -> IO [(Double, DynamicImage)]
getAllFrames vidPath = do 
  result <- try (imageReaderTime $ File vidPath) :: IO (Either SomeException (IO (Maybe (Image PixelRGB8, Double)), IO()))
  case result of 
    Left ex -> do 
                 printStatus "Invalid video-path or invalid video-format detected." "Video" 
                 return []
    Right (getFrame, _) -> addNextFrame getFrame [] 

-- Adds up all available frames to a video.
addNextFrame :: IO (Maybe (Image PixelRGB8, Double)) -> [(Double, DynamicImage)] -> IO [(Double, DynamicImage)]
addNextFrame getFrame frames = do
  frame <- getFrame
  case frame of 
    Nothing -> do 
                 printStatus "No more frames found." "Video"
                 return frames
    _       -> do                             
                 newFrameData <- fmap ImageRGB8 . swap . fromJust <$> getFrame 
                 printStatus ("Frame: " ++ (show $ length frames) ++ " added.") "Video"
                 addNextFrame getFrame (frames ++ [newFrameData]) 


    


    Where I am stuck / The code that should convert images to video :

    


    -- Converts from several images to video
juicyToFFmpeg :: [Image PixelYA8] -> ?
juicyToFFmpeg imgs = undefined


    


  • Script to cut video by silence part with FFMPEG

    11 février 2020, par fricadelle

    This is a question that is raised here How to split video or audio by silent parts or here How can I split an mp4 video with ffmpeg every time the volume is zero ?

    So I was able to come up with a straightforward bash script that works on my Mac.

    Here it is (only argument is the name of the video to be cut, it will generate a file start_timestamps.txt with the list of silence starts if the file does not exist and reuse it otherwise) :

    #!/bin/bash

    INPUT=$1

    filename=$(basename -- "$INPUT")
    extension="${filename##*.}"
    filename="${filename%.*}"

    SILENCE_DETECT="silence_detect_logs.txt"
    TIMESTAMPS="start_timestamps.txt"

    if [ ! -f $TIMESTAMPS ]; then
       echo "Probing start timestamps"
       ffmpeg -i "$INPUT" -af "silencedetect=n=-50dB:d=3" -f null - 2> "$SILENCE_DETECT"
       cat "$SILENCE_DETECT"| grep "silence_start: [0-9.]*" -o| grep -E '[0-9]+(?:\.[0-9]*)?' -o > "$TIMESTAMPS"
    fi

    PREV=0.0
    number=0

    cat "$TIMESTAMPS"| ( while read ts
    do
       printf -v fname -- "$filename-%02d.$extension" "$(( ++number ))"
       DURATION=$( bc <<< "$ts - $PREV")
       ffmpeg -y -ss "$PREV" -i "$INPUT" -t "$DURATION" -c copy "$fname"
       PREV=$ts
    done
    printf -v fname -- "$filename-%02d.$extension" "$(( ++number ))"
    ffmpeg -y -ss "$PREV" -i "$INPUT" -c copy "$fname" )

    Unfortunately it does not seem to work :

    I have a video that is basically a collection of clips, each clip being introduced by a 5 second silence with a static frame with a title on it. So I want to cut the original video so that each chunk is the 5 seconds "introduction" + video until the next introduction. Hope it’s clear.

    Anyway, in my script I first find all silence_start using ffmpeg silencedetect plugin. I get a start_timestamps.txt that read :

    141.126
    350.107
    1016.07
    etc.

    Then for example I would call (I don’t need to transcode again the video), knowing that (1016.07 - 350.107) = 665.963

    ffmpeg -ss 350.107 -i Some_video.mp4 -t 665.963 -c copy "Some_video02.mp4"

    The edge cases being the first chunk that has to go from 0 to 141.126 and the last chunk that has to go from last timestamp to end of the video.

    Anyway the start_timestamps seem legit. But my output chunks are completely wrong. Sometimes the video does not even play anymore in Quicktime. I don’t even have my static frame with the title in any of the videos...

    Hope someone can help. Thanks.

    EDIT Ok as explained in the comments, if I echo $PREV while commenting out the ffmpeg command I get a perfectly legit list of values :

    0.0
    141.126
    350.107
    1016.07
    etc.

    With the ffmpeg command I get :

    0.0
    141.126
    50.107
    016.07
    etc.

    bash variable changes in loop with ffmpeg shows why.

    I just need to append < /dev/null to the ffmpeg command or add -nostdin argument. Thanks everybody.

  • mpegvideo : drop support for real (non-emulated) edges

    20 décembre 2013, par Anton Khirnov
    mpegvideo : drop support for real (non-emulated) edges
    

    Several decoders disable those anyway and they are not measurably faster
    on x86. They might be somewhat faster on other platforms due to missing
    emu edge SIMD, but the gain is not large enough (and those decoders
    relevant enough) to justify the added complexity.

    • [DBH] libavcodec/mpegvideo.c
    • [DBH] libavcodec/mpegvideo.h
    • [DBH] libavcodec/mpegvideo_enc.c
    • [DBH] libavcodec/mpegvideo_motion.c
    • [DBH] libavcodec/mss2.c
    • [DBH] libavcodec/rv10.c
    • [DBH] libavcodec/rv34.c
    • [DBH] libavcodec/svq3.c
    • [DBH] libavcodec/vc1dec.c
    • [DBH] libavcodec/wmv2.c