Recherche avancée

Médias (33)

Mot : - Tags -/creative commons

Sur d’autres sites (346)

  • AVCodec h264_v4l2m2m hardware decoding unable to find device

    26 juillet 2023, par nathansizemore

    Using a custom compiled FFmpeg :

    


     $ ./ffmpeg -codecs | grep h264
ffmpeg version n6.0 Copyright (c) 2000-2023 the FFmpeg developers
  built with gcc 7 (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04)
  configuration: --arch=aarch64 --enable-cross-compile --target-os=linux --cross-prefix=aarch64-linux-gnu- --prefix=/builds/dronesense/rust/ffmpeg-build/ffmpeg/out --pkgconfigdir= --pkg-config=pkg-config --extra-libs='-ldl -lpthread' --enable-libvpx --enable-libx264 --enable-libx265 --enable-decklink --enable-gpl --enable-nonfree --enable-shared --disable-static
  libavutil      58.  2.100 / 58.  2.100
  libavcodec     60.  3.100 / 60.  3.100
  libavformat    60.  3.100 / 60.  3.100
  libavdevice    60.  1.100 / 60.  1.100
  libavfilter     9.  3.100 /  9.  3.100
  libswscale      7.  1.100 /  7.  1.100
  libswresample   4. 10.100 /  4. 10.100
  libpostproc    57.  1.100 / 57.  1.100
 DEV.LS h264                 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (decoders: h264 h264_v4l2m2m ) (encoders: libx264 libx264rgb h264_v4l2m2m )


    


    /dev/video32 seems to have H.264 decoding support :

    


    $ v4l2-ctl --list-formats-out -d /dev/video32
