I'm using FFMpeg to segment a WAV file into mp3s for use in HTTP Live Streaming.
I'm using this command:
ffmpeg -i input.wav -c:a libmp3lame -b:a 128k -map 0:0 -f segment
-segment_time 10 -segment_list outputlist.m3u8 -segment_format mp3 'output%03d.mp3'
The stream is working, however I'm getting small "gaps" between each mp3 segment. Why is this?
I was able to solve this by using -segment_format mpegts.
ffmpeg -i input.wav -c:a libmp3lame -b:a 128k -map 0:0 -f segment -segment_time 10 -segment_list outputlist.m3u8 -segment_format mpegts 'output%03d.mp3'
Related
I am using the following command
ffmpeg -framerate 30 -video_size 1280x720 -input_format h264 -i /dev/video2 -c copy -strftime 1 -hls_flags second_level_segment_index -hls_init_time 3 -flags -global_header -f hls -bsf:v h264_mp4toannexb -hls_time 3 -hls_segment_filename 'c_%Y-%m-%dT%H:%M:%S_%%06d.mp4' out.m3u8
I have the requirement that bitstream should be avc1, but I have to run separate FFmpeg command to convert the recorded video slice to avc1
ffmpeg -i h264.mp4 -c:v copy -bsf:v h264_mp4toannexb -an out.h264
For this, I have to wait for the conversion
How should I modify the first FFmpeg command so that I get avc1 bitstream video slices?
ffmpeg -framerate 30 -video_size 1280x720 -input_format h264 -i /dev/video2 -c copy -strftime 1 -hls_flags second_level_segment_index -hls_init_time 3 -flags -global_header -f hls -bsf:v h264_mp4toannexb -hls_time 3 -hls_segment_filename 'c_%Y-%m-%dT%H:%M:%S_%%06d.mp4' out.m3u8
and
ffmpeg -i h264.mp4 -c:v copy -bsf:v h264_mp4toannexb -an out.h264
I need avc1 bitstream
i am having issue, to concat video, it looses the audio sync and audio started from previous video.
i have tried below two link/so answer by Mulvya, but none of them work :(
here is the code i am trying:
1: re-encode file a (1):
ffmpeg.exe -i "f:\1.avi" -af apad -vf scale=1280:720 -crf 15.0 -vcodec libx264 -acodec aac -ar 48000 -b:a 192k -coder 1 -rc_lookahead 60 -threads 0 -shortest -avoid_negative_ts make_zero -fflags +genpts 01.mp4
2: re-encode file b (2):
ffmpeg.exe -i "f:\2.mp4" -af apad -vf scale=1280:720 -crf 15.0 -vcodec libx264 -acodec aac -ar 48000 -b:a 192k -coder 1 -rc_lookahead 60 -threads 0 -shortest -avoid_negative_ts make_zero -fflags +genpts 02.mp4
3: Now contact using following command:
ffmpeg.exe -f concat -safe 0 -i "f:\files.txt" -c copy test.mp4
but audio is not synced with video ;(
i also uploaded both video (and also the output) on dropbox:
Video Sync Issue Source And Result Files
so, any help, how to make audio perfectly sync with video would be great :)
Some one else on another forum helped me to find the issue. So, i post it as answer here so that someone else may can get help.
I was concerned about same frame size, audio and video codec to concat properly, but i forgot about frame rate.
That first sample video (mentioned in my question) frame rate was 12, while 2nd video frame rate was 25; and that's what make the sync problem.
Now, i have set frame rate 25 to those two video (-r 25) and it's works like charms :)
below is the full conversion code:
ffmpeg.exe -i "f:\1.avi" -r 25 -af apad -vf scale=1280:720 -crf 15.0 -vcodec libx264 -acodec aac -ar 48000 -b:a 192k -coder 1 -rc_lookahead 60 -threads 0 -shortest -avoid_negative_ts make_zero -fflags +genpts 01.mp4
hope it may help some one like me in near future.
best regards
some other solution for syncing audio & video
use -bsf:v h264_mp4toannexb in your input files
ffmpeg.exe -i "1.avi" -af apad -vf scale=1280:720 -crf 15.0 -vcodec libx264 -acodec aac -bsf:v h264_mp4toannexb -ar 48000 -b:a 192k -coder 1 -rc_lookahead 60 -threads 0 -shortest -avoid_negative_ts make_zero -fflags +genpts output1.flv
and same for 2nd file
ffmpeg.exe -i "2.avi" -af apad -vf scale=1280:720 -crf 15.0 -vcodec libx264 -acodec aac -bsf:v h264_mp4toannexb -ar 48000 -b:a 192k -coder 1 -rc_lookahead 60 -threads 0 -shortest -avoid_negative_ts make_zero -fflags +genpts output2.flv
then files can be joined together
ffmpeg -f concat -safe 0 -i concat.txt -c copy -bsf:a aac_adtstoasc final.flv
where concat.txt file contains
file 'output1.flv'
file 'output2.flv'
I was using the following command for recording input streams to mp4 into 10 seconds clip. But since few days there is no voice in the output mp4 clips.
Command is
ffmpeg -i rtsp://localhost:8554/mystream -c copy -bsf:a aac_adtstoasc -f segment -segment_time 10 -reset_timestamps 1 -map 0 output%d.mp4
ffmpeg output
I think its because of the format of input stream but i don't know for sure and also, i don't know how to solve it.
I solved it using the following command.
ffmpeg -i rtsp://localhost:8554/mystream -c:a aac -c:v copy -bsf:a aac_adtstoasc -f segment -segment_time 10 -reset_timestamps 1 -map 0 output%d.mp4
changing -c to -c:a aac -c:v
I have setup a HLS live stream on AWS. Significant part of the video plays as expected but in some portions audio is lost while the video continues to play. Please share you thoughts/insights if you have faced such an issue.
I transcode video to h264, baseline3.1 and audio to aac stereo 2 channels before segmenting to 10s files. Following commands are being used:
Transcoding:
ffmpeg -y -i ${file_path} -b:v ${vBitrate} -minrate ${vBitrate} -maxrate ${vBitrate} -c:v libx264 -b:a ${aBitrate} -c:a libfaac -ac 2 -r 25 -s ${resolution} -profile:v baseline -level 3.1 ${output_dir}/${file_name}.ts
Ex: vBitrate: 1m, aBirate: 128k, resolution: 960x540
Splittting:
ffmpeg -i ${file_path} -c:v copy -c:a copy -flags -global_header -map 0 -f segment -segment_time ${segment} -segment_list ${output_dir}/playlist.m3u8 -segment_format mpegts tmp0/${file_name}_%02d.ts
Ex: segment: 10
Setup: segments are being served from Nginx and playlist is managed by a Python/Flask app.
I'm looking for a way to record a video UDP stream using ffmpeg but in 10mn chunks.
I currently use the following to get 10mn of video (with h264 transcoding).
"ffmpeg -i udp://239.0.77.15:5000 -map 0:0 -map 0:1 -s 640x360 -vcodec libx264 -g 100 -vb 500000 -r 25 -strict experimental -vf yadif -acodec aac -ab 96000 -ac 2 -t 600 -y /media/test.m4 "
My problem is that using command line ffmpeg needs time to resync with the udp stream loosing 2 seconds of video each time. Is it normal ?
Any idea if there is a way to do it in command line or should I tried to use the ffmpeg API ?
Thanks in advance
Ok found it.
Recently ffmpeg add a segmenter, here is the syntax:
-f segment: tell ffmpeg to use the segmenter
-segment_time: chunk size in second
You can use autoincrement file name with something like %03d (000,001,002,003...).
Here is my line to transcode a UDP MPEGTS stream, into H264+AAC and save it to file chunk (60 seconds):
ffmpeg -i udp://239.0.77.15:5000 -map 0:0 -map 0:1 -s 640x360 -vcodec libx264 -g 60 -vb 500000 -strict experimental -vf yadif -acodec aac -ab 96000 -ac 2 -y -f segment -segment_time 60 "xxx-%03d.ts"
This is a better way:
ffmpeg -re -i udp://10.1.1.238:1234?fifo_size=1000000 -vcodec libx264 -vb 500000 -g 60 -vprofile main -acodec aac -ab 128000 -ar 48000 -ac 2 -vbsf h264_mp4toannexb -b 1000k -minrate 1000k -maxrate 1000k -strict experimental -f stream_segment -segment_format mpegts -segment_time 5 -segment_atclocktime 1 -reset_timestamps 1 -strftime 1 d:/%H%M%S.mp4
By this code ffmpeg makes series of output files using current system time.