I am using ffmpeg to create m3u8 playlist for a video (actually a live video stream). I am using the following command:
ffmpeg -i /home/ubuntu/Download/1459530099245.mkv -c:a aac -strict experimental -ac 2 -ar 48k -ab 64k -c:v libx264 -s 480x270 -aspect 16:9 -b:v 400k -r 15 -g 45 -profile:v baseline -level 3.0 -f hls -hls_time 9 -hls_list_size 0 /home/ubuntu/Download/New Playlist.m3u8
It produces m3u8 file as well as ts files.
Question: simply, how can we produce m3u8 playlist and TS files for a particular duration of source video? E.g., I want to get playlist only for first 20 seconds or so?
You can use command -to. Just add -to 00:00:20 after input path
In your variant:
ffmpeg -i /home/ubuntu/Download/1459530099245.mkv -to 00:00:20 -c:a aac -strict experimental -ac 2 -ar 48k -ab 64k -c:v libx264 -s 480x270 -aspect 16:9 -b:v 400k -r 15 -g 45 -profile:v baseline -level 3.0 -f hls -hls_time 9 -hls_list_size 0 /home/ubuntu/Download/New Playlist.m3u8
More information here: http://www.bogotobogo.com/FFMpeg/ffmpeg_seeking_ss_option_cutting_section_video_image.php
Related
I am using following code to live stream video in youtube.
ffmpeg -y -loop 1 -i "still.jpg" -i "audio.mp3" " -c:v libx264 -pix_fmt yuv420p -crf 21 -r 1 -g 30 -keyint_min 5 -x264opts "keyint=5:min-keyint=5:no-scenecut" -s 1280x720 -tune zerolatency -b:a 128k -c:a aac -ar 48000 -strict experimental -f flv rtmp://a.rtmp.youtube.com/live2/steam-key.
I would like to set youtube live title and description in the above command. Is it possible?
I have the following ffmpeg command that streams an input to an RTMP endpoint :
ffmpeg
-re
-i -
-r 30
-vf scale=852:480
-c:v libx264
-pix_fmt yuv420p
-profile:v main
-preset veryfast
-x264opts "nal-hrd=cbr:no-scenecut"
-minrate 3000
-maxrate 3000
-g 60
-c:a aac
-b:a 160k
-ac 2
-ar 44100
-f flv
Some RTMPURL/ Some RTMPKey
This command works but the output frame rate is not respected. It drops to 6 fps.
I need it to be always 30 fps.
Does anyone know why it's not respected please ?
Thanks
I really would appreciate all the help I can get here.
I'm trying to use the libx265 codec for recording an xorg dummy screen. The command that currently works for H264 (libx264 codec) is:
ffmpeg -y -v info -f x11grab -draw_mouse 0 -r 30 -s 1280x720
-thread_queue_size 4096 -i :0.0+0,0 -f alsa -acodec aac -strict -2 -ar 44100 -b:a 128k -af aresample=async=1 -c:v libx264 -preset fast
-profile:v main -level 3.1 -pix_fmt yuv420p -r 30 -crf 21 -g 60 -tune zerolatency -f mp4 capture.mp4
In trying to get H265 instead, I first changed the codec to libx265 like below:
ffmpeg -y -v info -f x11grab -draw_mouse 0 -r 30 -s 1280x720
-thread_queue_size 4096 -i :0.0+0,0 -f alsa -acodec aac -strict -2 -ar 44100 -b:a 128k -af aresample=async=1 -c:v libx265 -preset fast
-profile:v main -level 3.1 -pix_fmt yuv420p -r 30 -crf 21 -g 60 -tune zerolatency -f mp4 capture.mp4
But that didn't do it. Although it didn't error, it was producing a file that was playing at twice the recorded speed (i.e. twice the speed of the clip that was recorded).
Then I tried using -x265-params to specify the parameters like this:
ffmpeg -y -v info -f x11grab -draw_mouse 0 -r 30 -s 1280x720
-thread_queue_size 4096 -i :0.0+0,0 -f alsa -acodec aac -strict -2 -ar 44100 -b:a 128k -af aresample=async=1 -c:v libx264 -preset fast
-x265-params profile=main:level=3.1:crf=21 -pix_fmt yuv420p -r 30 -g 60 -tune zerolatency -f mp4 capture.mp4
And this gave me an error with the following message:
"output file #0 does not contain any stream ffmpeg"
I've tried all sorts of combinations, searched extensively online (for both how to set 265 parameters and on the output file error), but I'm not making a headway. I'm really new to all this. Can anyone please help (with the most simple terms and directions)?
Is there a single command to transcode mp4 video + aac into HLS at multiple resolutions ?
I have a convert server, and I think to live stream multiple resolutions, I must create all resolutions at the same time and this process must be concurrent.
I raised this issue,because I do this process wtih running these below codes at 4 cmd seperately for creating 4 resolutions of a video examply at the same time:
1- 720p
ffmpeg -i 123.mp4 -c:a aac -strict experimental -c:v libx264 -s hd720 -aspect 16:9 -f hls -hls_list_size 0 -hls_time 2 720p/out.m3u8
2- 480p
ffmpeg -i 123.mp4 -c:a aac -strict experimental -c:v libx264 -s hd480 -aspect 16:9 -f hls -hls_list_size 0 -hls_time 2 480p/out.m3u8
3- 360p
ffmpeg -i 123.mp4 -c:a aac -strict experimental -c:v libx264 -s nhd -aspect 16:9 -f hls -hls_list_size 0 -hls_time 2 360p/out.m3u8
4- 200p
ffmpeg -i 123.mp4 -c:a aac -strict experimental -c:v libx264 -s cga -aspect 16:9 -f hls -hls_list_size 0 -hls_time 2 200p/out.m3u8
but doing in this way have some problems.
1- the .TS parts of each resolutions doesn't create with another resolutions part at the same time(this issue makes that in switching resolutions, player cannot seek to the continue of selected resolution,because that part doesn't create yet).
2- You have run some threads for each live streaming.
Here is the answer of mine,Note that you must be set -hls_time If you want the number part of each resolutions be same.
ffmpeg -re -i 123.mp4
-c:a aac -c:v libx264 -s hd480 -aspect 16:9 -f hls -hls_list_size 0 -hls_time 2 480p/out.m3u8
-c:a aac -c:v libx264 -s nhd -aspect 16:9 -f hls -hls_list_size 0 -hls_time 2 360p/out.m3u8
-c:a aac -c:v libx264 -s cga -aspect 16:9 -f hls -hls_list_size 0 -hls_time 2 200p/out.m3u8
I am trying to stream a video loop to justin.tv using FFmpeg? I have managed to loop an image sequence and combine it with line in audio:
ffmpeg -loop 1 -i imageSequence%04d.jpg -f alsa -ac 2 -ar 22050 -ab 64k \
-i pulse -acodec adpcm_swf -r 10 -vcodec flv \
-f flv rtmp://live.justin.tv/app/<yourStreamKeyHere>
Is it possible to do this with a video file?
Definitely possible. In the recent versions of ffmpeg they have added a -stream_loop flag that allows you to loop the input as many times as required.
The gotcha is that if you don't regenerate the pts from the source, ffmpeg will drop frames after the first loop (as the timestamp will suddenly go back in time). To avoid this, you need to tell ffmpeg to generate the pts so you get an increasing timestamp between loops. This is done with the +genpts call (it has to be before the -i arg).
Here's an example ffmpeg call (replace $F with your input file). This example generates two output streams and the -stream_loop -1 argument tells ffmpeg to continuously loop the input. The output in this case is for a similar stream broadcast ingest (MetaCDN), adjust accordingly to your requirements.
ffmpeg -threads 2 -re -fflags +genpts -stream_loop -1 -i $F \
-s 640x360 -ac 2 -f flv -vcodec libx264 -profile:v baseline -b:v 600k -maxrate 600k -bufsize 600k -r 24 -ar 44100 -g 48 -c:a libfdk_aac -b:a 64k "rtmp://publish.live.metacdn.com/2050C7/dfsdfsd/lowquality_664?hello&adbe-live-event=lowquality_" \
-s 1920x1080 -ac 2 -f flv -vcodec libx264 -profile:v baseline -b:v 2000k -maxrate 2000k -bufsize 2000k -r 24 -ar 44100 -g 48 -c:a libfdk_aac -b:a 64k "rtmp://publish.live.metacdn.com/2050C7/dfsdfsd/highquality_2064?mate&adbe-live-event=highquality_"
Sinclair Media has found a solution by using the lavfi filter and appending :loop=0 to the file name :
This is untested:
ffmpeg -f lavfi -re -i movie=StreamTest.avi:loop=0 \
-acodec libfaac -b:a 64k -pix_fmt yuv420p -vcodec libx264 \
-x264opts level=41 -r 25 -profile:v baseline -b:v 1500k \
-maxrate 2000k -force_key_frames 50 -s 640×360 -map 0 -flags \
-global_header -f segment -segment_list index_1500.m3u8 \
-segment_time 10 -segment_format mpeg_ts \
-segment_list_type m3u8 segmented.ts
But it should create a local "index_1500.m3u8" file that streams the video in "StreamTest.avi".
I just reuse the Rob's answers with a few of modifications in order to provide a file to live streaming
ffmpeg -threads 2 -re -fflags +genpts -stream_loop -1 -i gvf.mp4 -c copy -f mpegts -mpegts_service_id 102 -metadata service_name=My_channel -metadata service_provider=My_Self -max_interleave_delta 0 -use_wallclock_as_timestamps 1 -flush_packets 1 "udp://233.0.0.1:1001?localaddr=10.60.4.237&pkt_size=188"