Newest 'ffmpeg' Questions - Stack Overflow

Les articles publiés sur le site

  • FFMPEG distorting when resampling audio

    19 août, par jsamaudio

    I'm making an mp3 from a flac file with ffmpeg. This is usually hum-dum for me.

    Tonight, for some reason, the converted audio is distorting when I use the same commands I've always used. After troubleshooting, it appears the problem is the "-out_sample_rate" flag.

    My command:

    ffmpeg -i input.flac -write_id3v1 1 -id3v2_version 3 -dither_method modified_e_weighted -out_sample_rate 44.1k -b:a 320k output.mp3

    The audio in the mp3 is then incredibly distorted by a jacked gain resulting in digital clipping.

    I've tried updating ffmpeg, and then problem remains. I've tried converting various sample rates (44.1k source files, 48k source files, 96k source files) to both 44.1k and 48k mp3s, problem remains whenever there's a conversion.

    I'm on macOS, and I installed ffmpeg via homebrew.

    Any ideas?

  • ffmpeg inaccurate seeking keyframes with H265 vcopy

    19 août, par dsagilles

    I've got an H265 4K MP4 29.97fps video with a GOP-size of exactly 30 frames. When I try to cut from the start using :

    ffmpeg -ss 1 -i INPUT.MP4 -vcodec copy OUTPUT_1SEC.MP4
    ffmpeg -ss 2 -i INPUT.MP4 -vcodec copy OUTPUT_2SEC.MP4
    ffmpeg -ss 3 -i INPUT.MP4 -vcodec copy OUTPUT_3SEC.MP4
    ffmpeg -ss 4 -i INPUT.MP4 -vcodec copy OUTPUT_4SEC.MP4
    ffmpeg -ss 5 -i INPUT.MP4 -vcodec copy OUTPUT_5SEC.MP4
    ffmpeg -ss 6 -i INPUT.MP4 -vcodec copy OUTPUT_6SEC.MP4
    ffmpeg -ss 7 -i INPUT.MP4 -vcodec copy OUTPUT_7SEC.MP4
    ffmpeg -ss 8 -i INPUT.MP4 -vcodec copy OUTPUT_8SEC.MP4
    ffmpeg -ss 9 -i INPUT.MP4 -vcodec copy OUTPUT_9SEC.MP4

    The output videos starts at either 0 (-ss 1~4), 4 (-ss 5~8) or 8 sec (-ss 9) as shown below:

    Premiere Pro Timeline

    So it seems ffmpeg somehow detect a GOP of 4 seconds instead of 1 seconds. Is it normal ?

    Also, how can I burn the correct timecode in the output video ? For example, I tried many combinations such as:

    ffmpeg -ss 5 -i INPUT.MP4 -vcodec copy -timecode 00:00:05:00 OUTPUT_5SEC.MP4
    ffmpeg -ss 5 -i INPUT.MP4 -vcodec copy -copyts OUTPUT_5SEC.MP4
    ffmpeg -start_at_zero -ss 5 -i INPUT.MP4 -vcodec copy -copyts OUTPUT_5SEC.MP4

    But it either give me the exact timecode I put (first line) or starts at zero (two last lines)

    Originally, I was thinking about seeking at the exact second (or a few frame after) so I knew I would get a keyframe so I could guess the exact timecode the output would start, but it seems ffmpeg -ss is not exactly based on keyframes ? Maybe I'm missing something here ? Thanks for the help.

    Additionnal infos

    I'd like to script the cut process, that's why I want to know where this 4-sec "keyframe interval" come from.

    Here is the ffprobe output of my input:

    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'INPUT.MP4':
        major_brand     : isom
        minor_version   : 512
        compatible_brands: isomiso2mp41
        encoder         : Lavf57.72.101
        comment         : DE=None, Mode=M, DSW=0001
        location-{    : +XX.4914-0XX.5164+XX.000000/
        location        : +XX.4914-0XX.5164+XX.000000/
      Duration: 00:01:45.31, start: 0.000000, bitrate: 100065 kb/s
        Stream #0:0(eng): Video: hevc (Main) (hev1 / 0x31766568), yuv420p(tv, bt709), 4096x2160 [SAR 1:1 DAR 256:135], 100062 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 29.97 tbc (default)
          handler_name    : VideoHandler
        Stream #0:1(eng): Subtitle: mov_text (tx3g / 0x67337874), 2 kb/s (default)
          handler_name    : SubtitleHandler

    Here is the command I used to check gop-size ('I' type at 1,31,61,... and 'P' in between):

    ffprobe -i INPUT.MP4 -select_streams v -show_frames -show_entries frame=pict_type -of csv > OUTPUT.CSV

    ffmpeg version N-86330-gbd1179e and ffmpeg version N-86330-gbd1179e

    Edit : Sample video here

  • ffmpeg progress is freezing frames when scene change

    19 août, par Karol

    I'm capturing data from IP camera with RTSP protocol with ffmpeg with command:

    ffmpeg -rtsp_transport tcp -progress /media/kamip/stats.txt -i rtsp:// 
    -c:v copy -c:a copy -strict 1 -map 0 -f segment -strftime 1 
    -segment_time 1800 /media/kamip/cam_%d_%m_%Y_%H_%M_%S.mkv

    I'm using this for 5 cameras. One is different type and it is in different location. Because ffmpeg does not support reconnect I'm writing status to /media/kamip/stats.txt file. In another script I'm parsing this output and every 30 seconds I'm checking if frame number changed, if yes - it is ok, if not, I'm restarting above command.

    The problem is only in the night. When is quite dark and suddenly lights on, for example when car is parking, the /media/kamip/stats.txt is showing the same frame number, so my script is recognizing this as a lost connection (video freeze)

    I tried "-strict 1" option and I think it is better (one false alarm per day instead of 10 per day), so I think this may be related to ffmpeg, not camera/video source, especially because the video is fine even frame number reported by ffmpeg is still the same. Also VLC does not have this kind of problem (but I cannot use it currently for this camera)

    I found that ffmpeg has build-in scene change detector, but it should works only when encoding video (I'm using "copy" option for audio and video)?

    I'm thinking about different way of analyzing the video capturing, but this "-progress" in ffmpeg should works fine - and it is working fine for other cameras for few years).

    I also do not see any errors, when I encoded one cutted file with "-loglevel debug" I saw only information like below:

    [libx264 @ 0x25d77a0] scene cut at 174 Icost:2049115 Pcost:2006553 
    ratio:0.0208 bias:0.1387 gop:54 (imb:3186 pmb:168)

    ffmpeg in latest version

    ffmpeg version 3.3.3-1ubuntu1~16.04.york0 Copyright (c) 2000-2017 the FFmpeg developers built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.4) 20160609

    any help will be appreciated

  • Add watermark on ffmpeg stream

    19 août, par Michael Rodriguez

    How i can add watermark with text or image on ffmpeg stream ? This is my command :

    ffmpeg -re -i "input.mp4" -c:v copy -c:a aac -ar 44100 -ab 128k -ac 2 -strict -2
        -flags +global_header -bsf:a aac_adtstoasc -f flv "rtmp://"
  • Ffmpeg streaming from capturing device Osprey 450e fails

    19 août, par diegonaranjo

    i want to encode live stream video with ffmpeg capturing from Directshow card(Osprey Card 450e) to mp4 streaming multicast. For the moment i have this error.

    ffmpeg -f dshow -i video="Osprey-450e Video Device 1A":audio="Osprey-450e Audio Device 1A" -f mpegts -b:v 5120k -r 30 -c:v mpeg2video -c:a ac3 -b:a 256k udp://
    [dshow @ 02c7f640] Could not run filter video=Osprey-450e Video Device 1A:Audio?Osprey-450e Audio Device 1A: Input/output error

    Ffmpeg can encode a Directshow input?