ioctl: VIDIOC_ENUM_FMT
    Index       : 0
    Type        : Video Output Multiplanar
    Pixel Format: 'MPG2' (compressed)
    Name        : MPEG-2 ES

    Index       : 1
    Type        : Video Output Multiplanar
    Pixel Format: 'H264' (compressed)
    Name        : H.264

    Index       : 2
    Type        : Video Output Multiplanar
    Pixel Format: 'HEVC' (compressed)
    Name        : HEVC

    Index       : 3
    Type        : Video Output Multiplanar
    Pixel Format: 'VP80' (compressed)
    Name        : VP8

    Index       : 4
    Type        : Video Output Multiplanar
    Pixel Format: 'VP90' (compressed)
    Name        : VP9


    


    I've tried two approaches (Rust with bindgen) :

    


    Approach 1 :

    


    fn init_decoder() -> Arc<contextwrapper> {&#xA;    let name = CString::new("h264_v4l2m2m").unwrap();&#xA;    let codec = unsafe { ffmpeg::avcodec_find_decoder_by_name(name.as_ptr()) };&#xA;    if codec.is_null() {&#xA;        error!("finding codec");&#xA;        process::exit(1);&#xA;    }&#xA;&#xA;    let ctx = unsafe { ffmpeg::avcodec_alloc_context3(codec) };&#xA;    if ctx.is_null() {&#xA;        error!("creating context");&#xA;        process::exit(1);&#xA;    }&#xA;&#xA;    let r = unsafe { ffmpeg::avcodec_open2(ctx, codec, ptr::null_mut()) };&#xA;    if r &lt; 0 {&#xA;        error!("opening codec: {r}");&#xA;        process::exit(1);&#xA;    }&#xA;&#xA;    Arc::new(ContextWrapper(ctx))&#xA;}&#xA;</contextwrapper>

    &#xA;

    Results in :

    &#xA;

    [h264_v4l2m2m @ 0x7f1c001600] Could not find a valid device&#xA;[h264_v4l2m2m @ 0x7f1c001600] can&#x27;t configure decoder&#xA;[ERROR] [decoder] [webrtc::codec] opening codec: -1&#xA;

    &#xA;

    Approach 2

    &#xA;

    fn init_decoder() -> Arc<contextwrapper> {&#xA;    let name = CString::new("h264_v4l2m2m").unwrap();&#xA;    let codec = unsafe { ffmpeg::avcodec_find_decoder_by_name(name.as_ptr()) };&#xA;    if codec.is_null() {&#xA;        error!("finding codec");&#xA;        process::exit(1);&#xA;    }&#xA;&#xA;    let mut i = 0;&#xA;    let mut hw_pix_fmt: AVPixelFormat = unsafe { mem::zeroed() };&#xA;    loop {&#xA;        let config = unsafe { ffmpeg::avcodec_get_hw_config(codec, i) };&#xA;        if config.is_null() {&#xA;            error!("decoder not supported");&#xA;            process::exit(1);&#xA;        }&#xA;&#xA;        unsafe {&#xA;            info!("device type: {:?}", (*config).device_type);&#xA;            if ((*config).methods &amp; ffmpeg::AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX as i32) > 0 {&#xA;                hw_pix_fmt = (*config).pix_fmt;&#xA;                break;&#xA;            }&#xA;        }&#xA;    }&#xA;&#xA;    info!("pixel format: {:?}", hw_pix_fmt);&#xA;&#xA;    let ctx = unsafe { ffmpeg::avcodec_alloc_context3(codec) };&#xA;    if ctx.is_null() {&#xA;        error!("creating context");&#xA;        process::exit(1);&#xA;    }&#xA;&#xA;    let r = unsafe { ffmpeg::avcodec_open2(ctx, codec, ptr::null_mut()) };&#xA;    if r &lt; 0 {&#xA;        error!("opening codec: {r}");&#xA;        process::exit(1);&#xA;    }&#xA;&#xA;    Arc::new(ContextWrapper(ctx))&#xA;}&#xA;&#xA;</contextwrapper>

    &#xA;

    Results in :&#xA;error!("decoder not supported");

    &#xA;

    I feel like there is a major step missing because looking at FFmpeg's Hardware Decode Example there are looking for a device type, to which v4l2 is not a part of the enum, so I do not what functions to call to get it setup.

    &#xA;

    What is the proper way to setup an AVCodec decoder with H.264 hardware acceleration for v4l2m2m ?

    &#xA;

  • Everytime I run my code ffmpeg responds with this instead of doing its function. How do I fix ?

    25 juillet 2023, par Oreo F
    Output from ffmpeg/avlib:&#xA;&#xA;ffmpeg version 2023-07-19-git-efa6cec759-full_build-www.gyan.dev Copyright (c) 2000-2023 the FFmpeg developers&#xA;  built with gcc 12.2.0 (Rev10, Built by MSYS2 project)&#xA;  configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libaribb24 --enable-libaribcaption --enable-libdav1d --enable-libdavs2 --enable-libuavs3d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libaom --enable-libjxl --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-libharfbuzz --enable-liblensfun --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libvpl --enable-libshaderc --enable-vulkan --enable-libplacebo --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libcodec2 --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint&#xA;  libavutil      58. 14.100 / 58. 14.100&#xA;  libavcodec     60. 22.100 / 60. 22.100&#xA;  libavformat    60. 10.100 / 60. 10.100&#xA;  libavdevice    60.  2.101 / 60.  2.101&#xA;  libavfilter     9.  8.102 /  9.  8.102&#xA;  libswscale      7.  3.100 /  7.  3.100&#xA;  libswresample   4. 11.100 /  4. 11.100&#xA;  libpostproc    57.  2.100 / 57.  2.100&#xA;

    &#xA;

    Everytime I run the code it does this.

    &#xA;

    code :

    &#xA;

    import praw&#xA;import requests&#xA;import cv2&#xA;import os&#xA;from pydub import AudioSegment&#xA;&#xA;def download_video(url, filename):&#xA;    response = requests.get(url)&#xA;    with open(filename, &#x27;wb&#x27;) as f:&#xA;        f.write(response.content)&#xA;&#xA;def combine_videos(video_urls, output_filename):&#xA;    video_clips = []&#xA;    audio_clips = []&#xA;    for i, url in enumerate(video_urls):&#xA;        temp_filename = f&#x27;temp_video_{i}.mp4&#x27;&#xA;        download_video(url, temp_filename)&#xA;        video_clip = cv2.VideoCapture(temp_filename)&#xA;        audio_clip = AudioSegment.from_file(temp_filename, format="mp4")&#xA;        video_clips.append(video_clip)&#xA;        audio_clips.append(audio_clip)&#xA;    &#xA;    if not video_clips:&#xA;        print("No video clips to combine.")&#xA;        return&#xA;&#xA;    frame_width = int(video_clips[0].get(cv2.CAP_PROP_FRAME_WIDTH))&#xA;    frame_height = int(video_clips[0].get(cv2.CAP_PROP_FRAME_HEIGHT))&#xA;    fps = int(video_clips[0].get(cv2.CAP_PROP_FPS))&#xA;&#xA;    fourcc = cv2.VideoWriter_fourcc(*&#x27;mp4v&#x27;)&#xA;    output_clip = cv2.VideoWriter(output_filename, fourcc, fps, (frame_width, frame_height))&#xA;&#xA;    for i, video_clip in enumerate(video_clips):&#xA;        while True:&#xA;            ret, frame = video_clip.read()&#xA;            if not ret:&#xA;                break&#xA;            output_clip.write(frame)&#xA;    &#xA;    for video_clip in video_clips:&#xA;        video_clip.release()&#xA;    &#xA;    output_clip.release()&#xA;&#xA;    # Combining audio using pydub&#xA;    combined_audio = sum(audio_clips)&#xA;    combined_audio.export("combined_audio.mp3", format="mp3")&#xA;&#xA;    # Merging audio with video using ffmpeg&#xA;    os.system(f&#x27;ffmpeg -i {output_filename} -i combined_audio.mp3 -c:v copy -c:a aac -strict experimental -map 0:v:0 -map 1:a:0 final_output.mp4&#x27;)&#xA;&#xA;    # Cleaning up temporary files&#xA;    os.remove("combined_audio.mp3")&#xA;&#xA;def main():&#xA;    reddit = praw.Reddit(&#xA;       client_id=&#x27;XXX&#x27;,&#xA;        client_secret=&#x27;XXX&#x27;,&#xA;        user_agent=&#x27;Reddit Video Downloader&#x27;&#xA;    )&#xA;    &#xA;    subreddit_name = input("Enter the name of the subreddit: ")&#xA;    limit = int(input("Enter the number of videos to download: "))&#xA;    &#xA;    subreddit = reddit.subreddit(subreddit_name)&#xA;    submissions = subreddit.hot(limit=limit)&#xA;    &#xA;    video_urls = [submission.url for submission in submissions if submission.media and &#x27;reddit_video&#x27; in submission.media]&#xA;    &#xA;    if video_urls:&#xA;        output_filename = input("Enter the output filename (e.g., output.mp4): ")&#xA;        combine_videos(video_urls, output_filename)&#xA;        print("Videos combined successfully!")&#xA;    else:&#xA;        print("No Reddit videos found in the subreddit.")&#xA;&#xA;if __name__ == "__main__":&#xA;    main()&#xA;

    &#xA;

    Anyone got any idea why this happens ?

    &#xA;

    I'm making a script that scrapes videos from a specific subreddit.

    &#xA;

    Also if it helps the temp video file is corrupted when it gets made.

    &#xA;

    I've put this into chatGPT as well and brought an expert friend and he hasn't been able to help me.

    &#xA;

  • FFMPEG Fontconfig error : Cannot load default config file : No such file : (null) Abort trap

    28 juillet 2023, par FastNumbers

    /usr/local/bin/ffmpeg -loop 1 -t 11.14 -i 3339861349.jpg -filter_complex "drawtext=text=aaaaa" -r 25 -vcodec libx264 -preset veryfast -threads 8 -x264opts no-scenecut -b 850k -bt 850k -ac 2 -ab 32k -async 1 -y -f mp4 test.mp4&#xA;Give me result&#xA;Fontconfig error : Cannot load default config file : No such file : (null)&#xA;Abort trap

    &#xA;

    With path to font file :&#xA;/usr/local/bin/ffmpeg -loop 1 -t 11.14 -i 3339861349.jpg -filter_complex "drawtext=text=aaaaa:fontfile=/usr/local/share/fonts/Roboto-Regular.ttf" -r 25 -vcodec libx264 -preset veryfast -threads 8 -x264opts no-scenecut -b 850k -bt 850k -ac 2 -ab 32k -async 1 -y -f mp4 test.mp4&#xA;Give me result&#xA;Abort trap

    &#xA;

    Rebild ffmpeg with —enable-libfontconfig

    &#xA;

    ffmpeg version 6.0-6.0 Copyright (c) 2000-2023 the FFmpeg developers&#xA;built with FreeBSD clang version 13.0.0 (git@github.com:llvm/llvm-project.git llvmorg-13.0.0-0-gd7b669b3a303)&#xA;configuration : —enable-gpl —enable-gmp —enable-gnutls —enable-libdav1d —enable-libsvtav1 —enable-librav1e —enable-libvmaf —enable-libx264 —enable-chromaprint —enable-libx265 —enable-libvpx —enable-libxvid —enable-libvidstab —enable-libaom —enable-libzimg —enable-libmodplug —enable-libsoxr —enable-libmysofa —enable-lv2 —enable-libopencore_amrnb —enable-libopencore_amrwb —enable-libmp3lame —enable-libopus —enable-libvorbis —enable-libtwolame —enable-libspeex —enable-lv2 —enable-libtheora —enable-librubberband —enable-libgme —enable-libwebp —enable-libzmq —enable-libfribidi —enable-libfontconfig —enable-libfreetype —enable-libass —enable-runtime-cpudetect —cc=cc —cxx=cpp —disable-ffplay —disable-debug —disable-doc —disable-shared —enable-pthreads —enable-static —enable-small —enable-version3 —extra-cflags='-static -I/usr/home/azureagent/vsts/_work/1/s/FFmpeg/workspace/include -I/usr/home/azureagent/vsts/_work/1/s/FFmpeg/workspace/include/lilv-0 -I/usr/home/azureagent/vsts/_work/1/s/FFmpeg/workspace/include/lilv-0' —extra-cxxflags='-static -static-libstdc++' —extra-ldexeflags= —extra-ldflags=-L/usr/home/azureagent/vsts/_work/1/s/FFmpeg/workspace/lib —extra-libs='-static -lc++ -ldl -lpthread -lm -lmd -lz -lfftw3' —pkgconfigdir=/usr/home/azureagent/vsts/_work/1/s/FFmpeg/workspace/lib/pkgconfig —pkg-config-flags=—static —prefix=/usr/home/azureagent/vsts/_work/1/s/FFmpeg/workspace/done/ —extra-version=6.0

    &#xA;