Newest 'ffmpeg' Questions - Stack Overflow

http://stackoverflow.com/questions/tagged/ffmpeg

Les articles publiés sur le site

  • Nginx rtmp module - on_publish fires multiple time instead of once

    29 juillet 2017, par Stephen Wright

    This is copy and pasted from the bug report I created on the rtmp-module by Arut, I am not completely sure if it is a bug or me not understanding how the module works, I have read the whole directives of module as from https://github.com/arut/nginx-rtmp-module/wiki/Directives

    Proper explanation, if code is not displayed properly I will edit and fix

    Hi, been using the module and finding it very very good!

    Think I have found a issue though, although it may be me misunderstanding the directives.

    Essentially I wish to fire a script (/usr/local/bin/make_thumbnail.sh) which creates a thumbnail automatically from a stream (using ffmpeg), the idea is to have this done for every stream as soon as it is published in order to create a function a bit like twitch tv where the streamer will not have to specify any thumbnail image, authenticated users simply start a stream (which will later be authenticated but is not yet) The script does also write data into the database however this stage works fine and I don't believe the issue is related, if I comment out these lines then the thumbnail creation still works and my issue continues.

    Initially this was done using the "exec" command as I believe I mis-read the documentation and I believe the exec command doesn't work for my problem as ". When publishing stops the process is terminated." does this mean it will continually execute until stream stops?

    I have started using the exec_publish command to try and fix this issue however the same issue seems to occur. The entire script repeats approximately every 15-17 seconds, a new thumbnail is created and a new database entry is create with all the correct information.

    Below is the nginx.conf line. Please ignore if indentation is incorrect couldn't see a way to indent blocks of code and it's late here, assume all code is indented correctly unless you believe that could be the issue in which case I will post it indented as early as I can.

    application live {
    allow play all;
    live on;
    record all;
    record_path /var/stream/video_recordings/;
    record_unique on; 
    hls on;
    hls_nested on;
    hls_path /var/stream/HLS/live;
    hls_fragment 10s;
    
    #on publish create thumbnail using first second of stream and save in 
    /var/stream/video_recordings/thumbnails
    exec_publish usr/local/bin/make_thumbnail.sh $name;
    

    The rest can be pasted or attached if needed but is working nginx config for rtmp + website

    The most simple version of the make_thumbnail..sh is pasted below, I have omitted the variables that I have used for database entryys obviously but as the script works without fail from terminal I believe this to be an nginx issue (if I run the command manually under the nginx user e.g. sudo -u nginx /usr/local/bin/make_thumbnail.sh with a name the same as any running stream, it works and only executes once as would expect, all permissions in script are ok and tested.

    make_thumbnail.sh

    #!/bin/bash
    
    TIME=$(date +%s)
    NAME=$1 
    echo "time: "
    FILENAME=${TIME}_${NAME}
    
    ffmpeg -i rtmp://192.168.0.98:1935/live/$1 -vframes 1 -s 150x150 -ss 10 -
    strftime 1 /var/stream/video_recordings/thumbnails/"$FILENAME.jpg";
    
    #Writes path to video into database
    mysql --user=$DB_USER --password=$DB_PASSWD $DB_NAME << EOF
    INSERT INTO $TABLE3 (thumbnailfile) VALUES ('$FILENAME');
    set @last_id_in_thumbnails = LAST_INSERT_ID();
    INSERT INTO $TABLE (created_at, updated_at, thumnailID) VALUES 
    (NOW(),NOW(),@last_id_in_thumbnails);
    SET @last_id_in_livestreams = LAST_INSERT_ID();
    INSERT INTO $TABLE2 (created_at, updated_at, filename,liveID) VALUES 
    (NOW(),NOW(),'$FILENAME',@last_id_in_livestreams); 
    EOF
    

    I have not got the nginx rtmp logs installed, I can obviously do this however some of the logs appear in the nginx error.log, strangely the latest stream I tried did not update in the access log, however I think this is because I did not attempt to connect to it via any method. I don't fully understand the error.log, in my stupidity I decided to use nginx with which I am quite inexperienced and I am finding it very difficult to troubleshoot this issue, it appears to me that as part of the RTMP protocol or my streaming software (OBS) is either directly pinging the rtmp stream or is being pinged by the server to ensure the connection is still there. And this ping is

    I have left a stream running from approx 4 minutes without interacting with the server, streaming software, computer running the stream, I have ensured the internet connection is constant as my first though was the connection dropped, however on inspecting the database the executing is done always after at least 11 seconds however usually this is 16, I can't seem to figure out how to select the closest dates from the database however there has been at least a few 17 second differences (potentially when I am unsure if this is an issue or if it is intended behavior but I do require this to finish a university degree, I'm not asking for answers but if it is a legitimate issue then I would be happy to spend as much time I can commit to it if some insight into what is causing it, or if there is a workaround I believe it should be documented somewhere, I have googled into making any exec commands run only once on publish

    I can't seem to pinpoint where in the log the issue is happening however think it is something to do with the below exceprts I would attach the file but can't seem to select all lines after the timestamp upon starting a stream

    2017/07/26 18:17:35 [info] 1451#0: *2229 exec: starting managed child 
    'ffmpeg', client: 192.168.0.78, server: 0.0.0.0:1935
    2017/07/26 18:17:35 [info] 1451#0: *2412 client connected '192.168.0.98'
    2017/07/26 18:17:35 [info] 1451#0: *2412 connect: app='live' args='' 
    flashver='LNX 9,0,124,2' swf_url='' tc_url='rtmp://192.168.0.98:1935/live' 
    page_url='' acodecs=4071 vcodecs=252 object_encoding=0, client: 
    192.168.0.98, server: 0.0.0.0:1935
    2017/07/26 18:17:35 [info] 1451#0: *2412 createStream, client: 192.168.0.98, 
    server: 0.0.0.0:1935
    2017/07/26 18:17:35 [info] 1451#0: *2412 play: name='newname' args='' 
    start=-2000 duration=0 reset=0 silent=0, client: 192.168.0.98, server:  
    0.0.0.0:1935
    2017/07/26 18:17:36 [info] 1451#0: *2410 recv() failed (104: Connection  
    reset by peer), client: 192.168.0.98, server: 0.0.0.0:1935
    2017/07/26 18:17:36 [info] 1451#0: *2410 disconnect, client: 192.168.0.98, 
    server: 0.0.0.0:1935
    2017/07/26 18:17:36 [info] 1451#0: *2410 deleteStream, client: 192.168.0.98, 
    server: 0.0.0.0:1935
    2017/07/26 18:17:36 [notice] 1451#0: signal 17 (SIGCHLD) received
    2017/07/26 18:17:36 [notice] 1451#0: unknown process 10487 exited with code 
    0
    2017/07/26 18:17:36 [info] 1451#0: *2229 exec: child 10487 exited; ignoring, 
    client: 192.168.0.78, server: 0.0.0.0:1935
    
    ver: 0.0.0.0:1935
    2017/07/26 18:17:41 [info] 1451#0: *2229 exec: starting managed child 
    'usr/local/bin/make_thumbnail.sh', client: 192.168.0.78, server:  
    0.0.0.0:1935
    2017/07/26 18:17:41 [info] 1451#0: *2413 client connected '192.168.0.98'
    2017/07/26 18:17:41 [info] 1451#0: *2413 connect: app='live' args='' 
    flashver='LNX 9,0,124,2' swf_url='' tc_url='rtmp://192.168.0.98:1935/live' 
    page_url='' acodecs=4071 vcodecs=252 object_encoding=0, client: 
    192.168.0.98, 
    server: 0.0.0.0:1935
    2017/07/26 18:17:41 [info] 1451#0: *2413 createStream, client: 192.168.0.98, 
    server: 0.0.0.0:1935
    2017/07/26 18:17:41 [info] 1451#0: *2413 play: name='newname' args='' 
    start=-2000 duration=0 reset=0 silent=0, client: 192.168.0.98, server: 
    0.0.0.0:1935
    2017/07/26 18:17:43 [info] 1451#0: *2229 exec: starting managed child 
    'ffmpeg', 
    client: 192.168.0.78, server: 0.0.0.0:1935
    2017/07/26 18:17:43 [info] 1451#0: *2414 client connected '192.168.0.98'
    2017/07/26 18:17:43 [info] 1451#0: *2414 connect: app='live' args='' 
    flashver='LNX 9,0,124,2' swf_url='' tc_url='rtmp://192.168.0.98:1935/live' 
    page_url='' acodecs=4071 vcodecs=252 object_encoding=0, client: 
    192.168.0.98, 
    server: 0.0.0.0:1935
    @
    
  • Generate individual HLS-compatible .ts segments on-demand by downloading as little bytes as possible from a remote input file

    28 juillet 2017, par Romain Cointepas

    I’m trying to generate individual HLS-compatible .ts segments on-demand by downloading/reading as little bytes as possible from a remote input file (hosted on a server supporting byte-ranges requests).

    One of the application for this would be to be able to transcode and play on Apple TV (via Airplay) a remote file that is not Airplay compatible, without having to download the entire file first.

    I am generating the playlist myself, and I have access to the ffprobe results for the remote file (that gives video duration, etc.).

    I have something working that plays via Airplay but with small video and audio glitches between each segments when I use the following command to generate each segment:

    ffmpeg -ss 60 -t 6 -i http://s3.amazonaws.com/misc-12345/avicii.vob -f mpegts -map 0:v:0 -map 0:a:0 -c:v libx264 -bsf:v h264_mp4toannexb -force_key_frames "expr:gte(t,n_forced*6)" -forced-idr 1 -pix_fmt yuv420p -colorspace bt709 -c:a aac -async 1 -preset ultrafast pipe:1

    Note: above command is for segment 11.ts, and in the m3u8 playlist I advertise each segment duration as 6 seconds.

    Here is a Youtube video showing the audio/video glitches between segments: https://www.youtube.com/watch?v=0vMwgbSfsu0

    The segment or hls modules of ffmpeg can’t be used because they both generate all the segments at once.

    I’ve been struggling on this for some days now and I would really appreciate some help!

  • ffmpeg yuvj422p color movie conversion avi2ogv

    28 juillet 2017, par 7Tonin

    While converting avi video to ogv, there is a color problem in output file. How can I solve this issue ? normal colors altered colors

    Actually a part of the problem is from the player - so weak question

    Command using ffmpeg-3.3.2-1.mga6.tainted :

    ffmpeg -i dscn0146.avi -pix_fmt yuv422p -s 640x480 dscn0146_hq.ogv -y
    

    And input metadata:

    Guessed Channel Layout for Input Stream #0.1 : mono
    Input #0, avi, from 'dscn0146.avi':
      Metadata:
        encoder         : 
        maker           : NIKON
        model           : COOLPIX S3500
        creation_time   : 2017-07-22 12:09:06
      Duration: 00:00:07.33, start: 0.000000, bitrate: 11091 kb/s
        Stream #0:0: Video: mjpeg (MJPG / 0x47504A4D), yuvj422p(pc, bt470bg/unknown/unknown), 640x480, 10770 kb/s, 30 fps, 30 tbr, 30 tbn, 30 tbc
        Stream #0:1: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 22050 Hz, mono, s16, 352 kb/s
    Stream mapping:
      Stream #0:0 -> #0:0 (mjpeg (native) -> theora (libtheora))
      Stream #0:1 -> #0:1 (pcm_s16le (native) -> vorbis (libvorbis))
    

    Processes normaly, but fires a warning:

    [swscaler @ 0xd3c3a0] deprecated pixel format used, make sure you did set range correctly
    

    Output metadata:

    Output #0, ogv, to 'dscn0146_hq.ogv':
      Metadata:
        model           : COOLPIX S3500
        maker           : NIKON
        encoder         : Lavf57.71.100
        Stream #0:0: Video: theora (libtheora), yuv422p(progressive), 640x480, q=2-31, 200 kb/s, 30 fps, 30 tbn, 30 tbc
        Metadata:
          encoder         : Lavc57.89.100 libtheora
          model           : COOLPIX S3500
          maker           : NIKON
        Stream #0:1: Audio: vorbis (libvorbis), 22050 Hz, mono, fltp
        Metadata:
          encoder         : Lavc57.89.100 libvorbis
          model           : COOLPIX S3500
          maker           : NIKON
    
  • Emulate iphone video stream from file to RTMPS in ffpmeg ?

    28 juillet 2017, par Alex808

    Try to do this by command

    ffmpeg -re -i IMG_0450.MOV -vcodec libx264 -profile:v main -preset:v medium -r 
    30 -g 60 -keyint_min 60 -sc_threshold 0 -b:v 2500k -maxrate 2500k -bufsize 
    2500k -filter:v scale="trunc(oha/2)2:720" -sws_flags lanczos+accurate_rnd -
    acodec libfdk_aac -b:a 96k -ar 48000 -ac 2 -f flv rtmps:\\...
    

    but witout success :(

  • Split screen and resize on ffmpeg streams

    28 juillet 2017, par lukas.gab

    I want get h264 streams from IP cameras, resize it, combine to grid, and restream or save to file. I succesfull split streams and save, but I don't know how can I resize streams. Becouse this streems are large, ffmpeg go to 100% cpu, loss frames and crach. Please tell me how can I resize this streams before combine and save ?? Thank for your help and time.

    This is my cli

    ffmpeg -rtsp_transport tcp -i "rtsp://admin:Pass@192.168.88.76:554/h264" -rtsp_transport tcp -i "rtsp://admin:Pass@192.168.88.76:554/h264" -filter_complex "[0:v][1:v]hstack" -c:v libx264 combo.avi